Skip to content
Permalink
Browse files

[JENKINS-34138] Fix maven installs from stepping on each other (#3042)

* [JENKINS-34138] Adding equals/hashCode methods so that installs don't step on each other

* [JENKINS-34138] Added issue reference to unit tests

* [JENKINS-34138] - changed the order of equals / hashcode

(cherry picked from commit d688c15)
  • Loading branch information...
t-hall authored and olivergondza committed Nov 16, 2017
1 parent 2a1406e commit 065b874a4784c5d0bcfd9731c0ad4139c5e61c78
Showing with 59 additions and 24 deletions.
  1. +21 −0 core/src/main/java/hudson/tasks/Maven.java
  2. +38 −24 test/src/test/java/hudson/tasks/MavenTest.java
@@ -709,6 +709,27 @@ public void setInstallations(MavenInstallation... installations) {
return ((MavenInstallation)obj).mavenHome;
}
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

final MavenInstallation that = (MavenInstallation) o;

if (getHome() != null ? !getHome().equals(that.getHome()) : that.getHome() != null) return false;
if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) return false;
return true;
}

@Override
public int hashCode() {
int result = getHome() != null ? getHome().hashCode() : 0;
result = 31 * result + (getName() != null ? getName().hashCode() : 0);
//result = 31 * result + (getProperties() != null ? getProperties().hashCode() : 0);
return result;
}

}

/**
@@ -23,50 +23,48 @@
*/
package hudson.tasks;

import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.EnvVars;
import hudson.model.Build;
import hudson.model.Cause.LegacyCodeCause;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import jenkins.mvn.DefaultGlobalSettingsProvider;
import jenkins.mvn.DefaultSettingsProvider;
import jenkins.mvn.FilePathGlobalSettingsProvider;
import jenkins.mvn.FilePathSettingsProvider;
import jenkins.mvn.GlobalMavenConfig;
import hudson.model.JDK;
import hudson.model.ParametersAction;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.PasswordParameterDefinition;
import hudson.model.Result;
import hudson.model.StringParameterDefinition;
import hudson.model.ParametersAction;
import hudson.model.StringParameterValue;
import hudson.model.Cause.LegacyCodeCause;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.slaves.EnvironmentVariablesNodeProperty.Entry;
import hudson.tasks.Maven.MavenInstallation;
import hudson.tasks.Maven.MavenInstaller;
import hudson.tasks.Maven.MavenInstallation.DescriptorImpl;
import hudson.tasks.Maven.MavenInstaller;
import hudson.tools.InstallSourceProperty;
import hudson.tools.ToolProperty;
import hudson.tools.ToolPropertyDescriptor;
import hudson.tools.InstallSourceProperty;
import hudson.util.DescribableList;

import java.util.Collections;

import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;

import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import hudson.EnvVars;
import hudson.model.FreeStyleBuild;
import hudson.model.PasswordParameterDefinition;
import org.jvnet.hudson.test.Issue;
import static org.junit.Assert.*;

import jenkins.mvn.DefaultGlobalSettingsProvider;
import jenkins.mvn.DefaultSettingsProvider;
import jenkins.mvn.FilePathGlobalSettingsProvider;
import jenkins.mvn.FilePathSettingsProvider;
import jenkins.mvn.GlobalMavenConfig;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.ToolInstallations;

import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import java.util.Collections;

import static org.junit.Assert.*;

/**
* @author Kohsuke Kawaguchi
*/
@@ -356,4 +354,20 @@ public void parametersReferencedFromPropertiesShouldRetainBackslashes() throws E
assertTrue("Properties should always be injected, even when build variables injection is enabled",
log.contains("-DTEST_PROP1=VAL1") && log.contains("-DTEST_PROP2=VAL2"));
}

@Issue("JENKINS-34138")
@Test public void checkMavenInstallationEquals() throws Exception {
MavenInstallation maven = ToolInstallations.configureMaven3();
MavenInstallation maven2 = ToolInstallations.configureMaven3();
assertEquals(maven.hashCode(), maven2.hashCode());
assertTrue(maven.equals(maven2));
}

@Issue("JENKINS-34138")
@Test public void checkMavenInstallationNotEquals() throws Exception {
MavenInstallation maven3 = ToolInstallations.configureMaven3();
MavenInstallation maven2 = ToolInstallations.configureDefaultMaven();
assertNotEquals(maven3.hashCode(), maven2.hashCode());
assertFalse(maven3.equals(maven2));
}
}

0 comments on commit 065b874

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