|
| 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 |
0 commit comments