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/Artifact.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.List;
25
import java.util.Vector;
26
27
import com.ibm.uma.IPlatform;
28
import com.ibm.uma.UMA;
29
import com.ibm.uma.UMAException;
30
31
public class Artifact extends PredicateList {
32
33
public static final int TYPE_SHARED = 1;
34
public static final int TYPE_STATIC = 2;
35
public static final int TYPE_EXECUTABLE = 3;
36
public static final int TYPE_SUBDIR = 4;
37
public static final int TYPE_BUNDLE = 5;
38
public static final int TYPE_REFERENCE = 6;
39
public static final int TYPE_TARGET = 7;
40
41
Hashtable<String, Library> allLibrariesThisArtifactDependsOn;
42
boolean appendRelease = false;
43
String bundle;
44
boolean console = true;
45
String description;
46
Vector<Export> exports = new Vector<Export>();
47
Vector<Flag> flags = new Vector<Flag>();
48
Vector<Include> includes = new Vector<Include>();
49
Vector<Library> libraries = new Vector<Library>();
50
Vector<Command> commands = new Vector<Command>();
51
Vector<Dependency> dependencies = new Vector<Dependency>();
52
String loadgroup;
53
String makefileName;
54
Vector<MakefileStub> makefileStubs = new Vector<MakefileStub>();
55
Module module;
56
String name;
57
String scope;
58
boolean includeInAllTarget;
59
Vector<Object> objects = new Vector<Object>();
60
Hashtable<String, Option> options = new Hashtable<String,Option>();
61
boolean[] phases = new boolean[UMA.getUma().getConfiguration().numberOfPhases()];
62
Vector<Library> staticLinkLibraries = new Vector<Library>();
63
boolean buildLocal = false;
64
int type;
65
Vector<VPath> vpaths = new Vector<VPath>();
66
public Artifact(Module module) {
67
super(module.getModulePath());
68
this.module = module;
69
for ( int phase=0; phase < UMA.getUma().getConfiguration().numberOfPhases(); phase ++ ) {
70
phases[phase] = false;
71
}
72
}
73
74
public Artifact copy() throws UMAException {
75
Artifact copy = new Artifact(module);
76
77
// Hashtable<String, Library> allLibrariesThisArtifactDependsOn; Cached when requested, no need to copy it.
78
// set type
79
copy.setType(getType());
80
// copy description
81
copy.setDescription(getDescription());
82
// copy commands
83
for ( Command command : getCommands() ) {
84
copy.addCommand(command);
85
}
86
// copy dependencies
87
for ( Dependency dependency : getDependendies() ) {
88
copy.addDependency(dependency);
89
}
90
// copy vpaths
91
for ( VPath vPath : getVPaths() ) {
92
copy.addVPath(vPath);
93
}
94
// copy options
95
for ( Option option : getOptions().values()) {
96
copy.addOption(option);
97
}
98
// copy phase information
99
for ( int k=0; k<UMA.getUma().getConfiguration().numberOfPhases(); k++ ) {
100
copy.setPhase(k, isInPhase(k));
101
}
102
// copy includes information
103
for( Include include : getIncludes() ) {
104
copy.addInclude(include);
105
}
106
// copy library information
107
for ( Library library : getLibraries() ) {
108
copy.addLibrary(library);
109
}
110
// copy static library information
111
for ( Library library : getStaticLinkLibraries() ) {
112
copy.addStaticLinkLibrary(library);
113
}
114
// copy object information
115
for ( Object object : getObjects() ) {
116
copy.addObject(object);
117
}
118
// copy makefile information
119
for ( MakefileStub makefileStub : getMakefileStubs() ){
120
copy.addMakefileStub(makefileStub);
121
}
122
// copy export information
123
for ( Export export : getExports() ) {
124
copy.addExport(export);
125
}
126
// copy flags
127
for ( Flag flag : getFlags() ) {
128
copy.addFlag(flag);
129
}
130
// set the scope
131
copy.setScope(getScope());
132
// set artifact name
133
copy.setName(getTargetName());
134
// set makefile name
135
copy.setMakefileName(getMakefileName());
136
137
// set various flags
138
copy.setBundle(getBundle());
139
copy.setLoadgroup(getLoadGroup());
140
copy.setBuildLocal(getBuildLocal());
141
copy.setAppendRelease(appendRelease());
142
copy.setConsoleApplication(isConsoleApplication());
143
copy.setIncludeInAllTarget(includeInAllTarget());
144
145
return copy;
146
}
147
148
public String getScope() {
149
return scope;
150
}
151
152
153
public void setScope(String scope) {
154
this.scope = scope;
155
if (makefileName != null && !makefileName.startsWith(scope+"_")) {
156
makefileName = scope + "_" + makefileName;
157
}
158
}
159
160
public void setIncludeInAllTarget(boolean includeInAllTarget) {
161
this.includeInAllTarget = includeInAllTarget;
162
}
163
164
public boolean includeInAllTarget() {
165
return includeInAllTarget;
166
}
167
168
public void addExport(Export export) {
169
exports.add(export);
170
}
171
172
public void addFlag(Flag flag) {
173
flags.add(flag);
174
}
175
176
public void addInclude(Include include) {
177
includes.add(include);
178
}
179
180
public void addCommand(Command command) {
181
commands.add(command);
182
}
183
184
public void addDependency(Dependency dependency) {
185
dependencies.add(dependency);
186
}
187
188
public void addLibrary(Library library) {
189
libraries.add(library);
190
}
191
192
public void addMakefileStub(MakefileStub makefileStub) {
193
makefileStubs.add(makefileStub);
194
}
195
196
public void addObject(Object object) {
197
objects.add(object);
198
}
199
200
public void addOption(Option option) {
201
options.put(option.getName(), option);
202
}
203
204
public void addStaticLinkLibrary(Library library) {
205
staticLinkLibraries.add(library);
206
}
207
208
public void addVPath(VPath vpath) {
209
vpaths.add(vpath);
210
}
211
212
public boolean appendRelease() {
213
return appendRelease;
214
}
215
216
@Override
217
public boolean evaluate() throws UMAException {
218
/*
219
* short circuit evaluation if this artifact was specified to be always excluded.
220
*/
221
List<String> excludedArtifacts = UMA.getUma().getConfiguration().getExcludedArtifacts();
222
if ( excludedArtifacts.contains(name)) return false;
223
return super.evaluate();
224
}
225
226
public boolean flagSet(String flag) throws UMAException {
227
Option option = options.get(flag);
228
if ( option == null || !option.evaluate() ) return false;
229
return true;
230
}
231
232
public String[] getAllLibrariesInTree() {
233
String[] libs = new String[libraries.size()];
234
for ( int i=0; i<libraries.size(); i++ ) {
235
libs[i] = libraries.elementAt(i).getName();
236
}
237
return libs;
238
}
239
240
public Hashtable<String, Library> getAllLibrariesThisArtifactDependsOn() throws UMAException {
241
if ( allLibrariesThisArtifactDependsOn == null ) {
242
allLibrariesThisArtifactDependsOn = new Hashtable<String, Library>();
243
for ( Library lib : libraries ) {
244
245
/* Check to see if the library should be included */
246
if (!lib.evaluate()) {
247
continue;
248
}
249
250
if ( allLibrariesThisArtifactDependsOn.get(lib.getName()) == null ) {
251
switch ( lib.getType() ) {
252
case Library.TYPE_BUILD:
253
Artifact artifact = UMA.getUma().getArtifact(lib.getName());
254
if ( artifact == null || !artifact.evaluate()) {
255
// this lib is not being built ignore it
256
continue;
257
}
258
259
if ( lib.getName().equals(getArtifactKey()) ) {
260
throw new UMAException("circular dependency artifact [" + getArtifactKey()+ "] defined in [" + getContainingFile() + "] depends on itself via artifact [" + artifact.getArtifactKey()+ "] defined in [" + artifact.getContainingFile() + "]" );
261
}
262
263
if ( artifact.isInBundle() && (!isInBundle() || !artifact.getBundle().equalsIgnoreCase(getBundle()))) {
264
if ( allLibrariesThisArtifactDependsOn.get(artifact.getBundle()) == null ) {
265
Library bundleLib = new Library(containingFile);
266
bundleLib.setName(artifact.getBundle());
267
bundleLib.setType("build");
268
allLibrariesThisArtifactDependsOn.put(artifact.getBundle(), bundleLib);
269
}
270
} else {
271
allLibrariesThisArtifactDependsOn.put(lib.getName(), lib);
272
}
273
274
Hashtable<String, Library> hasht = artifact.getAllLibrariesThisArtifactDependsOn();
275
for ( String libname : hasht.keySet() ) {
276
if ( allLibrariesThisArtifactDependsOn.get(libname) == null ) {
277
if ( libname.equals(getArtifactKey()) ) {
278
throw new UMAException("circular dependency artifact [" + getArtifactKey()+ "] defined in [" + getContainingFile() + "] depends on itself via artifact [" + artifact.getArtifactKey()+ "] defined in [" + artifact.getContainingFile() + "]" );
279
}
280
allLibrariesThisArtifactDependsOn.put(libname, hasht.get(libname));
281
}
282
}
283
break;
284
default:
285
allLibrariesThisArtifactDependsOn.put(lib.getName(), lib);
286
break;
287
}
288
}
289
}
290
}
291
return allLibrariesThisArtifactDependsOn;
292
}
293
294
public String getBundle() {
295
return bundle;
296
}
297
298
public Module getContainingModule() {
299
return module;
300
}
301
302
public String[] getData(String name) throws UMAException {
303
Option option = options.get(name);
304
if ( option == null || !option.evaluate() ) return null;
305
return option.getData();
306
}
307
308
public String getDescription() {
309
return description;
310
}
311
312
public Vector<Export> getExportedFunctions() throws UMAException {
313
if ( type == TYPE_BUNDLE ) {
314
return getBundleExportedFunctions();
315
} else {
316
return getArtifactExportedFunctions();
317
}
318
}
319
320
public Vector<Export> getArtifactExportedFunctions() throws UMAException {
321
Vector<Export> ef = new Vector<Export>();
322
for ( Export export : exports ) {
323
if ( !export.evaluate() ) continue;
324
switch ( export.getType() ) {
325
case Export.TYPE_FUNCTION:
326
ef.add(export);
327
break;
328
case Export.TYPE_GROUP:
329
Exports expGroup = module.getExports().get(export.getExport());
330
if ( expGroup == null ) {
331
throw new UMAException("Error: export group " + export.getExport() + " not found in module " + module.getModulePath() + ".");
332
}
333
if ( expGroup.evaluate() ) {
334
for ( Export exp : expGroup.getExports() ) {
335
if ( !exp.evaluate() ) continue;
336
switch ( exp.getType() ) {
337
case Export.TYPE_FUNCTION:
338
ef.add(exp);
339
break;
340
case Export.TYPE_GROUP:
341
throw new UMAException("Error: export group " + export.getExport() + " refers to another group [" + exp.getExport() +"] in module " + module.getModulePath() + ".");
342
}
343
}
344
}
345
}
346
}
347
return ef;
348
}
349
350
private Export addArtifactPrefix(Artifact artifact, Export export)
351
{
352
String exportName = export.getExport();
353
if (exportName.equals("JVM_OnLoad") || exportName.equals("JVM_OnUnload") || exportName.equals("J9VMDllMain") || exportName.equals("JNI_OnLoad") || exportName.equals("JNI_OnUnload") ) {
354
Export copy = new Export(export.containingFile);
355
copy.setExport(artifact.getTargetName() + "_" + exportName);
356
copy.setType(export.getType());
357
return copy;
358
}
359
360
return export;
361
}
362
363
public Vector<Export> getBundleExportedFunctions() throws UMAException {
364
Vector<Export> ef = new Vector<Export>();
365
Vector<Artifact> bundleArtifacts = getAllArtifactsInThisBundle();
366
for ( Artifact artifact : bundleArtifacts ) {
367
for ( Export export : artifact.exports ) {
368
if ( !export.evaluate() ) continue;
369
switch ( export.getType() ) {
370
case Export.TYPE_FUNCTION:
371
ef.add( addArtifactPrefix(artifact, export) );
372
break;
373
case Export.TYPE_GROUP:
374
Exports expGroup = artifact.module.getExports().get(export.getExport());
375
if ( expGroup == null ) {
376
throw new UMAException("Error: export group " + export.getExport() + " not found in module " + module.getModulePath() + ".");
377
}
378
if ( expGroup.evaluate() ) {
379
for ( Export exp : expGroup.getExports() ) {
380
if ( !exp.evaluate() ) continue;
381
switch ( exp.getType() ) {
382
case Export.TYPE_FUNCTION:
383
ef.add( addArtifactPrefix(artifact, exp) );
384
break;
385
case Export.TYPE_GROUP:
386
throw new UMAException("Error: export group " + export.getExport() + " refers to another group [" + exp.getExport() +"] in module " + module.getModulePath() + ".");
387
}
388
}
389
}
390
}
391
}
392
}
393
return ef;
394
}
395
396
397
public Vector<Export> getExports() {
398
return exports;
399
}
400
401
public Vector<Flag> getFlags() throws UMAException {
402
Vector<Flag> processedFlags = flags;
403
if (flags.size() > 0) {
404
processedFlags = new Vector<Flag>();
405
for (Flag f : flags) {
406
if (f == null) {
407
continue;
408
}
409
//System.out.println("Flag: " + (f == null ? "null" : f.getName()));
410
switch(f.type) {
411
case Flag.SINGLE:
412
processedFlags.add(f);
413
break;
414
case Flag.GROUP:
415
//System.out.println("Group Flag: " + f.getName() + " group:"+ f.groupName);
416
Flags group = module.getFlags().get(f.groupName);
417
if (group == null) {
418
throw new UMAException("Error: flags group " + f.groupName + " not found in module " + module.getModulePath() + ".");
419
}
420
for (Flag groupFlag : group.getFlags()) {
421
//System.out.println("Group Flag: " + groupFlag.getName() + " group:"+ f.groupName);
422
switch(groupFlag.type) {
423
case Flag.SINGLE:
424
processedFlags.add(groupFlag);
425
break;
426
case Flag.GROUP:
427
throw new UMAException("Error: flags group " + groupFlag.groupName + " inside group in " + module.getModulePath() + ".");
428
}
429
}
430
break;
431
}
432
}
433
}
434
return processedFlags;
435
}
436
437
public Vector<Include> getIncludes() {
438
return includes;
439
}
440
441
public Vector<Command> getCommands() {
442
return commands;
443
}
444
445
public Vector<Dependency> getDependendies() {
446
return dependencies;
447
}
448
449
450
public String getArtifactKey() {
451
String artifactKey = getTargetName();
452
if ( getScope() != null ) {
453
artifactKey = getScope() + "_" + artifactKey;
454
}
455
return artifactKey;
456
}
457
458
public Hashtable<String, Artifact> getAllArtifactsInThisBundleInHashtable() throws UMAException {
459
Hashtable<String, Artifact> table = new Hashtable<String, Artifact>();
460
for ( Artifact artifact : getAllArtifactsInThisBundle() ) {
461
table.put(artifact.getArtifactKey(), artifact);
462
}
463
return table;
464
}
465
466
public Vector<Artifact> getAllArtifactsInThisBundle() throws UMAException {
467
Vector<Artifact> artifactsInThisBundle = new Vector<Artifact>();
468
for ( Module module : UMA.getUma().getModules() ) {
469
if (!module.evaluate()) continue;
470
for ( Artifact artifact : module.getArtifacts() ) {
471
if (!artifact.evaluate()) continue;
472
String bundle = artifact.getBundle();
473
if (bundle != null && bundle.equalsIgnoreCase(getTargetName())) {
474
artifactsInThisBundle.add(artifact);
475
}
476
}
477
}
478
return artifactsInThisBundle;
479
}
480
481
public Boolean isInBundle() throws UMAException {
482
if ( getBundle() != null ) {
483
Artifact bundleArtifact = UMA.getUma().getBundleArtifact(getBundle());
484
if ( bundleArtifact != null && bundleArtifact.evaluate() ) {
485
return true;
486
}
487
}
488
return false;
489
}
490
491
public boolean isBundle() {
492
return type == TYPE_BUNDLE;
493
}
494
495
public Vector<Library> getLibraries() throws UMAException {
496
if ( type == TYPE_BUNDLE ) {
497
//TODO cache this result instead calculating it everytime
498
Vector<Library> bundleLibraries = new Vector<Library>(libraries);
499
Vector<Artifact> bundleArtifacts = getAllArtifactsInThisBundle();
500
for ( Artifact artifact : bundleArtifacts ) {
501
Library artifactLib = new Library(containingFile);
502
artifactLib.setName(artifact.getTargetName());
503
artifactLib.setType("build");
504
bundleLibraries.add(artifactLib);
505
bundleLibraries.addAll(artifact.getLibraries());
506
}
507
return bundleLibraries;
508
}
509
return libraries;
510
}
511
512
public String getLoadGroup() {
513
return loadgroup;
514
}
515
516
public String getMakefileName() {
517
return makefileName;
518
}
519
520
public String getMakefileFileName() throws UMAException {
521
if (module.requiresDispatchMakefile()) return getMakefileName() + ".mk";
522
return "makefile";
523
}
524
525
public Vector<MakefileStub> getMakefileStubs() {
526
return makefileStubs;
527
}
528
public Vector<Object> getObjects() {
529
return objects;
530
}
531
532
public Vector<VPath> getVPaths() {
533
return vpaths;
534
}
535
536
public Hashtable<String, Option> getOptions() {
537
return options;
538
}
539
540
public Vector<Library> getStaticLinkLibraries() throws UMAException {
541
Vector<Library> combinedStaticLibraries = new Vector<Library>(staticLinkLibraries);
542
for ( Library library : libraries ) {
543
if ( !library.evaluate() ) continue;
544
if ( library.getType() == Library.TYPE_BUILD ) {
545
Artifact libArtifact = UMA.getUma().getArtifact(library.getName());
546
if ( libArtifact == null || !libArtifact.evaluate() ) continue;
547
if ( libArtifact.isInBundle() ) {
548
// need to augment static libraries with libraries that make
549
// up this bundle
550
Library refLibrary = new Library("static-link-created");
551
refLibrary.setName(libArtifact.getTargetName());
552
combinedStaticLibraries.add(refLibrary);
553
}
554
}
555
556
}
557
return combinedStaticLibraries;
558
}
559
560
public String getTargetName() {
561
return name;
562
}
563
564
public String getTargetNameWithScope() {
565
if (scope == null ) return getTargetName();
566
return scope + "_" + name;
567
}
568
569
public String getTargetPath() {
570
if (buildLocal) {
571
return module.getFullName() + "/";
572
}
573
return null;
574
}
575
576
public boolean getBuildLocal() {
577
return buildLocal;
578
}
579
580
public String getTargetPath(IPlatform platform) throws UMAException {
581
if ( getTargetPath() != null ) return getTargetPath();
582
switch ( type ) {
583
case TYPE_EXECUTABLE:
584
return platform.getExecutablePath();
585
case TYPE_BUNDLE: // fall-thru
586
case TYPE_SHARED:
587
return platform.getSharedLibPath();
588
case TYPE_STATIC:
589
return platform.getStaticLibPath();
590
}
591
return "";
592
}
593
594
public String getTargetPathAsStatic(IPlatform platform) throws UMAException {
595
if ( getTargetPath() != null ) return getTargetPath();
596
return platform.getStaticLibPath();
597
}
598
599
public int getType() throws UMAException {
600
if ( type == TYPE_SHARED && isInBundle() ) {
601
type = TYPE_STATIC;
602
}
603
return type;
604
}
605
606
public boolean isConsoleApplication() {
607
return console;
608
}
609
610
public boolean isInPhase(int phase) throws UMAException {
611
return phases[phase];
612
}
613
614
public boolean isLibDefinedInTree( String lib ) {
615
return lib.equals(name);
616
}
617
public boolean requires(Artifact oa) throws UMAException {
618
for ( Library library : libraries ) {
619
if (!library.evaluate()) continue;
620
if ( library.getName().equalsIgnoreCase(oa.getTargetName()) ) {
621
return true;
622
}
623
Artifact libArt = UMA.getUma().getArtifact(library.getName());
624
if ( libArt != null && libArt.evaluate() && libArt.requires(oa) ) {
625
return true;
626
}
627
}
628
return false;
629
}
630
public void setAppendRelease(boolean appendRelease) {
631
this.appendRelease = appendRelease;
632
}
633
public void setBundle(String bundle) {
634
this.bundle = bundle;
635
}
636
public void setConsoleApplication( boolean console ) {
637
this.console = console;
638
}
639
640
public void setDescription(String desc) {
641
description = desc;
642
}
643
644
public void setLoadgroup(String loadgroup) {
645
this.loadgroup = loadgroup;
646
if (loadgroup == null || loadgroup.equals("")) {
647
this.loadgroup = getTargetName();
648
}
649
}
650
651
public void setMakefileName(String nm) {
652
makefileName = nm;
653
if (scope != null && !makefileName.startsWith(scope+"_")) {
654
makefileName = scope + "_" + makefileName;
655
}
656
}
657
658
public void setName(String name) {
659
this.name = name;
660
// default is to set makefileName to name
661
makefileName = name;
662
if (scope != null && !makefileName.startsWith(scope+"_")) {
663
makefileName = scope + "_" + makefileName;
664
}
665
}
666
667
public void setPhase(int phase, boolean value) {
668
try {
669
phases[phase] = value;
670
} catch (ArrayIndexOutOfBoundsException e) {
671
// Bad phase passed in, ignore.
672
}
673
}
674
675
public void setBuildLocal(boolean buildLocal) {
676
this.buildLocal = buildLocal;
677
}
678
679
public void setType(String type) {
680
if ( type.equalsIgnoreCase("shared")) {
681
this.type = TYPE_SHARED;
682
} else if ( type.equalsIgnoreCase("static")) {
683
this.type = TYPE_STATIC;
684
} else if ( type.equalsIgnoreCase("executable")) {
685
this.type = TYPE_EXECUTABLE;
686
} else if ( type.equalsIgnoreCase("subdir") ) {
687
this.type = TYPE_SUBDIR;
688
} else if ( type.equalsIgnoreCase("bundle") ) {
689
this.type = TYPE_BUNDLE;
690
} else if ( type.equalsIgnoreCase("reference") ) {
691
this.type = TYPE_REFERENCE;
692
} else if ( type.equalsIgnoreCase("target") ) {
693
this.type = TYPE_TARGET;
694
}
695
}
696
697
private void setType(int type) {
698
this.type = type;
699
}
700
701
702
}
703
704