KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > Jikes


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.taskdefs;
19
20 import java.io.File JavaDoc;
21 import java.io.FileWriter JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24 import java.util.Random JavaDoc;
25
26 import org.apache.tools.ant.BuildException;
27 import org.apache.tools.ant.Project;
28 import org.apache.tools.ant.util.FileUtils;
29
30 /**
31  * Encapsulates a Jikes compiler, by directly executing an external
32  * process.
33  *
34  * <p><strong>As of Ant 1.2, this class is considered to be dead code
35  * by the Ant developers and is unmaintained. Don't use
36  * it.</strong></p>
37  *
38  * @deprecated since 1.2.
39  * Merged into the class Javac.
40  */

41 public class Jikes {
42
43     // CheckStyle:VisibilityModifier OFF - bc
44
protected JikesOutputParser jop;
45     protected String JavaDoc command;
46     protected Project project;
47     // CheckStyle:VisibilityModifier ON
48

49     /**
50      * Constructs a new Jikes object.
51      * @param jop Parser to send jike's output to
52      * @param command name of jikes executable
53      * @param project the current project
54      */

55     protected Jikes(JikesOutputParser jop, String JavaDoc command, Project project) {
56         super();
57
58         System.err.println("As of Ant 1.2 released in October 2000, "
59             + "the Jikes class");
60         System.err.println("is considered to be dead code by the Ant "
61             + "developers and is unmaintained.");
62         System.err.println("Don\'t use it!");
63
64         this.jop = jop;
65         this.command = command;
66         this.project = project;
67     }
68
69     /**
70      * Do the compile with the specified arguments.
71      * @param args - arguments to pass to process on command line
72      */

73     protected void compile(String JavaDoc[] args) {
74         String JavaDoc[] commandArray = null;
75         File JavaDoc tmpFile = null;
76
77         try {
78             String JavaDoc myos = System.getProperty("os.name");
79
80             // Windows has a 32k limit on total arg size, so
81
// create a temporary file to store all the arguments
82

83             // There have been reports that 300 files could be compiled
84
// so 250 is a conservative approach
85
if (myos.toLowerCase().indexOf("windows") >= 0
86                 && args.length > 250) {
87                 PrintWriter JavaDoc out = null;
88                 try {
89                     String JavaDoc tempFileName = "jikes"
90                         + (new Random JavaDoc(System.currentTimeMillis())).nextLong();
91                     tmpFile = new File JavaDoc(tempFileName);
92                     out = new PrintWriter JavaDoc(new FileWriter JavaDoc(tmpFile));
93                     for (int i = 0; i < args.length; i++) {
94                         out.println(args[i]);
95                     }
96                     out.flush();
97                     commandArray = new String JavaDoc[] {command,
98                                                "@" + tmpFile.getAbsolutePath()};
99                 } catch (IOException JavaDoc e) {
100                     throw new BuildException("Error creating temporary file",
101                                              e);
102                 } finally {
103                     FileUtils.close(out);
104                 }
105             } else {
106                 commandArray = new String JavaDoc[args.length + 1];
107                 commandArray[0] = command;
108                 System.arraycopy(args, 0, commandArray, 1, args.length);
109             }
110
111             // We assume, that everything jikes writes goes to
112
// standard output, not to standard error. The option
113
// -Xstdout that is given to Jikes in Javac.doJikesCompile()
114
// should guarantee this. At least I hope so. :)
115
try {
116                 Execute exe = new Execute(jop);
117                 exe.setAntRun(project);
118                 exe.setWorkingDirectory(project.getBaseDir());
119                 exe.setCommandline(commandArray);
120                 exe.execute();
121             } catch (IOException JavaDoc e) {
122                 throw new BuildException("Error running Jikes compiler", e);
123             }
124         } finally {
125             if (tmpFile != null) {
126                 tmpFile.delete();
127             }
128         }
129     }
130 }
131
Popular Tags