Cherry pick the banglets and such from wip-l1summercoat, this will be the basis for...
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / multivm / VMLibraryTaskUpToDate.java
blob3c86e13bf2a3d0daee777a035b44726e8ca1129e
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.TargetClassifier;
13 import java.io.File;
14 import java.time.Instant;
15 import java.util.HashSet;
16 import java.util.Set;
17 import org.gradle.api.Task;
18 import org.gradle.api.specs.Spec;
20 /**
21 * This is a check to determine if a task is up-to-date or not for the library
22 * compiler.
24 * @since 2020/11/28
26 public class VMLibraryTaskUpToDate
27 implements Spec<Task>
29 /** The classifier used. */
30 protected final TargetClassifier classifier;
32 /**
33 * Initializes the task dependencies.
35 * @param __classifier The classifier used.
36 * @throws NullPointerException On null arguments.
37 * @since 2020/11/28
39 public VMLibraryTaskUpToDate(TargetClassifier __classifier)
40 throws NullPointerException
42 if (__classifier == null)
43 throw new NullPointerException("NARG");
45 this.classifier = __classifier;
48 /**
49 * {@inheritDoc}
50 * @since 2020/11/28
52 @Override
53 public boolean isSatisfiedBy(Task __task)
55 // Get the times the output was last changed
56 Set<Instant> taskOuts = new HashSet<>();
57 for (File f : __task.getOutputs().getFiles().getFiles())
58 taskOuts.add(Instant.ofEpochMilli(f.lastModified()));
60 // Determine if any part of the compiler was not considered up-to-date
61 for (Task dep : this.classifier.getVmType().processLibraryDependencies(
62 (VMExecutableTask)__task, this.classifier.getBangletVariant()))
64 for (File f : dep.getOutputs().getFiles().getFiles())
66 Instant fileTime = Instant.ofEpochMilli(f.lastModified());
68 // One of the JARs the compiler uses is newer than the JAR we
69 // made, so this is not up-to-date!
70 for (Instant taskOut : taskOuts)
71 if (fileTime.compareTo(taskOut) > 0)
72 return false;
76 // Considered up to date
77 return true;