Polish usage of settings.xml to configure repository
See gh-12293
This commit is contained in:
parent
0858e9b368
commit
a809e8f316
|
@ -40,7 +40,14 @@ import org.springframework.web.util.UriTemplateHandler;
|
||||||
public abstract class AbstractEmbeddedServletContainerIntegrationTests {
|
public abstract class AbstractEmbeddedServletContainerIntegrationTests {
|
||||||
|
|
||||||
@ClassRule
|
@ClassRule
|
||||||
public static final TemporaryFolder temporaryFolder = new TemporaryFolder();
|
public static final TemporaryFolder temporaryFolder = new TemporaryFolder() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final AbstractApplicationLauncher launcher;
|
public final AbstractApplicationLauncher launcher;
|
||||||
|
|
|
@ -36,6 +36,7 @@ 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;
|
||||||
|
|
||||||
|
@ -72,10 +73,10 @@ 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);
|
File settingsXml = writeSettingsXml(appFolder);
|
||||||
writePom(appFolder, resourcesJar);
|
writePom(appFolder, resourcesJar);
|
||||||
copyApplicationSource(appFolder);
|
copyApplicationSource(appFolder);
|
||||||
packageApplication(appFolder);
|
packageApplication(appFolder, settingsXml);
|
||||||
return new File(appFolder, "target/app-0.0.1." + this.packaging);
|
return new File(appFolder, "target/app-0.0.1." + this.packaging);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,14 +110,20 @@ class ApplicationBuilder {
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeSettingsXml(File appFolder) throws IOException {
|
private File writeSettingsXml(File appFolder) throws IOException {
|
||||||
|
String repository = System.getProperty("repository");
|
||||||
|
if (!StringUtils.hasText(repository)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Map<String, Object> context = new HashMap<>();
|
Map<String, Object> context = new HashMap<>();
|
||||||
context.put("repository", System.getProperty("repository"));
|
context.put("repository", repository);
|
||||||
FileWriter out = new FileWriter(new File(appFolder, "settings.xml"));
|
File settingsXml = new File(appFolder, "settings.xml");
|
||||||
Mustache.compiler().escapeHTML(false)
|
try (FileWriter out = new FileWriter(settingsXml)) {
|
||||||
.compile(new FileReader("src/test/resources/settings-template.xml"))
|
Mustache.compiler().escapeHTML(false)
|
||||||
.execute(context, out);
|
.compile(new FileReader("src/test/resources/settings-template.xml"))
|
||||||
out.close();
|
.execute(context, out);
|
||||||
|
}
|
||||||
|
return settingsXml;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyApplicationSource(File appFolder) throws IOException {
|
private void copyApplicationSource(File appFolder) throws IOException {
|
||||||
|
@ -133,11 +140,14 @@ class ApplicationBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void packageApplication(File appFolder) throws MavenInvocationException {
|
private void packageApplication(File appFolder, File settingsXml)
|
||||||
|
throws MavenInvocationException {
|
||||||
InvocationRequest invocation = new DefaultInvocationRequest();
|
InvocationRequest invocation = new DefaultInvocationRequest();
|
||||||
invocation.setBaseDirectory(appFolder);
|
invocation.setBaseDirectory(appFolder);
|
||||||
invocation.setGoals(Collections.singletonList("package"));
|
invocation.setGoals(Collections.singletonList("package"));
|
||||||
invocation.setUserSettingsFile(new File(appFolder, "settings.xml"));
|
if (settingsXml != null) {
|
||||||
|
invocation.setUserSettingsFile(settingsXml);
|
||||||
|
}
|
||||||
InvocationResult execute = new DefaultInvoker().execute(invocation);
|
InvocationResult execute = new DefaultInvoker().execute(invocation);
|
||||||
assertThat(execute.getExitCode()).isEqualTo(0);
|
assertThat(execute.getExitCode()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,12 @@
|
||||||
<profile>
|
<profile>
|
||||||
<id>repository</id>
|
<id>repository</id>
|
||||||
<activation>
|
<activation>
|
||||||
<property>
|
<activeByDefault>true</activeByDefault>
|
||||||
<name>repository</name>
|
|
||||||
</property>
|
|
||||||
</activation>
|
</activation>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>repository</id>
|
<id>repository</id>
|
||||||
<url>${repository}</url>
|
<url>{{repository}}</url>
|
||||||
<snapshots>
|
<snapshots>
|
||||||
<enabled>true</enabled>
|
<enabled>true</enabled>
|
||||||
</snapshots>
|
</snapshots>
|
||||||
|
@ -21,7 +19,7 @@
|
||||||
<pluginRepositories>
|
<pluginRepositories>
|
||||||
<pluginRepository>
|
<pluginRepository>
|
||||||
<id>repository</id>
|
<id>repository</id>
|
||||||
<url>${repository}</url>
|
<url>{{repository}}</url>
|
||||||
<snapshots>
|
<snapshots>
|
||||||
<enabled>true</enabled>
|
<enabled>true</enabled>
|
||||||
</snapshots>
|
</snapshots>
|
||||||
|
|
Loading…
Reference in New Issue