Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions core/src/main/java/hudson/tasks/Maven.java
Expand Up @@ -709,6 +709,27 @@ public static class ConverterImpl extends ToolConverter {
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;
}

}

/**
Expand Down
62 changes: 38 additions & 24 deletions test/src/test/java/hudson/tasks/MavenTest.java
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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));
}
}