Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-38616] Fixed MavenModule prebuilders when linting grad…
…le and shell scripts
  • Loading branch information
v1v committed Sep 29, 2016
1 parent d819550 commit 2d83215
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 18 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -33,7 +33,8 @@ TODO
- Configure Checks (enabled, disabled, change severity)
- Load checks dynamically.
- Jobs action to show those Jenkins lints.

- System.exit in system admin groovy scripts (prebuilder, builders, publishers and parameters)
- Support pipeline

List available Checks
=====================
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -93,7 +93,7 @@
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
<version>2.8</version>
<scope>test</scope>
<optional>true</optional>
</dependency>

<dependency>
Expand Down
@@ -1,6 +1,7 @@
package org.jenkins.ci.plugins.jenkinslint.check;

import hudson.matrix.MatrixProject;
import hudson.maven.MavenModuleSet;
import hudson.model.Item;
import hudson.model.Project;
import hudson.tasks.Builder;
Expand All @@ -27,16 +28,19 @@ public GradleWrapperChecker() {
public boolean executeCheck(Item item) {
boolean found = false;
if (Jenkins.getInstance().pluginManager.getPlugin("gradle") != null) {
if (item.getClass().getName().endsWith("hudson.maven.MavenModuleSet")) {
found = false;
} else {
if (item instanceof Project) {
found = isGradlew(((Project) item).getBuilders());
}
if (item instanceof MatrixProject) {
found = isGradlew(((MatrixProject) item).getBuilders());

if (Jenkins.getInstance().pluginManager.getPlugin("maven-plugin")!=null) {
if (item instanceof MavenModuleSet) {
found = isGradlew(((MavenModuleSet) item).getPrebuilders());
}
}
if (item instanceof Project) {
found = isGradlew(((Project) item).getBuilders());
}
if (item instanceof MatrixProject) {
found = isGradlew(((MatrixProject) item).getBuilders());
}

}
return found;
}
Expand Down
Expand Up @@ -4,7 +4,9 @@
import hudson.model.Item;
import hudson.model.Project;
import hudson.tasks.Builder;
import hudson.maven.MavenModuleSet;
import hudson.tasks.CommandInterpreter;
import jenkins.model.Jenkins;
import org.jenkins.ci.plugins.jenkinslint.model.AbstractCheck;

import java.util.List;
Expand All @@ -28,16 +30,17 @@ public HardcodedScriptChecker() {
public boolean executeCheck(Item item) {
LOG.log(Level.FINE, "executeCheck " + item);
boolean found = false;
if (item.getClass().getName().endsWith("hudson.maven.MavenModuleSet")) {
found = false;
} else {
if (item instanceof Project) {
found = isBuilderHarcoded (((Project)item).getBuilders());
}
if (item instanceof MatrixProject) {
found = isBuilderHarcoded (((MatrixProject)item).getBuilders());
if (Jenkins.getInstance().pluginManager.getPlugin("maven-plugin")!=null) {
if (item instanceof MavenModuleSet) {
found = isBuilderHarcoded(((MavenModuleSet) item).getPrebuilders());
}
}
if (item instanceof Project) {
found = isBuilderHarcoded (((Project)item).getBuilders());
}
if (item instanceof MatrixProject) {
found = isBuilderHarcoded (((MatrixProject)item).getBuilders());
}
return found;
}

Expand Down
Expand Up @@ -70,6 +70,11 @@ public class GradleWrapperCheckerTestCase {
assertFalse(checker.isIgnored(project.getDescription()));
project.setDescription("#lint:ignore:" + checker.getClass().getSimpleName());
assertTrue(checker.isIgnored(project.getDescription()));
project.delete();
MavenModuleSet mavenProject = j.createMavenProject();
assertFalse(checker.isIgnored(mavenProject.getDescription()));
mavenProject.setDescription("#lint:ignore:" + checker.getClass().getSimpleName());
assertTrue(checker.isIgnored(mavenProject.getDescription()));
}
//@Issue("JENKINS-29427")
@Test public void testAnotherBuilders() throws Exception {
Expand All @@ -82,4 +87,24 @@ public class GradleWrapperCheckerTestCase {
assertFalse(checker.executeCheck(project));
project.delete();
}
//@Issue("JENKINS-38616")
@Test public void testMavenModuleJob() throws Exception {
MavenModuleSet project = j.createMavenProject();
assertFalse(checker.executeCheck(project));
}
//@Issue("JENKINS-38616")
@Test public void testMavenModuleJobbWithHardcodedScript() throws Exception {
MavenModuleSet project = j.createMavenProject();
project.getPrebuilders().add(new hudson.tasks.Shell("#!/bin/bash #single line"));
assertFalse(checker.executeCheck(project));
project.delete();
project = j.createMavenProject("WithoutWrapper");
project.getPrebuilders().add(new hudson.plugins.gradle.Gradle("description","switches","tasks","rootBuildScriptDir","buildFile","gradleName", false, false, false, false));
project.save();
assertTrue(checker.executeCheck(project));
project.delete();
project = j.createMavenProject("WithWrapper");
project.getPrebuilders().add(new hudson.plugins.gradle.Gradle("description","switches","tasks","rootBuildScriptDir","buildFile","gradleName", true, false, false, false));
assertFalse(checker.executeCheck(project));
}
}
Expand Up @@ -75,6 +75,10 @@ public class HardcodedScriptCheckerTestCase {
assertFalse(checker.isIgnored(project.getDescription()));
project.setDescription("#lint:ignore:" + checker.getClass().getSimpleName());
assertTrue(checker.isIgnored(project.getDescription()));
MavenModuleSet mavenProject = j.createMavenProject();
assertFalse(checker.isIgnored(mavenProject.getDescription()));
mavenProject.setDescription("#lint:ignore:" + checker.getClass().getSimpleName());
assertTrue(checker.isIgnored(mavenProject.getDescription()));
}
//@Issue("JENKINS-29427")
@Test public void testAnotherBuilders() throws Exception {
Expand All @@ -87,4 +91,27 @@ public class HardcodedScriptCheckerTestCase {
assertFalse(checker.executeCheck(project));
project.delete();
}
//@Issue("JENKINS-38616")
@Test public void testMavenModuleJob() throws Exception {
MavenModuleSet project = j.createMavenProject();
assertFalse(checker.executeCheck(project));
}
//@Issue("JENKINS-38616")
@Test public void testMavenModuleJobbWithHardcodedScript() throws Exception {
MavenModuleSet project = j.createMavenProject();
project.getPrebuilders().add(new hudson.tasks.Shell("#!/bin/bash #single line"));
assertFalse(checker.executeCheck(project));
project.delete();
project = j.createMavenProject("Bash_Multiple_Line");
project.getPrebuilders().add(new hudson.tasks.Shell("#!/bin/bash\nline1\nline2\nline3\nline4\nline5\nline6"));
assertTrue(checker.executeCheck(project));
project.delete();
project = j.createMavenProject("Batch_Single_Line");
project.getPrebuilders().add(new hudson.tasks.BatchFile("echo first"));
assertFalse(checker.executeCheck(project));
project.delete();
project = j.createMavenProject("Batch_Multiple_Line");
project.getPrebuilders().add(new hudson.tasks.BatchFile("echo first\nline1\nline2\nline3\nline4\nline5\nline6"));
assertTrue(checker.executeCheck(project));
}
}

0 comments on commit 2d83215

Please sign in to comment.