use of sh.tak.appbundler.logging.MojoLogChute in project appbundle-maven-plugin by federkasten.
the class CreateApplicationBundleMojo method writeInfoPlist.
/**
* Writes an Info.plist file describing this bundle.
*
* @param infoPlist The file to write Info.plist contents to
* @param files A list of file names of the jar files to add in $JAVAROOT
* @throws MojoExecutionException
*/
private void writeInfoPlist(File infoPlist, List<String> files) throws MojoExecutionException {
Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, new MojoLogChute(this));
Velocity.setProperty("file.resource.loader.path", TARGET_CLASS_ROOT);
try {
Velocity.init();
} catch (Exception ex) {
throw new MojoExecutionException("Exception occured in initializing velocity", ex);
}
VelocityContext velocityContext = new VelocityContext();
velocityContext.put("mainClass", mainClass);
velocityContext.put("cfBundleExecutable", javaLauncherName);
velocityContext.put("bundleName", cleanBundleName(bundleName));
velocityContext.put("workingDirectory", workingDirectory);
if (embeddJre && jrePath != null) {
velocityContext.put("jrePath", "JRE");
velocityContext.put("jreFullPath", "");
} else if (embeddJre && jreFullPath != null) {
velocityContext.put("jrePath", "");
velocityContext.put("jreFullPath", jreFullPath);
} else {
velocityContext.put("jrePath", "");
velocityContext.put("jreFullPath", "");
}
if (iconFile == null) {
velocityContext.put("iconFile", "GenericJavaApp.icns");
} else {
File f = searchFile(iconFile, project.getBasedir());
velocityContext.put("iconFile", (f != null && f.exists() && f.isFile()) ? f.getName() : "GenericJavaApp.icns");
}
velocityContext.put("version", version);
velocityContext.put("jvmVersion", jvmVersion);
StringBuilder options = new StringBuilder();
options.append("<array>").append("\n ");
for (String jvmOption : defaultJvmOptions) {
options.append(" ").append("<string>").append(jvmOption).append("</string>").append("\n");
}
options.append(" ").append("<string>").append("-Xdock:name=" + bundleName).append("</string>").append("\n");
if (jvmOptions != null) {
for (String jvmOption : jvmOptions) {
options.append(" ").append("<string>").append(jvmOption).append("</string>").append("\n");
}
}
options.append(" ").append("</array>");
velocityContext.put("jvmOptions", options);
StringBuilder jarFiles = new StringBuilder();
jarFiles.append("<array>").append("\n");
for (String file : files) {
jarFiles.append(" ").append("<string>").append(file).append("</string>").append("\n");
}
if (additionalClasspath != null) {
for (String pathElement : additionalClasspath) {
jarFiles.append(" ").append("<string>").append(pathElement).append("</string>");
}
}
jarFiles.append(" ").append("</array>");
velocityContext.put("classpath", jarFiles.toString());
try {
File sourceInfoPlist = new File(TARGET_CLASS_ROOT, dictionaryFile);
if (sourceInfoPlist.exists() && sourceInfoPlist.isFile()) {
String encoding = detectEncoding(sourceInfoPlist);
getLog().debug("Detected encoding " + encoding + " for dictionary file " + dictionaryFile);
Writer writer = new OutputStreamWriter(new FileOutputStream(infoPlist), encoding);
Template template = Velocity.getTemplate(dictionaryFile, encoding);
template.merge(velocityContext, writer);
writer.close();
} else {
Writer writer = new OutputStreamWriter(new FileOutputStream(infoPlist), "UTF-8");
velocity.getEngine().mergeTemplate(dictionaryFile, "UTF-8", velocityContext, writer);
writer.close();
}
} catch (IOException ex) {
throw new MojoExecutionException("Could not write Info.plist to file " + infoPlist, ex);
} catch (ParseErrorException ex) {
throw new MojoExecutionException("Error parsing " + dictionaryFile, ex);
} catch (ResourceNotFoundException ex) {
throw new MojoExecutionException("Could not find resource for template " + dictionaryFile, ex);
} catch (MethodInvocationException ex) {
throw new MojoExecutionException("MethodInvocationException occured merging Info.plist template " + dictionaryFile, ex);
} catch (Exception ex) {
throw new MojoExecutionException("Exception occured merging Info.plist template " + dictionaryFile, ex);
}
}
Aggregations