Skip to content

Commit 6db64ca

Browse files
author
Dave Syer
committed
Refactor test for settings.xml repository location setting
The jitpack repo is now mirrored in repo.spring.io so we can't rely on non-existence of those artifacts to show that they are not being configured properly.
1 parent e99b20c commit 6db64ca

File tree

7 files changed

+51
-27
lines changed

7 files changed

+51
-27
lines changed

launcher/src/test/java/org/springframework/boot/loader/thin/ThinJarLauncherTests.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
package org.springframework.boot.loader.thin;
1717

1818
import java.io.File;
19+
import java.io.FileInputStream;
20+
import java.io.FileOutputStream;
21+
import java.nio.charset.Charset;
1922
import java.util.Collections;
2023
import java.util.Properties;
2124

2225
import org.eclipse.aether.artifact.DefaultArtifact;
2326
import org.eclipse.aether.graph.Dependency;
24-
import org.junit.Ignore;
2527
import org.junit.Rule;
2628
import org.junit.Test;
2729
import org.junit.rules.ExpectedException;
@@ -30,6 +32,8 @@
3032
import org.springframework.boot.test.rule.OutputCapture;
3133
import org.springframework.core.io.Resource;
3234
import org.springframework.test.util.ReflectionTestUtils;
35+
import org.springframework.util.FileSystemUtils;
36+
import org.springframework.util.StreamUtils;
3337

3438
import static org.assertj.core.api.Assertions.assertThat;
3539
import static org.mockito.Matchers.any;
@@ -377,28 +381,39 @@ public void settingsOffline() throws Exception {
377381
}
378382

379383
@Test
380-
@Ignore("Not sure why this broke. Local settings?")
381384
public void repositorySettingsMissing() throws Exception {
382385
DependencyResolver.close();
383-
deleteRecursively(new File("target/thin/test/repository/com/github/jitpack"));
386+
deleteRecursively(new File("target/thin/test/repository/com/example"));
384387
String[] args = new String[] { "--thin.root=target/thin/test",
385388
"--thin.dryrun=true", "--thin.archive=src/test/resources/apps/jitpack",
386389
"--debug" };
387390
expected.expect(RuntimeException.class);
388-
expected.expectMessage("maven-simple:jar:1.1");
391+
expected.expectMessage("maven-simple:jar:1.0");
389392
ThinJarLauncher.main(args);
390-
assertThat(new File("target/thin/test/repository/com/github/jitpack/maven-simple")
393+
assertThat(new File("target/thin/test/repository/com/example/maven/maven-simple")
391394
.exists()).isFalse();
392395
}
393396

394397
@Test
395398
public void repositorySettingsPresent() throws Exception {
396399
DependencyResolver.close();
400+
File userhome = new File("target/settings/repo/.m2");
401+
if (!userhome.exists()) {
402+
userhome.mkdirs();
403+
}
404+
String settings = StreamUtils.copyToString(
405+
new FileInputStream(
406+
new File("src/test/resources/settings/repo/.m2/settings.xml")),
407+
Charset.defaultCharset());
408+
settings = settings.replace("${repo.url}",
409+
"file://" + new File("target/test-classes/repo").getAbsolutePath());
410+
StreamUtils.copy(settings, Charset.defaultCharset(),
411+
new FileOutputStream(new File(userhome, "settings.xml")));
397412
String home = System.getProperty("user.home");
398413
System.setProperty("user.home",
399-
new File("src/test/resources/settings/profile").getAbsolutePath());
414+
new File("target/settings/repo").getAbsolutePath());
400415
try {
401-
deleteRecursively(new File("target/thin/test/repository/com/github/jitpack"));
416+
deleteRecursively(new File("target/thin/test/repository/com/example"));
402417
String[] args = new String[] { "--thin.root=target/thin/test",
403418
"--thin.dryrun=true",
404419
"--thin.archive=src/test/resources/apps/jitpack", "--debug" };
@@ -408,7 +423,7 @@ public void repositorySettingsPresent() throws Exception {
408423
System.setProperty("user.home", home);
409424
}
410425
assertThat(new File("target/thin/test/repository").exists()).isTrue();
411-
assertThat(new File("target/thin/test/repository/com/github/jitpack/maven-simple")
426+
assertThat(new File("target/thin/test/repository/com/example/maven/maven-simple")
412427
.exists()).isTrue();
413428
}
414429

@@ -433,23 +448,7 @@ public void repositorySettingsMissingForSnapshotDependency() throws Exception {
433448
}
434449

435450
public static boolean deleteRecursively(File root) {
436-
if (root != null && root.exists()) {
437-
if (root.isDirectory()) {
438-
File[] children = root.listFiles();
439-
if (children != null) {
440-
for (File child : children) {
441-
deleteRecursively(child);
442-
}
443-
}
444-
}
445-
boolean deleted = root.delete();
446-
if (!deleted) {
447-
System.err.println("Cannot delete: " + root);
448-
}
449-
return deleted;
450-
}
451-
System.err.println("Did not delete: " + root);
452-
return false;
451+
return FileSystemUtils.deleteRecursively(root);
453452
}
454453

455454
}

launcher/src/test/resources/apps/jitpack/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
<dependencies>
2828
<dependency>
29-
<groupId>com.github.jitpack</groupId>
29+
<groupId>com.example.maven</groupId>
3030
<artifactId>maven-simple</artifactId>
31-
<version>1.1</version>
31+
<version>1.0</version>
3232
</dependency>
3333
</dependencies>
3434

Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
d7c90f3ab0e6eb25b552c3585c0572a04dc300dc
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example.maven</groupId>
7+
<artifactId>maven-simple</artifactId>
8+
<version>1.0</version>
9+
<packaging>jar</packaging>
10+
11+
</project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
96aab6c54cff89cd8fd457c20b2d9798cdbbf21c
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<metadata>
2+
<groupId>com.example.maven</groupId>
3+
<artifactId>maven-simple</artifactId>
4+
<versioning>
5+
<latest>1.0</latest>
6+
<release>1.0</release>
7+
<versions>
8+
<version>1.0</version>
9+
</versions>
10+
<lastUpdated>20190416201550</lastUpdated>
11+
</versioning>
12+
</metadata>

0 commit comments

Comments
 (0)