mojohaus / animal-sniffer

https://www.mojohaus.org/animal-sniffer/animal-sniffer-maven-plugin/
MIT License
86 stars 44 forks source link

Cannot check signatures against non-Java-Platform APIs #19

Closed jglick closed 1 year ago

jglick commented 8 years ago

The documentation claims you can generate signatures of other APIs. I just tried to do so, for javax.servlet:servlet-api:2.4. It did not work. If I build

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <groupId>…</groupId>
    <artifactId>…</artifactId>
    <version>…</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>animal-sniffer-maven-plugin</artifactId>
                <version>1.15</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <configuration>
                            <includeJavaHome>false</includeJavaHome>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

then I get a reasonable-looking artifact. But if I try to then use it

<execution>
  <goals>
    <goal>check</goal>
  </goals>
  <id>check-servlet</id>
  <configuration>
    <signature>
      <groupId>…</groupId>
      <artifactId>…</artifactId>
      <version>…</version>
    </signature>
  </configuration>
</execution>

I get numerous errors:

/…/src/main/java/….java:…: Undefined reference: Object

Now the documentation does say

in general the Java Runtime signatures should form part of your API's signatures

I do not really want to do this—I am already checking a Java Platform signature separately, and in this check I only want to check Servlet API class usages—but fine, I will include the Java 8 Platform in my signature. Yet when I go to do this

you can base your API off an existing Java Runtime signature

the documentation refers to

<includeSignatures>

which does not exist. (The coordinate org.codehaus.mojo.animal_sniffer:java:1.0:java-1.4-generic is wrong too, by the way; I think you meant org.codehaus.mojo.signature:java15:1.0?)

<includeDependencies>
    <dependency>javax.servlet:servlet-api</dependency>
</includeDependencies>

at check time does not help.

If I give up on referring to a known Java Platform artifact and just delete

<configuration>
    <includeJavaHome>false</includeJavaHome>
</configuration>

then (even though I am running Maven with …/jdk8/bin/java) I get an error

Cannot include java home if java home is not specified (either via javaClassPath, javaHome or jdk)

referring to a nonexistent parameter javaClassPath; I suppose javaHomeClassPath was meant. I need to pass

-DjavaHome=/…/jdk8

to the mvn command to build the signature. But now when I run the check goal against this, it passes even if I have deliberately inserted a call to HttpServletResponse.getStatus() into my sources, which was a method added in 3.0.

simontunnat commented 8 years ago

I'm having the same problem. I was just trying it the exact same way for another (non open source) API.

simontunnat commented 8 years ago

I could get it to work by adding the jdk base signature as a dependency:

    <dependencies>
        <dependency>
            <groupId>org.codehaus.mojo.signature</groupId>
            <artifactId>java16</artifactId>
            <type>signature</type>
        </dependency>
    </dependencies>
TobiX commented 6 years ago

Additionally, this seems expected behaviour: http://www.mojohaus.org/animal-sniffer/animal-sniffer-maven-plugin/examples/checking-signatures.html#Referencing_classes_from_dependencies