@@ -13,6 +13,8 @@ buildscript {
1313}
1414
1515import org.gradle.api.file.RelativePath
16+ import java.nio.file.Files
17+ import java.nio.file.StandardCopyOption
1618
1719// Set the license for IDEs that understand this
1820ext. license = file(" $rootDir /source-file-header-template.txt" )
@@ -25,7 +27,7 @@ allprojects {
2527 mavenCentral()
2628 google()
2729 }
28- tasks. withType(Jar ) {
30+ tasks. withType(Jar ). configureEach {
2931 duplicatesStrategy = ' include'
3032 }
3133}
@@ -47,7 +49,7 @@ subprojects {
4749 toolVersion = libs. versions. spotbugs. get()
4850 }
4951
50- tasks. withType(com.github.spotbugs.snom.SpotBugsTask ) {
52+ tasks. withType(com.github.spotbugs.snom.SpotBugsTask ) . configureEach {
5153 reports {
5254 html. required = ! project. hasProperty(" xml-reports" )
5355 xml. required = project. hasProperty(" xml-reports" )
@@ -63,39 +65,57 @@ tasks.register('run') {
6365
6466defaultTasks ' run'
6567
68+ def fileSystemOperations = services. get(FileSystemOperations )
69+ def libDistDir = layout. buildDirectory. dir(' libDist' )
70+ def libDistArchives = subprojects. collectMany { subproject ->
71+ if (subproject. hasProperty(' mainClassName' )) {
72+ return []
73+ }
74+ subproject. tasks. withType(Jar ). matching { task ->
75+ task. name == ' jar' ||
76+ task. name == ' sourcesJar' ||
77+ (buildJavaDoc == " true" && task. name == ' javadocJar' )
78+ }. collect { archiveTask ->
79+ [
80+ projectName : subproject. name,
81+ archiveFile : archiveTask. archiveFile,
82+ archiveClassifier : archiveTask. archiveClassifier,
83+ archiveExtension : archiveTask. archiveExtension,
84+ ]
85+ }
86+ }
87+
6688def libDist = tasks. register(' libDist' ) {
67- dependsOn(subprojects . collect { it. tasks . named( ' build ' ) })
89+ dependsOn(libDistArchives . collect { it. archiveFile })
6890 description = ' Builds and copies the engine binaries, sources and javadoc to build/libDist'
91+ inputs. files(libDistArchives. collect { it. archiveFile })
92+ outputs. dir(libDistDir)
6993
7094 doLast {
71- File libFolder = mkdir(" $buildDir /libDist/lib" )
72- File sourceFolder = mkdir(" $buildDir /libDist/sources" )
73- File javadocFolder = mkdir(" $buildDir /libDist/javadoc" )
74- subprojects. each {project ->
75- if (! project. hasProperty(' mainClassName' )){
76- project. tasks. withType(Jar ). each {archiveTask ->
77- String classifier = archiveTask. archiveClassifier. get()
78- String ext = archiveTask. archiveExtension. get()
79- File archiveFile = archiveTask. archiveFile. get(). asFile
80- if (classifier == " sources" ) {
81- copy {
82- from archiveFile
83- into sourceFolder
84- rename {project. name + ' -' + classifier + ' .' + ext}
85- }
86- } else if (classifier == " javadoc" ) {
87- copy {
88- from archiveFile
89- into javadocFolder
90- rename {project. name + ' -' + classifier + ' .' + ext}
91- }
92- } else {
93- copy {
94- from archiveFile
95- into libFolder
96- rename {project. name + ' .' + ext}
97- }
98- }
95+ File libFolder = libDistDir. get(). dir(' lib' ). asFile
96+ File sourceFolder = libDistDir. get(). dir(' sources' ). asFile
97+ File javadocFolder = libDistDir. get(). dir(' javadoc' ). asFile
98+ libDistArchives. each { archive ->
99+ String classifier = archive. archiveClassifier. get()
100+ String ext = archive. archiveExtension. get()
101+ File archiveFile = archive. archiveFile. get(). asFile
102+ if (classifier == " sources" ) {
103+ fileSystemOperations. copy {
104+ from archiveFile
105+ into sourceFolder
106+ rename {archive. projectName + ' -' + classifier + ' .' + ext}
107+ }
108+ } else if (classifier == " javadoc" ) {
109+ fileSystemOperations. copy {
110+ from archiveFile
111+ into javadocFolder
112+ rename {archive. projectName + ' -' + classifier + ' .' + ext}
113+ }
114+ } else {
115+ fileSystemOperations. copy {
116+ from archiveFile
117+ into libFolder
118+ rename {archive. projectName + ' .' + ext}
99119 }
100120 }
101121 }
@@ -145,7 +165,13 @@ def mergedJavadocSubprojects = [
145165 " :jme3-plugins" ,
146166 " :jme3-terrain" ,
147167]
168+ def mergedJavadocClasspath = providers. provider {
169+ mergedJavadocSubprojects. collectMany { projectPath ->
170+ project(projectPath). sourceSets. main. compileClasspath. files as List<File >
171+ }
172+ }
148173tasks. register(' mergedJavadoc' , Javadoc ) {
174+ dependsOn mergedJavadocSubprojects. collect { project(it). tasks. named(' classes' ) }
149175 description = ' Creates Javadoc from all the projects.'
150176 title = ' jMonkeyEngine3'
151177 destinationDir = file(" dist/javadoc" )
@@ -157,7 +183,7 @@ tasks.register('mergedJavadoc', Javadoc) {
157183
158184 options. overview = file(" javadoc-overview.html" )
159185 source = mergedJavadocSubprojects. collect { project(it). sourceSets. main. allJava }
160- classpath = files(mergedJavadocSubprojects . collect { project(it) . sourceSets . main . compileClasspath } )
186+ classpath = files(mergedJavadocClasspath )
161187}
162188
163189def cleanMergedJavadoc = tasks. register(' cleanMergedJavadoc' , Delete ) {
@@ -197,45 +223,40 @@ gradle.rootProject.ext.set("usePrebuildNatives", buildNativeProjects!="true");
197223
198224if (skipPrebuildLibraries != " true" && buildNativeProjects != " true" ) {
199225 File nativesSnapshotPropF = file(' natives-snapshot.properties' )
226+ String prebuildNativesUrlTemplate = PREBUILD_NATIVES_URL
200227
201228 if (nativesSnapshotPropF. exists()) {
202- def readNativesConfig = {
203- Properties nativesSnapshotProp = new Properties ()
204- nativesSnapshotPropF. withInputStream { nativesSnapshotProp. load(it) }
205-
206- String nativesSnapshot = nativesSnapshotProp. getProperty(" natives.snapshot" )
207- if (! nativesSnapshot) {
208- throw new GradleException (" Missing 'natives.snapshot' in ${ nativesSnapshotPropF} " )
209- }
229+ Properties nativesSnapshotProp = new Properties ()
230+ nativesSnapshotPropF. withInputStream { nativesSnapshotProp. load(it) }
210231
211- [
212- snapshot : nativesSnapshot,
213- url : PREBUILD_NATIVES_URL . replace(' ${natives.snapshot}' , nativesSnapshot),
214- zipFile : layout. buildDirectory. file(" ${ nativesSnapshot} -natives.zip" ),
215- nativeDir : layout. buildDirectory. dir(" native" ),
216- ]
232+ String nativesSnapshot = nativesSnapshotProp. getProperty(" natives.snapshot" )
233+ if (! nativesSnapshot) {
234+ throw new GradleException (" Missing 'natives.snapshot' in ${ nativesSnapshotPropF} " )
217235 }
218236
219- def nativesZipFile = providers. provider { readNativesConfig(). zipFile. get(). asFile }
237+ String nativesUrl = prebuildNativesUrlTemplate. replace(' ${natives.snapshot}' , nativesSnapshot)
238+ File nativesZipFile = layout. buildDirectory. file(" ${ nativesSnapshot} -natives.zip" ). get(). asFile
220239 def nativesPath = layout. buildDirectory. dir(" native" )
221240
222241 def getNativesZipFile = tasks. register(' getNativesZipFile' ) {
242+ inputs. property(' nativesUrl' , nativesUrl)
223243 outputs. file(nativesZipFile)
224244 doFirst {
225- def nativesConfig = readNativesConfig()
226- File target = nativesConfig. zipFile. get(). asFile
227- println (" Use natives snapshot: ${ nativesConfig.url} " )
228- println (" Download natives from ${ nativesConfig.url} to ${ target} " )
229- target. getParentFile(). mkdirs()
230- ant. get(src : nativesConfig. url, dest : target)
245+ println (" Use natives snapshot: ${ nativesUrl} " )
246+ println (" Download natives from ${ nativesUrl} to ${ nativesZipFile} " )
247+ nativesZipFile. getParentFile(). mkdirs()
248+ File tempFile = new File (nativesZipFile. parentFile, " ${ nativesZipFile.name} .part" )
249+ tempFile. delete()
250+ ant. get(src : nativesUrl, dest : tempFile)
251+ Files . move(tempFile. toPath(), nativesZipFile. toPath(), StandardCopyOption . REPLACE_EXISTING )
231252 }
232253 }
233254
234255 def extractPrebuiltNatives = tasks. register(' extractPrebuiltNatives' , Sync ) {
235256 dependsOn(getNativesZipFile)
236257 into(nativesPath)
237258 from({
238- zipTree(readNativesConfig() . zipFile . get() . asFile )
259+ zipTree(nativesZipFile )
239260 }) {
240261 eachFile { details ->
241262 def segments = details. relativePath. segments
0 commit comments