- project {
- name = "Jalview with gradle build"
-
- natures 'org.eclipse.jdt.core.javanature',
- 'org.eclipse.jdt.groovy.core.groovyNature',
- 'org.eclipse.buildship.core.gradleprojectnature'
-
- buildCommand 'org.eclipse.jdt.core.javabuilder'
- buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
- }
-
- classpath {
- //defaultOutputDir = sourceSets.main.java.outputDir
- def removeThese = []
- configurations.each{ if (it.isCanBeResolved()) {
- removeThese += it
- }
- }
- containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
-
- minusConfigurations += removeThese
- plusConfigurations = [ ]
- file {
-
- whenMerged { cp ->
- def removeTheseToo = []
- HashMap<String, Boolean> addedSrcPath = new HashMap<>();
- cp.entries.each { entry ->
- if (entry.kind == 'src') {
- if (addedSrcPath.getAt(entry.path) || !(entry.path == "src" || entry.path == "test" || entry.path == "resources")) {
- removeTheseToo += entry
- } else {
- addedSrcPath.putAt(entry.path, true)
- }
- }
- }
- cp.entries.removeAll(removeTheseToo)
- }
-
- withXml {
- def node = it.asNode()
- def srcTestAttributes
- node.children().each{ cpe ->
- def attributes = cpe.attributes()
- if (attributes.get("kind") == "src" && attributes.get("path") == "test") {
- srcTestAttributes = cpe.find { a -> a.name() == "attributes" }
- return
- }
- }
- def addTestAttribute = true
- srcTestAttributes.each{a ->
- if (a.name() == "attribute" && a.attributes().getAt("name") == "test") {
- addTestAttribute = false
- }
- }
- if (addTestAttribute) {
- srcTestAttributes.append(new Node(null, "attribute", [name:"test", value:"true"]))
- }
-
- node.appendNode('classpathentry', [kind:"output", path:"bin/main"])
- HashMap<String, Boolean> addedLibPath = new HashMap<>();
- def allPaths = sourceSets.test.compileClasspath + sourceSets.main.compileClasspath
- sourceSets.main.compileClasspath.each{
- //if ((it.isDirectory() || ! it.exists()) && ! (it.equals(sourceSets.main.java.outputDir))) {
- //no longer want to add outputDir as eclipse is using its own output dir in bin/main
- if (it.isDirectory() || ! it.exists()) {
- // don't add dirs to classpath
- //println("Not adding directory "+it)
- return
- }
- def itPath = it.toString()
- if (itPath.startsWith(jalviewDirAbsolutePath+"/")) {
- itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
- }
- if (addedLibPath.get(itPath)) {
- //println("Not adding duplicate entry "+itPath)
- } else {
- //println("Adding entry "+itPath)
- node.appendNode('classpathentry', [kind:"lib", path:itPath])
- addedLibPath.put(itPath, true)
- }
- }
- sourceSets.test.compileClasspath.each{
- //if ((it.isDirectory() || ! it.exists()) && ! (it.equals(sourceSets.main.java.outputDir))) {
- //no longer want to add outputDir as eclipse is using its own output dir in bin/main
- if (it.isDirectory() || ! it.exists()) {
- // don't add dirs to classpath
- //println("Not adding directory "+it)
- return
- }
- def itPath = it.toString()
- if (itPath.startsWith(jalviewDirAbsolutePath+"/")) {
- itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
- }
- if (addedLibPath.get(itPath)) {
- //println("Not adding duplicate entry "+itPath)
- } else {
- //println("Adding entry "+itPath)
- node.appendNode('classpathentry', [kind:"lib", path:itPath])
- .appendNode('attributes')
- .appendNode('attribute', [name:"test", value:"true"])
- addedLibPath.put(itPath, true)
- }
- }
- }
-
- }
- }
-
- jdt {
- // for the IDE, use java 11 compatibility
- sourceCompatibility = 11
- targetCompatibility = 11
- javaRuntimeName = "JavaSE-11"
-
- file {
- withProperties { props ->
- def jalview_prefs = new Properties()
- def ins = new FileInputStream(eclipse_extra_jdt_prefs_file)
- jalview_prefs.load(ins)
- ins.close()
- jalview_prefs.forEach { t, v ->
- if (props.getAt(t) == null) {
- props.putAt(t, v)
+ project {
+ name = "Jalview with gradle build"
+
+ natures 'org.eclipse.jdt.core.javanature',
+ 'org.eclipse.jdt.groovy.core.groovyNature',
+ 'org.eclipse.buildship.core.gradleprojectnature'
+
+ buildCommand 'org.eclipse.jdt.core.javabuilder'
+ buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
+ }
+
+ classpath {
+ //defaultOutputDir = sourceSets.main.java.outputDir
+ def removeThese = []
+ configurations.each{ if (it.isCanBeResolved()) {
+ removeThese += it
+ }
+ }
+
+ minusConfigurations += removeThese
+ plusConfigurations = [ ]
+ file {
+
+ whenMerged { cp ->
+ def removeTheseToo = []
+ HashMap<String, Boolean> addedSrcPath = new HashMap<>();
+ cp.entries.each { entry ->
+ if (entry.kind == 'src') {
+ if (addedSrcPath.getAt(entry.path) || !(entry.path == "src" || entry.path == "test")) {
+ removeTheseToo += entry
+ } else {
+ addedSrcPath.putAt(entry.path, true)
+ }
+ }
+ }
+ cp.entries.removeAll(removeTheseToo)
+
+ print ("CP="+cp.inspect())
+
+ cp.entries += new Output("bin/main")
+ cp.entries += new Library(fileReference(helpParentDir))
+ cp.entries += new Library(fileReference(resourceDir))
+
+ HashMap<String, Boolean> addedLibPath = new HashMap<>();
+
+ // changing from sourcesets.main.classpath to specific Java version lib
+ //sourceSets.main.compileClasspath.each{
+ fileTree("$jalviewDir/$libDistDir").include("**/*.jar").include("*.jar").each {
+ //don't want to add outputDir as eclipse is using its own output dir in bin/main
+ if (it.isDirectory() || ! it.exists()) {
+ // don't add dirs to classpath
+ return
+ }
+ def itPath = it.toString()
+ if (itPath.startsWith(jalviewDirAbsolutePath+"/")) {
+ itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
+ }
+ if (addedLibPath.get(itPath)) {
+ //println("Not adding duplicate entry "+itPath)
+ } else {
+ //println("Adding entry "+itPath)
+ cp.entries += new Library(fileReference(itPath))
+ addedLibPath.put(itPath, true)
+ }
+ }
+
+ // changing from sourcesets.main.classpath to specific Java version lib
+ //sourceSets.test.compileClasspath.each{
+ fileTree(dir: "$jalviewDir/$utilsDir", include: ["**/*.jar"]).each {
+ //if ((it.isDirectory() || ! it.exists()) && ! (it.equals(sourceSets.main.java.outputDir))) {
+ //no longer want to add outputDir as eclipse is using its own output dir in bin/main
+ if (it.isDirectory() || ! it.exists()) {
+ // don't add dirs to classpath
+ return false // groovy "break" in .each loop
+ }
+ def itPath = it.toString()
+ if (itPath.startsWith(jalviewDirAbsolutePath+"/")) {
+ itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
+ }
+ if (addedLibPath.get(itPath)) {
+ // don't duplicate
+ } else {
+ def lib = new Library(fileReference(itPath))
+ // this doesn't work... yet. Adding test=true attribute using withXml below
+ //def attrs = new Node(null, 'attributes', ["test":"true"])
+ //lib.appendNode(attrs) //
+ cp.entries += lib
+ addedLibPath.put(itPath, true)
+ }
+ }
+ }
+
+ // withXml changes ignored by buildship, these add the "test=true" attribute
+ withXml {
+ def node = it.asNode()
+
+ def srcTestAttributes
+ node.children().each{ cpe ->
+ def attributes = cpe.attributes()
+ if (attributes.get("kind") == "src" && attributes.get("path") == "test") {
+ srcTestAttributes = cpe.find { a -> a.name() == "attributes" }
+ return
+ }
+ }
+ def addTestAttribute = true
+ srcTestAttributes.each{a ->
+ if (a.name() == "attribute" && a.attributes().getAt("name") == "test") {
+ addTestAttribute = false
+ }
+ }
+ if (addTestAttribute) {
+ srcTestAttributes.append(new Node(null, "attribute", [name:"test", value:"true"]))
+ }
+
+ node.children().each{ cpe ->
+ def attributes = cpe.attributes()
+ if (attributes.get("kind") == "lib" && attributes.get("path").startsWith("utils/")) {
+ cpe.appendNode('attributes')
+ .appendNode('attribute', [name:"test", value:"true"])
+ }
+ }
+ } // withXML
+ } // file
+
+ containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
+ } // classpath
+
+ jdt {
+ // for the IDE, use java 11 compatibility
+ sourceCompatibility = compile_source_compatibility
+ targetCompatibility = compile_target_compatibility
+ javaRuntimeName = eclipse_java_runtime_name
+
+ file {
+ withProperties { props ->
+ def jalview_prefs = new Properties()
+ def ins = new FileInputStream(jalviewDirAbsolutePath+"/"+eclipse_extra_jdt_prefs_file)
+ jalview_prefs.load(ins)
+ ins.close()
+ jalview_prefs.forEach { t, v ->
+ if (props.getAt(t) == null) {
+ props.putAt(t, v)
+ }
+ }