Fixed start.jar handling of expanded modules during --add-to-start

This commit is contained in:
Greg Wilkins 2014-04-04 14:09:46 +11:00
parent f9e2f1d6bc
commit cf430665b5
4 changed files with 74 additions and 15 deletions

View File

@ -41,8 +41,10 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -333,7 +335,7 @@ public class Main
}
private void moduleIni(StartArgs args, String name, boolean topLevel, boolean appendStartIni) throws IOException
{
{
// Find the start.d relative to the base directory only.
File start_d = baseHome.getBaseFile("start.d");
@ -457,7 +459,9 @@ public class Main
{
StartLog.info("%-15s initialised in %s",name,short_ini);
}
else
StartLog.info("%-15s initialised transitively",name);
// Also list other places this module is enabled
for (String source : module.getSources())
{
@ -473,23 +477,57 @@ public class Main
initFile(new FileArg(file));
}
// Process dependencies from top level only
// Process dependencies
module.expandProperties(args.getProperties());
modules.registerParentsIfMissing(baseHome,args,module);
modules.buildGraph();
// process new ini modules
if (topLevel)
{
List<Module> parents = new ArrayList<>();
for (String parent : modules.resolveParentModulesOf(name))
List<Module> depends = new ArrayList<>();
for (String depend : modules.resolveParentModulesOf(name))
{
if (!name.equals(parent))
if (!name.equals(depend))
{
Module m = modules.get(parent);
Module m = modules.get(depend);
m.setEnabled(true);
parents.add(m);
depends.add(m);
}
}
Collections.sort(parents,Collections.reverseOrder(new Module.DepthComparator()));
for (Module m : parents)
Collections.sort(depends,Collections.reverseOrder(new Module.DepthComparator()));
Set<String> done = new HashSet<>(0);
while (true)
{
moduleIni(args,m.getName(),false,appendStartIni);
// initialize known dependencies
boolean complete=true;
for (Module m : depends)
{
if (!done.contains(m.getName()))
{
complete=false;
moduleIni(args,m.getName(),false,appendStartIni);
done.add(m.getName());
}
}
if (complete)
break;
// look for any new ones resolved via expansion
depends.clear();
for (String depend : modules.resolveParentModulesOf(name))
{
if (!name.equals(depend))
{
Module m = modules.get(depend);
m.setEnabled(true);
depends.add(m);
}
}
Collections.sort(depends,Collections.reverseOrder(new Module.DepthComparator()));
}
}
}
@ -644,13 +682,13 @@ public class Main
}
}
// Initialize
// Initialize start.ini
for (String module : args.getModuleStartIni())
{
moduleIni(args,module,true,true);
}
// Initialize
// Initialize start.d
for (String module : args.getModuleStartdIni())
{
moduleIni(args,module,true,false);

View File

@ -118,7 +118,10 @@ public class Modules implements Iterable<Module>
if (parent == null)
{
StartLog.debug("module not found [%s]%n",parentName);
if (parentName.contains("${"))
StartLog.debug("module not found [%s]%n",parentName);
else
StartLog.warn("module not found [%s]%n",parentName);
}
else
{
@ -370,6 +373,23 @@ public class Modules implements Iterable<Module>
return module;
}
public void registerParentsIfMissing(BaseHome basehome, StartArgs args, Module module) throws IOException
{
for (String name : module.getParentNames())
{
if (!modules.containsKey(name))
{
File file = basehome.getFile("modules/" + name + ".mod");
if (FS.canReadFile(file))
{
Module parent = registerModule(basehome,args,file);
updateParentReferencesTo(parent);
registerParentsIfMissing(basehome, args, parent);
}
}
}
}
public void registerAll(BaseHome basehome, StartArgs args) throws IOException
{
for (Path path : basehome.getPaths("modules/*.mod"))

View File

@ -131,7 +131,7 @@ public final class Props implements Iterable<Prop>
if (value == null)
{
StartLog.debug("Unable to expand: %s",property);
expanded.append(property);
expanded.append(mat.group(1));
}
else
{

View File

@ -91,6 +91,7 @@ public class PropsTest
assertThat(props.expand("port=8080"),is("port=8080"));
assertThat(props.expand("jdk=${java.version}"),is("jdk=" + System.getProperty("java.version")));
assertThat(props.expand("id=${name}-${version}"),is("id=jetty-9.1"));
assertThat(props.expand("id=${unknown}-${wibble}"),is("id=${unknown}-${wibble}"));
}
@Test