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

Option to warn about failures when loading workspace modules, instead of throwing errors #38937

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public class BootstrapConfig {
@ConfigItem(defaultValue = "false")
Boolean workspaceDiscovery;

/**
* If set to true, workspace loader will log warnings for modules that could not be loaded for some reason
* instead of throwing errors.
*/
@ConfigItem(defaultValue = "false")
boolean warnOnFailingWorkspaceModules;

/**
* By default, the bootstrap mechanism will create a shared cache of open JARs for
* Quarkus classloaders to reduce the total number of opened ZIP FileSystems in dev and test modes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class BootstrapMavenContext {
private static final String SETTINGS_SECURITY = "settings.security";

private static final String EFFECTIVE_MODEL_BUILDER_PROP = "quarkus.bootstrap.effective-model-builder";
private static final String WARN_ON_FAILING_WS_MODULES_PROP = "quarkus.bootstrap.warn-on-failing-workspace-modules";

private static final String MAVEN_RESOLVER_TRANSPORT_KEY = "maven.resolver.transport";
private static final String MAVEN_RESOLVER_TRANSPORT_DEFAULT = "default";
Expand All @@ -112,6 +113,11 @@ public class BootstrapMavenContext {
private File userSettings;
private File globalSettings;
private Boolean offline;

// Typically, this property will not be enabled in Quarkus application development use-cases
// It was introduced to support use-cases of using the bootstrap resolver API beyond Quarkus application development
private Boolean warnOnFailingWorkspaceModules;

private LocalWorkspace workspace;
private LocalProject currentProject;
private Settings settings;
Expand Down Expand Up @@ -152,6 +158,7 @@ public BootstrapMavenContext(BootstrapMavenContextConfig<?> config)
this.artifactTransferLogging = config.artifactTransferLogging;
this.localRepo = config.localRepo;
this.offline = config.offline;
this.warnOnFailingWorkspaceModules = config.warnOnFailedWorkspaceModules;
this.repoSystem = config.repoSystem;
this.repoSession = config.repoSession;
this.remoteRepos = config.remoteRepos;
Expand Down Expand Up @@ -273,6 +280,12 @@ public boolean isOffline() throws BootstrapMavenException {
: offline;
}

public boolean isWarnOnFailingWorkspaceModules() {
return warnOnFailingWorkspaceModules == null
? warnOnFailingWorkspaceModules = Boolean.getBoolean(WARN_ON_FAILING_WS_MODULES_PROP)
: warnOnFailingWorkspaceModules;
}

public RepositorySystem getRepositorySystem() throws BootstrapMavenException {
if (repoSystem == null) {
initRepoSystemAndManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class BootstrapMavenContextConfig<T extends BootstrapMavenContextConfig<?
protected Function<Path, Model> modelProvider;
protected List<String> excludeSisuBeanPackages;
protected List<String> includeSisuBeanPackages;
protected Boolean warnOnFailedWorkspaceModules;

public T excludeSisuBeanPackage(String packageName) {
if (excludeSisuBeanPackages == null) {
Expand Down Expand Up @@ -320,6 +321,18 @@ public T setProjectModelProvider(Function<Path, Model> modelProvider) {
return (T) this;
}

/**
* Whether to warn about failures loading workspace modules instead of throwing errors
*
* @param warnOnFailedWorkspaceModules whether to warn about failures loading workspace modules instead of throwing errors
* @return this config instance
*/
@SuppressWarnings("unchecked")
public T setWarnOnFailedWorkspaceModules(boolean warnOnFailedWorkspaceModules) {
this.warnOnFailedWorkspaceModules = warnOnFailedWorkspaceModules;
return (T) this;
}

private BootstrapMavenOptions getInitializedCliOptions() {
return cliOptions == null ? cliOptions = BootstrapMavenOptions.newInstance() : cliOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private static Path locateCurrentProjectPom(Path path) throws BootstrapMavenExce

private final LocalWorkspace workspace = new LocalWorkspace();
private final Path currentProjectPom;
private boolean warnOnFailingWsModules;

private ModelBuilder modelBuilder;
private BootstrapModelResolver modelResolver;
Expand Down Expand Up @@ -94,6 +95,7 @@ private static Path locateCurrentProjectPom(Path path) throws BootstrapMavenExce
}
activeProfileIds.addAll(cliOptions.getActiveProfileIds());
inactiveProfileIds = cliOptions.getInactiveProfileIds();
warnOnFailingWsModules = ctx.isWarnOnFailingWorkspaceModules();
}
workspace.setBootstrapMavenContext(ctx);
}
Expand Down Expand Up @@ -131,10 +133,14 @@ LocalProject load() throws BootstrapMavenException {
req.setProfiles(profiles);
req.setRawModel(rawModel);
req.setWorkspaceModelResolver(this);
LocalProject project;
LocalProject project = null;
try {
project = new LocalProject(modelBuilder.build(req), workspace);
} catch (Exception e) {
if (warnOnFailingWsModules) {
log.warn("Failed to resolve effective model for " + rawModel.getPomFile(), e);
return;
}
throw new RuntimeException("Failed to resolve the effective model for " + rawModel.getPomFile(), e);
}
if (currentProject.get() == null && project.getDir().equals(currentProjectPom.getParent())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,26 @@ public void testBuildDirs() throws Exception {
assertEquals(parentDir.resolve("custom-target").resolve("test-classes"), parent.getTestClassesDir());
}

@Test
public void warnOnFailingWorkspaceModules() throws Exception {
final URL moduleUrl = Thread.currentThread().getContextClassLoader()
.getResource("invalid-module");
assertNotNull(moduleUrl);
final Path moduleDir = Path.of(moduleUrl.toURI());
assertNotNull(moduleUrl);

final LocalWorkspace ws = new BootstrapMavenContext(BootstrapMavenContext.config()
.setOffline(true)
.setEffectiveModelBuilder(true)
.setWarnOnFailedWorkspaceModules(true)
.setCurrentProject(moduleDir.toString()))
.getWorkspace();

assertNotNull(ws.getProject("io.playground", "asm"));
assertNotNull(ws.getProject("io.playground", "module"));
assertEquals(2, ws.getProjects().size());
}

private void testMavenCiFriendlyVersion(String placeholder, String testResourceDirName, String expectedResolvedVersion,
boolean resolvesFromWorkspace) throws Exception {
final URL module1Url = Thread.currentThread().getContextClassLoader()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.playground</groupId>
<artifactId>asm</artifactId>
<version>2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>invalid-module</artifactId>
</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.playground</groupId>
<artifactId>asm</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>module</artifactId>
</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>io.playground</groupId>
<artifactId>asm</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>module</module>
<module>invalid-module</module>
</modules>
</project>

Loading