Merge branch 'jetty-9.4.x' of github.com:eclipse/jetty.project into jetty-9.4.x

This commit is contained in:
Jan Bartel 2016-06-23 12:04:15 +10:00
commit 3c6dab9790
42 changed files with 167 additions and 174 deletions

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.start;
import java.io.IOException;
import java.net.URI;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@ -113,23 +114,21 @@ public class BaseBuilder
Modules modules = startArgs.getAllModules();
// Select all the added modules to determine which ones are newly enabled
Set<String> newly_enabled = new HashSet<>();
Set<String> newly_added = new HashSet<>();
if (!startArgs.getStartModules().isEmpty())
{
for (String name:startArgs.getStartModules())
newly_enabled.addAll(modules.enable(name,"--add-to-start[d]"));
newly_added.addAll(modules.enable(name,"--add-to-start"));
}
if (StartLog.isDebugEnabled())
StartLog.debug("start[d]=%s",newly_enabled);
StartLog.debug("added=%s",newly_added);
// Check the licenses
if (startArgs.isLicenseCheckRequired())
{
Licensing licensing = new Licensing();
for (String name : newly_enabled)
for (String name : newly_added)
licensing.addModule(modules.get(name));
if (licensing.hasLicenses())
@ -151,22 +150,36 @@ public class BaseBuilder
AtomicReference<BaseBuilder.Config> builder = new AtomicReference<>();
AtomicBoolean modified = new AtomicBoolean();
if (!newly_enabled.isEmpty())
Path startd = getBaseHome().getBasePath("start.d");
Path startini = getBaseHome().getBasePath("start.ini");
if (startArgs.isCreateStartd() && !Files.exists(startd))
{
Path startd = getBaseHome().getBasePath("start.d");
Path startini = getBaseHome().getBasePath("start.ini");
if(FS.ensureDirectoryExists(startd))
modified.set(true);
if (Files.exists(startini))
{
if (Files.exists(startd))
StartLog.warn("Should not use both %s and %s",getBaseHome().toShortForm(startd),getBaseHome().toShortForm(startini));
else if (startArgs.isUseStartd())
throw new UsageException("Cannot --add-to-startd when %s exists",getBaseHome().toShortForm(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())
{
boolean useStartD=startArgs.isUseStartd() || Files.exists(startd);
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_enabled.stream().map(n->modules.get(n)).forEach(module ->
newly_added.stream().map(n->modules.get(n)).forEach(module ->
{
try
{

View File

@ -76,7 +76,7 @@ public class Main
}
catch (UsageException e)
{
System.err.println(e.getMessage());
StartLog.warn(e.getMessage());
usageExit(e.getCause(),e.getExitCode(),test);
}
catch (Throwable e)
@ -197,7 +197,7 @@ public class Main
}
catch (ClassNotFoundException e)
{
System.out.println("WARNING: Nothing to start, exiting ...");
StartLog.warn("Nothing to start, exiting ...");
StartLog.debug(e);
usageExit(ERR_INVOKE_MAIN);
return;
@ -452,7 +452,7 @@ public class Main
if (args.hasJvmArgs() || args.hasSystemProperties())
{
System.err.println("WARNING: System properties and/or JVM args set. Consider using --dry-run or --exec");
StartLog.warn("System properties and/or JVM args set. Consider using --dry-run or --exec");
}
ClassLoader cl = classpath.getClassLoader();
@ -507,13 +507,13 @@ public class Main
{
if (port <= 0)
{
System.err.println("STOP.PORT system property must be specified");
StartLog.warn("STOP.PORT system property must be specified");
}
if (key == null)
{
key = "";
System.err.println("STOP.KEY system property must be specified");
System.err.println("Using empty key");
StartLog.info("STOP.KEY system property must be specified");
StartLog.info("Using empty key");
}
try (Socket s = new Socket(InetAddress.getByName(host),port))
@ -530,7 +530,7 @@ public class Main
if (timeout > 0)
{
System.err.printf("Waiting %,d seconds for jetty to stop%n",timeout);
StartLog.info("Waiting %,d seconds for jetty to stop%n",timeout);
LineNumberReader lin = new LineNumberReader(new InputStreamReader(s.getInputStream()));
String response;
while ((response = lin.readLine()) != null)
@ -547,7 +547,7 @@ public class Main
}
catch (SocketTimeoutException e)
{
System.err.println("Timed out waiting for stop confirmation");
StartLog.warn("Timed out waiting for stop confirmation");
System.exit(ERR_UNKNOWN);
}
catch (ConnectException e)
@ -565,7 +565,7 @@ public class Main
StartLog.endStartLog();
if(!printTextResource("org/eclipse/jetty/start/usage.txt"))
{
System.err.println("ERROR: detailed usage resource unavailable");
StartLog.warn("detailed usage resource unavailable");
}
if (exit)
{
@ -592,7 +592,7 @@ public class Main
}
else
{
System.out.println("Unable to find resource: " + resourceName);
StartLog.warn("Unable to find resource: " + resourceName);
}
}
catch (IOException e)
@ -613,7 +613,7 @@ public class Main
}
catch (UsageException e)
{
System.err.println(e.getMessage());
StartLog.warn(e.getMessage());
usageExit(e.getCause(),e.getExitCode(),startupArgs.isTestingModeEnabled());
}
catch (Throwable e)

View File

@ -19,8 +19,10 @@
package org.eclipse.jetty.start;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@ -486,4 +488,20 @@ public class Module
{
return isEnabled() && !_notTransitive;
}
public void writeIniSection(BufferedWriter writer)
{
PrintWriter out = new PrintWriter(writer);
out.println("# --------------------------------------- ");
out.println("# Module: " + getName());
for (String line : getDescription())
out.append("# ").println(line);
out.println("# --------------------------------------- ");
out.println("--module=" + getName());
out.println();
for (String line : getIniTemplate())
out.println(line);
out.println();
out.flush();
}
}

View File

@ -364,7 +364,7 @@ public class Modules implements Iterable<Module>
if (unsatisfied.length()>0)
unsatisfied.append(',');
unsatisfied.append(m.getName());
System.err.printf("%nWARN: Module %s requires %s from one of %s%n",m.getName(),d,providers);
StartLog.warn("Module %s requires %s from one of %s%n",m.getName(),d,providers);
}
});
});

View File

@ -175,7 +175,7 @@ public class StartArgs
private boolean listConfig = false;
private boolean version = false;
private boolean dryRun = false;
private boolean useStartd = false;
private boolean createStartd = false;
private boolean exec = false;
private String exec_properties;
@ -775,9 +775,9 @@ public class StartArgs
return version;
}
public boolean isUseStartd()
public boolean isCreateStartd()
{
return useStartd;
return createStartd;
}
public void parse(ConfigSources sources)
@ -947,14 +947,28 @@ public class StartArgs
}
// jetty.base build-out : add to ${jetty.base}/start.ini
if (arg.startsWith("--add-to-startd=")||
arg.startsWith("--add-to-start="))
if ("--create-startd".equals(arg))
{
if (arg.startsWith("--add-to-startd="))
useStartd=true;
List<String> moduleNames = Props.getValues(arg);
startModules.addAll(moduleNames);
createStartd=true;
run = false;
download = true;
licenseCheckRequired = true;
return;
}
if (arg.startsWith("--add-to-startd="))
{
String value = Props.getValue(arg);
StartLog.warn("--add-to-startd is deprecated! Instead use:%n %s",value);
createStartd=true;
startModules.addAll(Props.getValues(arg));
run = false;
download = true;
licenseCheckRequired = true;
return;
}
if (arg.startsWith("--add=") || arg.startsWith("--add-to-start="))
{
startModules.addAll(Props.getValues(arg));
run = false;
download = true;
licenseCheckRequired = true;

View File

@ -84,12 +84,12 @@ public class StartLog
public static void info(String format, Object... args)
{
log("INFO",format,args);
log("INFO ",format,args);
}
public static void warn(String format, Object... args)
{
log("WARNING",format,args);
log("WARN ",format,args);
}
public static void warn(Throwable t)

View File

@ -76,29 +76,11 @@ public class StartDirBuilder implements BaseBuilder.Config
try (BufferedWriter writer = Files.newBufferedWriter(ini,StandardCharsets.UTF_8,StandardOpenOption.CREATE,StandardOpenOption.TRUNCATE_EXISTING))
{
writeModuleSection(writer,module);
module.writeIniSection(writer);
}
return true;
}
return false;
}
protected void writeModuleSection(BufferedWriter writer, Module module)
{
PrintWriter out = new PrintWriter(writer);
out.println("# --------------------------------------- ");
out.println("# Module: " + module.getName());
out.println("--module=" + module.getName());
out.println();
for (String line : module.getIniTemplate())
{
out.println(line);
}
out.println();
out.flush();
}
}

