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
.Collection
;
16 import java
.util
.LinkedHashSet
;
17 import java
.util
.Objects
;
18 import javax
.inject
.Inject
;
20 import org
.gradle
.api
.DefaultTask
;
21 import org
.gradle
.api
.Project
;
22 import org
.gradle
.api
.Task
;
23 import org
.gradle
.api
.provider
.Provider
;
24 import org
.gradle
.api
.tasks
.Internal
;
25 import org
.gradle
.jvm
.tasks
.Jar
;
28 * Performs compaction of the library so that it does not have debug
29 * information and is smaller.
33 public class VMCompactLibraryTask
39 public final Jar baseJar
;
41 /** The source set used. */
44 private final String sourceSet
;
47 * Initializes the compacting task.
49 * @param __sourceSet The source set this belongs to.
50 * @param __baseJar The original source Jar.
51 * @throws NullPointerException On null arguments.
55 public VMCompactLibraryTask(String __sourceSet
,
57 throws NullPointerException
59 if (__sourceSet
== null || __baseJar
== null)
60 throw new NullPointerException("NARG");
62 Project project
= this.getProject();
64 this.baseJar
= __baseJar
;
65 this.sourceSet
= __sourceSet
;
67 // Set details of this task
68 this.setGroup("squirreljme");
70 "Compacts the library and removes debugging info.");
72 // Depends on the base Jar but also depends on all the
73 // compactLibs for all dependencies
74 this.dependsOn(__baseJar
, this.getProject().provider(() ->
75 VMHelpers
.compactLibTaskDepends(this.getProject(),
78 // Only run if the source JAR would run
79 this.onlyIf(this::onlyIf
);
81 // The input of this is the original Jar and any Jars and maps that are
83 this.getInputs().files(this.inputBaseJarPath(),
84 this.getProject().provider(() -> {
85 Collection
<Object
> result
= new LinkedHashSet
<>();
86 for (VMCompactLibraryTask compactTask
:
87 VMHelpers
.compactLibTaskDepends(this.getProject(),
90 // If the input Jar changes, we want to update this one
91 result
.add(compactTask
.inputBaseJarPath());
93 // If the output Jar changes, we want that one as well
94 // since the mappings will be different
95 result
.add(compactTask
.outputJarPath());
101 // Inputs are the proguard options, so if this changes we need to
103 this.getInputs().property("squirreljme.proguardOptions",
104 this.getProject().provider(() -> Objects
.toString(
105 SquirrelJMEPluginConfiguration
.configuration(project
)
108 // Error code that is used for the prefix
109 this.getInputs().property("squirreljme.javaDocErrorCode",
110 this.getProject().provider(() -> Objects
.toString(
111 SquirrelJMEPluginConfiguration
.configuration(project
)
112 .javaDocErrorCode
)));
114 // Also include the built-in plugin options, in case those change as
116 this.getInputs().property("squirreljme.proguardOptionsDefault",
117 this.getProject().provider(() -> Arrays
.toString(
118 VMCompactLibraryTaskAction
._PARSE_SETTINGS
) +
119 Arrays
.toString(VMCompactLibraryTaskAction
._TEST_SETTINGS
)));
121 // The output of this JAR is just where it should be placed, this
122 // includes the mapping file for incremental mapping
123 this.getOutputs().files(this.outputJarPath(), this.outputMapPath());
125 // Performs the action of the task
126 this.doLast(new VMCompactLibraryTaskAction(__sourceSet
));
130 * When should this run?
132 * @param __task The task to check.
133 * @return If this should run.
136 private boolean onlyIf(Task __task
)
138 return this.baseJar
.getOnlyIf().isSatisfiedBy(this.baseJar
);
142 * Returns the input Jar that will get transformed accordingly.
144 * @return The input Jar that we will be transforming.
147 public final Provider
<Path
> inputBaseJarPath()
149 return this.getProject().provider(() -> this.baseJar
.getOutputs()
150 .getFiles().getSingleFile().toPath());
154 * Returns the output path of the archive.
156 * @return The output path.
159 public final Provider
<Path
> outputJarPath()
161 return this.getProject().provider(() ->
162 this.getProject().getBuildDir().toPath()
163 .resolve("squirreljme").resolve("obfuscated")
164 .resolve(this.baseJar
.getOutputs().getFiles()
165 .getSingleFile().toPath().getFileName()));
169 * Returns the output path of the mapping file.
171 * @return The output path of the mapping file.
174 public final Provider
<Path
> outputMapPath()
176 return this.getProject().provider(() ->
178 Path jarOut
= this.outputJarPath().get();
180 return jarOut
.resolveSibling(
181 VMHelpers
.getBaseName(jarOut
) + ".map");