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

Ensure that sigtest -IgnoreJDKClass can ignore JDK classes (java.* and javax.transaction.xa.*) during signature check #30

Merged
merged 3 commits into from
Apr 10, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions tools/sigtest/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SigTest

**_NOTE:_** This is a fork of the https://github.com/jtulach/netbeans-apitest project to allow for
updates as needed by the Jakarta projects. The GAV for this fork has changed to:
**_NOTE:_** This is a fork of the https://github.com/jtulach/netbeans-apitest (which was a fork of the now archived OpenJDK https://github.com/openjdk/sigtest) project.
The purpose of this project is to allow for updates as needed by the Jakarta projects. The GAV for this fork has changed to:
```xml
<dependency>
<groupId>jakarta.tck</groupId>
Expand All @@ -12,10 +12,7 @@ updates as needed by the Jakarta projects. The GAV for this fork has changed to:

*SigTest* is the tool for checking incompatibilities between different versions of the same API.
It is possible to use it as a Maven plugin or an Ant task to check for binary backward
compatibility and mutual signature compatibility. The tool is known to work with JDK8 and JDK11 and is used by many projects including [Graal](https://github.com/oracle/graal/commit/6ca3d0458d108ba183997f09fa51596fbe503893#diff-6229fdf88aa48f7dda4de6126283c913),
[Hibernate](https://github.com/hibernate/hibernate-validator/pull/831/files), Apache [NetBeans](https://github.com/apache/incubator-netbeans/pull/670), and [Jakarta EE](https://jakarta.ee).

[![Travis Status](https://travis-ci.org/jtulach/netbeans-apitest.svg?branch=master)](https://travis-ci.org/jtulach/netbeans-apitest)
compatibility and mutual signature compatibility. The tool is known to work with JDK11+.

## Use in Maven

Expand All @@ -40,7 +37,7 @@ e.g. the signature file. Just add following into your own `pom.xml` file:
</execution>
</executions>
<configuration>
<release>8</release> <!-- specify version of JDK API to use 8,11,...21 -->
<release>11</release> <!-- specify version of JDK API to use 11,...21 -->
<packages>org.yourcompany.app.api,org.yourcompany.help.api</packages>
</configuration>
</plugin>
Expand Down Expand Up @@ -76,7 +73,7 @@ Try the following:
<configuration>
<packages>org.yourcompany.app.api,org.yourcompany.help.api</packages>
<releaseVersion>1.3</releaseVersion>
<release>8</release> <!-- specify version of JDK API to use 6,7,8,...15 -->
<release>11</release> <!-- specify version of JDK API to use 11,...21 -->
</configuration>
</plugin>
```
Expand Down Expand Up @@ -139,7 +136,7 @@ then try:

<packages>org.yourcompany.app.api,org.yourcompany.help.api</packages>
<releaseVersion>1.3</releaseVersion>
<release>8</release> <!-- specify version of JDK API to use 6,7,8,...15 -->
<release>11</release> <!-- specify version of JDK API to use 11,...21 -->
</configuration>
```

Expand All @@ -148,25 +145,23 @@ with the action option set to `strictcheck` the plugin will detect any API chang
## Relax verification of JDK signatures

There are some cases where avoiding the verification of certain JDK classes entirely or their signatures can improve the ability to verify your API on different JDK versions.
The `-IgnoreJDKClass` option can be used to specify a set of JDK classes that can benefit from relaxed signature verification rules when it comes to dealing with JDK
specific signature changes introduced by a later JDK version. As an example, a Signature file with @java.lang.Deprecated annotations from JDK8 may be seeing verification failures on JDK9+
due to `default` fields being added to @Deprecated. With `-IgnoreJDKClass java.lang.Deprecated` enabled, verification of the @Deprecated will only check that the tested class member has the
The `-IgnoreJDKClass` option will ignore (all) JDK java.* and javax.* classes during signature verification checking which helps avoid failures caused by
JDK specific signature changes introduced by a later JDK version. As an example, a Signature file with @java.lang.Deprecated annotations from JDK8 may be seeing verification failures on JDK9+
due to `default` fields being added to @Deprecated. With `-IgnoreJDKClass specified, verification of the @Deprecated will only check that the tested class member has the
@Deprecated class but no verification of the @Deprecated signature will be performed.

Note that previous releases allowed a list of JDK classes to be specified after the -IgnoreJDKClass option but that is no longer allowed.

### Specify JDK classes to ignore in Maven plugin
To configure the JDK classes to pass to the sigtest engine with a `-IgnoreJDKClass` option, use the ignoreJDKClasses
configuration element and provide the classes to ignore using the include element as shown here:
Specify the `-IgnoreJDKClass` option as shown below:

```xml
<configuration>
<action>check</action>

<packages>org.yourcompany.app.api,org.yourcompany.help.api</packages>
<releaseVersion>1.3</releaseVersion>
<ignoreJDKClasses>
<include>java.lang.Deprecated</include>
<include>java.lang.Object</include>
</ignoreJDKClasses>
<ignoreJDKClasses/>
</configuration>
```

