Skip to content
Commits on Source (2)
......@@ -4,11 +4,11 @@
<parent>
<artifactId>access-modifier</artifactId>
<groupId>org.kohsuke</groupId>
<version>1.12</version>
<version>1.14</version>
</parent>
<artifactId>access-modifier-annotation</artifactId>
<name>Custom Acess Modifier annotations</name>
<name>Custom Access Modifier annotations</name>
<dependencies>
<dependency>
......
......@@ -85,6 +85,13 @@ public abstract class AccessRestriction {
*/
public abstract void written(Location loc, RestrictedElement target, ErrorListener errorListener);
/**
* Whether this access restriction, if applied to a type, should also be considered to apply implicitly to all transitively nested members.
* @return by default, false
*/
public boolean appliesToNested() {
return false;
}
/**
* {@link AccessRestriction} that imposes no restriction.
......
......@@ -74,4 +74,10 @@ public interface Location {
* access restrictions.
*/
ClassLoader getDependencyClassLoader();
/**
* Loads a configuration setting from the environment, such as when configured by a Maven plugin.
*/
/*@CheckForNull*/ String getProperty(String key);
}
/*
* The MIT License
*
* Copyright 2018 CloudBees, Inc.
*
* 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 org.kohsuke.accmod.restrictions;
import org.kohsuke.accmod.impl.ErrorListener;
import org.kohsuke.accmod.impl.Location;
import org.kohsuke.accmod.impl.RestrictedElement;
/**
* References are only allowed within the same module, as in {@link NoExternalUse},
* or when a special flag is set in the consuming module.
* This is the property {@code useBeta} with the value {@code true}.
*/
public class Beta extends DoNotUse {
@Override
public void error(Location loc, RestrictedElement target, ErrorListener errorListener) {
if (target.isInTheInspectedModule()) {
return;
}
if ("true".equals(loc.getProperty("useBeta"))) {
return;
}
errorListener.onError(null, loc, target + " is still in beta");
}
}
......@@ -61,4 +61,10 @@ public class DoNotUse extends AccessRestriction {
public void error(Location loc, RestrictedElement target, ErrorListener errorListener) {
errorListener.onError(null,loc,target+" must not be used");
}
@Override
public boolean appliesToNested() {
return true;
}
}
......@@ -4,7 +4,7 @@
<parent>
<artifactId>access-modifier</artifactId>
<groupId>org.kohsuke</groupId>
<version>1.12</version>
<version>1.14</version>
</parent>
<artifactId>access-modifier-checker</artifactId>
<packaging>maven-plugin</packaging>
......
<?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>beta-fail</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>
\ No newline at end of file
package api;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;
public class Api {
@Restricted(Beta.class)
public static void experimental() {}
static {
experimental(); // OK
}
}
<?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>beta-fail</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>
\ No newline at end of file
package caller;
import api.Api;
public class Caller {
public Caller() {
Api.experimental(); // illegal
}
}
invoker.goals=clean package
invoker.buildResult = failure
<?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>beta-fail</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<modules>
<module>api</module>
<module>caller</module>
</modules>
</project>
\ No newline at end of file
assert new File(basedir, 'build.log').text.contains('[ERROR] caller/Caller:8 api/Api.experimental()V is still in beta')
<?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>beta-pass</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>
\ No newline at end of file
package api;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;
public class Api {
@Restricted(Beta.class)
public static void experimental() {}
static {
experimental(); // OK
}
}
<?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>beta-pass</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>
<configuration>
<properties>
<property>
<name>useBeta</name>
<value>true</value>
</property>
</properties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package caller;
import api.Api;
public class Caller {
public Caller() {
Api.experimental(); // OK
}
}
<?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>beta-pass</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<modules>
<module>api</module>
<module>caller</module>
</modules>
</project>
\ No newline at end of file
<?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>failOnError</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>
\ No newline at end of file