Skip to content

Commit

Permalink
Return empty list for not existing source root location
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Dec 20, 2023
1 parent b5631da commit 36ead1f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
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());
}
}

0 comments on commit 36ead1f

Please sign in to comment.