Search in sources :

Example 1 with PropertyClassGenerator

use of net.jangaroo.properties.PropertyClassGenerator in project jangaroo-tools by CoreMedia.

the class PropertiesMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (!generatedSourcesDirectory.exists()) {
        getLog().info("generating sources into: " + generatedSourcesDirectory.getPath());
        getLog().debug("created " + generatedSourcesDirectory.mkdirs());
    }
    if (properties == null) {
        properties = new FileSet();
        properties.setDirectory(resourceDirectory.getAbsolutePath());
        properties.addInclude("**/*.properties");
    }
    FileLocations config = new FileLocations();
    config.setOutputDirectory(generatedSourcesDirectory);
    for (String srcFileRelativePath : new FileSetManager().getIncludedFiles(properties)) {
        config.addSourceFile(new File(resourceDirectory, srcFileRelativePath));
    }
    try {
        config.setSourcePath(Arrays.asList(resourceDirectory));
    } catch (IOException e) {
        throw new MojoExecutionException("configuration failure", e);
    }
    PropertyClassGenerator generator = new PropertyClassGenerator(config);
    try {
        generator.generate();
    } catch (PropcException e) {
        throw new MojoExecutionException("Generation failure", e);
    }
}
Also used : FileSet(org.apache.maven.shared.model.fileset.FileSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) PropertyClassGenerator(net.jangaroo.properties.PropertyClassGenerator) PropcException(net.jangaroo.properties.api.PropcException) IOException(java.io.IOException) File(java.io.File) FileLocations(net.jangaroo.utils.FileLocations) FileSetManager(org.apache.maven.shared.model.fileset.util.FileSetManager)

Example 2 with PropertyClassGenerator

use of net.jangaroo.properties.PropertyClassGenerator in project jangaroo-tools by CoreMedia.

the class PropertiesCompiler method run.

public static int run(String[] args) {
    FileLocations config = new FileLocations();
    CmdLineParser parser = new CmdLineParser(config);
    try {
        // parse the arguments.
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        StringBuilder msg = new StringBuilder();
        // if there's a problem in the command line,
        // you'll get this exception. this will report
        // an error message.
        msg.append(e.getMessage());
        msg.append("\n");
        msg.append("java -jar properties-compiler.jar [options...] source files...\n");
        // print the list of available options
        StringWriter writer = new StringWriter();
        parser.printUsage(writer, null);
        msg.append(writer.getBuffer());
        msg.append("\n");
        // print option sample. This is useful some time
        msg.append("  Example: java -jar properties-compiler.jar").append(parser.printExample(REQUIRED));
        msg.append("\n");
        // NOSONAR this is a commandline tool
        System.err.println(msg);
        return -1;
    }
    if (!config.getOutputDirectory().exists()) {
        throw new IllegalArgumentException("destination directory does not exist: " + config.getOutputDirectory().getAbsolutePath());
    }
    PropertyClassGenerator generator = new PropertyClassGenerator(config);
    generator.generate();
    return 0;
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) StringWriter(java.io.StringWriter) PropertyClassGenerator(net.jangaroo.properties.PropertyClassGenerator) FileLocations(net.jangaroo.utils.FileLocations) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 3 with PropertyClassGenerator

use of net.jangaroo.properties.PropertyClassGenerator in project jangaroo-tools by CoreMedia.

the class PropertyClassGeneratorTest method testSimplePropertySet.

