Search in sources :

Example 1 with StartDirBuilder

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();
}
Also used : Path(java.nio.file.Path) Files(java.nio.file.Files) StartIniBuilder(org.eclipse.jetty.start.builders.StartIniBuilder) LocalFileInitializer(org.eclipse.jetty.start.fileinits.LocalFileInitializer) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) BaseHomeFileInitializer(org.eclipse.jetty.start.fileinits.BaseHomeFileInitializer) TestFileInitializer(org.eclipse.jetty.start.fileinits.TestFileInitializer) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UriFileInitializer(org.eclipse.jetty.start.fileinits.UriFileInitializer) List(java.util.List) MavenLocalRepoFileInitializer(org.eclipse.jetty.start.fileinits.MavenLocalRepoFileInitializer) URI(java.net.URI) StartDirBuilder(org.eclipse.jetty.start.builders.StartDirBuilder) Path(java.nio.file.Path) Prop(org.eclipse.jetty.start.Props.Prop) CopyOption(java.nio.file.CopyOption) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) StartDirBuilder(org.eclipse.jetty.start.builders.StartDirBuilder) StartIniBuilder(org.eclipse.jetty.start.builders.StartIniBuilder) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashSet(java.util.HashSet)

Aggregations

IOException (java.io.IOException)1 URI (java.net.URI)1 CopyOption (java.nio.file.CopyOption)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Prop (org.eclipse.jetty.start.Props.Prop)1 StartDirBuilder (org.eclipse.jetty.start.builders.StartDirBuilder)1 StartIniBuilder (org.eclipse.jetty.start.builders.StartIniBuilder)1 BaseHomeFileInitializer (org.eclipse.jetty.start.fileinits.BaseHomeFileInitializer)1 LocalFileInitializer (org.eclipse.jetty.start.fileinits.LocalFileInitializer)1 MavenLocalRepoFileInitializer (org.eclipse.jetty.start.fileinits.MavenLocalRepoFileInitializer)1 TestFileInitializer (org.eclipse.jetty.start.fileinits.TestFileInitializer)1 UriFileInitializer (org.eclipse.jetty.start.fileinits.UriFileInitializer)1