-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from agentgonzo/JENKINS-53675
[JENKINS-53675] Add the ability to disable checks for certain classes only
- Loading branch information
Showing
29 changed files
with
657 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
access-modifier-checker/src/it/disable-restrictions-wrong-annotation/api/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?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> | ||
<parent> | ||
<groupId>test</groupId> | ||
<artifactId>disable-restrictions-wrong-annotation</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>api</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.kohsuke</groupId> | ||
<artifactId>access-modifier-annotation</artifactId> | ||
<version>@project.version@</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
13 changes: 13 additions & 0 deletions
13
...-restrictions-wrong-annotation/api/src/main/java/api/ApiWithRestrictedMethodAndField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package api; | ||
|
||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
public class ApiWithRestrictedMethodAndField { | ||
|
||
@Restricted(NoExternalUse.class) | ||
public String field; | ||
|
||
@Restricted(NoExternalUse.class) | ||
public static void notReallyPublic() {} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ker/src/it/disable-restrictions-wrong-annotation/api/src/main/java/api/RestrictedApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package api; | ||
|
||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
@Restricted(NoExternalUse.class) | ||
public class RestrictedApi { | ||
|
||
public String field; | ||
|
||
public void doNotUse() {} | ||
} |
8 changes: 8 additions & 0 deletions
8
...c/it/disable-restrictions-wrong-annotation/api/src/main/java/api/RestrictedInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package api; | ||
|
||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
@Restricted(NoExternalUse.class) | ||
public interface RestrictedInterface { | ||
} |
33 changes: 33 additions & 0 deletions
33
access-modifier-checker/src/it/disable-restrictions-wrong-annotation/caller/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?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> | ||
<parent> | ||
<groupId>test</groupId> | ||
<artifactId>disable-restrictions-wrong-annotation</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>caller</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.kohsuke</groupId> | ||
<artifactId>access-modifier-checker</artifactId> | ||
<version>@project.version@</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>enforce</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
11 changes: 11 additions & 0 deletions
11
...cker/src/it/disable-restrictions-wrong-annotation/caller/src/main/java/caller/Caller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package caller; | ||
|
||
import api.ApiWithRestrictedMethodAndField; | ||
|
||
public class Caller { | ||
|
||
@WrongAnnotation(ApiWithRestrictedMethodAndField.class) | ||
public Caller() { | ||
ApiWithRestrictedMethodAndField.notReallyPublic(); // illegal | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...restrictions-wrong-annotation/caller/src/main/java/caller/CallerDisabledAtClassLevel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package caller; | ||
|
||
import api.ApiWithRestrictedMethodAndField; | ||
|
||
@WrongAnnotation(ApiWithRestrictedMethodAndField.class) | ||
public class CallerDisabledAtClassLevel { | ||
public CallerDisabledAtClassLevel() { | ||
ApiWithRestrictedMethodAndField.notReallyPublic(); // illegal | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...it/disable-restrictions-wrong-annotation/caller/src/main/java/caller/WrongAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2018, Steve Arch | ||
* | ||
* 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. | ||
*/ | ||
package caller; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
@Retention(RUNTIME) | ||
@Documented | ||
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE}) | ||
public @interface WrongAnnotation { | ||
Class<?>[] value(); | ||
} |
2 changes: 2 additions & 0 deletions
2
access-modifier-checker/src/it/disable-restrictions-wrong-annotation/invoker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
invoker.goals=clean package | ||
invoker.buildResult = failure |
17 changes: 17 additions & 0 deletions
17
access-modifier-checker/src/it/disable-restrictions-wrong-annotation/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?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>test</groupId> | ||
<artifactId>disable-restrictions-wrong-annotation</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>pom</packaging> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.7</maven.compiler.source> | ||
<maven.compiler.target>1.7</maven.compiler.target> | ||
</properties> | ||
<modules> | ||
<module>api</module> | ||
<module>caller</module> | ||
</modules> | ||
</project> |
2 changes: 2 additions & 0 deletions
2
access-modifier-checker/src/it/disable-restrictions-wrong-annotation/postbuild.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
assert new File(basedir, 'build.log').text.contains('[ERROR] caller/Caller:9 api/ApiWithRestrictedMethodAndField.notReallyPublic()V must not be used') | ||
assert new File(basedir, 'build.log').text.contains('[ERROR] caller/CallerDisabledAtClassLevel:8 api/ApiWithRestrictedMethodAndField.notReallyPublic()V must not be used') |
17 changes: 17 additions & 0 deletions
17
access-modifier-checker/src/it/disable-restrictions/api/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?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> | ||
<parent> | ||
<groupId>test</groupId> | ||
<artifactId>disable-restrictions</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>api</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.kohsuke</groupId> | ||
<artifactId>access-modifier-annotation</artifactId> | ||
<version>@project.version@</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
13 changes: 13 additions & 0 deletions
13
...er/src/it/disable-restrictions/api/src/main/java/api/ApiWithRestrictedMethodAndField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package api; | ||
|
||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
public class ApiWithRestrictedMethodAndField { | ||
|
||
@Restricted(NoExternalUse.class) | ||
public String field; | ||
|
||
@Restricted(NoExternalUse.class) | ||
public static void notReallyPublic() {} | ||
} |
12 changes: 12 additions & 0 deletions
12
access-modifier-checker/src/it/disable-restrictions/api/src/main/java/api/RestrictedApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package api; | ||
|
||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
@Restricted(NoExternalUse.class) | ||
public class RestrictedApi { | ||
|
||
public String field; | ||
|
||
public void doNotUse() {} | ||
} |
8 changes: 8 additions & 0 deletions
8
...difier-checker/src/it/disable-restrictions/api/src/main/java/api/RestrictedInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package api; | ||
|
||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
@Restricted(NoExternalUse.class) | ||
public interface RestrictedInterface { | ||
} |
38 changes: 38 additions & 0 deletions
38
access-modifier-checker/src/it/disable-restrictions/caller/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?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> | ||
<parent> | ||
<groupId>test</groupId> | ||
<artifactId>disable-restrictions</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>caller</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.kohsuke</groupId> | ||
<artifactId>access-modifier-suppressions</artifactId> | ||
<version>@project.version@</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.kohsuke</groupId> | ||
<artifactId>access-modifier-checker</artifactId> | ||
<version>@project.version@</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>enforce</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
36 changes: 36 additions & 0 deletions
36
access-modifier-checker/src/it/disable-restrictions/caller/src/main/java/caller/Caller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package caller; | ||
|
||
import api.ApiWithRestrictedMethodAndField; | ||
import api.RestrictedApi; | ||
import org.kohsuke.accmod.restrictions.suppressions.SuppressRestrictedWarnings; | ||
|
||
public class Caller extends ApiWithRestrictedMethodAndField { // This is fine, ApiWithRestrictedMethodAndField itself is not restricted | ||
|
||
private RestrictedApi restrictedApi; | ||
|
||
@SuppressRestrictedWarnings(ApiWithRestrictedMethodAndField.class) | ||
public Caller() { | ||
ApiWithRestrictedMethodAndField.notReallyPublic(); // illegal but check disabled at the method level | ||
} | ||
|
||
@SuppressRestrictedWarnings({RestrictedApi.class, ApiWithRestrictedMethodAndField.class}) | ||
private void invalidFieldUse() { | ||
restrictedApi.field = null; | ||
super.field = null; | ||
} | ||
|
||
@SuppressRestrictedWarnings(ApiWithRestrictedMethodAndField.class) | ||
public void callerMethod() { | ||
ApiWithRestrictedMethodAndField.notReallyPublic(); // illegal but check disabled at the method level | ||
} | ||
|
||
@SuppressRestrictedWarnings(RestrictedApi.class) | ||
public void methodWithRestrictedParameter(RestrictedApi api) { | ||
api.doNotUse(); // illegal but check disabled at the method level | ||
} | ||
|
||
@SuppressRestrictedWarnings(RestrictedApi.class) | ||
public RestrictedApi getRestrictedApi() { | ||
return new RestrictedApi(); // illegal but check disabled at the method level | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...r/src/it/disable-restrictions/caller/src/main/java/caller/CallerDisabledAtClassLevel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package caller; | ||
|
||
import api.ApiWithRestrictedMethodAndField; | ||
import api.RestrictedApi; | ||
import org.kohsuke.accmod.restrictions.suppressions.SuppressRestrictedWarnings; | ||
|
||
@SuppressRestrictedWarnings( {ApiWithRestrictedMethodAndField.class, RestrictedApi.class}) | ||
public class CallerDisabledAtClassLevel extends RestrictedApi { | ||
|
||
private RestrictedApi restrictedApi; | ||
|
||
public CallerDisabledAtClassLevel() { | ||
ApiWithRestrictedMethodAndField.notReallyPublic(); // illegal but check disabled at the class level | ||
} | ||
|
||
private void invalidFieldUse() { | ||
restrictedApi.field = null; | ||
super.field = null; | ||
} | ||
|
||
public void callerMethod() { | ||
ApiWithRestrictedMethodAndField.notReallyPublic(); // illegal but check disabled at the class level | ||
} | ||
|
||
public void methodWithRestrictedParameter(RestrictedApi api) { | ||
api.doNotUse(); // illegal but check disabled at the class level | ||
} | ||
|
||
public RestrictedApi getRestrictedApi() { | ||
return new RestrictedApi(); // illegal but check disabled at the class level | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...hecker/src/it/disable-restrictions/caller/src/main/java/caller/RestrictedApiSubclass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package caller; | ||
|
||
import api.RestrictedApi; | ||
import org.kohsuke.accmod.restrictions.suppressions.SuppressRestrictedWarnings; | ||
|
||
@SuppressRestrictedWarnings(RestrictedApi.class) | ||
public class RestrictedApiSubclass extends RestrictedApi { | ||
} |
8 changes: 8 additions & 0 deletions
8
...t/disable-restrictions/caller/src/main/java/caller/RestrictedInterfaceImplementation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package caller; | ||
|
||
import api.RestrictedInterface; | ||
import org.kohsuke.accmod.restrictions.suppressions.SuppressRestrictedWarnings; | ||
|
||
@SuppressRestrictedWarnings(RestrictedInterface.class) | ||
public class RestrictedInterfaceImplementation implements RestrictedInterface { | ||
} |
2 changes: 2 additions & 0 deletions
2
access-modifier-checker/src/it/disable-restrictions/invoker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
invoker.goals=clean package | ||
invoker.buildResult = success |
Oops, something went wrong.