Skip to content
Permalink
Browse files

Refactor git dependency #8 [JENKINS-29546] in order to avoid plugin d…

…ependencies
  • Loading branch information
v1v committed Jul 21, 2015
1 parent 89ea91d commit 8f63aee12ce78f56a7660ea4ee05d3c8a01230d2
@@ -100,7 +100,7 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>2.3.4</version>
<optional>true</optional>
<scope>test</scope>
</dependency>

<dependency>
@@ -2,13 +2,13 @@

import hudson.model.Item;
import hudson.model.Project;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.GitSCMExtensionDescriptor;
import hudson.plugins.git.extensions.impl.CloneOption;
import hudson.util.DescribableList;
import jenkins.model.Jenkins;
import org.jenkins.ci.plugins.jenkinslint.model.AbstractCheck;

import java.lang.reflect.Method;
import java.util.AbstractList;
import java.util.logging.Level;

/**
* @author Victor Martinez
*/
@@ -23,15 +23,32 @@ public GitShallowChecker() {

public boolean executeCheck(Item item) {
if (item instanceof Project) {
if (((Project) item).getScm() instanceof hudson.plugins.git.GitSCM) {
DescribableList<GitSCMExtension, GitSCMExtensionDescriptor> extensionsList = ((GitSCM) ((Project) item).getScm()).getExtensions();
boolean status = true;
for (GitSCMExtension extension : extensionsList) {
if (extension instanceof hudson.plugins.git.extensions.impl.CloneOption && ((CloneOption) extension).isShallow()) {
if (Jenkins.getInstance().pluginManager.getPlugin("git")!=null) {
if (((Project) 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());
if (extensionsList instanceof AbstractList) {
for (Object extension : ((AbstractList) extensionsList) ) {
if (extension.getClass().getName().endsWith("CloneOption")) {
Object isShallow = extension.getClass().getMethod("isShallow", null).invoke(extension);
if (isShallow instanceof Boolean) {
status = ! ((Boolean) isShallow).booleanValue();
}
}
}
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause());
status = false;
} finally {
return status;
}
}
return status;
} else {
LOG.log(Level.FINE, "Plugin GIT doesn't exist");
return false;
}
}
return false;
@@ -49,6 +49,9 @@
extensions.add(new CleanCheckout());
project.setScm(new hudson.plugins.git.GitSCM(null, null, false, null, null, "", extensions));
assertTrue(checker.executeCheck(project));
extensions.add(new CloneOption(false, "", 0));
project.setScm(new hudson.plugins.git.GitSCM(null, null, false, null, null, "", extensions));
assertTrue(checker.executeCheck(project));
}
@Test public void testGitSCMWithCloneOptionExtensionNoShallowJob() throws Exception {
FreeStyleProject project = j.createFreeStyleProject();

0 comments on commit 8f63aee

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