Issue #5256 Adding start.jar --add-module (#5258)

* Issue #5256 --add-modules

Signed-off-by: Greg Wilkins <gregw@webtide.com>

* main.ini

Signed-off-by: Greg Wilkins <gregw@webtide.com>

* Issue #5256 --add-modules

usage.txt

Signed-off-by: Greg Wilkins <gregw@webtide.com>

* Issue #5256 --add-modules

updates from review

Signed-off-by: Greg Wilkins <gregw@webtide.com>

* Issue #5256 --add-modules

updates from review

Signed-off-by: Greg Wilkins <gregw@webtide.com>

* fixed test

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2020-09-15 11:54:44 +02:00 committed by GitHub
parent e23eaa26b9
commit 0f4031089b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 283 additions and 87 deletions

View File

@ -18,10 +18,13 @@
package org.eclipse.jetty.start;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URI;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@ -125,11 +128,11 @@ public class BaseBuilder
{
for (String name : startArgs.getStartModules())
{
newlyAdded.addAll(modules.enable(name, "--add-to-start"));
newlyAdded.addAll(modules.enable(name, "--add-module"));
if (!newlyAdded.contains(name))
{
Set<String> sources = modules.get(name).getEnableSources();
sources.remove("--add-to-start");
sources.remove("--add-module");
StartLog.info("%s already enabled by %s", name, sources);
}
}
@ -169,35 +172,70 @@ public class BaseBuilder
Path startd = getBaseHome().getBasePath("start.d");
Path startini = getBaseHome().getBasePath("start.ini");
if (startArgs.isCreateStartd() && !Files.exists(startd))
if (startArgs.isCreateStartIni())
{
if (FS.ensureDirectoryExists(startd))
if (!Files.exists(startini))
{
StartLog.log("MKDIR", baseHome.toShortForm(startd));
StartLog.info("create " + baseHome.toShortForm(startini));
Files.createFile(startini);
modified.set(true);
}
if (Files.exists(startini))
if (Files.exists(startd))
{
int ini = 0;
Path startdStartIni = startd.resolve("start.ini");
while (Files.exists(startdStartIni))
// Copy start.d files into start.ini
DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>()
{
ini++;
startdStartIni = startd.resolve("start" + ini + ".ini");
PathMatcher iniMatcher = PathMatchers.getMatcher("glob:**/start.d/*.ini");
@Override
public boolean accept(Path entry) throws IOException
{
return iniMatcher.matches(entry);
}
};
List<Path> paths = new ArrayList<>();
for (Path path : Files.newDirectoryStream(startd, filter))
paths.add(path);
paths.sort(new NaturalSort.Paths());
// Read config from start.d
List<String> startLines = new ArrayList<>();
for (Path path : paths)
{
StartLog.info("copy " + baseHome.toShortForm(path) + " into " + baseHome.toShortForm(startini));
startLines.add("");
startLines.add("# Config from " + baseHome.toShortForm(path));
startLines.addAll(Files.readAllLines(path));
}
Files.move(startini, startdStartIni);
modified.set(true);
// append config to start.ini
try (FileWriter out = new FileWriter(startini.toFile(), true))
{
for (String line : startLines)
out.append(line).append(System.lineSeparator());
}
// delete start.d files
for (Path path : paths)
Files.delete(path);
Files.delete(startd);
}
}
if (!newlyAdded.isEmpty())
{
if (!Files.exists(startini) && !Files.exists(startd) && FS.ensureDirectoryExists(startd))
{
StartLog.info("mkdir " + baseHome.toShortForm(startd));
modified.set(true);
}
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));
newlyAdded.stream().map(n -> modules.get(n)).forEach(module ->
newlyAdded.stream().map(modules::get).forEach(module ->
{
String ini = null;
try
@ -236,16 +274,18 @@ public class BaseBuilder
else if (module.isTransitive())
{
if (module.hasIniTemplate())
StartLog.info("%-15s transitively enabled, ini template available with --add-to-start=%s",
StartLog.info("%-15s transitively enabled, ini template available with --add-module=%s",
module.getName(),
module.getName());
else
StartLog.info("%-15s transitively enabled", module.getName());
}
else
{
StartLog.info("%-15s initialized in %s",
module.getName(),
ini);
}
});
}

View File

@ -128,9 +128,9 @@ public abstract class FileInitializer
protected void download(URI uri, Path destination) throws IOException
{
if (FS.ensureDirectoryExists(destination.getParent()))
StartLog.log("MKDIR", _basehome.toShortForm(destination.getParent()));
StartLog.info("mkdir " + _basehome.toShortForm(destination.getParent()));
StartLog.log("DOWNLD", "%s to %s", uri, _basehome.toShortForm(destination));
StartLog.info("download %s to %s", uri, _basehome.toShortForm(destination));
HttpURLConnection http = (HttpURLConnection)uri.toURL().openConnection();
http.setInstanceFollowRedirects(true);
@ -206,7 +206,7 @@ public abstract class FileInitializer
{
if (FS.ensureDirectoryExists(to))
{
StartLog.log("MKDIR", _basehome.toShortForm(to));
StartLog.info("mkdir " + _basehome.toShortForm(to));
modified = true;
}
@ -215,7 +215,7 @@ public abstract class FileInitializer
}
else if (!Files.exists(to))
{
StartLog.log("COPY ", "%s to %s", _basehome.toShortForm(from), _basehome.toShortForm(to));
StartLog.info("copy %s to %s", _basehome.toShortForm(from), _basehome.toShortForm(to));
Files.copy(from, to);
modified = true;
}

View File

@ -85,7 +85,7 @@ public class Licensing
String propBasedAckValue = System.getProperty(PROP_ACK_LICENSES);
if (propBasedAckValue != null)
{
StartLog.log("TESTING MODE", "Programmatic ACK - %s=%s", PROP_ACK_LICENSES, propBasedAckValue);
StartLog.info("Automatic License Acknowledgment - %s=%s", PROP_ACK_LICENSES, propBasedAckValue);
licenseAck = Boolean.parseBoolean(propBasedAckValue);
}
else

View File

@ -221,7 +221,7 @@ public class Modules implements Iterable<Module>
name = "";
}
if (module.isTransitive() && module.hasIniTemplate())
System.out.printf(" init template available with --add-to-start=%s%n", module.getName());
System.out.printf(" init template available with --add-module=%s%n", module.getName());
}
}

