Compilation fixes with missing import.
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / multivm / VMCompactLibraryTask.java
blobd2c93b174d4808696f169e1f7b61244aa624afab
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;
17 import lombok.Getter;
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;
25 /**
26 * Performs compaction of the library so that it does not have debug
27 * information and is smaller.
29 * @since 2023/02/01
31 public class VMCompactLibraryTask
32 extends DefaultTask
34 /** The base JAR. */
35 @Internal
36 @Getter
37 public final Jar baseJar;
39 /** The source set used. */
40 @Internal
41 @Getter
42 private final String sourceSet;
44 /**
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.
50 * @since 2023/02/01
52 @Inject
53 public VMCompactLibraryTask(String __sourceSet,
54 Jar __baseJar)
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");
67 this.setDescription(
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(),
74 this.sourceSet)));
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
83 // do a rebuild!
84 this.getInputs().property("squirreljme.proguardOptions",
85 this.getProject().provider(() -> Objects.toString(
86 SquirrelJMEPluginConfiguration.configuration(project)
87 .proGuardOptions)));
89 // Error code that is used for the prefix
90 this.getInputs().property("squirreljme.javaDocErrorCode",
91 this.getProject().provider(() -> Objects.toString(
92 SquirrelJMEPluginConfiguration.configuration(project)
93 .javaDocErrorCode)));
95 // Also include the built-in plugin options, in case those change as
96 // well!
97 this.getInputs().property("squirreljme.proguardOptionsDefault",
98 this.getProject().provider(() -> Arrays.toString(
99 VMCompactLibraryTaskAction._PARSE_SETTINGS)));
101 // The output of this JAR is just where it should be placed, this
102 // includes the mapping file for incremental mapping
103 this.getOutputs().files(this.outputJarPath(), this.outputMapPath());
105 // Performs the action of the task
106 this.doLast(new VMCompactLibraryTaskAction(__sourceSet));
110 * When should this run?
112 * @param __task The task to check.
113 * @return If this should run.
114 * @since 2023/02/01
116 private boolean onlyIf(Task __task)
118 return this.baseJar.getOnlyIf().isSatisfiedBy(this.baseJar);
122 * Returns the input Jar that will get transformed accordingly.
124 * @return The input Jar that we will be transforming.
125 * @since 2023/02/05
127 public final Provider<Path> inputBaseJarPath()
129 return this.getProject().provider(() -> this.baseJar.getOutputs()
130 .getFiles().getSingleFile().toPath());
134 * Returns the output path of the archive.
136 * @return The output path.
137 * @since 2023/02/01
139 public final Provider<Path> outputJarPath()
141 return this.getProject().provider(() ->
142 this.getProject().getBuildDir().toPath()
143 .resolve("squirreljme").resolve("obfuscated")
144 .resolve(this.baseJar.getOutputs().getFiles()
145 .getSingleFile().toPath().getFileName()));
149 * Returns the output path of the mapping file.
151 * @return The output path of the mapping file.
152 * @since 2023/02/05
154 public final Provider<Path> outputMapPath()
156 return this.getProject().provider(() ->
158 Path jarOut = this.outputJarPath().get();
160 return jarOut.resolveSibling(
161 VMHelpers.getBaseName(jarOut) + ".map");