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 / util / SingleTaskOutputFile.java
blobdf04d4f651227c764d2dc53faa62fd7ef7b1e35e
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.util;
12 import java.nio.file.Path;
13 import java.util.concurrent.Callable;
14 import org.gradle.api.Task;
15 import org.gradle.api.file.FileCollection;
17 /**
18 * This takes the output of a task and provides a {@link Callable} so that
19 * it produces that single file.
21 * @since 2020/09/06
23 public class SingleTaskOutputFile
24 implements Callable<Path>
26 /** The task to get. */
27 protected final Task task;
29 /**
30 * Initializes the utility.
32 * @param __task The task to extract from.
33 * @throws NullPointerException On null arguments.
34 * @since 2020/09/06
36 public SingleTaskOutputFile(Task __task)
37 throws NullPointerException
39 if (__task == null)
40 throw new NullPointerException("NARG");
42 this.task = __task;
45 /**
46 * {@inheritDoc}
47 * @since 2020/09/06
49 @Override
50 public Path call()
52 FileCollection files = this.task.getOutputs().getFiles();
54 if (files.getFiles().isEmpty())
55 return null;
57 return files.getSingleFile().toPath();