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 @@ -21,7 +21,6 @@
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamException;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
Expand Down Expand Up @@ -128,11 +127,13 @@ public SettingsBuilderResult build(SettingsBuilderRequest request) throws Settin
.build();
}

// for the special case of a drive-relative Windows path, make sure it's absolute to save plugins from trouble
// resolve relative local repository paths to absolute to save plugins from trouble.
// paths containing property placeholders like ${user.home} must be left as-is
// so that later interpolation can resolve them.
String localRepository = effective.getLocalRepository();
if (localRepository != null && !localRepository.isEmpty()) {
Path file = Paths.get(localRepository);
if (!file.isAbsolute() && file.toString().startsWith(File.separator)) {
if (!file.isAbsolute() && !localRepository.contains("${")) {
effective = effective.withLocalRepository(file.toAbsolutePath().toString());
}
}
Comment on lines 133 to 139
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -160,6 +161,17 @@ void testSettingsWithDuplicateServersIds() throws Exception {
problems.problems().findFirst().orElseThrow().getMessage());
}

@Test
void testRelativeLocalRepositoryIsResolvedToAbsolute() {
Settings settings = execute("settings-relative-local-repo").getEffectiveSettings();

String localRepository = settings.getLocalRepository();
assertNotNull(localRepository);
assertFalse(localRepository.isEmpty());
Path repoPath = Paths.get(localRepository);
assertTrue(repoPath.isAbsolute(), "Relative local repository should be resolved to absolute");
}
Comment on lines +164 to +173

private Path getSettings(String name) {
return Paths.get("src/test/resources/settings/" + name + ".xml").toAbsolutePath();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns='http://maven.apache.org/SETTINGS/1.0.0'>
<localRepository>relative/repo</localRepository>
</settings>
Loading