Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The plugin is ignoring my custom file when specific the file with path. #39

Open
arohim opened this issue Aug 17, 2021 · 4 comments
Open
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@arohim
Copy link

arohim commented Aug 17, 2021

As the document said we have to create a custom file at the root of the folder and it's working fine on my project,
Is it possible to move my custom file into another folder?

staging {
    secrets {
        propertiesFileName 'properties/staging.properties'
    }
}

The plugin is ignoring my custom file with the path and then somehow read from my release.properties instead.

Does anyone know how to read the configuration file from another folder?

@arriolac arriolac added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Aug 17, 2021
@arriolac
Copy link
Collaborator

Reading from another folder is not possible at the moment. If this is useful for others as well it can certainly be implemented.

@arohim
Copy link
Author

arohim commented Aug 24, 2021

I see, thank you for letting me know

@saket
Copy link

saket commented Mar 27, 2022

It'd be nice to have this. I am trying to use this plugin in multiple modules with a single properties file.

@saeedata
Copy link

saeedata commented Sep 3, 2022

hi,
I have this issue too, you can clone the project and use it locally with these changes:

instead of getting root project in SecretsPlugin.kt file:

project.rootProject.loadPropertiesFile(
        extension.propertiesFileName
)

you can change to:

project.loadPropertiesFile(
       extension.propertiesFileName
)

this change load properties from current module: however you should be aware about how the plugin work, I mean if you don't declare a file path in the plugin extension config for properties, you should at least have local.properties file in any module you want to use plugin or maybe you can change this logic as well.

const val defaultPropertiesFile = "local.properties"

also I'd like to have a regex for properties files,
so you can change this line too:

val buildTypeFileName = "secrets.${variant.buildType}.properties"
val flavorFileName = "secrets.${variant.flavorName}.properties"

this force the properties files to start with secrets.

in addition, if you like to have boolean and integer variable in you BuildConfig too you can change these line too:

fun Variant.inject(properties: Properties, ignore: List<String>) {
   val ignoreRegexs = ignore.map { Regex(pattern = it) }
   properties.keys.map { key ->
        key as String
    }.filter { key ->
        key.isNotEmpty() && !ignoreRegexs.any { it.containsMatchIn(key) }
    }.forEach { key ->
        val value = properties.getProperty(key).removeSurrounding("\"")
        val translatedKey = key.replace(javaVarRegexp, "")
        if (value == "true" || value == "false") {
            buildConfigFields.put(
                translatedKey,
                BuildConfigField("boolean", value, null)
            )
        } else if (value.matches("\\d+(?:\\.\\d+)?".toRegex())) {
            buildConfigFields.put(
                translatedKey,
                BuildConfigField("int", value, null)
            )
        } else {
            buildConfigFields.put(
                translatedKey,
                BuildConfigField("String", value.addParenthesisIfNeeded(), null)
            )
        }
        manifestPlaceholders.put(translatedKey, value)
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

4 participants