Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 55 additions & 15 deletions jetty-start/src/main/java/org/eclipse/jetty/start/BaseBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -125,11 +128,11 @@ public boolean build() throws IOException
{
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);
}
}
Expand Down Expand Up @@ -169,35 +172,70 @@ else if (!licensing.acknowledgeLicenses())
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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be mkdir for consistency with other logs, not create.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it is not a directory! "touch" ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed from startd to startini ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joakime exectly because the option is now --create-start-ini and --create-startd is a noop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that --create-start-ini takes all the files in start.d and concats them into a start.ini and then removes start.d

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>()
{
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)
{
ini++;
startdStartIni = startd.resolve("start" + ini + ".ini");
StartLog.info("copy " + baseHome.toShortForm(path) + " to " + 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
Expand Down Expand Up @@ -236,16 +274,18 @@ else if (!licensing.acknowledgeLicenses())
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);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ protected Path getDestination(URI uri, String location) throws IOException
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);
Expand Down Expand Up @@ -206,7 +206,7 @@ public boolean copyDirectory(Path source, Path destination) throws IOException
{
if (FS.ensureDirectoryExists(to))
{
StartLog.log("MKDIR", _basehome.toShortForm(to));
StartLog.info("mkdir " + _basehome.toShortForm(to));
modified = true;
}

Expand All @@ -215,7 +215,7 @@ public boolean copyDirectory(Path source, Path destination) throws IOException
}
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));
gregw marked this conversation as resolved.
Show resolved Hide resolved
Files.copy(from, to);
modified = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public boolean acknowledgeLicenses() throws IOException
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void dumpEnabled()
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());
}
}

Expand Down
27 changes: 15 additions & 12 deletions jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();

Expand Down Expand Up @@ -229,7 +229,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;

Expand Down Expand Up @@ -1019,9 +1019,9 @@ public boolean isVersion()
return version;
}

public boolean isCreateStartd()
public boolean isCreateStartIni()
{
return createStartd;
return createStartIni;
}

public boolean isUpdateIni()
Expand Down Expand Up @@ -1260,27 +1260,30 @@ public void parse(final String rawarg, String source)
}

// jetty.base build-out : add to ${jetty.base}/start.ini
if ("--create-startd".equals(arg))

if ("--create-start-ini".equals(arg))
{
createStartd = true;
createStartIni = true;
run = false;
createFiles = true;
licenseCheckRequired = true;
return;
}
if (arg.startsWith("--add-to-startd="))
if ("--create-startd".equals(arg))
{
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));
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-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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public static StartLog getInstance()
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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/**
* 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
{
Expand All @@ -47,7 +47,7 @@ public StartDirBuilder(BaseBuilder baseBuilder) throws IOException
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/**
* 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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public boolean create(URI uri, String location) throws IOException
else if (FS.ensureDirectoryExists(destination))
{
modified = true;
StartLog.log("MKDIR", _basehome.toShortForm(destination));
StartLog.info("mkdir " + _basehome.toShortForm(destination));
}

copyDirectory(source, destination);
Expand All @@ -79,12 +79,12 @@ else if (FS.ensureDirectoryExists(destination))
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public boolean create(URI uri, String location) throws IOException
// Create directory
boolean mkdir = FS.ensureDirectoryExists(destination);
if (mkdir)
StartLog.log("MKDIR", _basehome.toShortForm(destination));
StartLog.info("mkdir " + _basehome.toShortForm(destination));
return mkdir;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ public boolean create(URI uri, String location) throws IOException
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public boolean create(URI uri, String location) throws IOException
FS.ensureDirectoryExists(destination.getParent());
}

StartLog.log("TESTING MODE", "Skipping download of " + uri);
StartLog.info("Skipping download of %s", uri);
return true;
}
}
Loading