]>
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.compiler;\r | |
18 | \r | |
19 | import java.io.File;\r | |
20 | \r | |
21 | import net.sf.antcontrib.cpptasks.AslcompilerDef;\r | |
22 | import net.sf.antcontrib.cpptasks.CCTask;\r | |
23 | import net.sf.antcontrib.cpptasks.ProcessorDef;\r | |
24 | import net.sf.antcontrib.cpptasks.TargetDef;\r | |
25 | \r | |
26 | /**\r | |
27 | * An abstract asl compiler implementation.\r | |
28 | * \r | |
29 | */\r | |
30 | public abstract class AbstractAslcompiler extends AbstractProcessor\r | |
31 | implements Aslcompiler {\r | |
32 | private String outputSuffix;\r | |
33 | protected AbstractAslcompiler(String[] sourceExtensions,\r | |
34 | String[] headerExtensions, String outputSuffix) {\r | |
35 | super(sourceExtensions, headerExtensions);\r | |
36 | this.outputSuffix = outputSuffix;\r | |
37 | } \r | |
38 | abstract protected AslcompilerConfiguration createConfiguration(CCTask task,\r | |
39 | LinkType linkType, ProcessorDef[] baseConfigs,\r | |
40 | AslcompilerDef specificConfig, TargetDef targetPlatform);\r | |
41 | \r | |
42 | public ProcessorConfiguration createConfiguration(CCTask task,\r | |
43 | LinkType linkType, ProcessorDef[] baseConfigs,\r | |
44 | ProcessorDef specificConfig, TargetDef targetPlatform) {\r | |
45 | if (specificConfig == null) {\r | |
46 | throw new NullPointerException("specificConfig");\r | |
47 | }\r | |
48 | return createConfiguration(task, linkType, baseConfigs,\r | |
49 | (AslcompilerDef) specificConfig, targetPlatform);\r | |
50 | }\r | |
51 | \r | |
52 | public String getOutputFileName(String inputFile) {\r | |
53 | if (bid(inputFile) > 1) {\r | |
54 | String baseName = getBaseOutputName(inputFile);\r | |
55 | return baseName + outputSuffix;\r | |
56 | }\r | |
57 | return null;\r | |
58 | }\r | |
59 | protected String getBaseOutputName(String inputFile) {\r | |
60 | int lastSlash = inputFile.lastIndexOf('/');\r | |
61 | int lastReverse = inputFile.lastIndexOf('\\');\r | |
62 | int lastSep = inputFile.lastIndexOf(File.separatorChar);\r | |
63 | if (lastReverse > lastSlash) {\r | |
64 | lastSlash = lastReverse;\r | |
65 | }\r | |
66 | if (lastSep > lastSlash) {\r | |
67 | lastSlash = lastSep;\r | |
68 | }\r | |
69 | int lastPeriod = inputFile.lastIndexOf('.');\r | |
70 | if (lastPeriod < 0) {\r | |
71 | lastPeriod = inputFile.length();\r | |
72 | }\r | |
73 | return inputFile.substring(lastSlash + 1, lastPeriod);\r | |
74 | }\r | |
75 | } |