Skip to content

Commit

Permalink
Support flattened poms
Browse files Browse the repository at this point in the history
When using the `flatten-maven-plugin`, the POM file resolves to `PROJECT_DIR/target/.flattened-pom.xml`, which makes calls to `pomFile.getParent()` return the `target/` directory

- Fixes quarkusio#34764
  • Loading branch information
gastaldi committed Jul 15, 2023
1 parent e3037ba commit a7695c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static LocalProject load(Path path, boolean required) throws BootstrapMav
return null;
}
try {
return new LocalProject(readModel(pom), null);
return new LocalProject(readModel(pom), null, null);
} catch (UnresolvedVersionException e) {
// if a property in the version couldn't be resolved, we are trying to resolve it from the workspace
return loadWorkspace(pom);
Expand Down Expand Up @@ -165,10 +165,10 @@ static Path locateCurrentProjectPom(Path path, boolean required) throws Bootstra
}
}

LocalProject(Model rawModel, LocalWorkspace workspace) throws BootstrapMavenException {
LocalProject(Model rawModel, LocalWorkspace workspace, Path projectDirectory) throws BootstrapMavenException {
this.modelBuildingResult = null;
this.rawModel = rawModel;
this.dir = rawModel.getProjectDirectory().toPath();
this.dir = (projectDirectory != null) ? projectDirectory : rawModel.getProjectDirectory().toPath();
this.workspace = workspace;
this.key = ArtifactKey.ga(ModelUtils.getGroupId(rawModel), rawModel.getArtifactId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ private LocalProject loadAndCacheProject(Path pomFile) throws BootstrapMavenExce
throw new BootstrapMavenException("Failed to resolve the effective model for " + pomFile, e);
}
} else {
project = new LocalProject(rawModel, workspace);
project = new LocalProject(rawModel, workspace, resolveProjectPath(pomFile));
}
projectCache.put(pomFile.getParent(), project);
projectCache.put(resolveProjectPath(pomFile), project);
return project;
}

Expand Down Expand Up @@ -272,6 +272,13 @@ public Model resolveEffectiveModel(String groupId, String artifactId, String ver
: null;
}

private Path resolveProjectPath(Path pomFile) {
if (pomFile.endsWith("target/.flattened-pom.xml")) {
return pomFile.getParent().getParent().toAbsolutePath();
}
return pomFile.getParent().toAbsolutePath();
}

@Override
public WorkspaceRepository getRepository() {
return workspace.getRepository();
Expand Down

0 comments on commit a7695c2

Please sign in to comment.