Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.maven.impl.model;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
Expand Down Expand Up @@ -366,10 +365,14 @@ public DefaultProfileActivationContext setModel(Model model) {

@Override
public String interpolatePath(String path) throws InterpolatorException {
return pathTranslator.alignToBaseDirectory(interpolate(path), model.getProjectDirectory());
}

private String interpolate(String path) throws InterpolatorException {
if (path == null) {
return null;
}
String absolutePath = interpolator.interpolate(path, s -> {
return interpolator.interpolate(path, s -> {
if ("basedir".equals(s) || "project.basedir".equals(s)) {
return getModelBaseDirectory();
}
Expand All @@ -385,7 +388,6 @@ public String interpolatePath(String path) throws InterpolatorException {
}
return r;
});
return pathTranslator.alignToBaseDirectory(absolutePath, model.getProjectDirectory());
}

@Override
Expand All @@ -399,9 +401,10 @@ public boolean exists(String path, boolean enableGlob) throws ModelBuilderExcept
}

private boolean doExists(String path, boolean enableGlob) throws ModelBuilderException {
String pattern = interpolatePath(path);
String fixed, glob;
if (enableGlob) {
// split before aligning to the base directory: '*' and '?' are not valid in a Windows path
String pattern = interpolate(path);
int asteriskIndex = pattern.indexOf('*');
int questionMarkIndex = pattern.indexOf('?');
int firstWildcardIndex = questionMarkIndex < 0
Expand All @@ -411,17 +414,15 @@ private boolean doExists(String path, boolean enableGlob) throws ModelBuilderExc
fixed = pattern;
glob = "";
} else {
int lastSep = pattern.substring(0, firstWildcardIndex).lastIndexOf(File.separatorChar);
if (lastSep < 0) {
fixed = "";
glob = pattern;
} else {
fixed = pattern.substring(0, lastSep);
glob = pattern.substring(lastSep + 1);
}
String prefix = pattern.substring(0, firstWildcardIndex);
int lastSep = Math.max(prefix.lastIndexOf('/'), prefix.lastIndexOf('\\'));
fixed = pattern.substring(0, lastSep + 1);
// '\' is an escape character in the glob syntax, on Windows too, where '/' matches the separator
glob = pattern.substring(lastSep + 1).replace('\\', '/');
}
fixed = pathTranslator.alignToBaseDirectory(fixed, model.getProjectDirectory());
} else {
fixed = pattern;
fixed = interpolatePath(path);
glob = "";
}
Path fixedPath = Paths.get(fixed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,13 @@ void testFileRootDirectory() {
}

@Test
@Disabled
void testFileWilcards() {
assertActivation(true, newProfile("exists('${project.rootDirectory}/**/*.xsd')"), newFileContext());
assertActivation(true, newProfile("exists('${project.basedir}/**/*.xsd')"), newFileContext());
assertActivation(true, newProfile("exists('${project.basedir}/**/*.xsd')"), newFileContext());
assertActivation(true, newProfile("exists('**/*.xsd')"), newFileContext());
assertActivation(true, newProfile("missing('**/*.xml')"), newFileContext());
assertActivation(false, newProfile("missing('${project.basedir}/**/*.xsd')"), newFileContext());
assertActivation(false, newProfile("exists('${project.basedir}/**/*.xml')"), newFileContext());
}

@Test
Expand Down
Loading