View File

@ -193,7 +193,7 @@ public class StartArgs
// jetty.base - build out commands
/**
* --add-to-start[d]=[module,[module]]
* --add-module=[module,[module]]
*/
private List<String> startModules = new ArrayList<>();
@ -230,7 +230,7 @@ public class StartArgs
private boolean dryRun = false;
private final Set<String> dryRunParts = new HashSet<>();
private boolean jpms = false;
private boolean createStartd = false;
private boolean createStartIni = false;
private boolean updateIni = false;
private String mavenBaseUri;
@ -1024,9 +1024,9 @@ public class StartArgs
return version;
}
public boolean isCreateStartd()
public boolean isCreateStartIni()
{
return createStartd;
return createStartIni;
}
public boolean isUpdateIni()
@ -1280,27 +1280,30 @@ public class StartArgs
}
// jetty.base build-out : add to ${jetty.base}/start.ini
if ("--create-start-ini".equals(arg))
{
createStartIni = true;
run = false;
createFiles = true;
licenseCheckRequired = true;
return;
}
if ("--create-startd".equals(arg))
{
createStartd = true;
StartLog.warn("--create-startd option is deprecated! By default start.d is used");
run = false;
createFiles = true;
licenseCheckRequired = true;
return;
}
if (arg.startsWith("--add-to-startd="))
{
String value = Props.getValue(arg);
StartLog.warn("--add-to-startd is deprecated! Instead use: --create-startd --add-to-start=%s", value);
createStartd = true;
startModules.addAll(Props.getValues(arg));
run = false;
createFiles = true;
licenseCheckRequired = true;
return;
}
if (arg.startsWith("--add-to-start="))
if (arg.startsWith("--add-module=") || arg.startsWith("--add-modules=") || arg.startsWith("--add-to-start=") || arg.startsWith("--add-to-startd="))
{
if (arg.startsWith("--add-to-start=") || arg.startsWith("--add-to-startd="))
{
String value = Props.getValue(arg);
StartLog.warn("Option " + arg.split("=")[0] + " is deprecated! Instead use: --add-module=%s", value);
}
startModules.addAll(Props.getValues(arg));
run = false;
createFiles = true;

View File

@ -78,12 +78,12 @@ public class StartLog
return INSTANCE;
}
public static void log(String type, String msg)
private static void log(String type, String msg)
{
logStream.printf("%-6s: %s%n", type, msg);
}
public static void log(String type, String format, Object... args)
private static void log(String type, String format, Object... args)
{
log(type, String.format(format, args));
}

