]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /*\r |
2 | * \r | |
3 | * Copyright 2001-2005 The Ant-Contrib project\r | |
4 | *\r | |
5 | * Licensed under the Apache License, Version 2.0 (the "License");\r | |
6 | * you may not use this file except in compliance with the License.\r | |
7 | * You may obtain a copy of the License at\r | |
8 | *\r | |
9 | * http://www.apache.org/licenses/LICENSE-2.0\r | |
10 | *\r | |
11 | * Unless required by applicable law or agreed to in writing, software\r | |
12 | * distributed under the License is distributed on an "AS IS" BASIS,\r | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r | |
14 | * See the License for the specific language governing permissions and\r | |
15 | * limitations under the License.\r | |
16 | */\r | |
17 | package net.sf.antcontrib.cpptasks;\r | |
18 | \r | |
19 | import java.io.BufferedReader;\r | |
20 | import java.io.File;\r | |
21 | import java.io.FileReader;\r | |
22 | import java.util.Vector;\r | |
23 | \r | |
24 | import net.sf.antcontrib.cpptasks.compiler.Assembler;\r | |
25 | import net.sf.antcontrib.cpptasks.compiler.Processor;\r | |
26 | import net.sf.antcontrib.cpptasks.gcc.GccAssembler;\r | |
27 | import net.sf.antcontrib.cpptasks.types.AssemblerArgument;\r | |
28 | import net.sf.antcontrib.cpptasks.types.ConditionalPath;\r | |
29 | import net.sf.antcontrib.cpptasks.types.IncludePath;\r | |
30 | import net.sf.antcontrib.cpptasks.types.SystemIncludePath;\r | |
31 | \r | |
32 | import org.apache.tools.ant.BuildException;\r | |
33 | import org.apache.tools.ant.Project;\r | |
34 | \r | |
35 | /**\r | |
36 | * A assembler definition. Assembler elements may be placed either as children\r | |
37 | * of a cc element or the project element. A assembler element with an id\r | |
38 | * attribute may be referenced from assembler elements with refid or extends\r | |
39 | * attributes.\r | |
40 | * \r | |
41 | */\r | |
42 | public final class AssemblerDef extends ProcessorDef {\r | |
43 | \r | |
44 | private final Vector includePaths = new Vector();\r | |
45 | \r | |
46 | private final Vector sysIncludePaths = new Vector();\r | |
47 | \r | |
48 | private Boolean defaultflag = new Boolean(true);\r | |
49 | \r | |
50 | public AssemblerDef () {\r | |
51 | }\r | |
52 | \r | |
53 | /**\r | |
54 | * Adds a assembler command-line arg.\r | |
55 | */\r | |
56 | public void addConfiguredAssemblerArg(AssemblerArgument arg) {\r | |
57 | if (isReference()) {\r | |
58 | throw noChildrenAllowed();\r | |
59 | }\r | |
60 | addConfiguredProcessorArg(arg);\r | |
61 | }\r | |
62 | \r | |
63 | /**\r | |
64 | * Creates an include path.\r | |
65 | */\r | |
66 | public IncludePath createIncludePath() {\r | |
67 | Project p = getProject();\r | |
68 | if (p == null) {\r | |
69 | throw new java.lang.IllegalStateException("project must be set");\r | |
70 | }\r | |
71 | if (isReference()) {\r | |
72 | throw noChildrenAllowed();\r | |
73 | }\r | |
74 | IncludePath path = new IncludePath(p);\r | |
75 | includePaths.addElement(path);\r | |
76 | return path;\r | |
77 | }\r | |
78 | \r | |
79 | /**\r | |
80 | * Creates an include path.\r | |
81 | */\r | |
82 | public SystemIncludePath createSysIncludePath() {\r | |
83 | Project p = getProject();\r | |
84 | if (p == null) {\r | |
85 | throw new java.lang.IllegalStateException("project must be set");\r | |
86 | }\r | |
87 | if (isReference()) {\r | |
88 | throw noChildrenAllowed();\r | |
89 | }\r | |
90 | SystemIncludePath path = new SystemIncludePath(p);\r | |
91 | sysIncludePaths.addElement(path);\r | |
92 | return path;\r | |
93 | }\r | |
94 | \r | |
95 | /**\r | |
96 | * Add a <includepath>or <sysincludepath> if specify the file attribute\r | |
97 | * \r | |
98 | * @throws BuildException\r | |
99 | * if the specify file not exist\r | |
100 | */\r | |
101 | protected void loadFile(Vector activePath, File file) throws BuildException {\r | |
102 | FileReader fileReader;\r | |
103 | BufferedReader in;\r | |
104 | String str;\r | |
105 | if (!file.exists()) {\r | |
106 | throw new BuildException("The file " + file + " is not existed");\r | |
107 | }\r | |
108 | try {\r | |
109 | fileReader = new FileReader(file);\r | |
110 | in = new BufferedReader(fileReader);\r | |
111 | while ((str = in.readLine()) != null) {\r | |
112 | if (str.trim() == "") {\r | |
113 | continue;\r | |
114 | }\r | |
115 | str = getProject().replaceProperties(str);\r | |
116 | activePath.addElement(str.trim());\r | |
117 | }\r | |
118 | } catch (Exception e) {\r | |
119 | throw new BuildException(e.getMessage());\r | |
120 | }\r | |
121 | }\r | |
122 | \r | |
123 | public void execute() throws org.apache.tools.ant.BuildException {\r | |
124 | throw new org.apache.tools.ant.BuildException(\r | |
125 | "Not an actual task, but looks like one for documentation purposes");\r | |
126 | }\r | |
127 | \r | |
128 | /**\r | |
129 | * Returns the assembler-specific include path.\r | |
130 | */\r | |
131 | public String[] getActiveIncludePaths() {\r | |
132 | if (isReference()) {\r | |
133 | return ((AssemblerDef) getCheckedRef(AssemblerDef.class,\r | |
134 | "AssemblerDef")).getActiveIncludePaths();\r | |
135 | }\r | |
136 | return getActivePaths(includePaths);\r | |
137 | }\r | |
138 | \r | |
139 | /**\r | |
140 | * Returns the assembler-specific sysinclude path.\r | |
141 | */\r | |
142 | public String[] getActiveSysIncludePaths() {\r | |
143 | if (isReference()) {\r | |
144 | return ((AssemblerDef) getCheckedRef(AssemblerDef.class,\r | |
145 | "AssemblerDef")).getActiveSysIncludePaths();\r | |
146 | }\r | |
147 | return getActivePaths(sysIncludePaths);\r | |
148 | }\r | |
149 | \r | |
150 | private String[] getActivePaths(Vector paths) {\r | |
151 | Project p = getProject();\r | |
152 | if (p == null) {\r | |
153 | throw new java.lang.IllegalStateException("project not set");\r | |
154 | }\r | |
155 | Vector activePaths = new Vector(paths.size());\r | |
156 | for (int i = 0; i < paths.size(); i++) {\r | |
157 | ConditionalPath path = (ConditionalPath) paths.elementAt(i);\r | |
158 | if (path.isActive(p)) {\r | |
159 | if (path.getFile() == null) {\r | |
160 | String[] pathEntries = path.list();\r | |
161 | for (int j = 0; j < pathEntries.length; j++) {\r | |
162 | activePaths.addElement(pathEntries[j]);\r | |
163 | }\r | |
164 | } else {\r | |
165 | loadFile(activePaths, path.getFile());\r | |
166 | }\r | |
167 | }\r | |
168 | }\r | |
169 | String[] pathNames = new String[activePaths.size()];\r | |
170 | activePaths.copyInto(pathNames);\r | |
171 | return pathNames;\r | |
172 | }\r | |
173 | \r | |
174 | public final Boolean getDefaultflag(AssemblerDef[] defaultProviders,\r | |
175 | int index) {\r | |
176 | if (isReference()) {\r | |
177 | return ((AssemblerDef) getCheckedRef(AssemblerDef.class,\r | |
178 | "AssemblerDef")).getDefaultflag(defaultProviders,\r | |
179 | index);\r | |
180 | }\r | |
181 | return defaultflag;\r | |
182 | }\r | |
183 | \r | |
184 | public Processor getProcessor() {\r | |
185 | Processor processor = super.getProcessor();\r | |
186 | if (processor == null) {\r | |
187 | processor = GccAssembler.getInstance();\r | |
188 | }\r | |
189 | return processor;\r | |
190 | }\r | |
191 | \r | |
192 | /**\r | |
193 | * Sets r type.\r | |
194 | * \r | |
195 | * <table width="100%" border="1"> <thead>Supported assemblers</thead>\r | |
196 | * <tr>\r | |
197 | * <td>gcc (default)</td>\r | |
198 | * <td>GAS assembler</td>\r | |
199 | * </tr>\r | |
200 | * <tr>\r | |
201 | * <td>masm</td>\r | |
202 | * <td>MASM assembler</td>\r | |
203 | * </tr>\r | |
204 | * </table>\r | |
205 | * \r | |
206 | */\r | |
207 | public void setName(AssemblerEnum name) throws BuildException {\r | |
208 | if (isReference()) {\r | |
209 | throw tooManyAttributes();\r | |
210 | }\r | |
211 | Assembler assembler = name.getAssembler();\r | |
212 | setProcessor(assembler);\r | |
213 | }\r | |
214 | \r | |
215 | protected void setProcessor(Processor proc) throws BuildException {\r | |
216 | try {\r | |
217 | super.setProcessor((Assembler) proc);\r | |
218 | } catch (ClassCastException ex) {\r | |
219 | throw new BuildException(ex);\r | |
220 | }\r | |
221 | }\r | |
222 | \r | |
223 | /**\r | |
224 | * Enables or disables default flags.\r | |
225 | * \r | |
226 | * @param defaultflag\r | |
227 | * if true, default flags will add to command line.\r | |
228 | * \r | |
229 | */\r | |
230 | public void setDefaultflag(boolean defaultflag) {\r | |
231 | if (isReference()) {\r | |
232 | throw tooManyAttributes();\r | |
233 | }\r | |
234 | this.defaultflag = booleanValueOf(defaultflag);\r | |
235 | }\r | |
236 | \r | |
237 | }\r |