Skip to content

Commit

Permalink
Post merge fix (the profile condition activation missed some reshuffl…
Browse files Browse the repository at this point in the history
…e of project layout) (#1933)
  • Loading branch information
cstamas authored Nov 22, 2024
1 parent a55accd commit 9bea6ec
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions impl/maven-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ under the License.
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public DefaultRootLocator() {

@Override
public Path findRoot(Path basedir) {
requireNonNull(basedir, "basedir is null");
requireNonNull(basedir, getNoRootMessage());
Path rootDirectory = basedir;
while (rootDirectory != null && !isRootDirectory(rootDirectory)) {
rootDirectory = rootDirectory.getParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
*/
package org.apache.maven.internal.impl.model.profile;

import java.nio.file.Path;
import java.util.Properties;

import org.apache.maven.api.model.Model;
import org.apache.maven.api.model.Profile;
import org.apache.maven.api.services.model.ProfileActivationContext;
import org.apache.maven.api.services.model.ProfileActivator;
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.BeforeEach;

Expand All @@ -35,6 +37,12 @@
*
*/
public abstract class AbstractProfileActivatorTest<T extends ProfileActivator> {
static class FakeRootLocator extends DefaultRootLocator {
@Override
protected boolean isRootDirectory(Path dir) {
return true;
}
}

protected T activator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import org.apache.maven.internal.impl.model.DefaultInterpolator;
import org.apache.maven.internal.impl.model.DefaultPathTranslator;
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.profile.ConditionParser.ExpressionFunction;
import org.apache.maven.internal.impl.model.rootlocator.DefaultRootLocator;
import org.eclipse.aether.util.version.GenericVersionScheme;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -53,7 +53,9 @@ void setUp() {
DefaultVersionParser versionParser =
new DefaultVersionParser(new DefaultModelVersionParser(new GenericVersionScheme()));
ProfileActivationFilePathInterpolator interpolator = new ProfileActivationFilePathInterpolator(
new DefaultPathTranslator(), bd -> true, new DefaultInterpolator());
new DefaultPathTranslator(),
new AbstractProfileActivatorTest.FakeRootLocator(),
new DefaultInterpolator());
DefaultRootLocator rootLocator = new DefaultRootLocator();

functions = ConditionProfileActivator.registerFunctions(context, versionParser, interpolator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import org.apache.maven.internal.impl.model.DefaultInterpolator;
import org.apache.maven.internal.impl.model.DefaultPathTranslator;
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.rootlocator.DefaultRootLocator;
import org.eclipse.aether.util.version.GenericVersionScheme;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
Expand All @@ -57,7 +57,7 @@ void setUp() throws Exception {
activator = new ConditionProfileActivator(
new DefaultVersionParser(new DefaultModelVersionParser(new GenericVersionScheme())),
new ProfileActivationFilePathInterpolator(
new DefaultPathTranslator(), bd -> true, new DefaultInterpolator()),
new DefaultPathTranslator(), new FakeRootLocator(), new DefaultInterpolator()),
new DefaultRootLocator());

Path file = tempDir.resolve("file.txt");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class FileProfileActivatorTest extends AbstractProfileActivatorTest<FileProfileA
@Override
void setUp() throws Exception {
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());

Expand All @@ -67,8 +67,8 @@ void setUp() throws Exception {
void testRootDirectoryWithNull() {
context.setModel(Model.newInstance());

IllegalStateException e = assertThrows(
IllegalStateException.class,
NullPointerException e = assertThrows(
NullPointerException.class,
() -> assertActivation(false, newExistsProfile("${project.rootDirectory}"), context));
assertEquals(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE, e.getMessage());
}
Expand Down

0 comments on commit 9bea6ec

Please sign in to comment.