449291 - --create-files downloads without license
+ Adding dist-home replicationa real distribution Adding RebuildTestResources.java to help rebuild this dist-home occasionally. There is no need to keep this directory up to date as religiously and frequently as the main distribution. + Adding LicenseTest.java to test various licensing scenarios + Added ability to ask for license via --create-files flows
This commit is contained in:
parent
153dd4023e
commit
214246061e
|
@ -465,7 +465,7 @@ public class BaseHome
|
|||
*/
|
||||
public String toShortForm(final String path)
|
||||
{
|
||||
if (path == null)
|
||||
if ((path == null) || (path.charAt(0) == '<'))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
|
|
@ -20,11 +20,23 @@ package org.eclipse.jetty.start;
|
|||
|
||||
public class FileArg
|
||||
{
|
||||
public String uri;
|
||||
public String location;
|
||||
|
||||
public final String moduleName;
|
||||
public final String uri;
|
||||
public final String location;
|
||||
|
||||
public FileArg(final Module module, final String uriLocation)
|
||||
{
|
||||
this(module == null?(String)null:module.getName(),uriLocation);
|
||||
}
|
||||
|
||||
public FileArg(final String uriLocation)
|
||||
{
|
||||
this((String)null,uriLocation);
|
||||
}
|
||||
|
||||
private FileArg(final String moduleName, final String uriLocation)
|
||||
{
|
||||
this.moduleName = moduleName;
|
||||
String parts[] = uriLocation.split("\\|",3);
|
||||
if (parts.length > 2)
|
||||
{
|
||||
|
@ -49,7 +61,7 @@ public class FileArg
|
|||
this.location = uriLocation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
|
|
|
@ -80,6 +80,7 @@ import org.eclipse.jetty.start.config.CommandLineConfigSource;
|
|||
*/
|
||||
public class Main
|
||||
{
|
||||
private static final String EXITING_LICENSE_NOT_ACKNOWLEDGED = "Exiting: license not acknowledged!";
|
||||
private static final int EXIT_USAGE = 1;
|
||||
|
||||
public static String join(Collection<?> objs, String delim)
|
||||
|
@ -171,26 +172,32 @@ public class Main
|
|||
}).start();
|
||||
}
|
||||
|
||||
private void initFile(FileArg arg)
|
||||
private void initFile(StartArgs args, FileArg farg)
|
||||
{
|
||||
try
|
||||
{
|
||||
Path file = baseHome.getBasePath(arg.location);
|
||||
|
||||
StartLog.debug("Module file %s %s",file.toAbsolutePath(),(FS.exists(file)?"[Exists!]":""));
|
||||
Path file = baseHome.getBasePath(farg.location);
|
||||
|
||||
StartLog.debug("[init-file] %s module specified file %s",file.toAbsolutePath(),(FS.exists(file)?"[Exists!]":""));
|
||||
if (FS.exists(file))
|
||||
{
|
||||
// file already initialized / downloaded, skip it
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg.uri!=null)
|
||||
if (farg.uri!=null)
|
||||
{
|
||||
URL url = new URL(arg.uri);
|
||||
URL url = new URL(farg.uri);
|
||||
|
||||
System.err.println("DOWNLOAD: " + url + " to " + arg.location);
|
||||
StartLog.log("DOWNLOAD", "%s to %s", url, farg.location);
|
||||
|
||||
FS.ensureDirectoryExists(file.getParent());
|
||||
|
||||
if (args.isTestingModeEnabled())
|
||||
{
|
||||
StartLog.log("TESTING MODE", "Skipping download of " + url);
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] buf = new byte[8192];
|
||||
try (InputStream in = url.openStream();
|
||||
|
@ -211,19 +218,25 @@ public class Main
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (arg.location.endsWith("/"))
|
||||
else if (farg.location.endsWith("/"))
|
||||
{
|
||||
System.err.println("MKDIR: " + baseHome.toShortForm(file));
|
||||
StartLog.log("MKDIR",baseHome.toShortForm(file));
|
||||
FS.ensureDirectoryExists(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
StartLog.warn("MISSING: required file "+ baseHome.toShortForm(file));
|
||||
String shortRef = baseHome.toShortForm(file);
|
||||
if (args.isTestingModeEnabled())
|
||||
{
|
||||
StartLog.log("TESTING MODE","Skipping required file check on: %s",shortRef);
|
||||
return;
|
||||
}
|
||||
StartLog.warn("MISSING: Required file %s",shortRef);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
StartLog.warn("ERROR: processing %s%n%s",arg,e);
|
||||
StartLog.warn("ERROR: processing %s%n%s",farg,e);
|
||||
StartLog.warn(e);
|
||||
usageExit(EXIT_USAGE);
|
||||
}
|
||||
|
@ -394,6 +407,15 @@ public class Main
|
|||
}
|
||||
}
|
||||
|
||||
if (!args.isApproveAllLicenses())
|
||||
{
|
||||
if (!module.acknowledgeLicense())
|
||||
{
|
||||
StartLog.warn(EXITING_LICENSE_NOT_ACKNOWLEDGED);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
boolean buildIni=false;
|
||||
if (module.isEnabled())
|
||||
{
|
||||
|
@ -425,44 +447,13 @@ public class Main
|
|||
buildIni=true;
|
||||
}
|
||||
|
||||
String source = "<transitive>";
|
||||
|
||||
// If we need an ini
|
||||
if (buildIni)
|
||||
{
|
||||
if (module.hasLicense())
|
||||
{
|
||||
System.err.printf("%nModule %s:%n",module.getName());
|
||||
System.err.printf(" + contains software not provided by the Eclipse Foundation!%n");
|
||||
System.err.printf(" + contains software not covered by the Eclipse Public License!%n");
|
||||
System.err.printf(" + has not been audited for compliance with its license%n");
|
||||
System.err.printf("%n");
|
||||
for (String l : module.getLicense())
|
||||
{
|
||||
System.err.printf(" %s%n",l);
|
||||
}
|
||||
|
||||
if (args.isApproveAllLicenses())
|
||||
{
|
||||
System.err.println("All licenses approved via command line");
|
||||
}
|
||||
else
|
||||
{
|
||||
try (BufferedReader input = new BufferedReader(new InputStreamReader(System.in)))
|
||||
{
|
||||
System.err.printf("%nProceed (y/N)? ");
|
||||
String line = input.readLine();
|
||||
|
||||
if (line == null || line.length() == 0 || !line.toLowerCase().startsWith("y"))
|
||||
{
|
||||
System.err.printf("Exiting: license not acknowledged%n");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// File BufferedWriter
|
||||
BufferedWriter writer = null;
|
||||
String source = null;
|
||||
PrintWriter out = null;
|
||||
try
|
||||
{
|
||||
|
@ -494,12 +485,11 @@ public class Main
|
|||
out.println("--module=" + name);
|
||||
|
||||
args.parse("--module=" + name,source);
|
||||
modules.enable(name,Collections.singletonList(source));
|
||||
args.parseModule(module);
|
||||
|
||||
for (String line : module.getDefaultConfig())
|
||||
{
|
||||
out.println(line);
|
||||
args.parse(line,source);
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
@ -511,20 +501,22 @@ public class Main
|
|||
}
|
||||
}
|
||||
|
||||
modules.enable(name,Collections.singletonList(source));
|
||||
|
||||
// Also list other places this module is enabled
|
||||
for (String source : module.getSources())
|
||||
for (String src : module.getSources())
|
||||
{
|
||||
StartLog.debug("also enabled in: %s",source);
|
||||
if (!short_start_ini.equals(source))
|
||||
StartLog.debug("also enabled in: %s",src);
|
||||
if (!short_start_ini.equals(src))
|
||||
{
|
||||
StartLog.info("%-15s enabled in %s",name,baseHome.toShortForm(source));
|
||||
StartLog.info("%-15s enabled in %s",name,baseHome.toShortForm(src));
|
||||
}
|
||||
}
|
||||
|
||||
// Do downloads now
|
||||
for (String file : module.getFiles())
|
||||
{
|
||||
initFile(new FileArg(file));
|
||||
initFile(args, new FileArg(module,file));
|
||||
}
|
||||
|
||||
// Process dependencies
|
||||
|
@ -701,17 +693,43 @@ public class Main
|
|||
{
|
||||
doStop(args);
|
||||
}
|
||||
|
||||
boolean rebuildGraph = false;
|
||||
|
||||
// Initialize start.ini
|
||||
for (String module : args.getAddToStartIni())
|
||||
{
|
||||
buildIni(args,module,true,true);
|
||||
rebuildGraph = true;
|
||||
}
|
||||
|
||||
// Initialize start.d
|
||||
for (String module : args.getAddToStartdIni())
|
||||
{
|
||||
buildIni(args,module,true,false);
|
||||
rebuildGraph = true;
|
||||
}
|
||||
|
||||
if (rebuildGraph)
|
||||
{
|
||||
args.getAllModules().clearMissing();
|
||||
args.getAllModules().buildGraph();
|
||||
}
|
||||
|
||||
// If in --create-files, check licenses
|
||||
if(args.isDownload())
|
||||
{
|
||||
if (!args.isApproveAllLicenses())
|
||||
{
|
||||
for (Module module : args.getAllModules().resolveEnabled())
|
||||
{
|
||||
if (!module.acknowledgeLicense())
|
||||
{
|
||||
StartLog.warn(EXITING_LICENSE_NOT_ACKNOWLEDGED);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check ini files for download possibilities
|
||||
|
@ -720,7 +738,7 @@ public class Main
|
|||
Path file = baseHome.getBasePath(arg.location);
|
||||
if (!FS.exists(file) && args.isDownload())
|
||||
{
|
||||
initFile(arg);
|
||||
initFile(args, arg);
|
||||
}
|
||||
|
||||
if (!FS.exists(file))
|
||||
|
@ -728,7 +746,7 @@ public class Main
|
|||
boolean isDir = arg.location.endsWith("/");
|
||||
if (isDir)
|
||||
{
|
||||
System.err.println("MKDIR: " + baseHome.toShortForm(file));
|
||||
StartLog.log("MKDIR", baseHome.toShortForm(file));
|
||||
FS.ensureDirectoryExists(file);
|
||||
/* Startup should not fail to run on missing directories.
|
||||
* See Bug #427204
|
||||
|
@ -737,6 +755,13 @@ public class Main
|
|||
}
|
||||
else
|
||||
{
|
||||
String shortRef = baseHome.toShortForm(file);
|
||||
if (args.isTestingModeEnabled())
|
||||
{
|
||||
StartLog.log("TESTING MODE","Skipping required file check on: %s",shortRef);
|
||||
return;
|
||||
}
|
||||
|
||||
StartLog.warn("Missing Required File: %s",baseHome.toShortForm(file));
|
||||
args.setRun(false);
|
||||
if (arg.uri != null)
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.start;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
@ -111,6 +112,7 @@ public class Module
|
|||
private boolean enabled = false;
|
||||
/** List of sources that enabled this module */
|
||||
private final Set<String> sources = new HashSet<>();
|
||||
private boolean licenseAck = false;
|
||||
|
||||
public Module(BaseHome basehome, Path file) throws FileNotFoundException, IOException
|
||||
{
|
||||
|
@ -250,7 +252,7 @@ public class Module
|
|||
{
|
||||
return parentNames;
|
||||
}
|
||||
|
||||
|
||||
public Set<String> getSources()
|
||||
{
|
||||
return Collections.unmodifiableSet(sources);
|
||||
|
@ -268,14 +270,57 @@ public class Module
|
|||
|
||||
public boolean hasLicense()
|
||||
{
|
||||
return license!=null && license.size()>0;
|
||||
return license != null && license.size() > 0;
|
||||
}
|
||||
|
||||
|
||||
public boolean acknowledgeLicense() throws IOException
|
||||
{
|
||||
if (!hasLicense() || licenseAck)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
System.err.printf("%nModule %s:%n",getName());
|
||||
System.err.printf(" + contains software not provided by the Eclipse Foundation!%n");
|
||||
System.err.printf(" + contains software not covered by the Eclipse Public License!%n");
|
||||
System.err.printf(" + has not been audited for compliance with its license%n");
|
||||
System.err.printf("%n");
|
||||
for (String l : getLicense())
|
||||
{
|
||||
System.err.printf(" %s%n",l);
|
||||
}
|
||||
|
||||
String propBasedAckName = "org.eclipse.jetty.start.ack.license." + getName();
|
||||
String propBasedAckValue = System.getProperty(propBasedAckName);
|
||||
if (propBasedAckValue != null)
|
||||
{
|
||||
StartLog.log("TESTING MODE", "Programmatic ACK - %s=%s",propBasedAckName,propBasedAckValue);
|
||||
licenseAck = Boolean.parseBoolean(propBasedAckValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Boolean.getBoolean("org.eclipse.jetty.start.testing"))
|
||||
{
|
||||
throw new RuntimeException("Test Configuration Missing - Pre-specify answer to (" + propBasedAckName + ") in test case");
|
||||
}
|
||||
|
||||
try (BufferedReader input = new BufferedReader(new InputStreamReader(System.in)))
|
||||
{
|
||||
System.err.printf("%nProceed (y/N)? ");
|
||||
String line = input.readLine();
|
||||
|
||||
licenseAck = !(line == null || line.length() == 0 || !line.toLowerCase().startsWith("y"));
|
||||
}
|
||||
}
|
||||
|
||||
return licenseAck;
|
||||
}
|
||||
|
||||
public List<String> getLicense()
|
||||
{
|
||||
return license;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
|
|
|
@ -128,13 +128,13 @@ public class Modules implements Iterable<Module>
|
|||
|
||||
if (parent == null)
|
||||
{
|
||||
if (parentName.contains("${"))
|
||||
if (Props.hasPropertyKey(parentName))
|
||||
{
|
||||
StartLog.debug("module not found [%s]%n",parentName);
|
||||
StartLog.debug("Module property not expandable (yet) [%s]",parentName);
|
||||
}
|
||||
else
|
||||
{
|
||||
StartLog.warn("module not found [%s]%n",parentName);
|
||||
StartLog.warn("Module not found [%s]",parentName);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -149,7 +149,7 @@ public class Modules implements Iterable<Module>
|
|||
Module optional = get(optionalParentName);
|
||||
if (optional == null)
|
||||
{
|
||||
StartLog.debug("optional module not found [%s]%n",optionalParentName);
|
||||
StartLog.debug("Optional module not found [%s]",optionalParentName);
|
||||
}
|
||||
else if (optional.isEnabled())
|
||||
{
|
||||
|
@ -178,6 +178,11 @@ public class Modules implements Iterable<Module>
|
|||
}
|
||||
}
|
||||
|
||||
public void clearMissing()
|
||||
{
|
||||
missingModules.clear();
|
||||
}
|
||||
|
||||
public Integer count()
|
||||
{
|
||||
return modules.size();
|
||||
|
@ -316,18 +321,23 @@ public class Modules implements Iterable<Module>
|
|||
|
||||
private void enableModule(Module module, List<String> sources) throws IOException
|
||||
{
|
||||
String via = "<transitive>";
|
||||
|
||||
// Always add the sources
|
||||
if (sources != null)
|
||||
{
|
||||
module.addSources(sources);
|
||||
via = Main.join(sources, ", ");
|
||||
}
|
||||
|
||||
// If already enabled, nothing else to do
|
||||
if (module.isEnabled())
|
||||
{
|
||||
StartLog.debug("Enabled module: %s (via %s)",module.getName(),Main.join(sources,", "));
|
||||
StartLog.debug("Enabled module: %s (via %s)",module.getName(),via);
|
||||
return;
|
||||
}
|
||||
|
||||
StartLog.debug("Enabling module: %s (via %s)",module.getName(),Main.join(sources,", "));
|
||||
StartLog.debug("Enabling module: %s (via %s)",module.getName(),via);
|
||||
module.setEnabled(true);
|
||||
args.parseModule(module);
|
||||
module.expandProperties(args.getProperties());
|
||||
|
@ -346,12 +356,16 @@ public class Modules implements Iterable<Module>
|
|||
if (FS.canReadFile(file))
|
||||
{
|
||||
parent = registerModule(file);
|
||||
parent.expandProperties(args.getProperties());
|
||||
updateParentReferencesTo(parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
StartLog.debug("Missing module definition: [ Mod: %s | File: %s ]",name,file);
|
||||
missingModules.add(name);
|
||||
if (!Props.hasPropertyKey(name))
|
||||
{
|
||||
StartLog.debug("Missing module definition: [ Mod: %s | File: %s ]",name,file);
|
||||
missingModules.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (parent != null)
|
||||
|
@ -507,12 +521,22 @@ public class Modules implements Iterable<Module>
|
|||
Module module = registerModule(file);
|
||||
updateParentReferencesTo(module);
|
||||
if (!expanded.equals(missingParent))
|
||||
{
|
||||
expandedModules.add(missingParent);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
StartLog.debug("Missing module definition: %s == %s",missingParent,expanded);
|
||||
missingModules.add(missingParent);
|
||||
if (Props.hasPropertyKey(expanded))
|
||||
{
|
||||
StartLog.debug("Module property not expandable (yet) [%s]",expanded);
|
||||
expandedModules.add(missingParent);
|
||||
}
|
||||
else
|
||||
{
|
||||
StartLog.debug("Missing module definition: %s expanded to %s",missingParent,expanded);
|
||||
missingModules.add(missingParent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -650,4 +674,5 @@ public class Modules implements Iterable<Module>
|
|||
str.append("]");
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ public class PathFinder extends SimpleFileVisitor<Path>
|
|||
{
|
||||
if (dirMatcher.matches(dir))
|
||||
{
|
||||
StartLog.debug("Following dir: " + dir);
|
||||
StartLog.trace("Following dir: " + dir);
|
||||
if (includeDirsInResults && fileMatcher.matches(dir))
|
||||
{
|
||||
addHit(dir);
|
||||
|
@ -96,7 +96,7 @@ public class PathFinder extends SimpleFileVisitor<Path>
|
|||
}
|
||||
else
|
||||
{
|
||||
StartLog.debug("Skipping dir: " + dir);
|
||||
StartLog.trace("Skipping dir: " + dir);
|
||||
return FileVisitResult.SKIP_SUBTREE;
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ public class PathFinder extends SimpleFileVisitor<Path>
|
|||
}
|
||||
else
|
||||
{
|
||||
StartLog.debug("Ignoring file: " + file);
|
||||
StartLog.trace("Ignoring file: " + file);
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
|
|
@ -233,7 +233,7 @@ public final class Props implements Iterable<Prop>
|
|||
value = getString(property);
|
||||
if (value == null)
|
||||
{
|
||||
StartLog.debug("Unable to expand: %s",property);
|
||||
StartLog.trace("Unable to expand: %s",property);
|
||||
expanded.append(mat.group(1));
|
||||
}
|
||||
else
|
||||
|
@ -316,6 +316,11 @@ public final class Props implements Iterable<Prop>
|
|||
return new Prop(key,value,ORIGIN_SYSPROP);
|
||||
}
|
||||
|
||||
public static boolean hasPropertyKey(String name)
|
||||
{
|
||||
return Pattern.compile("(?<=[^$]|^)(\\$\\{[^}]*\\})").matcher(name).find();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Prop> iterator()
|
||||
{
|
||||
|
|
|
@ -123,15 +123,16 @@ public class StartArgs
|
|||
|
||||
private boolean exec = false;
|
||||
private boolean approveAllLicenses = false;
|
||||
private boolean testingMode = false;
|
||||
|
||||
public StartArgs()
|
||||
{
|
||||
classpath = new Classpath();
|
||||
}
|
||||
|
||||
private void addFile(String uriLocation)
|
||||
private void addFile(Module module, String uriLocation)
|
||||
{
|
||||
FileArg arg = new FileArg(uriLocation);
|
||||
FileArg arg = new FileArg(module, uriLocation);
|
||||
if (!files.contains(arg))
|
||||
{
|
||||
files.add(arg);
|
||||
|
@ -376,6 +377,7 @@ public class StartArgs
|
|||
*/
|
||||
public void expandLibs(BaseHome baseHome) throws IOException
|
||||
{
|
||||
StartLog.debug("Expanding Libs");
|
||||
for (String rawlibref : rawLibs)
|
||||
{
|
||||
StartLog.debug("rawlibref = " + rawlibref);
|
||||
|
@ -401,6 +403,7 @@ public class StartArgs
|
|||
*/
|
||||
public void expandModules(BaseHome baseHome, List<Module> activeModules) throws IOException
|
||||
{
|
||||
StartLog.debug("Expanding Modules");
|
||||
for (Module module : activeModules)
|
||||
{
|
||||
// Find and Expand Libraries
|
||||
|
@ -434,7 +437,7 @@ public class StartArgs
|
|||
for (String file : module.getFiles())
|
||||
{
|
||||
StartLog.debug("Adding module specified file: %s",file);
|
||||
addFile(file);
|
||||
addFile(module,file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -638,6 +641,11 @@ public class StartArgs
|
|||
{
|
||||
return stopCommand;
|
||||
}
|
||||
|
||||
public boolean isTestingModeEnabled()
|
||||
{
|
||||
return testingMode;
|
||||
}
|
||||
|
||||
public boolean isVersion()
|
||||
{
|
||||
|
@ -702,6 +710,13 @@ public class StartArgs
|
|||
// valid, but handled in StartLog instead
|
||||
return;
|
||||
}
|
||||
|
||||
if ("--testing-mode".equals(arg))
|
||||
{
|
||||
System.setProperty("org.eclipse.jetty.start.testing","true");
|
||||
testingMode = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg.startsWith("--include-jetty-dir="))
|
||||
{
|
||||
|
@ -718,7 +733,7 @@ public class StartArgs
|
|||
|
||||
if (arg.startsWith("--download="))
|
||||
{
|
||||
addFile(Props.getValue(arg));
|
||||
addFile(null,Props.getValue(arg));
|
||||
run = false;
|
||||
download = true;
|
||||
return;
|
||||
|
@ -793,7 +808,8 @@ public class StartArgs
|
|||
// jetty.base build-out : add to ${jetty.base}/start.d/
|
||||
if (arg.startsWith("--add-to-startd="))
|
||||
{
|
||||
addToStartdIni.addAll(Props.getValues(arg));
|
||||
List<String> moduleNames = Props.getValues(arg);
|
||||
addToStartdIni.addAll(moduleNames);
|
||||
run = false;
|
||||
download = true;
|
||||
return;
|
||||
|
@ -802,7 +818,8 @@ public class StartArgs
|
|||
// jetty.base build-out : add to ${jetty.base}/start.ini
|
||||
if (arg.startsWith("--add-to-start="))
|
||||
{
|
||||
addToStartIni.addAll(Props.getValues(arg));
|
||||
List<String> moduleNames = Props.getValues(arg);
|
||||
addToStartIni.addAll(moduleNames);
|
||||
run = false;
|
||||
download = true;
|
||||
return;
|
||||
|
@ -811,17 +828,8 @@ public class StartArgs
|
|||
// Enable a module
|
||||
if (arg.startsWith("--module="))
|
||||
{
|
||||
for (String moduleName : Props.getValues(arg))
|
||||
{
|
||||
modules.add(moduleName);
|
||||
List<String> list = sources.get(moduleName);
|
||||
if (list == null)
|
||||
{
|
||||
list = new ArrayList<String>();
|
||||
sources.put(moduleName,list);
|
||||
}
|
||||
list.add(source);
|
||||
}
|
||||
List<String> moduleNames = Props.getValues(arg);
|
||||
enableModules(source,moduleNames);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -921,6 +929,21 @@ public class StartArgs
|
|||
throw new UsageException(ERR_BAD_ARG,"Unrecognized argument: \"%s\" in %s",arg,source);
|
||||
}
|
||||
|
||||
private void enableModules(String source, List<String> moduleNames)
|
||||
{
|
||||
for (String moduleName : moduleNames)
|
||||
{
|
||||
modules.add(moduleName);
|
||||
List<String> list = sources.get(moduleName);
|
||||
if (list == null)
|
||||
{
|
||||
list = new ArrayList<String>();
|
||||
sources.put(moduleName,list);
|
||||
}
|
||||
list.add(source);
|
||||
}
|
||||
}
|
||||
|
||||
public void parseModule(Module module)
|
||||
{
|
||||
if(module.hasDefaultConfig())
|
||||
|
|
|
@ -50,6 +50,14 @@ public class StartLog
|
|||
out.printf(format + "%n",args);
|
||||
}
|
||||
}
|
||||
|
||||
public static void trace(String format, Object... args)
|
||||
{
|
||||
if (INSTANCE.trace)
|
||||
{
|
||||
out.printf("TRACE: " + format + "%n",args);
|
||||
}
|
||||
}
|
||||
|
||||
public static void debug(Throwable t)
|
||||
{
|
||||
|
@ -63,15 +71,25 @@ public class StartLog
|
|||
{
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static void log(String type, String msg)
|
||||
{
|
||||
err.println(type + ": " + msg);
|
||||
}
|
||||
|
||||
public static void log(String type, String format, Object... args)
|
||||
{
|
||||
err.printf(type + ": " + format + "%n",args);
|
||||
}
|
||||
|
||||
public static void info(String format, Object... args)
|
||||
{
|
||||
err.printf("INFO: " + format + "%n",args);
|
||||
log("INFO",format,args);
|
||||
}
|
||||
|
||||
public static void warn(String format, Object... args)
|
||||
{
|
||||
err.printf("WARNING: " + format + "%n",args);
|
||||
log("WARNING",format,args);
|
||||
}
|
||||
|
||||
public static void warn(Throwable t)
|
||||
|
@ -84,6 +102,7 @@ public class StartLog
|
|||
return INSTANCE.debug;
|
||||
}
|
||||
|
||||
private boolean trace = false;
|
||||
private boolean debug = false;
|
||||
|
||||
public void initialize(BaseHome baseHome, CommandLineConfigSource cmdLineSource) throws IOException
|
||||
|
|
|
@ -85,7 +85,7 @@ public class FileArgTest
|
|||
@Test
|
||||
public void testFileArg()
|
||||
{
|
||||
FileArg arg = new FileArg(rawFileRef);
|
||||
FileArg arg = new FileArg(null,rawFileRef);
|
||||
if (expectedUri == null)
|
||||
{
|
||||
assertThat("URI",arg.uri,nullValue());
|
||||
|
|
|
@ -0,0 +1,154 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.start;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.IO;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.toolchain.test.OS;
|
||||
import org.eclipse.jetty.toolchain.test.TestingDir;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test various license handling.
|
||||
*/
|
||||
public class LicenseTest
|
||||
{
|
||||
@Rule
|
||||
public TestingDir testdir = new TestingDir();
|
||||
|
||||
@Rule
|
||||
public SystemExitAsException exitrule = new SystemExitAsException();
|
||||
|
||||
private String assertFileExists(File basePath, String name) throws IOException
|
||||
{
|
||||
File file = new File(basePath, OS.separators(name));
|
||||
FS.exists(file.toPath());
|
||||
return IO.readToString(file);
|
||||
}
|
||||
|
||||
private void execMain(List<String> cmds) throws Exception
|
||||
{
|
||||
int len = cmds.size();
|
||||
String args[] = cmds.toArray(new String[len]);
|
||||
|
||||
Main main = new Main();
|
||||
StartArgs startArgs = main.processCommandLine(args);
|
||||
main.start(startArgs);
|
||||
}
|
||||
|
||||
public List<String> getBaseCommandLine(File basePath)
|
||||
{
|
||||
List<String> cmds = new ArrayList<String>();
|
||||
cmds.add("-Djava.io.tmpdir=" + MavenTestingUtils.getTargetDir().getAbsolutePath());
|
||||
cmds.add("-Djetty.home=" + MavenTestingUtils.getTestResourceDir("dist-home").getAbsolutePath());
|
||||
cmds.add("-Djetty.base=" + basePath.getAbsolutePath());
|
||||
cmds.add("--testing-mode");
|
||||
|
||||
return cmds;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd_NoLicensed() throws Exception
|
||||
{
|
||||
File basePath = testdir.getEmptyDir();
|
||||
|
||||
List<String> cmds = getBaseCommandLine(basePath);
|
||||
|
||||
cmds.add("--add-to-start=http,deploy");
|
||||
|
||||
execMain(cmds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd_CDI_Licensed() throws Exception
|
||||
{
|
||||
File basePath = testdir.getEmptyDir();
|
||||
|
||||
List<String> cmds = getBaseCommandLine(basePath);
|
||||
|
||||
cmds.add("-Dorg.eclipse.jetty.start.ack.license.cdi=true");
|
||||
cmds.add("--add-to-start=cdi");
|
||||
|
||||
execMain(cmds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd_SPDY_Licensed() throws Exception
|
||||
{
|
||||
File basePath = testdir.getEmptyDir();
|
||||
|
||||
List<String> cmds = getBaseCommandLine(basePath);
|
||||
|
||||
cmds.add("-Dorg.eclipse.jetty.start.ack.license.protonego-impl=true");
|
||||
cmds.add("--add-to-start=spdy");
|
||||
|
||||
execMain(cmds);
|
||||
|
||||
String contents = assertFileExists(basePath, "start.ini");
|
||||
assertThat("Contents",contents,containsString("--module=spdy"+System.lineSeparator()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate_SPDY_Licensed() throws Exception
|
||||
{
|
||||
File basePath = testdir.getEmptyDir();
|
||||
|
||||
List<String> cmds = getBaseCommandLine(basePath);
|
||||
|
||||
cmds.add("-Dorg.eclipse.jetty.start.ack.license.protonego-impl=true");
|
||||
|
||||
StringReader startIni = new StringReader("--module=spdy\n");
|
||||
try (FileWriter writer = new FileWriter(new File(basePath,"start.ini")))
|
||||
{
|
||||
IO.copy(startIni,writer);
|
||||
}
|
||||
|
||||
execMain(cmds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate_CDI_Licensed() throws Exception
|
||||
{
|
||||
File basePath = testdir.getEmptyDir();
|
||||
|
||||
List<String> cmds = getBaseCommandLine(basePath);
|
||||
|
||||
cmds.add("-Dorg.eclipse.jetty.start.ack.license.cdi=true");
|
||||
cmds.add("--create-files");
|
||||
|
||||
StringReader startIni = new StringReader("--module=cdi\n");
|
||||
try (FileWriter writer = new FileWriter(new File(basePath,"start.ini")))
|
||||
{
|
||||
IO.copy(startIni,writer);
|
||||
}
|
||||
|
||||
execMain(cmds);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,190 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.start;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.PathMatcher;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
|
||||
/**
|
||||
* Utility class to rebuild the src/test/resources/dist-home from the active build tree.
|
||||
* <p>
|
||||
* Not really meant to be run with each build. Nor is it a good idea to attempt to do that (as this would introduce a dependency from jetty-start ->
|
||||
* jetty-distribution which is a circular dependency)
|
||||
*/
|
||||
public class RebuildTestResources
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
File realDistHome = MavenTestingUtils.getProjectDir("../jetty-distribution/target/distribution");
|
||||
File outputDir = MavenTestingUtils.getTestResourceDir("dist-home");
|
||||
try
|
||||
{
|
||||
new RebuildTestResources(realDistHome,outputDir).rebuild();
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static interface FileCopier
|
||||
{
|
||||
public void copy(Path from, Path to) throws IOException;
|
||||
}
|
||||
|
||||
private static class NormalFileCopier implements FileCopier
|
||||
{
|
||||
@Override
|
||||
public void copy(Path from, Path to) throws IOException
|
||||
{
|
||||
Files.copy(from,to,StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
|
||||
private static class TouchFileCopier implements FileCopier
|
||||
{
|
||||
@Override
|
||||
public void copy(Path from, Path to) throws IOException
|
||||
{
|
||||
Files.createFile(to);
|
||||
}
|
||||
}
|
||||
|
||||
private static interface Renamer
|
||||
{
|
||||
public String getName(Path path);
|
||||
}
|
||||
|
||||
private static class NoRenamer implements Renamer
|
||||
{
|
||||
@Override
|
||||
public String getName(Path path)
|
||||
{
|
||||
return path.getFileName().toString();
|
||||
}
|
||||
}
|
||||
|
||||
private static class RegexRenamer implements Renamer
|
||||
{
|
||||
private final Pattern pat;
|
||||
private final String replacement;
|
||||
|
||||
public RegexRenamer(String regex, String replacement)
|
||||
{
|
||||
this.pat = Pattern.compile(regex);
|
||||
this.replacement = replacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(Path path)
|
||||
{
|
||||
String origName = path.getFileName().toString();
|
||||
return pat.matcher(origName).replaceAll(replacement);
|
||||
}
|
||||
}
|
||||
|
||||
private final Path destDir;
|
||||
private final Path srcDir;
|
||||
|
||||
public RebuildTestResources(File realDistHome, File outputDir) throws IOException
|
||||
{
|
||||
this.srcDir = realDistHome.toPath().toRealPath();
|
||||
this.destDir = outputDir.toPath();
|
||||
}
|
||||
|
||||
private void copyLibs() throws IOException
|
||||
{
|
||||
System.out.println("Copying libs (lib dir) ...");
|
||||
Path libsDir = destDir.resolve("lib");
|
||||
FS.ensureDirExists(libsDir.toFile());
|
||||
|
||||
PathMatcher matcher = getPathMatcher("glob:**.jar");
|
||||
Renamer renamer = new RegexRenamer("-9\\.[0-9.]*(v[0-9]*)?(-SNAPSHOT)?(RC[0-9])?(M[0-9])?","-TEST");
|
||||
FileCopier copier = new TouchFileCopier();
|
||||
copyDir(srcDir.resolve("lib"),libsDir,matcher,renamer,copier);
|
||||
}
|
||||
|
||||
private void copyModules() throws IOException
|
||||
{
|
||||
System.out.println("Copying modules ...");
|
||||
Path modulesDir = destDir.resolve("modules");
|
||||
FS.ensureDirExists(modulesDir.toFile());
|
||||
|
||||
PathMatcher matcher = getPathMatcher("glob:**.mod");
|
||||
Renamer renamer = new NoRenamer();
|
||||
FileCopier copier = new NormalFileCopier();
|
||||
copyDir(srcDir.resolve("modules"),modulesDir,matcher,renamer,copier);
|
||||
}
|
||||
|
||||
private void copyXmls() throws IOException
|
||||
{
|
||||
System.out.println("Copying xmls (etc dir) ...");
|
||||
Path xmlDir = destDir.resolve("etc");
|
||||
FS.ensureDirExists(xmlDir.toFile());
|
||||
|
||||
PathMatcher matcher = getPathMatcher("glob:**.xml");
|
||||
Renamer renamer = new NoRenamer();
|
||||
FileCopier copier = new TouchFileCopier();
|
||||
copyDir(srcDir.resolve("etc"),xmlDir,matcher,renamer,copier);
|
||||
}
|
||||
|
||||
private void rebuild() throws IOException
|
||||
{
|
||||
copyModules();
|
||||
copyLibs();
|
||||
copyXmls();
|
||||
System.out.println("Done");
|
||||
}
|
||||
|
||||
private PathMatcher getPathMatcher(String pattern)
|
||||
{
|
||||
return FileSystems.getDefault().getPathMatcher(pattern);
|
||||
}
|
||||
|
||||
private void copyDir(Path from, Path to, PathMatcher fileMatcher, Renamer renamer, FileCopier copier) throws IOException
|
||||
{
|
||||
Files.createDirectories(to);
|
||||
|
||||
for (Path path : Files.newDirectoryStream(from))
|
||||
{
|
||||
String name = renamer.getName(path);
|
||||
Path dest = to.resolve(name);
|
||||
if (Files.isDirectory(path))
|
||||
{
|
||||
copyDir(path,dest,fileMatcher,renamer,copier);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fileMatcher.matches(path))
|
||||
{
|
||||
copier.copy(path,dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.start;
|
||||
|
||||
import java.security.Permission;
|
||||
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
public class SystemExitAsException implements TestRule
|
||||
{
|
||||
@SuppressWarnings("serial")
|
||||
public static class SystemExitException extends RuntimeException
|
||||
{
|
||||
public SystemExitException(int status)
|
||||
{
|
||||
super("Encountered System.exit(" + status + ")");
|
||||
}
|
||||
}
|
||||
|
||||
private static class NoExitSecurityManager extends SecurityManager
|
||||
{
|
||||
@Override
|
||||
public void checkPermission(Permission perm)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkPermission(Permission perm, Object context)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkExit(int status)
|
||||
{
|
||||
super.checkExit(status);
|
||||
throw new SystemExitException(status);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement apply(final Statement statement, Description description)
|
||||
{
|
||||
return new Statement()
|
||||
{
|
||||
@Override
|
||||
public void evaluate() throws Throwable
|
||||
{
|
||||
SecurityManager origSecurityManager = System.getSecurityManager();
|
||||
try
|
||||
{
|
||||
System.setSecurityManager(new NoExitSecurityManager());
|
||||
statement.evaluate();
|
||||
}
|
||||
finally
|
||||
{
|
||||
System.setSecurityManager(origSecurityManager);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue