Search in sources :

Example 11 with SortedProperties

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;
}
Also used : SortedProperties(com.codename1.ant.SortedProperties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 12 with SortedProperties

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;
}
Also used : Enumeration(java.util.Enumeration) BuildException(org.apache.tools.ant.BuildException) SortedProperties(com.codename1.ant.SortedProperties)

Aggregations

SortedProperties (com.codename1.ant.SortedProperties)12 File (java.io.File)5 FileInputStream (java.io.FileInputStream)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 FileOutputStream (java.io.FileOutputStream)2 FileObject (org.apache.commons.vfs2.FileObject)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 BufferedImage (java.awt.image.BufferedImage)1 Enumeration (java.util.Enumeration)1 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)1 PatternFileSelector (org.apache.commons.vfs2.PatternFileSelector)1 Artifact (org.apache.maven.artifact.Artifact)1 BuildException (org.apache.tools.ant.BuildException)1 Copy (org.apache.tools.ant.taskdefs.Copy)1 Expand (org.apache.tools.ant.taskdefs.Expand)1 FileSet (org.apache.tools.ant.types.FileSet)1