Skip to content

Commit

Permalink
Allow all local.properties flags to be overridden by environment
Browse files Browse the repository at this point in the history
Fixes #360

local.properties values will override those in environment
  • Loading branch information
advayDev1 committed Aug 20, 2015
1 parent 2ae4450 commit 06eb941
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,20 @@ Also see the FAQ note on [developing with Swift](https://github.com/j2objc-contr
You can reduce the build time by 50% by skipping the release binaries by adding the
following to your root level `local.properties` file:

j2objc.release.enabled=false
```properties
j2objc.release.enabled=false
```

This is helpful for a tight modify-compile-test loop using only debug binaries.
You can also do this for `j2objc.debug.enabled`.

If you'd rather just disable release builds for a particular run of the command line:

```sh
J2OBJC_RELEASE_ENABLED=false ./gradlew build
```

The `local.properties` value overrides the environment variable, if present.

### J2ObjC Standard Libraries

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ class Utils {

private static final String PROPERTY_KEY_PREFIX = 'j2objc.'

/**
* Retrieves the local properties with highest precedence:
* 1. local.properties value like j2objc.name1.name2 when present.
* 2. environment variable like J2OBJC_NAME1_NAME2 when present.
* 3. defaultValue.
*/
static String getLocalProperty(Project proj, String key, String defaultValue = null) {

// Check for requesting invalid key
Expand All @@ -96,7 +102,7 @@ class Utils {
"Valid Keys: $PROPERTIES_VALID_KEYS")
}
File localPropertiesFile = new File(proj.rootDir, 'local.properties')
String result = defaultValue
String result = null
if (localPropertiesFile.exists()) {
Properties localProperties = new Properties()
localPropertiesFile.withInputStream {
Expand All @@ -117,18 +123,21 @@ class Utils {
}
}

result = localProperties.getProperty(PROPERTY_KEY_PREFIX + key, defaultValue)
result = localProperties.getProperty(PROPERTY_KEY_PREFIX + key, null)
}
return result
if (result == null) {
// debug.enabled becomes J2OBJC_DEBUG_ENABLED
String envName = 'J2OBJC_' + key.replace('.', '_').toUpperCase(Locale.ENGLISH)
// TODO: Unit tests.
result = System.getenv(envName)
}
return result == null ? defaultValue : result
}

// MUST be used only in @Input getJ2objcHome() methods to ensure up-to-date checks are correct
// @Input getJ2objcHome() method can be used freely inside the task action
static String j2objcHome(Project proj) {
String result = getLocalProperty(proj, 'home')
if (result == null) {
result = System.getenv('J2OBJC_HOME')
}
if (result == null) {
String message =
"J2ObjC Home not set, this should be configured either:\n" +
Expand Down

0 comments on commit 06eb941

Please sign in to comment.