Commits

Dhananjay Nene committed 1554a31

Changes due to dynamic properties deprecation in gradle 1.0m9

Comments (0)

Files changed (2)

 apply plugin:'maven'
 
 version = '0.0.1-SNAPSHOT'
-groupId = 'in.vayana.gradle-plugins'
-artifactId = 'gradle-bnd-plugin'
+ext.groupId = 'in.vayana.gradle-plugins'
+ext.artifactId = 'gradle-bnd-plugin'
 
 sourceCompatibility = 1.6
 targetCompatibility = 1.6
 
 configure(install.repositories.mavenInstaller) {
     pom.project {
-	groupId = project.groupId
-	artifactId = project.artifactId
+	groupId = project.ext.groupId
+	artifactId = project.ext.artifactId
         version = project.version
     }
 }
     compile 'biz.aQute:bndlib:1.50.0'
 }
 
-metadata = {
+ext.metadata = {
     name 'Gradle Bnd plugin'
     packaging 'jar'
     description 'Plugin to combine multiple jars into one (optionally) and add OSGi metadata'

src/main/groovy/in/vayana/gradle_plugins/GradleBndPlugin.groovy

         project.configurations { exclusions }
         project.tasks.jar {
             doLast() {
-                oldJar = project.jar.archivePath
-                excludedJars = []
-                includedJars = []
-                pattern = /(.*)-([0-9][a-zA-Z0-9_\.^-]*)(-SNAPSHOT)?(.standalone)?.jar$/
-                classFilePattern =  /(.*)\/[^\/]*.class/
+                def oldJar = project.jar.archivePath
+                def excludedJars = []
+                def includedJars = []
+                def pattern = /(.*)-([0-9][a-zA-Z0-9_\.^-]*)(-SNAPSHOT)?(.standalone)?.jar$/
+                def classFilePattern =  /(.*)\/[^\/]*.class/
                 if(project.bnd.condense) {
                     // move old jar away
-                    newJarName = oldJar.toString().replaceFirst('.jar$',".standalone.jar")
+                    def newJarName = oldJar.toString().replaceFirst('.jar$',".standalone.jar")
                     log.debug("Moving " + oldJar.toString() + " to " + newJarName)
                     oldJar.renameTo(new File(newJarName))
 
                     // create the new jar with same name as the output of the jar task
 
-                    outputJar = new JarOutputStream(
+                    def outputJar = new JarOutputStream(
                                     new FileOutputStream(oldJar.toString()))
-                    depJars = (project.configurations.compile as List) + new File(newJarName) 
+                    def depJars = (project.configurations.compile as List) + new File(newJarName) 
                     if (project.bnd.includeTestDependencies)
                         depJars = depJars + (project.configurations.testCompile 
 as List)
-                    excluded = (project.configurations.exclusions as List).collect {it.name} 
+                    def excluded = (project.configurations.exclusions as List).collect {it.name} 
                     depJars.each { file -> 
                         if (!(file.name in excluded)) {
                             log.debug(file.name + " included")
                             includedJars.add(file.name)
-                            matcher = file.name =~ pattern
+                            def matcher = file.name =~ pattern
                             if (! matcher.matches() ) {
                                 println("***** Unable to get version number for " + file.name)
                             }
-                            jarVersion = matcher[0][2]
+                            def jarVersion = matcher[0][2]
                             jarVersion = (jarVersion =~ /([a-zA-Z-_]+)/).replaceAll("")
                             jarVersion = (jarVersion =~ /[\.-]*$/).replaceAll("")
-                            packageInfoSet = [] as Set
+                            def packageInfoSet = [] as Set
                             // extract each entry from the jar file
-                            jarFile = new JarFile(file.absolutePath)
+                            def jarFile = new JarFile(file.absolutePath)
                             jarFile.entries().each { entry ->
                                 // copy each entry over into the destination jar
-                                outEntry = new JarEntry(entry.getName())
+                                def outEntry = new JarEntry(entry.getName())
                                 outEntry.setTime(entry.getTime())
                                 try {
                                     outputJar.putNextEntry(outEntry)
                                     if (! entry.isDirectory()) {
                                         outputJar.write(
                                             jarFile.getInputStream(entry).getBytes())
-                                        cfMatcher = entry.getName() =~ classFilePattern
+                                        def cfMatcher = entry.getName() =~ classFilePattern
                                         if (cfMatcher.matches()) {
-                                            dir = cfMatcher[0][1]
+                                            def dir = cfMatcher[0][1]
                                             if (!packageInfoSet.contains(dir)) {
                                                 packageInfoSet.add(dir)
-                                                packageEntry = new JarEntry(dir + "/packageinfo")
+                                                def packageEntry = new JarEntry(dir + "/packageinfo")
                                                 outputJar.putNextEntry(packageEntry)
                                                 outputJar.write(("version " + jarVersion).getBytes("utf-8"))
                                             }
                 
                 excludedJars.each{jarPath -> analyzer.addClasspath(new File(jarPath))}
                 java.util.jar.Manifest manifest = analyzer.calcManifest()
-                jarFile = new File(oldJar.toString())
-                tmpFileName = oldJar.toString() + ".tmp"
+                def jarFile = new File(oldJar.toString())
+                def tmpFileName = oldJar.toString() + ".tmp"
                 log.debug("Renaming (Copying due to windows jdk bug)" + oldJar.toString() + " to " + tmpFileName)
                 new File(tmpFileName) << jarFile.bytes
         
-                outputJar = new JarOutputStream(
+                def outputJar = new JarOutputStream(
                                 new FileOutputStream(oldJar.toString()))
                 log.debug("Creating a new jar file " + oldJar.toString())
-                jarFileHandle = new File(tmpFileName)
+                def jarFileHandle = new File(tmpFileName)
                 jarFile = new JarFile(jarFileHandle) // , false, java.util.zip.ZipFile.OPEN_DELETE)
                 jarFile.entries().each { entry ->
                     if (entry.toString() != "META-INF/MANIFEST.MF") {
-                        outEntry = new JarEntry(entry.getName())
+                        def outEntry = new JarEntry(entry.getName())
                         outEntry.setTime(entry.getTime())
                         try {
                             outputJar.putNextEntry(outEntry)
                 jarFile.close();
                 log.debug("Deleting file " + tmpFileName)
                 new File(tmpFileName).delete();
-                jarEntry = new JarEntry("META-INF/MANIFEST.MF")
+                def jarEntry = new JarEntry("META-INF/MANIFEST.MF")
                 outputJar.putNextEntry(jarEntry)
                 manifest.write(outputJar)
                 outputJar.close()
             }
 
             project.tasks.install.repositories.mavenInstaller.pom.whenConfigured {pom ->
-                exclusions = project.configurations.exclusions.dependencies.collect { dep ->
+                def exclusions = project.configurations.exclusions.dependencies.collect { dep ->
                                     [dep.group, dep.name, dep.version] }
-                condensed = pom.dependencies.findAll { dep -> !exclusions.contains([dep.groupId,dep.artifactId,dep.version]) }
-                constrs = condensed.collect {
-                    vals = [it.groupId,it.artifactId,it.version]
+                def condensed = pom.dependencies.findAll { dep -> !exclusions.contains([dep.groupId,dep.artifactId,dep.version]) }
+                def constrs = condensed.collect {
+                    def vals = [it.groupId,it.artifactId,it.version]
                     if(it.type != null) { vals.add(it.type) }
                     vals.join(":")
                 }.join(",")