Commonize into PathUtils; On Linux/BSD try to use xdg-open/x-www-browser if Java...
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / tasks / AdditionalManifestPropertiesTask.java
blob67d930bfef201b611adbce71945d395525db99ab
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.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;
23 /**
24 * Adds additional properties to the manifest file.
26 * @since 2020/02/28
28 public class AdditionalManifestPropertiesTask
29 extends DefaultTask
31 /** The source set used. */
32 protected final String sourceSet;
34 /**
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.
42 * @since 2020/02/28
44 @Inject
45 public AdditionalManifestPropertiesTask(Jar __jar, ProcessResources __pr,
46 String __sourceSet, Task __cleanTask)
47 throws NullPointerException
49 if (__jar == null || __pr == null || __sourceSet == null ||
50 __cleanTask == 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)
74 .javaDocErrorCode)));
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)
82 .definedProfiles)));
83 this.getInputs().property("squirreljme.definedStandards",
84 this.getProject().provider(() -> Objects.toString(
85 SquirrelJMEPluginConfiguration.configuration(project)
86 .definedStandards)));
87 this.getInputs().property("squirreljme.midlets",
88 this.getProject().provider(() -> Objects.toString(
89 SquirrelJMEPluginConfiguration.configuration(project)
90 .midlets)));
91 this.getInputs().property("squirreljme.ignoreInLauncher",
92 this.getProject().provider(() -> Boolean.toString(
93 SquirrelJMEPluginConfiguration.configuration(project)
94 .ignoreInLauncher)));
95 this.getInputs().property("squirreljme.swmName",
96 this.getProject().provider(() -> Objects.toString(
97 SquirrelJMEPluginConfiguration.configuration(project)
98 .swmName)));
99 this.getInputs().property("squirreljme.swmType",
100 this.getProject().provider(() -> Objects.toString(
101 SquirrelJMEPluginConfiguration.configuration(project)
102 .swmType)));
103 this.getInputs().property("squirreljme.swmVendor",
104 this.getProject().provider(() -> Objects.toString(
105 SquirrelJMEPluginConfiguration.configuration(project)
106 .swmVendor)));
107 this.getInputs().property("squirreljme.mainClass",
108 this.getProject().provider(() -> Objects.toString(
109 SquirrelJMEPluginConfiguration.configuration(project)
110 .mainClass)));
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
117 __jar.manifest(
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.
129 * @since 2020/02/28
131 Path __taskOutput()
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.
142 * @since 2020/02/28
144 private FileCollection __taskOutputAsFileCollection()
146 return this.getProject().files(this.__taskOutput().toFile());