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 Mozilla Public License Version 2.0.
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
.util
.StringUtils
;
14 import cc
.squirreljme
.runtime
.cldc
.util
.UnmodifiableIterator
;
15 import java
.lang
.ref
.Reference
;
16 import java
.lang
.ref
.WeakReference
;
17 import java
.util
.Arrays
;
18 import java
.util
.Collection
;
19 import java
.util
.Iterator
;
20 import java
.util
.LinkedHashSet
;
24 * This contains all of the information for dependencies which are provided
25 * by an application or library.
29 public final class ProvidedInfo
30 implements Iterable
<MarkedProvided
>
32 /** Provided fields. */
33 private final MarkedProvided
[] _provided
;
35 /** String representation. */
36 private Reference
<String
> _string
;
39 * Initializes the provided dependency info.
41 * @param __provs The provided set.
44 public ProvidedInfo(MarkedProvided
... __provs
)
47 __provs
= (__provs
== null ?
new MarkedProvided
[0] : __provs
.clone());
50 for (MarkedProvided o
: __provs
)
52 throw new NullPointerException("NARG");
54 this._provided
= __provs
;
58 * Initializes the provided dependency info.
60 * @param __provs The provided set.
61 * @throws NullPointerException On null arguments.
64 public ProvidedInfo(Collection
<MarkedProvided
> __provs
)
65 throws NullPointerException
67 this(__provs
.<MarkedProvided
>toArray(
68 new MarkedProvided
[__provs
.size()]));
76 public final boolean equals(Object __o
)
81 if (!(__o
instanceof ProvidedInfo
))
84 return Arrays
.equals(this._provided
, ((ProvidedInfo
)__o
)._provided
);
92 public final int hashCode()
94 return Arrays
.asList(this._provided
).hashCode();
102 public Iterator
<MarkedProvided
> iterator()
104 return UnmodifiableIterator
.of(this._provided
);
112 public final String
toString()
114 Reference
<String
> ref
= this._string
;
117 if (ref
== null || null == (rv
= ref
.get()))
118 this._string
= new WeakReference
<>(
119 (rv
= Arrays
.asList(this._provided
).toString()));
125 * Parses the given suite information and returns all of the provided
126 * resolutions for dependencies which are specified in the manifest.
128 * @param __info The suite information to parse.
129 * @return The parsed provided resolution information.
130 * @throws InvalidSuiteException If the manifest is not correct.
131 * @throws NullPointerException On null arguments.
134 public static ProvidedInfo
of(SuiteInfo __info
)
135 throws InvalidSuiteException
, NullPointerException
138 throw new NullPointerException("NARG");
140 Set
<MarkedProvided
> provided
= new LinkedHashSet
<>();
141 JavaManifestAttributes attr
= __info
.manifest().getMainAttributes();
144 // Defined configurations
145 value
= attr
.getValue("X-SquirrelJME-DefinedConfigurations");
147 for (String s
: StringUtils
.basicSplit(" \t", value
))
148 provided
.add(new Configuration(s
));
151 value
= attr
.getValue("X-SquirrelJME-DefinedProfiles");
153 for (String s
: StringUtils
.basicSplit(" \t", value
))
154 provided
.add(new Profile(s
));
157 value
= attr
.getValue("X-SquirrelJME-DefinedStandards");
159 for (String s
: StringUtils
.basicSplit(",", value
))
160 provided
.add(new Standard(s
.trim()));
162 // Has internal project name?
163 String internalname
= attr
.getValue(
164 "X-SquirrelJME-InternalProjectName");
165 if (internalname
!= null)
166 provided
.add(new InternalName(internalname
));
168 // This provides a library or otherwise
169 provided
.add(new TypedSuite(__info
.type(), __info
.suite()));
172 return new ProvidedInfo(provided
);