Skip to content

Commit 00b9f13

Browse files
committed
[MPMD-379] Simplify language selection in CpdExecutor
1 parent f9449bc commit 00b9f13

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
import net.sourceforge.pmd.cpd.SimpleRenderer;
4040
import net.sourceforge.pmd.cpd.XMLRenderer;
4141
import net.sourceforge.pmd.lang.Language;
42-
import net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule;
43-
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
44-
import net.sourceforge.pmd.lang.jsp.JspLanguageModule;
4542
import org.apache.maven.plugin.MojoExecutionException;
4643
import org.apache.maven.plugins.pmd.ExcludeDuplicationsFromFile;
4744
import org.apache.maven.reporting.MavenReportException;
@@ -156,16 +153,13 @@ private CpdResult run() throws MavenReportException {
156153
cpdConfiguration.setIgnoreLiterals(request.isIgnoreLiterals());
157154
cpdConfiguration.setIgnoreIdentifiers(request.isIgnoreIdentifiers());
158155

159-
Language cpdLanguage;
160-
if ("java".equals(request.getLanguage()) || null == request.getLanguage()) {
161-
cpdLanguage = new JavaLanguageModule();
162-
} else if ("javascript".equals(request.getLanguage())) {
163-
cpdLanguage = new EcmascriptLanguageModule();
164-
} else if ("jsp".equals(request.getLanguage())) {
165-
cpdLanguage = new JspLanguageModule();
166-
} else {
167-
cpdLanguage = cpdConfiguration.getLanguageRegistry().getLanguageById(request.getLanguage());
156+
String languageId = request.getLanguage();
157+
if ("javascript".equals(languageId)) {
158+
languageId = "ecmascript";
159+
} else if (languageId == null) {
160+
languageId = "java"; // default
168161
}
162+
Language cpdLanguage = cpdConfiguration.getLanguageRegistry().getLanguageById(languageId);
169163

170164
cpdConfiguration.setOnlyRecognizeLanguage(cpdLanguage);
171165
cpdConfiguration.setSourceEncoding(Charset.forName(request.getSourceEncoding()));
@@ -191,7 +185,7 @@ private CpdResult run() throws MavenReportException {
191185
}
192186
});
193187
} catch (IOException e) {
194-
LOG.error(e.getMessage(), e);
188+
LOG.error("Error while executing CPD: {}", e.getMessage(), e);
195189
}
196190
LOG.debug("CPD finished.");
197191

0 commit comments

Comments
 (0)