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.
* Initial approach: suggest to use git ref repos in submodules... only when using git over 2.4+ * Using the right method name and fixed some syntax errors * Added further tests and using the right plugin version validation * Still WIP * Fixed wrong asserts * Speeding up tests and using the AbstractAction pattern * Added missing import * Fixed test asserts * Git Plugin 2.4.1 version required another Jenkins Core Version which didn't have the MatrixProject bundled within the core and thereofre it required an explicit version, and I didn't want to depend on it therefore I used the reflection to avoid ti * Fixed flake test since it is not the right assert to test * Visualise Test output * Fixed unused imports * Added UI Test * Fixed hardcoded strings
- Loading branch information
Showing
12 changed files
with
197 additions
and
69 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
64 changes: 64 additions & 0 deletions
64
src/main/java/org/jenkins/ci/plugins/jenkinslint/check/GitRefSubmoduleChecker.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,64 @@ | ||
package org.jenkins.ci.plugins.jenkinslint.check; | ||
|
||
import hudson.PluginWrapper; | ||
import hudson.model.Item; | ||
import hudson.model.Project; | ||
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 | ||
*/ | ||
public class GitRefSubmoduleChecker extends AbstractCheck { | ||
|
||
public GitRefSubmoduleChecker() { | ||
super(); | ||
this.setDescription(Messages.GitRefSubmoduleCheckerDesc()); | ||
this.setSeverity(Messages.GitRefSubmoduleCheckerSeverity()); | ||
} | ||
|
||
public boolean executeCheck(Item item) { | ||
if (item instanceof Project) { | ||
PluginWrapper plugin = Jenkins.getInstance().pluginManager.getPlugin("git"); | ||
if (plugin!=null && plugin.getVersionNumber().isNewerThan(new hudson.util.VersionNumber("2.4.0"))) { | ||
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("SubmoduleOption")) { | ||
Object reference = extension.getClass().getMethod("getReference",null).invoke(extension); | ||
if (reference instanceof String) { | ||
LOG.log(Level.WARNING, "foundXXX " + reference); | ||
status = ((String) reference).isEmpty(); | ||
} | ||
} | ||
} | ||
} | ||
} catch (Exception e) { | ||
LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause()); | ||
status = false; | ||
} finally { | ||
return status; | ||
} | ||
} | ||
} else { | ||
LOG.log(Level.FINE, "Plugin GIT hasn't been configured in this project"); | ||
return false; | ||
} | ||
} else { | ||
LOG.log(Level.FINE, "Plugin GIT doesn't exist"); | ||
return false; | ||
} | ||
|
||
} | ||
return false; | ||
} | ||
} |
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
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
Oops, something went wrong.