Skip to content

Commit

Permalink
Merge pull request #115 from dmlloyd/modules-256
Browse files Browse the repository at this point in the history
[MODULES-256] Support slotless module finder path scheme
  • Loading branch information
dmlloyd committed Nov 7, 2016
2 parents 6006d08 + a70c3c0 commit 2d45663
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 35 deletions.
21 changes: 16 additions & 5 deletions src/main/java/org/jboss/modules/JarModuleFinder.java
Expand Up @@ -93,7 +93,7 @@ public ModuleSpec findModule(final String name, final ModuleLoader delegateLoade
// invalid
continue;
}
File root = null;
File root;
try {
File path = new File(new URI(entry));
if (path.isAbsolute()) {
Expand Down Expand Up @@ -150,12 +150,14 @@ public ModuleSpec findModule(final String name, final ModuleLoader delegateLoade
builder.addDependency(DependencySpec.createLocalDependencySpec());
return builder.create();
} else {
ModuleIdentifier identifier = ModuleIdentifier.fromString(name);
String namePath = identifier.getName().replace('.', '/');
String basePath = "modules/" + namePath + "/" + identifier.getSlot();
String basePath = "modules/" + toPathString(name);
JarEntry moduleXmlEntry = jarFile.getJarEntry(basePath + "/module.xml");
if (moduleXmlEntry == null) {
return null;
basePath = "modules/" + toLegacyPathString(name);
moduleXmlEntry = jarFile.getJarEntry(basePath + "/module.xml");
if (moduleXmlEntry == null) {
return null;
}
}
ModuleSpec moduleSpec;
try {
Expand All @@ -171,4 +173,13 @@ public ModuleSpec findModule(final String name, final ModuleLoader delegateLoade
return moduleSpec;
}
}

private static String toPathString(String moduleName) {
return moduleName.replace('.', '/') + '/' + moduleName;
}

private static String toLegacyPathString(String moduleName) {
final ModuleIdentifier moduleIdentifier = ModuleIdentifier.fromString(moduleName);
return moduleIdentifier.getName().replace('.', '/') + '/' + moduleIdentifier.getSlot();
}
}
60 changes: 30 additions & 30 deletions src/main/java/org/jboss/modules/LocalModuleFinder.java
Expand Up @@ -129,41 +129,36 @@ private static File[] getFiles(final String modulePath, final int stringIdx, fin
return files;
}

private static String toPathString(ModuleIdentifier moduleIdentifier) {
final StringBuilder builder = new StringBuilder(40);
builder.append(moduleIdentifier.getName().replace('.', File.separatorChar));
builder.append(File.separatorChar).append(moduleIdentifier.getSlot());
builder.append(File.separatorChar);
private static String toPathString(String moduleName) {
return moduleName.replace('.', File.separatorChar) + File.separatorChar + moduleName;
}

private static String toLegacyPathString(String moduleName) {
final ModuleIdentifier moduleIdentifier = ModuleIdentifier.fromString(moduleName);
final String name = moduleIdentifier.getName();
final String slot = moduleIdentifier.getSlot();
final StringBuilder builder = new StringBuilder(name.length() + slot.length() + 2);
builder.append(name.replace('.', File.separatorChar));
builder.append(File.separatorChar).append(slot);
return builder.toString();
}

public ModuleSpec findModule(final String name, final ModuleLoader delegateLoader) throws ModuleLoadException {
final String child = toPathString(ModuleIdentifier.fromString(name));
if (pathFilter.accept(child)) {
final String child1 = toPathString(name);
final String child2 = toLegacyPathString(name);
final PathFilter pathFilter = this.pathFilter;
if (pathFilter.accept(child1 + "/") || pathFilter.accept(child2 + "/")) {
try {
return doPrivileged((PrivilegedExceptionAction<ModuleSpec>) () -> {
for (File root : repoRoots) {
final File file = new File(root, child);
final File moduleXml = new File(file, "module.xml");
if (moduleXml.exists()) {
final ModuleSpec spec = ModuleXmlParser.parseModuleXml(delegateLoader, name, file, moduleXml);
if (spec == null) break;
return spec;
}
}
return null;
}, accessControlContext);
return doPrivileged((PrivilegedExceptionAction<ModuleSpec>) () -> parseModuleXmlFile(name, delegateLoader, repoRoots), accessControlContext);
} catch (PrivilegedActionException e) {
try {
throw e.getException();
} catch (RuntimeException e1) {
throw e1;
} catch (ModuleLoadException e1) {
throw e.getCause();
} catch (IOException e1) {
throw new ModuleLoadException(e1);
} catch (RuntimeException | Error | ModuleLoadException e1) {
throw e1;
} catch (Error e1) {
throw e1;
} catch (Exception e1) {
throw new UndeclaredThrowableException(e1);
} catch (Throwable t) {
throw new UndeclaredThrowableException(t);
}
}
}
Expand Down Expand Up @@ -197,10 +192,15 @@ public static ModuleSpec parseModuleXmlFile(final ModuleIdentifier identifier, f
* @throws ModuleLoadException if creating the module specification failed (e.g. due to a parse error)
*/
public static ModuleSpec parseModuleXmlFile(final String name, final ModuleLoader delegateLoader, final File... roots) throws IOException, ModuleLoadException {
final String child = toPathString(ModuleIdentifier.fromString(name));
final String child1 = toPathString(name);
final String child2 = toLegacyPathString(name);
for (File root : roots) {
final File file = new File(root, child);
final File moduleXml = new File(file, "module.xml");
File file = new File(root, child1);
File moduleXml = new File(file, "module.xml");
if (! moduleXml.exists()) {
file = new File(root, child2);
moduleXml = new File(file, "module.xml");
}
if (moduleXml.exists()) {
final ModuleSpec spec = ModuleXmlParser.parseModuleXml(delegateLoader, name, file, moduleXml);
if (spec == null) break;
Expand Down

0 comments on commit 2d45663

Please sign in to comment.