@Test
public void testSimplePropertySet() throws Exception {
    FileLocations locations = new FileLocations();
    List<File> sourcePath = new ArrayList<File>();
    sourcePath.add(new File(getClass().getResource("/").toURI()));
    locations.setSourcePath(sourcePath);
    locations.addSourceFile("testPackage/subPackage/Properties.properties");
    locations.addSourceFile("testPackage/PropertiesTest.properties");
    locations.addSourceFile("testPackage/PropertiesTest_de.properties");
    locations.addSourceFile("testPackage/PropertiesTest_es_ES.properties");
    locations.addSourceFile("testPackage/PropertiesTest_it_VA_WIN.properties");
    PropertyClassGenerator generator = new PropertyClassGenerator(locations);
    StringWriter writer = new StringWriter();
    ResourceBundleClass rbc = new ResourceBundleClass("testPackage.PropertiesTest");
    PropertiesConfiguration p = new PropertiesConfiguration();
    p.setProperty("key", "Die Platte \"{1}\" enthält {0}.");
    p.setProperty("key2", "Die Platte \"{1}\" enthält {0}.");
    PropertiesClass pc = new PropertiesClass(rbc, null, p, null);
    generator.generatePropertiesClass(pc, writer);
    assertEquals(("package testPackage {\n" + "import joo.ResourceBundleAwareClassLoader;\n" + "import joo.JavaScriptObject;\n" + "\n" + "/**\n" + " * Properties class for ResourceBundle \"PropertiesTest\".\n" + " * @see PropertiesTest_properties#INSTANCE\n" + " */\n" + "[ResourceBundle('PropertiesTest')]\n" + "public class PropertiesTest_properties extends joo.JavaScriptObject {\n" + "\n" + "/**\n" + " * Singleton for the current user Locale's instance of ResourceBundle \"PropertiesTest\".\n" + " * @see PropertiesTest_properties\n" + " */\n" + "public static const INSTANCE:PropertiesTest_properties = ResourceBundleAwareClassLoader.INSTANCE.createSingleton(PropertiesTest_properties) as PropertiesTest_properties;\n" + "\n" + "[Resource(key='key',bundle='PropertiesTest')]\n" + "public native function get key():String;\n" + "[Resource(key='key2',bundle='PropertiesTest')]\n" + "public native function get key2():String;\n" + "\n" + "public function PropertiesTest_properties() {\n" + "  this[\"key\"] = \"Die Platte \\\"{1}\\\" enthält {0}.\";\n" + "  this[\"key2\"] = \"Die Platte \\\"{1}\\\" enthält {0}.\";\n" + "}\n" + "}\n" + "}").replaceAll("\n", LINE_SEPARATOR), writer.toString());
    PropertiesClass psc = new PropertiesClass(rbc, Locale.ENGLISH, p, null);
    writer = new StringWriter();
    generator.generatePropertiesClass(psc, writer);
    assertEquals(("package testPackage {\n" + "\n" + "/**\n" + " * Properties class for ResourceBundle \"PropertiesTest\" and Locale \"en\".\n" + " * @see PropertiesTest_properties#INSTANCE\n" + " */\n" + "[ResourceBundle('PropertiesTest_en')]\n" + "public class PropertiesTest_properties_en extends PropertiesTest_properties {\n" + "\n" + "\n" + "public function PropertiesTest_properties_en() {\n" + "  this[\"key\"] = \"Die Platte \\\"{1}\\\" enthält {0}.\";\n" + "  this[\"key2\"] = \"Die Platte \\\"{1}\\\" enthält {0}.\";\n" + "}\n" + "}\n" + "}").replaceAll("\n", LINE_SEPARATOR), writer.toString());
}
Also used : StringWriter(java.io.StringWriter) ResourceBundleClass(net.jangaroo.properties.model.ResourceBundleClass) ArrayList(java.util.ArrayList) PropertyClassGenerator(net.jangaroo.properties.PropertyClassGenerator) PropertiesClass(net.jangaroo.properties.model.PropertiesClass) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) FileLocations(net.jangaroo.utils.FileLocations) Test(org.junit.Test)

Aggregations

PropertyClassGenerator (net.jangaroo.properties.PropertyClassGenerator)3 FileLocations (net.jangaroo.utils.FileLocations)3 File (java.io.File)2 StringWriter (java.io.StringWriter)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 PropcException (net.jangaroo.properties.api.PropcException)1 PropertiesClass (net.jangaroo.properties.model.PropertiesClass)1 ResourceBundleClass (net.jangaroo.properties.model.ResourceBundleClass)1 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 FileSet (org.apache.maven.shared.model.fileset.FileSet)1 FileSetManager (org.apache.maven.shared.model.fileset.util.FileSetManager)1 Test (org.junit.Test)1 CmdLineException (org.kohsuke.args4j.CmdLineException)1 CmdLineParser (org.kohsuke.args4j.CmdLineParser)1