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
.multivm
;
12 import cc
.squirreljme
.plugin
.multivm
.ident
.SourceTargetClassifier
;
14 import java
.io
.IOException
;
15 import java
.nio
.file
.Files
;
16 import java
.nio
.file
.Path
;
17 import java
.time
.Instant
;
18 import java
.util
.HashSet
;
20 import org
.gradle
.api
.Task
;
21 import org
.gradle
.api
.specs
.Spec
;
24 * This is used to check if a test is considered invalid because one of the
25 * inputs is no longer up to date.
29 public class VMRunUpToDateWhen
32 /** The classifier used. */
33 protected final SourceTargetClassifier classifier
;
36 * Initializes the handler.
38 * @param __classifier The classifier used.
39 * @throws NullPointerException On null arguments.
42 public VMRunUpToDateWhen(SourceTargetClassifier __classifier
)
43 throws NullPointerException
45 if (__classifier
== null)
46 throw new NullPointerException("NARG");
48 this.classifier
= __classifier
;
56 public boolean isSatisfiedBy(Task __task
)
58 // Get the times the output was last changed
59 Set
<Instant
> taskOuts
= new HashSet
<>();
60 for (File f
: __task
.getOutputs().getFiles().getFiles())
61 taskOuts
.add(Instant
.ofEpochMilli(f
.lastModified()));
63 // Determine if any of our parent dependencies were out of date
64 for (Path dep
: VMHelpers
.runClassPath(__task
, this.classifier
,
70 fileTime
= Files
.getLastModifiedTime(dep
).toInstant();
72 catch (IOException ignored
)
77 // One of our runtime libraries is newer than our own outputs
78 for (Instant taskOut
: taskOuts
)
79 if (fileTime
.compareTo(taskOut
) > 0)
83 // Considered up to date