Skip to content

Commit

Permalink
add example projects
Browse files Browse the repository at this point in the history
  • Loading branch information
xvik committed Feb 9, 2023
1 parent 060d07f commit 361ee17
Show file tree
Hide file tree
Showing 31 changed files with 1,114 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions examples/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wrapper {
gradleVersion = '7.6'
}
10 changes: 10 additions & 0 deletions examples/buildSignature/README.md
Original file line number Diff line number Diff line change
@@ -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)
25 changes: 25 additions & 0 deletions examples/buildSignature/fromClasses/README.md
Original file line number Diff line number Diff line change
@@ -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
```
25 changes: 25 additions & 0 deletions examples/buildSignature/fromClasses/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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);
}
}
31 changes: 31 additions & 0 deletions examples/buildSignature/fromJars/README.md
Original file line number Diff line number Diff line change
@@ -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
```
25 changes: 25 additions & 0 deletions examples/buildSignature/fromJars/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
95 changes: 95 additions & 0 deletions examples/buildSignature/fromMix/README.md
Original file line number Diff line number Diff line change
@@ -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
```
33 changes: 33 additions & 0 deletions examples/buildSignature/fromMix/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
16 changes: 16 additions & 0 deletions examples/buildSignature/fromMix/src/main/java/sample/Sample.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading

0 comments on commit 361ee17

Please sign in to comment.