424598 - Module [npn] downloads wrong npn jar

+ Separating Module logical name from file system reference name
+ [depend] references in *.mod files are tried as file system reference
  names, then logical names.
+ --module=<name> are tried only as logical names.
+ All of the npn/npn-${jvm.version}.mod files are defined as logical
  name of npn-boot
This commit is contained in:
Joakim Erdfelt 2014-01-06 09:52:01 -07:00
parent 658c2ce762
commit 7af87b4a04
33 changed files with 215 additions and 51 deletions

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.3.v20130313/npn-boot-1.1.3.v20130313.jar:lib/npn/npn-boot-1.1.3.v20130313.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.3.v20130313/npn-boot-1.1.3.v20130313.jar:lib/npn/npn-boot-1.1.3.v20130313.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.4.v20130313/npn-boot-1.1.4.v20130313.jar:lib/npn/npn-boot-1.1.4.v20130313.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.5.v20130313/npn-boot-1.1.5.v20130313.jar:lib/npn/npn-boot-1.1.5.v20130313.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.5.v20130313/npn-boot-1.1.5.v20130313.jar:lib/npn/npn-boot-1.1.5.v20130313.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.5.v20130313/npn-boot-1.1.5.v20130313.jar:lib/npn/npn-boot-1.1.5.v20130313.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.5.v20130313/npn-boot-1.1.5.v20130313.jar:lib/npn/npn-boot-1.1.5.v20130313.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.0.v20120525/npn-boot-1.1.0.v20120525.jar:lib/npn/npn-boot-1.1.0.v20120525.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.6.v20130911/npn-boot-1.1.6.v20130911.jar:lib/npn/npn-boot-1.1.6.v20130911.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.6.v20130911/npn-boot-1.1.6.v20130911.jar:lib/npn/npn-boot-1.1.6.v20130911.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.0.v20120525/npn-boot-1.1.0.v20120525.jar:lib/npn/npn-boot-1.1.0.v20120525.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.1.v20121030/npn-boot-1.1.1.v20121030.jar:lib/npn/npn-boot-1.1.1.v20121030.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.1.v20121030/npn-boot-1.1.1.v20121030.jar:lib/npn/npn-boot-1.1.1.v20121030.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.3.v20130313/npn-boot-1.1.3.v20130313.jar:lib/npn/npn-boot-1.1.3.v20130313.jar

View File

@ -102,6 +102,9 @@ public class NpnModuleTest
Module mod = new Module(basehome,modFile);
assertNotNull("module",mod);
// Validate logical name
assertThat("Module name",mod.getName(),is("npn-boot"));
List<String> expectedBootClasspath = new ArrayList<>();
for (String line : mod.getFiles())

View File

