434505 Allow property files on start.jar command line

Signed-off-by: Tom Zeller<tzeller@dragonacea.biz>

(cherry picked from commit d621df3c34)

Conflicts:
	jetty-start/src/main/java/org/eclipse/jetty/start/FS.java
	jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java
This commit is contained in:
Greg Wilkins 2014-05-13 12:04:10 +02:00
parent fb2010177c
commit 51324a2786
3 changed files with 63 additions and 1 deletions

View File

@ -120,7 +120,17 @@ public class FS
{
return filename.toLowerCase(Locale.ENGLISH).endsWith(".xml");
}
public static String toRelativePath(File baseDir, File path)
{
return baseDir.toURI().relativize(path.toURI()).toASCIIString();
}
public static boolean isPropertyFile(String filename)
{
return filename.toLowerCase(Locale.ENGLISH).endsWith(".properties");
}
public static String separators(String path)
{
StringBuilder ret = new StringBuilder();

View File

@ -593,6 +593,9 @@ public class Main
// ------------------------------------------------------------
// 6) Resolve Extra XMLs
args.resolveExtraXmls(baseHome);
// 9) Resolve Property Files
args.resolvePropertyFiles(baseHome);
return args;
}

View File

@ -88,6 +88,12 @@ public class StartArgs
/** List of all xml references found directly on command line or start.ini */
private List<String> xmlRefs = new ArrayList<>();
/** List of all property references found directly on command line or start.ini */
private List<String> propertyFileRefs = new ArrayList<>();
/** List of all property files */
private List<Path> propertyFiles = new ArrayList<>();
private Props properties = new Props();
private Set<String> systemPropertyKeys = new HashSet<>();
private List<String> rawLibs = new ArrayList<>();
@ -149,6 +155,19 @@ public class StartArgs
xmls.add(xmlfile);
}
}
private void addUniquePropertyFile(String propertyFileRef, Path propertyFile) throws IOException
{
if (!FS.canReadFile(propertyFile))
{
throw new IOException("Cannot read file: " + propertyFileRef);
}
propertyFile = FS.toRealPath(propertyFile);
if (!propertyFiles.contains(propertyFile))
{
propertyFiles.add(propertyFile);
}
}
public void dumpActiveXmls(BaseHome baseHome)
{
@ -506,6 +525,11 @@ public class StartArgs
{
cmd.addRawArg(xml.toAbsolutePath().toString());
}
for (Path propertyFile : propertyFiles)
{
cmd.addRawArg(propertyFile.toAbsolutePath().toString());
}
return cmd;
}
@ -844,6 +868,16 @@ public class StartArgs
}
return;
}
if (FS.isPropertyFile(arg))
{
// only add non-duplicates
if (!propertyFileRefs.contains(arg))
{
propertyFileRefs.add(arg);
}
return;
}
// Anything else is unrecognized
throw new UsageException(ERR_BAD_ARG,"Unrecognized argument: \"%s\" in %s",arg,source);
@ -863,6 +897,21 @@ public class StartArgs
addUniqueXmlFile(xmlRef,xmlfile);
}
}
public void resolvePropertyFiles(BaseHome baseHome) throws IOException
{
// Find and Expand property files
for (String propertyFileRef : propertyFileRefs)
{
// Straight Reference
Path propertyFile = baseHome.getPath(propertyFileRef);
if (!FS.exists(propertyFile))
{
propertyFile = baseHome.getPath("etc/" + propertyFileRef);
}
addUniquePropertyFile(propertyFileRef,propertyFile);
}
}
public void setAllModules(Modules allModules)
{