Coder Social home page Coder Social logo

andrewhunter0 / gradle-cpd-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aaschmid/gradle-cpd-plugin

0.0 1.0 0.0 248 KB

Gradle plugin to find duplicate code using PMDs copy/paste detection (= CPD).

License: Apache License 2.0

Groovy 86.19% Java 13.81%

gradle-cpd-plugin's Introduction

Build Status Coverage Status Download license Issues Forks Stars

Gradle CPD plugin

Table of Contents

What is it

A Gradle plugin to find duplicate code using PMDs copy/paste detection (= CPD).

Requirements

Currently this plugin requires PMD greater or equal to version 5.2 such that toolVersion >= v5.2.0.

Explaination: As PMDs source code and artifacts were modularized into modules for every language with v5.2.0 (see Changelog - 5.2.0) this plugin uses the 'pmd-dist' dependency by default. This dependency further includes 'pmd-core', 'pmd-java', 'pmd-cpp', ... transitively. This also forces proper working of toolVersion to PMD v5.2.0 and higher. If you want to use a version prior to v5.2.0, you can use the following snipped

dependencies {
    cpd 'net.sourceforge.pmd:pmd:5.0.5'
}

Usage

This plugin is available using either the new Gradle plugins DSL

plugins {
    id 'de.aaschmid.cpd' version '1.0'
}

or the old fashion buildscript block from Maven Central or jCenter.

buildscript {
    repositories {
        // choose your prefered one
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath 'de.aaschmid:gradle-cpd-plugin:1.0'
    }
}
apply plugin: 'cpd'

Attention: The plugins groupId was changed from de.aaschmid.gradle.plugins to de.aaschmid in v1.0.

By default the copy-paste-detection looks at all source code of all projects which at least apply JavaBasePlugin. If you use a different programming language and want to get it configurated out of the box, please open an issue :-)

Single module project

If you have a single module project you just need to make sure that the JavaBasePlugin is also applied to it (explicitly or implicitly through e.g. Java or Groovy plugin). Otherwise you can simply add a dependency to a task you like by

analyze.dependsOn(cpdCheck)

Multi module project

If the root project of your multi-module project applies the JavaBasePlugin, you are done. But most likely this is not how your project looks like. If so, you need to manually add a task graph dependency manually to either one or all of your subprojects such that the cpdCheck task is executed:

// one single subproject where 'JavaBasePlugin' is available
subprojectOne.check.dependsOn(':cpdCheck')

// all subprojects where 'check' task is available (which comes with 'JavaBasePlugin')
subprojects {
    plugins.withType(JavaBasePlugin) { // <- just if 'JavaBasePlugin' plugin is not applied to all subprojects
        check.dependsOn(rootProject.cpdCheck)
    }
}

Examples

This example shows a project where only main sources should be checked for duplicates:

// optional - settings for every CPD task
cpd {
    language = 'cpp'
    toolVersion = '5.2.3' // defaults to '5.4.2'; just available for v5.2.0 and higher (see explanation above)
}

// optional - default report is xml and default sources are 'main' and 'test'
cpdCheck {
    reports {
        text.enabled = true
        xml.enabled = false
    }
    source = sourceSets.main.allJava // only java, groovy and scala classes in 'main' sourceSets
}

Note: With v0.2, I have renamed the default task from cpd to cpdCheck that it does not have a name clash anymore.

Options

This plugin supports the following options, either set for the plugin using cpd { } or for every task explicitly, e.g. using cpdCheck { }:

Attribute Default Applies for language since
encoding System default v0.1
ignoreAnnotations false 'java' v0.4
ignoreFailures false v0.1
ignoreIdentifiers false 'java' v0.4
ignoreLiterals false 'java' v0.4
language 'java' v0.4
minimumTokenCount 50 v0.1
skipDuplicateFiles false v0.5
skipLexicalErrors false v0.5
skipBlocks true 'cpp' v0.4
skipBlocksPattern ```'#if 0 #endif'``` 'cpp'

For more information about options and their descriptions, see here, and for the available programming languages have a look on CPD documentation. To request more options, please file an issue here.

Additionally, one can configure the following reports for every task analogous to Reporting as for any other reporting plugin. See also the example in Usage section above.

Report Default Further options and their defaults
csv disabled separator = ','
text disabled lineSeparator = '=====================================================================', trimLeadingCommonSourceWhitespaces = false
xml enabled encoding = <<System default>>

Contributing

You are very welcome to contribute by providing a patch/pull request.

Please note that running the test cases my take quite long becuase the acceptance test cases (see de.aaschmid.gradle.plugins.cpd.test.CpdAcceptanceTest will download CPD and its dependencies for every version. I recommend to get these dependencies in your localMaven() repository as the test cases look there for it first.

gradle-cpd-plugin's People

Contributors

aaschmid avatar prestontim avatar

Watchers

andrewhunter avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.