Skip to content

Return empty list for not existing source root location #338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2023
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 @@ -25,6 +25,7 @@
*/
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -145,10 +146,14 @@ public static String getPathString(List<String> pathElements) {
}

protected static Set<String> getSourceFilesForSourceRoot(CompilerConfiguration config, String sourceLocation) {
DirectoryScanner scanner = new DirectoryScanner();

DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(sourceLocation);

if (!scanner.getBasedir().exists()) {
return Collections.emptySet();
}

Set<String> includes = config.getIncludes();

if (includes != null && !includes.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.codehaus.plexus.compiler;

import java.io.File;
import java.util.Set;

import org.junit.jupiter.api.Test;

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

class AbstractCompilerTest {

@Test
void getSourceFilesForSourceRootShouldReturnEmptyForNotExistingLocation() {

CompilerConfiguration config = new CompilerConfiguration();
File fileLocation = new File("non/existing/location").getAbsoluteFile();

assertFalse(fileLocation.exists());

Set<String> sourcesFile = AbstractCompiler.getSourceFilesForSourceRoot(config, fileLocation.getAbsolutePath());

assertTrue(sourcesFile.isEmpty());
}
}