Make it so mapping files are used and then reapplied.
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / multivm / VMLibraryTask.java
blobd16c03618db0d6d75ee0fd2ff261a4a9fb9f39b3
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // 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.multivm.ident.SourceTargetClassifier;
13 import java.nio.file.Path;
14 import javax.inject.Inject;
15 import lombok.Getter;
16 import org.gradle.api.DefaultTask;
17 import org.gradle.api.Project;
18 import org.gradle.api.Task;
19 import org.gradle.api.internal.AbstractTask;
20 import org.gradle.api.provider.Provider;
21 import org.gradle.api.tasks.Internal;
22 import org.gradle.api.tasks.bundling.AbstractArchiveTask;
23 import org.gradle.jvm.tasks.Jar;
25 /**
26 * This task is responsible for creating a library that is used for the task
27 * execution.
29 * @since 2020/08/07
31 public class VMLibraryTask
32 extends DefaultTask
33 implements VMBaseTask, VMExecutableTask
35 /** The base JAR. */
36 @Internal
37 @Getter
38 public final AbstractTask baseJar;
40 /** The classifier used. */
41 @Internal
42 @Getter
43 private final SourceTargetClassifier classifier;
45 /**
46 * Initializes the library creation task.
48 * @param __classifier The classifier used.
49 * @param __baseJar The task with the Jar output.
50 * @throws NullPointerException On null arguments.
51 * @since 2020/08/07
53 @Inject
54 public VMLibraryTask(SourceTargetClassifier __classifier,
55 AbstractTask __baseJar)
56 throws NullPointerException
58 if (__classifier == null || __baseJar == null)
59 throw new NullPointerException("NARG");
61 // These are used at the build stage
62 this.baseJar = __baseJar;
63 this.classifier = __classifier;
65 // Set details of this task
66 this.setGroup("squirreljme");
67 this.setDescription("Compiles/constructs the library for execution.");
69 // The JAR we are compiling has to be built first
70 // We also need the virtual machine library compiler as well
71 this.dependsOn(__baseJar, new VMLibraryTaskDependencies(this,
72 __classifier.getTargetClassifier()));
74 // Only run if the JAR would run
75 this.onlyIf(this::onlyIf);
77 // The input of this task is the JAR that was created
78 this.getInputs().file(this.getProject().provider(() ->
79 VMHelpers.onlyFile(__baseJar.getOutputs().getFiles(),
80 "jar")));
82 // The output depends on the task and its source set
83 this.getOutputs().files(
84 this.getProject().provider(() -> this.__taskOutputFile()));
85 this.getOutputs().upToDateWhen(
86 new VMLibraryTaskUpToDate(__classifier.getTargetClassifier()));
88 // Performs the action of the task
89 this.doLast(new VMLibraryTaskAction(__classifier));
92 /**
93 * When should this run?
95 * @param __task The task to check.
96 * @return If this should run.
97 * @since 2022/05/20
99 private boolean onlyIf(Task __task)
101 return this.baseJar.getOnlyIf().isSatisfiedBy(this.baseJar);
105 * Returns the output path of the archive.
107 * @return The output path.
108 * @since 2020/08/07
110 public final Provider<Path> outputPath()
112 return this.getProject().provider(() -> VMHelpers.cacheDir(
113 this.getProject(), this.classifier).get()
114 .resolve(this.classifier.getVmType()
115 .outputLibraryName(this.getProject(),
116 this.classifier.getSourceSet())));
120 * Returns the output file for this task.
122 * @return The output file for this task.
123 * @since 2022/05/20
125 private Object __taskOutputFile()
127 if (this.onlyIf(this))
128 return this.outputPath();
129 return null;