You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/03/18 22:43:31 UTC

[06/14] incubator-geode git commit: GEODE-27: A couple of tools to dump dependencies

GEODE-27: A couple of tools to dump dependencies

Adding a task to dump all jars in the binary distribution

This makes it easy to see what dependencies we actually end up shipping
with the product. This dumps all jars found in the distribution or
embedded within war files in the distribution.

Adding a task to determine if a dependency is used

This task checks to see if a dependency is used in the source code.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/5839e4d2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/5839e4d2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/5839e4d2

Branch: refs/heads/feature/GEODE-1050
Commit: 5839e4d2a741dd0b84ce0ed20588fb5bb2d62565
Parents: 0d86c3b
Author: Dan Smith <up...@apache.org>
Authored: Tue Mar 8 16:23:39 2016 -0800
Committer: Dan Smith <up...@apache.org>
Committed: Fri Mar 18 13:43:55 2016 -0700

----------------------------------------------------------------------
 build.gradle                        |  1 +
 geode-assembly/build.gradle         | 29 ++++++++++
 gradle/dependency-resolution.gradle | 98 ++++++++++++++++++++++++++++++++
 3 files changed, 128 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5839e4d2/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index 19f72a0..200dd8a 100755
--- a/build.gradle
+++ b/build.gradle
@@ -74,6 +74,7 @@ if (name == 'geode') {
 
 apply from: "${scriptDir}/utilities.gradle"
 apply from: "${scriptDir}/java.gradle"
+apply from: "${scriptDir}/dependency-resolution.gradle"
 apply from: "${scriptDir}/test.gradle"
 apply from: "${scriptDir}/publish.gradle"
 apply from: "${scriptDir}/code-analysis.gradle"

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5839e4d2/geode-assembly/build.gradle
----------------------------------------------------------------------
diff --git a/geode-assembly/build.gradle b/geode-assembly/build.gradle
index d2a5a65..2213614 100755
--- a/geode-assembly/build.gradle
+++ b/geode-assembly/build.gradle
@@ -363,3 +363,32 @@ integrationTest dependOnInstalledProduct
 build.dependsOn installDist
 
 installDist.dependsOn ':extensions/geode-modules-assembly:dist'
+
+/**Print the names of all jar files in a fileTree */
+def printJars(tree) {
+  tree.matching {include("**/*.jar")}.visit{ file -> 
+    if(!file.isDirectory()) {
+      println file.name
+    }
+  };
+}
+
+task dumpInstalledJars(dependsOn: installDist) << {
+  description "Dump a list of all of the jars shipped with the binary distribution, for validation purposes"
+
+  FileTree installDir = fileTree(dir: installDist.destinationDir)
+
+  println("Jars in the binary install")
+  println("==========================")
+  printJars(installDir)
+
+  installDir.include("**/*.war").visit{ file -> 
+    if(!file.isDirectory()) {
+        FileTree warContents = zipTree(file.file)
+        println ""
+        println file.name
+        println("==========================")
+        printJars(warContents);
+    } 
+  };
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5839e4d2/gradle/dependency-resolution.gradle
----------------------------------------------------------------------
diff --git a/gradle/dependency-resolution.gradle b/gradle/dependency-resolution.gradle
new file mode 100644
index 0000000..1e2b62b
--- /dev/null
+++ b/gradle/dependency-resolution.gradle
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+subprojects {
+  configurations.all {
+    resolutionStrategy {
+    //  failOnVersionConflict()
+
+//    exclude module: 'aopalliance'
+  //    exclude 'asm'
+  //    exclude 'aspectjweaver'
+  //    exclude 'cglib'
+      
+
+  // Force certain versions of transitive dependencies
+  //    force 'asm:asm-all:3.3.1'
+  //    force 'asm:asm-all:3.3.1'
+    }
+  }
+
+  //Task to dump all depencies of all projects, in a way
+  //that can be diffed before and after dependency changes
+  task dumpDependencies() << {
+    description "Dump all of the dependencies as a flat, sorted list"
+
+    project.configurations.each{ configuration -> 
+      println( project.name + ":" + configuration.name )
+      println( '-------------------')
+      configuration.resolvedConfiguration.resolvedArtifacts.collect{dep -> dep.file.name}.unique().toSorted().each{dep ->
+        println(dep)
+      }
+      println()
+    }
+  }
+
+  //Task to find all of the jars in a compile task
+  //that are unused
+  task findUsage() << {
+    description "Find usages of a jar in the source code"
+
+    String jarName = System.getProperty("jar.name")
+    if(jar == null || jar == "")  {
+      println "You must specify a jar name: ./gradlew findUsage -Djar.name=commons-io"
+      return
+    }
+    FileTree sourceFiles = compileJava.source
+    FileCollection jars = compileJava.classpath
+
+    File jar = jars.find{file -> file.name.contains(jarName)}
+
+    FileTree jarContents = zipTree(jar)
+    Set packages = new HashSet()
+    jarContents.visit{file -> 
+      if(!file.isDirectory() && !file.path.contains("META-INF")) {
+        packages.add(file.relativePath.parent.toString().replace('/', '.'))
+      }
+    }
+
+    println("Packages")
+    println "========"
+    packages.each { p -> println p  }
+
+    println ""
+    println("Matches")
+    println "========"
+    sourceFiles.visit{ file -> 
+      if(!file.isDirectory()) {
+        boolean matches = false;
+        file.file.eachLine { line ->
+        def matcher = line =~ /^import (.*)\..*;/
+          if(matcher) {
+            def pack = matcher[0][1]
+//            println pack
+            matches |= packages.contains(pack)
+          }
+        }
+
+        if(matches) {
+          println file.relativePath;
+        }
+      }
+    }
+  }
+
+}