Skip to content

Commit

Permalink
Shade JDK, add String-based find methods to JavaSource
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed Aug 8, 2016
1 parent 7ae2c7c commit 6ea629a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
27 changes: 25 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'me.champeau.gradle.antlr4' version '0.1'
id 'com.gradle.plugin-publish' version '0.9.4'
id 'java-gradle-plugin'
id 'com.github.johnrengelman.shadow' version '1.2.3'
id 'nebula.plugin-plugin' version '4.24.0'
}

Expand Down Expand Up @@ -30,8 +31,13 @@ configurations {
compile.extendsFrom antlr4
}

configurations {
jdk.description = 'The JDK itself so that we can shade it and run this code against a JRE'
compile.extendsFrom jdk
}

dependencies {
compile files("${System.getProperty('java.home')}/../lib/tools.jar")
jdk files("${System.getProperty('java.home')}/../lib/tools.jar")
compile 'eu.infomas:annotation-detector:latest.release'
compile 'org.slf4j:slf4j-api:1.7.+'
compileOnly 'junit:junit:4.+'
Expand Down Expand Up @@ -65,4 +71,21 @@ pluginBundle {
tasks.withType(Javadoc) {
// generated ANTLR sources violate doclint
options.addStringOption('Xdoclint:none', '-quiet')
}
}

// Relocate jgit dependency not available in Maven Central
// Replaces the main artifact by removing the classifier for the shadow jar, and replacing jar with shadowJar
// Relocated dependencies are removed from the generated pom
shadowJar {
configurations = [project.configurations.jdk]
classifier = null
relocate 'com.sun', 'com.netflix.devinsight.shaded.com.sun'
relocate 'sun', 'com.netflix.devinsight.shaded.sun'

mergeServiceFiles {
exclude 'META-INF/services/com.sun.*'
}
}

jar.deleteAllActions()
jar.dependsOn shadowJar
7 changes: 5 additions & 2 deletions src/main/kotlin/com/netflix/java/refactor/JavaSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ class JavaSource(internal val cu: CompilationUnit) {
}

fun hasType(clazz: Class<*>): Boolean = HasType(clazz.name).scanner().scan(cu)

fun hasType(clazz: String): Boolean = HasType(clazz).scanner().scan(cu)

/**
* Find fields defined on this class, but do not include inherited fields up the type hierarchy
*/
fun findFields(clazz: Class<*>): List<Field> = FindFields(clazz.name, false).scanner().scan(cu)

fun findFields(clazz: String): List<Field> = FindFields(clazz, false).scanner().scan(cu)

/**
* Find fields defined both on this class and visible inherited fields up the type hierarchy
*/
fun findFieldsIncludingInherited(clazz: Class<*>): List<Field> = FindFields(clazz.name, true).scanner().scan(cu)
fun findFieldsIncludingInherited(clazz: String): List<Field> = FindFields(clazz, true).scanner().scan(cu)

fun findMethodCalls(signature: String): List<Method> = FindMethods(signature).scanner().scan(cu)
}

0 comments on commit 6ea629a

Please sign in to comment.