Skip to content

Commit

Permalink
Extract JSON library to external project
Browse files Browse the repository at this point in the history
The JSON library that was built as part of Chunky is now a separate library,
and included via a Maven dependency.
The JSON library lives here: https://github.com/llbit/jo-json

Moved the process for building of the release Jar to the Gradle build, in the
releaseJar task.  Only version information is processed by the old
ReleaseBuilder tool.
  • Loading branch information
llbit committed May 7, 2017
1 parent a4d84e9 commit 3ad4dd8
Show file tree
Hide file tree
Showing 31 changed files with 490 additions and 2,110 deletions.
370 changes: 201 additions & 169 deletions build.gradle

Large diffs are not rendered by default.

276 changes: 141 additions & 135 deletions chunky/build.gradle
Expand Up @@ -5,176 +5,182 @@ apply plugin: 'signing'
mainClassName = 'se.llbit.chunky.main.Chunky'
archivesBaseName = 'chunky-core'

jar {
// Include classes from the common library.
from project(':lib').configurations.archives.allArtifacts.files.collect {
zipTree(it)
}
manifest {
attributes("Main-Class": mainClassName)
}
configurations {
jsonlib
}

sourceSets {
main {
java {
srcDir 'src/java'
srcDir 'src/gen'
}
resources {
srcDir 'src/gen-res'
srcDir 'src/res'
}
}
test {
java {
srcDir 'src/test'
}
}
}
dependencies {
compile 'org.apache.commons:commons-math3:3.2'
compile project(':lib')

testCompile 'com.google.truth:truth:0.30'
testCompile 'junit:junit:4.12'

repositories {
mavenCentral()
jsonlib 'se.llbit:jo-json:1.3.0'
}

dependencies {
compile 'org.apache.commons:commons-math3:3.2'
compile project(':lib')
jar {
// Include classes from the common library.
from project(':lib').configurations.archives.allArtifacts.files.collect {
zipTree(it)
}
from configurations.jsonlib.files.collect {
zipTree(it)
}
manifest {
attributes('Main-Class': mainClassName)
}
}

testCompile 'com.google.truth:truth:0.30'
testCompile 'junit:junit:4.12'
sourceSets {
main {
java {
srcDir 'src/java'
srcDir 'src/gen'
}
resources {
srcDir 'src/gen-res'
srcDir 'src/res'
}
}
test {
java {
srcDir 'src/test'
}
}
}

processResources.dependsOn 'updateVersionString'

task updateVersionString {
description 'Store the current version string in src/gen-res/Version.properties'

outputs.upToDateWhen {
def props = new Properties()
def output = file('src/gen-res/Version.properties')
if (output.isFile()) {
output.withInputStream { stream -> props.load(stream) }
}
props['version'] == project.version
}

doLast {
file('src/gen-res').mkdirs()
def date = new Date()
def versionFile = file('src/gen-res/Version.properties')
ant.propertyfile(file: versionFile) {
entry(key: 'version', value: project.version)
}
}
description 'Store the current version string in src/gen-res/Version.properties'

outputs.upToDateWhen {
def props = new Properties()
def output = file('src/gen-res/Version.properties')
if (output.isFile()) {
output.withInputStream { stream -> props.load(stream) }
}
props['version'] == project.version
}

doLast {
file('src/gen-res').mkdirs()
def date = new Date()
def versionFile = file('src/gen-res/Version.properties')
ant.propertyfile(file: versionFile) {
entry(key: 'version', value: project.version)
}
}
}

compileJava.dependsOn 'generateJava'

task generateJava() {
inputs.dir 'src/jastadd'
outputs.dir 'src/gen'

doLast {
project.file('src/gen').mkdirs()
ant.taskdef(
name: 'jastadd',
classname: 'org.jastadd.JastAddTask',
classpath: project.configurations.jastadd.asPath)
ant.jastadd(
outdir: project.file('src/gen'),
package: 'se.llbit.nbt',
rewrite: 'none',
visitCheck: false,
debug: false) {
fileset(dir: project.file('src/jastadd')) {
include(name: '*.ast')
include(name: '*.jrag')
include(name: '*.jadd')
}
}
}
inputs.dir 'src/jastadd'
outputs.dir 'src/gen'

doLast {
project.file('src/gen').mkdirs()
ant.taskdef(
name: 'jastadd',
classname: 'org.jastadd.JastAddTask',
classpath: project.configurations.jastadd.asPath)
ant.jastadd(
outdir: project.file('src/gen'),
package: 'se.llbit.nbt',
rewrite: 'none',
visitCheck: false,
debug: false) {
fileset(dir: project.file('src/jastadd')) {
include(name: '*.ast')
include(name: '*.jrag')
include(name: '*.jadd')
}
}
}
}

task chunkyJavadoc(type: Javadoc) {
exclude 'src/gen/**'
exclude 'src/gen/**'
}

task javadocJar(type: Jar) {
classifier = 'javadoc'
from chunkyJavadoc
classifier = 'javadoc'
from chunkyJavadoc
}

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
classifier = 'sources'
from sourceSets.main.allSource
}

artifacts {
archives javadocJar, sourcesJar
archives javadocJar, sourcesJar
}

signing {
// Require OSSRH credentials before signing artifacts:
required { project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword') }
sign configurations.archives
// Require OSSRH credentials before signing artifacts:
required { project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword') }
sign configurations.archives
}

uploadArchives {
repositories.mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2') {
if (project.hasProperty('ossrhUsername')) {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
}

snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots') {
if (project.hasProperty('ossrhUsername')) {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
}

pom.project {
name 'Chunky'
packaging 'jar'
description 'Minecraft mapping and rendering tool'
url 'http://chunky.llbit.se'
licenses {
license {
name 'GNU General Public License Version 3 (GPLv3)'
url 'https://www.gnu.org/licenses/gpl-3.0.en.html'
distribution 'repo'
}
}
developers {
developer {
name 'Jesper Öqvist'
email 'jesper@llbit.se'
}
}
scm {
connection 'scm:git:https://github.com/llbit/chunky.git'
url 'https://github.com/llbit/chunky'
}
}
}
repositories.mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2') {
if (project.hasProperty('ossrhUsername')) {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
}

snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots') {
if (project.hasProperty('ossrhUsername')) {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
}

pom.project {
name 'Chunky'
packaging 'jar'
description 'Minecraft mapping and rendering tool'
url 'http://chunky.llbit.se'
licenses {
license {
name 'GNU General Public License Version 3 (GPLv3)'
url 'https://www.gnu.org/licenses/gpl-3.0.en.html'
distribution 'repo'
}
}
developers {
developer {
name 'Jesper Öqvist'
email 'jesper@llbit.se'
}
}
scm {
connection 'scm:git:https://github.com/llbit/chunky.git'
url 'https://github.com/llbit/chunky'
}
}
}
}

project.afterEvaluate {
def installers = project.tasks.install.repositories
def deployers = project.tasks.uploadArchives.repositories
installers.plus(deployers)*.pom*.whenConfigured {pom ->
// Exclude the :lib dependency since we embed it in the Jar.
pom.dependencies.removeAll { it.groupId == 'se.llbit' && it.artifactId == 'lib' }

// Change POM version to -SNAPSHOT for intermediate builds.
if (project.version =~ /\d+\.\d+(\.\d+)?-.+/) {
// This is a SNAPSHOT build.
def match = (project.version =~ /(\d+\.\d+(\.\d+)?)-.+/)
pom.version = "${match[0][1]}-SNAPSHOT"
}
println("POM version: ${pom.version}")
}
def installers = project.tasks.install.repositories
def deployers = project.tasks.uploadArchives.repositories
installers.plus(deployers)*.pom*.whenConfigured {pom ->
// Exclude the :lib and jo-json dependencies because they are embedded in the built Jar.
pom.dependencies.removeAll { it.groupId == 'se.llbit' && it.artifactId == 'lib' }
pom.dependencies.removeAll { it.groupId == 'se.llbit' && it.artifactId == 'jo-json' }

// Change POM version to -SNAPSHOT for intermediate builds.
if (project.version =~ /\d+\.\d+(\.\d+)?-.+/) {
// This is a SNAPSHOT build.
def match = (project.version =~ /(\d+\.\d+(\.\d+)?)-.+/)
pom.version = "${match[0][1]}-SNAPSHOT"
}
println("POM version: ${pom.version}")
}
}
2 changes: 1 addition & 1 deletion chunky/src/java/se/llbit/chunky/main/Chunky.java
Expand Up @@ -221,7 +221,7 @@ public static void loadDefaultTextures() {

private void loadPlugins() {
JsonValue plugins = PersistentSettings.getPlugins();
for (JsonValue plugin : plugins.array().getElementList()) {
for (JsonValue plugin : plugins.array()) {
String jar = plugin.object().get("jar").stringValue("");
String main = plugin.object().get("main").stringValue("");
// The MD5 checksum is only for Jar integrity checking, not security!
Expand Down
9 changes: 2 additions & 7 deletions chunky/src/java/se/llbit/chunky/main/CommandLineOptions.java
Expand Up @@ -16,7 +16,6 @@
*/
package se.llbit.chunky.main;

import org.jastadd.util.PrettyPrinter;
import se.llbit.chunky.PersistentSettings;
import se.llbit.chunky.renderer.ConsoleProgressListener;
import se.llbit.chunky.renderer.RenderContext;
Expand All @@ -28,6 +27,7 @@
import se.llbit.json.JsonParser.SyntaxError;
import se.llbit.json.JsonString;
import se.llbit.json.JsonValue;
import se.llbit.json.PrettyPrinter;
import se.llbit.log.Log;
import se.llbit.util.MCDownloader;
import se.llbit.util.NotNull;
Expand Down Expand Up @@ -292,12 +292,7 @@ public CommandLineOptions(String[] args) {
for (int j = 0; j < path.length - 1; ++j) {
obj = obj.get(path[j]).object();
}
for (int j = 0; j < obj.getNumMember(); ++j) {
if (obj.getMember(j).getName().equals(name)) {
obj.getMemberList().removeChild(j);
break;
}
}
obj.remove(name);
writeSceneJson(file, desc);
System.out.println("Updated scene " + file.getAbsolutePath());
} catch (SyntaxError e) {
Expand Down

0 comments on commit 3ad4dd8

Please sign in to comment.