From eb944299136695003cc4a43998c25640a7dda48e Mon Sep 17 00:00:00 2001 From: hansd Date: Mon, 19 Oct 2009 03:57:07 +0200 Subject: [PATCH] GRADLE-702 Maven deployer uses the repositories specified in the user's settings.xml, rather than those specified in the build file. Gradle now ignores any existing settings.xml file. --- .../maven/deploy/AbstractMavenResolver.java | 19 +++++++++++- .../deploy/AbstractMavenResolverTest.java | 30 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/subprojects/gradle-core/src/main/groovy/org/gradle/api/internal/artifacts/publish/maven/deploy/AbstractMavenResolver.java b/subprojects/gradle-core/src/main/groovy/org/gradle/api/internal/artifacts/publish/maven/deploy/AbstractMavenResolver.java index d10f1be42122..bc1219b3c824 100644 --- a/subprojects/gradle-core/src/main/groovy/org/gradle/api/internal/artifacts/publish/maven/deploy/AbstractMavenResolver.java +++ b/subprojects/gradle-core/src/main/groovy/org/gradle/api/internal/artifacts/publish/maven/deploy/AbstractMavenResolver.java @@ -37,6 +37,7 @@ import org.apache.maven.artifact.ant.AttachedArtifact; import org.apache.maven.settings.Settings; import org.apache.tools.ant.Project; +import org.apache.commons.io.FileUtils; import org.gradle.api.artifacts.maven.MavenPom; import org.gradle.api.artifacts.maven.MavenResolver; import org.gradle.api.artifacts.maven.PomFilterContainer; @@ -45,6 +46,7 @@ import org.gradle.api.logging.DefaultStandardOutputCapture; import org.gradle.api.logging.LogLevel; import org.gradle.api.logging.StandardOutputCapture; +import org.gradle.api.UncheckedIOException; import org.gradle.util.AntUtil; import java.io.File; @@ -57,6 +59,8 @@ * @author Hans Dockter */ public abstract class AbstractMavenResolver implements MavenResolver { + protected final static String SETTINGS_XML = ""; + private String name; private ArtifactPomContainer artifactPomContainer; @@ -175,10 +179,13 @@ public void abortPublishTransaction() throws IOException { public void commitPublishTransaction() throws IOException { InstallDeployTaskSupport installDeployTaskSupport = createPreConfiguredTask(AntUtil.createProject()); Set deployableFilesInfos = getArtifactPomContainer().createDeployableFilesInfos(configurationContainer.getAll()); + File emptySettingsXml = createEmptyMavenSettingsXml(); + installDeployTaskSupport.setSettingsFile(emptySettingsXml); for (DeployableFilesInfo deployableFilesInfo : deployableFilesInfos) { addPomAndArtifact(installDeployTaskSupport, deployableFilesInfo); - execute(installDeployTaskSupport); + execute(installDeployTaskSupport); } + emptySettingsXml.delete(); settings = ((CustomInstallDeployTaskSupport) installDeployTaskSupport).getSettings(); } @@ -205,6 +212,16 @@ private void addPomAndArtifact(InstallDeployTaskSupport installOrDeployTask, Dep } } + private File createEmptyMavenSettingsXml() { + try { + File settingsXml = File.createTempFile("gradle_empty_settings", ".xml"); + FileUtils.writeStringToFile(settingsXml, SETTINGS_XML); + return settingsXml; + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + public void setSettings(ResolverSettings settings) { // do nothing } diff --git a/subprojects/gradle-core/src/test/groovy/org/gradle/api/internal/artifacts/publish/maven/deploy/AbstractMavenResolverTest.java b/subprojects/gradle-core/src/test/groovy/org/gradle/api/internal/artifacts/publish/maven/deploy/AbstractMavenResolverTest.java index 53f9070b9d9e..81ff2bdd074b 100644 --- a/subprojects/gradle-core/src/test/groovy/org/gradle/api/internal/artifacts/publish/maven/deploy/AbstractMavenResolverTest.java +++ b/subprojects/gradle-core/src/test/groovy/org/gradle/api/internal/artifacts/publish/maven/deploy/AbstractMavenResolverTest.java @@ -23,6 +23,7 @@ import org.apache.maven.artifact.ant.AttachedArtifact; import org.apache.maven.settings.Settings; import org.apache.tools.ant.Project; +import org.apache.commons.io.FileUtils; import org.codehaus.plexus.PlexusContainerException; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.ConfigurationContainer; @@ -38,6 +39,8 @@ import org.hamcrest.Matcher; import static org.hamcrest.Matchers.*; import org.jmock.Expectations; +import org.jmock.api.Action; +import org.jmock.api.Invocation; import org.jmock.lib.legacy.ClassImposteriser; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; @@ -123,9 +126,12 @@ public void deployOrInstall() throws IOException, PlexusContainerException { } protected void checkTransaction(final Set deployableFilesInfos, final AttachedArtifact attachedArtifact, ClassifierArtifact classifierArtifact) throws IOException, PlexusContainerException { + final GrabSettingsFileAction grabSettingsFileAction = new GrabSettingsFileAction(); context.checking(new Expectations() { { one(getInstallDeployTask()).setProject(with(any(Project.class))); + one(getInstallDeployTask()).setSettingsFile(with(any(File.class))); + will(grabSettingsFileAction); for (DeployableFilesInfo deployableFilesInfo : deployableFilesInfos) { one(getInstallDeployTask()).setFile(deployableFilesInfo.getArtifactFile()); one(getInstallDeployTask()).addPom(with(pomMatcher(deployableFilesInfo.getPomFile(), getInstallDeployTask().getProject()))); @@ -137,6 +143,8 @@ protected void checkTransaction(final Set deployableFilesIn assertThat(attachedArtifact.getFile(), equalTo(classifierArtifact.getFile())); assertThat(attachedArtifact.getType(), equalTo(classifierArtifact.getType())); assertThat(attachedArtifact.getClassifier(), equalTo(classifierArtifact.getClassifier())); + assertThat(grabSettingsFileAction.getSettingsFile().exists(), equalTo(false)); + assertThat(grabSettingsFileAction.getSettingsFileContent(), equalTo(AbstractMavenResolver.SETTINGS_XML)); } private static Matcher pomMatcher(final File expectedPomFile, final Project expectedAntProject) { @@ -218,4 +226,26 @@ public void pom() { }}); assertSame(pomMock, getMavenResolver().pom(testName)); } + + private static class GrabSettingsFileAction implements Action { + private File settingsFile; + private String settingsFileContent; + + public void describeTo(Description description) { + } + + public Object invoke(Invocation invocation) throws Throwable { + settingsFile = (File) invocation.getParameter(0); + settingsFileContent = FileUtils.readFileToString(settingsFile); + return null; + } + + public File getSettingsFile() { + return settingsFile; + } + + public String getSettingsFileContent() { + return settingsFileContent; + } + } }