2020-08-21 15:47:11 -04:00
/ *
* 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 .
* /
2021-03-26 19:42:29 -04:00
import org.apache.tools.ant.filters.ReplaceTokens ;
2020-08-21 15:47:11 -04:00
import org.gradle.plugins.ide.eclipse.model.SourceFolder
import org.gradle.plugins.ide.eclipse.model.ClasspathEntry
2020-08-31 09:09:26 -04:00
def resources = scriptResources ( buildscript )
2020-08-21 15:47:11 -04:00
configure ( rootProject ) {
apply plugin: "eclipse"
2022-09-27 05:11:49 -04:00
def eclipseJavaVersion = propertyOrDefault ( "eclipse.javaVersion" , rootProject . minJavaVersion )
2020-08-21 15:47:11 -04:00
def relativize = { other - > rootProject . rootDir . relativePath ( other ) . toString ( ) }
eclipse {
project {
2021-03-18 06:04:45 -04:00
name = "Apache Lucene ${version}"
2020-08-21 15:47:11 -04:00
}
classpath {
defaultOutputDir = file ( 'build/eclipse' )
file {
beforeMerged { classpath - > classpath . entries . removeAll { it . kind = = "src" } }
whenMerged { classpath - >
def projects = allprojects . findAll { prj - >
2021-03-18 06:04:45 -04:00
return prj . plugins . hasPlugin ( JavaPlugin )
2020-08-21 15:47:11 -04:00
}
2022-09-27 05:11:49 -04:00
2022-11-10 11:18:30 -05:00
Set < String > sourceSetNames = [ 'main' , 'test' , "main${eclipseJavaVersion}" as String , "test${eclipseJavaVersion}" as String , 'tools' ] as Set
2020-08-21 15:47:11 -04:00
Set < String > sources = [ ]
Set < File > jars = [ ]
projects . each { prj - >
prj . sourceSets . each { sourceSet - >
2022-09-27 05:11:49 -04:00
if ( sourceSetNames . contains ( sourceSet . name ) ) {
sources + = sourceSet . java . srcDirs . findAll { dir - > dir . exists ( ) } . collect { dir - > relativize ( dir ) }
sources + = sourceSet . resources . srcDirs . findAll { dir - > dir . exists ( ) } . collect { dir - > relativize ( dir ) }
}
2020-08-21 15:47:11 -04:00
}
// 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 ( )
}
2021-12-19 02:51:13 -05:00
classpath . entries + = sources . sort ( ) . collect { name - >
def sourceFolder = new SourceFolder ( name , "build/eclipse/" + name )
sourceFolder . setExcludes ( [ "module-info.java" ] )
return sourceFolder
}
2022-06-24 13:42:42 -04:00
classpath . entries + = jars . unique ( ) . findAll { location - > location . isFile ( ) & & ! ( location . name = = ~ /lucene-.*\.jar/ ) } . collect { location - >
2020-08-21 15:47:11 -04:00
new LibEntry ( location . toString ( ) )
}
}
}
}
jdt {
2022-09-27 05:11:49 -04:00
sourceCompatibility = eclipseJavaVersion
targetCompatibility = eclipseJavaVersion
javaRuntimeName = "JavaSE-$eclipseJavaVersion"
2020-08-21 15:47:11 -04:00
}
}
2021-03-27 07:08:12 -04:00
task luceneEclipseJdt ( type: Sync ) {
2021-03-26 19:42:29 -04:00
def errorMode = project . propertyOrDefault ( 'eclipse.errors' , 'warning' ) ;
def ecjLintFile = rootProject . file ( 'gradle/validation/ecj-lint/ecj.javadocs.prefs' ) ;
2021-03-27 07:08:12 -04:00
description = 'Generates the Eclipse JDT settings file.'
2021-03-26 19:42:29 -04:00
inputs . file ( ecjLintFile )
inputs . property ( 'errorMode' , errorMode )
2022-09-27 05:11:49 -04:00
inputs . property ( 'eclipseJavaVersion' , eclipseJavaVersion as String )
2021-03-26 19:42:29 -04:00
2021-03-27 07:08:12 -04:00
from rootProject . file ( "${resources}/dot.settings" )
into rootProject . file ( ".settings" )
filter ( ReplaceTokens , tokens: [
'ecj-lint-config' : ecjLintFile . getText ( 'UTF-8' ) . replaceAll ( /=error\b/ , '=' + errorMode )
] )
filteringCharset = 'UTF-8'
2020-08-21 15:47:11 -04:00
doLast {
2022-09-27 05:11:49 -04:00
logger . lifecycle ( 'Eclipse config for Java {} written with ECJ errors configured as {}. Change by passing -Peclipse.errors=ignore/warning/error.' , eclipseJavaVersion , errorMode )
logger . lifecycle ( 'To edit classes of MR-JARs for a specific Java version, use e.g., -Peclipse.javaVersion=19' )
2020-08-21 15:47:11 -04:00
}
}
2021-03-27 07:08:12 -04:00
eclipseJdt {
enabled = false
dependsOn 'luceneEclipseJdt'
}
2022-09-27 05:11:49 -04:00
eclipseClasspath {
inputs . property ( 'eclipseJavaVersion' , eclipseJavaVersion as String )
}
2020-08-21 15:47:11 -04:00
}
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
) ) ;
}
}