Search in sources :

Example 41 with Property

use of com.codename1.rad.models.Property in project CodenameOne by codenameone.

the class EditableResources method setThemeProperty.

/**
 * Place a theme property into the resource editor
 */
public void setThemeProperty(final String themeName, final String key, final Object value) {
    final Object oldValue = getTheme(themeName).get(key);
    pushUndoable(new UndoableEdit() {

        @Override
        protected String performAction() {
            if (value == null) {
                getTheme(themeName).remove(key);
            } else {
                getTheme(themeName).put(key, value);
            }
            return themeName;
        }

        @Override
        protected String performUndo() {
            if (oldValue == null) {
                getTheme(themeName).remove(key);
            } else {
                getTheme(themeName).put(key, oldValue);
            }
            return themeName;
        }
    });
}
Also used : AnimationObject(com.codename1.ui.animations.AnimationObject)

Example 42 with Property

use of com.codename1.rad.models.Property in project CodenameOne by codenameone.

the class EditableResources method setThemeProperties.

/**
 * Place a theme property into the resource editor
 */
public void setThemeProperties(final String themeName, final String[] keys, final Object[] values) {
    final Object[] oldValues = new Object[keys.length];
    Hashtable th = getTheme(themeName);
    if (th == null) {
        return;
    }
    for (int iter = 0; iter < keys.length; iter++) {
        oldValues[iter] = th.get(keys[iter]);
    }
    pushUndoable(new UndoableEdit() {

        @Override
        protected String performAction() {
            for (int iter = 0; iter < keys.length; iter++) {
                if (values[iter] == null) {
                    getTheme(themeName).remove(keys[iter]);
                } else {
                    getTheme(themeName).put(keys[iter], values[iter]);
                }
            }
            return themeName;
        }

        @Override
        protected String performUndo() {
            for (int iter = 0; iter < keys.length; iter++) {
                if (oldValues[iter] == null) {
                    getTheme(themeName).remove(keys[iter]);
                } else {
                    getTheme(themeName).put(keys[iter], oldValues[iter]);
                }
            }
            return themeName;
        }
    });
}
Also used : Hashtable(java.util.Hashtable) AnimationObject(com.codename1.ui.animations.AnimationObject)

Example 43 with Property

use of com.codename1.rad.models.Property in project CodenameOne by codenameone.

the class CN1BuildMojo method mergeRequiredProperties.

private SortedProperties mergeRequiredProperties(String libraryName, Properties libProps, Properties projectProps) throws LibraryPropertiesException {
    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 VersionMismatchException(libraryName, "Cannot use a cn1lib with java version " + "greater then the project java version");
        }
    }
    // merge and save
    SortedProperties merged = new SortedProperties();
    merged.putAll(projectProps);
    Enumeration keys = libProps.propertyNames();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        if (!merged.containsKey(key)) {
            merged.put(key, libProps.getProperty(key));
        } else {
            // install will fail
            if (!merged.get(key).equals(libProps.getProperty(key))) {
                throw new PropertyConflictException(libraryName, "Property " + key + " has a conflict");
            }
        }
    }
    return merged;
}
Also used : SortedProperties(com.codename1.ant.SortedProperties)

Example 44 with Property

use of com.codename1.rad.models.Property in project CodenameOne by codenameone.

the class GenerateArchetypeFromTemplateMojo method generateBaseArchetype.

