forked from abayer/gradle-hpi-plugin
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce checkAccessModifier#ignoreFailures
This was requested to ease into the new functionality. checkAccessModifier will run by default, but not fail the build. It will never be considered up-to-date when ignoreFailures is true. Fixes #176.
- Loading branch information
Showing
8 changed files
with
170 additions
and
5 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
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
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
83 changes: 83 additions & 0 deletions
83
...g/jenkinsci/gradle/plugins/accmod/CheckAccessModifierIgnoreFailuresIntegrationSpec.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,83 @@ | ||
package org.jenkinsci.gradle.plugins.accmod | ||
|
||
import com.squareup.javapoet.ClassName | ||
import com.squareup.javapoet.JavaFile | ||
import com.squareup.javapoet.MethodSpec | ||
import com.squareup.javapoet.TypeSpec | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import org.jenkinsci.gradle.plugins.jpi.IntegrationSpec | ||
import org.jenkinsci.gradle.plugins.jpi.TestDataGenerator | ||
import org.jenkinsci.gradle.plugins.jpi.TestSupport | ||
|
||
import javax.lang.model.element.Modifier | ||
import java.nio.file.Path | ||
|
||
class CheckAccessModifierIgnoreFailuresIntegrationSpec extends IntegrationSpec { | ||
private final String projectName = TestDataGenerator.generateName() | ||
private File build | ||
private Path srcMainJava | ||
|
||
def setup() { | ||
File settings = projectDir.newFile('settings.gradle') | ||
settings << """rootProject.name = \"$projectName\"""" | ||
build = projectDir.newFile('build.gradle') | ||
build << """\ | ||
plugins { | ||
id 'org.jenkins-ci.jpi' | ||
} | ||
jenkinsPlugin { | ||
jenkinsVersion.set('${TestSupport.RECENT_JENKINS_VERSION}') | ||
} | ||
dependencies { | ||
implementation 'org.jenkins-ci.plugins:mercurial:2.10' | ||
} | ||
""".stripIndent() | ||
srcMainJava = new File(projectDir.root, 'src/main/java').toPath() | ||
JavaFile.builder('org.example', TypeSpec.classBuilder('Consumer') | ||
.addModifiers(Modifier.PUBLIC) | ||
.addMethod(MethodSpec.methodBuilder('callDoNotUse') | ||
.addStatement('$1T o = new $1T()', ClassName.get('hudson.plugins.mercurial', 'MercurialChangeSet')) | ||
.addStatement('o.setMsg($S)', 'some message') | ||
.build()) | ||
.addMethod(MethodSpec.methodBuilder('callNoExternalUse') | ||
.addStatement('$1T o = new $1T()', ClassName.get('hudson.plugins.mercurial', 'MercurialStatus')) | ||
.addStatement('o.doNotifyCommit($S, $S, $S)', '', '', '') | ||
.addException(ClassName.get('javax.servlet', 'ServletException')) | ||
.addException(IOException) | ||
.build()) | ||
.build()) | ||
.build() | ||
.writeToPath(srcMainJava) | ||
} | ||
|
||
def 'should not fail when using @Restricted method by default'() { | ||
when: | ||
def result = gradleRunner() | ||
.withArguments(CheckAccessModifierTask.NAME, '-s') | ||
.build() | ||
|
||
then: | ||
result.task(':' + CheckAccessModifierTask.NAME).outcome == TaskOutcome.SUCCESS | ||
result.output.contains('hudson/plugins/mercurial/MercurialChangeSet.setMsg(Ljava/lang/String;)V must not be used') | ||
result.output.contains('hudson/plugins/mercurial/MercurialStatus.doNotifyCommit(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lorg/kohsuke/stapler/HttpResponse; must not be used') | ||
} | ||
|
||
def 'should allow overriding by configuring task property'() { | ||
given: | ||
build << ''' | ||
tasks.named('checkAccessModifier').configure { | ||
ignoreFailures.set(false) | ||
} | ||
'''.stripIndent() | ||
|
||
when: | ||
def result = gradleRunner() | ||
.withArguments(CheckAccessModifierTask.NAME) | ||
.buildAndFail() | ||
|
||
then: | ||
result.task(':' + CheckAccessModifierTask.NAME).outcome == TaskOutcome.FAILED | ||
result.output.contains('hudson/plugins/mercurial/MercurialChangeSet.setMsg(Ljava/lang/String;)V must not be used') | ||
result.output.contains('hudson/plugins/mercurial/MercurialStatus.doNotifyCommit(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lorg/kohsuke/stapler/HttpResponse; must not be used') | ||
} | ||
} |
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