Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daemons should not swallow any exception #969

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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