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
.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
;
25 * This contains all of the information for dependencies which are provided
26 * by an application or library.
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
;
41 * Initializes the provided dependency info.
43 * @param __provs The provided set.
47 public ProvidedInfo(MarkedProvided
... __provs
)
50 __provs
= (__provs
== null ?
new MarkedProvided
[0] : __provs
.clone());
53 for (MarkedProvided o
: __provs
)
55 throw new NullPointerException("NARG");
57 this._provided
= __provs
;
61 * Initializes the provided dependency info.
63 * @param __provs The provided set.
64 * @throws NullPointerException On null arguments.
68 public ProvidedInfo(Collection
<MarkedProvided
> __provs
)
69 throws NullPointerException
71 this(__provs
.<MarkedProvided
>toArray(
72 new MarkedProvided
[__provs
.size()]));
80 public final boolean equals(Object __o
)
85 if (!(__o
instanceof ProvidedInfo
))
88 return Arrays
.equals(this._provided
, ((ProvidedInfo
)__o
)._provided
);
96 public final int hashCode()
98 return Arrays
.asList(this._provided
).hashCode();
106 public Iterator
<MarkedProvided
> iterator()
108 return UnmodifiableIterator
.of(this._provided
);
116 public final String
toString()
118 Reference
<String
> ref
= this._string
;
121 if (ref
== null || null == (rv
= ref
.get()))
122 this._string
= new WeakReference
<>(
123 (rv
= Arrays
.asList(this._provided
).toString()));
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.
139 public static ProvidedInfo
of(SuiteInfo __info
)
140 throws InvalidSuiteException
, NullPointerException
143 throw new NullPointerException("NARG");
145 Set
<MarkedProvided
> provided
= new LinkedHashSet
<>();
146 JavaManifestAttributes attr
= __info
.manifest().getMainAttributes();
149 // Defined configurations
150 value
= attr
.getValue("X-SquirrelJME-DefinedConfigurations");
152 for (String s
: StringUtils
.basicSplit(" \t", value
))
153 provided
.add(new Configuration(s
));
156 value
= attr
.getValue("X-SquirrelJME-DefinedProfiles");
158 for (String s
: StringUtils
.basicSplit(" \t", value
))
159 provided
.add(new Profile(s
));
162 value
= attr
.getValue("X-SquirrelJME-DefinedStandards");
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()));
177 return new ProvidedInfo(provided
);