Fixes #5844 - --download flag to jetty-start causes NullPointerException.

Added test case, null guard and a couple small fixes.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2021-01-07 12:51:06 +01:00 committed by GitHub
parent 5a28c7484a
commit b45c32616c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 24 deletions

View File

@ -282,7 +282,7 @@ This allows for some complex hierarchies of configuration details.
--download=<http-uri>|<location>::
If the file does not exist at the given location, download it from the given http URI.
Note: location is always relative to `${jetty.base}`.
You might need to escape the slash "\|" to use this on some environments.
You might need to escape the pipe "\|" to use this on some environments.
maven.repo.uri=[url]::
The url to use to download Maven dependencies.
@ -321,4 +321,4 @@ Alternatively to create an args file for java:
----
$ java -jar start.jar --dry-run=opts,path,main,args > /tmp/args
$ java @/tmp/args
----
----

View File

@ -245,9 +245,9 @@ public class StartArgs
private void addFile(Module module, String uriLocation)
{
if (module.isSkipFilesValidation())
if (module != null && module.isSkipFilesValidation())
{
StartLog.debug("Not validating %s [files] for %s", module, uriLocation);
StartLog.debug("Not validating module %s [files] for %s", module, uriLocation);
return;
}

View File

@ -184,7 +184,7 @@ Advanced Commands:
Advanced usage, If the file does not exist at the given
location, download it from the given http URI.
Notes: location is always relative to ${jetty.base}.
you might need to escape the slash "\|" to use
you might need to escape the pipe "\|" to use
this on some environments.
maven.repo.uri=[url]
The url to use to download Maven dependencies.

View File

@ -56,7 +56,7 @@ public class MainTest
// cmdLineArgs.add("jetty.http.port=9090");
Main main = new Main();
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()]));
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[0]));
BaseHome baseHome = main.getBaseHome();
// System.err.println(args);
@ -92,7 +92,7 @@ public class MainTest
cmdLineArgs.add("STOP.WAIT=300");
Main main = new Main();
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()]));
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[0]));
// System.err.println(args);
// assertEquals(0, args.getEnabledModules().size(), "--stop should not build module tree");
@ -113,7 +113,7 @@ public class MainTest
// cmdLineArgs.add("--debug");
Main main = new Main();
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()]));
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[0]));
main.listConfig(args);
}
@ -131,8 +131,8 @@ public class MainTest
List<String> cmdLineArgs = new ArrayList<>();
Path homePath = MavenTestingUtils.getTestResourceDir("dist-home").toPath().toRealPath();
cmdLineArgs.add("jetty.home=" + homePath.toString());
cmdLineArgs.add("user.dir=" + homePath.toString());
cmdLineArgs.add("jetty.home=" + homePath);
cmdLineArgs.add("user.dir=" + homePath);
// JVM args
cmdLineArgs.add("--exec");
@ -146,13 +146,8 @@ public class MainTest
assertThat("Extra Jar exists: " + extraJar, Files.exists(extraJar), is(true));
assertThat("Extra Dir exists: " + extraDir, Files.exists(extraDir), is(true));
StringBuilder lib = new StringBuilder();
lib.append("--lib=");
lib.append(extraJar.toString());
lib.append(File.pathSeparator);
lib.append(extraDir.toString());
cmdLineArgs.add(lib.toString());
String lib = "--lib=" + extraJar + File.pathSeparator + extraDir;
cmdLineArgs.add(lib);
// Arbitrary XMLs
cmdLineArgs.add("config.xml");
@ -161,7 +156,7 @@ public class MainTest
Main main = new Main();
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()]));
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[0]));
BaseHome baseHome = main.getBaseHome();
assertThat("jetty.home", baseHome.getHome(), is(homePath.toString()));
@ -176,8 +171,8 @@ public class MainTest
List<String> cmdLineArgs = new ArrayList<>();
Path homePath = MavenTestingUtils.getTestResourceDir("dist-home").toPath().toRealPath();
cmdLineArgs.add("jetty.home=" + homePath.toString());
cmdLineArgs.add("user.dir=" + homePath.toString());
cmdLineArgs.add("jetty.home=" + homePath);
cmdLineArgs.add("user.dir=" + homePath);
// JVM args
cmdLineArgs.add("--exec");
@ -187,7 +182,7 @@ public class MainTest
Main main = new Main();
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()]));
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[0]));
BaseHome baseHome = main.getBaseHome();
assertThat("jetty.home", baseHome.getHome(), is(homePath.toString()));
@ -216,7 +211,7 @@ public class MainTest
Main main = new Main();
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()]));
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[0]));
BaseHome baseHome = main.getBaseHome();
assertThat("jetty.home", baseHome.getHome(), is(homePath.toString()));
@ -231,7 +226,7 @@ public class MainTest
Path distPath = MavenTestingUtils.getTestResourceDir("dist-home").toPath().toRealPath();
Path homePath = MavenTestingUtils.getTargetTestingPath().resolve("dist home with spaces");
IO.copy(distPath.toFile(), homePath.toFile());
homePath.resolve("lib/a library.jar").toFile().createNewFile();
Files.createFile(homePath.resolve("lib/a library.jar"));
List<String> cmdLineArgs = new ArrayList<>();
cmdLineArgs.add("user.dir=" + homePath);
@ -239,7 +234,7 @@ public class MainTest
cmdLineArgs.add("--lib=lib/a library.jar");
Main main = new Main();
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()]));
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[0]));
BaseHome baseHome = main.getBaseHome();
assertThat("jetty.home", baseHome.getHome(), is(homePath.toString()));

View File

@ -35,6 +35,7 @@ import org.eclipse.jetty.unixsocket.client.HttpClientTransportOverUnixSockets;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.DisabledOnOs;
@ -406,4 +407,28 @@ public class DistributionTests extends AbstractDistributionTest
}
}
}
@Test
@Tag("external")
public void testDownload() throws Exception
{
Path jettyBase = Files.createTempDirectory("jetty_base");
String jettyVersion = System.getProperty("jettyVersion");
DistributionTester distribution = DistributionTester.Builder.newInstance()
.jettyVersion(jettyVersion)
.jettyBase(jettyBase)
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
.build();
String outPath = "etc/maven-metadata.xml";
String[] args1 = {
"--download=https://repo1.maven.org/maven2/org/eclipse/jetty/maven-metadata.xml|" + outPath
};
try (DistributionTester.Run run = distribution.start(args1))
{
assertTrue(run.awaitConsoleLogsFor("Base directory was modified", 15, TimeUnit.SECONDS));
Path target = jettyBase.resolve(outPath);
assertTrue(Files.exists(target), "could not create " + target);
}
}
}