Skip to content
Permalink
Browse files

Merge pull request #12 from jenkinsci/maven_matrix_support

[JENKINS-42310] Fixed lint defects which didn't support Maven and Matrix projects
  • Loading branch information...
v1v committed Feb 26, 2017
2 parents ced83f2 + ac23bed commit 926d5705e9b8ff4a1e7227ee668d0fd95a09d417
Showing with 363 additions and 45 deletions.
  1. +3 −4 src/main/java/org/jenkins/ci/plugins/jenkinslint/check/ArtifactChecker.java
  2. +3 −2 src/main/java/org/jenkins/ci/plugins/jenkinslint/check/CleanupWorkspaceChecker.java
  3. +5 −5 src/main/java/org/jenkins/ci/plugins/jenkinslint/check/GitRefChecker.java
  4. +5 −5 src/main/java/org/jenkins/ci/plugins/jenkinslint/check/GitShallowChecker.java
  5. +3 −3 src/main/java/org/jenkins/ci/plugins/jenkinslint/check/JavadocChecker.java
  6. +3 −2 src/main/java/org/jenkins/ci/plugins/jenkinslint/check/JobAssignedLabelChecker.java
  7. +4 −4 src/main/java/org/jenkins/ci/plugins/jenkinslint/check/JobDescriptionChecker.java
  8. +3 −3 src/main/java/org/jenkins/ci/plugins/jenkinslint/check/NullSCMChecker.java
  9. +3 −3 src/main/java/org/jenkins/ci/plugins/jenkinslint/check/TimerTriggerChecker.java
  10. +37 −0 src/test/java/org/jenkins/ci/plugins/jenkinslint/check/ArtifactCheckerTestCase.java
  11. +25 −0 src/test/java/org/jenkins/ci/plugins/jenkinslint/check/CleanupWorkspaceCheckerTestCase.java
  12. +37 −0 src/test/java/org/jenkins/ci/plugins/jenkinslint/check/GitRefCheckerTestCase.java
  13. +48 −0 src/test/java/org/jenkins/ci/plugins/jenkinslint/check/GitShallowCheckerTestCase.java
  14. +5 −4 src/test/java/org/jenkins/ci/plugins/jenkinslint/check/GradleWrapperCheckerTestCase.java
  15. +5 −4 src/test/java/org/jenkins/ci/plugins/jenkinslint/check/GroovySystemExitCheckerTestCase.java
  16. +5 −4 src/test/java/org/jenkins/ci/plugins/jenkinslint/check/HardcodedScriptCheckerTestCase.java
  17. +38 −0 src/test/java/org/jenkins/ci/plugins/jenkinslint/check/JavadocCheckerTestCase.java
  18. +29 −0 src/test/java/org/jenkins/ci/plugins/jenkinslint/check/JobAssignedLabelCheckerTestCase.java
  19. +25 −0 src/test/java/org/jenkins/ci/plugins/jenkinslint/check/JobDescriptionCheckerTestCase.java
  20. +32 −0 src/test/java/org/jenkins/ci/plugins/jenkinslint/check/NullSCMCheckerTestCase.java
  21. +3 −2 src/test/java/org/jenkins/ci/plugins/jenkinslint/check/TimeoutCheckerTestCase.java
  22. +42 −0 src/test/java/org/jenkins/ci/plugins/jenkinslint/check/TimerTriggerCheckerTestCase.java
@@ -2,7 +2,7 @@

