Workaround for getting tests to work.
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / multivm / VMRunUpToDateWhen.java
blob2dcbcfb9bc1d5fe20839081fd2670ebb59a459b9
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.multivm;
12 import cc.squirreljme.plugin.multivm.ident.SourceTargetClassifier;
13 import java.io.File;
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;
19 import java.util.Set;
20 import org.gradle.api.Task;
21 import org.gradle.api.specs.Spec;
23 /**
24 * This is used to check if a test is considered invalid because one of the
25 * inputs is no longer up to date.
27 * @since 2021/02/23
29 public class VMRunUpToDateWhen
30 implements Spec<Task>
32 /** The classifier used. */
33 protected final SourceTargetClassifier classifier;
35 /**
36 * Initializes the handler.
38 * @param __classifier The classifier used.
39 * @throws NullPointerException On null arguments.
40 * @since 2021/02/23
42 public VMRunUpToDateWhen(SourceTargetClassifier __classifier)
43 throws NullPointerException
45 if (__classifier == null)
46 throw new NullPointerException("NARG");
48 this.classifier = __classifier;
51 /**
52 * {@inheritDoc}
53 * @since 2021/02/23
55 @Override
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,
65 true))
67 Instant fileTime;
68 try
70 fileTime = Files.getLastModifiedTime(dep).toInstant();
72 catch (IOException ignored)
74 continue;
77 // One of our runtime libraries is newer than our own outputs
78 for (Instant taskOut : taskOuts)
79 if (fileTime.compareTo(taskOut) > 0)
80 return false;
83 // Considered up to date
84 return true;