Skip to content

Commit

Permalink
Daemons should not swallow any exception (#969)
Browse files Browse the repository at this point in the history
The "happy path" should happen without anything thrown, unsure why here runtime ex is rethrown, others swallowed.

Change: just remove the try/catch and make method throw Exception (diff best seen with whitespace ignored).

Fixes #957
Fixes #966
  • Loading branch information
cstamas authored Apr 23, 2024
1 parent 9bafc4b commit a6dbd07
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 111 deletions.
104 changes: 48 additions & 56 deletions daemon-m39/src/main/java/org/apache/maven/cli/DaemonMavenCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -717,64 +717,56 @@ protected void configure() {
}

private List<CoreExtensionEntry> loadCoreExtensions(
List<CoreExtension> extensions, ClassRealm containerRealm, Set<String> providedArtifacts) {
try {
if (extensions.isEmpty()) {
return Collections.emptyList();
}
ContainerConfiguration cc = new DefaultContainerConfiguration() //
.setClassWorld(classWorld) //
.setRealm(containerRealm) //
.setClassPathScanning(PlexusConstants.SCANNING_INDEX) //
.setAutoWiring(true) //
.setJSR250Lifecycle(true) //
.setName("maven");

DefaultPlexusContainer container = new DefaultPlexusContainer(cc, new AbstractModule() {
@Override
protected void configure() {
bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
}
});
MavenExecutionRequestPopulator executionRequestPopulator = null;
try {
CliRequest cliRequest = new CliRequest(new String[0], classWorld);
cliRequest.commandLine = new CommandLine.Builder().build();
container.setLookupRealm(null);
container.setLoggerManager(plexusLoggerManager);
container.getLoggerManager().setThresholds(cliRequest.request.getLoggingLevel());
Thread.currentThread().setContextClassLoader(container.getContainerRealm());
executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
final Map<String, ConfigurationProcessor> configurationProcessors =
container.lookupMap(ConfigurationProcessor.class);
final EventSpyDispatcher eventSpyDispatcher = container.lookup(EventSpyDispatcher.class);
properties(cliRequest);
configure(cliRequest, eventSpyDispatcher, configurationProcessors);
LoggingExecutionListener executionListener = container.lookup(LoggingExecutionListener.class);
populateRequest(
cliRequest,
cliRequest.request,
slf4jLogger,
eventSpyDispatcher,
container.lookup(ModelProcessor.class),
createTransferListener(cliRequest),
buildEventListener,
executionListener);
executionRequestPopulator.populateDefaults(cliRequest.request);
BootstrapCoreExtensionManager resolver = container.lookup(BootstrapCoreExtensionManager.class);
return Collections.unmodifiableList(
resolver.loadCoreExtensions(cliRequest.request, providedArtifacts, extensions));
} finally {
executionRequestPopulator = null;
container.dispose();
List<CoreExtension> extensions, ClassRealm containerRealm, Set<String> providedArtifacts) throws Exception {
if (extensions.isEmpty()) {
return Collections.emptyList();
}
ContainerConfiguration cc = new DefaultContainerConfiguration() //
.setClassWorld(classWorld) //
.setRealm(containerRealm) //
.setClassPathScanning(PlexusConstants.SCANNING_INDEX) //
.setAutoWiring(true) //
.setJSR250Lifecycle(true) //
.setName("maven");

DefaultPlexusContainer container = new DefaultPlexusContainer(cc, new AbstractModule() {
@Override
protected void configure() {
bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
}
} catch (RuntimeException e) {
// runtime exceptions are most likely bugs in maven, let them bubble up to the user
throw e;
} catch (Exception e) {
slf4jLogger.warn("Failed to load extensions descriptor {}: {}", extensions, e.getMessage());
});
MavenExecutionRequestPopulator executionRequestPopulator = null;
try {
CliRequest cliRequest = new CliRequest(new String[0], classWorld);
cliRequest.commandLine = new CommandLine.Builder().build();
container.setLookupRealm(null);
container.setLoggerManager(plexusLoggerManager);
container.getLoggerManager().setThresholds(cliRequest.request.getLoggingLevel());
Thread.currentThread().setContextClassLoader(container.getContainerRealm());
executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
final Map<String, ConfigurationProcessor> configurationProcessors =
container.lookupMap(ConfigurationProcessor.class);
final EventSpyDispatcher eventSpyDispatcher = container.lookup(EventSpyDispatcher.class);
properties(cliRequest);
configure(cliRequest, eventSpyDispatcher, configurationProcessors);
LoggingExecutionListener executionListener = container.lookup(LoggingExecutionListener.class);
populateRequest(
cliRequest,
cliRequest.request,
slf4jLogger,
eventSpyDispatcher,
container.lookup(ModelProcessor.class),
createTransferListener(cliRequest),
buildEventListener,
executionListener);
executionRequestPopulator.populateDefaults(cliRequest.request);
BootstrapCoreExtensionManager resolver = container.lookup(BootstrapCoreExtensionManager.class);
return Collections.unmodifiableList(
resolver.loadCoreExtensions(cliRequest.request, providedArtifacts, extensions));
} finally {
executionRequestPopulator = null;
container.dispose();
}
return Collections.emptyList();
}

private ClassRealm setupContainerRealm(
Expand Down
102 changes: 47 additions & 55 deletions daemon-m40/src/main/java/org/apache/maven/cli/DaemonMavenCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -642,63 +642,55 @@ public Object getValue(String expression) {
}

private List<CoreExtensionEntry> loadCoreExtensions(
List<CoreExtension> extensions, ClassRealm containerRealm, Set<String> providedArtifacts) {
try {
if (extensions.isEmpty()) {
return Collections.emptyList();
}
ContainerConfiguration cc = new DefaultContainerConfiguration() //
.setClassWorld(classWorld) //
.setRealm(containerRealm) //
.setClassPathScanning(PlexusConstants.SCANNING_INDEX) //
.setAutoWiring(true) //
.setJSR250Lifecycle(true) //
.setName("maven");

DefaultPlexusContainer container = new DefaultPlexusContainer(cc, new AbstractModule() {
@Override
protected void configure() {
bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
}
});
MavenExecutionRequestPopulator executionRequestPopulator = null;
try {
CliRequest cliRequest = new CliRequest(new String[0], classWorld);
cliRequest.commandLine = new CommandLine.Builder().build();
container.setLookupRealm(null);
container.setLoggerManager(plexusLoggerManager);
container.getLoggerManager().setThresholds(cliRequest.request.getLoggingLevel());
Thread.currentThread().setContextClassLoader(container.getContainerRealm());
executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
final Map<String, ConfigurationProcessor> configurationProcessors =
container.lookupMap(ConfigurationProcessor.class);
final EventSpyDispatcher eventSpyDispatcher = container.lookup(EventSpyDispatcher.class);
properties(cliRequest);
configure(cliRequest, eventSpyDispatcher, configurationProcessors);
LoggingExecutionListener executionListener = container.lookup(LoggingExecutionListener.class);
populateRequest(
cliRequest,
cliRequest.request,
eventSpyDispatcher,
container.lookup(ModelProcessor.class),
createTransferListener(cliRequest),
buildEventListener,
executionListener);
executionRequestPopulator.populateDefaults(cliRequest.request);
BootstrapCoreExtensionManager resolver = container.lookup(BootstrapCoreExtensionManager.class);
return Collections.unmodifiableList(
resolver.loadCoreExtensions(cliRequest.request, providedArtifacts, extensions));
} finally {
executionRequestPopulator = null;
container.dispose();
List<CoreExtension> extensions, ClassRealm containerRealm, Set<String> providedArtifacts) throws Exception {
if (extensions.isEmpty()) {
return Collections.emptyList();
}
ContainerConfiguration cc = new DefaultContainerConfiguration() //
.setClassWorld(classWorld) //
.setRealm(containerRealm) //
.setClassPathScanning(PlexusConstants.SCANNING_INDEX) //
.setAutoWiring(true) //
.setJSR250Lifecycle(true) //
.setName("maven");

DefaultPlexusContainer container = new DefaultPlexusContainer(cc, new AbstractModule() {
@Override
protected void configure() {
bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
}
} catch (RuntimeException e) {
// runtime exceptions are most likely bugs in maven, let them bubble up to the user
throw e;
} catch (Exception e) {
slf4jLogger.warn("Failed to load extensions descriptor {}: {}", extensions, e.getMessage());
});
MavenExecutionRequestPopulator executionRequestPopulator = null;
try {
CliRequest cliRequest = new CliRequest(new String[0], classWorld);
cliRequest.commandLine = new CommandLine.Builder().build();
container.setLookupRealm(null);
container.setLoggerManager(plexusLoggerManager);
container.getLoggerManager().setThresholds(cliRequest.request.getLoggingLevel());
Thread.currentThread().setContextClassLoader(container.getContainerRealm());
executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
final Map<String, ConfigurationProcessor> configurationProcessors =
container.lookupMap(ConfigurationProcessor.class);
final EventSpyDispatcher eventSpyDispatcher = container.lookup(EventSpyDispatcher.class);
properties(cliRequest);
configure(cliRequest, eventSpyDispatcher, configurationProcessors);
LoggingExecutionListener executionListener = container.lookup(LoggingExecutionListener.class);
populateRequest(
cliRequest,
cliRequest.request,
eventSpyDispatcher,
container.lookup(ModelProcessor.class),
createTransferListener(cliRequest),
buildEventListener,
executionListener);
executionRequestPopulator.populateDefaults(cliRequest.request);
BootstrapCoreExtensionManager resolver = container.lookup(BootstrapCoreExtensionManager.class);
return Collections.unmodifiableList(
resolver.loadCoreExtensions(cliRequest.request, providedArtifacts, extensions));
} finally {
executionRequestPopulator = null;
container.dispose();
}
return Collections.emptyList();
}

private ClassRealm setupContainerRealm(
Expand Down

0 comments on commit a6dbd07

Please sign in to comment.