Add heuristic to detect when a scratchpad is in big endian format; Keep scratchpad...
[SquirrelJME.git] / modules / build.gradle
blob4935a7e0bdcda5916269f065476f36682d817929
1 import org.gradle.plugins.ide.idea.model.IdeaLanguageLevel
2 import org.gradle.util.VersionNumber
4 plugins {
5         id "de.set.ecj" version "1.4.1" apply false
6         id "idea"
9 group = "cc.squirreljme.modules"
10 description = "Modules which are a part of SquirrelJME."
12 // Helper function to normalize the Maven version
13 static VersionNumber normalizeMavenVersion(Object __inVersion) {
14         VersionNumber inVersion = VersionNumber.parse(__inVersion.toString())
15         
16         // If this is an even version, then this is a release version
17         if ((inVersion.minor % 2) == 0)
18                 return inVersion
19         
20         // Otherwise odd numbers are considered to be "snapshot" versions
21         return VersionNumber.parse(inVersion.toString() + "-SNAPSHOT")
24 idea {
25         module
26         {
27                 // This is 1.8 because 1.7 is not really available
28                 jdkName = "squirreljme-8"
29         }
32 // Every sub-project needs SquirrelJME specific pieces
33 subprojects {
34         // Apply ECJ for compilation? (Such as too new of Java)
35         if (project.hasProperty("squirreljmeEcjEnabled") &&
36                 project.squirreljmeEcjEnabled) {
37                 apply plugin: "de.set.ecj"
38         }
39         
40         apply plugin: "java-library"
41         apply plugin: "java-test-fixtures"
42         apply plugin: "cc.squirreljme.plugin"
43         apply plugin: "idea"
44         apply plugin: "maven-publish"
45         apply plugin: "signing"
46         
47         // The Java versions this works with
48         sourceCompatibility = 8
49         targetCompatibility = 8
50         
51         idea {
52                 module
53                 {
54                         // This is 1.8 because 1.7 is not really available
55                         jdkName = "squirreljme-8"
56                         
57                         // However, everything targets 1.7 otherwise
58                         languageLevel = new IdeaLanguageLevel("1.7")
59                         targetBytecodeVersion = JavaVersion.VERSION_1_7
60                 }
61         }
62         
63         // Disable native header generation when using ECJ as it does not have
64         // the -h option. See:
65         // https://github.com/gradle/gradle/issues/12904#issuecomment-619212927
66         if (project.hasProperty("squirreljmeEcjEnabled") &&
67                 project.squirreljmeEcjEnabled) {
68                 tasks.withType(JavaCompile) {
69                         options.headerOutputDirectory.convention((Directory)null)
70                 }
71         }
72         
73         // Configure the compiler
74         java {
75                 // Java ME 8 is effectively Java 7, but use Java 8 here
76         compileJava.sourceCompatibility = JavaVersion.VERSION_1_7
77                 compileJava.targetCompatibility = JavaVersion.VERSION_1_8
79                 // All files are always in UTF-8 format
80                 compileJava.options.encoding = "utf-8"
82                 // Emit deprecation errors
83                 compileJava.options.deprecation = true
84                 
85                 // Maximize debugging
86                 compileJava.options.debug = true
87                 compileJava.options.debugOptions.setDebugLevel("source,lines,vars")
89                 // Copy to tests
90                 compileTestJava.sourceCompatibility = compileJava.sourceCompatibility
91                 compileTestJava.targetCompatibility = compileJava.targetCompatibility
92                 compileTestJava.options.encoding = compileJava.options.encoding
93                 compileTestJava.options.verbose = compileJava.options.verbose
94                 compileTestJava.options.deprecation = compileJava.options.deprecation
95                 compileTestJava.options.debug = compileJava.options.debug
96                 compileTestJava.options.debugOptions = compileJava.options.debugOptions
98                 // Copy to JavaDoc
99                 javadoc.options.source = "1.7"
100                 javadoc.options.tags = [ "squirreljme.property",
101                         "squirreljme.env",
102                         "squirreljme.error",
103                         "squirreljme.syscallparam",
104                         "squirreljme.syscallreturn",
105                         "squirreljme.tsiparam",
106                         "squirreljme.configtype",
107                         "squirreljme.uiwidgetparam" ]
108                         
109                 // Build sources and JavaDoc as well
110                 withSourcesJar()
111                 withJavadocJar()
112         }
114         // Enable SquirrelJME Tests
115         apply from: project.rootProject.findProject(":emulators:emulator-base").
116                 projectDir.toPath().resolve("enable-testing.gradle").toFile()
117         
118         // Publishing
119         publishing {
120                 // What is being published?
121                 publications {
122                         maven(MavenPublication) {
123                                 // Adjustments to the Maven POM
124                                 pom {
125                                         /*System.err.printf("Name/Desc: %s %s%n", project.squirreljme.swmName ?: project.name, project.description)
126                                         name = project.squirreljme.swmName ?: project.name
127                                         description = project.description*/
128                                         url = "https://squirreljme.cc/"
129                                         
130                                         // SquirrelJME started to exist in 2016!
131                                         inceptionYear = "2016"
132                                         
133                                         licenses {
134                                                 license {
135                                                         name = "GNU General Public License v3"
136                                                         url = "https://squirreljme.cc/file?name=LICENSE&ci=trunk"
137                                                 }
138                                         }
139                                         
140                                         developers {
141                                                 developer {
142                                                         id = "stephanie.gawroriski"
143                                                         name = "Stephanie Gawroriski"
144                                                         email = "xerthesquirrel@gmail.com"
145                                                 }
146                                         }
147                                         
148                                         contributors {
149                                                 contributor {
150                                                         name = "Stephanie Gawroriski"
151                                                         email = "xerthesquirrel@gmail.com"
152                                                         roles = [ "Primary Developer" ]
153                                                         timezone = "America/New_York"
154                                                         url = "https://shadowtail.dev/"
155                                                 }
156                                         }
157                                                 
158                                         scm {
159                                                 url = "https://squirreljme.cc/"
160                                                 connection = "fossil:https://squirreljme.cc/"
161                                         }
162                                         
163                                         organization {
164                                                 name = "SquirrelJME"
165                                                 url = "https://squirreljme.cc/"
166                                         }
167                                         
168                                         issueManagement {
169                                                 system = "GitHub"
170                                                 url = "https://github.com/SquirrelJME/SquirrelJME/issues"
171                                         }
172                                         
173                                         ciManagement {
174                                                 system = "CircleCI"
175                                                 url = "https://app.circleci.com/pipelines/github/SquirrelJME"
176                                         }
177                                         
178                                         withXml {
179                                                 // Lazy evaluation of the project name and description so that it
180                                                 // uses the proper name for Maven and otherwise
181                                                 asNode().appendNode("name", project.squirreljme.swmName ?: project.name)
182                                                 asNode().appendNode("description", project.description)
183                                                 
184                                                 def propMap = asNode().appendNode("properties")
185                                                 
186                                                 // Properties that are needed by Maven, although
187                                                 // not recommended to use Maven for building
188                                                 propMap.appendNode("maven.compiler.source",
189                                                         "1.7")
190                                                 propMap.appendNode("maven.compiler.target",
191                                                         "1.7")
192                                                 propMap.appendNode("project.build.sourceEncoding",
193                                                         "UTF-8")
194                                                 
195                                                 // SquirrelJME properties
196                                                 if (project.squirreljme.swmType != null)
197                                                         propMap.appendNode("squirreljme.type",
198                                                                 project.squirreljme.swmType)
199                                                 propMap.appendNode("squirreljme.vendor",
200                                                         project.squirreljme.swmVendor)
201                                                 propMap.appendNode("squirreljme.errorCode",
202                                                         project.squirreljme.javaDocErrorCode)
203                                                 propMap.appendNode("squirreljme.configurations",
204                                                         Objects.toString(project.squirreljme.definedConfigurations))
205                                                 propMap.appendNode("squirreljme.profiles",
206                                                         Objects.toString(project.squirreljme.definedProfiles))
207                                                 propMap.appendNode("squirreljme.standards",
208                                                         Objects.toString(project.squirreljme.definedStandards))
209                                                 propMap.appendNode("squirreljme.midlets",
210                                                         Objects.toString(project.squirreljme.midlets))
211                                         }
212                                 }
213                                 
214                                 // Normal information
215                                 groupId = "cc.squirreljme.modules"
216                                 artifactId = project.name
217                                 version = normalizeMavenVersion(rootProject.version)
218                                 
219                                 // What is being published?
220                                 from components.java
221                         }
222                 }
223                 
224                 // Where is this to be published?
225                 repositories {
226                         // Publishing to local Maven
227                         mavenLocal()
228                         
229                         // OSSRH Repository (https://oss.sonatype.org/)
230                         maven {
231                                 url = (normalizeMavenVersion(rootProject.version)
232                                         .toString().endsWith("-SNAPSHOT") ? 
233                                         "https://oss.sonatype.org/content/repositories/snapshots/" :
234                                         "https://oss.sonatype.org/service/local/staging/deploy/maven2/")
235                                 
236                                 credentials {
237                                         username = findProperty("ossrhUser") ?: "ossrh_user_unset!"
238                                         password = findProperty("ossrhPassword") ?: "ossrh_pass_unset!"
239                                 }
240                         }
241                 }
242                 
243                 // IntelliJ adjustments
244                 idea {
245                         module {
246                                 // Make testFixtures as part of tests so that in search and
247                                 // otherwise they appear as such
248                                 testSourceDirs += project.projectDir.toPath().resolve("src")
249                                         .resolve("testFixtures").resolve("java").toFile()
250                                 testResourceDirs += project.projectDir.toPath().resolve("src")
251                                         .resolve("testFixtures").resolve("resources").toFile()
252                         }
253                 }
254         }
255         
256         // Signing publications
257         signing {
258                 required {
259                         false
260                 }
261                 
262                 // Load key into memory and the password
263                 def signingKeyId = findProperty("signingKeyId")
264                 def signingPassword = findProperty("signingPassword")
265                 
266                 def signingKeyBase64 = findProperty("signingKey")
267                 def signingKey = (signingKeyBase64 == null ? null :
268                         new String(Base64.getMimeDecoder()
269                                 .decode(signingKeyBase64.toString()), "utf-8"))
270                 
271                 // Use in memory key signing
272                 useInMemoryPgpKeys(/*signingKeyId,*/ signingKey, signingPassword)
273                 
274                 // The default Maven release becomes signed
275                 sign publishing.publications.maven
276         }
279 // Properties for every sub-project, except for cldc-compact as it is special
280 configure(subprojects
281         - project(":modules:cldc-compact")) {
282         apply plugin: "java-library"
284         // All projects use the base classpath
285     java {
286                 // Only use SquirrelJME's boot classes, not the system SDK
287                 Project cldcCompactProject = project(":modules:cldc-compact")
288                 compileJava.options.bootstrapClasspath = project.objects.
289                         fileCollection().from(cldcCompactProject.buildDir.toPath().
290                         resolve("classes").resolve("java").resolve("main")).getAsFileTree()
292                 // Copy to JavaDoc
293                 javadoc.options.bootClasspath = compileJava.options.bootstrapClasspath
294                         .collect()
295     }
297         dependencies {
298                 // All projects depend on the Compact CLDC Library
299                 api project(":modules:cldc-compact")
300         }