You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by to...@apache.org on 2020/02/18 17:48:23 UTC

[lucene-solr] branch master updated: LUCENE-9219: Port ECJ-based linter to gradle

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

tomoko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new 2a88aa9  LUCENE-9219: Port ECJ-based linter to gradle
2a88aa9 is described below

commit 2a88aa9d0f77044d9a69cadf97683cc478b49063
Author: Dawid Weiss <dw...@apache.org>
AuthorDate: Wed Feb 19 02:43:47 2020 +0900

    LUCENE-9219: Port ECJ-based linter to gradle
    
    Co-authored-by: Tomoko Uchida <to...@apache.org>
---
 build.gradle                       |   7 ++-
 gradle/validation/ecj-lint.gradle  | 112 +++++++++++++++++++++++++++++++++++++
 gradle/validation/precommit.gradle |   1 +
 solr/solr-ref-guide/build.gradle   |   9 +++
 4 files changed, 128 insertions(+), 1 deletion(-)

diff --git a/build.gradle b/build.gradle
index 1661ac2..03637bd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -43,6 +43,7 @@ ext {
       "apache-rat": "0.11",
       "javacc": "5.0",
       "jflex": "1.7.0",
+      "ecj": "3.19.0"
   ]
 }
 
@@ -54,6 +55,10 @@ ext {
 
 apply from: file('gradle/generate-defaults.gradle')
 
+// Ant-compatibility layer: apply folder layout early so that
+// evaluation of other scripts doesn't need to be deferred.
+apply from: file('gradle/ant-compat/folder-layout.gradle')
+
 // Set up defaults and configure aspects for certain modules or functionality
 // (java, tests)
 apply from: file('gradle/defaults.gradle')
@@ -80,6 +85,7 @@ apply from: file('gradle/validation/validate-source-patterns.gradle')
 apply from: file('gradle/validation/config-file-sanity.gradle')
 apply from: file('gradle/validation/rat-sources.gradle')
 apply from: file('gradle/validation/owasp-dependency-check.gradle')
+apply from: file('gradle/validation/ecj-lint.gradle')
 
 // Source or data regeneration tasks
 apply from: file('gradle/generation/jflex.gradle')
@@ -99,7 +105,6 @@ apply from: file('gradle/help.gradle')
 // here so that we can coexist with current ant build but they are indicative
 // of potential problems with the build conventions, dependencies, etc.
 apply from: file('gradle/ant-compat/force-versions.gradle')
-apply from: file('gradle/ant-compat/folder-layout.gradle')
 apply from: file('gradle/ant-compat/misc.gradle')
 apply from: file('gradle/ant-compat/resolve.gradle')
 apply from: file('gradle/ant-compat/post-jar.gradle')
diff --git a/gradle/validation/ecj-lint.gradle b/gradle/validation/ecj-lint.gradle
new file mode 100644
index 0000000..5ae13c1
--- /dev/null
+++ b/gradle/validation/ecj-lint.gradle
@@ -0,0 +1,112 @@
+/*
+ * 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.
+ */
+
+// This adds 'ecjLint' task.
+
+configure(rootProject) {
+  configurations {
+    ecjDeps
+  }
+
+  dependencies {
+    ecjDeps "org.eclipse.jdt:ecj:${scriptDepVersions['ecj']}"
+  }
+}
+
+allprojects {
+  plugins.withType(JavaPlugin) {
+    // Create a [sourceSetName]EcjLint task for each source set
+    // with a non-empty java.srcDirs. These tasks are then
+    // attached to project's "ecjLint" task.
+    def lintTasks = sourceSets.collect { sourceSet ->
+      def srcDirs = sourceSet.java.srcDirs.findAll { dir -> dir.exists() }
+
+      tasks.create(sourceSet.getTaskName("ecjLint", null), JavaExec, {
+        // This dependency is on a configuration; technically it causes
+        // all dependencies to be resolved before this task executes
+        // (this includes scheduling tasks that compile the
+        // sources from other projects for example).
+        dependsOn sourceSet.compileClasspath
+
+        // The inputs are all source files from the sourceSet.
+        inputs.files sourceSet.allSource.asFileTree
+        // The outputs are always up to date (we don't generate anything).
+        outputs.upToDateWhen { true }
+
+        // We create a task for all source sets but ignore those
+        // that don't have any Java source directories.
+        enabled = !srcDirs.isEmpty()
+
+        classpath = rootProject.configurations.ecjDeps
+        main = "org.eclipse.jdt.internal.compiler.batch.Main"
+
+        // Don't emit any .class files.
+        // Hack around "-d none" still emitting package-info.class
+        // by running in a temporary directory.
+        def tmpDst = getTemporaryDir()
+        workingDir tmpDst
+
+        args += [ "-d", "none" ]
+
+        // Compilation environment.
+        args += [ "-source", project.java.sourceCompatibility ]
+        args += [ "-target", project.java.targetCompatibility ]
+        args += [ "-encoding", "UTF-8"]
+        args += [ "-proc:none" ]
+        args += [ "-nowarn" ]
+        args += [ "-enableJavadoc" ]
+        args += [ "-properties", project(":lucene").file("tools/javadoc/ecj.javadocs.prefs").absolutePath ]
+
+        doFirst {
+          tmpDst.mkdirs()
+
+          // Add classpath locations at execution time (can't resolve the
+          // configuration at evaluation time). Filter out non-existing entries
+          // (output folders for non-existing input source dirs like resources).
+          def cpath = sourceSet.compileClasspath.filter { p -> p.exists() }
+          if (!cpath.isEmpty()) {
+            args += ["-classpath", cpath.asPath]
+          }
+
+          // Add source location(s). Ideally we'd provide a set of files as in:
+          // args += sourceSet.java.files
+          // but this exceeds max allowed command line size. So we pass source
+          // directories instead:
+          args += srcDirs
+        }
+      })
+    }
+
+    task ecjLint() {
+      description "Lint Java sources using ECJ."
+      group "Verification"
+
+      dependsOn lintTasks
+    }
+
+    // Attach ecjLint to check.
+    check.dependsOn ecjLint
+  }
+}
+
+// This excludes solr-ref-guide from the check (excludes are not taken into account
+// and linting of the ant-based task fails.
+configure(project(":solr:solr-ref-guide")) {
+  afterEvaluate {
+    project.tasks.findByPath("ecjLintMain").enabled = false
+  }
+}
diff --git a/gradle/validation/precommit.gradle b/gradle/validation/precommit.gradle
index 7ba530e..f98952d 100644
--- a/gradle/validation/precommit.gradle
+++ b/gradle/validation/precommit.gradle
@@ -39,6 +39,7 @@ configure(rootProject) {
           "licenses",
           "javadoc",
           "rat",
+          "ecjLint"
       ]}
     }
   }
diff --git a/solr/solr-ref-guide/build.gradle b/solr/solr-ref-guide/build.gradle
index 5a40e27..7e68894 100644
--- a/solr/solr-ref-guide/build.gradle
+++ b/solr/solr-ref-guide/build.gradle
@@ -96,6 +96,9 @@ dependencies {
 sourceSets {
     refGuide {
         java {
+            srcDirs = []
+        }
+        resources {
             srcDirs = ['src']
         }
     }
@@ -107,6 +110,12 @@ sourceSets {
             exclude "**/asciidoctor-antlib.xml"
         }
     }
+
+    test {
+        java {
+            srcDirs = []
+        }
+    }
 }
 
 ext {