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);
}
}
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) {
//
}
}
}
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));
}
Aggregations