in nbm-maven-plugin/src/main/java/org/apache/netbeans/nbm/BuildInstallersMojo.java [168:308]
public void execute() throws MojoExecutionException, MojoFailureException {
Project antProject = antProject();
if (!"nbm-application".equals(project.getPackaging())) {
throw new MojoExecutionException(
"This goal only makes sense on project with 'nbm-application' packaging.");
}
if (!installerOsLinux && !installerOsMacosx && !installerOsSolaris && !installerOsWindows) {
getLog().warn("None of the Operating System Installers selected, skipping 'build-installers' goal.");
return;
}
String zipName = finalName + ".zip";
File zipFile = new File(outputDirectory, zipName);
getLog().info(String.format("Running Build Installers action for (existing=%2$s) zip file %1$s",
zipFile, zipFile.exists()));
File appIconIcnsFile;
// Copy Netbeans Installer resources
FileUrlUtils fu = new FileUrlUtils();
File harnessDir = new File(outputDirectory, "installer");
fu.copyResourcesRecursively(getClass().getClassLoader().getResource("harness"), harnessDir);
// Overwrite template file with modified version to accept branded images etc.
if (templateFile != null) {
File template = new File(harnessDir, "nbi/stub/template.xml");
fu.copyFile(templateFile, template);
}
appIconIcnsFile = new File(harnessDir, "etc" + File.separatorChar + "applicationIcon.icns");
getLog().info("Application icon:" + appIconIcnsFile.getAbsolutePath());
Map<String, String> props = new HashMap<>();
props.put("suite.location", basedir.getAbsolutePath().replace("\\", "/"));
props.put("suite.props.app.name", brandingToken);
props.put("suite.dist.zip", zipFile.getAbsolutePath().replace("\\", "/"));
props.put("suite.dist.directory", outputDirectory.getAbsolutePath().replace("\\", "/"));
props.put("installer.build.dir", new File(outputDirectory, "installerbuild").getAbsolutePath().replace("\\", "/"));
props.put("installers.file.prefix", installersFilePrefix);
// props.put( "install.dir.name", installDirName );
//mkleint: this is a flawed pattern! cannot make any assumption on multimodule layout
String appName = project.getParent().getArtifactId().replace(".", "").replace("-", "").replace("_", "").replaceAll("[0-9]+", "");
props.put("suite.nbi.product.uid", appName.toLowerCase(Locale.ENGLISH));
props.put("suite.props.app.title", (project.getName() + " " + project.getVersion()).replaceAll("-SNAPSHOT", ""));
String appVersion = project.getVersion().replaceAll("-SNAPSHOT", "");
props.put("suite.nbi.product.version.short", appVersion);
while (appVersion.split("\\.").length < 5) {
appVersion += ".0";
}
props.put("suite.nbi.product.version", appVersion);
props.put("nbi.stub.location", new File(harnessDir, "nbi/stub").getAbsolutePath().replace("\\", "/"));
props.put("nbi.stub.common.location", new File(harnessDir, "nbi/.common").getAbsolutePath().replace("\\", "/"));
props.put("nbi.ant.tasks.jar", new File(harnessDir, "modules/ext/nbi-ant-tasks.jar").getAbsolutePath().replace("\\", "/"));
props.put("nbi.registries.management.jar", new File(harnessDir, "modules/ext/nbi-registries-management.jar").getAbsolutePath().replace("\\", "/"));
props.put("nbi.engine.jar", new File(harnessDir, "modules/ext/nbi-engine.jar").getAbsolutePath().replace("\\", "/"));
if (installerLicenseFile != null) {
getLog().info(String.format("License file is at %1s, exist = %2$s", installerLicenseFile,
installerLicenseFile.exists()));
//mkleint: no path replacement here??
props.put("nbi.license.file", installerLicenseFile.getAbsolutePath());
}
List<String> platforms = new ArrayList<>();
if (this.installerOsLinux) {
platforms.add("linux");
File linuxFile = new File(outputDirectory, installersFilePrefix + "-linux.sh");
projectHelper.attachArtifact(project, "sh", "linux", linuxFile);
}
if (this.installerOsSolaris) {
platforms.add("solaris");
File solarisFile = new File(outputDirectory, installersFilePrefix + "-solaris.sh");
projectHelper.attachArtifact(project, "sh", "solaris", solarisFile);
}
if (this.installerOsWindows) {
platforms.add("windows");
File windowsFile = new File(outputDirectory, installersFilePrefix + "-windows.exe");
projectHelper.attachArtifact(project, "exe", "windows", windowsFile);
}
if (this.installerOsMacosx) {
platforms.add("macosx");
File macosxFile = new File(outputDirectory, installersFilePrefix + "-macosx.tgz");
projectHelper.attachArtifact(project, "tgz", "macosx", macosxFile);
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < platforms.size(); i++) {
if (i != 0) {
sb.append(" ");
}
sb.append(platforms.get(i));
}
if (sb.length() == 0) {
//nothing to build
getLog().warn("Nothing to build.");
}
props.put("generate.installer.for.platforms", sb.toString());
File javaHome = new File(System.getProperty("java.home"));
//mkleint: does this work on mac? no rt.jar there
if (new File(javaHome, "lib/rt.jar").exists() && javaHome.getName().equals("jre")) {
javaHome = javaHome.getParentFile();
}
props.put("generator-jdk-location-forward-slashes", javaHome.getAbsolutePath().replace("\\", "/"));
props.put("pack200.enabled", "" + installerPack200Enable);
props.put("nbi.dock.icon.file", appIconIcnsFile.getAbsolutePath());
try {
antProject.setUserProperty("ant.file", new File(harnessDir, "nbi/stub/template.xml").getAbsolutePath().replace("\\", "/"));
ProjectHelper helper = ProjectHelper.getProjectHelper();
antProject.addReference("ant.projectHelper", helper);
helper.parse(antProject, new File(harnessDir, "nbi/stub/template.xml"));
for (Map.Entry<String, String> e : props.entrySet()) {
antProject.setProperty(e.getKey(), e.getValue());
}
if (userSettings != null) {
for (Map.Entry<String, String> e : userSettings.entrySet()) {
antProject.setProperty(e.getKey(), e.getValue());
}
}
antProject.executeTarget("build");
} catch (BuildException ex) {
throw new MojoExecutionException("Installers creation failed: " + ex, ex);
}
}