forked from v1v/jenkinslint-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [JENKINS-42268] Initial approach to detect whether BFA has been installed and enabled in every job unless using the control comment to force some way of declaring why it was not enabled [JENKINS-42268] Added Maven and Matrix projects * Enabling Check * i18 support * Removed imports * Fixed asserts * [JENKINS-42268] Using the full classname of the property * [JENKINS-42268] Using Job class to avoid casing each jobtype * Removed unused imports and speeding up BFA Test Case with the AbstractCheckerTestCase * Fixed wrong TestCase name * Added missing bits and pieces in the Messages and also UI Testing * Fixed missing Jelly XSS security bit and also added the sortable class in the JobAction * Added _blank attribute * Fixed cosmetic message * Fixed Log severity and trace
- Loading branch information
Showing
12 changed files
with
140 additions
and
22 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
1 change: 0 additions & 1 deletion
1
src/main/java/org/jenkins/ci/plugins/jenkinslint/SlaveLintAction.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
2 changes: 0 additions & 2 deletions
2
src/main/java/org/jenkins/ci/plugins/jenkinslint/SlaveLintActionFactory.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
49 changes: 49 additions & 0 deletions
49
src/main/java/org/jenkins/ci/plugins/jenkinslint/check/BFAChecker.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,49 @@ | ||
package org.jenkins.ci.plugins.jenkinslint.check; | ||
|
||
import hudson.model.Item; | ||
import hudson.model.Job; | ||
import jenkins.model.Jenkins; | ||
import org.jenkins.ci.plugins.jenkinslint.model.AbstractCheck; | ||
|
||
import java.util.logging.Level; | ||
|
||
/** | ||
* @author Victor Martinez | ||
*/ | ||
public class BFAChecker extends AbstractCheck { | ||
|
||
public BFAChecker() { | ||
super(); | ||
this.setDescription(Messages.BFACheckerDesc()); | ||
this.setSeverity(Messages.BFACheckerSeverity()); | ||
} | ||
|
||
public boolean executeCheck(Item item) { | ||
LOG.log(Level.FINE, "executeCheck " + item); | ||
boolean found = false; | ||
if (Jenkins.getInstance().pluginManager.getPlugin("build-failure-analyzer") != null) { | ||
found = isDoNotScan(((Job) item).getProperty("com.sonyericsson.jenkins.plugins.bfa.model.ScannerJobProperty")); | ||
} | ||
return found; | ||
} | ||
|
||
private boolean isDoNotScan (Object property) { | ||
boolean status = false; | ||
if (property != null) { | ||
try { | ||
Object isDoNotScan = property.getClass().getMethod("isDoNotScan", null).invoke(property); | ||
if (isDoNotScan instanceof Boolean) { | ||
status = ((Boolean) isDoNotScan).booleanValue(); | ||
LOG.log(Level.FINE, "isDoNotScan " + status); | ||
} | ||
} catch (Exception e) { | ||
LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause()); | ||
status = false; | ||
} | ||
} else { | ||
status = true; | ||
} | ||
return status; | ||
} | ||
|
||
} |
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
63 changes: 63 additions & 0 deletions
63
src/test/java/org/jenkins/ci/plugins/jenkinslint/check/BFACheckerTestCase.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,63 @@ | ||
package org.jenkins.ci.plugins.jenkinslint.check; | ||
|
||
import com.sonyericsson.jenkins.plugins.bfa.model.ScannerJobProperty; | ||
import hudson.matrix.MatrixProject; | ||
import hudson.maven.MavenModuleSet; | ||
import hudson.model.FreeStyleProject; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* BFAChecker Test Case. | ||
* | ||
* @author Victor Martinez | ||
*/ | ||
public class BFACheckerTestCase extends AbstractCheckerTestCase { | ||
private BFAChecker checker = new BFAChecker(); | ||
|
||
@Test public void testEmptyJob() throws Exception { | ||
FreeStyleProject project = j.createFreeStyleProject(); | ||
assertTrue(checker.executeCheck(project)); | ||
} | ||
@Test public void testDisabledBFAJob() throws Exception { | ||
FreeStyleProject project = j.createFreeStyleProject(); | ||
project.addProperty(new ScannerJobProperty(true)); | ||
assertTrue(checker.executeCheck(project)); | ||
} | ||
@Test public void testEnabledBFAJob() throws Exception { | ||
FreeStyleProject project = j.createFreeStyleProject(); | ||
project.addProperty(new ScannerJobProperty(false)); | ||
project.save(); | ||
assertFalse(checker.executeCheck(project)); | ||
} | ||
@Test public void testMatrixProject() throws Exception { | ||
MatrixProject project = j.createMatrixProject("doNotScan"); | ||
project.addProperty(new ScannerJobProperty(true)); | ||
project.save(); | ||
assertTrue(checker.executeCheck(project)); | ||
project.delete(); | ||
project = j.createMatrixProject("Scan"); | ||
project.addProperty(new ScannerJobProperty(false)); | ||
project.save(); | ||
assertFalse(checker.executeCheck(project)); | ||
} | ||
@Test public void testMavenModule() throws Exception { | ||
MavenModuleSet project = j.createMavenProject(); | ||
project.addProperty(new ScannerJobProperty(true)); | ||
project.save(); | ||
assertTrue(checker.executeCheck(project)); | ||
project.delete(); | ||
project = j.createMavenProject("Scan"); | ||
project.addProperty(new ScannerJobProperty(false)); | ||
project.save(); | ||
assertFalse(checker.executeCheck(project)); | ||
} | ||
@Test public void testControlComment() throws Exception { | ||
FreeStyleProject project = j.createFreeStyleProject(); | ||
assertFalse(checker.isIgnored(project.getDescription())); | ||
project.setDescription("#lint:ignore:" + checker.getClass().getSimpleName()); | ||
assertTrue(checker.isIgnored(project.getDescription())); | ||
} | ||
} |