private File generateBaseArchetype(String string, File templateFile) throws TemplateParseException, IOException {
    Dependency out = new Dependency();
    String archetype = extractSectionFrom(string, "archetype");
    Properties props = new Properties();
    props.load(new StringReader(archetype));
    String[] requiredProperties = new String[] { "artifactId", "groupId", "version" };
    for (String key : requiredProperties) {
        if (!props.containsKey(key)) {
            throw new TemplateParseException("archetype property " + key + " required and missing.  Make sure it is defined in the [archetype] section of the template");
        }
    }
    File dest = new File(outputDir, props.getProperty("artifactId"));
    if (dest.exists()) {
        if (overwrite) {
            FileUtils.deleteDirectory(dest);
        } else {
            throw new IOException("Project already exists at " + dest + ".  Delete this project before regenerating");
        }
    }
    String base = props.getProperty("extends", null);
    if (base == null) {
        throw new TemplateParseException("[archetype] section requires the 'extends' property to specify the path to the archetype project that this extends");
    }
    baseArchetypeDir = new File(base);
    if (!baseArchetypeDir.isAbsolute()) {
        baseArchetypeDir = new File(templateFile.getParentFile(), base);
    }
    if (!baseArchetypeDir.exists()) {
        throw new IOException("Cannot find archetype project that this template extends.  Looking for it in " + baseArchetypeDir);
    }
    if (!new File(baseArchetypeDir, "pom.xml").exists()) {
        throw new IOException("Base archetype directory " + baseArchetypeDir + " is not a maven project.");
    }
    FileUtils.copyDirectory(baseArchetypeDir, dest);
    File pomFile = new File(dest, "pom.xml");
    String groupId = null;
    String artifactId = null;
    String version = null;
    if (props.containsKey("id")) {
        String id = props.getProperty("id");
        String[] parts = id.split(":");
        if (parts.length != 3) {
            throw new TemplateParseException("Failed ot parse id property in [archetype] section.  It should be in the format groupId:artifactId:version");
        }
        groupId = parts[0];
        artifactId = parts[1];
        version = parts[2];
    }
    groupId = props.getProperty("groupId", groupId);
    artifactId = props.getProperty("artifactId", artifactId);
    version = props.getProperty("version", version);
    if (groupId == null || artifactId == null || version == null) {
        throw new TemplateParseException("The [archetype] section is required, and must have at least groupId, artifactId, and version defined.  You may also define these using the id property in the format groupId:artifactId:version");
    }
    String parentTag = "";
    String parentGroupId = null;
    String parentArtifactId = null;
    String parentVersion = null;
    if (props.containsKey("parent")) {
        String parent = props.getProperty("parent");
        String[] parts = parent.split(":");
        if (parts.length != 3) {
            throw new TemplateParseException("Failed to parse parent property in [archetype] section. It should be in the format groupId:artifactId:version");
        }
        parentGroupId = parts[0];
        parentArtifactId = parts[1];
        parentVersion = parts[2];
    }
    parentGroupId = props.getProperty("parentGroupId", parentGroupId);
    parentArtifactId = props.getProperty("parentArtifactId", parentArtifactId);
    parentVersion = props.getProperty("parentVersion", parentVersion);
    if (parentGroupId != null && parentVersion != null && parentArtifactId != null) {
        parentTag = "  <parent>\n" + "    <groupId>" + parentGroupId + "</groupId>\n" + "    <artifactId>" + parentArtifactId + "</artifactId>\n" + "    <version>" + parentVersion + "</version>\n" + "  </parent>\n";
    }
    String pomContents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" + "  <modelVersion>4.0.0</modelVersion>\n" + parentTag + "  <groupId>" + groupId + "</groupId>\n" + "  <artifactId>" + artifactId + "</artifactId>\n" + "  <version>" + version + "</version>\n" + "  <packaging>maven-archetype</packaging>\n" + "\n" + "  <name>" + artifactId + "</name>\n" + "\n" + "\n" + "  <build>\n" + "    <extensions>\n" + "      <extension>\n" + "        <groupId>org.apache.maven.archetype</groupId>\n" + "        <artifactId>archetype-packaging</artifactId>\n" + "        <version>3.2.0</version>\n" + "      </extension>\n" + "    </extensions>\n" + "\n" + "    <pluginManagement>\n" + "      <plugins>\n" + "        <plugin>\n" + "          <artifactId>maven-archetype-plugin</artifactId>\n" + "          <version>3.2.0</version>\n" + "        </plugin>\n" + "      </plugins>\n" + "    </pluginManagement>\n" + "  </build>\n" + "\n" + "  <description>Artifact generated using the cn1:generate-archetype goal</description>\n" + "\n" + "  <url>https://www.codenameone.com</url>\n" + "\n" + "  <licenses>\n" + "    <license>\n" + "      <name>GPL v2 With Classpath Exception</name>\n" + "      <url>https://openjdk.java.net/legal/gplv2+ce.html</url>\n" + "      <distribution>repo</distribution>\n" + "      <comments>A business-friendly OSS license</comments>\n" + "    </license>\n" + "  </licenses>\n" + "</project>\n";
    FileUtils.writeStringToFile(pomFile, pomContents, "UTF-8");
    return dest;
}
Also used : Dependency(org.apache.maven.model.Dependency) SortedProperties(com.codename1.ant.SortedProperties)

Example 45 with Property

use of com.codename1.rad.models.Property 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

Entity (com.codename1.rad.models.Entity)22 Property (com.codename1.rad.models.Property)16 IOException (java.io.IOException)11 ResultParser (com.codename1.rad.io.ResultParser)10 ArrayList (java.util.ArrayList)10 SimpleDateFormat (com.codename1.l10n.SimpleDateFormat)9 Component (com.codename1.ui.Component)9 Element (com.codename1.xml.Element)8 ParseException (com.codename1.l10n.ParseException)7 Container (com.codename1.ui.Container)7 Label (com.codename1.ui.Label)7 SortedProperties (com.codename1.ant.SortedProperties)6 Log (com.codename1.io.Log)6 Form (com.codename1.ui.Form)6 AnimationObject (com.codename1.ui.animations.AnimationObject)6 Map (java.util.Map)6 Thing (com.codename1.rad.schemas.Thing)5 XMLParser (com.codename1.xml.XMLParser)5 StringReader (java.io.StringReader)5 List (java.util.List)5