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 / ident / SourceTargetClassifier.java
blobcb77161492520856c9ce3363dc638b3799ff3a71
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: 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.ident;
12 import cc.squirreljme.plugin.multivm.BangletVariant;
13 import cc.squirreljme.plugin.multivm.VMHelpers;
14 import cc.squirreljme.plugin.multivm.VMSpecifier;
15 import cc.squirreljme.plugin.multivm.VMType;
16 import lombok.AllArgsConstructor;
17 import lombok.Builder;
18 import lombok.NonNull;
19 import lombok.Value;
20 import org.gradle.api.tasks.SourceSet;
22 /**
23 * Represents a source set and a target classifier.
25 * @since 2022/10/01
27 @Value
28 @AllArgsConstructor
29 @Builder
30 public class SourceTargetClassifier
32 /** The source set used. */
33 @NonNull
34 String sourceSet;
36 /** The classifier for the target that is used. */
37 @NonNull
38 TargetClassifier targetClassifier;
40 /**
41 * Initializes the classifier.
43 * @param __sourceSet The source set.
44 * @param __vmType The virtual machine type.
45 * @param __variant The variant used.
46 * @since 2022/10/01
48 public SourceTargetClassifier(String __sourceSet, VMSpecifier __vmType,
49 BangletVariant __variant)
51 this(__sourceSet, new TargetClassifier(__vmType, __variant));
54 /**
55 * Returns the banglet variant used.
57 * @return The banglet variant used.
58 * @since 2022/10/01
60 public BangletVariant getBangletVariant()
62 return this.getTargetClassifier().getBangletVariant();
65 /**
66 * Returns the virtual machine type.
68 * @return The virtual machine type.
69 * @since 2022/10/01
71 public VMSpecifier getVmType()
73 return this.getTargetClassifier().getVmType();
76 /**
77 * Is this the main source set?
79 * @return If this is the main source set or not.
80 * @since 2022/10/01
82 public boolean isMainSourceSet()
84 return this.sourceSet.equals(SourceSet.MAIN_SOURCE_SET_NAME);
87 /**
88 * Is this the test fixtures source set?
90 * @return If this is the test fixtures source set or not.
91 * @since 2022/10/01
93 public boolean isTestFixturesSourceSet()
95 return this.sourceSet.equals(VMHelpers.TEST_FIXTURES_SOURCE_SET_NAME);
98 /**
99 * Is this the test source set?
101 * @return If this is the test source set or not.
102 * @since 2022/10/01
104 public boolean isTestSourceSet()
106 return this.sourceSet.equals(SourceSet.TEST_SOURCE_SET_NAME);
110 * Modifies this classifier with the given source set.
112 * @param __sourceSet The source set to use instead.
113 * @return The classifier for the given source set.
114 * @throws NullPointerException On null arguments.
115 * @since 2022/10/01
117 public SourceTargetClassifier withSourceSet(String __sourceSet)
118 throws NullPointerException
120 if (__sourceSet == null)
121 throw new NullPointerException("NARG");
123 // No change?
124 if (this.sourceSet.equals(__sourceSet))
125 return this;
127 // Is changed
128 return new SourceTargetClassifier(__sourceSet, this.targetClassifier);
132 * Specifies an alternative virtual machine to use, but with the same
133 * source set.
135 * @param __vm The virtual machine to use instead.
136 * @return The modified source target classifier.
137 * @throws NullPointerException On null arguments.
138 * @since 2022/12/23
140 public SourceTargetClassifier withVm(VMSpecifier __vm)
141 throws NullPointerException
143 if (__vm == null)
144 throw new NullPointerException("NARG");
146 return new SourceTargetClassifier(this.sourceSet,
147 this.targetClassifier.withVm(__vm));
151 * Returns the classifier to be used by the emulated JIT.
153 * @return The classifier with the appropriate VM based on if it supports
154 * emulated JIT.
155 * @since 2022/12/23
157 public SourceTargetClassifier withVmByEmulatedJit()
159 if (this.targetClassifier.getVmType().hasEmulatorJit())
160 return new SourceTargetClassifier(this.sourceSet,
161 this.targetClassifier.withVmByEmulatedJit());
162 return this;