Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/sourcetools/com.ibm.jpp.preprocessor/com/ibm/jpp/om/JxeRulesExtension.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 1999, 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.jpp.om;
23
24
import java.io.File;
25
import java.io.FileOutputStream;
26
import java.io.IOException;
27
import java.io.PrintWriter;
28
import java.util.Properties;
29
import java.util.Set;
30
import java.util.TreeSet;
31
32
/**
33
* JXE Rules Extension
34
*/
35
public class JxeRulesExtension extends BuilderExtension {
36
37
/**
38
* The JXE rules found during the build.
39
*/
40
private final Set<String> jxeRules = new TreeSet<>();
41
42
/**
43
* Determines whether API classes should be preserved with jxe rules.
44
*/
45
private boolean jxePreserveApi = false;
46
47
/**
48
* The output path.
49
*/
50
private String jxeRulesPath = null;
51
52
/**
53
* The output filename.
54
*/
55
private static final String jxeRulesFilename = "jxeLink.rules";
56
57
/**
58
* Constructor for JxeRuleExtension.
59
*/
60
public JxeRulesExtension() {
61
super("jxerules");
62
}
63
64
/**
65
* @see com.ibm.jpp.om.BuilderExtension#notifyBuildEnd()
66
*/
67
@Override
68
public void notifyBuildEnd() {
69
if (jxeRules.size() > 0) {
70
if (this.jxeRulesPath != null) {
71
// add the generated jxerules to the file
72
File outputFile = getOutputRulesFile();
73
File parentDir = outputFile.getParentFile();
74
75
parentDir.mkdirs();
76
77
if (parentDir.exists()) {
78
try (FileOutputStream fout = new FileOutputStream(outputFile, true);
79
PrintWriter writer = new PrintWriter(fout)) {
80
for (String jxeRule : jxeRules) {
81
writer.println(jxeRule);
82
}
83
writer.flush();
84
builder.getLogger().log("Jxelink rules written to \"" + outputFile.getAbsolutePath() + "\"", Logger.SEVERITY_INFO);
85
} catch (IOException e) {
86
builder.getLogger().log("An exception occured while writing the jxelink rules", Logger.SEVERITY_ERROR, e);
87
}
88
}
89
} else {
90
builder.getLogger().log("No output path specified for jxe rules", Logger.SEVERITY_ERROR);
91
}
92
}
93
}
94
95
/**
96
* @see com.ibm.jpp.om.BuilderExtension#notifyConfigurePreprocessor(JavaPreprocessor)
97
*/
98
@Override
99
public void notifyConfigurePreprocessor(JavaPreprocessor preprocessor) {
100
preprocessor.setJxeRules(this.jxeRules);
101
preprocessor.setJxePreserveApi(this.jxePreserveApi);
102
}
103
104
/**
105
* Validates the JXE rule options
106
*
107
* @param options jxerules options
108
*
109
* @throws BuilderConfigurationException if the options are invalid
110
*
111
* @see com.ibm.jpp.om.BuilderExtension#validateOptions(Properties)
112
*/
113
@Override
114
public void validateOptions(Properties options) throws BuilderConfigurationException {
115
if (options.containsKey("jxerules:preserveapi")) {
116
this.jxePreserveApi = options.getProperty("jxerules:preserveapi").equalsIgnoreCase("true");
117
}
118
if (options.containsKey("jxerules:outputdir")) {
119
this.jxeRulesPath = options.getProperty("jxerules:outputdir");
120
}
121
}
122
123
private File getOutputRulesFile() {
124
return new File(new File(builder.getOutputDir(), jxeRulesPath), jxeRulesFilename);
125
}
126
127
}
128
129