1- import java.nio.file.Files ;
2- import java.nio.file.StandardCopyOption ;
3-
41buildscript {
52 repositories {
63 mavenCentral()
74 google()
85 maven {
9- url " https://plugins.gradle.org/m2/"
6+ url = " https://plugins.gradle.org/m2/"
107 }
118 }
129 dependencies {
@@ -15,6 +12,14 @@ buildscript {
1512 }
1613}
1714
15+ import org.gradle.api.file.RelativePath
16+
17+ // Set the license for IDEs that understand this
18+ ext. license = file(" $rootDir /source-file-header-template.txt" )
19+
20+ apply plugin : ' base'
21+ apply from : file(' version.gradle' )
22+
1823allprojects {
1924 repositories {
2025 mavenCentral()
@@ -25,13 +30,6 @@ allprojects {
2530 }
2631}
2732
28- // Set the license for IDEs that understand this
29- ext. license = file(" $rootDir /source-file-header-template.txt" )
30-
31- apply plugin : ' base'
32- apply plugin : ' com.github.spotbugs'
33- apply from : file(' version.gradle' )
34-
3533// This is applied to all sub projects
3634subprojects {
3735 if (! project. name. equals(' jme3-android-examples' )) {
@@ -58,13 +56,17 @@ subprojects {
5856 }
5957}
6058
61- task run (dependsOn : ' :jme3-examples:run' ) {
59+ tasks. register(' run' ) {
60+ dependsOn ' :jme3-examples:run'
6261 description = ' Run the jME3 examples'
6362}
6463
6564defaultTasks ' run'
6665
67- task libDist (dependsOn : subprojects. build, description : ' Builds and copies the engine binaries, sources and javadoc to build/libDist' ) {
66+ def libDist = tasks. register(' libDist' ) {
67+ dependsOn(subprojects. collect { it. tasks. named(' build' ) })
68+ description = ' Builds and copies the engine binaries, sources and javadoc to build/libDist'
69+
6870 doLast {
6971 File libFolder = mkdir(" $buildDir /libDist/lib" )
7072 File sourceFolder = mkdir(" $buildDir /libDist/sources" )
@@ -74,21 +76,22 @@ task libDist(dependsOn: subprojects.build, description: 'Builds and copies the e
7476 project. tasks. withType(Jar ). each {archiveTask ->
7577 String classifier = archiveTask. archiveClassifier. get()
7678 String ext = archiveTask. archiveExtension. get()
79+ File archiveFile = archiveTask. archiveFile. get(). asFile
7780 if (classifier == " sources" ) {
7881 copy {
79- from archiveTask . archivePath
82+ from archiveFile
8083 into sourceFolder
8184 rename {project. name + ' -' + classifier + ' .' + ext}
8285 }
8386 } else if (classifier == " javadoc" ) {
8487 copy {
85- from archiveTask . archivePath
88+ from archiveFile
8689 into javadocFolder
8790 rename {project. name + ' -' + classifier + ' .' + ext}
8891 }
8992 } else {
9093 copy {
91- from archiveTask . archivePath
94+ from archiveFile
9295 into libFolder
9396 rename {project. name + ' .' + ext}
9497 }
@@ -99,7 +102,9 @@ task libDist(dependsOn: subprojects.build, description: 'Builds and copies the e
99102 }
100103}
101104
102- task createZipDistribution (type :Zip ,dependsOn :[" dist" ," libDist" ], description :" Package the nightly zip distribution" ){
105+ tasks. register(' createZipDistribution' , Zip ) {
106+ dependsOn(tasks. named(' dist' ), libDist)
107+ description = ' Package the nightly zip distribution'
103108 archiveFileName = provider {
104109 " jME" + jmeFullVersion + " .zip"
105110 }
@@ -111,7 +116,7 @@ task createZipDistribution(type:Zip,dependsOn:["dist","libDist"], description:"P
111116 }
112117}
113118
114- task copyLibs ( type : Copy ){
119+ tasks . register( ' copyLibs ' , Copy ) {
115120// description 'Copies the engine dependencies to build/libDist'
116121 from {
117122 subprojects* . configurations* . implementation* . copyRecursive({ ! (it instanceof ProjectDependency ); })* . resolve()
@@ -120,8 +125,9 @@ task copyLibs(type: Copy){
120125 into " $buildDir /libDist/lib-ext" // buildDir.path + '/' + libsDirName + '/lib'
121126}
122127
123- task dist (dependsOn : [' :jme3-examples:dist' , ' mergedJavadoc' ]){
124- description ' Creates a jME3 examples distribution with all jme3 binaries, sources, javadoc and external libraries under ./dist'
128+ tasks. register(' dist' ) {
129+ dependsOn ' :jme3-examples:dist' , tasks. named(' mergedJavadoc' )
130+ description = ' Creates a jME3 examples distribution with all jme3 binaries, sources, javadoc and external libraries under ./dist'
125131}
126132
127133def mergedJavadocSubprojects = [
@@ -139,13 +145,12 @@ def mergedJavadocSubprojects = [
139145 " :jme3-plugins" ,
140146 " :jme3-terrain" ,
141147]
142- task mergedJavadoc (type : Javadoc , description : ' Creates Javadoc from all the projects.' ) {
148+ tasks. register(' mergedJavadoc' , Javadoc ) {
149+ description = ' Creates Javadoc from all the projects.'
143150 title = ' jMonkeyEngine3'
144- destinationDir = mkdir (" dist/javadoc" )
151+ destinationDir = file (" dist/javadoc" )
145152
146153 options. encoding = ' UTF-8'
147-
148- // Allows Javadoc to be generated on Java 8 despite doclint errors.
149154 if (JavaVersion . current(). isJava8Compatible()) {
150155 options. addStringOption(' Xdoclint:none' , ' -quiet' )
151156 }
@@ -155,13 +160,12 @@ task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the pro
155160 classpath = files(mergedJavadocSubprojects. collect { project(it). sourceSets. main. compileClasspath })
156161}
157162
158- clean. dependsOn(' cleanMergedJavadoc' )
159- task cleanMergedJavadoc (type : Delete ) {
163+ def cleanMergedJavadoc = tasks. register(' cleanMergedJavadoc' , Delete ) {
160164 delete file(' dist/javadoc' )
161165}
162166
163- task mergedSource ( type : Copy ) {
164-
167+ tasks . named( ' clean ' ) {
168+ dependsOn cleanMergedJavadoc
165169}
166170
167171ext {
@@ -192,54 +196,61 @@ task configureAndroidNDK {
192196gradle. rootProject. ext. set(" usePrebuildNatives" , buildNativeProjects!= " true" );
193197
194198if (skipPrebuildLibraries != " true" && buildNativeProjects != " true" ) {
195- String rootPath = rootProject. projectDir. absolutePath
196-
197- Properties nativesSnapshotProp = new Properties ()
198- File nativesSnapshotPropF = new File (" ${ rootPath} /natives-snapshot.properties" );
199+ File nativesSnapshotPropF = file(' natives-snapshot.properties' )
199200
200201 if (nativesSnapshotPropF. exists()) {
202+ def readNativesConfig = {
203+ Properties nativesSnapshotProp = new Properties ()
204+ nativesSnapshotPropF. withInputStream { nativesSnapshotProp. load(it) }
201205
202- nativesSnapshotPropF. withInputStream { nativesSnapshotProp. load(it) }
203-
204- String nativesSnapshot = nativesSnapshotProp. getProperty(" natives.snapshot" );
205- String nativesUrl = PREBUILD_NATIVES_URL . replace(' ${natives.snapshot}' , nativesSnapshot)
206- println " Use natives snapshot: " + nativesUrl
206+ String nativesSnapshot = nativesSnapshotProp. getProperty(" natives.snapshot" )
207+ if (! nativesSnapshot) {
208+ throw new GradleException (" Missing 'natives.snapshot' in ${ nativesSnapshotPropF} " )
209+ }
207210
208- String nativesZipFile = " ${ rootPath} " + File . separator + " build" + File . separator + nativesSnapshot + " -natives.zip"
209- String nativesPath = " ${ rootPath} " + File . separator + " build" + File . separator + " native"
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+ ]
217+ }
210218
219+ def nativesZipFile = providers. provider { readNativesConfig(). zipFile. get(). asFile }
220+ def nativesPath = layout. buildDirectory. dir(" native" )
211221
212- task getNativesZipFile {
213- outputs. file nativesZipFile
222+ def getNativesZipFile = tasks . register( ' getNativesZipFile ' ) {
223+ outputs. file( nativesZipFile)
214224 doFirst {
215- File target = file(nativesZipFile);
216- println (" Download natives from " + nativesUrl + " to " + nativesZipFile);
217- target. getParentFile(). mkdirs();
218- ant. get(src : nativesUrl, dest : target);
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)
219231 }
220232 }
221233
222- task extractPrebuiltNatives {
223- inputs. file nativesZipFile
224- outputs. dir nativesPath
225- dependsOn getNativesZipFile
226-
227- doFirst {
228- for (File src : zipTree(nativesZipFile)) {
229- String srcRel = src. getAbsolutePath(). substring((int ) (nativesZipFile. length() + 1 ));
230- srcRel = srcRel. substring(srcRel. indexOf(File . separator) + 1 );
231-
232- File dest = new File (nativesPath + File . separator + srcRel);
233- boolean doCopy = ! (dest. exists() && dest. lastModified() > src. lastModified())
234- if (doCopy) {
235- println (" Copy " + src + " " + dest);
236- dest. getParentFile(). mkdirs();
237- Files . copy(src. toPath(), dest. toPath(), StandardCopyOption . REPLACE_EXISTING );
234+ def extractPrebuiltNatives = tasks. register(' extractPrebuiltNatives' , Sync ) {
235+ dependsOn(getNativesZipFile)
236+ into(nativesPath)
237+ from({
238+ zipTree(readNativesConfig(). zipFile. get(). asFile)
239+ }) {
240+ eachFile { details ->
241+ def segments = details. relativePath. segments
242+ if (segments. length <= 1 ) {
243+ details. exclude()
244+ } else {
245+ details. relativePath = new RelativePath (details. isDirectory(), segments[1 .. -1 ] as String [])
238246 }
239247 }
248+ includeEmptyDirs = false
240249 }
241250 }
242251
243- assemble. dependsOn extractPrebuiltNatives
252+ tasks. named(' assemble' ) {
253+ dependsOn extractPrebuiltNatives
254+ }
244255 }
245256}
0 commit comments