org.gradle.api.plugins.quality.PmdPlugin Maven / Gradle / Ivy
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.api.plugins.quality;
import com.google.common.util.concurrent.Callables;
import org.gradle.api.Action;
import org.gradle.api.JavaVersion;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.ConventionMapping;
import org.gradle.api.plugins.quality.internal.AbstractCodeQualityPlugin;
import org.gradle.api.reporting.SingleFileReport;
import org.gradle.api.resources.TextResource;
import org.gradle.api.tasks.SourceSet;
import org.gradle.util.VersionNumber;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
/**
* A plugin for the PMD source code analyzer.
*
* Declares a pmd configuration which needs to be configured with the PMD library to be used.
*
* For each source set that is to be analyzed, a {@link Pmd} task is created and configured to analyze all Java code.
*
* All PMD tasks (including user-defined ones) are added to the check lifecycle task.
*
* @see PmdExtension
* @see Pmd
*/
public class PmdPlugin extends AbstractCodeQualityPlugin {
public static final String DEFAULT_PMD_VERSION = "5.5.1";
private PmdExtension extension;
@Override
protected String getToolName() {
return "PMD";
}
@Override
protected Class getTaskType() {
return Pmd.class;
}
@Override
protected CodeQualityExtension createExtension() {
extension = project.getExtensions().create("pmd", PmdExtension.class, project);
extension.setToolVersion(DEFAULT_PMD_VERSION);
extension.setRuleSets(new ArrayList(Arrays.asList("java-basic")));
extension.setRuleSetFiles(project.files());
conventionMappingOf(extension).map("targetJdk", new Callable