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 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
;
21 * Contains the task for creating a test JAR.
25 public class TestsJarTask
29 * Initializes the task.
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.");
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
);
54 * Only run this task in this situation.
56 * @param __task This task.
57 * @return If this should run or not.
60 private boolean __onlyIf(Task __task
)
62 // Only run if there are files to actually be added
63 return !this.__from().getAsFileTree().getFiles().isEmpty();
67 * Returns what makes up the test JAR.
69 * @return The files that make up the test JAR.
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());