in nbm-maven-plugin/src/main/java/org/apache/netbeans/nbm/CreateClusterAppMojo.java [613:739]
private void createBinEtcDir(File buildDir, String brandingToken) throws IOException, MojoExecutionException {
File etcDir = new File(buildDir + File.separator + "etc");
etcDir.mkdir();
// create app.clusters which contains a list of clusters to include in the application
File clusterConf = new File(etcDir + File.separator + brandingToken + ".clusters");
String clustersString;
if (etcClustersFile != null) {
clustersString = FileUtils.fileRead(etcClustersFile, "UTF-8");
} else {
clusterConf.createNewFile();
StringBuilder buffer = new StringBuilder();
File[] clusters = buildDir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return new File(pathname, ".lastModified").exists();
}
});
for (File cluster : clusters) {
buffer.append(cluster.getName());
buffer.append("\n");
}
clustersString = buffer.toString();
}
FileUtils.fileWrite(clusterConf.getAbsolutePath(), clustersString);
File confFile = etcConfFile;
String str;
if (confFile == null) {
File harnessDir = new File(buildDir, "harness");
// app.conf contains default options and other settings
confFile = new File(
harnessDir.getAbsolutePath() + File.separator + "etc" + File.separator + "app.conf");
if (confFile.exists()) {
str = FileUtils.fileRead(confFile, "UTF-8");
} else {
getLog().debug("Using fallback app.conf shipping with the nbm-maven-plugin.");
try (InputStream instream = getClass().getClassLoader().getResourceAsStream("harness/etc/app.conf")) {
str = IOUtil.toString(instream, "UTF-8");
}
}
} else {
str = FileUtils.fileRead(confFile, "UTF-8");
}
File confDestFile = new File(
etcDir.getAbsolutePath() + File.separator + brandingToken + ".conf");
str = str.replace("${branding.token}", brandingToken);
FileUtils.fileWrite(confDestFile.getAbsolutePath(), "UTF-8", str);
File destBinDir = new File(buildDir + File.separator + "bin");
destBinDir.mkdir();
File binDir;
File destExeW = new File(destBinDir, brandingToken + "_w.exe");
File destExe = new File(destBinDir, brandingToken + ".exe");
File destExe64 = new File(destBinDir, brandingToken + "64.exe");
File destSh = new File(destBinDir, brandingToken);
File harnessDir = new File(buildDir, "harness");
//we have org-netbeans-modules-apisupport-harness in target area, just use it's own launchers.
binDir = new File(harnessDir.getAbsolutePath() + File.separator + "launchers");
if (binDir.exists()) {
File exe = new File(binDir, "app.exe");
FileUtils.copyFile(exe, destExe);
File exe64 = new File(binDir, "app64.exe");
if (exe64.isFile()) {
FileUtils.copyFile(exe64, destExe64);
}
File exew = new File(binDir, "app_w.exe");
if (exew.exists()) //in 6.7 the _w.exe file is no more.
{
FileUtils.copyFile(exew, destExeW);
}
File sh = new File(binDir, "app.sh");
FileUtils.copyFile(sh, destSh);
} else {
File nbm = getHarnessNbm();
try (ZipFile zip = new ZipFile(nbm)) {
getLog().debug("Using fallback executables from downloaded org-netbeans-modules-apisupport-harness nbm file.");
writeFromZip(zip, "netbeans/launchers/app.sh", destSh, true);
writeFromZip(zip, "netbeans/launchers/app.exe", destExe, true);
writeFromZip(zip, "netbeans/launchers/app64.exe", destExe64, false);
writeFromZip(zip, "netbeans/launchers/app_w.exe", destExeW, false);
}
}
if (binDirectory != null) {
//we have custom launchers, only overwrite the ones the user provided.
binDir = binDirectory;
File[] fls = binDir.listFiles();
if (fls == null) {
throw new MojoExecutionException("Parameter 'binDirectory' has to point to an existing folder.");
}
for (File fl : fls) {
String name = fl.getName();
File dest = null;
if (name.endsWith("_w.exe")) {
dest = destExeW;
} else if (name.endsWith("64.exe")) {
dest = destExe64;
} else if (name.endsWith(".exe")) {
dest = destExe;
} else if (!name.contains(".") || name.endsWith(".sh")) {
dest = destSh;
}
if (dest != null && fl.exists()) //in 6.7 the _w.exe file is no more.
{
FileUtils.copyFile(fl, dest);
} else {
//warn about file not being copied
}
}
}
Project antProject = antProject();
Chmod chmod = (Chmod) antProject.createTask("chmod");
FileSet fs = new FileSet();
fs.setDir(destBinDir);
fs.setIncludes("*");
chmod.addFileset(fs);
chmod.setPerm("755");
chmod.execute();
}