|
| 1 | +/** |
| 2 | + * (c) Copyright IBM Corporation 2017. |
| 3 | + * This is licensed under the following license. |
| 4 | + * The Eclipse Public 1.0 License (http://www.eclipse.org/legal/epl-v10.html) |
| 5 | + * U.S. Government Users Restricted Rights: Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. |
| 6 | + */ |
| 7 | +/* The Groovy plugin for Gradle assumes the following layout |
| 8 | + * src/main/java |
| 9 | + * src/main/resources |
| 10 | + * src/main/groovy |
| 11 | + * |
| 12 | + * src/test/java |
| 13 | + * src/test/resources |
| 14 | + * src/test/groovy |
| 15 | + * |
| 16 | + * src/<sourceSet>/java |
| 17 | + * src/<sourceSet>/resources |
| 18 | + * src/<sourceSet>/groovy |
| 19 | + * |
| 20 | + * You can override or create a new sourceSet with the following snippet: |
| 21 | + * |
| 22 | + * sourceSets { |
| 23 | + * main { |
| 24 | + * // We can override src/main/groovy to also add src/main/zip |
| 25 | + * groovy { |
| 26 | + * srcDirs = ['src/main/groovy', 'src/main/zip'] |
| 27 | + * } |
| 28 | + * } |
| 29 | + * mySourceSet { |
| 30 | + * groovy { |
| 31 | + * srcDirs = ['src/myDir/groovy'] |
| 32 | + * } |
| 33 | + * } |
| 34 | + * } |
| 35 | + */ |
| 36 | + |
| 37 | +import org.apache.tools.ant.filters.ReplaceTokens |
| 38 | + |
| 39 | +def pluginName="Slack-UCD" |
| 40 | +def pluginVersion = project.hasProperty('pluginVersion') ? project.getProperty('pluginVersion') : 'dev' |
| 41 | + |
| 42 | +apply plugin: 'groovy' |
| 43 | + |
| 44 | +defaultTasks 'distPlugin' |
| 45 | + |
| 46 | +def buildLocaleDir = 'build/locale' |
| 47 | +def buildUtilDir = 'build/util' |
| 48 | + |
| 49 | +configurations { |
| 50 | + // Remove the groovy-all jar from runtime dependencies |
| 51 | + runtime.exclude module: 'groovy-all' |
| 52 | +} |
| 53 | + |
| 54 | +repositories { |
| 55 | + mavenCentral() |
| 56 | + maven { |
| 57 | + url "https://public.dhe.ibm.com/software/products/UrbanCode/maven2/" |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +dependencies { |
| 62 | + // groovy-plugin-utils pulls down groovy-all as a transitive dependency for the 'compile' configuration |
| 63 | + compile 'com.ibm.urbancode.plugins:groovy-plugin-utils:+' |
| 64 | + compile 'com.ibm.urbancode.util:i18n-scraper:+' |
| 65 | + compile 'commons-codec:commons-codec:1.2' |
| 66 | + compile 'commons-httpclient:commons-httpclient:3.1' |
| 67 | + compile 'commons-logging:commons-logging:1.1.3' |
| 68 | + //compile 'org.codehaus.groovy:groovy-json:2.4.0' |
| 69 | + |
| 70 | + // This compiles the i18n-scraper script |
| 71 | + compile localGroovy() |
| 72 | + testCompile 'junit:junit:4.11' |
| 73 | + testCompile 'org.hamcrest:hamcrest-core:1.3' |
| 74 | +} |
| 75 | + |
| 76 | +sourceSets { |
| 77 | + main { |
| 78 | + groovy { |
| 79 | + srcDirs = ['src/main/groovy', 'src/main/zip', "${buildDir}/util"] |
| 80 | + } |
| 81 | + } |
| 82 | + zip { |
| 83 | + groovy { |
| 84 | + srcDirs = ['src/main/zip'] |
| 85 | + } |
| 86 | + } |
| 87 | + classes { |
| 88 | + groovy { |
| 89 | + srcDirs = ['src/main/groovy', "${buildDir}/util"] |
| 90 | + } |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +compileJava { |
| 95 | + dependsOn 'extractGPU', 'copyi18n' |
| 96 | +} |
| 97 | +compileGroovy { |
| 98 | + include "i18n-scraper.groovy" |
| 99 | +} |
| 100 | + |
| 101 | +task copyDeps(type: Copy) { |
| 102 | + into 'lib' |
| 103 | + copy { |
| 104 | + from configurations.runtime |
| 105 | + include { target -> |
| 106 | + return target.file.path.contains("com.ibm.urbancode") |
| 107 | + } |
| 108 | + into 'lib' |
| 109 | + rename { fileName -> |
| 110 | + stripVersion(fileName) |
| 111 | + } |
| 112 | + } |
| 113 | + copy { |
| 114 | + from configurations.runtime |
| 115 | + exclude { target -> |
| 116 | + return target.file.path.contains("com.ibm.urbancode") |
| 117 | + } |
| 118 | + into 'lib' |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | +task extractGPU(type: Copy) { |
| 123 | + def zipFile = file('lib/groovy-plugin-utils.jar') |
| 124 | + def outputDir = file("${buildDir}/util") |
| 125 | + |
| 126 | + from zipTree(zipFile) |
| 127 | + into outputDir |
| 128 | +} |
| 129 | + |
| 130 | +task copyi18n(type: Copy) { |
| 131 | + def i18nFile = file('lib/i18n-scraper.groovy') |
| 132 | + def outputDir = file("${buildDir}/util") |
| 133 | + |
| 134 | + from i18nFile |
| 135 | + into outputDir |
| 136 | +} |
| 137 | + |
| 138 | +task distPlugin(type: Zip, dependsOn: ['compileGroovy', 'gatherI18n']) { |
| 139 | + from(sourceSets.zip.groovy.srcDirs) { |
| 140 | + filter(ReplaceTokens, tokens: [RELEASE_VERSION: pluginVersion]) |
| 141 | + } |
| 142 | + |
| 143 | + into('lib') { |
| 144 | + from copyDeps |
| 145 | + exclude 'i18n-scraper.groovy' |
| 146 | + exclude 'groovy-plugin-utils.jar' |
| 147 | + exclude 'groovy-all-*.jar' |
| 148 | + exclude 'gson-*.jar' |
| 149 | + } |
| 150 | + into('locale') { |
| 151 | + from buildLocaleDir |
| 152 | + } |
| 153 | + into('classes') { |
| 154 | + from sourceSets.classes.groovy.srcDirs |
| 155 | + exclude 'META-INF', 'i18n-scraper.groovy' |
| 156 | + } |
| 157 | + if (pluginVersion) { |
| 158 | + archiveName = "${pluginName}-v${pluginVersion}.zip" |
| 159 | + } else { |
| 160 | + archiveName = "${pluginName}-dev.zip" |
| 161 | + } |
| 162 | +} |
| 163 | + |
| 164 | +task gatherI18n(type: JavaExec) { |
| 165 | + delete buildLocaleDir |
| 166 | + mkdir buildLocaleDir |
| 167 | + |
| 168 | + main = 'i18n-scraper' |
| 169 | + args 'build/locale/en.properties' |
| 170 | + classpath = sourceSets.main.runtimeClasspath |
| 171 | +} |
| 172 | + |
| 173 | +task cleanAll(dependsOn: ['clean', 'cleanCopyDeps', 'cleanDistPlugin', 'cleanGatherI18n']) |
| 174 | + |
| 175 | +String stripVersion(String fileNameWithVersion) { |
| 176 | + String ext = fileNameWithVersion.substring(fileNameWithVersion.lastIndexOf("."),fileNameWithVersion.length()) |
| 177 | + int end = fileNameWithVersion.lastIndexOf("-"); //assumes that: name-version.ext. Will not work with name-version-SNAPSHOT.ext |
| 178 | + return fileNameWithVersion.substring(0, end) + ext |
| 179 | +} |
0 commit comments