View File

@ -118,29 +118,11 @@ public class StartIniBuilder implements BaseBuilder.Config
// Append to start.ini
try (BufferedWriter writer = Files.newBufferedWriter(startIni,StandardCharsets.UTF_8,StandardOpenOption.APPEND,StandardOpenOption.CREATE))
{
writeModuleSection(writer,module);
module.writeIniSection(writer);
}
return true;
}
return false;
}
protected void writeModuleSection(BufferedWriter writer, Module module)
{
PrintWriter out = new PrintWriter(writer);
out.println("# --------------------------------------- ");
out.println("# Module: " + module.getName());
out.println("--module=" + module.getName());
out.println();
for (String line : module.getIniTemplate())
{
out.println(line);
}
out.println();
out.flush();
}
}

View File

@ -73,23 +73,37 @@ Module Management:
Note: this can also be used in the ${jetty.base}/start.ini
or ${jetty.base}/start.d/*.ini files.
--add=<modulename>(,<modulename>)*
--add-to-start=<modulename>(,<modulename>)*
Enable a module. If the directory ${jetty.base}/start.d
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.
FS.ensureDirectoryExists(startDir);
FS.ensureDirectoryExists(startDir);
modules that the specified module depends on are also
.
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.
Lines that are added come from the ini template that
the module itself maintains.
Transitive module dependencies are followed and all
modules that the specified module depends on are also
enabled.
Note: not all modules have ini templates and thus may
be transitively enabled and not explicitly enabled in
a ini file.
--add-to-startd=<modulename>(,<modulename>)*
Ensure that a start.d directory exists and then enable
the module as for --add-to-start
--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
--write-module-graph=<filename>
Create a graphviz *.dot file of the module graph as it

View File

@ -20,12 +20,15 @@ package org.eclipse.jetty.start;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
@ -148,30 +151,14 @@ public class ConfigurationAssert
}
}
assertContainsUnordered("Downloads",expectedDownloads,actualDownloads);
// Validate Files/Dirs creation
List<String> expectedFiles = new ArrayList<>();
for(String line: textFile)
{
if(line.startsWith("FILE|"))
{
expectedFiles.add(getValue(line));
}
}
List<String> actualFiles = new ArrayList<>();
for(FileArg farg: args.getFiles())
{
if(farg.uri == null)
{
actualFiles.add(farg.location);
}
}
assertContainsUnordered("Files/Dirs",expectedFiles,actualFiles);
textFile.stream()
.filter(s->s.startsWith("EXISTS|"))
.map(s->baseHome.getPath(s.substring(7)).toFile())
.forEach(f->Assert.assertTrue(f+" exists?",f.exists()));
.filter(s->s.startsWith("EXISTS|")).map(f->f.substring(7)).forEach(f->
{
Path path=baseHome.getBasePath().resolve(f);
assertTrue(baseHome.toShortForm(path)+" exists?",Files.exists(path));
assertEquals(baseHome.toShortForm(path)+" isDir?",f.endsWith("/"),Files.isDirectory(path));
});
}
private static String shorten(BaseHome baseHome, Path path, Path testResourcesDir)

View File

@ -28,6 +28,7 @@ public class PropertyDump
{
public static void main(String[] args)
{
System.out.printf("PropertyDump%n");
// As System Properties
Properties props = System.getProperties();
Enumeration<?> names = props.propertyNames();
@ -37,7 +38,7 @@ public class PropertyDump
// only interested in "test." prefixed properties
if (name.startsWith("test."))
{
System.out.printf("%s=%s%n",name,props.getProperty(name));
System.out.printf("System %s=%s%n",name,props.getProperty(name));
}
}
@ -48,7 +49,6 @@ public class PropertyDump
{
Properties aprops = new Properties();
File propFile = new File(arg);
System.out.printf("[load file %s]%n",propFile.getName());
try (FileReader reader = new FileReader(propFile))
{
aprops.load(reader);
@ -58,7 +58,7 @@ public class PropertyDump
String name = (String)anames.nextElement();
if (name.startsWith("test."))
{
System.out.printf("%s=%s%n",name,aprops.getProperty(name));
System.out.printf("%s %s=%s%n",propFile.getName(),name,aprops.getProperty(name));
}
}
}

View File

@ -30,6 +30,8 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.IO;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
@ -45,6 +47,7 @@ public class PropertyPassingTest
private String mode;
private BufferedReader reader;
private StringWriter output;
private CountDownLatch latch=new CountDownLatch(1);
public ConsoleCapture(String mode, InputStream is)
{
@ -62,6 +65,7 @@ public class PropertyPassingTest
while ((line = reader.readLine()) != (null))
{
out.println(line);
out.flush();
}
}
catch (IOException ignore)
@ -71,11 +75,13 @@ public class PropertyPassingTest
finally
{
IO.close(reader);
latch.countDown();
}
}
public String getConsoleOutput()
public String getConsoleOutput() throws InterruptedException
{
latch.await(30,TimeUnit.SECONDS);
return output.toString();
}
@ -154,9 +160,9 @@ public class PropertyPassingTest
// Run command, collect output
String output = collectRunOutput(commands);
// Test for values
Assert.assertThat("output",output,containsString("foo=bar"));
Assert.assertThat(output,containsString("test.foo=bar"));
}
private String getClassPath()
@ -201,6 +207,7 @@ public class PropertyPassingTest
System.out.printf("STDOUT: [" + stdOutPump.getConsoleOutput() + "]%n");
Assert.assertThat("Exit code",exitCode,is(0));
}
stdErrPump.getConsoleOutput();
return stdOutPump.getConsoleOutput();
}

View File

@ -10,6 +10,3 @@ LIB|${jetty.base}/lib/agent-jdk-1.7.jar
# The Properties we expect (order is irrelevant)
PROP|main.prop=value0
# Files / Directories to create
FILE|maindir/

View File

@ -10,6 +10,3 @@ LIB|${jetty.home}/lib/other.jar
# The Properties we expect (order is irrelevant)
PROP|main.prop=value0
PROP|noDft.option=A
# Files / Directories to create
FILE|maindir/

View File

@ -13,6 +13,3 @@ LIB|${jetty.home}/lib/other.jar
PROP|main.prop=value0
PROP|default.option=default
PROP|noDft.option=B
# Files / Directories to create
FILE|maindir/

View File

@ -12,6 +12,3 @@ LIB|${jetty.home}/lib/other.jar
PROP|main.prop=value0
PROP|default.option=alternate
PROP|noDft.option=B
# Files / Directories to create
FILE|maindir/

View File

@ -12,6 +12,3 @@ LIB|${jetty.home}/lib/other.jar
PROP|main.prop=value0
PROP|default.option=alternate
PROP|noDft.option=B
# Files / Directories to create
FILE|maindir/

View File

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

View File

@ -1 +1,19 @@
EX|org.eclipse.jetty.start.UsageException: Cannot --add-to-startd when ${jetty.base}/start.ini exists
## 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.d/start.ini
EXISTS|start.d/optional.ini

View File

@ -1 +1 @@
--add-to-startd=optional
--create-startd --add=optional

View File

@ -1 +1 @@
--add-to-startd=unknown
--create-startd --add=unknown

View File

@ -9,6 +9,3 @@ LIB|${jetty.home}/lib/other.jar
# The Properties we expect (order is irrelevant)
PROP|main.prop=value0
# Files / Directories to create
FILE|maindir/

View File

@ -12,6 +12,3 @@ PROP|main.prop=value0
PROP|port=9090
PROP|other=value
PROP|jetty.http.port=9090
# Files / Directories to create
FILE|maindir/

View File

@ -14,7 +14,3 @@ LIB|${jetty.base}/lib/db/mysql-driver.jar
PROP|main.prop=value0
PROP|mysql.user=frank
PROP|mysql.pass=secret
# Files / Directories to create
FILE|maindir/

View File

@ -1 +1 @@
--add-to-startd=tom
--create-startd --add=tom

View File

@ -10,6 +10,3 @@ LIB|${jetty.home}/lib/other.jar
# The Properties we expect (order is irrelevant)
PROP|main.prop=value0
PROP|dynamic=1.7.0_31-from-mod
# Files / Directories to create
FILE|maindir/

View File

@ -10,6 +10,3 @@ LIB|${jetty.home}/lib/other.jar
# The Properties we expect (order is irrelevant)
PROP|main.prop=value0
PROP|dynamic=1.8.0_05_from_mod
# Files / Directories to create
FILE|maindir/

View File

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

View File

@ -1 +0,0 @@
EX|org.eclipse.jetty.start.UsageException: Cannot --add-to-startd when ${jetty.base}/start.ini exists

View File

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

View File

@ -18,7 +18,6 @@ PROP|main.prop=valueT
PROP|optional.prop=value0
# Files / Directories to create
FILE|maindir/
EXISTS|start.d/extra.ini
EXISTS|maindir/
EXISTS|start.d/start.ini
EXISTS|start.d/optional.ini
EXISTS|start.d/main.ini

View File

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

View File

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

View File

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

View File

@ -18,7 +18,8 @@ PROP|main.prop=valueT
PROP|optional.prop=value0
# Files / Directories to create
FILE|maindir/
EXISTS|maindir/
EXISTS|start.d/
EXISTS|start.d/main.ini
EXISTS|start.d/extra.ini
EXISTS|start.d/optional.ini
EXISTS|start.d/main.ini

View File

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

View File

@ -1 +1 @@
--add-to-startd=demo
--create-startd --add=demo

View File

@ -1 +1 @@
--add-to-startd=tom
--create-startd --add=tom

View File

@ -1 +1 @@
--add-to-startd=abstractB,abstractA
--create-startd --add=abstractB,abstractA

View File

@ -12,6 +12,3 @@ LIB|${jetty.home}/lib/other.jar
# The Properties we expect (order is irrelevant)
PROP|main.prop=value0
PROP|direct.option=direct
# Files / Directories to create
FILE|maindir/

View File

@ -13,6 +13,3 @@ LIB|${jetty.home}/lib/other.jar
PROP|main.prop=value0
PROP|transient.option=transient
PROP|direct.option=direct
# Files / Directories to create
FILE|maindir/

View File

@ -11,6 +11,3 @@ LIB|${jetty.home}/lib/other.jar
PROP|main.prop=value0
PROP|the-future=is-new
PROP|from-module=old
# Files / Directories to create
FILE|maindir/