Post merge fix (the profile condition activation missed some reshuffle of project layout) (#1933)

This commit is contained in:
Tamas Cservenak 2024-11-22 10:48:50 +01:00 committed by GitHub
parent a55accd518
commit 9bea6ec23b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 23 additions and 8 deletions

View File

@ -119,6 +119,11 @@ under the License.
<artifactId>junit-jupiter-api</artifactId> <artifactId>junit-jupiter-api</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>

View File

@ -48,7 +48,7 @@ public class DefaultRootLocator implements RootLocator {
@Override @Override
public Path findRoot(Path basedir) { public Path findRoot(Path basedir) {
requireNonNull(basedir, "basedir is null"); requireNonNull(basedir, getNoRootMessage());
Path rootDirectory = basedir; Path rootDirectory = basedir;
while (rootDirectory != null && !isRootDirectory(rootDirectory)) { while (rootDirectory != null && !isRootDirectory(rootDirectory)) {
rootDirectory = rootDirectory.getParent(); rootDirectory = rootDirectory.getParent();

View File

@ -18,6 +18,7 @@
*/ */
package org.apache.maven.internal.impl.model.profile; package org.apache.maven.internal.impl.model.profile;
import java.nio.file.Path;
import java.util.Properties; import java.util.Properties;
import org.apache.maven.api.model.Model; import org.apache.maven.api.model.Model;
@ -25,6 +26,7 @@ import org.apache.maven.api.model.Profile;
import org.apache.maven.api.services.model.ProfileActivationContext; import org.apache.maven.api.services.model.ProfileActivationContext;
import org.apache.maven.api.services.model.ProfileActivator; import org.apache.maven.api.services.model.ProfileActivator;
import org.apache.maven.internal.impl.model.DefaultProfileActivationContext; import org.apache.maven.internal.impl.model.DefaultProfileActivationContext;
import org.apache.maven.internal.impl.model.rootlocator.DefaultRootLocator;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -35,6 +37,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
* *
*/ */
public abstract class AbstractProfileActivatorTest<T extends ProfileActivator> { public abstract class AbstractProfileActivatorTest<T extends ProfileActivator> {
static class FakeRootLocator extends DefaultRootLocator {
@Override
protected boolean isRootDirectory(Path dir) {
return true;
}
}
protected T activator; protected T activator;

View File

@ -29,9 +29,9 @@ import org.apache.maven.internal.impl.DefaultVersionParser;
import org.apache.maven.internal.impl.model.DefaultInterpolator; import org.apache.maven.internal.impl.model.DefaultInterpolator;
import org.apache.maven.internal.impl.model.DefaultPathTranslator; import org.apache.maven.internal.impl.model.DefaultPathTranslator;
import org.apache.maven.internal.impl.model.DefaultProfileActivationContext; import org.apache.maven.internal.impl.model.DefaultProfileActivationContext;
import org.apache.maven.internal.impl.model.DefaultRootLocator;
import org.apache.maven.internal.impl.model.ProfileActivationFilePathInterpolator; import org.apache.maven.internal.impl.model.ProfileActivationFilePathInterpolator;
import org.apache.maven.internal.impl.model.profile.ConditionParser.ExpressionFunction; import org.apache.maven.internal.impl.model.profile.ConditionParser.ExpressionFunction;
import org.apache.maven.internal.impl.model.rootlocator.DefaultRootLocator;
import org.eclipse.aether.util.version.GenericVersionScheme; import org.eclipse.aether.util.version.GenericVersionScheme;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -53,7 +53,9 @@ class ConditionParserTest {
DefaultVersionParser versionParser = DefaultVersionParser versionParser =
new DefaultVersionParser(new DefaultModelVersionParser(new GenericVersionScheme())); new DefaultVersionParser(new DefaultModelVersionParser(new GenericVersionScheme()));
ProfileActivationFilePathInterpolator interpolator = new ProfileActivationFilePathInterpolator( ProfileActivationFilePathInterpolator interpolator = new ProfileActivationFilePathInterpolator(
new DefaultPathTranslator(), bd -> true, new DefaultInterpolator()); new DefaultPathTranslator(),
new AbstractProfileActivatorTest.FakeRootLocator(),
new DefaultInterpolator());
DefaultRootLocator rootLocator = new DefaultRootLocator(); DefaultRootLocator rootLocator = new DefaultRootLocator();
functions = ConditionProfileActivator.registerFunctions(context, versionParser, interpolator); functions = ConditionProfileActivator.registerFunctions(context, versionParser, interpolator);

View File

@ -33,8 +33,8 @@ import org.apache.maven.internal.impl.DefaultVersionParser;
import org.apache.maven.internal.impl.model.DefaultInterpolator; import org.apache.maven.internal.impl.model.DefaultInterpolator;
import org.apache.maven.internal.impl.model.DefaultPathTranslator; import org.apache.maven.internal.impl.model.DefaultPathTranslator;
import org.apache.maven.internal.impl.model.DefaultProfileActivationContext; import org.apache.maven.internal.impl.model.DefaultProfileActivationContext;
import org.apache.maven.internal.impl.model.DefaultRootLocator;
import org.apache.maven.internal.impl.model.ProfileActivationFilePathInterpolator; import org.apache.maven.internal.impl.model.ProfileActivationFilePathInterpolator;
import org.apache.maven.internal.impl.model.rootlocator.DefaultRootLocator;
import org.eclipse.aether.util.version.GenericVersionScheme; import org.eclipse.aether.util.version.GenericVersionScheme;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
@ -57,7 +57,7 @@ public class ConditionProfileActivatorTest extends AbstractProfileActivatorTest<
activator = new ConditionProfileActivator( activator = new ConditionProfileActivator(
new DefaultVersionParser(new DefaultModelVersionParser(new GenericVersionScheme())), new DefaultVersionParser(new DefaultModelVersionParser(new GenericVersionScheme())),
new ProfileActivationFilePathInterpolator( new ProfileActivationFilePathInterpolator(
new DefaultPathTranslator(), bd -> true, new DefaultInterpolator()), new DefaultPathTranslator(), new FakeRootLocator(), new DefaultInterpolator()),
new DefaultRootLocator()); new DefaultRootLocator());
Path file = tempDir.resolve("file.txt"); Path file = tempDir.resolve("file.txt");

View File

@ -53,7 +53,7 @@ class FileProfileActivatorTest extends AbstractProfileActivatorTest<FileProfileA
@Override @Override
void setUp() throws Exception { void setUp() throws Exception {
activator = new FileProfileActivator(new ProfileActivationFilePathInterpolator( activator = new FileProfileActivator(new ProfileActivationFilePathInterpolator(
new DefaultPathTranslator(), bd -> true, new DefaultInterpolator())); new DefaultPathTranslator(), new FakeRootLocator(), new DefaultInterpolator()));
context.setModel(Model.newBuilder().pomFile(tempDir.resolve("pom.xml")).build()); context.setModel(Model.newBuilder().pomFile(tempDir.resolve("pom.xml")).build());
@ -67,8 +67,8 @@ class FileProfileActivatorTest extends AbstractProfileActivatorTest<FileProfileA
void testRootDirectoryWithNull() { void testRootDirectoryWithNull() {
context.setModel(Model.newInstance()); context.setModel(Model.newInstance());
IllegalStateException e = assertThrows( NullPointerException e = assertThrows(
IllegalStateException.class, NullPointerException.class,
() -> assertActivation(false, newExistsProfile("${project.rootDirectory}"), context)); () -> assertActivation(false, newExistsProfile("${project.rootDirectory}"), context));
assertEquals(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE, e.getMessage()); assertEquals(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE, e.getMessage());
} }