Skip to content
Commits on Source (17)
plexus-languages (0.9.10-1) unstable; urgency=medium
* New upstream release
- Refreshed the patch
- Restored the compatibility with the version of Mockito in Debian
- Updated the Maven rules
* Standards-Version updated to 4.1.5
* Switch to debhelper level 11
* Use salsa.debian.org Vcs-* URLs
-- Emmanuel Bourg <ebourg@apache.org> Mon, 30 Jul 2018 02:04:23 +0200
plexus-languages (0.9.5-2) unstable; urgency=medium
* Added the missing plexus-component-metadata configuration
......
......@@ -4,7 +4,7 @@ Priority: optional
Maintainer: Debian Java Maintainers <pkg-java-maintainers@lists.alioth.debian.org>
Uploaders: Emmanuel Bourg <ebourg@apache.org>
Build-Depends:
debhelper (>= 10),
debhelper (>= 11~),
default-jdk,
junit4 (>= 4.12),
libasm-java (>= 6.0-1~),
......@@ -13,9 +13,9 @@ Build-Depends:
libplexus-component-metadata-java (>= 1.5.5),
libqdox2-java,
maven-debian-helper (>= 2.2)
Standards-Version: 4.1.2
Vcs-Git: https://anonscm.debian.org/git/pkg-java/plexus-languages.git
Vcs-Browser: https://anonscm.debian.org/cgit/pkg-java/plexus-languages.git
Standards-Version: 4.1.5
Vcs-Git: https://salsa.debian.org/java-team/plexus-languages.git
Vcs-Browser: https://salsa.debian.org/java-team/plexus-languages
Homepage: https://github.com/codehaus-plexus/plexus-languages
Package: libplexus-languages-java
......
org.apache.maven.plugins maven-failsafe-plugin * * * *
org.apache.maven.plugins maven-site-plugin * * * *
......@@ -3,3 +3,5 @@ com.thoughtworks.qdox qdox jar s/.*/2.x/ * *
junit junit jar s/4\..*/4.x/ * *
org.codehaus.plexus plexus-component-annotations jar s/.*/1.5.5/ * *
org.codehaus.plexus plexus-component-metadata maven-plugin * * *
org.apache.maven.plugins maven-surefire-plugin maven-plugin s/2.21.0/2.17/ * *
......@@ -4,10 +4,10 @@ Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: not-needed
--- a/plexus-java/pom.xml
+++ b/plexus-java/pom.xml
@@ -31,6 +31,20 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
@@ -33,6 +33,20 @@
<version>1.7.1</version>
<!-- WATCH OUT duplicate compiler blocks confuses this plugin -->
<!-- Generated components.xml copied to src/main/resources -->
+ <executions>
+ <execution>
+ <id>process-classes</id>
......@@ -22,6 +22,6 @@ Forwarded: not-needed
+ </goals>
+ </execution>
+ </executions>
</plugin>
</plugins>
</build>
<configuration>
<extractors>
<extractor>source</extractor>
Description: Fixes the compatibility with the version of Mockito in Debian
Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: not-needed
--- 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
@@ -41,7 +41,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
-@RunWith( org.mockito.junit.MockitoJUnitRunner.class )
+@RunWith( org.mockito.runners.MockitoJUnitRunner.class )
public class LocationManagerTest
{
@Mock
01-plexus-component-metadata-configuration.patch
02-mockito-compatibility.patch
......@@ -2,6 +2,3 @@
%:
dh $@
get-orig-source:
uscan --download-current-version --force-download --rename --repack --compression xz
version=3
version=4
opts="repack,compression=xz" \
https://github.com/codehaus-plexus/plexus-languages/tags .*/plexus-languages-([\d\.]+).tar.gz
......@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-languages</artifactId>
<version>0.9.5</version>
<version>0.9.10</version>
</parent>
<artifactId>plexus-java</artifactId>
......@@ -22,7 +22,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<version>2.21.0</version>
</plugin>
</plugins>
</pluginManagement>
......@@ -31,6 +31,32 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>1.7.1</version>
<!-- WATCH OUT duplicate compiler blocks confuses this plugin -->
<!-- Generated components.xml copied to src/main/resources -->
<configuration>
<extractors>
<extractor>source</extractor>
</extractors>
</configuration>
</plugin>
<!-- Rerun unittests with the multirelease jar, cannot be done with exploded directory of classes -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.21.0</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
......@@ -39,12 +65,12 @@
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.0</version>
<version>6.2</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.qdox</groupId>
<artifactId>qdox</artifactId>
<version>2.0-M7</version>
<version>2.0-M8</version>
</dependency>
<dependency>
......@@ -69,7 +95,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<version>2.18.3</version>
<scope>test</scope>
</dependency>
<dependency>
......@@ -80,4 +106,55 @@
</dependency>
</dependencies>
<profiles>
<profile>
<id>jdk9</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<executions>
<execution>
<id>jdk9</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>9</release>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java9</compileSourceRoot>
</compileSourceRoots>
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/9</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<configuration>
<archive>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
......@@ -23,27 +23,13 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.regex.Pattern;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ModuleVisitor;
import org.objectweb.asm.Opcodes;
/**
* Extract information from module with ASM
*
* @author Robert Scholte
* @since 1.0.0
*/
public class AsmModuleInfoParser
implements ModuleInfoParser
public abstract class AbstractBinaryModuleInfoParser implements ModuleInfoParser
{
private static final Pattern MRJAR_DESCRIPTOR = Pattern.compile( "META-INF/versions/[^/]+/module-info.class" );
......@@ -106,47 +92,5 @@ public class AsmModuleInfoParser
return descriptor;
}
private JavaModuleDescriptor parse( InputStream in )
throws IOException
{
final JavaModuleDescriptorWrapper wrapper = new JavaModuleDescriptorWrapper();
ClassReader reader = new ClassReader( in );
reader.accept( new ClassVisitor( Opcodes.ASM6 )
{
@Override
public ModuleVisitor visitModule( String name, int arg1, String arg2 )
{
wrapper.builder = JavaModuleDescriptor.newModule( name );
return new ModuleVisitor( Opcodes.ASM6 )
{
@Override
public void visitRequire( String module, int access, String version )
{
wrapper.builder.requires( module );
}
@Override
public void visitExport( String pn, int ms, String... targets )
{
if ( targets == null || targets.length == 0 )
{
wrapper.builder.exports( pn.replace( '/', '.' ) );
}
else
{
wrapper.builder.exports( pn.replace( '/', '.' ), new HashSet<>( Arrays.asList( targets ) ) );
}
}
};
}
}, 0 );
return wrapper.builder.build();
}
private static class JavaModuleDescriptorWrapper
{
private JavaModuleDescriptor.Builder builder;
}
abstract JavaModuleDescriptor parse( InputStream in ) throws IOException;
}
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
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ModuleVisitor;
import org.objectweb.asm.Opcodes;
/**
* Extract information from module with ASM
*
*
* @author Robert Scholte
* @since 1.0.0
*/
class BinaryModuleInfoParser extends AbstractBinaryModuleInfoParser
{
@Override
JavaModuleDescriptor parse( InputStream in )
throws IOException
{
final JavaModuleDescriptorWrapper wrapper = new JavaModuleDescriptorWrapper();
ClassReader reader = new ClassReader( in );
reader.accept( new ClassVisitor( Opcodes.ASM6 )
{
@Override
public ModuleVisitor visitModule( String name, int arg1, String arg2 )
{
wrapper.builder = JavaModuleDescriptor.newModule( name );
return new ModuleVisitor( Opcodes.ASM6 )
{
@Override
public void visitRequire( String module, int access, String version )
{
if ( ( access & Opcodes.ACC_STATIC_PHASE ) != 0 )
{
wrapper.builder.requires( Collections.singleton( JavaModuleDescriptor.JavaRequires.JavaModifier.STATIC ),
module );
}
else
{
wrapper.builder.requires( module );
}
}
@Override
public void visitExport( String pn, int ms, String... targets )
{
if ( targets == null || targets.length == 0 )
{
wrapper.builder.exports( pn.replace( '/', '.' ) );
}
else
{
wrapper.builder.exports( pn.replace( '/', '.' ), new HashSet<>( Arrays.asList( targets ) ) );
}
}
};
}
}, 0 );
return wrapper.builder.build();
}
private static class JavaModuleDescriptorWrapper
{
private JavaModuleDescriptor.Builder builder;
}
}
......@@ -21,6 +21,7 @@ package org.codehaus.plexus.languages.java.jpms;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
/**
......@@ -93,6 +94,26 @@ public class JavaModuleDescriptor
return this;
}
/**
* Adds a dependence on a module with the given (and possibly empty) set of modifiers.
*
* @param modifiers The set of modifiers
* @param name The module name
* @return This builder
*/
public Builder requires( Set<JavaModuleDescriptor.JavaRequires.JavaModifier> modifiers, String name )
{
JavaRequires requires = new JavaRequires( modifiers, name );
jModule.requires.add( requires );
return this;
}
/**
* Adds a dependence on a module with an empty set of modifiers.
*
* @param name The module name
* @return This builder
*/
public Builder requires( String name )
{
JavaRequires requires = new JavaRequires( name );
......@@ -100,6 +121,12 @@ public class JavaModuleDescriptor
return this;
}
/**
* Adds an exported package. The package is exported to all modules.
*
* @param source The package name
* @return This builder
*/
public Builder exports( String source )
{
JavaExports exports = new JavaExports( source );
......@@ -107,6 +134,13 @@ public class JavaModuleDescriptor
return this;
}
/**
* Adds an exported package. The package is exported to a set of target modules.
*
* @param source The package name
* @param targets The set of target modules names
* @return This builder
*/
public Builder exports( String source, Set<String> targets )
{
JavaExports exports = new JavaExports( source, targets );
......@@ -114,6 +148,11 @@ public class JavaModuleDescriptor
return this;
}
/**
* Builds and returns a ModuleDescriptor from its components.
*
* @return The module descriptor
*/
public JavaModuleDescriptor build()
{
return jModule;
......@@ -128,17 +167,76 @@ public class JavaModuleDescriptor
*/
public static class JavaRequires
{
private final Set<JavaModifier> modifiers;
private final String name;
private JavaRequires( Set<JavaModifier> modifiers, String name )
{
this.modifiers = modifiers;
this.name = name;
}
private JavaRequires( String name )
{
this.modifiers = Collections.emptySet();
this.name = name;
}
public Set<JavaModifier> modifiers()
{
return modifiers;
}
public String name()
{
return name;
}
/**
* Represents Module.Requires.Modifier
*
* @author Robert Scholte
* @since 1.0.0
*/
public static enum JavaModifier
{
STATIC
}
@Override
public int hashCode()
{
return Objects.hash( modifiers, name );
}
@Override
public boolean equals( Object obj )
{
if ( this == obj )
{
return true;
}
if ( obj == null )
{
return false;
}
if ( getClass() != obj.getClass() )
{
return false;
}
JavaRequires other = (JavaRequires) obj;
if ( !Objects.equals( modifiers, other.modifiers ) )
{
return false;
}
if ( !Objects.equals( name, other.name ) )
{
return false;
}
return true;
}
}
/**
......@@ -174,5 +272,41 @@ public class JavaModuleDescriptor
{
return targets;
}
@Override
public int hashCode()
{
return Objects.hash( source, targets );
}
@Override
public boolean equals( Object obj )
{
if ( this == obj )
{
return true;
}
if ( obj == null )
{
return false;
}
if ( getClass() != obj.getClass() )
{
return false;
}
JavaExports other = (JavaExports) obj;
if ( !Objects.equals( source, other.source ) )
{
return false;
}
if ( !Objects.equals( targets, other.targets ) )
{
return false;
}
return true;
}
}
}
......@@ -45,22 +45,30 @@ import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult.ModuleNameSour
@Component( role = LocationManager.class )
public class LocationManager
{
private ModuleInfoParser asmParser;
private ModuleInfoParser binaryParser;
private QDoxModuleInfoParser qdoxParser;
private SourceModuleInfoParser sourceParser;
public LocationManager()
{
this.asmParser = new AsmModuleInfoParser();
this.qdoxParser = new QDoxModuleInfoParser();
this.binaryParser = new BinaryModuleInfoParser();
this.sourceParser = new SourceModuleInfoParser();
}
LocationManager( ModuleInfoParser asmParser, QDoxModuleInfoParser qdoxParser )
LocationManager( ModuleInfoParser binaryParser, SourceModuleInfoParser sourceParser )
{
this.asmParser = asmParser;
this.qdoxParser = qdoxParser;
this.binaryParser = binaryParser;
this.sourceParser = sourceParser;
}
/**
* Decide for every {@code request.getPathElements()} if it belongs to the modulePath or classPath, based on the
* {@code request.getMainModuleDescriptor()}.
*
* @param request the paths to resolve
* @return the result of the resolution
* @throws IOException if a critical IOException occurs
*/
public <T> ResolvePathsResult<T> resolvePaths( ResolvePathsRequest<T> request )
throws IOException
{
......@@ -76,11 +84,11 @@ public class LocationManager
{
if ( descriptorPath.endsWith( "module-info.java" ) )
{
mainModuleDescriptor = qdoxParser.fromSourcePath( descriptorPath );
mainModuleDescriptor = sourceParser.fromSourcePath( descriptorPath );
}
else if ( descriptorPath.endsWith( "module-info.class" ) )
{
mainModuleDescriptor = asmParser.getModuleDescriptor( descriptorPath.getParent() );
mainModuleDescriptor = binaryParser.getModuleDescriptor( descriptorPath.getParent() );
}
else
{
......@@ -114,7 +122,15 @@ public class LocationManager
// either jar or outputDirectory
if ( Files.isRegularFile( path ) || Files.exists( path.resolve( "module-info.class" ) ) )
{
moduleDescriptor = asmParser.getModuleDescriptor( path );
try
{
moduleDescriptor = binaryParser.getModuleDescriptor( path );
}
catch( IOException e )
{
result.getPathExceptions().put( t, e );
continue;
}
}
if ( moduleDescriptor != null )
......@@ -136,8 +152,16 @@ public class LocationManager
filenameAutoModules.put( t, path );
}
else
{
try
{
moduleName = MainClassModuleNameExtractor.getModuleName( path );
}
catch ( Exception e )
{
result.getPathExceptions().put( t, e );
continue;
}
if ( moduleName != null )
{
......@@ -192,13 +216,22 @@ public class LocationManager
requiredNamedModules.add( mainModuleDescriptor.name() );
requiredNamedModules.addAll( request.getAdditionalModules() );
select( mainModuleDescriptor, Collections.unmodifiableMap( availableNamedModules ), requiredNamedModules );
// in case of identical module names, first one wins
Set<String> collectedModules = new HashSet<>( requiredNamedModules.size() );
for ( Entry<T, JavaModuleDescriptor> entry : pathElements.entrySet() )
{
if ( entry.getValue() != null && requiredNamedModules.contains( entry.getValue().name() ) )
{
result.getModulepathElements().put( entry.getKey(), moduleNameSources.get( entry.getValue().name() ) );
if ( collectedModules.add( entry.getValue().name() ) )
{
result.getModulepathElements().put( entry.getKey(),
moduleNameSources.get( entry.getValue().name() ) );
}
}
else
{
......
......@@ -22,6 +22,7 @@ package org.codehaus.plexus.languages.java.jpms;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.nio.file.FileVisitResult;
......@@ -78,7 +79,11 @@ public class MainClassModuleNameExtractor
for ( Path p : files.values() )
{
argsWriter.append( p.toAbsolutePath().toString() );
// make sure the path is surrounded with quotes in case there is space
argsWriter.append( '"' );
// make sure to escape Windows paths
argsWriter.append( p.toAbsolutePath().toString().replace( "\\", "\\\\" ) );
argsWriter.append( '"' );
argsWriter.newLine();
}
}
......@@ -134,6 +139,8 @@ public class MainClassModuleNameExtractor
Properties properties = new Properties();
for ( String path : args )
{
try
{
String moduleName = getModuleName( Paths.get( path ) );
if ( moduleName != null )
......@@ -141,6 +148,11 @@ public class MainClassModuleNameExtractor
properties.setProperty( path, moduleName );
}
}
catch ( Exception e )
{
System.err.append( e.getMessage() );
}
}
try
{
......@@ -152,7 +164,7 @@ public class MainClassModuleNameExtractor
}
}
public static String getModuleName( Path modulePath )
public static String getModuleName( Path modulePath ) throws Exception
{
String name = null;
try
......@@ -181,6 +193,13 @@ public class MainClassModuleNameExtractor
Method nameMethod = moduleDescriptorInstance.getClass().getMethod( "name" );
name = (String) nameMethod.invoke( moduleDescriptorInstance );
}
catch ( InvocationTargetException e )
{
if ( e.getCause() instanceof Exception )
{
throw (Exception) e.getCause();
}
}
catch ( ReflectiveOperationException e )
{
// noop
......
......@@ -33,7 +33,7 @@ import java.util.jar.Manifest;
* @author Robert Scholte
* @since 1.0.0
*/
public class ManifestModuleNameExtractor implements ModuleNameExtractor
class ManifestModuleNameExtractor implements ModuleNameExtractor
{
@Override
public String extract( Path file )
......
......@@ -28,16 +28,14 @@ import java.nio.file.Path;
* @author Robert Scholte
* @since 1.0.0
*/
public interface ModuleInfoParser
interface ModuleInfoParser
{
/**
* Extracts the name from the module-info file
*
* @param modulePath
* @return
* @throws IOException
* @param modulePath the path to the {@code module-info.class}
* @return the module descriptor
* @throws IOException when the file could not be parsed
*/
JavaModuleDescriptor getModuleDescriptor( Path modulePath )
throws IOException;
......
......@@ -22,7 +22,7 @@ package org.codehaus.plexus.languages.java.jpms;
import java.io.IOException;
import java.nio.file.Path;
public interface ModuleNameExtractor
interface ModuleNameExtractor
{
String extract( Path path ) throws IOException;
}
......@@ -23,6 +23,7 @@ import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Collections;
/**
* Contains all information required to analyze the project
......@@ -38,11 +39,22 @@ public abstract class ResolvePathsRequest<T>
private Collection<T> pathElements;
private Collection<String> additionalModules;
private ResolvePathsRequest()
{
}
/**
* @deprecated use {@link #ofFiles(Collection)} instead
*/
@Deprecated
public static ResolvePathsRequest<File> withFiles( Collection<File> files )
{
return ofFiles( files );
}
public static ResolvePathsRequest<File> ofFiles( Collection<File> files )
{
ResolvePathsRequest<File> request = new ResolvePathsRequest<File>()
{
......@@ -57,7 +69,16 @@ public abstract class ResolvePathsRequest<T>
return request;
}
/**
* @deprecated use {@link #ofPaths(Collection)} instead
*/
@Deprecated
public static ResolvePathsRequest<Path> withPaths( Collection<Path> paths )
{
return ofPaths( paths );
}
public static ResolvePathsRequest<Path> ofPaths( Collection<Path> paths )
{
ResolvePathsRequest<Path> request = new ResolvePathsRequest<Path>() {
@Override
......@@ -70,7 +91,16 @@ public abstract class ResolvePathsRequest<T>
return request;
}
/**
* @deprecated use {@link #ofStrings(Collection)} instead
*/
@Deprecated
public static ResolvePathsRequest<String> withStrings( Collection<String> strings )
{
return ofStrings( strings );
}
public static ResolvePathsRequest<String> ofStrings( Collection<String> strings )
{
ResolvePathsRequest<String> request = new ResolvePathsRequest<String>() {
@Override
......@@ -115,6 +145,7 @@ public abstract class ResolvePathsRequest<T>
* In case the JRE is Java 8 or before, this jdkHome is used to extract the module name.
*
* @param jdkHome
* @return this request
*/
public ResolvePathsRequest<T> setJdkHome( T jdkHome )
{
......@@ -127,4 +158,24 @@ public abstract class ResolvePathsRequest<T>
return jdkHome;
}
/**
* The module names that are usually passed with {@code --add-modules}
*
* @param additionalModules
* @return this request
*/
public ResolvePathsRequest<T> setAdditionalModules( Collection<String> additionalModules )
{
this.additionalModules = additionalModules;
return this;
}
public Collection<String> getAdditionalModules()
{
if ( additionalModules == null )
{
additionalModules = Collections.emptyList();
}
return additionalModules;
}
}