jetty-start / Making sure that download works
This commit is contained in:
parent
866a9c96d2
commit
c1517fe866
|
@ -41,6 +41,8 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.eclipse.jetty.start.StartArgs.DownloadArg;
|
||||
|
||||
/**
|
||||
* Main start class.
|
||||
* <p>
|
||||
|
@ -167,18 +169,11 @@ public class Main
|
|||
}).start();
|
||||
}
|
||||
|
||||
private void download(String arg)
|
||||
private void download(DownloadArg arg)
|
||||
{
|
||||
try
|
||||
{
|
||||
String[] split = arg.split("|",3);
|
||||
if ((split.length != 3) || "http".equalsIgnoreCase(split[0]) || !split[1].startsWith("//"))
|
||||
{
|
||||
throw new IllegalArgumentException("Not --download=<http uri>:<location>");
|
||||
}
|
||||
|
||||
String location = split[2];
|
||||
File file = baseHome.getBaseFile(location);
|
||||
File file = baseHome.getBaseFile(arg.location);
|
||||
|
||||
StartLog.debug("Download to %s %s",file.getAbsolutePath(),(file.exists()?"[Exists!]":""));
|
||||
if (file.exists())
|
||||
|
@ -186,9 +181,9 @@ public class Main
|
|||
return;
|
||||
}
|
||||
|
||||
URL url = new URL(split[0].substring(11) + ":" + split[1]);
|
||||
URL url = new URL(arg.uri);
|
||||
|
||||
System.err.println("DOWNLOAD: " + url + " to " + location);
|
||||
System.err.println("DOWNLOAD: " + url + " to " + arg.location);
|
||||
|
||||
FS.ensureDirectoryExists(file.getParentFile());
|
||||
|
||||
|
@ -444,6 +439,12 @@ public class Main
|
|||
usage(true);
|
||||
}
|
||||
|
||||
// Various Downloads
|
||||
for (DownloadArg url : args.getDownloads())
|
||||
{
|
||||
download(url);
|
||||
}
|
||||
|
||||
// Show the version information and return
|
||||
if (args.isListClasspath())
|
||||
{
|
||||
|
@ -469,12 +470,6 @@ public class Main
|
|||
System.out.println(cmd.toString());
|
||||
}
|
||||
|
||||
// Various Downloads
|
||||
for (String url : args.getDownloads())
|
||||
{
|
||||
download(url);
|
||||
}
|
||||
|
||||
// Enables/Disable
|
||||
ModulePersistence persistence = loadModulePersistence();
|
||||
if (args.isModulePersistenceChanging())
|
||||
|
@ -508,6 +503,7 @@ public class Main
|
|||
stop(stopPort,stopKey);
|
||||
}
|
||||
}
|
||||
|
||||
// Informational command line, don't run jetty
|
||||
if (!args.isRun())
|
||||
{
|
||||
|
|
|
@ -39,7 +39,76 @@ import java.util.Set;
|
|||
*/
|
||||
public class StartArgs
|
||||
{
|
||||
public static class DownloadArg
|
||||
{
|
||||
public String uri;
|
||||
public String location;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
DownloadArg other = (DownloadArg)obj;
|
||||
if (uri == null)
|
||||
{
|
||||
if (other.uri != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!uri.equals(other.uri))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (location == null)
|
||||
{
|
||||
if (other.location != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!location.equals(other.location))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = (prime * result) + ((uri == null)?0:uri.hashCode());
|
||||
result = (prime * result) + ((location == null)?0:location.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("DownloadArg [uri=");
|
||||
builder.append(uri);
|
||||
builder.append(", location=");
|
||||
builder.append(location);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
public static final String CMD_LINE_SOURCE = "<cmd-line>";
|
||||
|
||||
public static final String VERSION;
|
||||
|
||||
static
|
||||
|
@ -70,7 +139,7 @@ public class StartArgs
|
|||
private List<String> commandLine = new ArrayList<>();
|
||||
private Set<String> modules = new HashSet<>();
|
||||
private Map<String, List<String>> sources = new HashMap<>();
|
||||
private List<String> downloads = new ArrayList<>();
|
||||
private List<DownloadArg> downloads = new ArrayList<>();
|
||||
private Classpath classpath;
|
||||
private List<String> xmlRefs = new ArrayList<>();
|
||||
private List<File> xmls = new ArrayList<>();
|
||||
|
@ -98,6 +167,31 @@ public class StartArgs
|
|||
classpath = new Classpath();
|
||||
}
|
||||
|
||||
private void addDownload(String uriLocation)
|
||||
{
|
||||
String parts[] = uriLocation.split(":",3);
|
||||
if (parts.length != 3)
|
||||
{
|
||||
throw new IllegalArgumentException("Not <http uri>:<location>");
|
||||
}
|
||||
if (!"http".equalsIgnoreCase(parts[0]))
|
||||
{
|
||||
throw new IllegalArgumentException("Download only supports http protocol");
|
||||
}
|
||||
if (!parts[1].startsWith("//"))
|
||||
{
|
||||
throw new IllegalArgumentException("Download URI invalid: " + uriLocation);
|
||||
}
|
||||
DownloadArg arg = new DownloadArg();
|
||||
arg.uri = String.format("%s:%s",parts[0],parts[1]);
|
||||
arg.location = parts[2];
|
||||
|
||||
if (!downloads.contains(arg))
|
||||
{
|
||||
downloads.add(arg);
|
||||
}
|
||||
}
|
||||
|
||||
public void addSystemProperty(String key, String value)
|
||||
{
|
||||
this.systemPropertyKeys.add(key);
|
||||
|
@ -185,25 +279,6 @@ public class StartArgs
|
|||
}
|
||||
}
|
||||
|
||||
public void dumpSystemProperties()
|
||||
{
|
||||
System.out.println();
|
||||
System.out.println("System Properties:");
|
||||
System.out.println("------------------");
|
||||
|
||||
if (systemPropertyKeys.isEmpty())
|
||||
{
|
||||
System.out.println(" (no system properties specified)");
|
||||
return;
|
||||
}
|
||||
|
||||
for (String key : systemPropertyKeys)
|
||||
{
|
||||
String value = System.getProperty(key);
|
||||
System.out.printf(" %s = %s%n",key,value);
|
||||
}
|
||||
}
|
||||
|
||||
public void dumpProperties()
|
||||
{
|
||||
System.out.println();
|
||||
|
@ -226,6 +301,25 @@ public class StartArgs
|
|||
}
|
||||
}
|
||||
|
||||
public void dumpSystemProperties()
|
||||
{
|
||||
System.out.println();
|
||||
System.out.println("System Properties:");
|
||||
System.out.println("------------------");
|
||||
|
||||
if (systemPropertyKeys.isEmpty())
|
||||
{
|
||||
System.out.println(" (no system properties specified)");
|
||||
return;
|
||||
}
|
||||
|
||||
for (String key : systemPropertyKeys)
|
||||
{
|
||||
String value = System.getProperty(key);
|
||||
System.out.printf(" %s = %s%n",key,value);
|
||||
}
|
||||
}
|
||||
|
||||
private void dumpSystemProperty(String key)
|
||||
{
|
||||
System.out.printf(" %s=%s%n",key,System.getProperty(key));
|
||||
|
@ -327,16 +421,18 @@ public class StartArgs
|
|||
File xmlfile = baseHome.getFile(xmlRef);
|
||||
addUniqueXmlFile(xmlRef,xmlfile);
|
||||
}
|
||||
|
||||
|
||||
// Register Download operations
|
||||
for ( String download : module.getDownloads() )
|
||||
for (String download : module.getDownloads())
|
||||
{
|
||||
downloads.add(download);
|
||||
StartLog.debug("Adding module specified download: %s",download);
|
||||
addDownload(download);
|
||||
}
|
||||
|
||||
|
||||
// Register BootLib references
|
||||
for ( String bootlib : module.getBootLibs() )
|
||||
for (String bootlib : module.getBootLibs())
|
||||
{
|
||||
StartLog.debug("Adding module specified bootlib: %s",bootlib);
|
||||
exec = true;
|
||||
jvmArgs.add(bootlib);
|
||||
}
|
||||
|
@ -358,8 +454,8 @@ public class StartArgs
|
|||
return this.commandLine;
|
||||
}
|
||||
|
||||
public List<String> getDownloads()
|
||||
{
|
||||
public List<DownloadArg> getDownloads()
|
||||
{
|
||||
return downloads;
|
||||
}
|
||||
|
||||
|
@ -385,7 +481,7 @@ public class StartArgs
|
|||
{
|
||||
cmd.addArg(x);
|
||||
}
|
||||
|
||||
|
||||
cmd.addRawArg("-Djetty.home=" + baseHome.getHome());
|
||||
cmd.addRawArg("-Djetty.base=" + baseHome.getBase());
|
||||
|
||||
|
@ -445,11 +541,6 @@ public class StartArgs
|
|||
return modulePersistEnable;
|
||||
}
|
||||
|
||||
public boolean isModulePersistenceChanging()
|
||||
{
|
||||
return (modulePersistDisable.size() > 0) || (modulePersistEnable.size() > 0);
|
||||
}
|
||||
|
||||
public Properties getProperties()
|
||||
{
|
||||
return properties;
|
||||
|
@ -548,6 +639,11 @@ public class StartArgs
|
|||
return listModules;
|
||||
}
|
||||
|
||||
public boolean isModulePersistenceChanging()
|
||||
{
|
||||
return (modulePersistDisable.size() > 0) || (modulePersistEnable.size() > 0);
|
||||
}
|
||||
|
||||
public boolean isRun()
|
||||
{
|
||||
return run;
|
||||
|
@ -613,7 +709,7 @@ public class StartArgs
|
|||
|
||||
if (arg.startsWith("--download="))
|
||||
{
|
||||
downloads.add(getValue(arg));
|
||||
addDownload(getValue(arg));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jetty.start.StartArgs.DownloadArg;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.junit.Assert;
|
||||
|
||||
|
@ -108,7 +109,7 @@ public class ConfigurationAssert
|
|||
actualProperties.add(name + "=" + value);
|
||||
}
|
||||
assertContainsUnordered("Properties",expectedProperties,actualProperties);
|
||||
|
||||
|
||||
// Validate Downloads
|
||||
Set<String> expectedDownloads = new HashSet<>();
|
||||
for (String line : textFile)
|
||||
|
@ -119,12 +120,12 @@ public class ConfigurationAssert
|
|||
}
|
||||
}
|
||||
Set<String> actualDownloads = new HashSet<>();
|
||||
for (String line : args.getDownloads())
|
||||
for (DownloadArg darg : args.getDownloads())
|
||||
{
|
||||
actualDownloads.add(line);
|
||||
actualDownloads.add(String.format("%s:%s",darg.uri,darg.location));
|
||||
}
|
||||
assertContainsUnordered("Downloads",expectedDownloads,actualDownloads);
|
||||
|
||||
|
||||
// Validate Jvm Args / BootLib Entries
|
||||
Set<String> expectedJvmArgs = new HashSet<>();
|
||||
for (String line : textFile)
|
||||
|
@ -140,9 +141,9 @@ public class ConfigurationAssert
|
|||
actualJvmArgs.add(line);
|
||||
}
|
||||
assertContainsUnordered("JvmArgs",expectedJvmArgs,actualJvmArgs);
|
||||
if ( expectedJvmArgs.size() > 0 )
|
||||
if (expectedJvmArgs.size() > 0)
|
||||
{
|
||||
Assert.assertTrue("exec has been turned on", args.isExec());
|
||||
Assert.assertTrue("exec has been turned on",args.isExec());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue