]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /*\r |
2 | * \r | |
3 | * Copyright 2002-2004 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 | import java.io.File;\r | |
19 | import java.util.Hashtable;\r | |
20 | import java.util.Vector;\r | |
21 | \r | |
22 | import net.sf.antcontrib.cpptasks.compiler.LinkerConfiguration;\r | |
23 | import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration;\r | |
24 | \r | |
25 | import org.apache.tools.ant.BuildException;\r | |
26 | /**\r | |
27 | * This class matches each visited file with an appropriate compiler\r | |
28 | * \r | |
29 | * @author Curt Arnold\r | |
30 | */\r | |
31 | public final class TargetMatcher implements FileVisitor {\r | |
32 | private LinkerConfiguration linker;\r | |
33 | private Vector objectFiles;\r | |
34 | private File outputDir;\r | |
35 | private ProcessorConfiguration[] processors;\r | |
36 | private final File sourceFiles[] = new File[1];\r | |
37 | private Hashtable targets;\r | |
38 | private CCTask task;\r | |
39 | public TargetMatcher(CCTask task, File outputDir,\r | |
40 | ProcessorConfiguration[] processors, LinkerConfiguration linker,\r | |
41 | Vector objectFiles, Hashtable targets) {\r | |
42 | this.task = task;\r | |
43 | this.outputDir = outputDir;\r | |
44 | this.processors = processors;\r | |
45 | this.targets = targets;\r | |
46 | this.linker = linker;\r | |
47 | this.objectFiles = objectFiles;\r | |
48 | }\r | |
49 | public void visit(File parentDir, String filename) throws BuildException {\r | |
50 | //\r | |
51 | // see if any processor wants to bid\r | |
52 | // on this one\r | |
53 | ProcessorConfiguration selectedCompiler = null;\r | |
54 | int bid = 0;\r | |
55 | if (processors != null) {\r | |
56 | for (int k = 0; k < processors.length; k++) {\r | |
57 | int newBid = processors[k].bid(filename);\r | |
58 | if (newBid > bid) {\r | |
59 | bid = newBid;\r | |
60 | selectedCompiler = processors[k];\r | |
61 | }\r | |
62 | }\r | |
63 | }\r | |
64 | //\r | |
65 | // no processor interested in file\r | |
66 | // log diagnostic message\r | |
67 | if (bid <= 0) {\r | |
68 | if (linker != null) {\r | |
69 | int linkerbid = linker.bid(filename);\r | |
70 | if (linkerbid > 0) {\r | |
71 | File objFile = new File(parentDir, filename);\r | |
72 | objectFiles.addElement(objFile);\r | |
73 | if (linkerbid == 1) {\r | |
74 | task.log("Unrecognized file type " + objFile.toString()\r | |
75 | + " will be passed to linker");\r | |
76 | }\r | |
77 | }\r | |
78 | }\r | |
79 | } else {\r | |
80 | //\r | |
81 | // get output file name\r | |
82 | //\r | |
83 | String outputFileName = selectedCompiler\r | |
84 | .getOutputFileName(filename);\r | |
85 | //\r | |
86 | // if there is some output for this task\r | |
87 | // (that is a source file and not an header file)\r | |
88 | //\r | |
89 | if (outputFileName != null) {\r | |
90 | sourceFiles[0] = new File(parentDir, filename);\r | |
91 | //\r | |
92 | // see if the same output file has already been registered\r | |
93 | //\r | |
94 | TargetInfo previousTarget = (TargetInfo) targets\r | |
95 | .get(outputFileName);\r | |
96 | if (previousTarget == null) {\r | |
97 | targets.put(outputFileName, new TargetInfo(\r | |
98 | selectedCompiler, sourceFiles, null, new File(\r | |
99 | outputDir, outputFileName),\r | |
100 | selectedCompiler.getRebuild()));\r | |
101 | } else {\r | |
102 | if (!previousTarget.getSources()[0].equals(sourceFiles[0])) {\r | |
103 | StringBuffer builder = new StringBuffer(\r | |
104 | "Output filename conflict: ");\r | |
105 | builder.append(outputFileName);\r | |
106 | builder.append(" would be produced from ");\r | |
107 | builder.append(previousTarget.getSources()[0]\r | |
108 | .toString());\r | |
109 | builder.append(" and ");\r | |
110 | builder.append(filename);\r | |
111 | throw new BuildException(builder.toString());\r | |
112 | }\r | |
113 | }\r | |
114 | }\r | |
115 | }\r | |
116 | }\r | |
117 | }\r |