use of org.eclipse.jetty.start.builders.StartDirBuilder in project jetty.project by eclipse.
the class BaseBuilder method build.
/**
* Build out the Base directory (if needed)
*
* @return true if base directory was changed, false if left unchanged.
* @throws IOException if unable to build
*/
public boolean build() throws IOException {
Modules modules = startArgs.getAllModules();
// Select all the added modules to determine which ones are newly enabled
Set<String> newly_added = new HashSet<>();
if (!startArgs.getStartModules().isEmpty()) {
for (String name : startArgs.getStartModules()) {
newly_added.addAll(modules.enable(name, "--add-to-start"));
if (!newly_added.contains(name)) {
Set<String> sources = modules.get(name).getEnableSources();
sources.remove("--add-to-start");
StartLog.info("%s already enabled by %s", name, sources);
}
}
}
if (StartLog.isDebugEnabled())
StartLog.debug("added=%s", newly_added);
// Check the licenses
if (startArgs.isLicenseCheckRequired()) {
Licensing licensing = new Licensing();
for (String name : newly_added) licensing.addModule(modules.get(name));
if (licensing.hasLicenses()) {
if (startArgs.isApproveAllLicenses()) {
StartLog.info("All Licenses Approved via Command Line Option");
} else if (!licensing.acknowledgeLicenses()) {
StartLog.warn(EXITING_LICENSE_NOT_ACKNOWLEDGED);
System.exit(1);
}
}
}
// generate the files
List<FileArg> files = new ArrayList<FileArg>();
AtomicReference<BaseBuilder.Config> builder = new AtomicReference<>();
AtomicBoolean modified = new AtomicBoolean();
Path startd = getBaseHome().getBasePath("start.d");
Path startini = getBaseHome().getBasePath("start.ini");
if (startArgs.isCreateStartd() && !Files.exists(startd)) {
if (FS.ensureDirectoryExists(startd)) {
StartLog.log("MKDIR", baseHome.toShortForm(startd));
modified.set(true);
}
if (Files.exists(startini)) {
int ini = 0;
Path startd_startini = startd.resolve("start.ini");
while (Files.exists(startd_startini)) {
ini++;
startd_startini = startd.resolve("start" + ini + ".ini");
}
Files.move(startini, startd_startini);
modified.set(true);
}
}
if (!newly_added.isEmpty()) {
if (Files.exists(startini) && Files.exists(startd))
StartLog.warn("Use both %s and %s is deprecated", getBaseHome().toShortForm(startd), getBaseHome().toShortForm(startini));
boolean useStartD = Files.exists(startd);
builder.set(useStartD ? new StartDirBuilder(this) : new StartIniBuilder(this));
newly_added.stream().map(n -> modules.get(n)).forEach(module -> {
String ini = null;
try {
if (module.isSkipFilesValidation()) {
StartLog.debug("Skipping [files] validation on %s", module.getName());
} else {
if (startArgs.getStartModules().contains(module.getName())) {
ini = builder.get().addModule(module, startArgs.getProperties());
if (ini != null)
modified.set(true);
}
for (String file : module.getFiles()) files.add(new FileArg(module, startArgs.getProperties().expand(file)));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
if (module.isDynamic()) {
for (String s : module.getEnableSources()) StartLog.info("%-15s %s", module.getName(), s);
} else if (module.isTransitive()) {
if (module.hasIniTemplate())
StartLog.info("%-15s transitively enabled, ini template available with --add-to-start=%s", module.getName(), module.getName());
else
StartLog.info("%-15s transitively enabled", module.getName());
} else
StartLog.info("%-15s initialized in %s", module.getName(), ini);
});
}
files.addAll(startArgs.getFiles());
if (!files.isEmpty() && processFileResources(files))
modified.set(Boolean.TRUE);
return modified.get();
}
Aggregations