Skip to content
Closed
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
3 changes: 2 additions & 1 deletion src/main/java/com/qulice/pmd/PmdValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.File;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Locale;

/**
* Validates source code with PMD.
Expand Down Expand Up @@ -79,7 +80,7 @@ public Collection<File> getNonExcludedFiles(final Collection<File> files) {
if (this.env.exclude("pmd", name)) {
continue;
}
if (!name.matches("^.*\\.java$")) {
if (!name.toLowerCase(Locale.ROOT).endsWith(".java")) {
continue;
}
sources.add(file);
Expand Down
46 changes: 46 additions & 0 deletions src/test/java/com/qulice/pmd/PmdValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.qulice.spi.Environment;
import com.qulice.spi.Violation;
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand All @@ -33,4 +34,49 @@ void findsProblemsInJavaFiles() throws Exception {
Matchers.not(Matchers.<Violation>empty())
);
}

@Test
void acceptsJavaFilesWithUppercaseExtension() throws Exception {
final String file = "src/main/java/Main.JAVA";
final Environment env = new Environment.Mock()
.withFile(file, "class Main { int x = 0; }");
final Collection<File> kept = new PmdValidator(env).getNonExcludedFiles(
Collections.singletonList(new File(env.basedir(), file))
);
MatcherAssert.assertThat(
"Java files with uppercase .JAVA extension should not be skipped",
kept,
Matchers.hasSize(1)
);
}

@Test
void acceptsJavaFilesWithMixedCaseExtension() throws Exception {
final String file = "src/main/java/Main.Java";
final Environment env = new Environment.Mock()
.withFile(file, "class Main { int x = 0; }");
final Collection<File> kept = new PmdValidator(env).getNonExcludedFiles(
Collections.singletonList(new File(env.basedir(), file))
);
MatcherAssert.assertThat(
"Java files with mixed-case .Java extension should not be skipped",
kept,
Matchers.hasSize(1)
);
}

@Test
void skipsFilesThatAreNotJava() throws Exception {
final String file = "src/main/java/notes.txt";
final Environment env = new Environment.Mock()
.withFile(file, "hello");
final Collection<File> kept = new PmdValidator(env).getNonExcludedFiles(
Collections.singletonList(new File(env.basedir(), file))
);
MatcherAssert.assertThat(
"Non-Java files should be skipped",
kept,
Matchers.empty()
);
}
}
Loading