Commit d0b8a848 authored by Andy Wilkinson's avatar Andy Wilkinson

Use settings.xml to pass repository into server integration tests

Closes gh-12293
parent a1ee9bc6
...@@ -24,7 +24,6 @@ import java.io.IOException; ...@@ -24,7 +24,6 @@ import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
...@@ -37,7 +36,6 @@ import org.apache.maven.shared.invoker.MavenInvocationException; ...@@ -37,7 +36,6 @@ import org.apache.maven.shared.invoker.MavenInvocationException;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -74,6 +72,7 @@ class ApplicationBuilder { ...@@ -74,6 +72,7 @@ class ApplicationBuilder {
File resourcesJar = createResourcesJar(); File resourcesJar = createResourcesJar();
File appFolder = new File(containerFolder, "app"); File appFolder = new File(containerFolder, "app");
appFolder.mkdirs(); appFolder.mkdirs();
writeSettingsXml(appFolder);
writePom(appFolder, resourcesJar); writePom(appFolder, resourcesJar);
copyApplicationSource(appFolder); copyApplicationSource(appFolder);
packageApplication(appFolder); packageApplication(appFolder);
...@@ -110,6 +109,16 @@ class ApplicationBuilder { ...@@ -110,6 +109,16 @@ class ApplicationBuilder {
out.close(); out.close();
} }
private void writeSettingsXml(File appFolder) throws IOException {
Map<String, Object> context = new HashMap<>();
context.put("repository", System.getProperty("repository"));
FileWriter out = new FileWriter(new File(appFolder, "settings.xml"));
Mustache.compiler().escapeHTML(false)
.compile(new FileReader("src/test/resources/settings-template.xml"))
.execute(context, out);
out.close();
}
private void copyApplicationSource(File appFolder) throws IOException { private void copyApplicationSource(File appFolder) throws IOException {
File examplePackage = new File(appFolder, "src/main/java/com/example"); File examplePackage = new File(appFolder, "src/main/java/com/example");
examplePackage.mkdirs(); examplePackage.mkdirs();
...@@ -128,12 +137,7 @@ class ApplicationBuilder { ...@@ -128,12 +137,7 @@ class ApplicationBuilder {
InvocationRequest invocation = new DefaultInvocationRequest(); InvocationRequest invocation = new DefaultInvocationRequest();
invocation.setBaseDirectory(appFolder); invocation.setBaseDirectory(appFolder);
invocation.setGoals(Collections.singletonList("package")); invocation.setGoals(Collections.singletonList("package"));
String repository = System.getProperty("repository"); invocation.setUserSettingsFile(new File(appFolder, "settings.xml"));
if (StringUtils.hasText(repository) && !repository.equals("${repository}")) {
Properties properties = new Properties();
properties.put("repository", repository);
invocation.setProperties(properties);
}
InvocationResult execute = new DefaultInvoker().execute(invocation); InvocationResult execute = new DefaultInvoker().execute(invocation);
assertThat(execute.getExitCode()).isEqualTo(0); assertThat(execute.getExitCode()).isEqualTo(0);
} }
......
...@@ -61,32 +61,4 @@ ...@@ -61,32 +61,4 @@
</snapshots> </snapshots>
</repository> </repository>
</repositories> </repositories>
<profiles>
<profile>
<id>repository</id>
<activation>
<property>
<name>repository</name>
</property>
</activation>
<repositories>
<repository>
<id>repository</id>
<url>${repository}</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repository</id>
<url>${repository}</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</project> </project>
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>repository</id>
<activation>
<property>
<name>repository</name>
</property>
</activation>
<repositories>
<repository>
<id>repository</id>
<url>${repository}</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repository</id>
<url>${repository}</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment