use of com.codename1.ant.SortedProperties in project CodenameOne by codenameone.
the class InstallCn1libsMojo method getLibraryAppendedProperties.
/**
* Appended properties for library.
* @param artifact
* @return
* @throws IOException
*/
private SortedProperties getLibraryAppendedProperties(Artifact artifact) throws IOException {
SortedProperties out = new SortedProperties();
File file = getLibraryAppendedPropertiesFile(artifact);
if (file.exists()) {
try (FileInputStream fis = new FileInputStream(file)) {
out.load(fis);
}
}
return out;
}
use of com.codename1.ant.SortedProperties in project CodenameOne by codenameone.
the class InstallCn1libsMojo method mergeProjectRequiredProperties.
/**
* Merges the lib's required properties with the project properties. Does not persist.
* @param artifact
* @return True if project properties were changed.
* @throws IOException
*/
private boolean mergeProjectRequiredProperties(Artifact artifact) throws IOException {
SortedProperties projectProps = getProjectProperties();
SortedProperties libProps = getLibraryRequiredProperties(artifact);
String javaVersion = (String) projectProps.getProperty("codename1.arg.java.version", "8");
String javaVersionLib = (String) libProps.get("codename1.arg.java.version");
if (javaVersionLib != null) {
int v1 = 5;
if (javaVersion != null) {
v1 = Integer.parseInt(javaVersion);
}
int v2 = Integer.parseInt(javaVersionLib);
// if the lib java version is bigger, this library cannot be used
if (v1 < v2) {
throw new BuildException("Cannot use a cn1lib with java version " + "greater then the project java version");
}
}
// merge and save
SortedProperties merged = projectProps;
// merged.putAll(projectProps);
Enumeration keys = libProps.propertyNames();
boolean changed = false;
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
if (!merged.containsKey(key)) {
merged.put(key, libProps.getProperty(key));
changed = true;
} else {
// install will fail
if (!merged.get(key).equals(libProps.getProperty(key))) {
throw new BuildException("Property " + key + " has a conflict");
}
}
}
return changed;
}
Aggregations