Skip to content

Commit

Permalink
[JENKINS-19141] - Make maven-plugin optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochen Fürbacher committed Apr 21, 2017
1 parent 421b4d9 commit 474313b
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -107,6 +107,7 @@
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
<version>2.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Expand Up @@ -32,9 +32,9 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.SortedMap;

import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/hudson/plugins/jobConfigHistory/FileHistoryDao.java
Expand Up @@ -407,17 +407,8 @@ public XmlFile getOldRevision(final AbstractItem item,
final String identifier) {
final File configFile = item.getConfigFile().getFile();
final File historyDir = new File(getHistoryDir(configFile), identifier);
boolean isMavenModuleAvailable = false;
try {
Class.forName("hudson.maven.MavenModule");
isMavenModuleAvailable = true;
} catch (ClassNotFoundException ex) {
LOG.log(Level.FINEST,
"MavenModule not available. JobConfigHistory needs MavenModule. ",
ex);
isMavenModuleAvailable = false;
}
if (isMavenModuleAvailable && item instanceof MavenModule) {
if (PluginUtils.isMavenPluginAvailable()
&& item instanceof MavenModule) {
final String path = historyDir
+ ((MavenModule) item).getParent().getFullName()
.replace("/", "/jobs/")
Expand Down
Expand Up @@ -404,7 +404,6 @@ public String getExcludedUsers() {
* @return true if the item configuration should be saved.
*/
public boolean isSaveable(final Saveable item, final XmlFile xmlFile) {

if (item instanceof TopLevelItem) {
return true;
}
Expand All @@ -413,7 +412,8 @@ public boolean isSaveable(final Saveable item, final XmlFile xmlFile) {
return checkRegex(xmlFile);
}

if (item instanceof MavenModule && saveModuleConfiguration) {
if (PluginUtils.isMavenPluginAvailable() && item instanceof MavenModule
&& saveModuleConfiguration) {
return true;
}

Expand Down
Expand Up @@ -101,10 +101,10 @@ public final String getIconFileName() {
return JobConfigHistoryConsts.ICONFILENAME;
}
if (getPlugin().getSaveModuleConfiguration()
&& PluginUtils.isMavenPluginAvailable()
&& project instanceof MavenModule) {
return JobConfigHistoryConsts.ICONFILENAME;
}

return null;
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/hudson/plugins/jobConfigHistory/PluginUtils.java
Expand Up @@ -29,6 +29,7 @@
import java.util.Date;
import java.util.regex.Pattern;

import hudson.Plugin;
import hudson.model.User;
import jenkins.model.Jenkins;

Expand Down Expand Up @@ -148,4 +149,16 @@ public static Date parsedDate(final String timeStamp) {
"Could not parse Date" + timeStamp, ex);
}
}

/**
* @return true, if Maven integration plugin is available and active.
*/
public static boolean isMavenPluginAvailable() {
try {
Plugin plugin = Jenkins.getInstance().getPlugin("maven-plugin");
return plugin.getWrapper().isActive();
} catch (Exception e) {
return false;
}
}
}
Expand Up @@ -20,6 +20,8 @@
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.WithPlugin;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

Expand All @@ -38,6 +40,9 @@
*/
public class JobConfigHistoryProjectActionTest {

@Rule
public JenkinsRule j = new JenkinsRule();

@Rule
public UnpackResourceZip testConfigs = UnpackResourceZip.create();

Expand Down Expand Up @@ -90,6 +95,7 @@ public void testGetIconFileNameSaveProjectNonMavenModules() {
/**
* Test of getIconFileName method, of class JobConfigHistoryProjectAction.
*/
@WithPlugin("maven-plugin.hpi")
@Test
public void testGetIconFileNameSaveMavenModules() {
when(mockedMavenModule.hasPermission(AbstractProject.CONFIGURE))
Expand Down
Binary file added src/test/resources/plugins/maven-plugin.hpi
Binary file not shown.

1 comment on commit 474313b

@jglick
Copy link
Member

@jglick jglick commented on 474313b Apr 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cf. #34

Please sign in to comment.