raster@16367
|
1 |
/*
|
raster@16367
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
raster@16367
|
3 |
*
|
raster@16367
|
4 |
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
|
raster@16367
|
5 |
*
|
raster@16367
|
6 |
* The contents of this file are subject to the terms of either the GNU
|
raster@16367
|
7 |
* General Public License Version 2 only ("GPL") or the Common
|
raster@16367
|
8 |
* Development and Distribution License("CDDL") (collectively, the
|
raster@16367
|
9 |
* "License"). You may not use this file except in compliance with the
|
raster@16367
|
10 |
* License. You can obtain a copy of the License at
|
raster@16367
|
11 |
* http://www.netbeans.org/cddl-gplv2.html
|
raster@16367
|
12 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
raster@16367
|
13 |
* specific language governing permissions and limitations under the
|
raster@16367
|
14 |
* License. When distributing the software, include this License Header
|
raster@16367
|
15 |
* Notice in each file and include the License file at
|
raster@16367
|
16 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
|
raster@16367
|
17 |
* particular file as subject to the "Classpath" exception as provided
|
raster@16367
|
18 |
* by Sun in the GPL Version 2 section of the License file that
|
raster@16367
|
19 |
* accompanied this code. If applicable, add the following below the
|
raster@16367
|
20 |
* License Header, with the fields enclosed by brackets [] replaced by
|
raster@16367
|
21 |
* your own identifying information:
|
raster@16367
|
22 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
raster@16367
|
23 |
*
|
raster@16367
|
24 |
* If you wish your version of this file to be governed by only the CDDL
|
raster@16367
|
25 |
* or only the GPL Version 2, indicate your decision by adding
|
raster@16367
|
26 |
* "[Contributor] elects to include this software in this distribution
|
raster@16367
|
27 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a
|
raster@16367
|
28 |
* single choice of license, a recipient has the option to distribute
|
raster@16367
|
29 |
* your version of this file under either the CDDL, the GPL Version 2 or
|
raster@16367
|
30 |
* to extend the choice of license to its licensees as provided above.
|
raster@16367
|
31 |
* However, if you add GPL Version 2 code and therefore, elected the GPL
|
raster@16367
|
32 |
* Version 2 license, then the option applies only if the new code is
|
raster@16367
|
33 |
* made subject to such option by the copyright holder.
|
raster@16367
|
34 |
*
|
raster@16367
|
35 |
* Contributor(s):
|
raster@16367
|
36 |
*
|
raster@16367
|
37 |
* Portions Copyrighted 2008 Sun Microsystems, Inc.
|
raster@16367
|
38 |
*/
|
raster@16367
|
39 |
package org.netbeans.modules.ada.platform.compiler.jgnat;
|
raster@16367
|
40 |
|
raster@16367
|
41 |
import java.util.ArrayList;
|
raster@16367
|
42 |
import java.util.LinkedHashMap;
|
raster@16367
|
43 |
import java.util.Map;
|
raster@16367
|
44 |
import org.netbeans.api.ada.platform.AdaException;
|
raster@16367
|
45 |
import org.netbeans.api.ada.platform.AdaPlatform;
|
raster@16367
|
46 |
import org.netbeans.spi.ada.platform.Compiler;
|
raster@16367
|
47 |
import org.netbeans.modules.ada.platform.compiler.jgnat.commands.JGnatCommand;
|
raster@16367
|
48 |
import org.netbeans.modules.ada.platform.compiler.jgnat.commands.JGnatClean;
|
raster@16367
|
49 |
import org.netbeans.modules.ada.platform.compiler.jgnat.commands.JGnatMake;
|
raster@16367
|
50 |
import org.netbeans.modules.ada.platform.compiler.jgnat.commands.JRun;
|
raster@16367
|
51 |
import org.openide.util.Exceptions;
|
raster@16367
|
52 |
|
raster@16367
|
53 |
/**
|
raster@16367
|
54 |
*
|
raster@16367
|
55 |
* @author Andrea Lucarelli
|
raster@16367
|
56 |
*/
|
raster@16367
|
57 |
public class JGnatCompiler implements Compiler {
|
raster@16367
|
58 |
|
raster@16367
|
59 |
private final Map<String, JGnatCommand> jgnatCommands;
|
raster@16367
|
60 |
private final AdaPlatform platform;
|
raster@16367
|
61 |
private final String projectName;
|
raster@16367
|
62 |
private final String projectPath;
|
raster@16367
|
63 |
private final ArrayList<String> sourceFolders;
|
raster@16367
|
64 |
private final String mainFile;
|
raster@16367
|
65 |
private final String outputFile;
|
raster@16367
|
66 |
private final String commandName;
|
raster@16367
|
67 |
private final String spcPostfix;
|
raster@16367
|
68 |
private final String bdyPostfix;
|
raster@16367
|
69 |
private final String sepPostfix;
|
raster@16367
|
70 |
private final String spcExt;
|
raster@16367
|
71 |
private final String bdyExt;
|
raster@16367
|
72 |
private final String sepExt;
|
raster@16367
|
73 |
|
raster@16367
|
74 |
/**
|
raster@16367
|
75 |
*
|
raster@16367
|
76 |
* @param project
|
raster@16367
|
77 |
*/
|
raster@16367
|
78 |
public JGnatCompiler(AdaPlatform platform, String projectName, String projectPath, ArrayList<String> sourceFolders, String mainFile, String outputFile, String commandName,
|
raster@16367
|
79 |
String spcPostfix, String bdyPostfix, String sepPostfix, String spcExt, String bdyExt, String sepExt) {
|
raster@16367
|
80 |
|
raster@16367
|
81 |
assert platform != null;
|
raster@16367
|
82 |
|
raster@16367
|
83 |
this.platform = platform;
|
raster@16367
|
84 |
this.projectName = projectName;
|
raster@16367
|
85 |
this.projectPath = projectPath;
|
raster@16367
|
86 |
this.sourceFolders = sourceFolders;
|
raster@16367
|
87 |
this.mainFile = mainFile;
|
raster@16367
|
88 |
this.outputFile = outputFile;
|
raster@16367
|
89 |
this.commandName = commandName;
|
raster@16367
|
90 |
|
raster@16367
|
91 |
jgnatCommands = new LinkedHashMap<String, JGnatCommand>();
|
raster@16367
|
92 |
JGnatCommand[] gnatCommandArray = new JGnatCommand[]{
|
raster@16367
|
93 |
new JGnatMake(this),
|
raster@16367
|
94 |
new JGnatClean(this),
|
raster@16367
|
95 |
new JRun(this)
|
raster@16367
|
96 |
};
|
raster@16367
|
97 |
for (JGnatCommand gnatCommand : gnatCommandArray) {
|
raster@16367
|
98 |
jgnatCommands.put(gnatCommand.getCommandId(), gnatCommand);
|
raster@16367
|
99 |
}
|
raster@16367
|
100 |
this.spcExt = spcExt;
|
raster@16367
|
101 |
this.bdyExt = bdyExt;
|
raster@16367
|
102 |
this.sepExt = sepExt;
|
raster@16367
|
103 |
this.spcPostfix = spcPostfix;
|
raster@16367
|
104 |
this.bdyPostfix = bdyPostfix;
|
raster@16367
|
105 |
this.sepPostfix = sepPostfix;
|
raster@16367
|
106 |
}
|
raster@16367
|
107 |
|
raster@16367
|
108 |
/**
|
raster@16367
|
109 |
*
|
raster@16367
|
110 |
* @param commandName
|
raster@16367
|
111 |
* @throws IllegalArgumentException
|
raster@16367
|
112 |
*/
|
raster@16367
|
113 |
private void invokeCommand(final String commandName, final String displayTitle, final String args) throws IllegalArgumentException, AdaException {
|
raster@16367
|
114 |
final JGnatCommand jgnatCommand = findCommand(commandName);
|
raster@16367
|
115 |
assert jgnatCommand != null;
|
raster@16367
|
116 |
jgnatCommand.invokeCommand(displayTitle, args);
|
raster@16367
|
117 |
}
|
raster@16367
|
118 |
|
raster@16367
|
119 |
/**
|
raster@16367
|
120 |
*
|
raster@16367
|
121 |
* @param commandName
|
raster@16367
|
122 |
* @return
|
raster@16367
|
123 |
*/
|
raster@16367
|
124 |
private JGnatCommand findCommand(final String commandName) {
|
raster@16367
|
125 |
assert commandName != null;
|
raster@16367
|
126 |
return jgnatCommands.get(commandName);
|
raster@16367
|
127 |
}
|
raster@16367
|
128 |
|
raster@16367
|
129 |
public void Build() {
|
raster@16367
|
130 |
try {
|
raster@16367
|
131 |
invokeCommand(JGnatCommand.JVM_GNAT_MAKE, this.getProjectName() + "(" + this.getCommandName() + ")", null);
|
raster@16367
|
132 |
} catch (IllegalArgumentException ex) {
|
raster@16367
|
133 |
Exceptions.printStackTrace(ex);
|
raster@16367
|
134 |
} catch (AdaException ex) {
|
raster@16367
|
135 |
Exceptions.printStackTrace(ex);
|
raster@16367
|
136 |
}
|
raster@16367
|
137 |
}
|
raster@16367
|
138 |
|
raster@16367
|
139 |
public void Run(String args) {
|
raster@16367
|
140 |
try {
|
raster@16367
|
141 |
invokeCommand(JGnatCommand.RUN, this.getProjectName() + "(" + this.getCommandName() + ")", args);
|
raster@16367
|
142 |
} catch (IllegalArgumentException ex) {
|
raster@16367
|
143 |
Exceptions.printStackTrace(ex);
|
raster@16367
|
144 |
} catch (AdaException ex) {
|
raster@16367
|
145 |
Exceptions.printStackTrace(ex);
|
raster@16367
|
146 |
}
|
raster@16367
|
147 |
}
|
raster@16367
|
148 |
|
raster@16367
|
149 |
public void Compile() {
|
raster@16367
|
150 |
try {
|
raster@16367
|
151 |
invokeCommand(JGnatCommand.JVM_GNAT_COMPILE, this.getProjectName() + "(" + this.getCommandName() + ")", null);
|
raster@16367
|
152 |
} catch (IllegalArgumentException ex) {
|
raster@16367
|
153 |
Exceptions.printStackTrace(ex);
|
raster@16367
|
154 |
} catch (AdaException ex) {
|
raster@16367
|
155 |
Exceptions.printStackTrace(ex);
|
raster@16367
|
156 |
}
|
raster@16367
|
157 |
}
|
raster@16367
|
158 |
|
raster@16367
|
159 |
public void Clean() {
|
raster@16367
|
160 |
try {
|
raster@16367
|
161 |
invokeCommand(JGnatCommand.JVM_GNAT_CLEAN, this.getProjectName() + "(" + this.getCommandName() + ")", null);
|
raster@16367
|
162 |
} catch (IllegalArgumentException ex) {
|
raster@16367
|
163 |
Exceptions.printStackTrace(ex);
|
raster@16367
|
164 |
} catch (AdaException ex) {
|
raster@16367
|
165 |
Exceptions.printStackTrace(ex);
|
raster@16367
|
166 |
}
|
raster@16367
|
167 |
}
|
raster@16367
|
168 |
|
raster@16367
|
169 |
public AdaPlatform getPlatform() {
|
raster@16367
|
170 |
return platform;
|
raster@16367
|
171 |
}
|
raster@16367
|
172 |
|
raster@16367
|
173 |
public String getExecutableFile() {
|
raster@16367
|
174 |
return outputFile;
|
raster@16367
|
175 |
}
|
raster@16367
|
176 |
|
raster@16367
|
177 |
public String getCommandName() {
|
raster@16367
|
178 |
return commandName;
|
raster@16367
|
179 |
}
|
raster@16367
|
180 |
|
raster@16367
|
181 |
public String getMainFile() {
|
raster@16367
|
182 |
return mainFile;
|
raster@16367
|
183 |
}
|
raster@16367
|
184 |
|
raster@16367
|
185 |
public String getProjectPath() {
|
raster@16367
|
186 |
return projectPath;
|
raster@16367
|
187 |
}
|
raster@16367
|
188 |
|
raster@16367
|
189 |
public String getProjectName() {
|
raster@16367
|
190 |
return projectName;
|
raster@16367
|
191 |
}
|
raster@16367
|
192 |
|
raster@16367
|
193 |
public ArrayList<String> getSourceFolders() {
|
raster@16367
|
194 |
return sourceFolders;
|
raster@16367
|
195 |
}
|
raster@16367
|
196 |
|
raster@16367
|
197 |
public String getBdyExt() {
|
raster@16367
|
198 |
return bdyExt;
|
raster@16367
|
199 |
}
|
raster@16367
|
200 |
|
raster@16367
|
201 |
public String getSepExt() {
|
raster@16367
|
202 |
return sepExt;
|
raster@16367
|
203 |
}
|
raster@16367
|
204 |
|
raster@16367
|
205 |
public String getSpcExt() {
|
raster@16367
|
206 |
return spcExt;
|
raster@16367
|
207 |
}
|
raster@16367
|
208 |
|
raster@16367
|
209 |
public String getBdyPostfix() {
|
raster@16367
|
210 |
return bdyPostfix;
|
raster@16367
|
211 |
}
|
raster@16367
|
212 |
|
raster@16367
|
213 |
public String getSepPostfix() {
|
raster@16367
|
214 |
return sepPostfix;
|
raster@16367
|
215 |
}
|
raster@16367
|
216 |
|
raster@16367
|
217 |
public String getSpcPostfix() {
|
raster@16367
|
218 |
return spcPostfix;
|
raster@16367
|
219 |
}
|
raster@16367
|
220 |
}
|