com.admc.gradle..JavaPropFile.groovy.swp Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-javaPropFile-plugin Show documentation
Show all versions of gradle-javaPropFile-plugin Show documentation
Load Gradle Project with properties from Java properties files
b0VIM 7.3 b??Np? ?j blaine beyla ~blaine/gradle-javaPropFile-plugin/src/main/groovy/com/admc/gradle/JavaPropFile.groovy utf-8
3210 #"! U tp Y a Z Q ?
ad ? Y ? ? ? ? ? d F
? ? t I ?
?
?
?
l
7
? ? ? ? ? ` ? ? ? ? r l k L ?
?
V
R
&
? ? ? q V 1 ? ? r R 2 ? ? B
? ? \ ? ? z R @ ? ? ? ? h C 9 ? ? z . ? ? ? = ? ? ? ? if (unsatisfiedRefBehavior == Behavior.NO_SET) return + unsatisfiedRefBehavior) + '.\nWill handle according to unsatisifiedRefBehavior: ' + '\ndue to unresolved references to: ' + unresolveds 'Unable to resolve top-level properties: ' + props.keySet() gp.logger.warn( + '\ndue to unresolved references to: ' + unresolveds) 'Unable to resolve top-level properties: ' + props.keySet() throw new GradleException( if (unsatisfiedRefBehavior == Behavior.THROW) // If we get here, then we have unsatisfied references if (prevCount == 0) return } prevCount = props.size() if (prevCount == props.size()) break } } props.remove(pk) assign(pk, newValString, systemPropPattern) if (haveNewVal) { } return matchGrps[0] haveNewVal = false unresolveds << matchGrps[1] return System.properties[matchGrps[1]] && System.properties.containsKey(matchGrps[1])) if (expandSystemProps return gp.property(matchGrps[1]) && (gp.property(matchGrps[1]) instanceof String)) if (gp.hasProperty(matchGrps[1]) // This block resolves ${references} in property values newValString = pv.replaceAll(curlyRefGrpPattern) { matchGrps -> haveNewVal = true new HashMap(props).each() { pk, pv -> unresolveds.clear() while (prevCount > 0) { : Pattern.compile("^\\Q" + systemPropPrefix + "\\E(.+)")) ? null Pattern systemPropPattern = ((systemPropPrefix == null) def unresolveds = [] int prevCount = props.size() boolean haveNewVal String newValString 'Loaded ' + props.size() + ' from ' + propFile.absolutePath) gp.logger.info( propFile.withInputStream { props.load(it) } Properties props = new Properties() """ """Specified properties file inaccessible: $propFile.absolutePath assert propFile.isFile() && propFile.canRead(): '''unsatisfiedRefBehavior may not be set to null''' assert unsatisfiedRefBehavior != null: void load(File propFile) { } gp = p JavaPropFile(Project p) { //enum Behavior { LITERAL, EMPTY, NO_SET, UNSET, THROW } enum Behavior { LITERAL, EMPTY, NO_SET, THROW } // property from a Project. Project.properties.remove('x') does not work. // Giving up on UNSET because Gradle provides no way to remove a String systemPropPrefix boolean typeCasting boolean overwriteThrow boolean overwrite = true boolean expandSystemProps = true Behavior unsatisfiedRefBehavior = Behavior.THROW private Project gp Pattern.compile(/(.+)\(([^)]+)\)/) private static final Pattern castLastPattern = Pattern.compile(/\(([^)]+)\)(.+)/) private static final Pattern castFirstPattern = Pattern.compile(/\$\{[^}]+\}/) private static final Pattern curlyRefPattern = Pattern.compile(/\$\{([^}]+)\}/) private static final Pattern curlyRefGrpPattern = class JavaPropFile { import org.gradle.api.GradleException import org.gradle.api.Project import java.lang.reflect.Constructor import java.lang.reflect.Method import java.util.regex.Matcher import java.util.regex.Pattern package com.admc.gradle ad ? ? ? ? ? ? ? } } } gp.setProperty(propName, newVal) ad G ? a ? ? M 7 ? ? ? _ < ?
?
?
?
t
j
d
c
<
? ? ? _ ? ? ? w 7 6 ?
?
?
h
8
2
1
? ? g ? ? ? ? d ? $ ? ? s O ( ? ? ? ? ~ . ? ? ? ~ a : ? ? ? ? I ) ? ? ? W 7 ? ? ? ? ? e B # ? ? ? ? String propName = nul String propName = null String cName = null Matcher matcher = null boolean setSysProp = false String rawName, String valString, Pattern systemPropPattern) { private void assign( } } throw new GradleException("Failed to construct a $c.name with param '$str': $e") } catch (Exception e) { return cons.newInstance(str) try { } throw new GradleException("TypeCasting class $cName has neither a static static .valueOf(String) method nor a (String) constructor") } catch (Exception e) { cons = c.getDeclaredConstructor(String.class) try { Constructor> cons = null } throw new GradleException("Failed to generate a $c.name with param '$str': $e") } catch (Exception e) { return m.invoke(null, str) if (m != null) try { } // Intentionally empty } catch (Exception e) { m = c.getDeclaredMethod("valueOf", String.class) try { Method m = null throw new GradleException("Inaccessible typeCasting class: $cName") if (c == null) } // intentionally empty } catch (Exception e) { c = Class.forName(cName) else try { } // intentionally empty } catch (Exception e) { break c = Class.forName(pkg + '.' + cName) for (pkg in JavaPropFile.defaultGroovyPackages) try { if (cName.indexOf('.') < 0) Class> c = null; if (cName == '') return null assert cName != null assert str != null private static Object instantiateFromString(String str, String cName) { // are only 2 other things in the package. // includes BigDecimal and BigInteger from that package, but there // java.math is a slight over-simplification because Groovy only ['java.lang', 'java.io', 'java.math', 'java.net', 'java.util'] private static final List defaultGroovyPackages = } overwriteThrow = originalOverwriteThrow overwrite = originalOverwrite unsatisfiedRefBehavior = originalBehavior if (localPropertiesFile.exists()) load(localPropertiesFile) unsatisfiedRefBehavior = Behavior.NO_SET if (appPropertiesFile.exists()) load(appPropertiesFile) overwriteThrow = false overwrite = true unsatisfiedRefBehavior = Behavior.THROW // Unlike Ant, the LAST loaded properties will override. File localPropertiesFile = gp.file('local.properties') File appPropertiesFile = gp.file('app.properties') boolean originalOverwriteThrow = overwriteThrow boolean originalOverwrite = overwrite Behavior originalBehavior = unsatisfiedRefBehavior void traditionalPropertiesInit() { } } } assert false: "Unexpected Behavior value: $unsatisfiedRefBehavior" default: */ break gp.properties.remove(pk) case Behavior.UNSET: /* See not above about Behavior.UNSET. break pv.replaceAll(curlyRefPattern, ''), systemPropPattern) assign(pk, case Behavior.EMPTY: break assign(pk, pv, systemPropPattern) case Behavior.LITERAL: switch (unsatisfiedRefBehavior) { new HashMap(props).each() { pk, pv -> ad b Q ? ? s i O ' ? ? o - ?
?
?
[
,
? ? ? C ? ? ? ` ?
?
?
[
+
? ? r A $ ? ? ? ? ? ? ? i 4 ? ? h " ? ? ? h % ? ? ? d ? ? a / ? ? x @ ? ? ? I 4 ? ? ? ? ? s b else System.setProperty(propName, newVal) if (setSysProp) // New property } else { } gp.setProperty(propName, newVal) else System.setProperty(propName, newVal) if (setSysProp) + newVal.class.name) + oldVal.class.name + ' to ' + "'$propName'. From " + "for change of property " throw new GradleException("Incompatible type " && !oldVal.class.equals(newVal.class)) if (oldVal != null && newVal != null // Property value really changing + "'$oldVal' to '$newVal'") + "value of property '$propName' from " + "changes, but attempted to change " "Configured to prohibit property value " throw new GradleException( if (overwriteThrow) || !oldVal.equals(newVal)))) { && ((oldVal == null || newVal == null) if ((overwrite || overwriteThrow) && (oldVal != newVal // or if oldVar == newVar. // (!overwrite && !overwriteThrow) // We will do absolutely nothing if either : gp.property(propName)) Object oldVal = (setSysProp ? System.properties[propName] || (!setSysProp && gp.hasProperty(propName))) { if ((setSysProp && System.properties.containsKey(propName)) : JavaPropFile.instantiateFromString(valString, cName)) Object newVal = ((cName == null) ? valString assert propName != null } propName = rawName } else { } } } propName = rawName } else { cName = matcher.group(2) propName = matcher.group(1) if (matcher.matches()) { matcher = castLastPattern.matcher(rawName) } else { propName = matcher.group(2) cName = matcher.group(1) if (matcher.matches()) { matcher = castFirstPattern.matcher(rawName) } else { cName = '' + "typeCast for property '$propName'") "Non-empty value supplied to a null " throw new GradleException( if (valString.length() > 0) propName = rawName.substring(0, rawName.length() - 2) } else if (rawName.length() > 2 && rawName.endsWith("()")) { cName = '' + "typeCast for property '$propName'") "Non-empty value supplied to a null " throw new GradleException( if (valString.length() > 0) propName = rawName.substring(2) if (rawName.length() > 2 && rawName.startsWith("()")) { + "end with ): $rawName") "TypeCast name may not begin with ( and " throw new GradleException( && rawName.charAt(rawName.length()-1) == ')') if (rawName.charAt(0) == '(' } else if (typeCasting) { propName = matcher.group(1) if (setSysProp) { } setSysProp = matcher.matches() matcher = systemPropPattern.matcher(rawName) if (systemPropPattern != null) {