Skip to content

Commit 0db62a1

Browse files
committed
Improve MavenClasspathEntry Error Handling
Closes gh-66
1 parent a236aab commit 0db62a1

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

spring-boot-testjars-maven/src/main/java/org/springframework/experimental/boot/server/exec/MavenClasspathEntry.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.eclipse.aether.impl.DefaultServiceLocator;
4040
import org.eclipse.aether.repository.LocalRepository;
4141
import org.eclipse.aether.repository.RemoteRepository;
42+
import org.eclipse.aether.resolution.ArtifactDescriptorPolicy;
4243
import org.eclipse.aether.resolution.ArtifactResult;
4344
import org.eclipse.aether.resolution.DependencyRequest;
4445
import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
@@ -47,6 +48,7 @@
4748
import org.eclipse.aether.transport.http.HttpTransporterFactory;
4849
import org.eclipse.aether.util.artifact.JavaScopes;
4950
import org.eclipse.aether.util.filter.DependencyFilterUtils;
51+
import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy;
5052

5153
import org.springframework.boot.SpringBootVersion;
5254

@@ -144,9 +146,9 @@ public List<String> resolve() {
144146
}
145147
}
146148
catch (Exception ex) {
147-
if (this.logger.isErrorEnabled()) {
148-
this.logger.error("Error resolving artifact " + this.coords, ex);
149-
}
149+
String message = "Error resolving artifact " + this.coords;
150+
this.logger.debug(message, ex);
151+
throw new RuntimeException(message, ex);
150152
}
151153
return result;
152154
}
@@ -188,6 +190,8 @@ private static DefaultRepositorySystemSession newRepositorySystemSession(Reposit
188190
session.setSystemProperties(sysProps);
189191
session.setConfigProperties(sysProps);
190192

193+
SimpleArtifactDescriptorPolicy policy = new SimpleArtifactDescriptorPolicy(ArtifactDescriptorPolicy.STRICT);
194+
session.setArtifactDescriptorPolicy(policy);
191195

192196
// uncomment to generate dirty trees
193197
// session.setDependencyGraphTransformer( null );

spring-boot-testjars/src/main/java/org/springframework/experimental/boot/server/exec/CommonsExecWebServer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.apache.commons.exec.DefaultExecutor;
2525
import org.apache.commons.exec.ExecuteException;
2626
import org.apache.commons.exec.ExecuteResultHandler;
27+
import org.apache.commons.logging.Log;
28+
import org.apache.commons.logging.LogFactory;
2729

2830
import org.springframework.beans.factory.DisposableBean;
2931
import org.springframework.beans.factory.InitializingBean;
@@ -41,6 +43,8 @@
4143
*/
4244
public final class CommonsExecWebServer implements WebServer, InitializingBean, DisposableBean, AutoCloseable {
4345

46+
private final Log logger = LogFactory.getLog(getClass());
47+
4448
private final CommandLine commandLine;
4549

4650
private final File applicationPortFile;
@@ -78,6 +82,9 @@ public void start() {
7882
DefaultExecutor executor = new DefaultExecutor();
7983
executor.setProcessDestroyer(this.processDestroyerBean);
8084
try {
85+
if (this.logger.isDebugEnabled()) {
86+
this.logger.debug("Executing command: " + this.commandLine);
87+
}
8188
executor.execute(this.commandLine, null, this.handler);
8289
}
8390
catch (Exception ex) {

spring-boot-testjars/src/main/java/org/springframework/experimental/boot/server/exec/ResourceClasspathEntry.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public List<String> resolve() {
6565
}
6666
}
6767
catch (IOException ex) {
68-
throw new RuntimeException(ex);
68+
throw new RuntimeException("Failed to copy existingResourceName '" + this.existingResourceName
69+
+ "' to '" + this.classpathResourceName + "'", ex);
6970
}
7071
}
7172
return Arrays.asList(this.classpath.toFile().getAbsolutePath());

spring-boot-testjars/src/main/java/org/springframework/experimental/boot/server/exec/ScanningClasspathEntry.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import java.util.function.Function;
2525
import java.util.regex.Pattern;
2626

27+
import org.apache.commons.logging.Log;
28+
import org.apache.commons.logging.LogFactory;
29+
2730
import org.springframework.core.io.ClassPathResource;
2831
import org.springframework.core.io.FileSystemResource;
2932
import org.springframework.core.io.Resource;
@@ -37,6 +40,8 @@
3740
*/
3841
class ScanningClasspathEntry implements ClasspathEntry {
3942

43+
private Log logger = LogFactory.getLog(getClass());
44+
4045
private final String resourcePattern;
4146

4247
private final Function<String, String> renameResource;
@@ -80,6 +85,9 @@ private Path createClasspath() {
8085
if (!path.endsWith("/") && resource.isReadable()) {
8186
Path destination = classpath.resolve(path);
8287
destination.getParent().toFile().mkdirs();
88+
if (this.logger.isDebugEnabled()) {
89+
this.logger.debug("Copying " + path + " to " + destination);
90+
}
8391
Files.copy(resource.getInputStream(), destination);
8492
}
8593
}

0 commit comments

Comments
 (0)