Make it so mapping files are used and then reapplied.
[SquirrelJME.git] / modules / cldc-compact / src / main / java / cc / squirreljme / jvm / suite / ProvidedInfo.java
blob64744214575cb52d2ea9daffbf573fa4ff9c21f6
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.jvm.suite;
12 import cc.squirreljme.jvm.manifest.JavaManifestAttributes;
13 import cc.squirreljme.runtime.cldc.annotation.Exported;
14 import cc.squirreljme.runtime.cldc.util.StringUtils;
15 import cc.squirreljme.runtime.cldc.util.UnmodifiableIterator;
16 import java.lang.ref.Reference;
17 import java.lang.ref.WeakReference;
18 import java.util.Arrays;
19 import java.util.Collection;
20 import java.util.Iterator;
21 import java.util.LinkedHashSet;
22 import java.util.Set;
24 /**
25 * This contains all of the information for dependencies which are provided
26 * by an application or library.
28 * @since 2017/11/30
30 @Exported
31 public final class ProvidedInfo
32 implements Iterable<MarkedProvided>
34 /** Provided fields. */
35 private final MarkedProvided[] _provided;
37 /** String representation. */
38 private Reference<String> _string;
40 /**
41 * Initializes the provided dependency info.
43 * @param __provs The provided set.
44 * @since 2017/12/31
46 @Exported
47 public ProvidedInfo(MarkedProvided... __provs)
49 // Defensive copy
50 __provs = (__provs == null ? new MarkedProvided[0] : __provs.clone());
52 // Check for nulls
53 for (MarkedProvided o : __provs)
54 if (o == null)
55 throw new NullPointerException("NARG");
57 this._provided = __provs;
60 /**
61 * Initializes the provided dependency info.
63 * @param __provs The provided set.
64 * @throws NullPointerException On null arguments.
65 * @since 2017/12/31
67 @Exported
68 public ProvidedInfo(Collection<MarkedProvided> __provs)
69 throws NullPointerException
71 this(__provs.<MarkedProvided>toArray(
72 new MarkedProvided[__provs.size()]));
75 /**
76 * {@inheritDoc}
77 * @since 2017/12/31
79 @Override
80 public final boolean equals(Object __o)
82 if (this == __o)
83 return true;
85 if (!(__o instanceof ProvidedInfo))
86 return false;
88 return Arrays.equals(this._provided, ((ProvidedInfo)__o)._provided);
91 /**
92 * {@inheritDoc}
93 * @since 2017/12/31
95 @Override
96 public final int hashCode()
98 return Arrays.asList(this._provided).hashCode();
102 * {@inheritDoc}
103 * @since 2021/01/31
105 @Override
106 public Iterator<MarkedProvided> iterator()
108 return UnmodifiableIterator.of(this._provided);
112 * {@inheritDoc}
113 * @since 2017/12/31
115 @Override
116 public final String toString()
118 Reference<String> ref = this._string;
119 String rv;
121 if (ref == null || null == (rv = ref.get()))
122 this._string = new WeakReference<>(
123 (rv = Arrays.asList(this._provided).toString()));
125 return rv;
129 * Parses the given suite information and returns all of the provided
130 * resolutions for dependencies which are specified in the manifest.
132 * @param __info The suite information to parse.
133 * @return The parsed provided resolution information.
134 * @throws InvalidSuiteException If the manifest is not correct.
135 * @throws NullPointerException On null arguments.
136 * @since 2017/11/20
138 @Exported
139 public static ProvidedInfo of(SuiteInfo __info)
140 throws InvalidSuiteException, NullPointerException
142 if (__info == null)
143 throw new NullPointerException("NARG");
145 Set<MarkedProvided> provided = new LinkedHashSet<>();
146 JavaManifestAttributes attr = __info.manifest().getMainAttributes();
147 String value;
149 // Defined configurations
150 value = attr.getValue("X-SquirrelJME-DefinedConfigurations");
151 if (value != null)
152 for (String s : StringUtils.basicSplit(" \t", value))
153 provided.add(new Configuration(s));
155 // Defined profiles
156 value = attr.getValue("X-SquirrelJME-DefinedProfiles");
157 if (value != null)
158 for (String s : StringUtils.basicSplit(" \t", value))
159 provided.add(new Profile(s));
161 // Defined standards
162 value = attr.getValue("X-SquirrelJME-DefinedStandards");
163 if (value != null)
164 for (String s : StringUtils.basicSplit(",", value))
165 provided.add(new Standard(s.trim()));
167 // Has internal project name?
168 String internalname = attr.getValue(
169 "X-SquirrelJME-InternalProjectName");
170 if (internalname != null)
171 provided.add(new InternalName(internalname));
173 // This provides a library or otherwise
174 provided.add(new TypedSuite(__info.type(), __info.suite()));
176 // Initialize
177 return new ProvidedInfo(provided);