Last active
August 29, 2015 13:56
-
-
Save sgalles/8792780 to your computer and use it in GitHub Desktop.
This is a quick and dirty Gradle script that can be used to pull maven artifacts from a repository and locally create a complete Ceylon repository with the same transitive dependencies. The script also create fatflat.jar : it is a jar with all dependencies merged that can be used to peform flat classpath tests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// usage : save this script as 'build.gradle' and run 'gradle' in the directory of this script | |
configurations { compile } | |
dependencies{ | |
//compile 'com.yammer.dropwizard:dropwizard-core:0.6.2' | |
compile 'com.octo.android.robospice:robospice-spring-android:1.4.9' | |
//compile 'org.hibernate:hibernate-core:4.3.0.Final' | |
} | |
repositories{ mavenCentral() } | |
class Module { | |
def dependencies = [] as Set | |
ResolvedArtifact artifact | |
} | |
String normalize(String s){ | |
s.replaceAll(/[-\.]/,'_') | |
} | |
String extractName(ModuleVersionIdentifier id){ | |
"x_${normalize(id.group)}_${normalize(id.name)}" | |
} | |
// used for module that does not have an artifact | |
task emptyJar(type: Jar){ | |
destinationDir=buildDir | |
baseName = "empty" | |
} | |
// create a big jar, use task generateCeylonImports as a 'configuration task' | |
task fatFlatJar(type: Jar, dependsOn: 'generateCeylonImports'){ | |
defaultTasks name | |
destinationDir=buildDir | |
baseName = "fatflat" | |
} | |
task generateCeylonImports{ | |
inputs.file(emptyJar) | |
doLast{ | |
def map = [:].withDefault{ new Module() } | |
def recurse | |
recurse = { ResolvedDependency dep -> | |
Module mod = map[dep.module.id] | |
if(dep.moduleArtifacts.size()>0){ | |
mod.artifact = dep.moduleArtifacts.iterator().next() | |
} | |
dep.getChildren().each { def childDep -> | |
mod.dependencies << childDep.module.id | |
recurse childDep | |
} | |
} | |
// pull dependencies | |
println "***** Use the following import directives :" | |
configurations.compile.resolvedConfiguration.firstLevelModuleDependencies.each { ResolvedDependency rootDep -> | |
println """import ${extractName(rootDep.module.id)} "${rootDep.module.id.version}";\n""" | |
recurse rootDep | |
} | |
println "*****" | |
// configure flatjar task | |
map.each { ModuleVersionIdentifier id, Module module -> | |
if(module.artifact){ | |
fatFlatJar.configure { from(zipTree(module.artifact.file)) } | |
} | |
} | |
// use what we found to populate repos | |
File reposDir = file("$buildDir/repo") | |
reposDir.mkdirs() | |
map.each { ModuleVersionIdentifier id, Module module -> | |
File moduleDir = file("$reposDir/${extractName(id)}") | |
File versionDir = file("$moduleDir/${id.version}") | |
versionDir.mkdirs() | |
println "Module created : $versionDir" | |
String jarName = "${moduleDir.name}-${versionDir.name}.jar" | |
copy { | |
from ( module.artifact ? module.artifact.file : emptyJar) | |
into versionDir | |
rename {jarName} | |
} | |
file("$versionDir/module.xml").withWriter { def w -> | |
w.write("""<module xmlns="urn:jboss:module:1.1" name="${moduleDir.name}" slot="${versionDir.name}">\n""") | |
w.write("""<resources>\n""") | |
w.write("""<resource-root path="$jarName"/>\n""") | |
w.write("""</resources>\n""") | |
w.write("""<dependencies>\n""") | |
module.dependencies.each { ModuleVersionIdentifier depId -> | |
w.write("""<module name="${extractName(depId)}" slot="${depId.version}" export="true"/>\n""") | |
} | |
w.write("""</dependencies>\n""") | |
w.write("""</module>\n""") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment