Skip to content
Draft
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 @@ -455,11 +455,12 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
private boolean failIfNoTests;

/**
* Relative path to <i>temporary-surefire-boot</i> directory containing internal Surefire temporary files.
* Path to <i>temporary-surefire-boot</i> directory containing internal Surefire temporary files.
* <br>
* The <i>temporary-surefire-boot</i> directory is <i>project.build.directory</i> on most platforms or
* <i>system default temporary-directory</i> specified by the system property {@code java.io.tmpdir}
* on Windows (see <a href="https://issues.apache.org/jira/browse/SUREFIRE-1400">SUREFIRE-1400</a>).
* Absolute paths and relative paths with directory separators are used as explicit directories on all platforms.
* <br>
* It is deleted after the test set has completed.
*
Expand Down Expand Up @@ -3361,13 +3362,28 @@ File createSurefireBootDirectoryInBuild() {
}

File createSurefireBootDirectoryInTemp() {
String tempDir = getTempDir();
if (isTempDirPath(tempDir)) {
File tmp = new File(tempDir);
if (!tmp.isAbsolute()) {
tmp = new File(getProjectBuildDirectory(), tempDir);
}
//noinspection ResultOfMethodCallIgnored
tmp.mkdirs();
return tmp;
Comment on lines +3366 to +3373
}

try {
return Files.createTempDirectory(getTempDir()).toFile();
} catch (IOException e) {
return Files.createTempDirectory(tempDir).toFile();
} catch (IOException | IllegalArgumentException e) {
return createSurefireBootDirectoryInBuild();
}
}

private static boolean isTempDirPath(String tempDir) {
return new File(tempDir).isAbsolute() || tempDir.indexOf('/') >= 0 || tempDir.indexOf('\\') >= 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure to understand the logic here to say this directory is temporary?
so a path such /home/uid/ is temporary?
can you document you use case?

}

@Override
public String getLocalRepositoryPath() {
return Optional.ofNullable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,21 @@ public void shouldExistTmpDirectory() throws IOException {
.isDirectory();
}

@Test
public void shouldUseAbsoluteTmpDirectory() throws IOException {
File targetDir = Files.createTempDirectory(tempFolder, "target").toFile();
File absoluteTempDir = tempFolder.resolve("surefire-tmp").toFile();

Mojo mojo = new Mojo();
mojo.setProjectBuildDirectory(targetDir);
mojo.setTempDir(absoluteTempDir.getAbsolutePath());

File bootDir = mojo.createSurefireBootDirectoryInTemp();

assertThat(bootDir).isDirectory();
assertThat(bootDir.getCanonicalFile()).isEqualTo(absoluteTempDir.getCanonicalFile());
}

@Test
public void shouldSmartlyResolveJUnit5ProviderWithJUnit4() throws Exception {
MavenProject mavenProject = new MavenProject();
Expand Down
Loading