in nbm-maven-plugin/src/main/java/org/apache/netbeans/nbm/BrandingMojo.java [99:173]
public void execute()
throws MojoExecutionException {
if (!"nbm".equals(project.getPackaging())) {
getLog().error("The nbm:branding goal shall be used within a NetBeans module project only (packaging 'nbm')");
}
if (!brandingSources.isDirectory()) {
getLog().info("No branding to process.");
return;
}
if (brandingToken == null) {
throw new MojoExecutionException("brandingToken must be defined for mojo:branding");
}
try {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setIncludes(new String[]{
"**/*.*"
});
scanner.addDefaultExcludes();
scanner.setBasedir(brandingSources);
scanner.scan();
final String clusterPathPart = "clusters" + File.separator + cluster;
File outputDir = new File(outputDirectory, "branding_and_locales");
outputDir.mkdirs();
File clusterDir = new File(nbmBuildDir, clusterPathPart);
clusterDir.mkdirs();
// copy all files and see to it that they get the correct names
for (String brandingFilePath : scanner.getIncludedFiles()) {
File brandingFile = new File(brandingSources, brandingFilePath);
String[] locale = getLocale(brandingFile.getName());
String token = locale[1] == null ? brandingToken : brandingToken + "_" + locale[1];
File root = new File(outputDir, token);
root.mkdirs();
String destinationName = locale[0] + "_" + token + locale[2];
File brandingDestination = new File(root, brandingFilePath.replace(brandingFile.getName(),
destinationName));
if (!brandingDestination.getParentFile().exists()) {
brandingDestination.getParentFile().mkdirs();
}
FileUtils.copyFile(brandingFile, brandingDestination);
}
for (File rootDir : outputDir.listFiles()) {
if (!rootDir.isDirectory()) {
continue;
}
String effectiveBranding = rootDir.getName();
// create jar-files from each toplevel .jar directory
scanner.setIncludes(new String[]{"**/*.jar"});
scanner.setBasedir(rootDir);
scanner.scan();
for (String jarDirectoryPath : scanner.getIncludedDirectories()) {
// move nnn.jar directory to nnn.jar.tmp
File jarDirectory = new File(rootDir, jarDirectoryPath);
File destinationLocation = new File(clusterDir, jarDirectoryPath).getParentFile();
destinationLocation.mkdirs();
// jars should be placed in locales/ under the same directory the jar-directories are
File destinationJar
= new File(destinationLocation + File.separator + "locale"
+ File.separator
+ destinationFileName(jarDirectory.getName(), effectiveBranding));
// create nnn.jar archive of contents
JarArchiver archiver = new JarArchiver();
archiver.setDestFile(destinationJar);
archiver.addDirectory(jarDirectory);
archiver.createArchive();
}
}
} catch (IOException | IllegalStateException | ArchiverException ex) {
throw new MojoExecutionException("Error creating branding", ex);
}
}