You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2019/06/02 15:39:19 UTC

[lucene-solr] 04/05: SOLR-13452: Don't include internal module outputs in jarChecksums.

This is an automated email from the ASF dual-hosted git repository.

markrmiller pushed a commit to branch jira/SOLR-13452_gradle_3
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 3be713bcbb88a0c424b2b248323846e55e753d03
Author: markrmiller <ma...@apache.org>
AuthorDate: Sun Jun 2 10:38:41 2019 -0500

    SOLR-13452: Don't include internal module outputs in jarChecksums.
---
 .../org/apache/lucene/gradle/JarChecksum.groovy    | 80 ++++++++++++++--------
 lucene/build.gradle                                |  9 +--
 solr/build.gradle                                  |  8 +--
 3 files changed, 57 insertions(+), 40 deletions(-)

diff --git a/buildSrc/src/main/groovy/org/apache/lucene/gradle/JarChecksum.groovy b/buildSrc/src/main/groovy/org/apache/lucene/gradle/JarChecksum.groovy
index 3a32b30..e21bccc 100644
--- a/buildSrc/src/main/groovy/org/apache/lucene/gradle/JarChecksum.groovy
+++ b/buildSrc/src/main/groovy/org/apache/lucene/gradle/JarChecksum.groovy
@@ -15,6 +15,10 @@ package org.apache.lucene.gradle
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
+import org.gradle.api.artifacts.ResolvedArtifact
+
+import javax.inject.Inject
 import org.gradle.api.DefaultTask
 import org.gradle.api.artifacts.Configuration
 import org.gradle.api.file.RelativePath
@@ -29,43 +33,65 @@ import java.nio.file.Files
 
 class JarChecksum extends DefaultTask {
   
-  @InputDirectory
-  File inputDir
+  private File inputDir
   
-  @OutputDirectory
-  File target
+  private File target
   
-  @TaskAction
-  void checksums() {
-    def skip = ['testRuntimeClasspath', 'testCompileClasspath']
-    
-    project.delete project.fileTree(dir: target.getAbsolutePath(), include: '**/*.jar.sha1')
+  @Inject
+  public JarChecksum(File inputDir,  File target) {
     
-    File tmpDir = File.createTempDir()
-    tmpDir.deleteOnExit()
-    tmpDir.mkdirs()
     
-    project.allprojects.each { p ->
-      p.configurations.each { Configuration config ->
-        if (skip.contains(config.name)) {  
-          config.files.each {
-            File destFile = new File(tmpDir, it.name)
-            if (it.name.endsWith(".jar") && it.exists() && !destFile.exists()) {
-              Files.copy(it.toPath(), destFile.toPath());
+    doLast({
+      File tmpDir = File.createTempDir()
+      tmpDir.deleteOnExit()
+      tmpDir.mkdirs()
+      
+      List<File> deps = new ArrayList<>()
+      project.allprojects.each { p ->
+        p.configurations.each { Configuration config ->
+          if (config.isCanBeResolved()) {
+            config.getResolvedConfiguration().getResolvedArtifacts().forEach( { ra -> deps.add(ra.getFile()) })
+            // exclude our jar and jarTest outputs
+            def ourJars = new ArrayList()
+            project.rootProject.subprojects.each{ subproject ->
+              if (subproject.hasProperty('jar')) {
+                ourJars.addAll(subproject.jar.outputs.files)
+                if (subproject.hasProperty('jarTest')) {
+                  ourJars.addAll(subproject.jarTest.outputs.files)
+                }
+              }
+            }
+            deps = deps - ourJars
+            
+            // copy files to tmp dir
+            deps.each {
+              def file = it
+              File destFile = new File(tmpDir, file.name)
+              if (file.name.endsWith(".jar") && file.exists() && !destFile.exists()) {
+                Files.copy(file.toPath(), destFile.toPath())
+              }
             }
           }
         }
-        
       }
-    }
-    
-    ant.checksum(algorithm: "SHA1", fileext: ".sha1", todir: target.getAbsolutePath()) {
-      ant.fileset(dir: tmpDir.getAbsolutePath())
-    }
+      
+      project.delete project.fileTree(dir: target.getAbsolutePath(), include: '**/*.jar.sha1')
+      
+      ant.checksum(algorithm: "SHA1", fileext: ".sha1", todir: target.getAbsolutePath()) {
+        ant.fileset(dir: tmpDir.getAbsolutePath())
+      }
+      
+      project.delete(tmpDir)
+      
+      ant.fixcrlf(srcdir: target.getAbsolutePath(), includes: "**/*.jar.sha1", eol: "lf", fixlast: "true", encoding: "US-ASCII")
+      
+    })
     
-    project.delete(tmpDir)
+  }
+  
+  @TaskAction
+  void checksums() {
     
-    ant.fixcrlf(srcdir: target.getAbsolutePath(), includes: "**/*.jar.sha1", eol: "lf", fixlast: "true", encoding: "US-ASCII")
   }
 }
 
diff --git a/lucene/build.gradle b/lucene/build.gradle
index c2c726c..712389e 100644
--- a/lucene/build.gradle
+++ b/lucene/build.gradle
@@ -16,6 +16,7 @@
  */
 
 import org.apache.lucene.gradle.LicenseCheckTask
+import org.apache.lucene.gradle.JarChecksum
 
 subprojects {
   group = 'org.apache.lucene'
@@ -26,13 +27,7 @@ def distDir = "dist"
 tasks.create("checkLicenses", LicenseCheckTask, new File(projectDir.getAbsolutePath()
     + System.properties['file.separator'] + "licenses"))
 
-
-task jarChecksum(type: org.apache.lucene.gradle.JarChecksum) {
-  group = 'Build'
-  description = "Generates checksums for Lucene dependency jars."
-  inputDir = new File(project.rootProject.projectDir, "/lucene")
-  target = new File(project.rootProject.projectDir, "/lucene/licenses")
-}
+tasks.create("jarChecksums", JarChecksum, new File(project.rootProject.projectDir, "/lucene"), new File(project.rootProject.projectDir, "/lucene/licenses"))
 
 task packageDist(type: org.apache.lucene.gradle.PackageLuceneSolrDist) {
   group = 'Dist'
diff --git a/solr/build.gradle b/solr/build.gradle
index d1f7dad..2f06581 100644
--- a/solr/build.gradle
+++ b/solr/build.gradle
@@ -16,6 +16,7 @@
  */
 
 import org.apache.lucene.gradle.LicenseCheckTask
+import org.apache.lucene.gradle.JarChecksum
 
 subprojects {
   group = 'org.apache.solr'
@@ -26,12 +27,7 @@ def distDir = "dist"
 tasks.create("checkLicenses", LicenseCheckTask, new File(projectDir.getAbsolutePath()
     + System.properties['file.separator'] + "licenses"))
 
-task jarChecksum(type: org.apache.lucene.gradle.JarChecksum) {
-  group = 'Build'
-  description = "Generates checksums for dependency Solr jars."
-  inputDir = new File(project.rootProject.projectDir, "/solr")
-  target = new File(project.rootProject.projectDir, "/solr/licenses")
-}
+tasks.create("jarChecksums", JarChecksum, new File(project.rootProject.projectDir, "/solr"), new File(project.rootProject.projectDir, "/solr/licenses"))
 
 task packageDist(type: org.apache.lucene.gradle.PackageLuceneSolrDist) {
   group = 'Dist'