1616package org .springframework .boot .loader .thin ;
1717
1818import java .io .File ;
19+ import java .io .FileInputStream ;
20+ import java .io .FileOutputStream ;
21+ import java .nio .charset .Charset ;
1922import java .util .Collections ;
2023import java .util .Properties ;
2124
2225import org .eclipse .aether .artifact .DefaultArtifact ;
2326import org .eclipse .aether .graph .Dependency ;
24- import org .junit .Ignore ;
2527import org .junit .Rule ;
2628import org .junit .Test ;
2729import org .junit .rules .ExpectedException ;
3032import org .springframework .boot .test .rule .OutputCapture ;
3133import org .springframework .core .io .Resource ;
3234import org .springframework .test .util .ReflectionTestUtils ;
35+ import org .springframework .util .FileSystemUtils ;
36+ import org .springframework .util .StreamUtils ;
3337
3438import static org .assertj .core .api .Assertions .assertThat ;
3539import 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}
0 commit comments