diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/maven/MavenSettings.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/maven/MavenSettings.java index 08ca2a6382..abf05c6447 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/maven/MavenSettings.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/maven/MavenSettings.java @@ -16,8 +16,11 @@ package org.springframework.boot.cli.compiler.maven; +import java.io.BufferedReader; import java.io.File; +import java.io.IOException; import java.io.PrintWriter; +import java.io.StringReader; import java.io.StringWriter; import java.util.ArrayList; import java.util.Collections; @@ -29,6 +32,7 @@ import org.apache.maven.model.ActivationOS; import org.apache.maven.model.ActivationProperty; import org.apache.maven.model.building.ModelProblemCollector; import org.apache.maven.model.building.ModelProblemCollectorRequest; +import org.apache.maven.model.path.DefaultPathTranslator; import org.apache.maven.model.profile.DefaultProfileSelector; import org.apache.maven.model.profile.ProfileActivationContext; import org.apache.maven.model.profile.activation.FileProfileActivator; @@ -147,15 +151,47 @@ public class MavenSettings { PrintWriter printer = new PrintWriter(message); printer.println("Failed to determine active profiles:"); for (ModelProblemCollectorRequest problem : problemCollector.getProblems()) { - printer.println( - " " + problem.getMessage() + " at " + problem.getLocation()); + printer.println(" " + problem.getMessage() + (problem.getLocation() != null + ? " at " + problem.getLocation() : "")); + if (problem.getException() != null) { + printer.println(indentStackTrace(problem.getException(), " ")); + } } return message.toString(); } + private String indentStackTrace(Exception ex, String indent) { + return indentLines(printStackTrace(ex), indent); + } + + private String printStackTrace(Exception ex) { + StringWriter stackTrace = new StringWriter(); + PrintWriter printer = new PrintWriter(stackTrace); + ex.printStackTrace(printer); + return stackTrace.toString(); + } + + private String indentLines(String input, String indent) { + StringWriter indented = new StringWriter(); + PrintWriter writer = new PrintWriter(indented); + String line; + BufferedReader reader = new BufferedReader(new StringReader(input)); + try { + while ((line = reader.readLine()) != null) { + writer.println(indent + line); + } + } + catch (IOException ex) { + return input; + } + return indented.toString(); + } + private DefaultProfileSelector createProfileSelector() { DefaultProfileSelector selector = new DefaultProfileSelector(); - selector.addProfileActivator(new FileProfileActivator()); + + selector.addProfileActivator(new FileProfileActivator() + .setPathTranslator(new DefaultPathTranslator())); selector.addProfileActivator(new JdkVersionProfileActivator()); selector.addProfileActivator(new PropertyProfileActivator()); selector.addProfileActivator(new OperatingSystemProfileActivator()); diff --git a/spring-boot-cli/src/test/resources/maven-settings/basic/.m2/settings.xml b/spring-boot-cli/src/test/resources/maven-settings/basic/.m2/settings.xml index b2b97db330..5439ce8cfb 100644 --- a/spring-boot-cli/src/test/resources/maven-settings/basic/.m2/settings.xml +++ b/spring-boot-cli/src/test/resources/maven-settings/basic/.m2/settings.xml @@ -28,4 +28,21 @@ - \ No newline at end of file + + + test-profile + + + ${user.home}/.m2/some_file + + + + + example-repository + http://repo.example.com + + + + + +