Skip to content

Commit 26a4152

Browse files
committed
Using classical ct.sym from JDK16
1 parent e4d2626 commit 26a4152

File tree

3 files changed

+131
-17
lines changed

3 files changed

+131
-17
lines changed

pom.xml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
</scm>
2121
<properties>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<ct.sym>${java.home}/lib/ct.sym</ct.sym>
2324
</properties>
2425
<build>
2526
<plugins>
@@ -52,20 +53,13 @@
5253
<id>unpack</id>
5354
<phase>process-resources</phase>
5455
<goals>
55-
<goal>unpack</goal>
56+
<goal>unpack-dependencies</goal>
5657
</goals>
5758
<configuration>
58-
<artifactItems>
59-
<artifactItem>
60-
<groupId>org.frgaal</groupId>
61-
<artifactId>compiler</artifactId>
62-
<version>15.0.0</version>
63-
<type>jar</type>
64-
<overWrite>false</overWrite>
65-
</artifactItem>
66-
</artifactItems>
67-
<includes>META-INF/ct.sym/**/*</includes>
68-
<outputDirectory>${project.build.directory}/classes</outputDirectory>
59+
<includeGroupIds>org.netbeans.tools</includeGroupIds>
60+
<includes>**/*</includes>
61+
<exclude>META-INF/**</exclude>
62+
<outputDirectory>${project.build.directory}/classes/META-INF/sigtest/</outputDirectory>
6963
<overWriteReleases>false</overWriteReleases>
7064
<overWriteSnapshots>true</overWriteSnapshots>
7165
</configuration>
@@ -85,16 +79,16 @@
8579
<version>1.6.0</version>
8680
<executions>
8781
<execution>
88-
<id>list-ct.sym</id>
82+
<id>list-sigtest</id>
8983
<phase>process-classes</phase>
9084
<goals>
9185
<goal>java</goal>
9286
</goals>
9387
<configuration>
9488
<mainClass>org.netbeans.apitest.ListCtSym</mainClass>
9589
<arguments>
96-
<argument>${project.build.directory}/classes/META-INF/ct.sym.ls</argument>
97-
<argument>${project.build.directory}/classes/META-INF/ct.sym/</argument>
90+
<argument>${project.build.directory}/classes/META-INF/sigtest.ls</argument>
91+
<argument>${project.build.directory}/classes/META-INF/sigtest/</argument>
9892
<argument>2</argument>
9993
</arguments>
10094
</configuration>
@@ -211,6 +205,14 @@
211205
<version>15.0.0</version>
212206
<scope>test</scope>
213207
</dependency>
208+
<dependency>
209+
<groupId>org.netbeans.tools</groupId>
210+
<artifactId>ct-sym</artifactId>
211+
<version>latest</version>
212+
<scope>system</scope>
213+
<systemPath>${ct.sym}</systemPath>
214+
<type>jar</type>
215+
</dependency>
214216
</dependencies>
215217
<description>
216218
Signature test to compare APIs of two versions of JARs

src/main/java/com/sun/tdk/signaturetest/classpath/Release.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ private Release(char version, String... prefixes) {
2626
* @return found version or null
2727
*/
2828
public static Release find(int version) {
29+
if (version > 15) {
30+
return null;
31+
}
2932
char ch = (char) (version < 10 ? '0' + version : 'A' + (version - 10));
3033
return RELEASES.get(ch);
3134
}
@@ -36,7 +39,7 @@ InputStream findClass(String name) {
3639
return ClassLoader.getSystemClassLoader().getResourceAsStream(resourceName);
3740
} else {
3841
for (String p : prefixes) {
39-
final String resourceName = "/META-INF/ct.sym/" + p + "/" + name.replace('.', '/') + ".class";
42+
final String resourceName = "/META-INF/sigtest/" + p + "/" + name.replace('.', '/') + ".sig";
4043
InputStream is = Release.class.getResourceAsStream(resourceName);
4144
if (is != null) {
4245
return is;
@@ -51,7 +54,7 @@ InputStream findClass(String name) {
5154
static {
5255
List<String> lines = new ArrayList<>();
5356
try {
54-
try (BufferedReader r = new BufferedReader(new InputStreamReader(Release.class.getResourceAsStream("/META-INF/ct.sym.ls")))) {
57+
try (BufferedReader r = new BufferedReader(new InputStreamReader(Release.class.getResourceAsStream("/META-INF/sigtest.ls")))) {
5558
for (;;) {
5659
String l = r.readLine();
5760
if (l == null) {
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Sun designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Sun in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22+
* CA 95054 USA or visit www.sun.com if you need additional information or
23+
* have any questions.
24+
*/
25+
package com.sun.tdk.signaturetest.classpath;
26+
27+
import com.sun.tdk.signaturetest.loaders.BinaryClassDescrLoader;
28+
import com.sun.tdk.signaturetest.model.ClassDescription;
29+
import com.sun.tdk.signaturetest.model.MethodDescr;
30+
import java.util.Arrays;
31+
import java.util.HashSet;
32+
import java.util.Set;
33+
import org.junit.Test;
34+
import static org.junit.Assert.*;
35+
36+
public class ReleaseTest {
37+
38+
public ReleaseTest() {
39+
}
40+
41+
@Test
42+
public void testFindJDK8() throws ClassNotFoundException {
43+
Release jdk8 = Release.find(8);
44+
assertNotNull(jdk8.findClass("java.lang.Object"));
45+
assertNull(jdk8.findClass("java.lang.Module"));
46+
47+
BinaryClassDescrLoader loader = new BinaryClassDescrLoader(new ClasspathImpl(jdk8, null), 4096);
48+
ClassDescription deprecatedClass = loader.load("java.lang.Deprecated");
49+
assertMethods(deprecatedClass);
50+
}
51+
52+
@Test
53+
public void testFindJDK9() throws ClassNotFoundException {
54+
Release jdk9 = Release.find(9);
55+
assertNotNull(jdk9.findClass("java.lang.Object"));
56+
assertNotNull(jdk9.findClass("java.lang.Module"));
57+
assertNull(jdk9.findClass("java.lang.Record"));
58+
59+
BinaryClassDescrLoader loader = new BinaryClassDescrLoader(new ClasspathImpl(jdk9, null), 4096);
60+
ClassDescription deprecatedClass = loader.load("java.lang.Deprecated");
61+
assertMethods(deprecatedClass, "forRemoval", "since");
62+
}
63+
64+
@Test
65+
public void testFindJDK13() throws ClassNotFoundException {
66+
Release jdk13 = Release.find(13);
67+
assertNotNull(jdk13.findClass("java.lang.Object"));
68+
assertNotNull(jdk13.findClass("java.lang.Module"));
69+
assertNull(jdk13.findClass("java.lang.Record"));
70+
71+
BinaryClassDescrLoader loader = new BinaryClassDescrLoader(new ClasspathImpl(jdk13, null), 4096);
72+
ClassDescription deprecatedClass = loader.load("java.lang.Deprecated");
73+
assertMethods(deprecatedClass, "forRemoval", "since");
74+
}
75+
76+
@Test
77+
public void testFindJDK14() {
78+
Release jdk14 = Release.find(14);
79+
assertNotNull(jdk14.findClass("java.lang.Object"));
80+
assertNotNull(jdk14.findClass("java.lang.Module"));
81+
assertNotNull(jdk14.findClass("java.lang.Record"));
82+
}
83+
84+
@Test
85+
public void testFindJDK15() throws ClassNotFoundException {
86+
Release jdk15 = Release.find(15);
87+
assertNotNull(jdk15.findClass("java.lang.Object"));
88+
assertNotNull(jdk15.findClass("java.lang.Module"));
89+
assertNotNull(jdk15.findClass("java.lang.Record"));
90+
BinaryClassDescrLoader loader = new BinaryClassDescrLoader(new ClasspathImpl(jdk15, null), 4096);
91+
ClassDescription deprecatedClass = loader.load("java.lang.Deprecated");
92+
assertMethods(deprecatedClass, "forRemoval", "since");
93+
}
94+
95+
private void assertMethods(ClassDescription deprecatedClass, String... names) {
96+
MethodDescr[] arr = deprecatedClass.getDeclaredMethods();
97+
assertEquals("Same number of methods: " + Arrays.toString(arr), names.length, arr.length);
98+
99+
Set<String> all = new HashSet<>(Arrays.asList(names));
100+
for (int i = 0; i < arr.length; i++) {
101+
MethodDescr m = arr[i];
102+
all.remove(m.getName());
103+
}
104+
105+
assertEquals("Not found methods " + all, 0, all.size());
106+
}
107+
108+
109+
}

0 commit comments

Comments
 (0)