Cherry pick String off-loading improvements from `wip-nanocoatexec`.
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / tasks / TestsJarTask.java
blobc6db0f7a73d26fed874e7f38400801f33eba5458
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 Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc.squirreljme.plugin.tasks;
12 import java.util.concurrent.Callable;
13 import javax.inject.Inject;
14 import org.gradle.api.Task;
15 import org.gradle.api.file.FileCollection;
16 import org.gradle.api.plugins.JavaPluginConvention;
17 import org.gradle.api.tasks.SourceSet;
18 import org.gradle.api.tasks.bundling.Jar;
20 /**
21 * Contains the task for creating a test JAR.
23 * @since 2020/03/04
25 public class TestsJarTask
26 extends Jar
28 /**
29 * Initializes the task.
31 * @since 2020/03/04
33 @Inject
34 public TestsJarTask(Task __testClasses, Task __testResources)
36 // Depend on these two tasks because they have to be done first
37 this.dependsOn(__testClasses, __testResources);
38 this.mustRunAfter(__testClasses, __testResources);
40 // Set details of this task
41 this.setGroup("squirreljme");
42 this.setDescription("Builds the test JAR which is needed to run " +
43 "tests from within the VM.");
45 // Setup the task
46 this.getArchiveClassifier().set("test");
47 this.from((Callable<FileCollection>)this::__from);
49 // Only run if there are actual tests
50 this.onlyIf(this::__onlyIf);
53 /**
54 * Only run this task in this situation.
56 * @param __task This task.
57 * @return If this should run or not.
58 * @since 2022/05/20
60 private boolean __onlyIf(Task __task)
62 // Only run if there are files to actually be added
63 return !this.__from().getAsFileTree().getFiles().isEmpty();
66 /**
67 * Returns what makes up the test JAR.
69 * @return The files that make up the test JAR.
70 * @since 2020/03/04
72 private FileCollection __from()
74 SourceSet set = this.getProject().getConvention()
75 .getPlugin(JavaPluginConvention.class).getSourceSets()
76 .getByName(SourceSet.TEST_SOURCE_SET_NAME);
77 return this.getProject().files(set.getOutput().getClassesDirs(),
78 set.getOutput().getResourcesDir());