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 Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.plugin
.util
;
13 import java
.nio
.file
.Path
;
14 import java
.util
.ArrayList
;
15 import java
.util
.Collection
;
16 import java
.util
.Deque
;
17 import java
.util
.LinkedList
;
18 import org
.gradle
.api
.Project
;
19 import org
.gradle
.api
.file
.DirectoryTree
;
20 import org
.gradle
.api
.plugins
.JavaPluginConvention
;
21 import org
.gradle
.api
.tasks
.SourceSet
;
24 * Utilities regarding test detection.
28 public final class TestDetection
35 private TestDetection()
40 * Is this considered a test?
42 * @param __className The class name to check.
43 * @return If this is considered a test.
46 public static boolean isTest(String __className
)
47 throws NullPointerException
49 if (__className
== null)
50 throw new NullPointerException("NARG");
52 // Get base name of the class
53 int ld
= __className
.lastIndexOf('.');
54 String base
= (ld
< 0 ? __className
: __className
.substring(ld
+ 1));
56 return (base
.startsWith("Do") || base
.startsWith("Test") ||
57 base
.endsWith("Test"));
61 * Returns a collection of source set files.
63 * @param __project The __project to scan.
64 * @param __sourceSet The source set to read files from.
65 * @return A collection of files within the source set.
66 * @throws NullPointerException On null arguments.
69 public static Collection
<FileLocation
> sourceSetFiles(Project __project
,
71 throws NullPointerException
73 if (__project
== null || __sourceSet
== null)
74 throw new NullPointerException("NARG");
76 // Get base source sets
77 SourceSet sourceSet
= __project
.getConvention().getPlugin(
78 JavaPluginConvention
.class).getSourceSets().getByName(__sourceSet
);
80 // Add normal Java sources along with resources (for Jasmin)
81 Deque
<DirectoryTree
> queue
= new LinkedList
<>();
82 queue
.addAll(sourceSet
.getJava().getSrcDirTrees());
83 queue
.addAll(sourceSet
.getResources().getSrcDirTrees());
85 // Discover all the input files (in sources)
86 Collection
<FileLocation
> result
= new ArrayList
<>();
87 while (!queue
.isEmpty())
89 DirectoryTree dir
= queue
.removeFirst();
90 Path baseDir
= dir
.getDir().toPath();
92 // Process all files in each directory
93 for (File file
: __project
.files(dir
))
95 Path path
= file
.toPath();
97 result
.add(new FileLocation(path
, baseDir
.relativize(path
)));