View File

@ -35,7 +35,7 @@ import org.eclipse.jetty.start.StartLog;
/**
* Management of the <code>${jetty.base}/start.d/</code> based configuration.
* <p>
* Implementation of the <code>--add-to-startd=[name]</code> command line behavior
* Implementation of the <code>--add-modules=[name]</code> command line behavior
*/
public class StartDirBuilder implements BaseBuilder.Config
{
@ -47,7 +47,7 @@ public class StartDirBuilder implements BaseBuilder.Config
this.baseHome = baseBuilder.getBaseHome();
this.startDir = baseHome.getBasePath("start.d");
if (FS.ensureDirectoryExists(startDir))
StartLog.log("MKDIR", baseHome.toShortForm(startDir));
StartLog.info("mkdir " + baseHome.toShortForm(startDir));
}
@Override

View File

@ -38,7 +38,7 @@ import org.eclipse.jetty.start.StartLog;
/**
* Management of the <code>${jetty.base}/start.ini</code> based configuration.
* <p>
* Implementation of the <code>--add-to-start=[name]</code> command line behavior
* Implementation of the <code>--add-module=[name]</code> command line behavior
*/
public class StartIniBuilder implements BaseBuilder.Config
{

View File

@ -62,14 +62,21 @@ public class DirConfigSource implements ConfigSource
BANNED_ARGS.add("--exec-print");
BANNED_ARGS.add("--list-config");
BANNED_ARGS.add("--list-classpath");
BANNED_ARGS.add("--list-module");
BANNED_ARGS.add("--list-modules");
BANNED_ARGS.add("--show-module");
BANNED_ARGS.add("--show-modules");
BANNED_ARGS.add("--write-module-graph");
BANNED_ARGS.add("--version");
BANNED_ARGS.add("-v");
BANNED_ARGS.add("--download");
BANNED_ARGS.add("--create-files");
BANNED_ARGS.add("--create-startd");
BANNED_ARGS.add("--create-start-ini");
BANNED_ARGS.add("--add-to-startd");
BANNED_ARGS.add("--add-to-start");
BANNED_ARGS.add("--add-module");
BANNED_ARGS.add("--add-modules");
}
private final String id;

View File

@ -69,7 +69,7 @@ public class BaseHomeFileInitializer extends FileInitializer
else if (FS.ensureDirectoryExists(destination))
{
modified = true;
StartLog.log("MKDIR", _basehome.toShortForm(destination));
StartLog.info("mkdir " + _basehome.toShortForm(destination));
}
copyDirectory(source, destination);
@ -79,12 +79,12 @@ public class BaseHomeFileInitializer extends FileInitializer
if (FS.ensureDirectoryExists(destination.getParent()))
{
modified = true;
StartLog.log("MKDIR", _basehome.toShortForm(destination.getParent()));
StartLog.info("mkdir " + _basehome.toShortForm(destination.getParent()));
}
if (!FS.exists(destination))
{
StartLog.log("COPY ", "%s to %s", _basehome.toShortForm(source), _basehome.toShortForm(destination));
StartLog.info("copy %s to %s", _basehome.toShortForm(source), _basehome.toShortForm(destination));
Files.copy(source, destination);
modified = true;
}

View File

@ -78,7 +78,7 @@ public class LocalFileInitializer extends FileInitializer
// Create directory
boolean mkdir = FS.ensureDirectoryExists(destination);
if (mkdir)
StartLog.log("MKDIR", _basehome.toShortForm(destination));
StartLog.info("mkdir " + _basehome.toShortForm(destination));
return mkdir;
}

