Skip to content

Commit

Permalink
GRADLE-702 Maven deployer uses the repositories specified in the user…
Browse files Browse the repository at this point in the history
…'s settings.xml, rather than those specified in the build file.

Gradle now ignores any existing settings.xml file.
  • Loading branch information
hansd committed Oct 19, 2009
1 parent 3389504 commit eb94429
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -57,6 +59,8 @@
* @author Hans Dockter
*/
public abstract class AbstractMavenResolver implements MavenResolver {
protected final static String SETTINGS_XML = "<settings/>";

private String name;

private ArtifactPomContainer artifactPomContainer;
Expand Down Expand Up @@ -175,10 +179,13 @@ public void abortPublishTransaction() throws IOException {
public void commitPublishTransaction() throws IOException {
InstallDeployTaskSupport installDeployTaskSupport = createPreConfiguredTask(AntUtil.createProject());
Set<DeployableFilesInfo> 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();
}

Expand All @@ -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
}
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -123,9 +126,12 @@ public void deployOrInstall() throws IOException, PlexusContainerException {
}

protected void checkTransaction(final Set<DeployableFilesInfo> 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())));
Expand All @@ -137,6 +143,8 @@ protected void checkTransaction(final Set<DeployableFilesInfo> 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<Pom> pomMatcher(final File expectedPomFile, final Project expectedAntProject) {
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit eb94429

Please sign in to comment.