Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactored: using reflection in order to load checks dynamically #6 […
…JENKINS-29485]
  • Loading branch information
v1v committed Jul 18, 2015
1 parent 5f2aeae commit 8d9dd49
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -97,6 +97,12 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.10</version>
</dependency>

<dependency>
<groupId>com.github.mjdetullio.jenkins.plugins</groupId>
<artifactId>multi-branch-project-plugin</artifactId>
Expand Down
Expand Up @@ -4,27 +4,16 @@
import hudson.model.AbstractProject;
import hudson.model.RootAction;
import jenkins.model.Jenkins;
import org.jenkins.ci.plugins.jenkinslint.check.ArtifactChecker;
import org.jenkins.ci.plugins.jenkinslint.check.CleanupWorkspaceChecker;
import org.jenkins.ci.plugins.jenkinslint.check.GitShallowChecker;
import org.jenkins.ci.plugins.jenkinslint.check.HardcodedScriptChecker;
import org.jenkins.ci.plugins.jenkinslint.check.JavadocChecker;
import org.jenkins.ci.plugins.jenkinslint.check.JobAssignedLabelChecker;
import org.jenkins.ci.plugins.jenkinslint.check.JobDescriptionChecker;
import org.jenkins.ci.plugins.jenkinslint.check.JobLogRotatorChecker;
import org.jenkins.ci.plugins.jenkinslint.check.JobNameChecker;
import org.jenkins.ci.plugins.jenkinslint.check.MasterLabelChecker;
import org.jenkins.ci.plugins.jenkinslint.check.MavenJobTypeChecker;
import org.jenkins.ci.plugins.jenkinslint.check.MultibranchJobTypeChecker;
import org.jenkins.ci.plugins.jenkinslint.check.NullSCMChecker;
import org.jenkins.ci.plugins.jenkinslint.check.PollingSCMTriggerChecker;
import org.jenkins.ci.plugins.jenkinslint.model.AbstractCheck;
import org.jenkins.ci.plugins.jenkinslint.model.InterfaceCheck;
import org.jenkins.ci.plugins.jenkinslint.model.Job;
import org.jenkins.ci.plugins.jenkinslint.model.Lint;
import org.reflections.Reflections;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -40,20 +29,17 @@ public void getData() throws IOException {
jobSet.clear();
checkList.clear();

checkList.add(new JobNameChecker());
checkList.add(new JobDescriptionChecker());
checkList.add(new JobAssignedLabelChecker());
checkList.add(new MasterLabelChecker());
checkList.add(new JobLogRotatorChecker());
checkList.add(new MavenJobTypeChecker());
checkList.add(new CleanupWorkspaceChecker());
checkList.add(new JavadocChecker());
checkList.add(new ArtifactChecker());
checkList.add(new NullSCMChecker());
checkList.add(new PollingSCMTriggerChecker( ));
checkList.add(new GitShallowChecker());
checkList.add(new MultibranchJobTypeChecker());
checkList.add(new HardcodedScriptChecker());
Reflections reflections = new Reflections("org.jenkins.ci.plugins.jenkinslint.check");
Set<Class<? extends AbstractCheck>> classes = reflections.getSubTypesOf(AbstractCheck.class);
for (Class<? extends AbstractCheck> reflectionClass : classes) {
try {
checkList.add(reflectionClass.newInstance());
} catch (InstantiationException e) {
LOG.log(Level.WARNING, "InstantiationException when running Reflection", e.getCause());
} catch (IllegalAccessException e) {
LOG.log(Level.WARNING, "IllegalAccessException when running Reflection", e.getCause());
}
}

for (AbstractProject item : Jenkins.getInstance().getAllItems(AbstractProject.class)) {
LOG.log(Level.FINER, "queryChecks " + item.getDisplayName());
Expand Down

0 comments on commit 8d9dd49

Please sign in to comment.