Skip to content

Commit

Permalink
Merge pull request #24094 from aloubyansky/pomless-modules
Browse files Browse the repository at this point in the history
Skip modules with no pom.xml during workspace discovery logging a warning
  • Loading branch information
aloubyansky authored Mar 4, 2022
2 parents 3aca34d + 9af90f1 commit 0903444
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.quarkus.bootstrap.resolver.maven.options.BootstrapMavenOptions;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -22,16 +23,25 @@
import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.model.resolution.UnresolvableModelException;
import org.apache.maven.model.resolution.WorkspaceModelResolver;
import org.jboss.logging.Logger;

public class WorkspaceLoader implements WorkspaceModelResolver {

private static final Logger log = Logger.getLogger(WorkspaceLoader.class);

private static final String POM_XML = "pom.xml";

static final Model readModel(Path pom) throws BootstrapMavenException {
try {
final Model model = ModelUtils.readModel(pom);
model.setPomFile(pom.toFile());
return model;
} catch (NoSuchFileException e) {
// some projects may be missing pom.xml relying on Maven extensions (e.g. tycho-maven-plugin) to build them,
// which we don't support in this workspace loader
log.warn("Module(s) under " + pom.getParent() + " will be handled as thirdparty dependencies because " + pom
+ " does not exist");
return null;
} catch (IOException e) {
throw new BootstrapMavenException("Failed to read " + pom, e);
}
Expand Down Expand Up @@ -122,8 +132,14 @@ private LocalProject loadAndCacheProject(Path pomFile) throws BootstrapMavenExce
} catch (Exception e) {
throw new BootstrapMavenException("Failed to resolve the effective model for " + pomFile, e);
}
} else if (cachedRawModel != null) {
project = new LocalProject(cachedRawModel, workspace);
} else {
project = new LocalProject(cachedRawModel == null ? readModel(pomFile) : cachedRawModel, workspace);
Model model = readModel(pomFile);
if (model == null) {
return null;
}
project = new LocalProject(model, workspace);
}
projectCache.put(pomFile.getParent(), project);
return project;
Expand Down Expand Up @@ -152,6 +168,9 @@ private LocalProject loadProject(final Path projectPom, String skipModule) throw
: loadProject(parentPom, parentPom.getParent().relativize(projectPom.getParent()).toString());

final LocalProject project = project(projectPom);
if (project == null) {
return null;
}
if (parentProject != null) {
parentProject.modules.add(project);
}
Expand Down Expand Up @@ -186,7 +205,9 @@ private LocalProject loadProjectModules(LocalProject project, String skipModule)
continue;
}
final LocalProject childProject = project(project.getDir().resolve(module).resolve(POM_XML));
project.modules.add(loadProjectModules(childProject, null));
if (childProject != null) {
project.modules.add(loadProjectModules(childProject, null));
}
}
}
return project;
Expand Down

0 comments on commit 0903444

Please sign in to comment.