|
| 1 | +import java.io.File |
| 2 | + |
| 3 | +import org.apache.commons.io.filefilter.DirectoryFileFilter |
| 4 | + |
| 5 | +plugins { |
| 6 | + // p2 dependencies |
| 7 | + id 'com.diffplug.gradle.p2.asmaven' version '3.9.0' |
| 8 | +} |
| 9 | + |
| 10 | +apply from: rootProject.file('../gradle/java-setup.gradle') |
| 11 | +apply from: rootProject.file('../gradle/java-publish.gradle') |
| 12 | + |
| 13 | +// The dependencies to pull from GrEclipse's p2 repositories |
| 14 | +def grEclipseDeps = [ |
| 15 | + 'org.codehaus.groovy.eclipse.refactoring':'+', // GroovyFormatter and related |
| 16 | + |
| 17 | + // The following lists does not reflect the complete transitive required packages, but |
| 18 | + // the once used during code formatting |
| 19 | + 'org.codehaus.groovy':'+', // Groovy compiler patches supporting use within GrEclipse and Groovy itself |
| 20 | + 'org.codehaus.groovy.eclipse.core':'+', // Groovy core classes (provides central logging used by formatter) |
| 21 | + 'org.eclipse.jdt.core':"${VER_JDT_PATCH}", // Patches org.eclipse.jdt.core classes supporting use within GrEclipse (provides AST generator) |
| 22 | + 'org.eclipse.jdt.groovy.core':'+' // Extends org.eclipse.jdt.core for Groovy |
| 23 | +] |
| 24 | + |
| 25 | +ext { |
| 26 | + developers = [ |
| 27 | + fvgh: [ name: 'Frank Vennemeyer', email: '[email protected]' ], |
| 28 | + ] |
| 29 | + |
| 30 | + //Include/Excludes form the JARs, which goes into a fat-jar with the spottless formatter interface. |
| 31 | + jarInclude = [ |
| 32 | + '**/*.class', // Take all classes |
| 33 | + '**/*.java', // ... and sources. |
| 34 | + '**/*.properties', // Text resources (for messages, etc) |
| 35 | + '**/*.xml', // Plugin XML and other resources |
| 36 | + '*.html', // License information about the included JARs, |
| 37 | + 'META-INF/**' // Information about the origin of the individual class files |
| 38 | + ] |
| 39 | + jarExclude = [ |
| 40 | + 'META-INF/*.RSA', // The eclipse jars are signed, and our fat-jar breaks the signatures |
| 41 | + 'META-INF/*.SF', // ... so all signatures are filtered |
| 42 | + ] |
| 43 | + |
| 44 | + //Some JARs include JARs themselfs |
| 45 | + internalJars = [ |
| 46 | + //Jars included by org.codehaus.groovy |
| 47 | + "**/groovy-all-${VER_GROOVY}-indy", // Use Groovy compiler compatible with GrEclipse instead of localGroovy |
| 48 | + '**/groovy-eclipse', // Patches/Overrides some of the Groovy compiler classes |
| 49 | + '**/eclipse-trace', // Provides logging capabilities for groovy-eclipse |
| 50 | + |
| 51 | + //Jars included by org.eclipse.jdt.groovy.core |
| 52 | + '**/nlcl' //Non locking class loader used by groovy compiler |
| 53 | + ] |
| 54 | + |
| 55 | + // The directory contains all external classes for the fat-jar |
| 56 | + embeddedClassesDirName = 'build/embeddedClasses' |
| 57 | + embeddedClassesDir = project.file(embeddedClassesDirName) |
| 58 | + embeddedClassesLibDirName = 'build/embeddedClasses/lib' |
| 59 | + embeddedClassesLibDir = project.file(embeddedClassesLibDirName) |
| 60 | +} |
| 61 | + |
| 62 | +// build a maven repo in our build folder containing these artifacts |
| 63 | +p2AsMaven { |
| 64 | + group 'p2', { |
| 65 | + repo "http://dist.springsource.org/release/GRECLIPSE/e${VER_ECLIPSE}" |
| 66 | + grEclipseDeps.keySet.each { p2.addIU(it) } |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +configurations { |
| 71 | + embeddedJars // GrEclipse JARs the fat-jar is based uppon |
| 72 | +} |
| 73 | + |
| 74 | +dependencies { |
| 75 | + grEclipseDeps.each { groupArtifact, version -> |
| 76 | + embeddedJars "p2:${groupArtifact}:${version}" |
| 77 | + } |
| 78 | + |
| 79 | + // The resulting fat-jar includes the classes from GRECLIPSE. |
| 80 | + compile files(embeddedClassesDir) |
| 81 | + |
| 82 | + compile "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLISPE_BASE}" |
| 83 | + // Provides text partitioners for formatters |
| 84 | + compile ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLISPE_JFACE}") { |
| 85 | + exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +jar { |
| 90 | + // this embeds the Eclipse-Groovy clases into our "fat JAR" |
| 91 | + from embeddedClassesDir |
| 92 | +} |
| 93 | + |
| 94 | +////////// |
| 95 | +// Test // |
| 96 | +////////// |
| 97 | +sourceSets { |
| 98 | + // Use JAR file with all resources for Eclipse-Groovy integration-tests |
| 99 | + test.runtimeClasspath = jar.outputs.files + sourceSets.test.output + sourceSets.test.compileClasspath |
| 100 | +} |
| 101 | + |
| 102 | +/////////////////// |
| 103 | +// External Deps // |
| 104 | +/////////////////// |
| 105 | + |
| 106 | +task unjarEmbeddedClasses { |
| 107 | + description = "Copies filtered set of embedded classes from the Eclise/GrEclipse dependencies to '${project.relativePath(embeddedClassesDir)}'." |
| 108 | + inputs.files(configurations.embeddedJars) |
| 109 | + inputs.property('internalJars', internalJars) |
| 110 | + inputs.property('jarInclude', jarInclude) |
| 111 | + inputs.property('jarExclude', jarExclude) |
| 112 | + outputs.file(embeddedClassesDir) |
| 113 | + |
| 114 | + doLast { |
| 115 | + embeddedClassesDir.deleteDir() |
| 116 | + embeddedClassesDir.mkdirs() |
| 117 | + embeddedClassesLibDir.deleteDir() |
| 118 | + embeddedClassesLibDir.mkdirs() |
| 119 | + configurations.embeddedJars.each { |
| 120 | + unjar(it, embeddedClassesDir) |
| 121 | + } |
| 122 | + //Unpack internal JARs. Maintain the order defined in internalJars |
| 123 | + internalJars.each { |
| 124 | + fileTree(embeddedClassesDir).include("${it}.jar").each { |
| 125 | + unjar(it, embeddedClassesDir) |
| 126 | + delete(it) |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +def unjar(File jarFile, File destDir) { |
| 133 | + ant.unjar(src: jarFile, dest: destDir) { |
| 134 | + patternset { |
| 135 | + jarInclude.each { |
| 136 | + include(name: "${it}") |
| 137 | + } |
| 138 | + internalJars.each { |
| 139 | + include(name: "**/${it}.jar") |
| 140 | + } |
| 141 | + jarExclude.each { |
| 142 | + exclude(name: "${it}") |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | + //Provide Fat JAR resources (following naming convention of spotless-eclipse-base) |
| 147 | + def fat_jar_resource_dir = jarFile.getName().split('-')[0] |
| 148 | + ant.move(todir: "${destDir}/${fat_jar_resource_dir}/META-INF", quiet: 'true', failonerror: 'false') { |
| 149 | + fileset(dir: "${destDir}/META-INF") |
| 150 | + } |
| 151 | + //Keep licenses and other human readable information for transparency |
| 152 | + ant.move(todir: "${destDir}/${fat_jar_resource_dir}", quiet: 'true') { |
| 153 | + fileset(dir: destDir) { |
| 154 | + include(name: 'META-INF') |
| 155 | + include(name: '*') |
| 156 | + type(type: 'file') |
| 157 | + exclude(name: '*jar-*') |
| 158 | + exclude(name: '*.jar') |
| 159 | + } |
| 160 | + } |
| 161 | +} |
| 162 | + |
| 163 | +tasks.compileJava.dependsOn(unjarEmbeddedClasses) |
| 164 | + |
| 165 | +///////// |
| 166 | +// IDE // |
| 167 | +///////// |
| 168 | + |
| 169 | +apply plugin: 'eclipse' |
| 170 | + |
| 171 | +// always create fresh projects |
| 172 | +tasks.eclipse.dependsOn(cleanEclipse) |
| 173 | +// Encure that the dependent classes are preovided for compilation if project is build via Eclipse instead of command line |
| 174 | +tasks.eclipseClasspath.dependsOn(unjarEmbeddedClasses) |
| 175 | + |
| 176 | +apply plugin: 'idea' |
| 177 | + |
| 178 | +// Encure that the dependent classes are preovided for compilation if project is build via Eclipse instead of command line |
| 179 | +tasks.idea.dependsOn(unjarEmbeddedClasses) |
0 commit comments