{
/**
* Represents the System property {@code java.specification.version}
*/
- public static final JavaVersion JAVA_SPECIFICATION_VERSION = parse( System.getProperty( "java.specification.version" ) );
+ public static final JavaVersion JAVA_SPECIFICATION_VERSION =
+ parse(System.getProperty("java.specification.version"));
/**
* Represents the System property {@code java.version}
*/
- public static final JavaVersion JAVA_VERSION = parse( System.getProperty( "java.version" ) );
-
- private static final Pattern startingDigits = Pattern.compile( "(\\d+)(.*)" );
-
+ public static final JavaVersion JAVA_VERSION = parse(System.getProperty("java.version"));
+
+ private static final Pattern startingDigits = Pattern.compile("(\\d+)(.*)");
+
private final String rawVersion;
-
- private final boolean isMajor;
- private JavaVersion( String rawVersion, boolean isMajor )
- {
+ private final boolean isMajor;
+
+ private JavaVersion(String rawVersion, boolean isMajor) {
this.rawVersion = rawVersion;
this.isMajor = isMajor;
}
/**
* Lazy parse the version-scheme.
- * Actual parsing is done when calling {@link #compareTo(JavaVersion)}
- *
+ * Actual parsing is done when calling {@link #compareTo(JavaVersion)}
+ *
* @param s the version string, never {@code null}
* @return the version wrapped in a JavadocVersion
*/
- public static JavaVersion parse( String s )
- {
- return new JavaVersion( s, !s.startsWith( "1." ) );
+ public static JavaVersion parse(String s) {
+ return new JavaVersion(s, !s.startsWith("1."));
}
@Override
- public int compareTo( JavaVersion other )
- {
- String[] thisSegments = this.rawVersion.split( "\\." );
- String[] otherSegments = other.rawVersion.split( "\\." );
-
- int minSegments = Math.min( thisSegments.length, otherSegments.length );
-
- for ( int index = 0; index < minSegments; index++ )
- {
- Matcher thisMatcher = startingDigits.matcher( thisSegments[index] );
-
+ public int compareTo(JavaVersion other) {
+ String[] thisSegments = this.rawVersion.split("\\.");
+ String[] otherSegments = other.rawVersion.split("\\.");
+
+ int minSegments = Math.min(thisSegments.length, otherSegments.length);
+
+ for (int index = 0; index < minSegments; index++) {
+ Matcher thisMatcher = startingDigits.matcher(thisSegments[index]);
+
int thisValue;
-
- if( thisMatcher.find() )
- {
- thisValue = Integer.parseInt( thisMatcher.group( 1 ) );
- }
- else
- {
+
+ if (thisMatcher.find()) {
+ thisValue = Integer.parseInt(thisMatcher.group(1));
+ } else {
thisValue = -1;
}
-
- Matcher otherMatcher = startingDigits.matcher( otherSegments[index] );
-
+
+ Matcher otherMatcher = startingDigits.matcher(otherSegments[index]);
+
int otherValue;
-
- if( otherMatcher.find() )
- {
- otherValue = Integer.parseInt( otherMatcher.group( 1 ) );
- }
- else
- {
+
+ if (otherMatcher.find()) {
+ otherValue = Integer.parseInt(otherMatcher.group(1));
+ } else {
otherValue = -1;
}
-
- int compareValue = Integer.compare( thisValue, otherValue );
-
- if ( compareValue != 0 )
- {
+
+ int compareValue = Integer.compare(thisValue, otherValue);
+
+ if (compareValue != 0) {
return compareValue;
}
- compareValue = suffixRate( thisMatcher.group( 2 ) ) - suffixRate( otherMatcher.group( 2 ) );
- if ( compareValue != 0 )
- {
+ compareValue = suffixRate(thisMatcher.group(2)) - suffixRate(otherMatcher.group(2));
+ if (compareValue != 0) {
return compareValue;
}
-
+
// works for now, but needs improvement
- compareValue = thisMatcher.group( 2 ).compareTo( otherMatcher.group( 2 ) );
-
- if ( compareValue != 0 )
- {
+ compareValue = thisMatcher.group(2).compareTo(otherMatcher.group(2));
+
+ if (compareValue != 0) {
return compareValue;
}
}
-
- return ( thisSegments.length - otherSegments.length );
+
+ return (thisSegments.length - otherSegments.length);
}
-
- private int suffixRate( String suffix ) {
- if ( "-ea".equals( suffix ) )
- {
+
+ private int suffixRate(String suffix) {
+ if ("-ea".equals(suffix)) {
return -100;
- }
- else if ( "".equals( suffix ) )
- {
+ } else if ("".equals(suffix)) {
return 0;
- }
- else
- {
+ } else {
return 10;
}
}
/**
* Verify if this version is before some other version
- *
+ *
* @param other the version to compare with
* @return {@code true} is this is less than {@code other}, otherwise {@code false}
*/
- public boolean isBefore( JavaVersion other )
- {
- return this.compareTo( other ) < 0;
+ public boolean isBefore(JavaVersion other) {
+ return this.compareTo(other) < 0;
}
/**
* Verify if this version is before some other version
- *
+ *
* @param other the version to compare with
* @return {@code true} is this is less than {@code other}, otherwise {@code false}
*/
- public boolean isBefore( String other )
- {
- return this.compareTo( parse( other ) ) < 0;
+ public boolean isBefore(String other) {
+ return this.compareTo(parse(other)) < 0;
}
/**
* Verify if this version is at least some other version
- *
+ *
* @param other the version to compare with
* @return {@code true} is this is greater than or equal to {@code other}, otherwise {@code false}
*/
- public boolean isAtLeast( JavaVersion other )
- {
- return this.compareTo( other ) >= 0;
+ public boolean isAtLeast(JavaVersion other) {
+ return this.compareTo(other) >= 0;
}
/**
* Verify if this version is at least some other version
- *
+ *
* @param other the version to compare with
* @return {@code true} is this is greater than or equal to {@code other}, otherwise {@code false}
*/
- public boolean isAtLeast( String other )
- {
- return this.compareTo( parse( other ) ) >= 0;
+ public boolean isAtLeast(String other) {
+ return this.compareTo(parse(other)) >= 0;
}
-
+
/**
* If original version starts with {@code "1."}, then remove this part from the version
- *
+ *
* @return a new JavaVersion if version has to be changed, otherwise return itself
*/
- public JavaVersion asMajor()
- {
- if ( !isMajor )
- {
- return new JavaVersion( rawVersion.substring( 2 ), true );
- }
- else
- {
+ public JavaVersion asMajor() {
+ if (!isMajor) {
+ return new JavaVersion(rawVersion.substring(2), true);
+ } else {
return this;
}
}
-
+
/**
* Returns the original version
- *
+ *
* @return the raw version
*/
- public String getValue()
- {
+ public String getValue() {
return rawVersion;
}
@@ -219,90 +192,72 @@ public String getValue()
* Returns a value respecting the nuber of groups.
* If the original has more groups, the end of that value will be removed.
* If the original has less groups, the value will be extended this ".0".
- *
+ *
*
- * JavaVersion.parse( "1" ).getValue( 1 ) is "1"
- * JavaVersion.parse( "1" ).getValue( 2 ) is "1.0"
- * JavaVersion.parse( "2.1" ).getValue( 1 ) is "2"
- * JavaVersion.parse( "2.1" ).getValue( 2 ) is "2.1"
+ * JavaVersion.parse( "1" ).getValue( 1 ) is "1"
+ * JavaVersion.parse( "1" ).getValue( 2 ) is "1.0"
+ * JavaVersion.parse( "2.1" ).getValue( 1 ) is "2"
+ * JavaVersion.parse( "2.1" ).getValue( 2 ) is "2.1"
*
- *
+ *
* @param groups number of groups to return
* @return the version respecting the number of groups
*/
- public String getValue( int groups )
- {
+ public String getValue(int groups) {
StringBuilder value = new StringBuilder();
- StringTokenizer tokenizer = new StringTokenizer( rawVersion, "." );
-
- value.append( tokenizer.nextToken() );
- for ( int group = 1 ; group < groups ; group++ )
- {
- value.append( '.' );
- if( tokenizer.hasMoreTokens() )
- {
- value.append( tokenizer.nextToken() );
- }
- else
- {
- value.append( "0" );
+ StringTokenizer tokenizer = new StringTokenizer(rawVersion, ".");
+
+ value.append(tokenizer.nextToken());
+ for (int group = 1; group < groups; group++) {
+ value.append('.');
+ if (tokenizer.hasMoreTokens()) {
+ value.append(tokenizer.nextToken());
+ } else {
+ value.append("0");
}
}
return value.toString();
}
@Override
- public String toString()
- {
+ public String toString() {
return rawVersion;
}
@Override
- public int hashCode()
- {
- return Objects.hashCode( rawVersion );
+ public int hashCode() {
+ return Objects.hashCode(rawVersion);
}
@Override
- public boolean equals( Object obj )
- {
- if ( this == obj )
- {
+ public boolean equals(Object obj) {
+ if (this == obj) {
return true;
}
- if ( obj == null )
- {
+ if (obj == null) {
return false;
}
- if ( getClass() != obj.getClass() )
- {
+ if (getClass() != obj.getClass()) {
return false;
}
-
+
JavaVersion other = (JavaVersion) obj;
- if ( isMajor != other.isMajor )
- {
+ if (isMajor != other.isMajor) {
final String thisOneDotVersion;
final String otherOneDotVersion;
- if ( isMajor )
- {
+ if (isMajor) {
thisOneDotVersion = "1." + rawVersion;
otherOneDotVersion = other.rawVersion;
- }
- else
- {
+ } else {
thisOneDotVersion = rawVersion;
otherOneDotVersion = "1." + other.rawVersion;
}
-
- if ( !Objects.equals( thisOneDotVersion, otherOneDotVersion ) )
- {
- return false;
- }
- }
- else if ( !Objects.equals( rawVersion, other.rawVersion ) )
- {
+
+ if (!Objects.equals(thisOneDotVersion, otherOneDotVersion)) {
return false;
+ }
+ } else if (!Objects.equals(rawVersion, other.rawVersion)) {
+ return false;
}
return true;
}
diff --git a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/AbstractFilenameModuleNameExtractorTest.java b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/AbstractFilenameModuleNameExtractorTest.java
index 96e0307..1db8b8c 100644
--- a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/AbstractFilenameModuleNameExtractorTest.java
+++ b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/AbstractFilenameModuleNameExtractorTest.java
@@ -19,52 +19,47 @@
* under the License.
*/
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assume.assumeThat;
-
import java.nio.file.Paths;
import org.junit.BeforeClass;
import org.junit.Test;
-public abstract class AbstractFilenameModuleNameExtractorTest
-{
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeThat;
+
+public abstract class AbstractFilenameModuleNameExtractorTest {
protected abstract ModuleNameExtractor getExtractor();
@BeforeClass
- public static void assume()
- {
- assumeThat( "Requires at least Java 9", System.getProperty( "java.version" ), not( startsWith( "1." ) ) );
+ public static void assume() {
+ assumeThat("Requires at least Java 9", System.getProperty("java.version"), not(startsWith("1.")));
}
-
+
@Test
- public void testJarWithoutManifest() throws Exception
- {
- String name = getExtractor().extract( Paths.get( "src/test/resources/jar.empty/plexus-java-1.0.0-SNAPSHOT.jar" ) );
- assertEquals( "plexus.java", name );
+ public void testJarWithoutManifest() throws Exception {
+ String name = getExtractor().extract(Paths.get("src/test/resources/jar.empty/plexus-java-1.0.0-SNAPSHOT.jar"));
+ assertEquals("plexus.java", name);
}
@Test
- public void testJarWithManifest() throws Exception
- {
- String name = getExtractor().extract( Paths.get( "src/test/resources/jar.manifest.with/plexus-java-1.0.0-SNAPSHOT.jar" ) );
- assertEquals( "org.codehaus.plexus.languages.java", name );
+ public void testJarWithManifest() throws Exception {
+ String name = getExtractor()
+ .extract(Paths.get("src/test/resources/jar.manifest.with/plexus-java-1.0.0-SNAPSHOT.jar"));
+ assertEquals("org.codehaus.plexus.languages.java", name);
}
-
+
@Test
- public void testJarUnsupported() throws Exception
- {
- String name = getExtractor().extract( Paths.get( "src/test/resources/jar.unsupported/jdom-1.0.jar" ) );
- assertEquals( null, name );
+ public void testJarUnsupported() throws Exception {
+ String name = getExtractor().extract(Paths.get("src/test/resources/jar.unsupported/jdom-1.0.jar"));
+ assertEquals(null, name);
}
@Test
- public void testJarWithSpacesInPath() throws Exception
- {
- String name = getExtractor().extract( Paths.get( "src/test/resources/jar with spaces in path/plexus-java-1.0.0-SNAPSHOT.jar" ) );
- assertEquals( "org.codehaus.plexus.languages.java", name );
+ public void testJarWithSpacesInPath() throws Exception {
+ String name = getExtractor()
+ .extract(Paths.get("src/test/resources/jar with spaces in path/plexus-java-1.0.0-SNAPSHOT.jar"));
+ assertEquals("org.codehaus.plexus.languages.java", name);
}
-
}
diff --git a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/BinaryModuleInfoParserTest.java b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/BinaryModuleInfoParserTest.java
index 963b508..f7aa257 100644
--- a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/BinaryModuleInfoParserTest.java
+++ b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/BinaryModuleInfoParserTest.java
@@ -1,6 +1,5 @@
package org.codehaus.plexus.languages.java.jpms;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -20,13 +19,6 @@
* under the License.
*/
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
@@ -43,162 +35,174 @@
import org.codehaus.plexus.languages.java.version.JavaVersion;
import org.junit.Test;
-public class BinaryModuleInfoParserTest
-{
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class BinaryModuleInfoParserTest {
private BinaryModuleInfoParser parser = new BinaryModuleInfoParser();
@Test
- public void testJarDescriptor() throws Exception
- {
- JavaModuleDescriptor descriptor = parser.getModuleDescriptor( Paths.get( "src/test/resources/jar.descriptor/asm-6.0_BETA.jar" ) );
-
- assertNotNull( descriptor);
- assertEquals( "org.objectweb.asm", descriptor.name() );
- assertEquals( false, descriptor.isAutomatic() );
-
- assertEquals( 1, descriptor.requires().size() );
- assertEquals( "java.base", descriptor.requires().iterator().next().name() );
-
- Set expectedExports = JavaModuleDescriptor.newAutomaticModule( "_" )
- .exports( "org.objectweb.asm" )
- .exports( "org.objectweb.asm.signature" )
+ public void testJarDescriptor() throws Exception {
+ JavaModuleDescriptor descriptor =
+ parser.getModuleDescriptor(Paths.get("src/test/resources/jar.descriptor/asm-6.0_BETA.jar"));
+
+ assertNotNull(descriptor);
+ assertEquals("org.objectweb.asm", descriptor.name());
+ assertEquals(false, descriptor.isAutomatic());
+
+ assertEquals(1, descriptor.requires().size());
+ assertEquals("java.base", descriptor.requires().iterator().next().name());
+
+ Set expectedExports = JavaModuleDescriptor.newAutomaticModule("_")
+ .exports("org.objectweb.asm")
+ .exports("org.objectweb.asm.signature")
.build()
.exports();
- assertEquals( expectedExports, descriptor.exports() );
+ assertEquals(expectedExports, descriptor.exports());
}
@Test
- public void testMultiReleaseJarDescriptor() throws Exception
- {
- JavaModuleDescriptor descriptor = parser.getModuleDescriptor( Paths.get( "src/test/resources/jar.mr.descriptor/jloadr-1.0-SNAPSHOT.jar" ), JavaVersion.parse( "17" ) );
-
- assertNotNull( descriptor);
- assertEquals( "de.adito.jloadr", descriptor.name() );
- assertEquals( false, descriptor.isAutomatic() );
+ public void testMultiReleaseJarDescriptor() throws Exception {
+ JavaModuleDescriptor descriptor = parser.getModuleDescriptor(
+ Paths.get("src/test/resources/jar.mr.descriptor/jloadr-1.0-SNAPSHOT.jar"), JavaVersion.parse("17"));
+
+ assertNotNull(descriptor);
+ assertEquals("de.adito.jloadr", descriptor.name());
+ assertEquals(false, descriptor.isAutomatic());
}
@Test
- public void testIncompleteMultiReleaseJarDescriptor() throws Exception
- {
+ public void testIncompleteMultiReleaseJarDescriptor() throws Exception {
// this jar is missing the Multi-Release: true entry in the Manifest
- JavaModuleDescriptor descriptor = parser.getModuleDescriptor( Paths.get( "src/test/resources/jar.mr.incomplete.descriptor/jloadr-1.0-SNAPSHOT.jar" ) );
-
- assertNull( descriptor);
+ JavaModuleDescriptor descriptor = parser.getModuleDescriptor(
+ Paths.get("src/test/resources/jar.mr.incomplete.descriptor/jloadr-1.0-SNAPSHOT.jar"));
+
+ assertNull(descriptor);
}
@Test
- public void testClassicJar() throws Exception
- {
- JavaModuleDescriptor descriptor = parser.getModuleDescriptor( Paths.get( "src/test/resources/jar.empty/plexus-java-1.0.0-SNAPSHOT.jar" ) );
-
- assertNull( descriptor);
+ public void testClassicJar() throws Exception {
+ JavaModuleDescriptor descriptor =
+ parser.getModuleDescriptor(Paths.get("src/test/resources/jar.empty/plexus-java-1.0.0-SNAPSHOT.jar"));
+
+ assertNull(descriptor);
}
-
+
@Test
- public void testOutputDirectoryDescriptor()
- throws Exception
- {
+ public void testOutputDirectoryDescriptor() throws Exception {
JavaModuleDescriptor descriptor =
- parser.getModuleDescriptor( Paths.get( "src/test/resources/dir.descriptor/out" ) );
+ parser.getModuleDescriptor(Paths.get("src/test/resources/dir.descriptor/out"));
- assertNotNull( descriptor );
- assertEquals( "org.codehaus.plexus.languages.java.demo", descriptor.name() );
- assertEquals( false, descriptor.isAutomatic() );
+ assertNotNull(descriptor);
+ assertEquals("org.codehaus.plexus.languages.java.demo", descriptor.name());
+ assertEquals(false, descriptor.isAutomatic());
- assertEquals( 3, descriptor.requires().size() );
+ assertEquals(3, descriptor.requires().size());
- Set expectedRequires = JavaModuleDescriptor.newAutomaticModule( "_" )
- .requires( "java.base" )
- .requires( "java.xml" )
- .requires( Collections.singleton( JavaRequires.JavaModifier.STATIC ), "com.google.common" )
- .build()
- .requires();
+ Set expectedRequires = JavaModuleDescriptor.newAutomaticModule("_")
+ .requires("java.base")
+ .requires("java.xml")
+ .requires(Collections.singleton(JavaRequires.JavaModifier.STATIC), "com.google.common")
+ .build()
+ .requires();
- assertEquals( expectedRequires, descriptor.requires() );
+ assertEquals(expectedRequires, descriptor.requires());
}
- @Test( expected = NoSuchFileException.class )
- public void testClassicOutputDirectory() throws Exception
- {
- parser.getModuleDescriptor( Paths.get( "src/test/resources/dir.empty/out" ) );
+ @Test(expected = NoSuchFileException.class)
+ public void testClassicOutputDirectory() throws Exception {
+ parser.getModuleDescriptor(Paths.get("src/test/resources/dir.empty/out"));
}
@Test
- public void testJModDescriptor() throws Exception
- {
- JavaModuleDescriptor descriptor = parser.getModuleDescriptor( Paths.get( "src/test/resources/jmod.descriptor/first-jmod-1.0-SNAPSHOT.jmod" ) );
-
- assertNotNull( descriptor);
- assertEquals( "com.corporate.project", descriptor.name() );
- assertEquals( false, descriptor.isAutomatic() );
-
- assertEquals( 1, descriptor.requires().size() );
- assertEquals( "java.base", descriptor.requires().iterator().next().name() );
-
- assertEquals ( 1, descriptor.exports().size() );
- assertEquals ( "com.corporate.project", descriptor.exports().iterator().next().source() );
+ public void testJModDescriptor() throws Exception {
+ JavaModuleDescriptor descriptor = parser.getModuleDescriptor(
+ Paths.get("src/test/resources/jmod.descriptor/first-jmod-1.0-SNAPSHOT.jmod"));
+
+ assertNotNull(descriptor);
+ assertEquals("com.corporate.project", descriptor.name());
+ assertEquals(false, descriptor.isAutomatic());
+
+ assertEquals(1, descriptor.requires().size());
+ assertEquals("java.base", descriptor.requires().iterator().next().name());
+
+ assertEquals(1, descriptor.exports().size());
+ assertEquals(
+ "com.corporate.project", descriptor.exports().iterator().next().source());
}
-
- @Test( expected = IOException.class )
- public void testInvalidFile() throws Exception
- {
- parser.getModuleDescriptor( Paths.get( "src/test/resources/nonjar/pom.xml" ) );
+
+ @Test(expected = IOException.class)
+ public void testInvalidFile() throws Exception {
+ parser.getModuleDescriptor(Paths.get("src/test/resources/nonjar/pom.xml"));
}
-
+
@Test
- public void testUses() throws Exception
- {
- try ( InputStream is = Files.newInputStream( Paths.get( "src/test/resources/dir.descriptor.uses/out/module-info.class" ) ) )
- {
- JavaModuleDescriptor descriptor = parser.parse( is );
-
- assertNotNull( descriptor);
- assertEquals( new HashSet<>( Arrays.asList( "org.apache.logging.log4j.spi.Provider",
- "org.apache.logging.log4j.util.PropertySource",
- "org.apache.logging.log4j.message.ThreadDumpMessage$ThreadInfoFactory" ) ),
- descriptor.uses() );
+ public void testUses() throws Exception {
+ try (InputStream is =
+ Files.newInputStream(Paths.get("src/test/resources/dir.descriptor.uses/out/module-info.class"))) {
+ JavaModuleDescriptor descriptor = parser.parse(is);
+
+ assertNotNull(descriptor);
+ assertEquals(
+ new HashSet<>(Arrays.asList(
+ "org.apache.logging.log4j.spi.Provider",
+ "org.apache.logging.log4j.util.PropertySource",
+ "org.apache.logging.log4j.message.ThreadDumpMessage$ThreadInfoFactory")),
+ descriptor.uses());
}
}
-
+
@Test
- public void testProvides() throws Exception
- {
- JavaModuleDescriptor descriptor = parser.getModuleDescriptor( Paths.get( "src/test/resources/jar.service/threeten-extra-1.4.jar" ) );
-
- assertNotNull( descriptor );
- assertEquals( 1, descriptor.provides().size() );
-
- JavaProvides provides = descriptor.provides().iterator().next();
- assertEquals( "java.time.chrono.Chronology", provides.service() );
- assertArrayEquals( new String[] { "org.threeten.extra.chrono.BritishCutoverChronology",
- "org.threeten.extra.chrono.CopticChronology", "org.threeten.extra.chrono.DiscordianChronology",
- "org.threeten.extra.chrono.EthiopicChronology", "org.threeten.extra.chrono.InternationalFixedChronology",
- "org.threeten.extra.chrono.JulianChronology", "org.threeten.extra.chrono.PaxChronology",
- "org.threeten.extra.chrono.Symmetry010Chronology", "org.threeten.extra.chrono.Symmetry454Chronology" },
- provides.providers().toArray( new String[0] ) );
+ public void testProvides() throws Exception {
+ JavaModuleDescriptor descriptor =
+ parser.getModuleDescriptor(Paths.get("src/test/resources/jar.service/threeten-extra-1.4.jar"));
+ assertNotNull(descriptor);
+ assertEquals(1, descriptor.provides().size());
+
+ JavaProvides provides = descriptor.provides().iterator().next();
+ assertEquals("java.time.chrono.Chronology", provides.service());
+ assertArrayEquals(
+ new String[] {
+ "org.threeten.extra.chrono.BritishCutoverChronology",
+ "org.threeten.extra.chrono.CopticChronology",
+ "org.threeten.extra.chrono.DiscordianChronology",
+ "org.threeten.extra.chrono.EthiopicChronology",
+ "org.threeten.extra.chrono.InternationalFixedChronology",
+ "org.threeten.extra.chrono.JulianChronology",
+ "org.threeten.extra.chrono.PaxChronology",
+ "org.threeten.extra.chrono.Symmetry010Chronology",
+ "org.threeten.extra.chrono.Symmetry454Chronology"
+ },
+ provides.providers().toArray(new String[0]));
}
@Test
- public void testRequires() throws Exception
- {
- try ( InputStream is = Files.newInputStream( Paths.get( "src/test/resources/dir.descriptor.requires/out/module-info.class" ) ) )
- {
- JavaModuleDescriptor descriptor = parser.parse( is );
-
- assertNotNull( descriptor);
- assertThat( descriptor.requires().size(), is( 5 ) );
-
- Set expectedRequires = JavaModuleDescriptor.newAutomaticModule( "_" )
- .requires( "java.base" )
- .requires( "mod_r" )
- .requires( Collections.singleton( JavaRequires.JavaModifier.STATIC ), "mod_r_s" )
- .requires( Collections.singleton( JavaRequires.JavaModifier.TRANSITIVE ), "mod_r_t" )
- .requires( new HashSet( Arrays.asList( JavaRequires.JavaModifier.STATIC, JavaRequires.JavaModifier.TRANSITIVE ) ), "mod_r_s_t" )
- .build()
- .requires();
-
- assertEquals( expectedRequires, descriptor.requires() );
+ public void testRequires() throws Exception {
+ try (InputStream is =
+ Files.newInputStream(Paths.get("src/test/resources/dir.descriptor.requires/out/module-info.class"))) {
+ JavaModuleDescriptor descriptor = parser.parse(is);
+
+ assertNotNull(descriptor);
+ assertThat(descriptor.requires().size(), is(5));
+
+ Set expectedRequires = JavaModuleDescriptor.newAutomaticModule("_")
+ .requires("java.base")
+ .requires("mod_r")
+ .requires(Collections.singleton(JavaRequires.JavaModifier.STATIC), "mod_r_s")
+ .requires(Collections.singleton(JavaRequires.JavaModifier.TRANSITIVE), "mod_r_t")
+ .requires(
+ new HashSet(Arrays.asList(
+ JavaRequires.JavaModifier.STATIC, JavaRequires.JavaModifier.TRANSITIVE)),
+ "mod_r_s_t")
+ .build()
+ .requires();
+
+ assertEquals(expectedRequires, descriptor.requires());
}
}
}
diff --git a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/CmdModuleNameExtractorTest.java b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/CmdModuleNameExtractorTest.java
index dd1248f..e0536c1 100644
--- a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/CmdModuleNameExtractorTest.java
+++ b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/CmdModuleNameExtractorTest.java
@@ -19,22 +19,20 @@
* under the License.
*/
-import static org.junit.Assert.assertEquals;
-
import java.nio.file.Path;
import org.junit.Test;
-public class CmdModuleNameExtractorTest
-{
+import static org.junit.Assert.assertEquals;
+
+public class CmdModuleNameExtractorTest {
@Test
- public void testMethodCount() throws Exception
- {
+ public void testMethodCount() throws Exception {
// ensure that both implementations are in sync
- assertEquals( 2, CmdModuleNameExtractor.class.getDeclaredMethods().length );
-
+ assertEquals(2, CmdModuleNameExtractor.class.getDeclaredMethods().length);
+
// if these don't exist, a NoSuchMethodException is thrown
- CmdModuleNameExtractor.class.getDeclaredMethod( "main", String[].class );
- CmdModuleNameExtractor.class.getDeclaredMethod( "getModuleName", Path.class );
+ CmdModuleNameExtractor.class.getDeclaredMethod("main", String[].class);
+ CmdModuleNameExtractor.class.getDeclaredMethod("getModuleName", Path.class);
}
}
diff --git a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerIT.java b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerIT.java
index c79a29f..ee243b2 100644
--- a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerIT.java
+++ b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerIT.java
@@ -19,14 +19,6 @@
* under the License.
*/
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assume.assumeThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.when;
-
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
@@ -38,15 +30,22 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assume.assumeThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
/**
- * NOTE Eclipse users must disable the Build automatically
option,
- * otherwise it'll continually rebuild the project, causing compilations or tests to fail.
- *
+ * NOTE Eclipse users must disable the Build automatically
option,
+ * otherwise it'll continually rebuild the project, causing compilations or tests to fail.
+ *
* @author Robert Scholte
*/
-@RunWith( org.mockito.junit.MockitoJUnitRunner.class )
-public class LocationManagerIT
-{
+@RunWith(org.mockito.junit.MockitoJUnitRunner.class)
+public class LocationManagerIT {
@Mock
private BinaryModuleInfoParser asmParser;
@@ -54,84 +53,81 @@ public class LocationManagerIT
private SourceModuleInfoParser qdoxParser;
private LocationManager locationManager;
-
- final Path mockModuleInfoJava = Paths.get( "src/test/resources/mock/module-info.java");
-
+
+ final Path mockModuleInfoJava = Paths.get("src/test/resources/mock/module-info.java");
+
@BeforeClass
- public static void assume()
- {
- assumeThat( "Requires at least Java 9", System.getProperty( "java.version" ), not( startsWith( "1." ) ) );
+ public static void assume() {
+ assumeThat("Requires at least Java 9", System.getProperty("java.version"), not(startsWith("1.")));
}
-
+
@Before
- public void onSetup()
- {
- locationManager = new LocationManager( qdoxParser )
- {
+ public void onSetup() {
+ locationManager = new LocationManager(qdoxParser) {
@Override
- ModuleInfoParser getBinaryModuleInfoParser( Path jdkHome )
- {
+ ModuleInfoParser getBinaryModuleInfoParser(Path jdkHome) {
return asmParser;
}
};
}
-
+
@Test
- public void testManifestWithoutReflectRequires() throws Exception
- {
- Path abc = Paths.get( "src/test/resources/manifest.without/out" );
- JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule( "base" ).requires( "any" ).build();
- when( qdoxParser.fromSourcePath( any( Path.class ) ) ).thenReturn( descriptor );
- ResolvePathsRequest request = ResolvePathsRequest.ofPaths( Collections.singletonList( abc ) ).setMainModuleDescriptor( mockModuleInfoJava );
-
- ResolvePathsResult result = locationManager.resolvePaths( request );
-
- assertThat( result.getPathExceptions().size(), is( 0 ) );
- assertThat( result.getMainModuleDescriptor(), is( descriptor) );
- assertThat( result.getPathElements().size(), is( 1 ) );
- assertThat( result.getModulepathElements().size(), is( 0 ) );
- assertThat( result.getClasspathElements().size(), is( 1 ) );
+ public void testManifestWithoutReflectRequires() throws Exception {
+ Path abc = Paths.get("src/test/resources/manifest.without/out");
+ JavaModuleDescriptor descriptor =
+ JavaModuleDescriptor.newModule("base").requires("any").build();
+ when(qdoxParser.fromSourcePath(any(Path.class))).thenReturn(descriptor);
+ ResolvePathsRequest request =
+ ResolvePathsRequest.ofPaths(Collections.singletonList(abc)).setMainModuleDescriptor(mockModuleInfoJava);
+
+ ResolvePathsResult result = locationManager.resolvePaths(request);
+
+ assertThat(result.getPathExceptions().size(), is(0));
+ assertThat(result.getMainModuleDescriptor(), is(descriptor));
+ assertThat(result.getPathElements().size(), is(1));
+ assertThat(result.getModulepathElements().size(), is(0));
+ assertThat(result.getClasspathElements().size(), is(1));
}
-
+
@Test
- public void testEmptyWithReflectRequires() throws Exception
- {
- Path abc = Paths.get( "src/test/resources/empty/out" );
- JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule( "base" ).requires( "a.b.c" ).build();
- when( qdoxParser.fromSourcePath( any( Path.class ) ) ).thenReturn( descriptor );
- ResolvePathsRequest request = ResolvePathsRequest.ofPaths( Collections.singletonList( abc ) ).setMainModuleDescriptor( mockModuleInfoJava );
-
- ResolvePathsResult result = locationManager.resolvePaths( request );
-
- assertThat( result.getPathExceptions().size(), is( 0 ) );
- assertThat( result.getMainModuleDescriptor(), is( descriptor) );
- assertThat( result.getPathElements().size(), is( 1 ) );
- assertThat( result.getModulepathElements().size(), is( 0 ) );
- assertThat( result.getClasspathElements().size(), is( 1 ) );
+ public void testEmptyWithReflectRequires() throws Exception {
+ Path abc = Paths.get("src/test/resources/empty/out");
+ JavaModuleDescriptor descriptor =
+ JavaModuleDescriptor.newModule("base").requires("a.b.c").build();
+ when(qdoxParser.fromSourcePath(any(Path.class))).thenReturn(descriptor);
+ ResolvePathsRequest request =
+ ResolvePathsRequest.ofPaths(Collections.singletonList(abc)).setMainModuleDescriptor(mockModuleInfoJava);
+
+ ResolvePathsResult result = locationManager.resolvePaths(request);
+
+ assertThat(result.getPathExceptions().size(), is(0));
+ assertThat(result.getMainModuleDescriptor(), is(descriptor));
+ assertThat(result.getPathElements().size(), is(1));
+ assertThat(result.getModulepathElements().size(), is(0));
+ assertThat(result.getClasspathElements().size(), is(1));
}
-
- @Test( expected = RuntimeException.class )
- public void testResolvePathWithException() throws Exception
- {
- assumeThat( "Requires at least Java 9", System.getProperty( "java.version" ), not( startsWith( "1." ) ) );
-
- Path p = Paths.get( "src/test/resources/jar.empty.invalid.name/101-1.0.0-SNAPSHOT.jar" );
- ResolvePathRequest request = ResolvePathRequest.ofPath( p );
-
- locationManager.resolvePath( request );
+
+ @Test(expected = RuntimeException.class)
+ public void testResolvePathWithException() throws Exception {
+ assumeThat("Requires at least Java 9", System.getProperty("java.version"), not(startsWith("1.")));
+
+ Path p = Paths.get("src/test/resources/jar.empty.invalid.name/101-1.0.0-SNAPSHOT.jar");
+ ResolvePathRequest request = ResolvePathRequest.ofPath(p);
+
+ locationManager.resolvePath(request);
}
-
+
@Test
- public void testClassicJarNameStartsWithNumber() throws Exception
- {
- assumeThat( "Requires at least Java 9", System.getProperty( "java.version" ), not( startsWith( "1." ) ) );
-
- Path p = Paths.get( "src/test/resources/jar.empty.invalid.name/101-1.0.0-SNAPSHOT.jar" );
- ResolvePathsRequest request = ResolvePathsRequest.ofPaths( Arrays.asList( p ) ).setMainModuleDescriptor( mockModuleInfoJava );
-
- ResolvePathsResult result = locationManager.resolvePaths( request );
-
- assertThat( result.getPathExceptions().size(), is( 1 ) );
- assertThat( result.getClasspathElements().size(), is(1) );
+ public void testClassicJarNameStartsWithNumber() throws Exception {
+ assumeThat("Requires at least Java 9", System.getProperty("java.version"), not(startsWith("1.")));
+
+ Path p = Paths.get("src/test/resources/jar.empty.invalid.name/101-1.0.0-SNAPSHOT.jar");
+ ResolvePathsRequest request =
+ ResolvePathsRequest.ofPaths(Arrays.asList(p)).setMainModuleDescriptor(mockModuleInfoJava);
+
+ ResolvePathsResult result = locationManager.resolvePaths(request);
+
+ assertThat(result.getPathExceptions().size(), is(1));
+ assertThat(result.getClasspathElements().size(), is(1));
}
}
diff --git a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerTest.java b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerTest.java
index 35a6f4e..09de41a 100644
--- a/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerTest.java
+++ b/plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerTest.java
@@ -19,12 +19,6 @@
* under the License.
*/
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.when;
-
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -33,15 +27,19 @@
import java.util.HashSet;
import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor.JavaRequires.JavaModifier;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-@RunWith( org.mockito.junit.MockitoJUnitRunner.class )
-public class LocationManagerTest
-{
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+@RunWith(org.mockito.junit.MockitoJUnitRunner.class)
+public class LocationManagerTest {
@Mock
private BinaryModuleInfoParser asmParser;
@@ -49,500 +47,557 @@ public class LocationManagerTest
private SourceModuleInfoParser qdoxParser;
private LocationManager locationManager;
-
- final Path mockModuleInfoJava = Paths.get( "src/test/resources/mock/module-info.java");
-
+
+ final Path mockModuleInfoJava = Paths.get("src/test/resources/mock/module-info.java");
+
@Before
- public void onSetup()
- {
- locationManager = new LocationManager( qdoxParser )
- {
+ public void onSetup() {
+ locationManager = new LocationManager(qdoxParser) {
@Override
- ModuleInfoParser getBinaryModuleInfoParser( Path jdkHome )
- {
+ ModuleInfoParser getBinaryModuleInfoParser(Path jdkHome) {
return asmParser;
}
};
}
@Test
- public void testNoPaths() throws Exception
- {
- ResolvePathsResult result = locationManager.resolvePaths( ResolvePathsRequest.ofFiles( Collections.emptyList() ) );
- assertThat( result.getMainModuleDescriptor(), nullValue( JavaModuleDescriptor.class) );
- assertThat( result.getPathElements().size(), is( 0 ) );
- assertThat( result.getModulepathElements().size(), is( 0 ) );
- assertThat( result.getClasspathElements().size(), is( 0 ) );
- assertThat( result.getPathExceptions().size(), is( 0 ) );
+ public void testNoPaths() throws Exception {
+ ResolvePathsResult result =
+ locationManager.resolvePaths(ResolvePathsRequest.ofFiles(Collections.emptyList()));
+ assertThat(result.getMainModuleDescriptor(), nullValue(JavaModuleDescriptor.class));
+ assertThat(result.getPathElements().size(), is(0));
+ assertThat(result.getModulepathElements().size(), is(0));
+ assertThat(result.getClasspathElements().size(), is(0));
+ assertThat(result.getPathExceptions().size(), is(0));
}
@Test
- public void testWithUnknownRequires() throws Exception
- {
- JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule( "base" ).requires( "java.base" ).requires( "jdk.net" ).build();
- when( qdoxParser.fromSourcePath( any( Path.class ) ) ).thenReturn( descriptor );
- ResolvePathsRequest request = ResolvePathsRequest.ofFiles( Collections.emptyList() ).setMainModuleDescriptor( mockModuleInfoJava.toFile() );
-
- ResolvePathsResult result = locationManager.resolvePaths( request );
-
- assertThat( result.getMainModuleDescriptor(), is( descriptor) );
- assertThat( result.getPathElements().size(), is( 0 ) );
- assertThat( result.getModulepathElements().size(), is( 0 ) );
- assertThat( result.getClasspathElements().size(), is( 0 ) );
- assertThat( result.getPathExceptions().size(), is( 0 ) );
- }
-
- @Test
- public void testManifestWithReflectRequires() throws Exception
- {
- Path abc = Paths.get( "src/test/resources/dir.manifest.with/out" );
- JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule( "base" ).requires( "auto.by.manifest" ).build();
- when( qdoxParser.fromSourcePath( any( Path.class ) ) ).thenReturn( descriptor );
- ResolvePathsRequest request = ResolvePathsRequest.ofPaths( Collections.singletonList( abc ) ).setMainModuleDescriptor( mockModuleInfoJava );
-
- ResolvePathsResult result = locationManager.resolvePaths( request );
-
- assertThat( result.getMainModuleDescriptor(), is( descriptor) );
- assertThat( result.getPathElements().size(), is( 1 ) );
- assertThat( result.getModulepathElements().size(), is( 1 ) );
- assertThat( result.getModulepathElements().get( abc), is( ModuleNameSource.MANIFEST ) );
- assertThat( result.getClasspathElements().size(), is( 0 ) );
- assertThat( result.getPathExceptions().size(), is( 0 ) );
+ public void testWithUnknownRequires() throws Exception {
+ JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule("base")
+ .requires("java.base")
+ .requires("jdk.net")
+ .build();
+ when(qdoxParser.fromSourcePath(any(Path.class))).thenReturn(descriptor);
+ ResolvePathsRequest request = ResolvePathsRequest.ofFiles(Collections.emptyList())
+ .setMainModuleDescriptor(mockModuleInfoJava.toFile());
+
+ ResolvePathsResult result = locationManager.resolvePaths(request);
+
+ assertThat(result.getMainModuleDescriptor(), is(descriptor));
+ assertThat(result.getPathElements().size(), is(0));
+ assertThat(result.getModulepathElements().size(), is(0));
+ assertThat(result.getClasspathElements().size(), is(0));
+ assertThat(result.getPathExceptions().size(), is(0));
}
-
+
@Test
- public void testDirDescriptorWithReflectRequires() throws Exception
- {
- Path abc = Paths.get( "src/test/resources/dir.descriptor/out" );
- JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule( "base" ).requires( "dir.descriptor" ).build();
- when( qdoxParser.fromSourcePath( any( Path.class ) ) ).thenReturn( descriptor );
- ResolvePathsRequest request = ResolvePathsRequest.ofPaths( Collections.singletonList( abc ) ).setMainModuleDescriptor( mockModuleInfoJava );
-
- when( asmParser.getModuleDescriptor( abc ) ).thenReturn( JavaModuleDescriptor.newModule( "dir.descriptor" ).build() );
-
- ResolvePathsResult result = locationManager.resolvePaths( request );
-
- assertThat( result.getMainModuleDescriptor(), is( descriptor) );
- assertThat( result.getPathElements().size(), is( 1 ) );
- assertThat( result.getModulepathElements().size(), is( 1 ) );
- assertThat( result.getModulepathElements().get( abc), is( ModuleNameSource.MODULEDESCRIPTOR ) );
- assertThat( result.getClasspathElements().size(), is( 0 ) );
- assertThat( result.getPathExceptions().size(), is( 0 ) );
+ public void testManifestWithReflectRequires() throws Exception {
+ Path abc = Paths.get("src/test/resources/dir.manifest.with/out");
+ JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule("base")
+ .requires("auto.by.manifest")
+ .build();
+ when(qdoxParser.fromSourcePath(any(Path.class))).thenReturn(descriptor);
+ ResolvePathsRequest request =
+ ResolvePathsRequest.ofPaths(Collections.singletonList(abc)).setMainModuleDescriptor(mockModuleInfoJava);
+
+ ResolvePathsResult result = locationManager.resolvePaths(request);
+
+ assertThat(result.getMainModuleDescriptor(), is(descriptor));
+ assertThat(result.getPathElements().size(), is(1));
+ assertThat(result.getModulepathElements().size(), is(1));
+ assertThat(result.getModulepathElements().get(abc), is(ModuleNameSource.MANIFEST));
+ assertThat(result.getClasspathElements().size(), is(0));
+ assertThat(result.getPathExceptions().size(), is(0));
}
@Test
- public void testJarWithAsmRequires() throws Exception
- {
- Path abc = Paths.get( "src/test/resources/jar.descriptor/asm-6.0_BETA.jar" );
- JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule( "base" ).requires( "org.objectweb.asm" ).build();
- when( qdoxParser.fromSourcePath( any( Path.class ) ) ).thenReturn( descriptor );
- ResolvePathsRequest request = ResolvePathsRequest.ofPaths( Collections.singletonList( abc ) ).setMainModuleDescriptor( mockModuleInfoJava );
-
- when( asmParser.getModuleDescriptor( abc ) ).thenReturn( JavaModuleDescriptor.newModule( "org.objectweb.asm" ).build() );
-
- ResolvePathsResult result = locationManager.resolvePaths( request );
-
- assertThat( result.getMainModuleDescriptor(), is( descriptor) );
- assertThat( result.getPathElements().size(), is( 1 ) );
- assertThat( result.getModulepathElements().size(), is( 1 ) );
- assertThat( result.getModulepathElements().get( abc), is( ModuleNameSource.MODULEDESCRIPTOR ) );
- assertThat( result.getClasspathElements().size(), is( 0 ) );
- assertThat( result.getPathExceptions().size(), is( 0 ) );
+ public void testDirDescriptorWithReflectRequires() throws Exception {
+ Path abc = Paths.get("src/test/resources/dir.descriptor/out");
+ JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule("base")
+ .requires("dir.descriptor")
+ .build();
+ when(qdoxParser.fromSourcePath(any(Path.class))).thenReturn(descriptor);
+ ResolvePathsRequest request =
+ ResolvePathsRequest.ofPaths(Collections.singletonList(abc)).setMainModuleDescriptor(mockModuleInfoJava);
+
+ when(asmParser.getModuleDescriptor(abc))
+ .thenReturn(JavaModuleDescriptor.newModule("dir.descriptor").build());
+
+ ResolvePathsResult result = locationManager.resolvePaths(request);
+
+ assertThat(result.getMainModuleDescriptor(), is(descriptor));
+ assertThat(result.getPathElements().size(), is(1));
+ assertThat(result.getModulepathElements().size(), is(1));
+ assertThat(result.getModulepathElements().get(abc), is(ModuleNameSource.MODULEDESCRIPTOR));
+ assertThat(result.getClasspathElements().size(), is(0));
+ assertThat(result.getPathExceptions().size(), is(0));
}
-
+
@Test
- public void testIdenticalModuleNames() throws Exception
- {
- Path pj1 = Paths.get( "src/test/resources/jar.empty/plexus-java-1.0.0-SNAPSHOT.jar" );
- Path pj2 = Paths.get( "src/test/resources/jar.empty.2/plexus-java-2.0.0-SNAPSHOT.jar" );
- JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule( "base" ).requires( "plexus.java" ).build();
- when( qdoxParser.fromSourcePath( any( Path.class ) ) ).thenReturn( descriptor );
- ResolvePathsRequest request = ResolvePathsRequest.ofPaths( Arrays.asList( pj1, pj2 ) ).setMainModuleDescriptor( mockModuleInfoJava );
-
- when( asmParser.getModuleDescriptor( pj1 ) ).thenReturn( JavaModuleDescriptor.newAutomaticModule( "plexus.java" ).build() );
- when( asmParser.getModuleDescriptor( pj2 ) ).thenReturn( JavaModuleDescriptor.newAutomaticModule( "plexus.java" ).build() );
-
- ResolvePathsResult result = locationManager.resolvePaths( request );
-
- assertThat( result.getMainModuleDescriptor(), is( descriptor) );
- assertThat( result.getPathElements().size(), is( 2 ) );
- assertThat( result.getModulepathElements().size(), is( 1 ) );
- assertThat( result.getModulepathElements().containsKey( pj1 ), is( true ) );
- assertThat( result.getModulepathElements().containsKey( pj2 ), is( false ) );
- assertThat( result.getClasspathElements().size(), is( 0 ) );
- assertThat( result.getPathExceptions().size(), is( 0 ) );
+ public void testJarWithAsmRequires() throws Exception {
+ Path abc = Paths.get("src/test/resources/jar.descriptor/asm-6.0_BETA.jar");
+ JavaModuleDescriptor descriptor = JavaModuleDescriptor.newModule("base")
+ .requires("org.objectweb.asm")
+ .build();
+ when(qdoxParser.fromSourcePath(any(Path.class))).thenReturn(descriptor);
+ ResolvePathsRequest request =
+ ResolvePathsRequest.ofPaths(Collections.singletonList(abc)).setMainModuleDescriptor(mockModuleInfoJava);
+
+ when(asmParser.getModuleDescriptor(abc))
+ .thenReturn(JavaModuleDescriptor.newModule("org.objectweb.asm").build());
+
+ ResolvePathsResult result = locationManager.resolvePaths(request);
+
+ assertThat(result.getMainModuleDescriptor(), is(descriptor));
+ assertThat(result.getPathElements().size(), is(1));
+ assertThat(result.getModulepathElements().size(), is(1));
+ assertThat(result.getModulepathElements().get(abc), is(ModuleNameSource.MODULEDESCRIPTOR));
+ assertThat(result.getClasspathElements().size(), is(0));
+ assertThat(result.getPathExceptions().size(), is(0));
}
@Test
- public void testNonJar() throws Exception
- {
- Path p = Paths.get( "src/test/resources/nonjar/pom.xml" );
-
- ResolvePathsRequest request = ResolvePathsRequest.ofPaths( Collections.singletonList( p ) ).setMainModuleDescriptor( mockModuleInfoJava );
-
- ResolvePathsResult result = locationManager.resolvePaths( request );
-
- assertThat( result.getPathExceptions().size(), is( 1 ) );
+ public void testIdenticalModuleNames() throws Exception {
+ Path pj1 = Paths.get("src/test/resources/jar.empty/plexus-java-1.0.0-SNAPSHOT.jar");
+ Path pj2 = Paths.get("src/test/resources/jar.empty.2/plexus-java-2.0.0-SNAPSHOT.jar");
+ JavaModuleDescriptor descriptor =
+ JavaModuleDescriptor.newModule("base").requires("plexus.java").build();
+ when(qdoxParser.fromSourcePath(any(Path.class))).thenReturn(descriptor);
+ ResolvePathsRequest