[Git][java-team/jboss-modules][upstream] New upstream version 1.10.0
Markus Koschany
gitlab at salsa.debian.org
Fri Mar 6 00:23:46 GMT 2020
Markus Koschany pushed to branch upstream at Debian Java Maintainers / jboss-modules
Commits:
0427e090 by Markus Koschany at 2020-03-06T01:16:03+01:00
New upstream version 1.10.0
- - - - -
14 changed files:
- pom.xml
- src/main/java/org/jboss/modules/IterableModuleFinder.java
- src/main/java/org/jboss/modules/JarFileResourceLoader.java
- src/main/java/org/jboss/modules/LocalModuleFinder.java
- src/main/java/org/jboss/modules/Main.java
- + src/main/java/org/jboss/modules/ModularAgent.java
- src/main/java/org/jboss/modules/ModuleLoader.java
- src/main/java/org/jboss/modules/PathResourceLoader.java
- + src/test/java/org/jboss/modules/MODULES_377_Test.java
- + src/test/java/org/jboss/modules/MavenResource2Test.java
- src/test/java/org/jboss/modules/MavenResourceTest.java
- src/test/java/org/jboss/modules/PathResourceLoaderTest.java
- + src/test/java/org/jboss/modules/SymlinkResourceLoaderTest.java
- + src/test/resources/test/MODULES_377/local/tests/module/main/module.xml
Changes:
=====================================
pom.xml
=====================================
@@ -23,13 +23,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.modules</groupId>
<artifactId>jboss-modules</artifactId>
- <version>1.9.2.Final</version>
+ <version>1.10.0.Final</version>
<name>JBoss Modules</name>
<parent>
<groupId>org.jboss</groupId>
<artifactId>jboss-parent</artifactId>
- <version>32</version>
+ <version>36</version>
</parent>
<licenses>
@@ -222,6 +222,10 @@
<Multi-Release>true</Multi-Release>
<Jar-Version>${project.version}</Jar-Version>
<Jar-Name>${project.artifactId}</Jar-Name>
+ <Agent-Class>org.jboss.modules.ModularAgent</Agent-Class>
+ <Premain-Class>org.jboss.modules.ModularAgent</Premain-Class>
+ <Can-Redefine-Classes>true</Can-Redefine-Classes>
+ <Can-Retransform-Classes>true</Can-Retransform-Classes>
</manifestEntries>
</archive>
</configuration>
=====================================
src/main/java/org/jboss/modules/IterableModuleFinder.java
=====================================
@@ -35,7 +35,7 @@ public interface IterableModuleFinder extends ModuleFinder {
* @param recursive {@code true} to find recursively nested modules, {@code false} to only find immediately nested
* modules
* @return an iterator for the modules in this module finder
- * @deprecated Use {@link #iterateModules(String, boolean)} instead.
+ * @deprecated Use {@link #iterateModules(String, boolean, ModuleLoader)} instead.
*/
default Iterator<ModuleIdentifier> iterateModules(ModuleIdentifier baseIdentifier, boolean recursive) {
return Collections.emptyIterator();
@@ -49,8 +49,13 @@ public interface IterableModuleFinder extends ModuleFinder {
* @param recursive {@code true} to find recursively nested modules, {@code false} to only find immediately nested
* modules; ignored if this module finder does not have a concept of nested modules
* @return an iterator for the modules in this module finder
+ * @deprecated Use {@link #iterateModules(String, boolean, ModuleLoader)} instead.
*/
default Iterator<String> iterateModules(String baseName, boolean recursive) {
+ return iterateModules(baseName, recursive, null);
+ }
+
+ default Iterator<String> iterateModules(String baseName, boolean recursive, final ModuleLoader delegateLoader) {
return IteratorUtils.transformingIterator(iterateModules(baseName == null ? null : ModuleIdentifier.fromString(baseName), recursive), ModuleIdentifier::toString);
}
}
=====================================
src/main/java/org/jboss/modules/JarFileResourceLoader.java
=====================================
@@ -18,15 +18,10 @@
package org.jboss.modules;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -45,12 +40,9 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
-import java.util.TreeSet;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
import static java.security.AccessController.doPrivileged;
@@ -61,8 +53,6 @@ import static java.security.AccessController.doPrivileged;
* @author <a href="mailto:ropalka at redhat.com">Richard Opalka</a>
*/
final class JarFileResourceLoader extends AbstractResourceLoader implements IterableResourceLoader {
- private static final String INDEX_FILE = "META-INF/PATHS.LIST";
-
private final JarFile jarFile;
private final String rootName;
private final URL rootUrl;
@@ -314,19 +304,6 @@ final class JarFileResourceLoader extends AbstractResourceLoader implements Iter
public Collection<String> getPaths() {
final Collection<String> index = new HashSet<String>();
index.add("");
- String relativePath = this.relativePath;
- // First check for an external index
- final JarFile jarFile = this.jarFile;
- // Next check for an internal index
- JarEntry listEntry = jarFile.getJarEntry(INDEX_FILE);
- if (listEntry != null) {
- try {
- return readIndex(jarFile.getInputStream(listEntry), index, relativePath);
- } catch (IOException e) {
- index.clear();
- }
- }
- // Next just read the JAR
extractJarPaths(jarFile, relativePath, index);
return index;
}
@@ -358,8 +335,7 @@ final class JarFileResourceLoader extends AbstractResourceLoader implements Iter
return new JarFileResourceLoader(rootName, jarFile, ourRelativePath == null ? fixedPath : ourRelativePath + "/" + fixedPath);
}
- static void extractJarPaths(final JarFile jarFile, String relativePath,
- final Collection<String> index) {
+ static void extractJarPaths(final JarFile jarFile, String relativePath, final Collection<String> index) {
index.add("");
final Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
@@ -382,105 +358,6 @@ final class JarFileResourceLoader extends AbstractResourceLoader implements Iter
}
}
- static void writeExternalIndex(final File indexFile,
- final Collection<String> index) {
- // Now try to write it
- boolean ok = false;
- try {
- try (final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(indexFile)))) {
- for (String name : index) {
- writer.write(name);
- writer.write('\n');
- }
- writer.close();
- ok = true;
- }
- } catch (IOException e) {
- // failed, ignore
- } finally {
- if (! ok) {
- // well, we tried...
- indexFile.delete();
- }
- }
- }
-
- static Collection<String> readIndex(final InputStream stream, final Collection<String> index, final String relativePath) throws IOException {
- final BufferedReader r = new BufferedReader(new InputStreamReader(stream));
- try {
- String s;
- while ((s = r.readLine()) != null) {
- String name = s.trim();
- if (relativePath == null) {
- index.add(name);
- } else {
- if (name.startsWith(relativePath + "/")) {
- index.add(name.substring(relativePath.length() + 1));
- }
- }
- }
- return index;
- } finally {
- // if exception is thrown, undo index creation
- r.close();
- }
- }
-
- static void addInternalIndex(File file, boolean modify) throws IOException {
- try (final JarFile oldJarFile = JDKSpecific.getJarFile(file, false)) {
- final Collection<String> index = new TreeSet<String>();
- final File outputFile;
-
- outputFile = new File(file.getAbsolutePath().replace(".jar", "-indexed.jar"));
-
- try (final ZipOutputStream zo = new ZipOutputStream(new FileOutputStream(outputFile))) {
- Enumeration<JarEntry> entries = oldJarFile.entries();
- while (entries.hasMoreElements()) {
- final JarEntry entry = entries.nextElement();
-
- // copy data, unless we're replacing the index
- if (!entry.getName().equals(INDEX_FILE)) {
- final JarEntry clone = (JarEntry) entry.clone();
- // Compression level and format can vary across implementations
- if (clone.getMethod() != ZipEntry.STORED)
- clone.setCompressedSize(-1);
- zo.putNextEntry(clone);
- Utils.copy(oldJarFile.getInputStream(entry), zo);
- }
-
- // add to the index
- final String name = entry.getName();
- final int idx = name.lastIndexOf('/');
- if (idx == -1) continue;
- final String path = name.substring(0, idx);
- if (path.length() == 0 || path.endsWith("/")) {
- // invalid name, just skip...
- continue;
- }
- index.add(path);
- }
-
- // write index
- zo.putNextEntry(new ZipEntry(INDEX_FILE));
- try (final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(zo))) {
- for (final String name : index) {
- writer.write(name);
- writer.write('\n');
- }
- }
- zo.close();
- oldJarFile.close();
-
- if (modify) {
- file.delete();
- if (!outputFile.renameTo(file)) {
- throw new IOException("failed to rename " + outputFile.getAbsolutePath() + " to " + file.getAbsolutePath());
- }
- }
- }
- }
- }
-
private static final CodeSigners EMPTY_CODE_SIGNERS = new CodeSigners(new CodeSigner[0]);
static final class CodeSigners {
=====================================
src/main/java/org/jboss/modules/LocalModuleFinder.java
=====================================
@@ -264,7 +264,7 @@ public final class LocalModuleFinder implements IterableModuleFinder, AutoClosea
}
};
- public Iterator<String> iterateModules(final String baseName, final boolean recursive) {
+ public Iterator<String> iterateModules(final String baseName, final boolean recursive, final ModuleLoader delegateLoader) {
return new Iterator<String>() {
private final Iterator<File> rootIter = Arrays.asList(repoRoots).iterator();
private final Set<String> found = new HashSet<>();
@@ -296,7 +296,7 @@ public final class LocalModuleFinder implements IterableModuleFinder, AutoClosea
continue;
}
try (InputStream stream = Files.newInputStream(nextPath)) {
- final ModuleSpec moduleSpec = ModuleXmlParser.parseModuleXml(ModuleXmlParser.ResourceRootFactory.getDefault(), nextPath.getParent().toString(), stream, nextPath.toString(), null, (String)null);
+ final ModuleSpec moduleSpec = ModuleXmlParser.parseModuleXml(ModuleXmlParser.ResourceRootFactory.getDefault(), nextPath.getParent().toString(), stream, nextPath.toString(), delegateLoader, (String)null);
this.next = moduleSpec.getName();
if (found.add(this.next)) {
return true;
=====================================
src/main/java/org/jboss/modules/Main.java
=====================================
@@ -26,8 +26,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
+import java.lang.instrument.Instrumentation;
import java.lang.management.ManagementFactory;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -47,6 +49,8 @@ import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.logging.LogManager;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
import java.util.prefs.Preferences;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -74,6 +78,8 @@ public final class Main {
private static final String[] NO_STRINGS = new String[0];
+ static volatile Instrumentation instrumentation;
+
private Main() {
}
@@ -82,7 +88,6 @@ public final class Main {
System.out.println(" java [-jvmoptions...] -jar " + getJarName() + ".jar [-options...] -jar <jar-name> [args...]");
System.out.println(" java [-jvmoptions...] -jar " + getJarName() + ".jar [-options...] -cp <class-path> <class-name> [args...]");
System.out.println(" java [-jvmoptions...] -jar " + getJarName() + ".jar [-options...] -class <class-name> [args...]");
- System.out.println(" java [-jvmoptions...] -jar " + getJarName() + ".jar -addindex [-modify] <jar-name> ");
System.out.println("where <module-spec> is a valid module specification string");
System.out.println("and options include:");
System.out.println(" -help Display this message");
@@ -100,6 +105,8 @@ public final class Main {
System.out.println(" -debuglog Enable debug mode output to System.out during bootstrap before any logging manager is installed");
System.out.println(" -jar Specify that the final argument is the name of a");
System.out.println(" JAR file to run as a module; not compatible with -class");
+ System.out.println(" -javaagent:agent.jar");
+ System.out.println(" Add a Java agent that can load modules");
System.out.println(" -jaxpmodule <module-spec>");
System.out.println(" The default JAXP implementation to use of the JDK");
System.out.println(" -secmgr Run with a security manager installed; not compatible with -secmgrmodule");
@@ -107,9 +114,6 @@ public final class Main {
System.out.println(" Run with a security manager module; not compatible with -secmgr");
System.out.println(" -add-provider <module-name>[/<class-name>]");
System.out.println(" Add a security provider of the given module and class (can be given more than once)");
- System.out.println(" -addindex Specify that the final argument is a");
- System.out.println(" jar to create an index for");
- System.out.println(" -modify Modify the indexes jar in-place");
System.out.println(" -version Print version and exit\n");
}
@@ -134,9 +138,8 @@ public final class Main {
String jaxpModuleName = null;
boolean defaultSecMgr = false;
String secMgrModule = null;
- boolean addIndex = false;
- boolean modifyInPlace = false;
boolean debuglog = false;
+ final List<String> agentJars = new ArrayList<>();
final List<String> addedProviders = new ArrayList<>();
for (int i = 0; i < argsLen; i++) {
final String arg = args[i];
@@ -149,10 +152,6 @@ public final class Main {
} else if ("-help".equals(arg)) {
usage();
return;
- } else if ("-addindex".equals(arg)) {
- addIndex = true;
- } else if ("-modify".equals(arg)) {
- modifyInPlace = true;
} else if ("-modulepath".equals(arg) || "-mp".equals(arg)) {
if (modulePath != null) {
System.err.println("Module path may only be specified once");
@@ -184,6 +183,7 @@ public final class Main {
} else if ("-debuglog".equals(arg)) {
debuglog = true;
} else if ("-jaxpmodule".equals(arg)) {
+ System.err.println("WARNING: -jaxpmodule is deprecated and may be removed in a future release");
jaxpModuleName = args[++i];
} else if ("-jar".equals(arg)) {
if (jar) {
@@ -247,9 +247,6 @@ public final class Main {
System.exit(1);
}
classDefined = true;
- } else if ("-logmodule".equals(arg)) {
- System.err.println("WARNING: -logmodule is deprecated. Please use the system property 'java.util.logging.manager' or the 'java.util.logging.LogManager' service loader.");
- i++;
} else if ("-secmgr".equals(arg)) {
if (defaultSecMgr) {
System.err.println("-secmgr may only be specified once");
@@ -271,7 +268,9 @@ public final class Main {
}
secMgrModule = args[++ i];
} else if ("-add-provider".equals(arg)) {
- addedProviders.add(args[++ i]);
+ addedProviders.add(args[++i]);
+ } else if (arg.startsWith("-javaagent:")) {
+ agentJars.add(arg.substring(11));
} else {
System.err.printf("Invalid option '%s'\n", arg);
usage();
@@ -292,72 +291,6 @@ public final class Main {
}
}
- if (modifyInPlace && ! addIndex) {
- System.err.println("-modify requires -addindex");
- usage();
- System.exit(1);
- }
-
- if (addIndex) {
- System.err.println("WARNING: -addindex is deprecated and may be removed in a future release");
- if (nameArgument == null) {
- System.err.println("-addindex requires a target JAR name");
- usage();
- System.exit(1);
- }
- if (modulePath != null) {
- System.err.println("-mp may not be used with -addindex");
- usage();
- System.exit(1);
- }
- if (jaxpModuleName != null) {
- System.err.println("-jaxpModuleName may not be used with -addindex");
- usage();
- System.exit(1);
- }
- if (classpathDefined) {
- System.err.println("-cp or -classpath may not be used with -addindex");
- usage();
- System.exit(1);
- }
- if (classDefined) {
- System.err.println("-class may not be used with -addindex");
- usage();
- System.exit(1);
- }
- if (jar) {
- System.err.println("-jar may not be used with -addindex");
- usage();
- System.exit(1);
- }
- if (deps != null) {
- System.err.println("-deps may not be used with -addindex");
- usage();
- System.exit(1);
- }
- if (defaultSecMgr) {
- System.err.println("-secmgr may not be used with -addindex");
- usage();
- System.exit(1);
- }
- if (secMgrModule != null) {
- System.err.println("-secmgrmodule may not be used with -addindex");
- usage();
- System.exit(1);
- }
- if (! addedProviders.isEmpty()) {
- System.err.println("-add-provider may not be used with -addindex");
- }
- if (depTree) {
- System.err.println("-deptree may not be used with -addindex");
- usage();
- System.exit(1);
- }
-
- JarFileResourceLoader.addInternalIndex(new File(nameArgument), modifyInPlace);
- return;
- }
-
if (deps != null && ! classDefined && ! classpathDefined) {
System.err.println("-deps may only be specified when -cp/-classpath or -class is in use");
System.exit(1);
@@ -422,6 +355,7 @@ public final class Main {
}
}
Module.initBootModuleLoader(environmentLoader);
+
if (jaxpModuleName != null) {
__JAXPRedirected.changeAll(jaxpModuleName, Module.getBootModuleLoader());
} else {
@@ -527,6 +461,72 @@ public final class Main {
}
}
+ if (! agentJars.isEmpty()) {
+ final Instrumentation instrumentation = Main.instrumentation;
+ if (instrumentation == null) {
+ // we have to self-attach (todo later)
+ System.err.println("Not started in agent mode (self-attach not supported yet)");
+ usage();
+ System.exit(1);
+ }
+ final ModuleLoader agentLoader = new ModuleLoader(new FileSystemClassPathModuleFinder(loader));
+ for (String agentJar : agentJars) {
+ final Module agentModule;
+ try {
+ agentModule = agentLoader.loadModule(new File(agentJar).getAbsolutePath());
+ } catch (ModuleLoadException ex) {
+ System.err.printf("Cannot load agent JAR %s: %s", agentJar, ex);
+ System.exit(1);
+ throw new IllegalStateException();
+ }
+ final ModuleClassLoader classLoader = agentModule.getClassLoaderPrivate();
+ final InputStream is = classLoader.getResourceAsStream("META-INF/MANIFEST.MF");
+ final Manifest manifest;
+ if (is == null) {
+ System.err.printf("Agent JAR %s has no manifest", agentJar);
+ System.exit(1);
+ throw new IllegalStateException();
+ }
+ try {
+ manifest = new Manifest();
+ manifest.read(is);
+ is.close();
+ } catch (IOException e) {
+ try {
+ is.close();
+ } catch (IOException e2) {
+ e2.addSuppressed(e);
+ throw e2;
+ }
+ throw e;
+ }
+ final Attributes attributes = manifest.getMainAttributes();
+ final String preMainClassName = attributes.getValue("Premain-Class");
+ if (preMainClassName != null) {
+ final Class<?> preMainClass = Class.forName(preMainClassName, true, classLoader);
+ final Method premain;
+ try {
+ premain = preMainClass.getDeclaredMethod("premain", String.class, Instrumentation.class);
+ } catch (Exception e) {
+ System.out.printf("Failed to find premain method: %s", e);
+ System.exit(1);
+ throw new IllegalStateException();
+ }
+ try {
+ premain.invoke(null, "" /*todo*/, instrumentation);
+ } catch (InvocationTargetException e) {
+ System.out.printf("Execution of premain method failed: %s", e.getCause());
+ System.exit(1);
+ throw new IllegalStateException();
+ }
+ } else {
+ System.out.printf("Agent JAR %s has no premain method", agentJar);
+ System.exit(1);
+ throw new IllegalStateException();
+ }
+ }
+ }
+
final String mbeanServerBuilderName = getServiceName(bootClassLoader, "javax.management.MBeanServerBuilder");
if (mbeanServerBuilderName != null) {
System.setProperty("javax.management.builder.initial", mbeanServerBuilderName);
=====================================
src/main/java/org/jboss/modules/ModularAgent.java
=====================================
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2019 Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.modules;
+
+import java.lang.instrument.Instrumentation;
+
+/**
+ * The modular agent entry point.
+ */
+public final class ModularAgent {
+ public static void premain(String agentArgs, Instrumentation instrumentation) {
+ agentmain(agentArgs, instrumentation);
+ }
+
+ public static void agentmain(String agentArgs, Instrumentation instrumentation) {
+ Main.instrumentation = instrumentation;
+ }
+}
=====================================
src/main/java/org/jboss/modules/ModuleLoader.java
=====================================
@@ -341,7 +341,7 @@ public class ModuleLoader {
}
final ModuleFinder finder = finders[idx++];
if (finder instanceof IterableModuleFinder) {
- nested = ((IterableModuleFinder) finder).iterateModules(baseName, recursive);
+ nested = ((IterableModuleFinder) finder).iterateModules(baseName, recursive, ModuleLoader.this);
}
}
=====================================
src/main/java/org/jboss/modules/PathResourceLoader.java
=====================================
@@ -24,6 +24,7 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.file.FileSystems;
+import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
@@ -168,7 +169,7 @@ class PathResourceLoader extends AbstractResourceLoader implements IterableResou
} catch (InvalidPathException ignored) {
return Collections.emptyIterator();
}
- return Files.walk(path, recursive ? Integer.MAX_VALUE : 1)
+ return Files.walk(path, recursive ? Integer.MAX_VALUE : 1, FileVisitOption.FOLLOW_LINKS)
.filter(it -> !Files.isDirectory(it))
.<Resource>map(resourcePath -> new PathResource(resourcePath, PathUtils.toGenericSeparators(root.relativize(resourcePath).toString()), context))
.iterator();
@@ -180,7 +181,7 @@ class PathResourceLoader extends AbstractResourceLoader implements IterableResou
@Override
public Collection<String> getPaths() {
try {
- return doPrivilegedIfNeeded(context, IOException.class, () -> Files.walk(root)
+ return doPrivilegedIfNeeded(context, IOException.class, () -> Files.walk(root, FileVisitOption.FOLLOW_LINKS)
.filter(Files::isDirectory)
.map(dir -> {
final String result = root.relativize(dir).toString();
=====================================
src/test/java/org/jboss/modules/MODULES_377_Test.java
=====================================
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2020 Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.modules;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.jboss.modules.util.Util;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.Iterator;
+
+/**
+ * [MODULES-377] Getting 'IAE: moduleLoader is null' when iterating modules and module.xml contains a permissions markup
+ *
+ * @author <a href="mailto:ropalka at redhat.com">Richard Opalka</a>
+ */
+public class MODULES_377_Test extends AbstractModuleTestCase {
+ private LocalModuleFinder moduleFinder;
+ private ModuleLoader moduleLoader;
+
+ @Before
+ public void setup() throws Exception {
+ final File repoRoot = Util.getResourceFile(getClass(), "test/MODULES_377");
+ moduleFinder = new LocalModuleFinder(new File[] {repoRoot});
+ moduleLoader = new ModuleLoader(moduleFinder);
+ }
+
+ @Test
+ public void issueTest() {
+ Iterator<String> i = moduleLoader.iterateModules((String) null, true);
+ assertTrue(i.hasNext());
+ assertEquals("local.tests.module", i.next());
+ assertFalse(i.hasNext());
+ }
+
+}
=====================================
src/test/java/org/jboss/modules/MavenResource2Test.java
=====================================
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2014 Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.modules;
+
+import org.jboss.modules.maven.MavenSettingsTest;
+import org.jboss.modules.util.Util;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:bill at burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public class MavenResource2Test {
+
+ protected static final ModuleIdentifier MODULE_ID2 = ModuleIdentifier.fromString("test.maven:non-main");
+
+ @Rule
+ public TemporaryFolder tmpdir = new TemporaryFolder();
+
+ private ModuleLoader moduleLoader;
+
+ @Before
+ public void setupRepo() throws Exception {
+ final File repoRoot = Util.getResourceFile(getClass(), "test/repo");
+ moduleLoader = new LocalModuleLoader(new File[]{repoRoot});
+ }
+
+ @Test
+ public void testDefaultRepositories() throws Exception {
+ try {
+ URL settingsXmlUrl = MavenSettingsTest.class.getResource("jboss-settings.xml");
+ System.setProperty("jboss.modules.settings.xml.url", settingsXmlUrl.toExternalForm());
+ Module module = moduleLoader.loadModule(MODULE_ID2);
+ URL url = module.getResource("org/jboss/resteasy/plugins/providers/jackson/ResteasyJacksonProvider.class");
+ System.out.println(url);
+ Assert.assertNotNull(url);
+ } finally {
+ System.clearProperty("jboss.modules.settings.xml.url");
+ }
+ }
+}
=====================================
src/test/java/org/jboss/modules/MavenResourceTest.java
=====================================
@@ -40,8 +40,6 @@ public class MavenResourceTest {
protected static final ModuleIdentifier MODULE_ID = ModuleIdentifier.fromString("test.maven");
- protected static final ModuleIdentifier MODULE_ID2 = ModuleIdentifier.fromString("test.maven:non-main");
-
@Rule
public TemporaryFolder tmpdir = new TemporaryFolder();
@@ -68,20 +66,6 @@ public class MavenResourceTest {
}
}
- @Test
- public void testDefaultRepositories() throws Exception {
- try {
- URL settingsXmlUrl = MavenSettingsTest.class.getResource("jboss-settings.xml");
- System.setProperty("jboss.modules.settings.xml.url", settingsXmlUrl.toExternalForm());
- Module module = moduleLoader.loadModule(MODULE_ID2);
- URL url = module.getResource("org/jboss/resteasy/plugins/providers/jackson/ResteasyJacksonProvider.class");
- System.out.println(url);
- Assert.assertNotNull(url);
- } finally {
- System.clearProperty("jboss.modules.settings.xml.url");
- }
- }
-
/**
* we test if it uses repostiory user has configured in user.home/.m2/settings.xml or M2_HOME/conf/settings.xml
*
=====================================
src/test/java/org/jboss/modules/PathResourceLoaderTest.java
=====================================
@@ -77,7 +77,7 @@ public class PathResourceLoaderTest extends AbstractResourceLoaderTestCase {
outputFile.getParentFile().mkdirs();
JarResourceLoaderTest.buildJar(super.getResourceRoot(test).toFile(), outputFile);
- FileSystem fileSystem = FileSystems.newFileSystem(outputFile.toPath(), null);
+ FileSystem fileSystem = FileSystems.newFileSystem(outputFile.toPath(), (ClassLoader) null);
return fileSystem.getRootDirectories().iterator().next();
}
};
=====================================
src/test/java/org/jboss/modules/SymlinkResourceLoaderTest.java
=====================================
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2014 Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.modules;
+
+import java.io.File;
+import java.nio.file.FileSystemException;
+import java.nio.file.Files;
+import java.security.AccessController;
+
+import org.jboss.modules.filter.PathFilter;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Assume;
+
+/**
+ * Test the functionality of the PathResourceLoader with resources containing symbolic links
+ *
+ * @author Bartosz Spyrko-Smietanko
+ */
+public class SymlinkResourceLoaderTest extends AbstractResourceLoaderTestCase {
+
+ private File resourceRoot;
+
+ @After
+ public void tearDown() throws Exception {
+ File base = getResource("test");
+ File symlink = new File(base, "symlink");
+ if (symlink.exists()) {
+ symlink.delete();
+ }
+ }
+
+ protected ResourceLoader createLoader(final PathFilter exportFilter) throws Exception {
+ File base = getResource("test");
+ File realRoot = getResource("test/fileresourceloader");
+ try {
+ resourceRoot = Files.createSymbolicLink(new File(base, "symlink").toPath(), realRoot.toPath()).toFile();
+ } catch (UnsupportedOperationException | FileSystemException e) {
+ Assume.assumeNoException(e);
+ }
+
+ // Copy the classfile over
+ copyResource("org/jboss/modules/test/TestClass.class", "test/fileresourceloader", "org/jboss/modules/test");
+ return new PathResourceLoader("test-root", resourceRoot.toPath(), AccessController.getContext());
+ }
+
+ @Override
+ protected void assertResource(Resource resource, String fileName) {
+ final File resourceFile = getExpectedFile(fileName);
+
+ Assert.assertEquals(resourceFile.length(), resource.getSize());
+ }
+
+ public void testGetClassSpec() throws Exception {
+ super.testGetClassSpec();
+ }
+
+ protected File getExpectedFile(String fileName) {
+ return new File(resourceRoot, fileName);
+ }
+}
=====================================
src/test/resources/test/MODULES_377/local/tests/module/main/module.xml
=====================================
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<module xmlns="urn:jboss:module:1.6" name="local.tests.module">
+ <dependencies>
+ <module name="org.jboss.modules"/>
+ </dependencies>
+
+ <permissions>
+ <grant permission="java.util.PropertyPermission" name=">org.mycompany.*" actions="read"></grant>
+ </permissions>
+</module>
\ No newline at end of file
View it on GitLab: https://salsa.debian.org/java-team/jboss-modules/-/commit/0427e09023d8467f1b0015d85b98b60053a29ac5
--
View it on GitLab: https://salsa.debian.org/java-team/jboss-modules/-/commit/0427e09023d8467f1b0015d85b98b60053a29ac5
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20200306/a7f5187d/attachment.html>
More information about the pkg-java-commits
mailing list