@ -169,6 +169,18 @@ public class FS
}
}
public static void ensureDirectoryWritable(File dir) throws IOException
{
if (!dir.exists())
{
throw new IOException("Directory does not exist: " + dir.getAbsolutePath());
}
if (!dir.canWrite())
{
throw new IOException("Unable to write to directory: " + dir.getAbsolutePath());
}
}
public static boolean isFile(File file)
{
if (file == null)

View File

@ -387,21 +387,23 @@ public class Main
else
{
// Create the directory if needed
if (!start_d.exists())
FS.ensureDirectoryExists(start_d);
FS.ensureDirectoryWritable(start_d);
try
{
start_d.mkdirs();
}
if (!start_d.isDirectory() || !start_d.canWrite())
{
StartLog.warn("ERROR: Bad start.d %s! ",start_d);
return;
}
// Create a new ini file for it
if (!ini.createNewFile())
{
StartLog.warn("ERROR: %s cannot be initialised in %s! ",name,short_ini);
return;
}
}
catch (IOException e)
{
StartLog.warn("ERROR: Unable to create %s!",ini);
StartLog.warn(e);
return;
}
source = short_ini;
StartLog.info("%-15s initialised in %s (created)",name,source);
out = new PrintWriter(ini);

View File

@ -54,8 +54,8 @@ public class Module
return diff;
}
// then by name (not really needed, but makes for predictable test cases)
CollationKey k1 = collator.getCollationKey(o1.name);
CollationKey k2 = collator.getCollationKey(o2.name);
CollationKey k1 = collator.getCollationKey(o1.fileRef);
CollationKey k2 = collator.getCollationKey(o2.fileRef);
return k1.compareTo(k2);
}
}
@ -68,16 +68,20 @@ public class Module
public int compare(Module o1, Module o2)
{
// by name (not really needed, but makes for predictable test cases)
CollationKey k1 = collator.getCollationKey(o1.name);
CollationKey k2 = collator.getCollationKey(o2.name);
CollationKey k1 = collator.getCollationKey(o1.fileRef);
CollationKey k2 = collator.getCollationKey(o2.fileRef);
return k1.compareTo(k2);
}
}
/** The file of the module */
private File file;
/** The name of this Module */
private String name;
/** The name of this Module (as a filesystem reference) */
private String fileRef;
/**
* The logical name of this module (for property selected references), And to aid in duplicate detection.
*/
private String logicalName;
/** The depth of the module in the tree */
private int depth = 0;
/** List of Modules, by name, that this Module depends on */
@ -106,9 +110,9 @@ public class Module
{
this.file = file;
String name = file.getName();
// Strip .ini
name = Pattern.compile(".mod$",Pattern.CASE_INSENSITIVE).matcher(name).replaceFirst("");
// Strip .mod
this.fileRef = Pattern.compile(".mod$",Pattern.CASE_INSENSITIVE).matcher(file.getName()).replaceFirst("");
this.logicalName = fileRef;
init(basehome);
process(basehome);
@ -160,14 +164,14 @@ public class Module
return false;
}
Module other = (Module)obj;
if (name == null)
if (fileRef == null)
{
if (other.name != null)
if (other.fileRef != null)
{
return false;
}
}
else if (!name.equals(other.name))
else if (!fileRef.equals(other.fileRef))
{
return false;
}
@ -201,6 +205,11 @@ public class Module
return files;
}
public String getFilesystemRef()
{
return fileRef;
}
public List<String> getInitialise()
{
return initialise;
@ -213,7 +222,7 @@ public class Module
public String getName()
{
return name;
return logicalName;
}
public Set<String> getOptionalParentNames()
@ -246,7 +255,7 @@ public class Module
{
final int prime = 31;
int result = 1;
result = (prime * result) + ((name == null)?0:name.hashCode());
result = (prime * result) + ((fileRef == null)?0:fileRef.hashCode());
return result;
}
@ -254,14 +263,15 @@ public class Module
{
String name = basehome.toShortForm(file);
// Find name
// Find module system name (usually in the form of a filesystem reference)
Pattern pat = Pattern.compile("^.*[/\\\\]{1}modules[/\\\\]{1}(.*).mod$",Pattern.CASE_INSENSITIVE);
Matcher mat = pat.matcher(name);
if (!mat.find())
{
throw new RuntimeException("Invalid Module location (must be located under /modules/ directory): " + name);
}
this.name = mat.group(1).replace('\\','/');
this.fileRef = mat.group(1).replace('\\','/');
this.logicalName = this.fileRef;
parentNames = new HashSet<>();
optionalParentNames = new HashSet<>();
@ -321,6 +331,9 @@ public class Module
case "":
// ignore (this would be entries before first section)
break;
case "NAME":
logicalName = line;
break;
case "DEPEND":
parentNames.add(line);
break;
@ -359,11 +372,22 @@ public class Module
this.enabled = enabled;
}
public void setParentNames(Set<String> parents)
{
this.parentNames.clear();
this.parentEdges.clear();
if (parents != null)
{
this.parentNames.addAll(parents);
}
}
@Override
public String toString()
{
StringBuilder str = new StringBuilder();
str.append("Module[").append(name);
str.append("Module[").append(logicalName);
str.append(",").append(fileRef);
if (enabled)
{
str.append(",enabled");

View File

@ -322,9 +322,10 @@ public class Modules implements Iterable<Module>
return xmls;
}
public void register(Module module)
public Module register(Module module)
{
modules.put(module.getName(),module);
return module;
}
public void registerAll(BaseHome basehome, StartArgs args) throws IOException
@ -335,15 +336,35 @@ public class Modules implements Iterable<Module>
}
// load missing post-expanded dependent modules
String missingParent;
while ((missingParent = nextMissingParent()) != null)
boolean done = false;
while (!done)
{
File file = basehome.getFile("modules/" + missingParent + ".mod");
registerModule(basehome,args,file);
done = true;
Set<String> missingParents = new HashSet<>();
for (Module m : modules.values())
{
for (String parent : m.getParentNames())
{
if (modules.containsKey(parent))
{
continue; // found. skip it.
}
done = false;
missingParents.add(parent);
}
}
private void registerModule(BaseHome basehome, StartArgs args, File file) throws FileNotFoundException, IOException
for (String missingParent : missingParents)
{
File file = basehome.getFile("modules/" + missingParent + ".mod");
Module module = registerModule(basehome,args,file);
updateParentReferencesTo(module);
}
}
}
private Module registerModule(BaseHome basehome, StartArgs args, File file) throws FileNotFoundException, IOException
{
if (!FS.canReadFile(file))
{
@ -352,24 +373,7 @@ public class Modules implements Iterable<Module>
StartLog.debug("Registering Module: %s",basehome.toShortForm(file));
Module module = new Module(basehome,file);
module.expandProperties(args.getProperties());
register(module);
}
private String nextMissingParent()
{
for (Module module : modules.values())
{
for (String parent : module.getParentNames())
{
if (modules.containsKey(parent))
{
continue; // found. skip it.
}
return parent;
}
}
return null;
return register(module);
}
public Set<String> resolveChildModulesOf(String moduleName)
@ -417,4 +421,39 @@ public class Modules implements Iterable<Module>
Arrays.fill(indent,' ');
return new String(indent);
}
/**
* Modules can have a different logical name than to their filesystem reference. This updates existing references to the filesystem form to use the logical
* name form.
*
* @param module
* the module that might have other modules referring to it.
*/
private void updateParentReferencesTo(Module module)
{
if (module.getName().equals(module.getFilesystemRef()))
{
// nothing to do, its sane already
return;
}
for (Module m : modules.values())
{
Set<String> resolvedParents = new HashSet<>();
for (String parent : m.getParentNames())
{
if (parent.equals(module.getFilesystemRef()))
{
// use logical name instead
resolvedParents.add(module.getName());
}
else
{
// use name as-is
resolvedParents.add(parent);
}
}
m.setParentNames(resolvedParents);
}
}
}

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.3.v20130313/npn-boot-1.1.3.v20130313.jar:lib/npn/npn-boot-1.1.3.v20130313.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.3.v20130313/npn-boot-1.1.3.v20130313.jar:lib/npn/npn-boot-1.1.3.v20130313.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.4.v20130313/npn-boot-1.1.4.v20130313.jar:lib/npn/npn-boot-1.1.4.v20130313.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.5.v20130313/npn-boot-1.1.5.v20130313.jar:lib/npn/npn-boot-1.1.5.v20130313.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.5.v20130313/npn-boot-1.1.5.v20130313.jar:lib/npn/npn-boot-1.1.5.v20130313.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.5.v20130313/npn-boot-1.1.5.v20130313.jar:lib/npn/npn-boot-1.1.5.v20130313.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.5.v20130313/npn-boot-1.1.5.v20130313.jar:lib/npn/npn-boot-1.1.5.v20130313.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.0.v20120525/npn-boot-1.1.0.v20120525.jar:lib/npn/npn-boot-1.1.0.v20120525.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.6.v20130911/npn-boot-1.1.6.v20130911.jar:lib/npn/npn-boot-1.1.6.v20130911.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.6.v20130911/npn-boot-1.1.6.v20130911.jar:lib/npn/npn-boot-1.1.6.v20130911.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.0.v20120525/npn-boot-1.1.0.v20120525.jar:lib/npn/npn-boot-1.1.0.v20120525.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.1.v20121030/npn-boot-1.1.1.v20121030.jar:lib/npn/npn-boot-1.1.1.v20121030.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.1.v20121030/npn-boot-1.1.1.v20121030.jar:lib/npn/npn-boot-1.1.1.v20121030.jar

View File

@ -1,3 +1,6 @@
[name]
npn-boot
[files]
http://central.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/1.1.3.v20130313/npn-boot-1.1.3.v20130313.jar:lib/npn/npn-boot-1.1.3.v20130313.jar