diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderRequest.java index b9b3ebed9e..f29d253e4d 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ModelBuilderRequest.java @@ -49,21 +49,26 @@ public interface ModelBuilderRequest { */ enum RequestType { /** - * The request is for building a model from a POM file in a project on the filesystem. + * The request is for building an initial model from a POM file in a project on the filesystem. */ - BUILD_POM, + BUILD_PROJECT, /** - * The request is for building the consumer POM. + * The request is for rebuilding the effective POM in a project on the filesystem. */ - CONSUMER_POM, + BUILD_EFFECTIVE, + /** + * The request is used specifically to parse the POM used as a basis for creating the consumer POM. + * This POM will not ungergo any profile activation. + */ + BUILD_CONSUMER, /** * The request is for building a model from a parent POM file from a downloaded artifact. */ - PARENT_POM, + CONSUMER_PARENT, /** * The request is for building a model from a dependency POM file from a downloaded artifact. */ - DEPENDENCY + CONSUMER_DEPENDENCY } /** diff --git a/impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java b/impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java index 265dabdcd7..138fc8c11d 100644 --- a/impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java +++ b/impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java @@ -21,14 +21,9 @@ package org.apache.maven.internal.transformation.impl; import javax.inject.Inject; import javax.inject.Named; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.stream.Collectors; import org.apache.maven.api.SessionData; @@ -44,7 +39,6 @@ import org.apache.maven.api.services.ModelBuilderException; import org.apache.maven.api.services.ModelBuilderRequest; import org.apache.maven.api.services.ModelBuilderResult; import org.apache.maven.api.services.ModelSource; -import org.apache.maven.api.services.Source; import org.apache.maven.api.services.model.LifecycleBindingsInjector; import org.apache.maven.internal.impl.InternalSession; import org.apache.maven.model.v4.MavenModelVersion; @@ -95,10 +89,9 @@ class DefaultConsumerPomBuilder implements ConsumerPomBuilder { throws ModelBuilderException { InternalSession iSession = InternalSession.from(session); ModelBuilderRequest.ModelBuilderRequestBuilder request = ModelBuilderRequest.builder(); - request.requestType(ModelBuilderRequest.RequestType.CONSUMER_POM); + request.requestType(ModelBuilderRequest.RequestType.BUILD_CONSUMER); request.session(iSession); - // in order to resolve parents, we need to fake being at the correct location - request.source(new PomConsumerModelSource(project.getModel().getPomPath(), src)); + request.source(ModelSource.fromPath(src)); request.locationTracking(false); request.systemProperties(session.getSystemProperties()); request.userProperties(session.getUserProperties()); @@ -208,63 +201,4 @@ class DefaultConsumerPomBuilder implements ConsumerPomBuilder { .filter(r -> !org.apache.maven.api.Repository.CENTRAL_ID.equals(r.getId())) .collect(Collectors.toList()); } - - static class PomConsumerModelSource implements ModelSource { - final Path path; - final Path src; - - PomConsumerModelSource(Path path, Path src) { - this.path = path; - this.src = src; - } - - @Override - public Path getPath() { - return path; - } - - @Override - public InputStream openStream() throws IOException { - return Files.newInputStream(src); - } - - @Override - public String getLocation() { - return src.toString(); - } - - @Override - public Source resolve(String relative) { - return ModelSource.fromPath(path.resolve(relative)); - } - - @Override - public ModelSource resolve(ModelLocator locator, String relative) { - String norm = relative.replace('\\', File.separatorChar).replace('/', File.separatorChar); - Path path = getPath().getParent().resolve(norm); - Path relatedPom = locator.locateExistingPom(path); - if (relatedPom != null) { - return ModelSource.fromPath(relatedPom); - } - return null; - } - - @Override - public boolean equals(Object o) { - return this == o - || o.getClass() == getClass() - && Objects.equals(path, ((PomConsumerModelSource) o).path) - && Objects.equals(src, ((PomConsumerModelSource) o).src); - } - - @Override - public int hashCode() { - return Objects.hash(path, src); - } - - @Override - public String toString() { - return "PomConsumerModelSource[" + "path=" + path + ']'; - } - } } diff --git a/impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 9de384e9e6..c473f43774 100644 --- a/impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -351,8 +351,8 @@ public class DefaultProjectBuilder implements ProjectBuilder { ModelBuilderRequest.RequestType type = pomFile != null && this.request.isProcessPlugins() && this.request.getValidationLevel() == ModelBuildingRequest.VALIDATION_LEVEL_STRICT - ? ModelBuilderRequest.RequestType.BUILD_POM - : ModelBuilderRequest.RequestType.PARENT_POM; + ? ModelBuilderRequest.RequestType.BUILD_EFFECTIVE + : ModelBuilderRequest.RequestType.CONSUMER_PARENT; MavenProject theProject = project; ModelBuilderRequest request = builder.source(modelSource) .requestType(type) @@ -489,7 +489,7 @@ public class DefaultProjectBuilder implements ProjectBuilder { }; ModelBuilderRequest modelBuildingRequest = getModelBuildingRequest() .source(ModelSource.fromPath(pomFile.toPath())) - .requestType(ModelBuilderRequest.RequestType.BUILD_POM) + .requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT) .locationTracking(true) .recursive(recursive) .lifecycleBindingsInjector(injector) @@ -780,7 +780,7 @@ public class DefaultProjectBuilder implements ProjectBuilder { InternalSession internalSession = InternalSession.from(session); modelBuildingRequest.session(internalSession); - modelBuildingRequest.requestType(ModelBuilderRequest.RequestType.BUILD_POM); + modelBuildingRequest.requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT); modelBuildingRequest.profiles( request.getProfiles() != null ? request.getProfiles().stream() @@ -913,7 +913,7 @@ public class DefaultProjectBuilder implements ProjectBuilder { } project.setPluginArtifactRepositories(pluginRepositories); - if (request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_POM) { + if (request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_PROJECT) { try { ProjectRealmCache.CacheRecord record = projectBuildingHelper.createProjectRealm(project, model3, projectBuildingRequest); diff --git a/impl/maven-core/src/test/java/org/apache/maven/internal/transformation/impl/ConsumerPomBuilderTest.java b/impl/maven-core/src/test/java/org/apache/maven/internal/transformation/impl/ConsumerPomBuilderTest.java index 510d5d6196..4b25258210 100644 --- a/impl/maven-core/src/test/java/org/apache/maven/internal/transformation/impl/ConsumerPomBuilderTest.java +++ b/impl/maven-core/src/test/java/org/apache/maven/internal/transformation/impl/ConsumerPomBuilderTest.java @@ -77,7 +77,7 @@ public class ConsumerPomBuilderTest extends AbstractRepositoryTestCase { Model orgModel = mbs.build(ModelBuilderRequest.builder() .session(InternalSession.from(session)) .source(ModelSource.fromPath(file)) - .requestType(ModelBuilderRequest.RequestType.BUILD_POM) + .requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT) .build()) .getEffectiveModel(); @@ -103,7 +103,7 @@ public class ConsumerPomBuilderTest extends AbstractRepositoryTestCase { Model orgModel = mbs.build(ModelBuilderRequest.builder() .session(InternalSession.from(session)) .source(ModelSource.fromPath(file)) - .requestType(ModelBuilderRequest.RequestType.BUILD_POM) + .requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT) .build()) .getEffectiveModel(); diff --git a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java index c403bacd94..95a364bdd1 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelBuilder.java @@ -200,40 +200,42 @@ public class DefaultModelBuilder implements ModelBuilder { } public ModelBuilderSession newSession() { - return new ModelBuilderSession() { - DefaultModelBuilderSession mainSession; - - /** - * Builds a model based on the provided ModelBuilderRequest. - * - * @param request The request containing the parameters for building the model. - * @return The result of the model building process. - * @throws ModelBuilderException If an error occurs during model building. - */ - @Override - public ModelBuilderResult build(ModelBuilderRequest request) throws ModelBuilderException { - // Create or derive a session based on the request - DefaultModelBuilderSession session; - if (mainSession == null) { - mainSession = new DefaultModelBuilderSession(request); - session = mainSession; - } else { - session = mainSession.derive(request, new DefaultModelBuilderResult()); - } - // Build the request - if (request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_POM) { - // build the build poms - session.buildBuildPom(); - } else { - // simply build the effective model - session.buildEffectiveModel(new LinkedHashSet<>()); - } - return session.result; - } - }; + return new ModelBuilderSessionImpl(); } - protected class DefaultModelBuilderSession implements ModelProblemCollector { + protected class ModelBuilderSessionImpl implements ModelBuilderSession { + ModelBuilderSessionState mainSession; + + /** + * Builds a model based on the provided ModelBuilderRequest. + * + * @param request The request containing the parameters for building the model. + * @return The result of the model building process. + * @throws ModelBuilderException If an error occurs during model building. + */ + @Override + public ModelBuilderResult build(ModelBuilderRequest request) throws ModelBuilderException { + // Create or derive a session based on the request + ModelBuilderSessionState session; + if (mainSession == null) { + mainSession = new ModelBuilderSessionState(request); + session = mainSession; + } else { + session = mainSession.derive(request, new DefaultModelBuilderResult()); + } + // Build the request + if (request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_PROJECT) { + // build the build poms + session.buildBuildPom(); + } else { + // simply build the effective model + session.buildEffectiveModel(new LinkedHashSet<>()); + } + return session.result; + } + } + + protected class ModelBuilderSessionState implements ModelProblemCollector { private static final Pattern REGEX = Pattern.compile("\\$\\{([^}]+)}"); final Session session; @@ -251,7 +253,7 @@ public class DefaultModelBuilder implements ModelBuilder { List externalRepositories; List repositories; - DefaultModelBuilderSession(ModelBuilderRequest request) { + ModelBuilderSessionState(ModelBuilderRequest request) { this( request.getSession(), request, @@ -274,7 +276,7 @@ public class DefaultModelBuilder implements ModelBuilder { } @SuppressWarnings("checkstyle:ParameterNumber") - private DefaultModelBuilderSession( + private ModelBuilderSessionState( Session session, ModelBuilderRequest request, DefaultModelBuilderResult result, @@ -296,26 +298,26 @@ public class DefaultModelBuilder implements ModelBuilder { this.result.setSource(this.request.getSource()); } - DefaultModelBuilderSession derive(ModelSource source) { + ModelBuilderSessionState derive(ModelSource source) { return derive(source, new DefaultModelBuilderResult(result)); } - DefaultModelBuilderSession derive(ModelSource source, DefaultModelBuilderResult result) { + ModelBuilderSessionState derive(ModelSource source, DefaultModelBuilderResult result) { return derive(ModelBuilderRequest.build(request, source), result); } /** * Creates a new session, sharing cached datas and propagating errors. */ - DefaultModelBuilderSession derive(ModelBuilderRequest request) { + ModelBuilderSessionState derive(ModelBuilderRequest request) { return derive(request, new DefaultModelBuilderResult(result)); } - DefaultModelBuilderSession derive(ModelBuilderRequest request, DefaultModelBuilderResult result) { + ModelBuilderSessionState derive(ModelBuilderRequest request, DefaultModelBuilderResult result) { if (session != request.getSession()) { throw new IllegalArgumentException("Session mismatch"); } - return new DefaultModelBuilderSession( + return new ModelBuilderSessionState( session, request, result, @@ -669,7 +671,7 @@ public class DefaultModelBuilder implements ModelBuilder { try (PhasingExecutor executor = createExecutor()) { for (DefaultModelBuilderResult r : allResults) { executor.execute(() -> { - DefaultModelBuilderSession mbs = derive(r.getSource(), r); + ModelBuilderSessionState mbs = derive(r.getSource(), r); try { mbs.buildEffectiveModel(new LinkedHashSet<>()); } catch (ModelBuilderException e) { @@ -815,7 +817,7 @@ public class DefaultModelBuilder implements ModelBuilder { resultModel = pluginManagementInjector.injectManagement(resultModel, request, this); // lifecycle bindings injection - if (request.getRequestType() != ModelBuilderRequest.RequestType.DEPENDENCY) { + if (request.getRequestType() != ModelBuilderRequest.RequestType.CONSUMER_DEPENDENCY) { org.apache.maven.api.services.ModelTransformer lifecycleBindingsInjector = request.getLifecycleBindingsInjector(); if (lifecycleBindingsInjector != null) { @@ -831,7 +833,7 @@ public class DefaultModelBuilder implements ModelBuilder { resultModel = modelNormalizer.injectDefaultValues(resultModel, request, this); - if (request.getRequestType() != ModelBuilderRequest.RequestType.DEPENDENCY) { + if (request.getRequestType() != ModelBuilderRequest.RequestType.CONSUMER_DEPENDENCY) { // plugins configuration resultModel = pluginConfigurationExpander.expandPluginConfiguration(resultModel, request, this); } @@ -853,9 +855,7 @@ public class DefaultModelBuilder implements ModelBuilder { // effective model validation modelValidator.validateEffectiveModel( resultModel, - request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_POM - ? ModelValidator.VALIDATION_LEVEL_STRICT - : ModelValidator.VALIDATION_LEVEL_MINIMAL, + isBuildRequest() ? ModelValidator.VALIDATION_LEVEL_STRICT : ModelValidator.VALIDATION_LEVEL_MINIMAL, request, this); @@ -896,8 +896,7 @@ public class DefaultModelBuilder implements ModelBuilder { private Model resolveParent(Model childModel) { Model parentModel = null; - if (request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_POM - || request.getRequestType() == ModelBuilderRequest.RequestType.CONSUMER_POM) { + if (isBuildRequest()) { parentModel = readParentLocally(childModel); } if (parentModel == null) { @@ -911,18 +910,30 @@ public class DefaultModelBuilder implements ModelBuilder { Parent parent = childModel.getParent(); String parentPath = parent.getRelativePath(); - if (parentPath != null && !parentPath.isEmpty()) { - candidateSource = request.getSource().resolve(modelProcessor::locateExistingPom, parentPath); - if (candidateSource == null) { - wrongParentRelativePath(childModel); - return null; + if (request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_PROJECT) { + if (parentPath != null && !parentPath.isEmpty()) { + candidateSource = request.getSource().resolve(modelProcessor::locateExistingPom, parentPath); + if (candidateSource == null) { + wrongParentRelativePath(childModel); + return null; + } + } else { + candidateSource = + resolveReactorModel(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()); + if (candidateSource == null && parentPath == null) { + candidateSource = request.getSource().resolve(modelProcessor::locateExistingPom, ".."); + } } - } - if (candidateSource == null) { + } else { candidateSource = resolveReactorModel(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()); - } - if (candidateSource == null && parentPath == null) { - candidateSource = request.getSource().resolve(modelProcessor::locateExistingPom, ".."); + if (candidateSource == null) { + if (parentPath == null) { + parentPath = ".."; + } + if (!parentPath.isEmpty()) { + candidateSource = request.getSource().resolve(modelProcessor::locateExistingPom, parentPath); + } + } } if (candidateSource == null) { @@ -1056,7 +1067,7 @@ public class DefaultModelBuilder implements ModelBuilder { buffer.append(" for ").append(ModelProblemUtils.toId(childModel)); } buffer.append(": ").append(e.getMessage()); - if (request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_POM) { + if (request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_PROJECT) { buffer.append(" and parent could not be found in reactor"); } @@ -1065,7 +1076,7 @@ public class DefaultModelBuilder implements ModelBuilder { } ModelBuilderRequest lenientRequest = ModelBuilderRequest.builder(request) - .requestType(ModelBuilderRequest.RequestType.PARENT_POM) + .requestType(ModelBuilderRequest.RequestType.CONSUMER_PARENT) .source(modelSource) .build(); @@ -1163,13 +1174,13 @@ public class DefaultModelBuilder implements ModelBuilder { // path correctly if it was not set in the input model if (inputModel.getParent() != null && inputModel.getParent().getRelativePath() == null) { String relPath; - if (parentModel.getPomFile() != null - && (request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_POM - || request.getRequestType() == ModelBuilderRequest.RequestType.CONSUMER_POM)) { + if (parentModel.getPomFile() != null && isBuildRequest()) { relPath = inputModel .getPomFile() .getParent() - .relativize(parentModel.getPomFile().getParent()) + .toAbsolutePath() + .relativize( + parentModel.getPomFile().toAbsolutePath().getParent()) .toString(); } else { relPath = ".."; @@ -1232,7 +1243,7 @@ public class DefaultModelBuilder implements ModelBuilder { private List getActiveProfiles( Collection interpolatedProfiles, DefaultProfileActivationContext profileActivationContext) { - if (request.getRequestType() != ModelBuilderRequest.RequestType.CONSUMER_POM) { + if (isBuildRequestWithActivation()) { return profileSelector.getActiveProfiles(interpolatedProfiles, profileActivationContext, this); } else { return List.of(); @@ -1254,7 +1265,7 @@ public class DefaultModelBuilder implements ModelBuilder { setSource(modelSource.getLocation()); logger.debug("Reading file model from " + modelSource.getLocation()); try { - boolean strict = request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_POM; + boolean strict = isBuildRequest(); try { rootDirectory = request.getSession().getRootDirectory(); } catch (IllegalStateException ignore) { @@ -1335,8 +1346,7 @@ public class DefaultModelBuilder implements ModelBuilder { } } - if (request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_POM - || request.getRequestType() == ModelBuilderRequest.RequestType.CONSUMER_POM) { + if (isBuildRequest()) { model = model.withPomFile(modelSource.getPath()); Parent parent = model.getParent(); @@ -1437,9 +1447,7 @@ public class DefaultModelBuilder implements ModelBuilder { setSource(model); modelValidator.validateFileModel( model, - request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_POM - ? ModelValidator.VALIDATION_LEVEL_STRICT - : ModelValidator.VALIDATION_LEVEL_MINIMAL, + isBuildRequest() ? ModelValidator.VALIDATION_LEVEL_STRICT : ModelValidator.VALIDATION_LEVEL_MINIMAL, request, this); if (hasFatalErrors()) { @@ -1459,12 +1467,9 @@ public class DefaultModelBuilder implements ModelBuilder { } private Model doReadRawModel() throws ModelBuilderException { - ModelBuilderRequest request = this.request; Model rawModel = readFileModel(); - if (!MODEL_VERSION_4_0_0.equals(rawModel.getModelVersion()) - && (request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_POM - || request.getRequestType() == ModelBuilderRequest.RequestType.CONSUMER_POM)) { + if (!MODEL_VERSION_4_0_0.equals(rawModel.getModelVersion()) && isBuildRequest()) { rawModel = transformFileToRaw(rawModel); } @@ -1474,9 +1479,7 @@ public class DefaultModelBuilder implements ModelBuilder { modelValidator.validateRawModel( rawModel, - request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_POM - ? ModelValidator.VALIDATION_LEVEL_STRICT - : ModelValidator.VALIDATION_LEVEL_MINIMAL, + isBuildRequest() ? ModelValidator.VALIDATION_LEVEL_STRICT : ModelValidator.VALIDATION_LEVEL_MINIMAL, request, this); @@ -1679,7 +1682,7 @@ public class DefaultModelBuilder implements ModelBuilder { } catch (IllegalStateException e) { rootDirectory = null; } - if (request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_POM && rootDirectory != null) { + if (request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_PROJECT && rootDirectory != null) { Path sourcePath = importSource.getPath(); if (sourcePath != null && sourcePath.startsWith(rootDirectory)) { add( @@ -1694,13 +1697,13 @@ public class DefaultModelBuilder implements ModelBuilder { try { ModelBuilderRequest importRequest = ModelBuilderRequest.builder() .session(request.getSession()) - .requestType(ModelBuilderRequest.RequestType.DEPENDENCY) + .requestType(ModelBuilderRequest.RequestType.CONSUMER_DEPENDENCY) .systemProperties(request.getSystemProperties()) .userProperties(request.getUserProperties()) .source(importSource) .repositories(repositories) .build(); - DefaultModelBuilderSession modelBuilderSession = derive(importRequest); + ModelBuilderSessionState modelBuilderSession = derive(importRequest); // build the effective model modelBuilderSession.buildEffectiveModel(importIds); importResult = modelBuilderSession.result; @@ -1738,6 +1741,16 @@ public class DefaultModelBuilder implements ModelBuilder { return cache.computeIfAbsent(source, tag, supplier); } + boolean isBuildRequest() { + return request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_PROJECT + || request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_EFFECTIVE + || request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_CONSUMER; + } + + boolean isBuildRequestWithActivation() { + return request.getRequestType() != ModelBuilderRequest.RequestType.BUILD_CONSUMER; + } + private List interpolateActivations( List profiles, DefaultProfileActivationContext context, ModelProblemCollector problems) { if (profiles.stream() @@ -1816,7 +1829,7 @@ public class DefaultModelBuilder implements ModelBuilder { } public Model buildRawModel(ModelBuilderRequest request) throws ModelBuilderException { - DefaultModelBuilderSession build = new DefaultModelBuilderSession(request); + ModelBuilderSessionState build = new ModelBuilderSessionState(request); Model model = build.readRawModel(); if (((ModelProblemCollector) build).hasErrors()) { throw build.newModelBuilderException(); diff --git a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelInterpolator.java b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelInterpolator.java index 927ed72f35..c15e34380c 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelInterpolator.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelInterpolator.java @@ -123,7 +123,7 @@ public class DefaultModelInterpolator implements ModelInterpolator { } protected List getProjectPrefixes(ModelBuilderRequest request) { - return request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_POM + return request.getRequestType() == ModelBuilderRequest.RequestType.BUILD_PROJECT ? PROJECT_PREFIXES_4_0 : PROJECT_PREFIXES_3_1; } diff --git a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/resolver/DefaultArtifactDescriptorReader.java b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/resolver/DefaultArtifactDescriptorReader.java index 82bae431cf..29d7b5439d 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/resolver/DefaultArtifactDescriptorReader.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/resolver/DefaultArtifactDescriptorReader.java @@ -194,7 +194,7 @@ public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader pomArtifact.getGroupId() + ":" + pomArtifact.getArtifactId() + ":" + pomArtifact.getVersion(); ModelBuilderRequest modelRequest = ModelBuilderRequest.builder() .session(iSession) - .requestType(ModelBuilderRequest.RequestType.DEPENDENCY) + .requestType(ModelBuilderRequest.RequestType.CONSUMER_DEPENDENCY) .source(ModelSource.fromPath(pomArtifact.getPath(), gav)) // This merge is on purpose because otherwise user properties would override model // properties in dependencies the user does not know. See MNG-7563 for details. diff --git a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/ComplexActivationTest.java b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/ComplexActivationTest.java index 3a7c5130df..df86fcc956 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/ComplexActivationTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/ComplexActivationTest.java @@ -56,7 +56,7 @@ class ComplexActivationTest { void testAndConditionInActivation() throws Exception { ModelBuilderRequest request = ModelBuilderRequest.builder() .session(session) - .requestType(ModelBuilderRequest.RequestType.BUILD_POM) + .requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT) .source(ModelSource.fromPath(getPom("complex"))) .systemProperties(Map.of("myproperty", "test")) .build(); @@ -71,7 +71,7 @@ class ComplexActivationTest { public void testConditionExistingAndMissingInActivation() throws Exception { ModelBuilderRequest request = ModelBuilderRequest.builder() .session(session) - .requestType(ModelBuilderRequest.RequestType.BUILD_POM) + .requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT) .source(ModelSource.fromPath(getPom("complexExistsAndMissing"))) .build(); ModelBuilderResult result = builder.newSession().build(request); diff --git a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/standalone/TestApiStandalone.java b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/standalone/TestApiStandalone.java index d6a6f29f1e..646ee273e0 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/standalone/TestApiStandalone.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/standalone/TestApiStandalone.java @@ -47,7 +47,7 @@ class TestApiStandalone { .build(ModelBuilderRequest.builder() .session(session) .source(ModelSource.fromPath(Paths.get("pom.xml").toAbsolutePath())) - .requestType(ModelBuilderRequest.RequestType.BUILD_POM) + .requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT) .recursive(true) .build()); assertNotNull(result.getEffectiveModel()); diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8340GeneratedPomInTargetTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8340GeneratedPomInTargetTest.java new file mode 100644 index 0000000000..f3d10b3315 --- /dev/null +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng8340GeneratedPomInTargetTest.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.it; + +import java.io.File; +import java.util.List; + +import org.apache.maven.shared.verifier.Verifier; +import org.apache.maven.shared.verifier.util.ResourceExtractor; +import org.junit.jupiter.api.Test; + +/** + * This is a test set for MNG-8340. + */ +class MavenITmng8340GeneratedPomInTargetTest extends AbstractMavenIntegrationTestCase { + + MavenITmng8340GeneratedPomInTargetTest() { + super("[3.8.6,4.0.0-beta-5),[4.0.0-beta-6,)"); + } + + /** + * Verify that the build succeeds. + */ + @Test + void testProjectWithShadePluginAndGeneratedPomUnderTarget() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-8340"); + + Verifier verifier = newVerifier(testDir.getAbsolutePath()); + verifier.addCliArgument("install"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + List l = verifier.loadLines(verifier.getLogFileName(), "UTF-8"); + assertFalse(l.stream() + .anyMatch(i -> i.contains( + "[FATAL] 'parent.relativePath' points at '../../pom.xml' but no POM could be found"))); + } +} diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java index e864606d7b..4bf5b649eb 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java @@ -120,6 +120,7 @@ public class TestSuiteOrdering implements ClassOrderer { * the tests are to finishing. Newer tests are also more likely to fail, so this is * a fail fast technique as well. */ + suite.addTestSuite(MavenITmng8340GeneratedPomInTargetTest.class); suite.addTestSuite(MavenITmng8360SubprojectProfileActivationTest.class); suite.addTestSuite(MavenITmng8347TransitiveDependencyManagerTest.class); suite.addTestSuite(MavenITmng8341DeadlockTest.class); diff --git a/its/core-it-suite/src/test/resources/mng-8340/.mvn/.gitkeep b/its/core-it-suite/src/test/resources/mng-8340/.mvn/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/its/core-it-suite/src/test/resources/mng-8340/child1/pom.xml b/its/core-it-suite/src/test/resources/mng-8340/child1/pom.xml new file mode 100644 index 0000000000..be68873dd6 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8340/child1/pom.xml @@ -0,0 +1,42 @@ + + + + 4.0.0 + + org.apache.maven.it.mng8340 + root + 1.0.0 + + + child1 + + + + org.slf4j + slf4j-api + 2.0.16 + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.5.0 + + + shade + + shade + + package + + ${basedir}/target/dr-pom.xml + + + + + + + diff --git a/its/core-it-suite/src/test/resources/mng-8340/child2/pom.xml b/its/core-it-suite/src/test/resources/mng-8340/child2/pom.xml new file mode 100644 index 0000000000..defeefc3c5 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8340/child2/pom.xml @@ -0,0 +1,21 @@ + + + + 4.0.0 + + org.apache.maven.it.mng8340 + root + 1.0.0 + + + child2 + + + + org.apache.maven.it.mng8340 + child1 + ${project.version} + + + + diff --git a/its/core-it-suite/src/test/resources/mng-8340/pom.xml b/its/core-it-suite/src/test/resources/mng-8340/pom.xml new file mode 100644 index 0000000000..2a04859db9 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-8340/pom.xml @@ -0,0 +1,15 @@ + + + + 4.0.0 + + org.apache.maven.it.mng8340 + root + 1.0.0 + pom + + + child1 + child2 + +