Skip to content

Commit 4515415

Browse files
gurunraoVerdent
authored andcommitted
jsonb signature test migration.
Signed-off-by: gurunandan.rao@oracle.com <gurunandan.rao@oracle.com>
1 parent 2a48519 commit 4515415

19 files changed

+4012
-1
lines changed

tck/pom.xml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<dependency>
6565
<groupId>jakarta.json</groupId>
6666
<artifactId>jakarta.json-api</artifactId>
67-
<version>2.0.1</version>
67+
<version>2.1.0</version>
6868
<scope>provided</scope>
6969
</dependency>
7070
<dependency>
@@ -94,10 +94,42 @@
9494
<artifactId>hamcrest</artifactId>
9595
<version>2.2</version>
9696
</dependency>
97+
<dependency>
98+
<groupId>org.netbeans.tools</groupId>
99+
<artifactId>sigtest-maven-plugin</artifactId>
100+
<version>1.4</version>
101+
</dependency>
97102
</dependencies>
98103

104+
<!-- TODO: Temporarily enable snapshot repository -->
105+
<repositories>
106+
<repository>
107+
<id>jakarta-snapshots</id>
108+
<url>https://jakarta.oss.sonatype.org/content/repositories/staging/</url>
109+
</repository>
110+
</repositories>
111+
112+
99113
<build>
100114
<plugins>
115+
<!--
116+
<plugin>
117+
<groupId>org.netbeans.tools</groupId>
118+
<artifactId>sigtest-maven-plugin</artifactId>
119+
<version>1.4</version>
120+
<executions>
121+
<execution>
122+
<goals>
123+
<goal>generate</goal>
124+
</goals>
125+
</execution>
126+
</executions>
127+
<configuration>
128+
<FileName>${project.build.directory}/jakarta.json.bind.sig_${version}</FileName>
129+
<packages>"jakarta.json.bind","jakarta.json.bind.adapter","jakarta.json.bind.annotation","jakarta.json.bind.config","jakarta.json.bind.serializer","jakarta.json.bind.spi"</packages>
130+
</configuration>
131+
</plugin>
132+
-->
101133
<plugin>
102134
<artifactId>maven-javadoc-plugin</artifactId>
103135
<configuration>
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
/*
18+
* $Id$
19+
*/
20+
package ee.jakarta.tck.json.bind.signaturetest;
21+
22+
import java.io.ByteArrayOutputStream;
23+
import java.io.File;
24+
import java.io.PrintWriter;
25+
import java.io.Serializable;
26+
import java.lang.reflect.Constructor;
27+
import java.lang.reflect.Method;
28+
import java.util.LinkedList;
29+
import java.util.List;
30+
31+
32+
public final class ApiCheckDriver extends SignatureTestDriver
33+
implements Serializable {
34+
35+
/* flags for the Diff utility argument list */
36+
private static final String BASE_FLAG = "-base";
37+
38+
private static final String TEST_FLAG = "-test";
39+
40+
private static final String PACKAGE_NO_SUBS_FLAG = "-PackageWithoutSubpackages";
41+
42+
private static final String PACKAGE_FLAG = "-package";
43+
44+
private static final String EXPACKAGE_FLAG = "-expackage";
45+
46+
private static final String REFLECT_FLAG = "-reflect";
47+
48+
private static final String CONST_FLAG = "-constvalues";
49+
50+
// ---------------------------------------- Methods from SignatureTestDriver
51+
52+
@Override
53+
protected String normalizeFileName(File f) {
54+
return f.getPath();
55+
}
56+
57+
@Override
58+
protected String[] createTestArguments(String packageListFile, String mapFile,
59+
String signatureRepositoryDir, String packageOrClassUnderTest,
60+
String classpath, boolean bStaticMode) throws Exception {
61+
62+
Class pkgListClass = Class.forName("javasoft.sqe.apiCheck.PackageList");
63+
Constructor pkgCtor = pkgListClass
64+
.getDeclaredConstructor(new Class[] { String.class });
65+
Object pkgInstance = pkgCtor.newInstance(new Object[] { packageListFile });
66+
67+
Method pkgMethod = pkgListClass.getDeclaredMethod("getSubPackagesFormatted",
68+
new Class[] { String.class });
69+
70+
String excludePkgs = (String) pkgMethod.invoke(pkgInstance,
71+
new Object[] { packageOrClassUnderTest });
72+
73+
List sigArgsList = new LinkedList();
74+
75+
sigArgsList.add(BASE_FLAG);
76+
sigArgsList.add(
77+
getSigFileInfo(packageOrClassUnderTest, mapFile, signatureRepositoryDir)
78+
.getFile());
79+
80+
if (classpath != null && classpath.length() > 0) {
81+
sigArgsList.add(TEST_FLAG);
82+
sigArgsList.add(classpath);
83+
}
84+
85+
sigArgsList.add(REFLECT_FLAG);
86+
sigArgsList.add(CONST_FLAG);
87+
sigArgsList.add(PACKAGE_FLAG);
88+
sigArgsList.add(packageOrClassUnderTest);
89+
90+
if (excludePkgs != null && excludePkgs.length() > 0) {
91+
sigArgsList.add(EXPACKAGE_FLAG);
92+
sigArgsList.add(excludePkgs);
93+
}
94+
95+
return (String[]) (sigArgsList.toArray(new String[sigArgsList.size()]));
96+
97+
} // END createTestArguments
98+
99+
@Override
100+
protected boolean runSignatureTest(String packageOrClassName,
101+
String[] testArguments) throws Exception {
102+
103+
Class diffClass = Class.forName("javasoft.sqe.apiCheck.Diff");
104+
Method mainMethod = diffClass.getDeclaredMethod("main",
105+
new Class[] { String[].class });
106+
mainMethod.invoke(null, new Object[] { testArguments });
107+
108+
Method diffMethod = diffClass.getDeclaredMethod("diffsFound",
109+
new Class[] {});
110+
return (!((Boolean) diffMethod.invoke(null, new Object[] {}))
111+
.booleanValue());
112+
113+
} // END runSignatureTest
114+
115+
@Override
116+
protected boolean runPackageSearch(String packageOrClassName,
117+
String[] testArguments) throws Exception {
118+
Class sigTestClass = Class
119+
.forName("com.sun.tdk.signaturetest.SignatureTest");
120+
Object sigTestInstance = sigTestClass.newInstance();
121+
122+
ByteArrayOutputStream output = new ByteArrayOutputStream();
123+
124+
// we want to replace the PACKAGE_FLAG with PACKAGE_NO_SUBS_FLAG
125+
for (int ii = 0; ii < testArguments.length; ii++) {
126+
if (testArguments[ii].equals(PACKAGE_FLAG)) {
127+
testArguments[ii] = PACKAGE_NO_SUBS_FLAG;
128+
}
129+
}
130+
131+
// dump args for debugging aid
132+
System.out.println(
133+
"\nCalling: com.sun.tdk.signaturetest.SignatureTest() with following args:");
134+
for (int ii = 0; ii < testArguments.length; ii++) {
135+
System.out.println(" testArguments[" + ii + "] = " + testArguments[ii]);
136+
}
137+
138+
@SuppressWarnings("unchecked")
139+
Method runMethod = sigTestClass.getDeclaredMethod("run",
140+
new Class[] { String[].class, PrintWriter.class, PrintWriter.class });
141+
runMethod.invoke(sigTestInstance,
142+
new Object[] { testArguments, new PrintWriter(output, true), null });
143+
144+
String rawMessages = output.toString();
145+
146+
// currently, there is no way to determine if there are error msgs in
147+
// the rawmessages, so we will always dump this and call it a status.
148+
System.out.println(
149+
"********** Status Report '" + packageOrClassName + "' **********\n");
150+
System.out.println(rawMessages);
151+
return sigTestInstance.toString().substring(7).startsWith("Passed.");
152+
}
153+
154+
@Override
155+
protected boolean verifyJTAJarForNoXA(String classpath, String repositoryDir)
156+
throws Exception {
157+
// Need to find out whether implementing this method is really required now.
158+
// By default, signature test framework will use sigtest
159+
return true;
160+
}
161+
162+
} // END ApiCheckDriver
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package ee.jakarta.tck.json.bind.signaturetest;
18+
19+
import java.lang.reflect.Method;
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
23+
/**
24+
* <p>
25+
* This implementation of {@link Recorder} will record signatures using the
26+
* <code>ApiCheck</code> framework.
27+
* </p>
28+
*/
29+
public class ApiCheckRecorder extends Recorder {
30+
31+
// ------------------------------------------------------------ Constructors
32+
33+
public ApiCheckRecorder(String[] args) {
34+
35+
super(args);
36+
System.setProperty("pkg.list.file.path", packageListFile);
37+
System.setProperty("map.file.path", signatureMapFile);
38+
System.setProperty("signature.repository.dir", signatureRepositoryDir);
39+
40+
} // END ApiCheckRecorder
41+
42+
// ------------------------------------------------------- Protected Methods
43+
44+
protected String[] createCommandLine(String version, String classpath,
45+
String outputFileName, String packageName) {
46+
47+
List command = new ArrayList();
48+
49+
command.add("-constvalues");
50+
command.add("-xpriv");
51+
52+
command.add("-in");
53+
command.add(classpath);
54+
55+
return ((String[]) command.toArray(new String[command.size()]));
56+
57+
} // END getCommandLine
58+
59+
protected void writePackageListFile(String basePackageName,
60+
String signatureFile, String packageListFile) throws Exception {
61+
62+
// no-op as this is done internally by our version of ApiCheck
63+
64+
} // END writePackageListFile
65+
66+
protected void doRecord(String[] commandLine) throws Exception {
67+
68+
Class batchSetup = Class.forName("javasoft.sqe.apiCheck.BatchSetup");
69+
Method mainMethod = batchSetup.getDeclaredMethod("main",
70+
new Class[] { String[].class });
71+
mainMethod.invoke(null, new Object[] { commandLine });
72+
73+
} // END doRecord
74+
75+
} // END SigTestRecorder

0 commit comments

Comments
 (0)