Skip to content

Commit

Permalink
GH-74 Unsupported Type as a return type or field is not recognized (#75)
Browse files Browse the repository at this point in the history
* GH-74 Unsupported Type as a return type or field is not recognized

Added tests and samples to verify the problem and solution
Added fields validation
Added method return type validation

* GH-74 Unsupported Type as a return type or field is not recognized

Updated examples to be Java 7 compatible

* GH-74 Unsupported Type as a return type or field is not recognized

Moved tests into IT
Bumped commons-lang3 to prevent java11 failure
Bumped maven invoker plugin to fix issue where IT builds were not executed on java13
  • Loading branch information
LZaruba authored and olamy committed Nov 1, 2019
1 parent 524e402 commit 7d2a805
Show file tree
Hide file tree
Showing 13 changed files with 405 additions and 81 deletions.
2 changes: 1 addition & 1 deletion animal-sniffer-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.buildResult=failure
102 changes: 102 additions & 0 deletions animal-sniffer-maven-plugin/src/it/github-74-1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright (c) 2009 codehaus.org.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.its</groupId>
<artifactId>animal-sniffer-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<groupId>localdomain.localhost</groupId>
<artifactId>real-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>github-74-1</name>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>@mojo.java.target@</source>
<target>@mojo.java.target@</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>${pluginGroupId}</groupId>
<artifactId>${pluginArtifactId}</artifactId>
<version>${pluginVersion}</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java16</artifactId>
<version>1.1</version>
</signature>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.outputEncoding>UTF-8</project.build.outputEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<pluginGroupId>@project.groupId@</pluginGroupId>
<pluginArtifactId>@project.artifactId@</pluginArtifactId>
<pluginVersion>@project.version@</pluginVersion>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package localhost;

import java.nio.file.Paths;

/**
* @author Lukas Zaruba, [email protected], 2019
*/
public class IllegalFieldSample {

private String stringField;
private Paths pathsField;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package localhost;

import java.nio.file.Path;

/**
* @author Lukas Zaruba, [email protected], 2019
*/
public class IllegalFieldWithAccessorsSample {

private String stringField;
private Path pathField;

public String getStringField() {
return stringField;
}

public void setStringField(String stringField) {
this.stringField = stringField;
}

public Path getPathField() {
return pathField;
}

public void setPathField(Path pathField) {
this.pathField = pathField;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package localhost;

import java.nio.file.Path;

/**
* @author Lukas Zaruba, [email protected], 2019
*/
public class IllegalFieldWithManipulationSample {

private String stringField;
private Path pathField;

public Path getPathField() {
return pathField;
}

public void setPathField(Path pathField) {
this.pathField = pathField.resolve("other");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package localhost;

import java.nio.file.Path;

/**
* @author Lukas Zaruba, [email protected], 2019
*/
public class IllegalTypeReturn {

public Path localDateTime() {
return null;
}

}
10 changes: 10 additions & 0 deletions animal-sniffer-maven-plugin/src/it/github-74-1/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
File log = new File(basedir, 'build.log')

assert log.text.contains( 'IllegalTypeReturn.java:11: Undefined reference: java.nio.file.Path' )
assert log.text.contains( 'IllegalFieldWithManipulationSample.java: Undefined reference: java.nio.file.Path' )
assert log.text.contains( 'IllegalFieldWithManipulationSample.java:14: Undefined reference: java.nio.file.Path' )
assert log.text.contains( 'IllegalFieldWithManipulationSample.java:18: Undefined reference: java.nio.file.Path' )
assert log.text.contains( 'IllegalFieldWithManipulationSample.java:18: Undefined reference: java.nio.file.Path java.nio.file.Path.resolve(String)' )
assert log.text.contains( 'IllegalFieldWithAccessorsSample.java: Undefined reference: java.nio.file.Path' )
assert log.text.contains( 'IllegalFieldWithAccessorsSample.java:22: Undefined reference: java.nio.file.Path' )
assert log.text.contains( 'IllegalFieldSample.java: Undefined reference: java.nio.file.Paths' )
102 changes: 102 additions & 0 deletions animal-sniffer-maven-plugin/src/it/github-74-2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright (c) 2009 codehaus.org.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.its</groupId>
<artifactId>animal-sniffer-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<groupId>localdomain.localhost</groupId>
<artifactId>real-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>github-74-2</name>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>@mojo.java.target@</source>
<target>@mojo.java.target@</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>${pluginGroupId}</groupId>
<artifactId>${pluginArtifactId}</artifactId>
<version>${pluginVersion}</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java16</artifactId>
<version>1.1</version>
</signature>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.outputEncoding>UTF-8</project.build.outputEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<pluginGroupId>@project.groupId@</pluginGroupId>
<pluginArtifactId>@project.artifactId@</pluginArtifactId>
<pluginVersion>@project.version@</pluginVersion>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.codehaus.mojo.animal_sniffer.samples;

/**
* @author Lukas Zaruba, [email protected], 2019
*/
public class FieldsOK {

private String niceFiled;

}
Loading

0 comments on commit 7d2a805

Please sign in to comment.