Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/sourcetools/com.ibm.uma/com/ibm/uma/om/Module.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2017 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
package com.ibm.uma.om;
23
import java.util.Hashtable;
24
import java.util.Vector;
25
26
import com.ibm.uma.UMA;
27
import com.ibm.uma.UMAException;
28
29
public class Module extends PredicateList {
30
Vector<Artifact> artifacts = new Vector<Artifact>();
31
Hashtable<String,Exports> exports = new Hashtable<String, Exports>();
32
Hashtable<String, Objects> objects = new Hashtable<String, Objects>();
33
Hashtable<String, Flags> flags = new Hashtable<String, Flags>();
34
String modulePath;
35
String fullName;
36
boolean rootModule = false;
37
int moduleDepth;
38
39
public Module(String modulePath) {
40
super(modulePath);
41
this.modulePath = modulePath;
42
43
String rootDir = UMA.getUma().getRootDirectory();
44
String cleanedPath = modulePath.replace("\\", "/");
45
String[] pathParts = cleanedPath.substring(rootDir.length()).split("/");
46
if ( pathParts.length == 1 || pathParts[pathParts.length-2].equals("")) {
47
rootModule = true;
48
this.fullName = "";
49
this.moduleDepth = 0;
50
} else {
51
this.fullName = modulePath.substring(rootDir.length(),modulePath.length()-UMA.getUma().getConfiguration().getMetadataFilename().length()-1);
52
this.moduleDepth = pathParts.length-1;
53
}
54
55
//System.out.println("modulePath " + modulePath + "\nfullName " + this.fullName + "\nmoduleDepth " + this.moduleDepth );
56
}
57
58
public void addArtifact(Artifact artifact) throws UMAException {
59
if ( artifact.getType() == Artifact.TYPE_SUBDIR ) {
60
artifacts.insertElementAt(artifact,0);
61
} else {
62
artifacts.add(artifact);
63
}
64
}
65
66
public void addExports(String group, Exports exps) {
67
if ( exports.containsKey(group) ) {
68
exports.get(group).addExports(exps);
69
} else {
70
exports.put(group, exps);
71
}
72
}
73
74
public void addObjects(String group, Objects objs) {
75
objects.put(group, objs);
76
}
77
78
public void addFlags(String group, Flags f) {
79
flags.put(group, f);
80
}
81
82
public boolean isSet(String moduleProperty) {
83
return false;
84
}
85
86
public String getValue(String moduleProperty) {
87
return "";
88
}
89
90
public boolean isInPhase(int phase) throws UMAException {
91
for ( int j=0; j<artifacts.size(); j++ ) {
92
Artifact artifact = artifacts.elementAt(j);
93
if ( !artifact.evaluate()) continue;
94
if ( artifact.isInPhase(phase) ) return true;
95
}
96
return false;
97
}
98
99
public boolean containsArtifact(String artifactName) throws UMAException {
100
if ( artifactName == null ) return false;
101
for ( Artifact artifact : artifacts ) {
102
if ( !artifact.evaluate() ) continue;
103
switch (artifact.getType()) {
104
case Artifact.TYPE_BUNDLE:
105
case Artifact.TYPE_SHARED:
106
case Artifact.TYPE_EXECUTABLE:
107
case Artifact.TYPE_STATIC:
108
if ( artifact.getTargetName().equals(artifactName)) return true;
109
break;
110
case Artifact.TYPE_SUBDIR:
111
SubdirArtifact subdirArtifact = (SubdirArtifact) artifact;
112
if ( subdirArtifact.getSubdirModule().containsArtifact(artifactName) ) return true;
113
break;
114
}
115
116
}
117
return false;
118
}
119
120
public boolean containsNonStaticArtifacts() throws UMAException {
121
for ( Artifact artifact : artifacts ) {
122
if ( !artifact.evaluate() ) continue;
123
switch (artifact.getType()) {
124
case Artifact.TYPE_EXECUTABLE: //Fall-Thru
125
case Artifact.TYPE_SHARED: //Fall-Thru
126
case Artifact.TYPE_BUNDLE:
127
return true;
128
case Artifact.TYPE_SUBDIR:
129
SubdirArtifact subdirArtifact = (SubdirArtifact) artifact;
130
if ( subdirArtifact.getSubdirModule().containsNonStaticArtifacts() ) return true;
131
break;
132
}
133
134
}
135
return false;
136
}
137
138
public Vector<Artifact> getArtifacts() {
139
return artifacts;
140
}
141
142
public Vector<Artifact> getSubdirArtifacts() throws UMAException {
143
Vector<Artifact> subdirs = new Vector<Artifact>();
144
boolean artifactNotAdded = true;
145
int iterations = 0;
146
while( artifactNotAdded ) {
147
artifactNotAdded = false;
148
iterations ++;
149
if ( iterations > artifacts.size() ) {
150
throw new UMAException("Error: dependency loop detected in tree rooted at " + this.getFullName());
151
}
152
for ( Artifact a : artifacts ) {
153
if ( a.getType() != Artifact.TYPE_SUBDIR ) continue;
154
if ( subdirs.contains(a) ) continue;
155
int index = -2;
156
for ( String lib : a.getAllLibrariesInTree()) {
157
for ( Artifact b : artifacts ) {
158
if ( b == a || b.getType() != Artifact.TYPE_SUBDIR ) continue;
159
if ( b.isLibDefinedInTree(lib) ) {
160
// A library used by the current subdir 'a' is defined
161
// inside of subdir 'b', thus 'a' goes before 'b'.
162
// determine the index of 'b' and see if we are already
163
// scheduled to go in earlier.
164
int index2 = subdirs.indexOf(b);
165
if ( (index2 > index && index != -1) || index2 == -1 ) {
166
index = index2;
167
}
168
//System.out.println( a.getTargetName() + " [" + index2 + "] depends on " + b.getTargetName());
169
}
170
}
171
}
172
if ( index == -1 ) {
173
// artifact has dependencies not yet inserted.
174
artifactNotAdded = true;
175
} else if ( index == -2 ) {
176
// Found no dependencies, so insert a end
177
subdirs.insertElementAt(a, 0);
178
} else {
179
// insert before any dependencies
180
subdirs.insertElementAt(a, index+1);
181
}
182
}
183
}
184
return subdirs;
185
}
186
187
public Vector<Artifact> getStaticArtifacts() throws UMAException {
188
Vector<Artifact> statics = new Vector<Artifact>();
189
for ( Artifact a : artifacts ) {
190
if ( a.getType() == Artifact.TYPE_STATIC) {
191
statics.add(a);
192
}
193
}
194
return statics;
195
}
196
197
public Vector<Artifact> getSharedArtifacts() throws UMAException {
198
Vector<Artifact> shareds = new Vector<Artifact>();
199
for ( Artifact a : artifacts ) {
200
if ( a.getType() == Artifact.TYPE_SHARED || a.getType() == Artifact.TYPE_BUNDLE) {
201
shareds.add(a);
202
}
203
}
204
return shareds;
205
}
206
207
public Vector<Artifact> getExecutableArtifacts() throws UMAException {
208
Vector<Artifact> executables = new Vector<Artifact>();
209
for ( Artifact a : artifacts ) {
210
if ( a.getType() == Artifact.TYPE_EXECUTABLE) {
211
executables.add(a);
212
}
213
}
214
return executables;
215
}
216
217
public Hashtable<String,Exports> getExports() {
218
return exports;
219
}
220
221
public Hashtable<String,Objects> getObjects() {
222
return objects;
223
}
224
225
public Hashtable<String,Flags> getFlags() {
226
return flags;
227
}
228
229
public String getModulePath() {
230
return modulePath;
231
}
232
233
public String getFullName() {
234
return fullName;
235
}
236
237
public String getLogicalFullName() {
238
if (rootModule) return "root";
239
return "root/" + fullName;
240
}
241
242
public int getModuleDepth() {
243
return moduleDepth;
244
}
245
246
public String moduleNameAtDepth(int depth) {
247
String[] moduleNames = getLogicalFullName().split("/");
248
return moduleNames[depth];
249
}
250
251
public boolean isTopLevel() {
252
if ( rootModule ) return true;
253
return false;
254
}
255
256
public String getTopLevelName() {
257
return moduleNameAtDepth(0);
258
}
259
260
public String[] getParents() {
261
int modDepth = getModuleDepth();
262
if ( modDepth == 0 ) return null;
263
String[] parents = new String[modDepth];
264
String parent = getTopLevelName();
265
parents[0] = parent;
266
for ( int depth = 1; depth < modDepth; depth++ ) {
267
parent = parent + "/" + moduleNameAtDepth(depth);
268
parents[depth] = parent;
269
}
270
return parents;
271
}
272
273
public boolean containsEnabledArtifacts() throws UMAException {
274
for ( Artifact artifact : artifacts ) {
275
if ( !artifact.evaluate() ) continue;
276
if ( artifact.getType() == Artifact.TYPE_SUBDIR ) {
277
SubdirArtifact subdirArtifact = (SubdirArtifact) artifact;
278
if ( subdirArtifact.getSubdirModule().containsEnabledArtifacts() ) return true;
279
} else {
280
return true;
281
}
282
}
283
return false;
284
285
}
286
287
public boolean requiresDispatchMakefile() throws UMAException {
288
int numEnabledArtifacts = 0;
289
for ( Artifact artifact : artifacts ) {
290
if ( !artifact.evaluate() ) continue;
291
if ( artifact.getType() == Artifact.TYPE_SUBDIR ) {
292
SubdirArtifact subdirArtifact = (SubdirArtifact) artifact;
293
if ( subdirArtifact.getSubdirModule().containsEnabledArtifacts() ) return true;
294
} else {
295
numEnabledArtifacts ++;
296
}
297
}
298
if ( numEnabledArtifacts > 1 ) return true;
299
return false;
300
}
301
302
public Vector<Artifact> getAllArtifactsInTree() throws UMAException {
303
Vector<Artifact> allArtifacts = new Vector<Artifact>();
304
for ( Artifact artifact : artifacts ) {
305
if ( !artifact.evaluate() ) continue;
306
if (artifact.getType() == Artifact.TYPE_REFERENCE) continue;
307
if (artifact.getType() == Artifact.TYPE_SUBDIR) {
308
Module subdirModule = ((SubdirArtifact)artifact).getSubdirModule();
309
allArtifacts.addAll(subdirModule.getAllArtifactsInTree());
310
} else {
311
allArtifacts.add(artifact);
312
}
313
}
314
return allArtifacts;
315
}
316
317
public String[] getAllLibrariesInTree() {
318
Vector<String> allLibs = new Vector<String>();
319
for ( Artifact artifact : artifacts ) {
320
for ( String lib : artifact.getAllLibrariesInTree() ) {
321
allLibs.add(lib);
322
}
323
}
324
String[] libs = new String[allLibs.size()];
325
allLibs.toArray(libs);
326
return libs;
327
}
328
329
public boolean isLibDefinedInTree( String lib ) {
330
for ( Artifact artifact : artifacts ) {
331
if ( artifact.isLibDefinedInTree(lib) ) return true;
332
}
333
return false;
334
}
335
}
336
337
338