-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
143 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
buildSrc/src/main/groovy/mmc/extentions/SetupDefaultJarTasks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package mmc.extentions; | ||
|
||
import mmc.MindustryModCoreExtension; | ||
import mmc.extentions.defaultjar.DeployTask; | ||
import mmc.extentions.defaultjar.JarAndroidTask; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.tasks.AbstractCopyTask; | ||
import org.gradle.api.tasks.TaskContainer; | ||
|
||
public interface SetupDefaultJarTasks extends AbstractExtension { | ||
default void setupDefaultEnvironment(Project target) { | ||
TaskContainer tasks = getProject().getTasks(); | ||
|
||
|
||
AbstractCopyTask jar = (AbstractCopyTask) tasks.getByName("jar"); | ||
MindustryModCoreExtension extension = target.getExtensions().getByType(MindustryModCoreExtension.class); | ||
jar.exclude(extension.getProjectInto().rootPackage.get()+"/entities/comp/**"); | ||
|
||
|
||
tasks.register("androidJar", JarAndroidTask.class,it->{ | ||
it.setGroup("build"); | ||
it.dependsOn("jar"); | ||
}); | ||
tasks.register("deploy", DeployTask.class, it->{ | ||
it.setGroup("build"); | ||
it.dependsOn("jar"); | ||
it.dependsOn("androidJar"); | ||
}); | ||
|
||
|
||
} | ||
|
||
default void setupDefaultEnvironment() { | ||
setupDefaultEnvironment(getProject()); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
buildSrc/src/main/groovy/mmc/extentions/defaultjar/DeployTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package mmc.extentions.defaultjar; | ||
|
||
|
||
import org.gradle.api.Project; | ||
import org.gradle.api.Task; | ||
import org.gradle.api.tasks.AbstractCopyTask; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.api.tasks.TaskContainer; | ||
import org.gradle.api.tasks.bundling.Zip; | ||
import org.gradle.jvm.tasks.Jar; | ||
|
||
public class DeployTask extends Zip { | ||
@TaskAction | ||
public void run(){ | ||
Project project = getProject(); | ||
TaskContainer tasks = project.getTasks(); | ||
Zip jar = (Zip) tasks.getByPath("jar"); | ||
Zip androidJar = (Zip) tasks.getByPath("androidJar"); | ||
|
||
|
||
from(project.zipTree(jar.getArchiveFile().get())); | ||
from(project.zipTree(androidJar.getArchiveFile().get())); | ||
doLast(it->{ | ||
project.delete(del->{ | ||
del.delete(jar.getArchiveFile(),androidJar.getArchiveFile()); | ||
}); | ||
}); | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
buildSrc/src/main/groovy/mmc/extentions/defaultjar/JarAndroidTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package mmc.extentions.defaultjar; | ||
|
||
import arc.struct.Seq; | ||
import arc.struct.Sort; | ||
import arc.util.Strings; | ||
import arc.util.Structs; | ||
import org.codehaus.groovy.runtime.ProcessGroovyMethods; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.GradleException; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.api.tasks.TaskContainer; | ||
import org.gradle.api.tasks.bundling.Zip; | ||
import org.gradle.jvm.tasks.Jar; | ||
|
||
import java.io.File; | ||
import java.io.FileDescriptor; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.sql.Struct; | ||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
|
||
public class JarAndroidTask extends Zip { | ||
|
||
@TaskAction | ||
public void run() throws IOException, InterruptedException { | ||
|
||
String sdkRoot = System.getenv("ANDROID_HOME"); | ||
if (sdkRoot == null) { | ||
sdkRoot = System.getenv("ANDROID_SDK_ROOT"); | ||
} | ||
if (sdkRoot == null || !new File(sdkRoot).exists()) | ||
throw new GradleException("No valid Android SDK found. Ensure that ANDROID_HOME is set to your Android SDK directory."); | ||
|
||
File[] files = new File("$sdkRoot/platforms/").listFiles(); | ||
Sort.instance().sort(files, Comparator.reverseOrder()); | ||
assert files != null; | ||
File platformRoot = Structs.find(files, f -> new File(f, "android.jar").exists()); | ||
|
||
if (platformRoot == null) | ||
throw new GradleException("No android.jar found. Ensure that you have an Android platform installed."); | ||
|
||
Seq<File> files1 = new Seq<>(); | ||
files1.add(new File(platformRoot, "android.jar")); | ||
getProject().getConfigurations().getByName("compileClasspath").forEach(files1::add); | ||
getProject().getConfigurations().getByName("runtimeClasspath").forEach(files1::add); | ||
//collect dependencies needed for desugaring | ||
String dependencies = files1.toString(" ", it -> "--classpath " + it.getPath()); | ||
|
||
String androidName = getArchiveBaseName().getOrElse(getProject().getName() + "Android.jar"); | ||
TaskContainer tasks = getProject().getTasks(); | ||
|
||
String desktopName = ((Zip) tasks.getByName("jar")).getArchiveBaseName().getOrElse(getProject().getName() + "Desktop.jar"); | ||
ProcessBuilder builder = new ProcessBuilder(); | ||
//dex and desugar files - this requires d8 in your PATH | ||
builder.command("d8 " + dependencies + " --min-api 14 --output " + androidName + " " + desktopName); | ||
builder.directory(new File(getProject().getBuildDir(), "libs")); | ||
ProcessGroovyMethods.waitForProcessOutput(builder.start(),(OutputStream) System.out, System.err); | ||
|
||
|
||
} | ||
} |