Move tool that generates JCL comparison into a separate project. Make this tool compatible with JRE9+
7
pom.xml
|
@ -360,6 +360,13 @@
|
|||
</modules>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>with-classlib-comparison</id>
|
||||
<modules>
|
||||
<module>tools/classlib-comparison-gen</module>
|
||||
</modules>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>sign-artifacts</id>
|
||||
<build>
|
||||
|
|
101
tools/classlib-comparison-gen/pom.xml
Normal file
|
@ -0,0 +1,101 @@
|
|||
<!--
|
||||
~ Copyright 2019 konsoletyper.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.teavm</groupId>
|
||||
<artifactId>teavm</artifactId>
|
||||
<version>0.6.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>teavm-classlib-comparison-gen</artifactId>
|
||||
|
||||
<name>Tool that generates HTML report about supported classes in TeaVM</name>
|
||||
<description>Tool that generates HTML report about supported classes in TeaVM</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.teavm</groupId>
|
||||
<artifactId>teavm-classlib</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-commons</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-util</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.carrotsearch</groupId>
|
||||
<artifactId>hppc</artifactId>
|
||||
<version>0.7.3</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.teavm</groupId>
|
||||
<artifactId>teavm-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<configuration>
|
||||
<configLocation>../../checkstyle.xml</configLocation>
|
||||
<propertyExpansion>config_loc=${basedir}/../..</propertyExpansion>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2014 Alexey Andreev.
|
||||
* Copyright 2019 konsoletyper.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -13,19 +13,20 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.classlib.impl.report;
|
||||
package org.teavm.tools.classlibcomparison;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class JCLClass {
|
||||
public final String name;
|
||||
public JCLStatus status;
|
||||
public JCLVisibility visibility = JCLVisibility.PUBLIC;
|
||||
public JCLClassType type;
|
||||
public final List<JCLItem> items = new ArrayList<>();
|
||||
final String name;
|
||||
JCLStatus status;
|
||||
JCLVisibility visibility = JCLVisibility.PUBLIC;
|
||||
JCLClassType type;
|
||||
String outer;
|
||||
final List<JCLItem> items = new ArrayList<>();
|
||||
|
||||
public JCLClass(String name) {
|
||||
JCLClass(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2014 Alexey Andreev.
|
||||
* Copyright 2019 konsoletyper.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.classlib.impl.report;
|
||||
package org.teavm.tools.classlibcomparison;
|
||||
|
||||
enum JCLClassType {
|
||||
CLASS,
|
|
@ -13,14 +13,31 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.classlib.impl.report;
|
||||
package org.teavm.tools.classlibcomparison;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.*;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.FileSystemNotFoundException;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.Type;
|
||||
|
@ -28,11 +45,8 @@ import org.teavm.model.ReferenceCache;
|
|||
import org.teavm.parsing.ClasspathClassHolderSource;
|
||||
|
||||
public class JCLComparisonBuilder {
|
||||
private static final String JAR_PREFIX = "jar:file:";
|
||||
private static final String JAR_SUFFIX = "!/java/lang/Object.class";
|
||||
private static final String CLASS_SUFFIX = ".class";
|
||||
private static final String TEMPLATE_PLACEHOLDER = "${CONTENT}";
|
||||
private Set<String> packages = new HashSet<>();
|
||||
private ClassLoader classLoader = JCLComparisonBuilder.class.getClassLoader();
|
||||
private JCLComparisonVisitor visitor;
|
||||
private String outputDirectory;
|
||||
|
@ -45,10 +59,6 @@ public class JCLComparisonBuilder {
|
|||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
public Set<String> getPackages() {
|
||||
return packages;
|
||||
}
|
||||
|
||||
public String getOutputDirectory() {
|
||||
return outputDirectory;
|
||||
}
|
||||
|
@ -59,7 +69,7 @@ public class JCLComparisonBuilder {
|
|||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length == 0) {
|
||||
System.err.println("Usage: package.name [package.name2 ...] [-output directory]");
|
||||
System.err.println("Usage: -output <directory>");
|
||||
System.exit(1);
|
||||
}
|
||||
JCLComparisonBuilder builder = new JCLComparisonBuilder();
|
||||
|
@ -67,8 +77,6 @@ public class JCLComparisonBuilder {
|
|||
for (int i = 0; i < args.length; ++i) {
|
||||
if (args[i].equals("-output")) {
|
||||
builder.setOutputDirectory(args[++i]);
|
||||
} else {
|
||||
builder.getPackages().add(args[i].replace('.', '/'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +98,7 @@ public class JCLComparisonBuilder {
|
|||
copyResource("html/enum_obj.png");
|
||||
copyResource("html/annotation_obj.png");
|
||||
try (Writer out = new OutputStreamWriter(new FileOutputStream(new File(
|
||||
outputDirectory, "jcl.html")), "UTF-8")) {
|
||||
outputDirectory, "jcl.html")), StandardCharsets.UTF_8)) {
|
||||
generateHtml(out, packages);
|
||||
}
|
||||
File packagesDirectory = new File(outputDirectory, "packages");
|
||||
|
@ -115,47 +123,75 @@ public class JCLComparisonBuilder {
|
|||
|
||||
private List<JCLPackage> buildModel() throws IOException {
|
||||
Map<String, JCLPackage> packageMap = new HashMap<>();
|
||||
URL url = classLoader.getResource("java/lang/Object" + CLASS_SUFFIX);
|
||||
String path = url.toString();
|
||||
if (!path.startsWith(JAR_PREFIX) || !path.endsWith(JAR_SUFFIX)) {
|
||||
throw new RuntimeException("Can't find JCL classes");
|
||||
}
|
||||
ClasspathClassHolderSource classSource = new ClasspathClassHolderSource(classLoader, new ReferenceCache());
|
||||
path = path.substring(JAR_PREFIX.length(), path.length() - JAR_SUFFIX.length());
|
||||
File outDir = new File(outputDirectory).getParentFile();
|
||||
if (!outDir.exists()) {
|
||||
outDir.mkdirs();
|
||||
}
|
||||
path = URLDecoder.decode(path, "UTF-8");
|
||||
try (JarInputStream jar = new JarInputStream(new FileInputStream(path))) {
|
||||
visitor = new JCLComparisonVisitor(classSource, packageMap);
|
||||
while (true) {
|
||||
JarEntry entry = jar.getNextJarEntry();
|
||||
if (entry == null) {
|
||||
break;
|
||||
}
|
||||
if (validateName(entry.getName())) {
|
||||
compareClass(jar);
|
||||
}
|
||||
jar.closeEntry();
|
||||
try {
|
||||
Path p = Paths.get(URI.create("jrt:/modules/java.base/java/"));
|
||||
Files.walkFileTree(p, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
if (validateName(file.getFileName().toString())) {
|
||||
try (InputStream input = Files.newInputStream(file)) {
|
||||
compareClass(input);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
System.out.println();
|
||||
} catch (FileSystemNotFoundException ex) {
|
||||
System.out.println("Could not read my modules (perhaps not Java 9?).");
|
||||
}
|
||||
|
||||
for (JCLPackage pkg : packageMap.values()) {
|
||||
for (JCLClass cls : pkg.classes.toArray(new JCLClass[0])) {
|
||||
if (cls.outer != null) {
|
||||
removeInnerPrivateClasses(packageMap, pkg, cls.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String packageName : packageMap.keySet().toArray(new String[0])) {
|
||||
JCLPackage pkg = packageMap.get(packageName);
|
||||
if (pkg.classes.stream().allMatch(cls -> cls.status == JCLStatus.MISSING)) {
|
||||
packageMap.remove(packageName);
|
||||
} else if (pkg.classes.stream().anyMatch(cls -> cls.status == JCLStatus.MISSING)) {
|
||||
pkg.status = JCLStatus.PARTIAL;
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<>(packageMap.values());
|
||||
}
|
||||
|
||||
private boolean removeInnerPrivateClasses(Map<String, JCLPackage> packageMap, JCLPackage pkg, String className) {
|
||||
JCLClass cls = pkg.classes.stream().filter(c -> c.name.equals(className)).findFirst().orElse(null);
|
||||
if (cls == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (cls.outer != null) {
|
||||
String packageName = cls.outer.substring(0, cls.outer.lastIndexOf('.'));
|
||||
JCLPackage outerPackage = packageMap.get(packageName);
|
||||
if (outerPackage == null || removeInnerPrivateClasses(packageMap, outerPackage, cls.outer)) {
|
||||
pkg.classes.remove(cls);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void processModel(List<JCLPackage> packages) {
|
||||
Collections.sort(packages, (o1, o2) -> o1.name.compareTo(o2.name));
|
||||
packages.sort(Comparator.comparing(o -> o.name));
|
||||
for (JCLPackage pkg : packages) {
|
||||
Collections.sort(pkg.classes, (o1, o2) -> o1.name.compareTo(o2.name));
|
||||
pkg.classes.sort(Comparator.comparing(o -> o.name));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validateName(String name) {
|
||||
if (!name.endsWith(CLASS_SUFFIX)) {
|
||||
return false;
|
||||
}
|
||||
int slashIndex = name.lastIndexOf('/');
|
||||
return slashIndex >= 0 && packages.contains(name.substring(0, slashIndex));
|
||||
return name.endsWith(CLASS_SUFFIX);
|
||||
}
|
||||
|
||||
private void compareClass(InputStream input) throws IOException {
|
||||
|
@ -174,7 +210,8 @@ public class JCLComparisonBuilder {
|
|||
|
||||
private void generateHtml(Writer out, List<JCLPackage> packages) throws IOException {
|
||||
String template;
|
||||
try (Reader reader = new InputStreamReader(classLoader.getResourceAsStream("html/jcl.html"), "UTF-8")) {
|
||||
try (Reader reader = new InputStreamReader(classLoader.getResourceAsStream("html/jcl.html"),
|
||||
StandardCharsets.UTF_8)) {
|
||||
template = IOUtils.toString(reader);
|
||||
}
|
||||
int placeholderIndex = template.indexOf(TEMPLATE_PLACEHOLDER);
|
||||
|
@ -207,7 +244,8 @@ public class JCLComparisonBuilder {
|
|||
|
||||
private void generatePackageHtml(Writer out, JCLPackage pkg) throws IOException {
|
||||
String template;
|
||||
try (Reader reader = new InputStreamReader(classLoader.getResourceAsStream("html/jcl-class.html"), "UTF-8")) {
|
||||
try (Reader reader = new InputStreamReader(classLoader.getResourceAsStream("html/jcl-class.html"),
|
||||
StandardCharsets.UTF_8)) {
|
||||
template = IOUtils.toString(reader);
|
||||
}
|
||||
template = template.replace("${CLASSNAME}", pkg.name);
|
||||
|
@ -242,7 +280,8 @@ public class JCLComparisonBuilder {
|
|||
|
||||
private void generateClassHtml(Writer out, JCLPackage pkg, JCLClass cls) throws IOException {
|
||||
String template;
|
||||
try (Reader reader = new InputStreamReader(classLoader.getResourceAsStream("html/jcl-class.html"), "UTF-8")) {
|
||||
try (Reader reader = new InputStreamReader(classLoader.getResourceAsStream("html/jcl-class.html"),
|
||||
StandardCharsets.UTF_8)) {
|
||||
template = IOUtils.toString(reader);
|
||||
}
|
||||
template = template.replace("${CLASSNAME}", pkg.name + "." + cls.name);
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2014 Alexey Andreev.
|
||||
* Copyright 2019 konsoletyper.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.classlib.impl.report;
|
||||
package org.teavm.tools.classlibcomparison;
|
||||
|
||||
import java.util.Map;
|
||||
import org.objectweb.asm.*;
|
||||
|
@ -135,30 +135,9 @@ class JCLComparisonVisitor extends ClassVisitor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void visitSource(String source, String debug) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitOuterClass(String owner, String name, String desc) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAttribute(Attribute attr) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInnerClass(String name, String outerName, String innerName, int access) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
if (jclPackage != null && (jclClass == null || jclClass.status != JCLStatus.FOUND)) {
|
||||
jclPackage.status = JCLStatus.PARTIAL;
|
||||
public void visitNestHost(String nestHost) {
|
||||
if (jclClass != null) {
|
||||
jclClass.outer = nestHost.replace('/', '.');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2014 Alexey Andreev.
|
||||
* Copyright 2019 konsoletyper.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.classlib.impl.report;
|
||||
package org.teavm.tools.classlibcomparison;
|
||||
|
||||
class JCLItem {
|
||||
public final JCLItemType type;
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2014 Alexey Andreev.
|
||||
* Copyright 2019 konsoletyper.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.classlib.impl.report;
|
||||
package org.teavm.tools.classlibcomparison;
|
||||
|
||||
enum JCLItemType {
|
||||
FIELD,
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2014 Alexey Andreev.
|
||||
* Copyright 2019 konsoletyper.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.classlib.impl.report;
|
||||
package org.teavm.tools.classlibcomparison;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2014 Alexey Andreev.
|
||||
* Copyright 2019 konsoletyper.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.classlib.impl.report;
|
||||
package org.teavm.tools.classlibcomparison;
|
||||
|
||||
enum JCLStatus {
|
||||
FOUND,
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2014 Alexey Andreev.
|
||||
* Copyright 2019 konsoletyper.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.teavm.classlib.impl.report;
|
||||
package org.teavm.tools.classlibcomparison;
|
||||
|
||||
enum JCLVisibility {
|
||||
PUBLIC,
|
Before Width: | Height: | Size: 481 B After Width: | Height: | Size: 481 B |
Before Width: | Height: | Size: 774 B After Width: | Height: | Size: 774 B |
Before Width: | Height: | Size: 513 B After Width: | Height: | Size: 513 B |
Before Width: | Height: | Size: 222 B After Width: | Height: | Size: 222 B |
Before Width: | Height: | Size: 221 B After Width: | Height: | Size: 221 B |
Before Width: | Height: | Size: 745 B After Width: | Height: | Size: 745 B |
Before Width: | Height: | Size: 299 B After Width: | Height: | Size: 299 B |
Before Width: | Height: | Size: 325 B After Width: | Height: | Size: 325 B |
Before Width: | Height: | Size: 345 B After Width: | Height: | Size: 345 B |