1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
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
.tasks
;
12 import cc
.squirreljme
.plugin
.SquirrelJMEPluginConfiguration
;
13 import java
.nio
.file
.Path
;
14 import java
.util
.Objects
;
15 import javax
.inject
.Inject
;
16 import org
.gradle
.api
.DefaultTask
;
17 import org
.gradle
.api
.Project
;
18 import org
.gradle
.api
.Task
;
19 import org
.gradle
.api
.file
.FileCollection
;
20 import org
.gradle
.jvm
.tasks
.Jar
;
21 import org
.gradle
.language
.jvm
.tasks
.ProcessResources
;
24 * Adds additional properties to the manifest file.
28 public class AdditionalManifestPropertiesTask
31 /** The source set used. */
32 protected final String sourceSet
;
35 * Initializes the task.
37 * @param __jar The JAR Task.
38 * @param __pr The process resources task.
39 * @param __sourceSet The source set used.
40 * @param __cleanTask The clean task.
41 * @throws NullPointerException On null arguments.
45 public AdditionalManifestPropertiesTask(Jar __jar
, ProcessResources __pr
,
46 String __sourceSet
, Task __cleanTask
)
47 throws NullPointerException
49 if (__jar
== null || __pr
== null || __sourceSet
== null ||
51 throw new NullPointerException("No tasks specified");
53 this.sourceSet
= __sourceSet
;
55 // Set details of this task
56 this.setGroup("squirreljme");
57 this.setDescription("Builds an additional manifest for this project.");
59 // Configure inputs and outputs
60 Project project
= this.getProject();
61 this.getInputs().files(
62 project
.provider(project
::getBuildFile
));
63 this.getOutputs().files(
64 project
.provider(this::__taskOutputAsFileCollection
));
66 // Clean must happen first
67 this.mustRunAfter(__cleanTask
);
69 // Add a bunch of properties as input that will change if any of
70 // these change in the configuration
71 this.getInputs().property("squirreljme.javaDocErrorCode",
72 this.getProject().provider(() -> Objects
.toString(
73 SquirrelJMEPluginConfiguration
.configuration(project
)
75 this.getInputs().property("squirreljme.definedConfigurations",
76 this.getProject().provider(() -> Objects
.toString(
77 SquirrelJMEPluginConfiguration
.configuration(project
)
78 .definedConfigurations
)));
79 this.getInputs().property("squirreljme.definedProfiles",
80 this.getProject().provider(() -> Objects
.toString(
81 SquirrelJMEPluginConfiguration
.configuration(project
)
83 this.getInputs().property("squirreljme.definedStandards",
84 this.getProject().provider(() -> Objects
.toString(
85 SquirrelJMEPluginConfiguration
.configuration(project
)
87 this.getInputs().property("squirreljme.midlets",
88 this.getProject().provider(() -> Objects
.toString(
89 SquirrelJMEPluginConfiguration
.configuration(project
)
91 this.getInputs().property("squirreljme.ignoreInLauncher",
92 this.getProject().provider(() -> Boolean
.toString(
93 SquirrelJMEPluginConfiguration
.configuration(project
)
95 this.getInputs().property("squirreljme.swmName",
96 this.getProject().provider(() -> Objects
.toString(
97 SquirrelJMEPluginConfiguration
.configuration(project
)
99 this.getInputs().property("squirreljme.swmType",
100 this.getProject().provider(() -> Objects
.toString(
101 SquirrelJMEPluginConfiguration
.configuration(project
)
103 this.getInputs().property("squirreljme.swmVendor",
104 this.getProject().provider(() -> Objects
.toString(
105 SquirrelJMEPluginConfiguration
.configuration(project
)
107 this.getInputs().property("squirreljme.mainClass",
108 this.getProject().provider(() -> Objects
.toString(
109 SquirrelJMEPluginConfiguration
.configuration(project
)
112 // This action creates the actual manifest file
113 this.doLast(new AdditionalManifestPropertiesTaskAction(
114 this.__taskOutput(), __sourceSet
));
116 // When the JAR is created it gets additional manifests from us
118 new ManifestTaskModifier(this.__taskOutput()));
120 // Jar and resources depend on this task
121 __jar
.dependsOn(this);
122 __pr
.dependsOn(this);
126 * Returns the output manifest file.
128 * @return The output manifest file.
133 return this.getProject().getBuildDir().toPath()
134 .resolve("squirreljme").resolve("manifests")
135 .resolve(this.sourceSet
).resolve("SQUIRRELJME.MF");
139 * Returns the output manifest file.
141 * @return The output manifest file.
144 private FileCollection
__taskOutputAsFileCollection()
146 return this.getProject().files(this.__taskOutput().toFile());