diff --git a/README.md b/README.md index bd694e5..0c59805 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,10 @@ Advanced features: * [Merging check signatures](https://github.com/xvik/gradle-animalsniffer-plugin/wiki/Library-signatures) (when small 3rd party lib signatures are used) * [Viewing signature content task](https://github.com/xvik/gradle-animalsniffer-plugin/wiki/View-signature-content) +Used by: +* [Mockito](https://github.com/mockito/mockito/blob/main/build.gradle#L101) for java and android compatibility checks +* [Okhttp](https://github.com/square/okhttp/blob/master/build.gradle.kts#L126) for java and android compatibility checks (using kotlin multiplatform) + #### Applicability If you're using JDK 9 or above then you can use the [--release](https://docs.oracle.com/en/java/javase/11/tools/javac.html#GUID-AEEC9F07-CB49-4E96-8BC7-BCC2C7F725C9) @@ -82,6 +86,14 @@ plugins { } ``` +Example projects (with intentional errors to see output): + +* [Java](examples/java) (including android signatures) +* [Groovy](examples/groovy) +* [Kotlin](examples/kotlin) +* [Scala](examples/scala) +* [Signature build examples](examples/buildSignature) + #### Compatibility **IMPORTANT**: Plugin only works when `java`-related plugin (`java-library`, `groovy`, `scala`, `org.jetbrains.kotlin.jvm`) is enabled, diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..ba1d03f --- /dev/null +++ b/examples/README.md @@ -0,0 +1,12 @@ +# AnimalSniffer plugin usage examples + +All projects intentionally contain errors to demonstrate error reporting + +* [Java](java) +* [Groovy](groovy) +* [Kotlin](kotlin) +* [Scala](scala) + +[Java](java) example shows also validation with android signature (would be the same for other examples) + +[Build signature examples](buildSignature) \ No newline at end of file diff --git a/examples/build.gradle b/examples/build.gradle new file mode 100644 index 0000000..30c225b --- /dev/null +++ b/examples/build.gradle @@ -0,0 +1,3 @@ +wrapper { + gradleVersion = '7.6' +} \ No newline at end of file diff --git a/examples/buildSignature/README.md b/examples/buildSignature/README.md new file mode 100644 index 0000000..eb6fc1a --- /dev/null +++ b/examples/buildSignature/README.md @@ -0,0 +1,10 @@ +# Signature creation examples + +Examples of building custom signature files for checks + +* [Classes](fromClasses) - signature from project classes +* [Jars](fromJars) - signature from project jars (configuration) +* [Signatures](fromSignatures) - signature from other signatures +* [Mixed](fromMix) - signature from different sources + +See [wiki for more details](https://github.com/xvik/gradle-animalsniffer-plugin/wiki/Library-signatures) \ No newline at end of file diff --git a/examples/buildSignature/fromClasses/README.md b/examples/buildSignature/fromClasses/README.md new file mode 100644 index 0000000..0718001 --- /dev/null +++ b/examples/buildSignature/fromClasses/README.md @@ -0,0 +1,25 @@ +# Signatures build from project classes + +``` +> Task :buildSignature:fromClasses:compileJava +> Task :buildSignature:fromClasses:processResources NO-SOURCE +> Task :buildSignature:fromClasses:classes +> Task :buildSignature:fromClasses:jar +> Task :buildSignature:fromClasses:assemble +> Task :buildSignature:fromClasses:animalsnifferMain UP-TO-DATE +> Task :buildSignature:fromClasses:compileTestJava NO-SOURCE +> Task :buildSignature:fromClasses:processTestResources NO-SOURCE +> Task :buildSignature:fromClasses:testClasses UP-TO-DATE +> Task :buildSignature:fromClasses:animalsnifferTest NO-SOURCE +> Task :buildSignature:fromClasses:test NO-SOURCE +> Task :buildSignature:fromClasses:check UP-TO-DATE +> Task :buildSignature:fromClasses:animalsnifferSignature + +> Task :buildSignature:fromClasses:printSignature +Signature mySignature.sig (286.0 bytes) contains 1 classes + sample 1 + +> Task :buildSignature:fromClasses:build + +BUILD SUCCESSFUL in 369ms +``` \ No newline at end of file diff --git a/examples/buildSignature/fromClasses/build.gradle b/examples/buildSignature/fromClasses/build.gradle new file mode 100644 index 0000000..cf04825 --- /dev/null +++ b/examples/buildSignature/fromClasses/build.gradle @@ -0,0 +1,25 @@ +plugins { + id 'java' + id 'ru.vyarus.animalsniffer' version '1.6.0' +} + +animalsnifferSignature { +// debug = true + // signature from project classes + files sourceSets.main.output + // by default project name + outputName 'mySignature' +} + +repositories { mavenCentral()} +dependencies { + implementation "org.codehaus.mojo:animal-sniffer-annotations:1.14" + implementation 'org.slf4j:slf4j-api:1.7.25' +} + +tasks.register('printSignature', ru.vyarus.gradle.plugin.animalsniffer.info.SignatureInfoTask) { + signature = tasks.animalsnifferSignature.outputFiles + depth = 2 +} + +tasks.build.dependsOn 'printSignature' \ No newline at end of file diff --git a/examples/buildSignature/fromClasses/src/main/java/sample/Sample.java b/examples/buildSignature/fromClasses/src/main/java/sample/Sample.java new file mode 100644 index 0000000..af364b4 --- /dev/null +++ b/examples/buildSignature/fromClasses/src/main/java/sample/Sample.java @@ -0,0 +1,16 @@ +package sample; + +import org.slf4j.LoggerFactory; + +public class Sample { + + private String sample; + + public Sample(String sample) { + this.sample = sample; + } + + public static void main(String[] args) { + LoggerFactory.getLogger(Sample.class); + } +} \ No newline at end of file diff --git a/examples/buildSignature/fromJars/README.md b/examples/buildSignature/fromJars/README.md new file mode 100644 index 0000000..2392295 --- /dev/null +++ b/examples/buildSignature/fromJars/README.md @@ -0,0 +1,31 @@ +# Signatures build from project jars + +``` +> Task :buildSignature:fromJars:compileJava NO-SOURCE +> Task :buildSignature:fromJars:processResources NO-SOURCE +> Task :buildSignature:fromJars:classes UP-TO-DATE +> Task :buildSignature:fromJars:jar +> Task :buildSignature:fromJars:assemble +> Task :buildSignature:fromJars:animalsnifferMain NO-SOURCE +> Task :buildSignature:fromJars:compileTestJava NO-SOURCE +> Task :buildSignature:fromJars:processTestResources NO-SOURCE +> Task :buildSignature:fromJars:testClasses UP-TO-DATE +> Task :buildSignature:fromJars:animalsnifferTest NO-SOURCE +> Task :buildSignature:fromJars:test NO-SOURCE +> Task :buildSignature:fromJars:check UP-TO-DATE +> Task :buildSignature:fromJars:animalsnifferSignature + +> Task :buildSignature:fromJars:printSignature +Signature mySignature.sig (20.7 Kb) contains 332 classes + org.junit 258 + org.hamcrest 45 + junit.framework 17 + junit.extensions 6 + junit.runner 3 + junit.textui 2 + org.codehaus 1 + +> Task :buildSignature:fromJars:build + +BUILD SUCCESSFUL in 338ms +``` \ No newline at end of file diff --git a/examples/buildSignature/fromJars/build.gradle b/examples/buildSignature/fromJars/build.gradle new file mode 100644 index 0000000..1a0bc92 --- /dev/null +++ b/examples/buildSignature/fromJars/build.gradle @@ -0,0 +1,25 @@ +plugins { + id 'java' + id 'ru.vyarus.animalsniffer' version '1.6.0' +} + +animalsnifferSignature { +// debug = true + // signature from project jars + files configurations.compileClasspath + // by default project name + outputName 'mySignature' +} + +repositories { mavenCentral()} +dependencies { + implementation 'junit:junit:4.12' + implementation "org.codehaus.mojo:animal-sniffer-annotations:1.14" +} + +tasks.register('printSignature', ru.vyarus.gradle.plugin.animalsniffer.info.SignatureInfoTask) { + signature = tasks.animalsnifferSignature.outputFiles + depth = 2 +} + +tasks.build.dependsOn 'printSignature' \ No newline at end of file diff --git a/examples/buildSignature/fromMix/README.md b/examples/buildSignature/fromMix/README.md new file mode 100644 index 0000000..b079ee2 --- /dev/null +++ b/examples/buildSignature/fromMix/README.md @@ -0,0 +1,95 @@ +# Signatures build from different sources + +``` +> Task :buildSignature:fromMix:compileJava +> Task :buildSignature:fromMix:processResources NO-SOURCE +> Task :buildSignature:fromMix:classes +> Task :buildSignature:fromMix:jar +> Task :buildSignature:fromMix:assemble +> Task :buildSignature:fromMix:animalsnifferMain +> Task :buildSignature:fromMix:compileTestJava NO-SOURCE +> Task :buildSignature:fromMix:processTestResources NO-SOURCE +> Task :buildSignature:fromMix:testClasses UP-TO-DATE +> Task :buildSignature:fromMix:animalsnifferTest NO-SOURCE +> Task :buildSignature:fromMix:test NO-SOURCE +> Task :buildSignature:fromMix:check +> Task :buildSignature:fromMix:animalsnifferSignature + +> Task :buildSignature:fromMix:printSignature +Signature mySignature.sig (1.7 Mb) contains 18348 classes + com.sun 7115 + javax.swing 1781 + sun.awt 771 + java.util 662 + sun.nio 640 + sun.security 632 + java.awt 561 + org.omg 538 + javax.xml 395 + sun.io 331 + sun.java2d 259 + javax.management 250 + java.lang 239 + sun.util 235 + sun.management 222 + sun.text 222 + sun.net 219 + java.security 212 + sun.rmi 157 + javax.print 156 + java.beans 155 + sun.misc 152 + java.nio 150 + org.w3c 150 + sun.reflect 143 + sun.org 130 + java.io 126 + java.net 122 + sun.font 122 + javax.naming 115 + sun.swing 104 + javax.security 99 + sun.print 96 + javax.imageio 89 + java.rmi 77 + java.text 71 + javax.sound 71 + javax.crypto 63 + sun.applet 63 + org.jcp 55 + java.sql 51 + javax.lang 48 + javax.net 48 + javax.sql 48 + sun.jdbc 42 + org.xml 39 + org.slf4j 34 + javax.accessibility 27 + javax.activation 27 + sun.jkernel 27 + sun.tools 24 + javax.tools 22 + javax.annotation 19 + javax.rmi 17 + javax.smartcardio 16 + javax.jws 14 + sun.audio 14 + javax.script 13 + sun.beans 12 + sun.dc 11 + java.math 10 + org.ietf 8 + javax.transaction 6 + java.applet 5 + sun.corba 4 + sun.instrument 4 + javax.activity 3 + sunw.util 2 + org.codehaus 1 + sample 1 + sunw.io 1 + +> Task :buildSignature:fromMix:build + +BUILD SUCCESSFUL in 1s +``` \ No newline at end of file diff --git a/examples/buildSignature/fromMix/build.gradle b/examples/buildSignature/fromMix/build.gradle new file mode 100644 index 0000000..61c9eee --- /dev/null +++ b/examples/buildSignature/fromMix/build.gradle @@ -0,0 +1,33 @@ +plugins { + id 'java' + id 'ru.vyarus.animalsniffer' version '1.6.0' +} + +// just an example of custom configuration usage, it might be defailt 'signature' configuration, but it would affect +// animalsniffer check task +configurations.create('buildSignatures') + +animalsnifferSignature { +// debug = true + // signature from project classes + files sourceSets.main.output + files configurations.compileClasspath + signatures configurations.buildSignatures + // by default project name + outputName 'mySignature' +} + +repositories { mavenCentral()} +dependencies { + buildSignatures 'org.codehaus.mojo.signature:java16-sun:1.0@signature' + + implementation "org.codehaus.mojo:animal-sniffer-annotations:1.14" + implementation 'org.slf4j:slf4j-api:1.7.25' +} + +tasks.register('printSignature', ru.vyarus.gradle.plugin.animalsniffer.info.SignatureInfoTask) { + signature = tasks.animalsnifferSignature.outputFiles + depth = 2 +} + +tasks.build.dependsOn 'printSignature' \ No newline at end of file diff --git a/examples/buildSignature/fromMix/src/main/java/sample/Sample.java b/examples/buildSignature/fromMix/src/main/java/sample/Sample.java new file mode 100644 index 0000000..af364b4 --- /dev/null +++ b/examples/buildSignature/fromMix/src/main/java/sample/Sample.java @@ -0,0 +1,16 @@ +package sample; + +import org.slf4j.LoggerFactory; + +public class Sample { + + private String sample; + + public Sample(String sample) { + this.sample = sample; + } + + public static void main(String[] args) { + LoggerFactory.getLogger(Sample.class); + } +} \ No newline at end of file diff --git a/examples/buildSignature/fromSignatures/README.md b/examples/buildSignature/fromSignatures/README.md new file mode 100644 index 0000000..a5ee308 --- /dev/null +++ b/examples/buildSignature/fromSignatures/README.md @@ -0,0 +1,137 @@ +# Signatures build from other signatures (merge signatures) + +``` +> Task :buildSignature:fromSignatures:compileJava NO-SOURCE +> Task :buildSignature:fromSignatures:processResources NO-SOURCE +> Task :buildSignature:fromSignatures:classes UP-TO-DATE +> Task :buildSignature:fromSignatures:jar +> Task :buildSignature:fromSignatures:assemble +> Task :buildSignature:fromSignatures:animalsnifferMain +> Task :buildSignature:fromSignatures:compileTestJava NO-SOURCE +> Task :buildSignature:fromSignatures:processTestResources NO-SOURCE +> Task :buildSignature:fromSignatures:testClasses UP-TO-DATE +> Task :buildSignature:fromSignatures:animalsnifferTest +> Task :buildSignature:fromSignatures:test NO-SOURCE +> Task :buildSignature:fromSignatures:check +> Task :buildSignature:fromSignatures:animalsnifferSignature + +> Task :buildSignature:fromSignatures:printSignature +Signature mySignature.sig (1.9 Mb) contains 20373 classes + com.sun 7115 + javax.swing 1781 + sun.awt 771 + java.util 662 + sun.nio 640 + sun.security 632 + java.awt 561 + org.omg 538 + javax.xml 395 + org.apache 367 + sun.io 331 + sun.java2d 259 + javax.management 250 + java.lang 239 + sun.util 235 + sun.management 222 + sun.text 222 + sun.net 219 + java.security 212 + android.widget 166 + android.provider 160 + android.view 157 + sun.rmi 157 + javax.print 156 + java.beans 155 + sun.misc 152 + java.nio 150 + org.w3c 150 + sun.reflect 143 + sun.org 130 + java.io 126 + java.net 122 + sun.font 122 + android.text 120 + javax.naming 115 + android.graphics 108 + sun.swing 104 + android.content 103 + javax.security 99 + sun.print 96 + android.app 92 + javax.imageio 89 + android.renderscript 84 + java.rmi 77 + java.text 71 + javax.sound 71 + android.net 70 + android.media 68 + javax.crypto 63 + sun.applet 63 + android.os 62 + org.jcp 55 + android.database 53 + java.sql 51 + javax.lang 48 + javax.net 48 + javax.sql 48 + android.test 44 + android.webkit 42 + sun.jdbc 42 + android.util 41 + org.xml 39 + android.hardware 27 + javax.accessibility 27 + javax.activation 27 + sun.jkernel 27 + android 24 + sun.tools 24 + android.preference 23 + android.drm 22 + javax.tools 22 + android.nfc 21 + android.opengl 20 + javax.annotation 19 + android.animation 18 + android.telephony 18 + javax.rmi 17 + android.bluetooth 16 + javax.smartcardio 16 + android.speech 14 + javax.jws 14 + sun.audio 14 + android.accounts 13 + android.gesture 13 + android.inputmethodservice 13 + javax.microedition 13 + javax.script 13 + sun.beans 12 + android.location 11 + sun.dc 11 + java.math 10 + junit.framework 10 + org.ietf 8 + android.sax 7 + javax.transaction 6 + android.appwidget 5 + android.mtp 5 + java.applet 5 + org.json 5 + org.xmlpull 5 + android.service 4 + dalvik.system 4 + sun.corba 4 + sun.instrument 4 + android.security 3 + javax.activity 3 + junit.runner 3 + android.accessibilityservice 2 + dalvik.annotation 2 + dalvik.bytecode 2 + sunw.util 2 + com.android 1 + sunw.io 1 + +> Task :buildSignature:fromSignatures:build + +BUILD SUCCESSFUL in 1s +``` \ No newline at end of file diff --git a/examples/buildSignature/fromSignatures/build.gradle b/examples/buildSignature/fromSignatures/build.gradle new file mode 100644 index 0000000..11be9c2 --- /dev/null +++ b/examples/buildSignature/fromSignatures/build.gradle @@ -0,0 +1,30 @@ +plugins { + id 'java' + id 'ru.vyarus.animalsniffer' version '1.6.0' +} + +// just an example of custom configuration usage, it might be defailt 'signature' configuration, but it would affect +// animalsniffer check task +configurations.create('buildSignatures') + +animalsnifferSignature { +// debug = true + signatures configurations.buildSignatures + // by default project name + outputName 'mySignature' +} + +repositories { mavenCentral()} +dependencies { + buildSignatures 'org.codehaus.mojo.signature:java16-sun:1.0@signature' + buildSignatures 'net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature' + + implementation 'org.slf4j:slf4j-api:1.7.25' +} + +tasks.register('printSignature', ru.vyarus.gradle.plugin.animalsniffer.info.SignatureInfoTask) { + signature = tasks.animalsnifferSignature.outputFiles + depth = 2 +} + +tasks.build.dependsOn 'printSignature' \ No newline at end of file diff --git a/examples/gradle/wrapper/gradle-wrapper.jar b/examples/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..943f0cb Binary files /dev/null and b/examples/gradle/wrapper/gradle-wrapper.jar differ diff --git a/examples/gradle/wrapper/gradle-wrapper.properties b/examples/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..f398c33 --- /dev/null +++ b/examples/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +networkTimeout=10000 +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/examples/gradlew b/examples/gradlew new file mode 100755 index 0000000..65dcd68 --- /dev/null +++ b/examples/gradlew @@ -0,0 +1,244 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original 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 +# +# https://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. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/examples/gradlew.bat b/examples/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/examples/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/examples/groovy/README.md b/examples/groovy/README.md new file mode 100644 index 0000000..e8b8b1d --- /dev/null +++ b/examples/groovy/README.md @@ -0,0 +1,34 @@ +# Groovy project with animalsniffer check + +Output: + +``` +> Task :groovy:compileJava NO-SOURCE +> Task :groovy:compileGroovy +> Task :groovy:processResources NO-SOURCE +> Task :groovy:classes +> Task :groovy:jar +> Task :groovy:assemble + +> Task :groovy:animalsnifferMain + +> Task :groovy:compileTestJava NO-SOURCE +> Task :groovy:compileTestGroovy NO-SOURCE +> Task :groovy:processTestResources NO-SOURCE +> Task :groovy:testClasses UP-TO-DATE +> Task :groovy:animalsnifferTest UP-TO-DATE +> Task :groovy:test NO-SOURCE +> Task :groovy:check +> Task :groovy:build + +BUILD SUCCESSFUL in 1s +4 actionable tasks: 3 executed, 1 up-to-date + +2 AnimalSniffer violations were found in 1 files. See the report at: file:////home/xvik/projects/xvik/gradle-animalsniffer-plugin/examples/groovy/build/reports/animalsniffer/main.text + +[Undefined reference] invalid.(Sample.groovy:13) + >> int Boolean.compare(boolean, boolean) + +[Undefined reference] invalid.(Sample.groovy:18) + >> java.nio.file.Path java.nio.file.Paths.get(String, String[]) +``` \ No newline at end of file diff --git a/examples/groovy/build.gradle b/examples/groovy/build.gradle new file mode 100644 index 0000000..19c4008 --- /dev/null +++ b/examples/groovy/build.gradle @@ -0,0 +1,18 @@ +plugins { + id 'groovy' + id 'ru.vyarus.animalsniffer' version '1.6.0' +} + +// NOTE for groovy works ONLY with @CompileStatic +animalsniffer { +// debug = true + // only show errors + ignoreFailures = true +} + +repositories { mavenCentral()} +dependencies { + signature 'org.codehaus.mojo.signature:java16-sun:1.0@signature' + implementation localGroovy() + implementation 'org.slf4j:slf4j-api:1.7.25' +} \ No newline at end of file diff --git a/examples/groovy/src/main/groovy/invalid/Sample.groovy b/examples/groovy/src/main/groovy/invalid/Sample.groovy new file mode 100644 index 0000000..86116a1 --- /dev/null +++ b/examples/groovy/src/main/groovy/invalid/Sample.groovy @@ -0,0 +1,21 @@ +package invalid + +import groovy.transform.CompileStatic +import org.slf4j.LoggerFactory + +import java.nio.file.Paths + +@CompileStatic +class Sample { + + static void main(String[] args) { + // method added in 1.7 + Boolean.compare(true, true) + } + + void someth() { + // class added in 1.7 + Paths.get("/tmp") + LoggerFactory.getLogger(Sample.class) + } +} \ No newline at end of file diff --git a/examples/java/README.md b/examples/java/README.md new file mode 100644 index 0000000..ef702b8 --- /dev/null +++ b/examples/java/README.md @@ -0,0 +1,35 @@ +# Java project with animalsniffer check + +Output: + +``` +> Task :java:compileJava +> Task :java:processResources NO-SOURCE +> Task :java:classes +> Task :java:jar +> Task :java:assemble + +> Task :java:animalsnifferMain + +> Task :java:compileTestJava NO-SOURCE +> Task :java:processTestResources NO-SOURCE +> Task :java:testClasses UP-TO-DATE +> Task :java:animalsnifferTest UP-TO-DATE +> Task :java:test NO-SOURCE +> Task :java:check +> Task :java:build + +BUILD SUCCESSFUL in 646ms +4 actionable tasks: 3 executed, 1 up-to-date + +3 AnimalSniffer violations were found in 1 files. See the report at: file:////home/xvik/projects/xvik/gradle-animalsniffer-plugin/examples/java/build/reports/animalsniffer/main.text + +[Undefined reference | java16-sun-1.0] invalid.(Sample.java:9) + >> int Boolean.compare(boolean, boolean) + +[Undefined reference | android-api-level-14-4.0_r4] invalid.(Sample.java:9) + >> int Boolean.compare(boolean, boolean) + +[Undefined reference | android-api-level-14-4.0_r4] invalid.(Sample.java:14) + >> Object javax.naming.InitialContext.doLookup(String) +``` \ No newline at end of file diff --git a/examples/java/build.gradle b/examples/java/build.gradle new file mode 100644 index 0000000..592dbc3 --- /dev/null +++ b/examples/java/build.gradle @@ -0,0 +1,18 @@ +plugins { + id 'java' + id 'ru.vyarus.animalsniffer' version '1.6.0' +} + +animalsniffer { +// debug = true + // only show errors + ignoreFailures = true +} + +repositories { mavenCentral()} +dependencies { + signature 'org.codehaus.mojo.signature:java16-sun:1.0@signature' + signature 'net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature' + + implementation 'org.slf4j:slf4j-api:1.7.25' +} \ No newline at end of file diff --git a/examples/java/src/main/java/invalid/Sample.java b/examples/java/src/main/java/invalid/Sample.java new file mode 100644 index 0000000..c7108bd --- /dev/null +++ b/examples/java/src/main/java/invalid/Sample.java @@ -0,0 +1,16 @@ +package invalid; + +import javax.naming.InitialContext; + +public class Sample { + + public static void main(String[] args) { + // method added in 1.7 + Boolean.compare(true, true); + } + + public void someth() throws Exception { + // not available in android + InitialContext.doLookup("some"); + } +} \ No newline at end of file diff --git a/examples/kotlin/README.md b/examples/kotlin/README.md new file mode 100644 index 0000000..173f71e --- /dev/null +++ b/examples/kotlin/README.md @@ -0,0 +1,35 @@ +# Kotlin project with animalsniffer check + +Output: + +``` +> Task :kotlin:processResources NO-SOURCE +> Task :kotlin:processTestResources NO-SOURCE +> Task :kotlin:compileKotlin +> Task :kotlin:compileJava NO-SOURCE +> Task :kotlin:classes UP-TO-DATE +> Task :kotlin:inspectClassesForKotlinIC +> Task :kotlin:jar +> Task :kotlin:assemble + +> Task :kotlin:animalsnifferMain + +> Task :kotlin:compileTestKotlin NO-SOURCE +> Task :kotlin:compileTestJava NO-SOURCE +> Task :kotlin:testClasses UP-TO-DATE +> Task :kotlin:animalsnifferTest UP-TO-DATE +> Task :kotlin:test NO-SOURCE +> Task :kotlin:check +> Task :kotlin:build + +BUILD SUCCESSFUL in 950ms +5 actionable tasks: 4 executed, 1 up-to-date + +2 AnimalSniffer violations were found in 1 files. See the report at: file:////home/xvik/projects/xvik/gradle-animalsniffer-plugin/examples/kotlin/build/reports/animalsniffer/main.text + +[Undefined reference] invalid.(Sample.kt:11) + >> int Boolean.compare(boolean, boolean) + +[Undefined reference] invalid.(Sample.kt:16) + >> java.nio.file.Path java.nio.file.Paths.get(String, String[]) +``` \ No newline at end of file diff --git a/examples/kotlin/build.gradle b/examples/kotlin/build.gradle new file mode 100644 index 0000000..fb90361 --- /dev/null +++ b/examples/kotlin/build.gradle @@ -0,0 +1,18 @@ +plugins { + id 'org.jetbrains.kotlin.jvm' version '1.6.21' + id 'ru.vyarus.animalsniffer' version '1.6.0' +} + +animalsniffer { +// debug = true + // only show errors + ignoreFailures = true +} + +repositories { mavenCentral()} +dependencies { + signature 'org.codehaus.mojo.signature:java16-sun:1.0@signature' + implementation platform('org.jetbrains.kotlin:kotlin-bom') + implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' + implementation 'org.slf4j:slf4j-api:1.7.25' +} \ No newline at end of file diff --git a/examples/kotlin/src/main/kotlin/invalid/Sample.kt b/examples/kotlin/src/main/kotlin/invalid/Sample.kt new file mode 100644 index 0000000..44e85c5 --- /dev/null +++ b/examples/kotlin/src/main/kotlin/invalid/Sample.kt @@ -0,0 +1,19 @@ +package invalid + +import org.slf4j.LoggerFactory + +import java.nio.file.Paths + +public class Sample { + + fun main() { + // method added in 1.7 + java.lang.Boolean.compare(true, true) + } + + fun someth() { + // class added in 1.7 + Paths.get("/tmp") + LoggerFactory.getLogger(Sample::class.java) + } +} \ No newline at end of file diff --git a/examples/scala/README.md b/examples/scala/README.md new file mode 100644 index 0000000..d6af868 --- /dev/null +++ b/examples/scala/README.md @@ -0,0 +1,39 @@ +# Scala project with animalsniffer check + +Output: + +``` +> Task :scala:compileJava NO-SOURCE + +> Task :scala:compileScala +[Warn] /home/xvik/projects/xvik/gradle-animalsniffer-plugin/examples/scala/src/main/scala/invalid/Sample.scala:8:8: Sample has a main method with parameter type Array[String], but invalid.Sample will not be a runnable program. + Reason: main method must have exact signature (Array[String])Unit +one warning found + +> Task :scala:processResources NO-SOURCE +> Task :scala:classes +> Task :scala:jar +> Task :scala:assemble + +> Task :scala:animalsnifferMain + +> Task :scala:compileTestJava NO-SOURCE +> Task :scala:compileTestScala NO-SOURCE +> Task :scala:processTestResources NO-SOURCE +> Task :scala:testClasses UP-TO-DATE +> Task :scala:animalsnifferTest UP-TO-DATE +> Task :scala:test NO-SOURCE +> Task :scala:check +> Task :scala:build + +BUILD SUCCESSFUL in 3s +4 actionable tasks: 3 executed, 1 up-to-date + +2 AnimalSniffer violations were found in 1 files. See the report at: file:////home/xvik/projects/xvik/gradle-animalsniffer-plugin/examples/scala/build/reports/animalsniffer/main.text + +[Undefined reference] invalid.(Sample.scala:12) + >> int Boolean.compare(boolean, boolean) + +[Undefined reference] invalid.(Sample.scala:17) + >> java.nio.file.Path java.nio.file.Paths.get(String, String[]) +``` \ No newline at end of file diff --git a/examples/scala/build.gradle b/examples/scala/build.gradle new file mode 100644 index 0000000..ef290bf --- /dev/null +++ b/examples/scala/build.gradle @@ -0,0 +1,17 @@ +plugins { + id 'scala' + id 'ru.vyarus.animalsniffer' version '1.6.0' +} + +animalsniffer { +// debug = true + // only show errors + ignoreFailures = true +} + +repositories { mavenCentral()} +dependencies { + signature 'org.codehaus.mojo.signature:java16-sun:1.0@signature' + implementation 'org.scala-lang:scala-library:2.11.12' + implementation 'org.slf4j:slf4j-api:1.7.25' +} \ No newline at end of file diff --git a/examples/scala/src/main/scala/invalid/Sample.scala b/examples/scala/src/main/scala/invalid/Sample.scala new file mode 100644 index 0000000..495ec0e --- /dev/null +++ b/examples/scala/src/main/scala/invalid/Sample.scala @@ -0,0 +1,20 @@ +package invalid + +import org.slf4j.LoggerFactory + +import java.nio.file.Paths +import java.lang.Boolean + +object Sample { + + def main(args: Array[String]) = { + // method added in 1.7 + Boolean.compare(true, true) + } + + def someth() { + // class added in 1.7 + Paths.get("/tmp") + LoggerFactory.getLogger("sample logger") + } +} \ No newline at end of file diff --git a/examples/settings.gradle b/examples/settings.gradle new file mode 100644 index 0000000..30db33e --- /dev/null +++ b/examples/settings.gradle @@ -0,0 +1,12 @@ +pluginManagement { + repositories { + mavenLocal() + gradlePluginPortal() + } +} + +include 'java', 'groovy', 'kotlin', 'scala', + 'buildSignature:fromClasses', + 'buildSignature:fromJars', + 'buildSignature:fromSignatures', + 'buildSignature:fromMix' \ No newline at end of file