1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.plugin
.multivm
;
12 import cc
.squirreljme
.plugin
.SquirrelJMEPluginConfiguration
;
13 import java
.nio
.file
.Path
;
14 import java
.util
.Arrays
;
15 import java
.util
.Objects
;
16 import javax
.inject
.Inject
;
18 import org
.gradle
.api
.DefaultTask
;
19 import org
.gradle
.api
.Project
;
20 import org
.gradle
.api
.Task
;
21 import org
.gradle
.api
.provider
.Provider
;
22 import org
.gradle
.api
.tasks
.Internal
;
23 import org
.gradle
.jvm
.tasks
.Jar
;
26 * Performs compaction of the library so that it does not have debug
27 * information and is smaller.
31 public class VMCompactLibraryTask
37 public final Jar baseJar
;
39 /** The source set used. */
42 private final String sourceSet
;
45 * Initializes the compacting task.
47 * @param __sourceSet The source set this belongs to.
48 * @param __baseJar The original source Jar.
49 * @throws NullPointerException On null arguments.
53 public VMCompactLibraryTask(String __sourceSet
,
55 throws NullPointerException
57 if (__sourceSet
== null || __baseJar
== null)
58 throw new NullPointerException("NARG");
60 Project project
= this.getProject();
62 this.baseJar
= __baseJar
;
63 this.sourceSet
= __sourceSet
;
65 // Set details of this task
66 this.setGroup("squirreljme");
68 "Compacts the library and removes debugging info.");
70 // Depends on the base Jar but also depends on all the
71 // compactLibs for all dependencies
72 this.dependsOn(__baseJar
, this.getProject().provider(() ->
73 VMHelpers
.compactLibTaskDepends(this.getProject(),
76 // Only run if the source JAR would run
77 this.onlyIf(this::onlyIf
);
79 // The input of this is the original Jar
80 this.getInputs().files(this.inputBaseJarPath());
82 // Inputs are the proguard options, so if this changes we need to
84 this.getInputs().property("squirreljme.proguardOptions",
85 this.getProject().provider(() -> Objects
.toString(
86 SquirrelJMEPluginConfiguration
.configuration(project
)
89 // Remember if the shrinking option has changed
90 this.getInputs().property("squirreljme.noShrinking",
91 this.getProject().provider(() -> Boolean
.toString(
92 SquirrelJMEPluginConfiguration
.configuration(project
)
95 // Error code that is used for the prefix
96 this.getInputs().property("squirreljme.javaDocErrorCode",
97 this.getProject().provider(() -> Objects
.toString(
98 SquirrelJMEPluginConfiguration
.configuration(project
)
101 // Also include the built-in plugin options, in case those change as
103 this.getInputs().property("squirreljme.proguardOptionsDefault",
104 this.getProject().provider(() -> Arrays
.toString(
105 VMCompactLibraryTaskAction
._PARSE_SETTINGS
)));
107 // The output of this JAR is just where it should be placed, this
108 // includes the mapping file for incremental mapping
109 this.getOutputs().files(this.outputJarPath(), this.outputMapPath());
111 // Performs the action of the task
112 this.doLast(new VMCompactLibraryTaskAction(__sourceSet
));
116 * When should this run?
118 * @param __task The task to check.
119 * @return If this should run.
122 private boolean onlyIf(Task __task
)
124 return this.baseJar
.getOnlyIf().isSatisfiedBy(this.baseJar
);
128 * Returns the input Jar that will get transformed accordingly.
130 * @return The input Jar that we will be transforming.
133 public final Provider
<Path
> inputBaseJarPath()
135 return this.getProject().provider(() -> this.baseJar
.getOutputs()
136 .getFiles().getSingleFile().toPath());
140 * Returns the output path of the archive.
142 * @return The output path.
145 public final Provider
<Path
> outputJarPath()
147 return this.getProject().provider(() ->
148 this.getProject().getBuildDir().toPath()
149 .resolve("squirreljme").resolve("obfuscated")
150 .resolve(this.baseJar
.getOutputs().getFiles()
151 .getSingleFile().toPath().getFileName()));
155 * Returns the output path of the mapping file.
157 * @return The output path of the mapping file.
160 public final Provider
<Path
> outputMapPath()
162 return this.getProject().provider(() ->
164 Path jarOut
= this.outputJarPath().get();
166 return jarOut
.resolveSibling(
167 VMHelpers
.getBaseName(jarOut
) + ".map");