Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled java9+ compatibility #91

Merged
merged 1 commit into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.FileVisitOption;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.Iterator;
Expand Down Expand Up @@ -123,6 +130,39 @@ else if ( ( file.getName().endsWith( ".jar" ) || file.getName().endsWith( ".jmod
// ignore other files
}

/**
* Recursively finds class files and invokes {@link #process(String, InputStream)}
*
* @param path Directory (or other Path like {@code Paths.get(URI.create("jrt:/modules"))}) full of class files,
* or a class file (in which case that single class is processed).
*/
public void process( Path path )
throws IOException {
Files.walkFileTree(path, Collections.<FileVisitOption>emptySet(), 10000, new SimpleFileVisitor<Path>() {

@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.getFileName().toString().endsWith(".class")) {
process(file.toString(), Files.newInputStream(file));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The InputStream created by Files.newInputStream(...) has to be closed again because it looks like the process(...) method does not do that.

}
// XXX we could add processing of jars here as well
// but it's not necessary for processing: Paths.get(URI.create("jrt:/modules"))
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
return FileVisitResult.CONTINUE;
}

});
}

protected void processDirectory( File dir )
throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.URI;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -71,8 +73,12 @@ public static void main( String[] args )
throws IOException
{
SignatureBuilder builder =
new SignatureBuilder( new FileOutputStream( "signature" ), new PrintWriterLogger( System.out ) );
builder.process( new File( System.getProperty( "java.home" ), "lib/rt.jar" ) );
new SignatureBuilder( new FileOutputStream( "signature" ), new PrintWriterLogger( System.out ) );
if ( getJavaVersion() > 8 ) {
builder.process( Paths.get(URI.create("jrt:/modules")) );
} else {
builder.process( new File( System.getProperty( "java.home" ), "lib/rt.jar" ) );
}
builder.close();
}

Expand Down Expand Up @@ -236,4 +242,22 @@ public FieldVisitor visitField( int access, String name, String desc, String sig
return null;
}
}

public static int getJavaVersion()
{
String version = System.getProperty("java.version");
if ( version.startsWith("1.") )
{
version = version.substring(2);
}
// Allow these formats:
// 1.8.0_72-ea
// 9-ea
// 9
// 9.0.1
int dotPos = version.indexOf( '.' );
int dashPos = version.indexOf( '-' );
return Integer.parseInt( version.substring( 0, dotPos > -1 ? dotPos : dashPos > -1 ? dashPos : 1 ) );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private class CheckingVisitor

public CheckingVisitor( String name )
{
super(Opcodes.ASM5);
super(Opcodes.ASM7);
this.ignoredPackageCache = new HashSet<String>( 50 * ignoredPackageRules.size() );
this.name = name;
}
Expand Down Expand Up @@ -355,7 +355,7 @@ public AnnotationVisitor visitAnnotation(String desc, boolean visible)

@Override
public FieldVisitor visitField(int access, String name, final String descriptor, String signature, Object value) {
return new FieldVisitor(Opcodes.ASM5) {
return new FieldVisitor(Opcodes.ASM7) {

@Override
public void visitEnd() {
Expand All @@ -369,7 +369,7 @@ public void visitEnd() {
public MethodVisitor visitMethod( int access, final String name, final String desc, String signature, String[] exceptions )
{
line = 0;
return new MethodVisitor(Opcodes.ASM5)
return new MethodVisitor(Opcodes.ASM7)
{
/**
* True if @IgnoreJRERequirement is set.
Expand Down