You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by th...@apache.org on 2020/09/14 16:38:23 UTC

[lucene-solr] 05/39: LUCENE-9438: Eclipse IDE support with gradle build system (#1761)

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

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

commit ed27e861a21ed6185f034fb1bc24a1bcd8acddf2
Author: Dawid Weiss <dw...@apache.org>
AuthorDate: Fri Aug 21 21:47:11 2020 +0200

    LUCENE-9438: Eclipse IDE support with gradle build system (#1761)
---
 build.gradle                |   5 ++-
 gradle/defaults-java.gradle |  10 ++++-
 gradle/help.gradle          |   1 +
 gradle/ide/eclipse.gradle   | 102 ++++++++++++++++++++++++++++++++++++++++++++
 help/IDEs.txt               |  20 +++++++++
 5 files changed, 135 insertions(+), 3 deletions(-)

diff --git a/build.gradle b/build.gradle
index 5e2f799..f145c73 100644
--- a/build.gradle
+++ b/build.gradle
@@ -21,8 +21,8 @@ import java.time.format.DateTimeFormatter
 plugins {
   id "base"
   id "com.palantir.consistent-versions" version "1.14.0"
-  id 'de.thetaphi.forbiddenapis' version '3.0.1' apply false
   id "org.owasp.dependencycheck" version "5.3.0"
+  id 'de.thetaphi.forbiddenapis' version '3.0.1' apply false
   id "de.undercouch.download" version "4.0.2" apply false
 }
 
@@ -63,6 +63,8 @@ ext {
   buildTime = DateTimeFormatter.ofPattern("HH:mm:ss").format(tstamp)
   buildYear = DateTimeFormatter.ofPattern("yyyy").format(tstamp)
 
+  minJavaVersion = JavaVersion.VERSION_11
+
   // Declare script dependency versions outside of palantir's
   // version unification control. These are not our main dependencies.
   scriptDepVersions = [
@@ -102,6 +104,7 @@ apply from: file('gradle/maven/defaults-maven.gradle')
 
 // IDE support, settings and specials.
 apply from: file('gradle/ide/intellij-idea.gradle')
+apply from: file('gradle/ide/eclipse.gradle')
 
 // Validation tasks
 apply from: file('gradle/validation/precommit.gradle')
diff --git a/gradle/defaults-java.gradle b/gradle/defaults-java.gradle
index 4d0fae7..e739a19 100644
--- a/gradle/defaults-java.gradle
+++ b/gradle/defaults-java.gradle
@@ -19,9 +19,15 @@
 
 allprojects {
   plugins.withType(JavaPlugin) {
-    sourceCompatibility = "11"
-    targetCompatibility = "11"
+    sourceCompatibility = rootProject.minJavaVersion
+    targetCompatibility = rootProject.minJavaVersion
 
+    // Use 'release' flag instead of 'source' and 'target'
+    tasks.withType(JavaCompile) {
+      options.compilerArgs += ["--release", rootProject.minJavaVersion.toString()]
+    }
+
+    // Configure warnings.
     tasks.withType(JavaCompile) {
       options.encoding = "UTF-8"
       options.compilerArgs += [
diff --git a/gradle/help.gradle b/gradle/help.gradle
index edee1c3..51435e1 100644
--- a/gradle/help.gradle
+++ b/gradle/help.gradle
@@ -28,6 +28,7 @@ configure(rootProject) {
       ["LocalSettings", "help/localSettings.txt", "Local settings, overrides and build performance tweaks."],
       ["Git", "help/git.txt", "Git assistance and guides."],
       ["ValidateLogCalls", "help/validateLogCalls.txt", "How to use logging calls efficiently."],
+      ["IDEs", "help/IDEs.txt", "IDE support."],
   ]
 
   helpFiles.each { section, path, sectionInfo ->
diff --git a/gradle/ide/eclipse.gradle b/gradle/ide/eclipse.gradle
new file mode 100644
index 0000000..3bebd1d
--- /dev/null
+++ b/gradle/ide/eclipse.gradle
@@ -0,0 +1,102 @@
+/*
+ * 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.
+ */
+
+import org.gradle.plugins.ide.eclipse.model.SourceFolder
+import org.gradle.plugins.ide.eclipse.model.ClasspathEntry
+
+configure(rootProject) {
+  apply plugin: "eclipse"
+
+  def relativize = { other -> rootProject.rootDir.relativePath(other).toString() }
+
+  eclipse {
+    project {
+      name = "Apache Lucene Solr ${version}"
+    }
+
+    classpath {
+      defaultOutputDir = file('build/eclipse')
+
+      file {
+        beforeMerged { classpath -> classpath.entries.removeAll { it.kind == "src" } }
+
+        whenMerged { classpath ->
+          def projects = allprojects.findAll { prj ->
+            return prj.plugins.hasPlugin(JavaPlugin) &&
+                   prj.path != ":solr:solr-ref-guide"
+          }
+
+          Set<String> sources = []
+          Set<File> jars = []
+          projects.each { prj ->
+            prj.sourceSets.each { sourceSet ->
+              sources += sourceSet.java.srcDirs.findAll { dir -> dir.exists() }.collect { dir -> relativize(dir) }
+            }
+
+            // This is hacky - we take the resolved compile classpath and just
+            // include JAR files from there. We should probably make it smarter
+            // by looking at real dependencies. But then: this Eclipse configuration
+            // doesn't really separate sources anyway so why bother.
+            jars += prj.configurations.compileClasspath.resolve()
+            jars += prj.configurations.testCompileClasspath.resolve()
+          }
+
+          classpath.entries += sources.sort().collect {name -> new SourceFolder(name, "build/eclipse/" + name) }
+          classpath.entries += jars.unique().findAll { location -> location.isFile() }.collect { location ->
+            new LibEntry(location.toString())
+          }
+        }
+      }
+    }
+
+    jdt {
+      sourceCompatibility = rootProject.minJavaVersion
+      targetCompatibility = rootProject.minJavaVersion
+      javaRuntimeName = "JavaSE-${rootProject.minJavaVersion}"
+    }
+  }
+
+  eclipseJdt {
+    doLast {
+      project.sync {
+        from rootProject.file("dev-tools/eclipse/dot.settings")
+        into rootProject.file(".settings")
+      }
+    }
+  }
+}
+
+public class LibEntry implements ClasspathEntry {
+  private String path;
+
+  LibEntry(String path) {
+    this.path = path;
+  }
+
+  @Override
+  String getKind() {
+    return "lib"
+  }
+
+  @Override
+  void appendNode(Node node) {
+    node.appendNode("classpathentry", Map.of(
+        "kind", "lib",
+        "path", path
+    ));
+  }
+}
diff --git a/help/IDEs.txt b/help/IDEs.txt
new file mode 100644
index 0000000..3ad5b85
--- /dev/null
+++ b/help/IDEs.txt
@@ -0,0 +1,20 @@
+IntelliJ IDEA
+=============
+
+Importing the project as a gradle project should just run out of the box.
+
+
+Eclipse
+=======
+
+Run the following to set up Eclipse project files:
+
+./gradlew eclipse
+
+then import the project into Eclipse with:
+
+File -> Import... -> Existing Project into Workspace
+
+Please note that Eclipse does not distinguish between sub-projects
+and package sets (main/ test) so pretty much all the sources and dependencies
+are available in one large bin.