View File

@ -129,8 +129,8 @@ public class MavenLocalRepoFileInitializer extends FileInitializer
if (localRepoFile != null)
{
if (FS.ensureDirectoryExists(destination.getParent()))
StartLog.log("MKDIR", _basehome.toShortForm(destination.getParent()));
StartLog.log("COPY ", "%s to %s", localRepoFile, _basehome.toShortForm(destination));
StartLog.info("mkdir " + _basehome.toShortForm(destination.getParent()));
StartLog.info("copy %s to %s", localRepoFile, _basehome.toShortForm(destination));
Files.copy(localRepoFile, destination);
return true;
}

View File

@ -57,7 +57,7 @@ public class TestFileInitializer extends FileInitializer
FS.ensureDirectoryExists(destination.getParent());
}
StartLog.log("TESTING MODE", "Skipping download of " + uri);
StartLog.info("Skipping download of %s", uri);
return true;
}
}

View File

@ -101,45 +101,48 @@ Jetty Module Management:
dependencies, tags, libraries and XMLs
--module=<modulename>(,<modulename>)*
Temporarily enable a module from the command line.
Note: this can also be used in the ${jetty.base}/start.ini
or ${jetty.base}/start.d/*.ini files.
Enable a module for this run. To enable a module for all
future runs, use --add-module
Note: this option is used in the ${jetty.base}/start.ini
or ${jetty.base}/start.d/*.ini files created by --add-module.
--add-to-start=<modulename>(,<modulename>)*
--add-module=<modulename>(,<modulename>)*
Add the modules to the list of modules enabled at start.
Transitive dependencies are followed and dependent
modules may also explicitly added.
Modules are added to the start by creating an ini file
that contains the --module argument and any other parameters
defined in the modules ini template.
If the directory ${jetty.base}/start.d
exists then <modulename>.ini files are created within
that directory, otherwise then enabling configuration
is appended to the ${jetty.base}/start.ini file.
If the ${jetty.base}/start.ini file exists, configuration is
appended, otherwise the directory ${jetty.base}/start.d
is used to create <modulename>.ini files.
If the ini template contains properties, these may be
amended in the generated file by specifying those
properties on the command line.
Note: not all modules have ini templates and thus may
be transitively enabled and not explicitly enabled in
a ini file.
If a module is transitively enabled, it's ini file will not
be generated. An explicit --add-module is required to generate
an ini file.
This option replaces the depecated --add-to-start and --add-to-startd.
--update-ini Scan all start.ini and start.d/*.ini files and update
any properties with values specified on the command
line. e.g. --update-ini jetty.http.port=8888
--create-startd Ensure that a start.d directory exists for use by
subsequent --add-to-start=*. If a start.ini file exists
it is moved to the start.d directory
--create-start-ini
Create a ${jetty.base}/start.ini file. If a ${jetty.base}/start.d
directory exists, then all it's contained ini files are concatinated into
the start.ini file.
--write-module-graph=<filename>
Create a graphviz *.dot file of the module graph as it
exists for the active ${jetty.base}.
See http://graphviz.org/ for details on how to post-process
this file into the output best suited for your needs.
--create-files Create any missing files that are required by initialized
modules. This may download a file from the network if the
--create-files Create any missing files that are required by initialized
modules. This may download a file from the network if the
module provides a URL.
--skip-file-validation=<modulename>(,<modulename)*
@ -148,14 +151,14 @@ Jetty Module Management:
module. Useful for modules that have downloadable
content that is being overridden with alternatives
in the ${jetty.base} directory.
CAUTION:
CAUTION:
This advanced option is for administrators that
fully understand the configuration of their
${jetty.base} and are willing to forego some of the
safety checks built into the jetty-start mechanism.
--approve-all-licenses
Approve all license questions. Useful for enabling
Approve all license questions. Useful for enabling
modules from a script that does not require user interaction.
Startup / Shutdown Command Line:
@ -170,7 +173,7 @@ Advanced Commands:
--lib=<classpath>
Add arbitrary classpath entries to the the server classpath.
--include-jetty-dir=<path>
Include an extra jetty directory to use as a source
for configuration details. This directory behaves similarly

View File

@ -0,0 +1,34 @@
## The XMLs we expect (order is important)
XML|${jetty.home}/etc/optional.xml
XML|${jetty.home}/etc/base.xml
XML|${jetty.home}/etc/main.xml
XML|${jetty.home}/etc/extra.xml
# The LIBs we expect (order is irrelevant)
LIB|${jetty.home}/lib/optional.jar
LIB|${jetty.home}/lib/base.jar
LIB|${jetty.home}/lib/main.jar
LIB|${jetty.home}/lib/other.jar
LIB|${jetty.home}/lib/extra/extra0.jar
LIB|${jetty.home}/lib/extra/extra1.jar
# The Properties we expect (order is irrelevant)
PROP|extra.prop=value0
PROP|main.prop=value0
PROP|optional.prop=value0
# Files / Directories to create
EXISTS|maindir/
EXISTS|start.ini
# Output Assertions [regex!] (order is irrelevant)
OUTPUT|INFO : mkdir ..jetty.base./start.d
OUTPUT|INFO : extra initialized in \$\{jetty.base\}/start.d/extra.ini
OUTPUT|INFO : main transitively enabled, ini template available with --add-module=main
OUTPUT|INFO : optional initialized in \$\{jetty.base\}/start.d/optional.ini
OUTPUT|INFO : base transitively enabled
OUTPUT|INFO : mkdir ..jetty.base./maindir
OUTPUT|INFO : Base directory was modified

View File

@ -0,0 +1,2 @@
--add-module=extra
--add-module=optional

View File

@ -0,0 +1,34 @@
## The XMLs we expect (order is important)
XML|${jetty.home}/etc/optional.xml
XML|${jetty.home}/etc/base.xml
XML|${jetty.home}/etc/main.xml
XML|${jetty.home}/etc/extra.xml
# The LIBs we expect (order is irrelevant)
LIB|${jetty.home}/lib/optional.jar
LIB|${jetty.home}/lib/base.jar
LIB|${jetty.home}/lib/main.jar
LIB|${jetty.home}/lib/other.jar
LIB|${jetty.home}/lib/extra/extra0.jar
LIB|${jetty.home}/lib/extra/extra1.jar
# The Properties we expect (order is irrelevant)
PROP|extra.prop=value0
PROP|main.prop=value0
PROP|optional.prop=value0
# Files / Directories to create
EXISTS|maindir/
EXISTS|start.ini
# Output Assertions [regex!] (order is irrelevant)
OUTPUT|INFO : create ..jetty.base./start.ini
OUTPUT|INFO : extra initialized in ..jetty.base./start.ini
OUTPUT|INFO : main transitively enabled, ini template available with --add-module=main
OUTPUT|INFO : optional initialized in ..jetty.base./start.ini
OUTPUT|INFO : base transitively enabled
OUTPUT|INFO : mkdir ..jetty.base./maindir
OUTPUT|INFO : Base directory was modified

View File

@ -0,0 +1,3 @@
--add-module=extra
--add-module=optional
--create-start-ini

View File

@ -1,3 +0,0 @@
--add-to-start=extra
--create-startd
--add-to-start=optional

View File

@ -1,2 +1 @@
--create-startd
--add-to-start=extra,optional
--add-to-startd=extra,optional

View File

@ -15,5 +15,5 @@ PROP|optional.prop=value0
# Files / Directories to create
EXISTS|maindir/
EXISTS|start.d/start.ini
EXISTS|start.d/main.ini
EXISTS|start.d/optional.ini

View File

@ -2,25 +2,20 @@
XML|${jetty.home}/etc/optional.xml
XML|${jetty.home}/etc/base.xml
XML|${jetty.home}/etc/main.xml
XML|${jetty.home}/etc/extra.xml
# The LIBs we expect (order is irrelevant)
LIB|${jetty.home}/lib/optional.jar
LIB|${jetty.home}/lib/base.jar
LIB|${jetty.home}/lib/main.jar
LIB|${jetty.home}/lib/other.jar
LIB|${jetty.home}/lib/extra/extra0.jar
LIB|${jetty.home}/lib/extra/extra1.jar
LIB|${jetty.home}/lib/optional.jar
# The Properties we expect (order is irrelevant)
PROP|extra.prop=value0
PROP|main.prop=value0
PROP|optional.prop=value0
# Files / Directories to create
EXISTS|maindir/
EXISTS|start.d/extra.ini
EXISTS|start.d/main.ini
EXISTS|start.d/optional.ini
# Output Assertions [regex!] (order is irrelevant)
OUTPUT|MKDIR : \$\{jetty.base\}[\\/]maindir
OUTPUT|WARN : Option --add-to-startd is deprecated! Instead use: --add-module=optional

View File

@ -0,0 +1 @@
--add-to-startd=optional

View File

@ -0,0 +1,17 @@
## The XMLs we expect (order is important)
XML|${jetty.home}/etc/base.xml
XML|${jetty.home}/etc/main.xml
# The LIBs we expect (order is irrelevant)
LIB|${jetty.home}/lib/base.jar
LIB|${jetty.home}/lib/main.jar
LIB|${jetty.home}/lib/other.jar
# The Properties we expect (order is irrelevant)
PROP|main.prop=value0
# Files / Directories to create
EXISTS|maindir/
EXISTS|start.d/main.ini
OUTPUT|INFO : main already enabled by \[\$\{jetty.base}[\\/]start.d/main.ini\]

View File

@ -0,0 +1,23 @@
## The XMLs we expect (order is important)
XML|${jetty.home}/etc/optional.xml
XML|${jetty.home}/etc/base.xml
XML|${jetty.home}/etc/main.xml
# The LIBs we expect (order is irrelevant)
LIB|${jetty.home}/lib/base.jar
LIB|${jetty.home}/lib/main.jar
LIB|${jetty.home}/lib/other.jar
LIB|${jetty.home}/lib/optional.jar
# The Properties we expect (order is irrelevant)
PROP|main.prop=value0
PROP|optional.prop=value0
# Files / Directories to create
EXISTS|maindir/
EXISTS|start.ini
OUTPUT|INFO : copy ..jetty.base./start.d/main.ini into ..jetty.base./start.ini
OUTPUT|INFO : optional initialized in ..jetty.base./start.ini
OUTPUT|INFO : mkdir ..jetty.base./maindir
OUTPUT|INFO : Base directory was modified

View File

@ -0,0 +1,2 @@
--add-to-start=optional
--create-start-ini

View File

@ -0,0 +1,20 @@
## The XMLs we expect (order is important)
XML|${jetty.home}/etc/optional.xml
XML|${jetty.home}/etc/base.xml
XML|${jetty.home}/etc/main.xml
# The LIBs we expect (order is irrelevant)
LIB|${jetty.home}/lib/base.jar
LIB|${jetty.home}/lib/main.jar
LIB|${jetty.home}/lib/other.jar
LIB|${jetty.home}/lib/optional.jar
# The Properties we expect (order is irrelevant)
PROP|main.prop=value0
PROP|optional.prop=value0
# Files / Directories to create
EXISTS|maindir/
EXISTS|start.ini
OUTPUT|WARN : Option --add-to-startd is deprecated! Instead use: --add-module=optional

View File

@ -0,0 +1 @@
--add-to-startd=optional

View File

@ -0,0 +1 @@
EX|UsageException

View File

@ -0,0 +1,2 @@
--create-startd
--add-to-start=unknown

View File

@ -0,0 +1 @@
--add-to-start=main

View File

@ -0,0 +1,11 @@
## The XMLs we expect (order is important)
XML|${jetty.home}/etc/base.xml
XML|${jetty.home}/etc/main.xml
# The LIBs we expect (order is irrelevant)
LIB|${jetty.home}/lib/base.jar
LIB|${jetty.home}/lib/main.jar
LIB|${jetty.home}/lib/other.jar
# The Properties we expect (order is irrelevant)
PROP|main.prop=value0

View File

@ -0,0 +1 @@
--module=main