Search in sources :

Example 1 with PropcException

use of net.jangaroo.properties.api.PropcException 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 PropcException

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

the class PropertyClassGenerator method generateJangarooClass.

public File generateJangarooClass(PropertiesClass pl) {
    File outputFile = PropcHelper.computeGeneratedPropertiesClassFile(locations, pl.getResourceBundle().getFullClassName(), pl.getLocale());
    // noinspection ResultOfMethodCallIgnored
    // NOSONAR
    outputFile.getParentFile().mkdirs();
    Writer writer = null;
    try {
        writer = new OutputStreamWriter(new FileOutputStream(outputFile), OUTPUT_CHARSET);
        generatePropertiesClass(pl, writer);
        return outputFile;
    } catch (Exception e) {
        throw new PropcException(e);
    } finally {
        try {
            if (writer != null) {
                writer.close();
            }
        } catch (IOException e) {
        // 
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) PropcException(net.jangaroo.properties.api.PropcException) IOException(java.io.IOException) File(java.io.File) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) PropcException(net.jangaroo.properties.api.PropcException) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Example 3 with PropcException

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

the class PropertyClassGenerator method generate.

@Override
public File generate(File propertiesFile) {
    PropertiesConfiguration p = new PropertiesConfiguration();
    p.setDelimiterParsingDisabled(true);
    Reader r = null;
    try {
        r = new BufferedReader(new InputStreamReader(new FileInputStream(propertiesFile), "UTF-8"));
        p.load(r);
    } catch (IOException e) {
        throw new PropcException("Error while parsing properties file", propertiesFile, e);
    } catch (ConfigurationException e) {
        throw new PropcException("Error while parsing properties file", propertiesFile, e);
    } finally {
        try {
            if (r != null) {
                r.close();
            }
        } catch (IOException e) {
        // not really
        }
    }
    ResourceBundleClass bundle = new ResourceBundleClass(PropcHelper.computeBaseClassName(locations, propertiesFile));
    // Create properties class, which registers itself with the bundle.
    return generateJangarooClass(new PropertiesClass(bundle, PropcHelper.computeLocale(propertiesFile), p, propertiesFile));
}
Also used : InputStreamReader(java.io.InputStreamReader) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ResourceBundleClass(net.jangaroo.properties.model.ResourceBundleClass) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) PropcException(net.jangaroo.properties.api.PropcException) PropertiesClass(net.jangaroo.properties.model.PropertiesClass) IOException(java.io.IOException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) FileInputStream(java.io.FileInputStream)

Aggregations

IOException (java.io.IOException)3 PropcException (net.jangaroo.properties.api.PropcException)3 File (java.io.File)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 TemplateException (freemarker.template.TemplateException)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Reader (java.io.Reader)1 Writer (java.io.Writer)1 PropertyClassGenerator (net.jangaroo.properties.PropertyClassGenerator)1 PropertiesClass (net.jangaroo.properties.model.PropertiesClass)1 ResourceBundleClass (net.jangaroo.properties.model.ResourceBundleClass)1 FileLocations (net.jangaroo.utils.FileLocations)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