Skip to content

Commit 4f68914

Browse files
authored
Merge pull request #698 from tonihele/bugfix/gradle-fixes-tweaks
Bugfix/gradle fixes tweaks
2 parents ce9d702 + b910b4f commit 4f68914

1 file changed

Lines changed: 132 additions & 99 deletions

File tree

build.gradle

Lines changed: 132 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -309,146 +309,182 @@ createBaseXml.inputs.files configurations.corelibs.resolve()
309309
createBaseXml.outputs.file "jme3-core-baselibs/nbproject/project.xml"
310310
createBaseXml.outputs.file "jme3-core-libraries/nbproject/project.xml"
311311

312+
tasks.register('copyProjectBaseLibraries', Copy) {
313+
description = 'Copies JME base libraries (jars, sources, javadocs)'
314+
315+
from(configurations.corelibs)
316+
from(configurations.optlibs)
317+
318+
include { details ->
319+
def name = details.name
320+
isSource(name) || isJavadoc(name) || isJmeDep(name)
321+
}
322+
323+
into "jme3-project-baselibs/release/libs/"
324+
325+
includeEmptyDirs = false
326+
duplicatesStrategy = DuplicatesStrategy.INCLUDE
327+
}
328+
329+
tasks.register('copyProjectLibraries', Copy) {
330+
description = 'Copies third-party project libraries'
331+
332+
from(configurations.corelibs)
333+
from(configurations.optlibs)
334+
335+
exclude { details ->
336+
def name = details.name
337+
isSource(name) || isJavadoc(name) || isJmeDep(name)
338+
}
339+
340+
into "jme3-project-libraries/release/libs/"
341+
342+
includeEmptyDirs = false
343+
duplicatesStrategy = DuplicatesStrategy.INCLUDE
344+
}
345+
346+
tasks.register('copyProjectTestData', Copy) {
347+
description = 'Copies jme3 test data'
348+
349+
from(configurations.testdatalibs) {
350+
include { isJmeDep(it.name) }
351+
}
352+
353+
into "jme3-project-testdata/release/modules/ext/"
354+
355+
rename(/jme3-testdata(.*)/, 'jme3-testdata.jar')
356+
357+
includeEmptyDirs = false
358+
}
359+
312360
tasks.register('copyProjectLibs') {
313-
dependsOn configurations.corelibs, configurations.testdatalibs
314-
doLast {
315-
description = "Copies the jar files needed to supply the J2SE Libraries in the " +
316-
"SDK to jme3-project-baselibs and jme3-project-libraries"
361+
description = 'Copies all project libraries and test data'
362+
dependsOn 'copyProjectBaseLibraries', 'copyProjectLibraries', 'copyProjectTestData'
363+
}
317364

318-
// for each dependency in corelibs and optlibs..
319-
def deps = []
320-
deps.addAll(project.configurations.corelibs.files)
321-
deps.addAll(project.configurations.optlibs.files)
322-
deps.each { dep ->
323-
// copy jme3 jar files, sources and javadocs to jme3-project-baselibs
365+
// workaround method to add a tag with the name "name" and "file" to an XML MarkupBuilder
366+
static def makeName(builder, nameR) { builder.name nameR }
324367

325-
if (isSource(dep.name)) {
326-
copy {
327-
from dep
328-
into "jme3-project-baselibs/release/libs/"
329-
}
330-
} else if (isJavadoc(dep.name)) {
331-
copy {
332-
from dep
333-
into "jme3-project-baselibs/release/libs/"
334-
}
335-
} else if (isJmeDep(dep.name)) {
336-
copy {
337-
from dep
338-
into "jme3-project-baselibs/release/libs/"
339-
}
340-
} else {
341-
copy {
342-
from dep
343-
into "jme3-project-libraries/release/libs/"
368+
static def makeFile(builder, nameR) { builder.file(name:nameR, url:nameR) }
369+
370+
ext.buildDependencyResolver = { configs ->
371+
372+
def allArtifacts = []
373+
def rootDepsByKey = [:]
374+
375+
configs.each { cfg ->
376+
def resolution = cfg.incoming.resolutionResult
377+
378+
resolution.root.dependencies.each { d ->
379+
if (d instanceof ResolvedDependencyResult) {
380+
def id = d.selected.id
381+
if (id instanceof ModuleComponentIdentifier) {
382+
rootDepsByKey["${id.group}:${id.module}"] = d.selected
344383
}
345384
}
346-
347385
}
348386

349-
project.configurations.testdatalibs.files.each { dep ->
350-
// copy jme3 test data to jme3-project-testdata
351-
if (isJmeDep(dep.name)) {
352-
copy {
353-
from dep
354-
into "jme3-project-testdata/release/modules/ext/"
355-
rename("jme3-testdata(.*)", "jme3-testdata.jar")
356-
}
387+
allArtifacts.addAll(cfg.incoming.artifacts.artifacts)
388+
}
389+
390+
def artifactsByComponent = allArtifacts.groupBy { it.id.componentIdentifier }
391+
392+
def collectTree
393+
collectTree = { component, visited, result ->
394+
if (!visited.add(component.id)) return []
395+
396+
result.add(component)
397+
398+
component.dependencies.each { d ->
399+
if (d instanceof ResolvedDependencyResult) {
400+
collectTree(d.selected, visited, result)
357401
}
358402
}
403+
404+
return result
359405
}
360-
}
361-
copyProjectLibs.inputs.files configurations.corelibs.resolve()
362-
copyProjectLibs.inputs.files configurations.optlibs.resolve()
363-
copyProjectLibs.inputs.files configurations.testdatalibs.resolve()
364-
copyProjectLibs.outputs.dir "jme3-project-baselibs/release/libs/"
365-
copyProjectLibs.outputs.dir "jme3-project-libraries/release/libs/"
366-
copyProjectLibs.outputs.dir "jme3-project-testdata/release/modules/ext/"
367406

368-
// workaround method to add a tag with the name "name" and "file" to an XML MarkupBuilder
369-
static def makeName(builder, nameR) { builder.name nameR }
407+
return { dep ->
408+
def key = "${dep.group}:${dep.name}"
409+
def rootComponent = rootDepsByKey[key]
410+
if (!rootComponent) return []
370411

371-
static def makeFile(builder, nameR) { builder.file(name:nameR, url:nameR) }
412+
def components = []
413+
collectTree(rootComponent, new HashSet(), components)
414+
415+
components.collectMany { comp ->
416+
artifactsByComponent[comp.id] ?: []
417+
}
418+
}
419+
}
372420

373421
tasks.register('createProjectXml') {
374-
dependsOn configurations.corelibs
422+
inputs.files(configurations.corelibs)
423+
inputs.files(configurations.optlibs)
424+
outputs.dir "jme3-project-baselibs/src/com/jme3/gde/project/baselibs/"
375425
doLast {
376426
description = "Creates needed J2SE library and layer XML files in jme3-project-baselibs"
377427

378428
def eol = System.properties.'line.separator'
379429
def j2seLibraries = [] // created J2SE library descriptors
380430

431+
def resolveClosure = buildDependencyResolver([configurations.corelibs, configurations.optlibs])
381432

382-
// for each dependency in corelibs..
383433
def deps = []
384434
deps.addAll(project.configurations.corelibs.dependencies)
385435
deps.addAll(project.configurations.optlibs.dependencies)
436+
386437
deps.each { dep ->
387-
def jmeJarFiles = [] // jme3 jar files
388-
def jmeSourceFiles = [] // jme3 sources
389-
def jmeJavadocFiles = [] // jme3 javadoc
390-
def externalJarFiles = [] // external jar files
391-
if (j2seLibraries.contains(dep.name + ".xml")) {
392-
return;
438+
439+
def artifacts = resolveClosure(dep)
440+
if (artifacts.isEmpty()) {
441+
return
393442
}
394443

395-
j2seLibraries.add(dep.name + ".xml")
396-
project.configurations.corelibs.files.findAll { d -> return d.name == dep.name }.each { file ->
397-
if (isSource(file.name)) {
398-
if (!jmeSourceFiles.contains(file.name)) {
399-
jmeSourceFiles.add(file.name)
400-
}
401-
} else if (isJavadoc(file.name)) {
402-
if (!jmeJavadocFiles.contains(file.name)) {
403-
jmeJavadocFiles.add(file.name)
404-
}
405-
} else if (isJmeDep(file.name)) {
406-
if (!jmeJarFiles.contains(file.name)) {
407-
jmeJarFiles.add(file.name)
408-
}
409-
} else {
410-
if (!externalJarFiles.contains(file.name)) {
411-
externalJarFiles.add(file.name)
412-
}
413-
}
444+
def name = dep.name
445+
if (j2seLibraries.contains(name + ".xml")) {
446+
return;
414447
}
448+
j2seLibraries.add(name + ".xml")
415449

416-
project.configurations.optlibs.files.findAll { d -> return d.name == dep.name }.each { file ->
450+
def jmeJarFiles = [] // jme3 jar files
451+
def jmeSourceFiles = [] // jme3 sources
452+
def jmeJavadocFiles = [] // jme3 javadoc
453+
def externalJarFiles = [] // external jar files
417454

418-
if (isSource(file.name)) {
419-
if (!jmeSourceFiles.contains(file.name)) {
420-
jmeSourceFiles.add(file.name)
421-
}
422-
} else if (isJavadoc(file.name)) {
423-
if (!jmeJavadocFiles.contains(file.name)) {
424-
jmeJavadocFiles.add(file.name)
425-
}
426-
} else if (isJmeDep(file.name)) {
427-
if (!jmeJarFiles.contains(file.name)) {
428-
jmeJarFiles.add(file.name)
429-
}
455+
artifacts.each { art ->
456+
def file = art.file
457+
def fileName = file.name
458+
459+
if (isSource(fileName)) {
460+
if (!jmeSourceFiles.contains(fileName))
461+
jmeSourceFiles.add(fileName)
462+
} else if (isJavadoc(fileName)) {
463+
if (!jmeJavadocFiles.contains(fileName))
464+
jmeJavadocFiles.add(fileName)
465+
} else if (isJmeDep(fileName)) {
466+
if (!jmeJarFiles.contains(fileName))
467+
jmeJarFiles.add(fileName)
430468
} else {
431-
if (!externalJarFiles.contains(file.name)) {
432-
externalJarFiles.add(file.name)
433-
}
469+
if (!externalJarFiles.contains(fileName))
470+
externalJarFiles.add(fileName)
434471
}
435472
}
436473

437474
// Workarounds where the automatic dependency detection did not work. This is mainly when there are runtime dependencies which are not available as artifacts
438-
if (dep.name.equals("jme3-jbullet")) {
475+
if (name == "jme3-jbullet") {
439476
externalJarFiles.add("jbullet.jar")
440477
externalJarFiles.add("stack-alloc.jar")
441478
}
442479

443-
444480
// create J2SE library descriptor xml file
445481
def libraryWriter = new StringWriter()
446482
def libraryXml = new MarkupBuilder(libraryWriter)
447483
// xml.mkp.xmlDeclaration(version:'1.0')
448484
libraryWriter << '<?xml version="1.0" encoding="UTF-8"?>' << eol
449485
libraryWriter << '<!DOCTYPE library PUBLIC "-//NetBeans//DTD Library Declaration 1.0//EN" "http://www.netbeans.org/dtds/library-declaration-1_0.dtd">' << eol
450486
libraryXml.library(version: "1.0", encoding: "UTF-8") {
451-
makeName(libraryXml, "${dep.name}")
487+
makeName(libraryXml, "${name}")
452488
type "j2se"
453489
"localizing-bundle" "com.jme3.gde.project.baselibs.Bundle"
454490
volume {
@@ -461,7 +497,7 @@ tasks.register('createProjectXml') {
461497
* If we would add all those each library would have it's one jme3-core, which might even lead
462498
* to build errors then.
463499
*/
464-
if (dep.name.equals("jme3_xbuf")) {
500+
if (name == "jme3_xbuf") {
465501
jmeJarFiles.each { jar ->
466502
if (jar.startsWith("jme3_xbuf")) {
467503
/* Technically you would only need the loaders, not the spatial viewer,
@@ -490,7 +526,7 @@ tasks.register('createProjectXml') {
490526
}
491527
}
492528
// write XML file
493-
File libraryXmlFile = file("jme3-project-baselibs/src/com/jme3/gde/project/baselibs/${dep.name}.xml");
529+
File libraryXmlFile = file("jme3-project-baselibs/src/com/jme3/gde/project/baselibs/${name}.xml");
494530
libraryXmlFile.write(libraryWriter.toString())
495531
}
496532

@@ -513,9 +549,6 @@ tasks.register('createProjectXml') {
513549
layerXmlFile.write(layerWriter.toString())
514550
}
515551
}
516-
createProjectXml.inputs.files configurations.corelibs.resolve()
517-
createProjectXml.inputs.files configurations.optlibs.resolve()
518-
createProjectXml.outputs.dir "jme3-project-baselibs/src/com/jme3/gde/project/baselibs/"
519552

520553
tasks.register('copyTestSources') {
521554
doLast {

0 commit comments

Comments
 (0)