import hudson.model.Descriptor;
import hudson.model.Item;
import hudson.model.Project;
import hudson.model.AbstractProject;
import hudson.tasks.ArtifactArchiver;
import hudson.tasks.Publisher;
import hudson.util.DescribableList;
@@ -24,9 +24,8 @@ public ArtifactChecker() {
public boolean executeCheck(Item item) {
LOG.log(Level.FINE, "executeCheck " + item);

if (item instanceof Project) {
Project project = (Project) item;
DescribableList<Publisher, Descriptor<Publisher>> publishersList = project.getPublishersList();
if (item instanceof AbstractProject) {
DescribableList<Publisher, Descriptor<Publisher>> publishersList = ((AbstractProject)item).getPublishersList();
for (Publisher publisher : publishersList) {
if (publisher instanceof ArtifactArchiver) {
LOG.log(Level.FINEST, "ArtifactChecker " + publisher);
@@ -2,7 +2,7 @@

import hudson.model.Descriptor;
import hudson.model.Item;
import hudson.model.Project;
import hudson.model.AbstractProject;
import jenkins.model.Jenkins;
import org.jenkins.ci.plugins.jenkinslint.model.AbstractCheck;

@@ -19,7 +19,8 @@ public CleanupWorkspaceChecker() {

public boolean executeCheck(Item item) {
if (Jenkins.getInstance().pluginManager.getPlugin("ws-cleanup")!=null) {
return item instanceof Project && ((Project) item).getPublisher(Descriptor.find("hudson.plugins.ws_cleanup.WsCleanup")) == null;
return item instanceof AbstractProject &&
((AbstractProject) item).getPublishersList().get(Descriptor.find("hudson.plugins.ws_cleanup.WsCleanup")) == null;
} else {
return true;
}
@@ -1,7 +1,7 @@
package org.jenkins.ci.plugins.jenkinslint.check;

import hudson.model.Item;
import hudson.model.Project;
import hudson.model.AbstractProject;
import jenkins.model.Jenkins;
import org.jenkins.ci.plugins.jenkinslint.model.AbstractCheck;

@@ -22,14 +22,14 @@ public GitRefChecker() {
}

public boolean executeCheck(Item item) {
if (item instanceof Project) {
if (item instanceof AbstractProject) {
PluginWrapper plugin = Jenkins.getInstance().pluginManager.getPlugin("git");
if (plugin!=null && !plugin.getVersionNumber().isOlderThan(new hudson.util.VersionNumber("2.0"))) {
if (((Project) item).getScm().getClass().getName().endsWith("GitSCM")) {
if (((AbstractProject) item).getScm().getClass().getName().endsWith("GitSCM")) {
boolean status = true;
try {
Method method = ((Project) item).getScm().getClass().getMethod("getExtensions", null);
Object extensionsList = method.invoke( ((Project) item).getScm());
Method method = ((AbstractProject) item).getScm().getClass().getMethod("getExtensions", null);
Object extensionsList = method.invoke( ((AbstractProject) item).getScm());
if (extensionsList instanceof AbstractList) {
for (Object extension : ((AbstractList) extensionsList) ) {
if (extension.getClass().getName().endsWith("CloneOption")) {
@@ -1,7 +1,7 @@
package org.jenkins.ci.plugins.jenkinslint.check;

import hudson.model.Item;
import hudson.model.Project;
import hudson.model.AbstractProject;
import jenkins.model.Jenkins;
import org.jenkins.ci.plugins.jenkinslint.model.AbstractCheck;

@@ -21,13 +21,13 @@ public GitShallowChecker() {
}

public boolean executeCheck(Item item) {
if (item instanceof Project) {
if (item instanceof AbstractProject) {
if (Jenkins.getInstance().pluginManager.getPlugin("git")!=null) {
if (((Project) item).getScm().getClass().getName().endsWith("GitSCM")) {
if (((AbstractProject) item).getScm().getClass().getName().endsWith("GitSCM")) {
boolean status = true;
try {
Method method = ((Project) item).getScm().getClass().getMethod("getExtensions", null);
Object extensionsList = method.invoke( ((Project) item).getScm());
Method method = ((AbstractProject) item).getScm().getClass().getMethod("getExtensions", null);
Object extensionsList = method.invoke( ((AbstractProject) item).getScm());
if (extensionsList instanceof AbstractList) {
for (Object extension : ((AbstractList) extensionsList) ) {
if (extension.getClass().getName().endsWith("CloneOption")) {
@@ -1,8 +1,8 @@
package org.jenkins.ci.plugins.jenkinslint.check;

import hudson.model.AbstractProject;
import hudson.model.Descriptor;
import hudson.model.Item;
import hudson.model.Project;
import hudson.tasks.JavadocArchiver;
import hudson.tasks.Publisher;
import hudson.util.DescribableList;
@@ -20,8 +20,8 @@ public JavadocChecker() {
}

public boolean executeCheck(Item item) {
if (item instanceof Project) {
DescribableList<Publisher, Descriptor<Publisher>> publishersList = ((Project) item).getPublishersList();
if (item instanceof AbstractProject) {
DescribableList<Publisher, Descriptor<Publisher>> publishersList = ((AbstractProject) item).getPublishersList();
for (Publisher publisher : publishersList) {
if (publisher instanceof hudson.tasks.JavadocArchiver) {
return ( ((JavadocArchiver) publisher).getJavadocDir() == null ||
@@ -1,7 +1,7 @@
package org.jenkins.ci.plugins.jenkinslint.check;

import hudson.model.Item;
import hudson.model.Project;
import hudson.model.AbstractProject;
import org.jenkins.ci.plugins.jenkinslint.model.AbstractCheck;

/**
@@ -16,6 +16,7 @@ public JobAssignedLabelChecker() {
}

public boolean executeCheck(Item item) {
return item instanceof Project && (((Project) item).getAssignedLabelString() == null || ((Project) item).getAssignedLabelString().length() == 0);
return item instanceof AbstractProject && (((AbstractProject) item).getAssignedLabelString() == null ||
((AbstractProject) item).getAssignedLabelString().length() == 0);
}
}
@@ -1,7 +1,7 @@
package org.jenkins.ci.plugins.jenkinslint.check;

import hudson.model.AbstractItem;
import hudson.model.Item;
import hudson.model.Project;
import org.jenkins.ci.plugins.jenkinslint.model.AbstractCheck;

/**
@@ -16,9 +16,9 @@ public JobDescriptionChecker() {
}

public boolean executeCheck(Item item) {
if (item instanceof hudson.model.Project) {
return (((Project) item).getDescription() == null
|| ((Project) item).getDescription().length() == 0);
if (item instanceof AbstractItem) {
return (((AbstractItem) item).getDescription() == null
|| ((AbstractItem) item).getDescription().length() == 0);
}
return false;
}
@@ -1,7 +1,7 @@
package org.jenkins.ci.plugins.jenkinslint.check;

import hudson.model.Item;
import hudson.model.Project;
import hudson.model.AbstractProject;
import org.jenkins.ci.plugins.jenkinslint.model.AbstractCheck;

/**
@@ -16,8 +16,8 @@ public NullSCMChecker() {
}

public boolean executeCheck(Item item) {
if (item instanceof Project) {
return (((Project) item).getScm() instanceof hudson.scm.NullSCM);
if (item instanceof AbstractProject) {
return (((AbstractProject) item).getScm() instanceof hudson.scm.NullSCM);
}
return false;
}
@@ -1,7 +1,7 @@
package org.jenkins.ci.plugins.jenkinslint.check;

import hudson.model.Item;
import hudson.model.Project;
import hudson.model.AbstractProject;
import hudson.triggers.TimerTrigger;
import org.jenkins.ci.plugins.jenkinslint.model.AbstractCheck;

@@ -21,8 +21,8 @@ public TimerTriggerChecker() {

public boolean executeCheck(Item item) {
boolean found = false;
if (item instanceof Project && ((Project) item).getTrigger(TimerTrigger.class) != null ) {
String spec = ((Project) item).getTrigger(TimerTrigger.class).getSpec().toLowerCase();
if (item instanceof AbstractProject && ((AbstractProject) item).getTrigger(TimerTrigger.class) != null ) {
String spec = ((AbstractProject) item).getTrigger(TimerTrigger.class).getSpec().toLowerCase();
if (spec.contains("h")) {
String[] myData = spec.split("\n");
for (String line: myData) {
@@ -1,10 +1,13 @@
package org.jenkins.ci.plugins.jenkinslint.check;

import hudson.matrix.MatrixProject;
import hudson.maven.MavenModuleSet;
import hudson.model.FreeStyleProject;
import hudson.tasks.ArtifactArchiver;
import hudson.tasks.JavadocArchiver;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

import static org.junit.Assert.assertFalse;
@@ -38,6 +41,40 @@
project.getPublishersList().add(new ArtifactArchiver("something","",false));
assertFalse(checker.executeCheck(project));
}
@Issue("JENKINS-42310")
@Test public void testMavenModuleJob() throws Exception {
MavenModuleSet project = j.createMavenProject();
assertFalse(checker.executeCheck(project));
}
@Issue("JENKINS-42310")
@Test public void testMavenArtifact() throws Exception {
MavenModuleSet project = j.createMavenProject();
project.getPublishersList().add(new JavadocArchiver("",false));
assertFalse(checker.executeCheck(project));
project.getPublishersList().add(new ArtifactArchiver("","",false));
assertTrue(checker.executeCheck(project));
project.delete();
project = j.createMavenProject();
project.getPublishersList().add(new ArtifactArchiver("something","",false));
assertFalse(checker.executeCheck(project));
}
@Issue("JENKINS-42310")
@Test public void testMatrixProject() throws Exception {
MatrixProject project = j.createMatrixProject();
assertFalse(checker.executeCheck(project));
}
@Issue("JENKINS-42310")
@Test public void testMatrixProjectArtifact() throws Exception {
MatrixProject project = j.createMatrixProject();
project.getPublishersList().add(new JavadocArchiver("",false));
assertFalse(checker.executeCheck(project));
project.getPublishersList().add(new ArtifactArchiver("","",false));
assertTrue(checker.executeCheck(project));
project.delete();
project = j.createMatrixProject();
project.getPublishersList().add(new ArtifactArchiver("something","",false));
assertFalse(checker.executeCheck(project));
}
@Test public void testControlComment() throws Exception {
FreeStyleProject project = j.createFreeStyleProject();
assertFalse(checker.isIgnored(project.getDescription()));
@@ -1,11 +1,14 @@
package org.jenkins.ci.plugins.jenkinslint.check;

import hudson.matrix.MatrixProject;
import hudson.maven.MavenModuleSet;
import hudson.model.FreeStyleProject;
import hudson.plugins.ws_cleanup.PreBuildCleanup;
import hudson.plugins.ws_cleanup.WsCleanup;
import hudson.tasks.ArtifactArchiver;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

import static org.junit.Assert.assertFalse;
@@ -40,6 +43,28 @@
project.getBuildWrappersList().add(new PreBuildCleanup(null, true, "", ""));
assertTrue(checker.executeCheck(project));
}
@Issue("JENKINS-42310")
@Test public void testMavenModuleJob() throws Exception {
MavenModuleSet project = j.createMavenProject();
assertTrue(checker.executeCheck(project));
}
@Issue("JENKINS-42310")
@Test public void testMavenCleanupWorkspacePublisher() throws Exception {
MavenModuleSet project = j.createMavenProject("WithPublisher");
project.getPublishersList().add(new WsCleanup(null, true, true, true, true, true, true, true, true, ""));
assertFalse(checker.executeCheck(project));
}
@Issue("JENKINS-42310")
@Test public void testMatrixProject() throws Exception {
MatrixProject project = j.createMatrixProject();
assertTrue(checker.executeCheck(project));
}
@Issue("JENKINS-42310")
@Test public void testMatrixProjectCleanupWorkspacePublisher() throws Exception {
MatrixProject project = j.createMatrixProject("WithoutSystem");
project.getPublishersList().add(new WsCleanup(null, true, true, true, true, true, true, true, true, ""));
assertFalse(checker.executeCheck(project));
}
@Test public void testControlComment() throws Exception {
FreeStyleProject project = j.createFreeStyleProject();
assertFalse(checker.isIgnored(project.getDescription()));
@@ -1,11 +1,14 @@
package org.jenkins.ci.plugins.jenkinslint.check;

import hudson.matrix.MatrixProject;
import hudson.maven.MavenModuleSet;
import hudson.model.FreeStyleProject;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.impl.CleanCheckout;
import hudson.plugins.git.extensions.impl.CloneOption;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

import java.util.ArrayList;
@@ -67,6 +70,40 @@
project.setScm(new hudson.plugins.git.GitSCM(null, null, false, null, null, "", extensions));
assertFalse(checker.executeCheck(project));
}
@Issue("JENKINS-42310")
@Test public void testMavenModuleJob() throws Exception {
MavenModuleSet project = j.createMavenProject();
assertFalse(checker.executeCheck(project));
}
@Issue("JENKINS-42310")
@Test public void testMavenGit() throws Exception {
MavenModuleSet project = j.createMavenProject();
project.setScm(new hudson.plugins.git.GitSCM(""));
assertTrue(checker.executeCheck(project));
project.delete();
project = j.createMavenProject();
ArrayList<GitSCMExtension> extensions = new ArrayList<GitSCMExtension>();
extensions.add(new CloneOption(false, "${WORKSPACE}/.git-cache", 0));
project.setScm(new hudson.plugins.git.GitSCM(null, null, false, null, null, "", extensions));
assertFalse(checker.executeCheck(project));
}
@Issue("JENKINS-42310")
@Test public void testMatrixProject() throws Exception {
MatrixProject project = j.createMatrixProject();
assertFalse(checker.executeCheck(project));
}
@Issue("JENKINS-42310")
@Test public void testMatrixProjectGit() throws Exception {
MatrixProject project = j.createMatrixProject();
project.setScm(new hudson.plugins.git.GitSCM(""));
assertTrue(checker.executeCheck(project));
project.delete();
project = j.createMatrixProject();
ArrayList<GitSCMExtension> extensions = new ArrayList<GitSCMExtension>();
extensions.add(new CloneOption(false, "${WORKSPACE}/.git-cache", 0));
project.setScm(new hudson.plugins.git.GitSCM(null, null, false, null, null, "", extensions));
assertFalse(checker.executeCheck(project));
}
@Test public void testControlComment() throws Exception {
FreeStyleProject project = j.createFreeStyleProject();
assertFalse(checker.isIgnored(project.getDescription()));
Oops, something went wrong.

0 comments on commit 926d570

Please sign in to comment.
You can’t perform that action at this time.