Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Add an options closure to enable and disable parts of CurseGradle
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewprenger committed Jul 23, 2016
1 parent c7181bb commit 2506386
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ class CurseExtension {

final Collection<CurseProject> curseProjects = new ArrayList<>()

boolean debug = false
Options curseGradleOptions = new Options()

@Deprecated
boolean getDebug() {
return curseGradleOptions.debug
}

@Deprecated
void setDebug(boolean debug) {
curseGradleOptions.debug = debug
}

/**
* Define a new CurseForge project for deployment
Expand All @@ -24,4 +34,8 @@ class CurseExtension {
}
curseProjects.add(curseProject)
}

void options(Closure<?> configClosure) {
curseGradleOptions.with(configClosure)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,18 @@ class CurseGradlePlugin implements Plugin<Project> {
uploadTask.apiKey = curseProject.apiKey
uploadTask.projectId = curseProject.id

Integration.checkJava(project, curseProject)
Integration.checkForgeGradle(project, curseProject)
CurseExtension ext = project.extensions.getByType(CurseExtension)

if (ext.curseGradleOptions.javaVersionAutoDetect) {
Integration.checkJavaVersion(project, curseProject)
}

if (ext.curseGradleOptions.javaIntegration) {
Integration.checkJava(project, curseProject)
}
if (ext.curseGradleOptions.forgeGradleIntegration) {
Integration.checkForgeGradle(project, curseProject)
}

curseProject.copyConfig()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CurseUploadTask extends DefaultTask {

int uploadFile(String json, File file) throws IOException, URISyntaxException {

if (project.extensions.getByName(CurseGradlePlugin.EXTENSION_NAME).debug) {
if (project.extensions.getByType(CurseExtension).curseGradleOptions.debug) {
logger.lifecycle("DEBUG: File: $file Json: $json")
return 0
}
Expand Down
32 changes: 20 additions & 12 deletions src/main/groovy/com/matthewprenger/cursegradle/Integration.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,32 @@ class Integration {
curseProject.uploadTask.dependsOn jarTask
}

JavaPluginConvention javaConv = (JavaPluginConvention) project.getConvention().getPlugins().get("java");
JavaVersion javaVersion = JavaVersion.toVersion(javaConv.targetCompatibility)

if (JavaVersion.VERSION_1_6.compareTo(javaVersion) >= 0) {
curseProject.addGameVersion('Java 6')
}
if (JavaVersion.VERSION_1_7.compareTo(javaVersion) >= 0) {
curseProject.addGameVersion('Java 7')
}
if (JavaVersion.VERSION_1_8.compareTo(javaVersion) >= 0) {
curseProject.addGameVersion('Java 8')
}
}
} catch (Throwable t) {
log.warn("Failed Java integration", t)
}
}

static void checkJavaVersion(Project project, CurseProject curseProject) {

try {
JavaPluginConvention javaConv = (JavaPluginConvention) project.getConvention().getPlugins().get("java");
JavaVersion javaVersion = JavaVersion.toVersion(javaConv.targetCompatibility)

if (JavaVersion.VERSION_1_6.compareTo(javaVersion) >= 0) {
curseProject.addGameVersion('Java 6')
}
if (JavaVersion.VERSION_1_7.compareTo(javaVersion) >= 0) {
curseProject.addGameVersion('Java 7')
}
if (JavaVersion.VERSION_1_8.compareTo(javaVersion) >= 0) {
curseProject.addGameVersion('Java 8')
}
} catch (Throwable t) {
log.warn("Failed to check Java Version", t)
}
}

static void checkForgeGradle(Project project, CurseProject curseProject) {
try {
if (project.hasProperty('minecraft')) {
Expand Down
29 changes: 29 additions & 0 deletions src/main/groovy/com/matthewprenger/cursegradle/Options.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.matthewprenger.cursegradle

/**
* Various options for CurseGradle. These affect the entire plugin and not just a single curse project.
*/
class Options {

/**
* Debug mode will stop just short of actually uploading the file to Curse, and instead spit out the JSON
* to the console. Useful for testing your buildscript.
*/
boolean debug = false

/**
* If this is left enabled, CurseGradle will automatically detect the compatible versions of Java for the project
* and add them to the CurseForge metadata.
*/
boolean javaVersionAutoDetect = true

/**
* Enable integration with the Gradle Java plugin. This includes setting the default artifact to the jar task.
*/
boolean javaIntegration = true

/**
* Enable integration with the ForgeGradle plugin. This includes setting dependencies on the reobfuscation tasks.
*/
boolean forgeGradleIntegration = true
}

0 comments on commit 2506386

Please sign in to comment.