Expand All @@ -177,8 +172,8 @@ but has been adopted to suite the needs of a [NetBeans project](http://wiki.netb
Since then it evolved into [general purpose tool](http://wiki.netbeans.org/SigTest). When NetBeans become
Apache project, Emilian Bold converted the [original Hg repository](http://hg.netbeans.org/apitest/) to
[Git repository](https://github.com/emilianbold/netbeans-apitest) to preserve the history. The development,
including support for JDK11, etc. now continues at following GitHub
[repository](https://github.com/jtulach/netbeans-apitest/).
including support for JDK11, etc. then moved to [repository](https://github.com/jtulach/netbeans-apitest/).
This tool has been forked (yet again) now to the [github repository](https://github.com/eclipse-ee4j/jakartaee-tck-tools/tree/master/tools/sigtest)

# License

Expand Down
29 changes: 25 additions & 4 deletions tools/sigtest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<groupId>jakarta.tck</groupId>
<artifactId>sigtest-maven-plugin</artifactId>
<version>2.2</version>
<version>2.3-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<name>API Signature Test Plugin</name>
<url>https://github.com/eclipse-ee4j/jakartaee-tck-tools/wiki</url>
Expand Down Expand Up @@ -216,10 +216,16 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -285,6 +291,21 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>jakarta.tck</groupId>
<artifactId>sigtest-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<release>17</release> <!-- specify version of JDK API to use -->
<packages>com.sun.tdk.signaturetest.classpath</packages>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void perform() {
try {
if (in.isFeatureSupported(FeaturesHolder.BuildMembers))
builder.createMembers(c, true, true, false);
normalizer.normThrows(c, true);
normalizer.normThrows(c, true, false);
} catch (ClassNotFoundException e) {
//storeError(i18n.getString("Setup.error.message.classnotfound", e.getMessage()));
}
Expand All @@ -240,7 +240,7 @@ void perform() {
ClassDescription c = (ClassDescription) i.next();
try {
builder.createMembers(c, false, true, false);
normalizer.normThrows(c, true);
normalizer.normThrows(c, true, false);
} catch (ClassNotFoundException e) {
storeError(i18n.getString("Merge.warning.message.classnotfound", e.getMessage()), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ protected boolean parseParameters(String[] args) {

parser.addOption(ERRORALL_OPTION, OptionInfo.optionalFlag(), optionsDecoder);

parser.addOption(EXCLUDE_JDK_CLASS_OPTION, OptionInfo.optionalFlag(), optionsDecoder);
try {
parser.processArgs(args);
}
Expand Down Expand Up @@ -481,7 +482,7 @@ private boolean create(URL sigFile) {

try {
testableMCBuilder.createMembers(c, addInherited(), true, false);
normalizer.normThrows(c, true);
normalizer.normThrows(c, true, false);
removeUndocumentedAnnotations(c, testableHierarchy);
} catch (ClassNotFoundException e) {
if (SigTest.debug) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public boolean run(String[] args, PrintWriter log, PrintWriter ref) {

parser.addOption(SigTest.PACKAGE_OPTION, OptionInfo.optionVariableParams(1, OptionInfo.UNLIMITED), optionsDecoder);
parser.addOption(SigTest.FILENAME_OPTION, OptionInfo.option(1), optionsDecoder);
parser.addOption(SigTest.EXCLUDE_JDK_CLASS_OPTION, OptionInfo.optionalFlag(), optionsDecoder);

parser.addOption(SigTest.WITHOUTSUBPACKAGES_OPTION, OptionInfo.optionVariableParams(1, OptionInfo.UNLIMITED), optionsDecoder);
parser.addOption(SigTest.EXCLUDE_OPTION, OptionInfo.optionVariableParams(1, OptionInfo.UNLIMITED), optionsDecoder);
Expand Down Expand Up @@ -174,6 +175,8 @@ public void decodeOptions(String optionName, String[] args) {
addOption(setupOptions, SigTest.CLASSPATH_OPTION, args[0]);
} else if (optionName.equalsIgnoreCase(TEST_OPTION)) {
addOption(testOptions, SigTest.CLASSPATH_OPTION, args[0]);
} else if (optionName.equalsIgnoreCase(SigTest.EXCLUDE_JDK_CLASS_OPTION)) {
addFlag(testOptions, SigTest.EXCLUDE_JDK_CLASS_OPTION);
} else if (optionName.equalsIgnoreCase(SigTest.FILENAME_OPTION) ||
optionName.equalsIgnoreCase(SigTest.PACKAGE_OPTION) ||
optionName.equalsIgnoreCase(SigTest.WITHOUTSUBPACKAGES_OPTION) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.sun.tdk.signaturetest.util.CommandLineParser;
import com.sun.tdk.signaturetest.util.CommandLineParserException;
import com.sun.tdk.signaturetest.util.I18NResourceBundle;
import com.sun.tdk.signaturetest.util.OptionInfo;

import java.io.PrintWriter;
import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -103,7 +104,7 @@ public abstract class SigTest extends Result implements PluginAPI, Log {
public static final String TESTURL_OPTION = "-TestURL";
public static final String PLUGIN_OPTION = "-Plugin";
public static final String ERRORALL_OPTION = "-ErrorAll";

public static final String EXCLUDE_JDK_CLASS_OPTION = "-IgnoreJDKClass";

private static I18NResourceBundle i18n = I18NResourceBundle.getBundleForClass(SigTest.class);

Expand Down Expand Up @@ -284,6 +285,8 @@ protected void decodeCommonOptions(String optionName, String[] args) throws Comm
excludedPackages.addPackages(CommandLineParser.parseListOption(args));
} else if (optionName.equalsIgnoreCase(CLASSPATH_OPTION)) {
classpathStr = args[0];
} else if (optionName.equalsIgnoreCase(EXCLUDE_JDK_CLASS_OPTION)) {
JDKExclude.enable();
} else if (optionName.equalsIgnoreCase(USE_BOOT_CP)) {
if (args.length == 0) {
release = Release.BOOT_CLASS_PATH;
Expand Down
Loading