Skip to content

Commit

Permalink
[JENKINS-38617] Refactored a bit to remove Optional plugin dependency…
Browse files Browse the repository at this point in the history
… by using Reflection
  • Loading branch information
v1v committed Feb 1, 2017
1 parent 147c0f7 commit 0a852b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
7 changes: 0 additions & 7 deletions pom.xml
Expand Up @@ -103,13 +103,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>groovy</artifactId>
<version>1.10</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ws-cleanup</artifactId>
Expand Down
Expand Up @@ -4,7 +4,6 @@
import hudson.maven.MavenModuleSet;
import hudson.model.Item;
import hudson.model.Project;
import hudson.plugins.groovy.StringScriptSource;
import hudson.tasks.Builder;
import jenkins.model.Jenkins;
import org.jenkins.ci.plugins.jenkinslint.model.AbstractCheck;
Expand Down Expand Up @@ -51,19 +50,25 @@ private boolean isSystemExit (List<Builder> builders) {
boolean status = false;
if (builders != null && builders.size() > 0 ) {
for (Builder builder : builders) {
// TODO: Reflection to decouple groovy plugin classs dependencies

if (builder instanceof hudson.plugins.groovy.SystemGroovy) {
hudson.plugins.groovy.SystemGroovy builder1 = (hudson.plugins.groovy.SystemGroovy) builder;
String command = ((hudson.plugins.groovy.StringScriptSource) builder1.getScriptSource()).getCommand();
LOG.log(Level.INFO, "groovy " + command);
// TODO: Parse to search for non comments, otherwise some false positives!
if (command != null && command.toLowerCase().contains("system.exit") ) {
status = true;
if (builder.getClass().getName().endsWith("SystemGroovy")) {
try {
Object scriptSource = builder.getClass().getMethod("getScriptSource",null).invoke(builder);
if (scriptSource.getClass().getName().endsWith("StringScriptSource")) {
Object command = scriptSource.getClass().getMethod("getCommand",null).invoke(scriptSource);
if (command instanceof String) {
// TODO: Parse to search for non comments, otherwise some false positives!
status = (command != null && ((String) command).toLowerCase().contains("system.exit"));
LOG.log(Level.FINE, "isSystemExit " + status);
}
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause());
status = false;
}
}
}
}
return status;
}

}

0 comments on commit 0a852b6

Please sign in to comment.