Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/debugtools/DDR_Autoblob/src/com/ibm/j9ddr/autoblob/GenerateSpecSuperset.java
6007 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2014 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.j9ddr.autoblob;
23
24
import java.io.File;
25
import java.io.FileFilter;
26
import java.io.FileReader;
27
import java.io.FileWriter;
28
import java.util.HashMap;
29
30
/**
31
* Utility class to generate the Java code needed for DDR - this consists of 2 steps
32
*
33
* 1. Merge the component supersets into a single c-build superset
34
* 2. Generate a new c-build superset which is the combined superset for the last i-build and the current c-build
35
*
36
* @author adam
37
*
38
*/
39
public class GenerateSpecSuperset {
40
private static final HashMap<String, String> opts = new HashMap<String, String>();
41
private static final String OPT_SRCDIR = "-s"; //where to find the component supersets
42
private static final String OPT_OUTPUTDIR = "-d"; //where to generate the output
43
private static final String OPT_FILENAME = "-f"; //superset file name
44
private static File outdir = null;
45
46
static {
47
opts.put(OPT_OUTPUTDIR, null);
48
opts.put(OPT_SRCDIR, null);
49
opts.put(OPT_FILENAME, "superset.spec.dat"); //default value
50
}
51
52
/**
53
* @param args
54
*/
55
public static void main(String[] args) throws Exception {
56
if(!parseArgs(args)) {
57
System.exit(1); //abort if invalid args are encountered
58
}
59
createOutputDir();
60
createSpecSuperset();
61
System.out.println("Finished");
62
}
63
64
private static void createSpecSuperset() throws Exception {
65
System.out.println("Creating superset");
66
String[] parts = opts.get(OPT_SRCDIR).split(",");
67
File out = new File(outdir, opts.get(OPT_FILENAME));
68
FileWriter writer = new FileWriter(out);
69
70
for(int i = 0; i < parts.length; i++) {
71
System.out.println("Scanning source directory for *.superset : " + parts[i]);
72
File srcdir = new File(parts[i]);
73
if(!srcdir.exists() || !srcdir.isDirectory()) {
74
System.err.println("Error : The specified source directory (" + srcdir.getAbsolutePath() + ") does not exist, or is not a directory.");
75
System.exit(1);
76
}
77
File[] files = srcdir.listFiles(new FileFilter() {
78
79
public boolean accept(File pathname) {
80
return pathname.getName().endsWith(".superset");
81
}
82
});
83
if(0 == files.length) {
84
System.err.println("Error : The source directory (" + srcdir.getAbsolutePath() + ") does not contain any superset files (*.superset).");
85
System.exit(1);
86
}
87
char[] buffer = new char[4096];
88
int charsread = 0;
89
for(File file : files) {
90
System.out.println(("Processing " + file.getName()));
91
FileReader reader = new FileReader(file);
92
while((charsread = reader.read(buffer)) != -1) {
93
writer.write(buffer, 0, charsread);
94
}
95
reader.close();
96
}
97
}
98
writer.close();
99
}
100
101
//creates the output directory for the superset and java code
102
private static void createOutputDir() {
103
outdir = new File(opts.get(OPT_OUTPUTDIR));
104
if(outdir.exists()) {
105
if(outdir.isDirectory()) {
106
System.out.println("Cleaning existing output directory " + outdir.getAbsolutePath());
107
//directory exists so clean it out
108
for(File file : outdir.listFiles()) {
109
file.delete();
110
}
111
} else {
112
//can't create as there is a conflict
113
System.err.println("Error : The specified output directory (" + outdir.getAbsolutePath() + ") already exists as a file.");
114
System.exit(1);
115
}
116
} else {
117
//dir does not exist so create it
118
System.out.println("Creating output directory " + outdir.getAbsolutePath());
119
if(!outdir.mkdirs()) {
120
System.err.println("Error : The could not create the output directory (" + outdir.getAbsolutePath() + ").");
121
System.exit(1);
122
}
123
}
124
}
125
126
private static boolean parseArgs(String[] args) {
127
boolean validargs = true;
128
//parse args
129
for(int i = 0; (i + 1) < args.length; i+=2) {
130
if(opts.containsKey(args[i])) {
131
opts.put(args[i], args[i+1]);
132
} else {
133
System.err.println("Option " + args[i] + " was not recognised");
134
}
135
}
136
//check none are missing
137
for(String key : opts.keySet()) {
138
if(null == opts.get(key)) {
139
validargs = false;
140
System.err.println("Required option " + key + " was not set on the command line");
141
}
142
}
143
return validargs;
144
}
145
146
}
147
148