1 | /*
|
---|
2 | * Copyright 2000,2002-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.taskdefs;
|
---|
18 |
|
---|
19 | import java.io.File;
|
---|
20 | import java.io.FileWriter;
|
---|
21 | import java.io.IOException;
|
---|
22 | import java.io.PrintWriter;
|
---|
23 | import java.util.Random;
|
---|
24 | import org.apache.tools.ant.BuildException;
|
---|
25 | import org.apache.tools.ant.Project;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Encapsulates a Jikes compiler, by directly executing an external
|
---|
29 | * process.
|
---|
30 | *
|
---|
31 | * <p><strong>As of Ant 1.2, this class is considered to be dead code
|
---|
32 | * by the Ant developers and is unmaintained. Don't use
|
---|
33 | * it.</strong></p>
|
---|
34 | *
|
---|
35 | * @deprecated merged into the class Javac.
|
---|
36 | */
|
---|
37 | public class Jikes {
|
---|
38 |
|
---|
39 | protected JikesOutputParser jop;
|
---|
40 | protected String command;
|
---|
41 | protected Project project;
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Constructs a new Jikes object.
|
---|
45 | * @param jop - Parser to send jike's output to
|
---|
46 | * @param command - name of jikes executable
|
---|
47 | */
|
---|
48 | protected Jikes(JikesOutputParser jop, String command, Project project) {
|
---|
49 | super();
|
---|
50 |
|
---|
51 | System.err.println("As of Ant 1.2 released in October 2000, "
|
---|
52 | + "the Jikes class");
|
---|
53 | System.err.println("is considered to be dead code by the Ant "
|
---|
54 | + "developers and is unmaintained.");
|
---|
55 | System.err.println("Don\'t use it!");
|
---|
56 |
|
---|
57 | this.jop = jop;
|
---|
58 | this.command = command;
|
---|
59 | this.project = project;
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Do the compile with the specified arguments.
|
---|
64 | * @param args - arguments to pass to process on command line
|
---|
65 | */
|
---|
66 | protected void compile(String[] args) {
|
---|
67 | String[] commandArray = null;
|
---|
68 | File tmpFile = null;
|
---|
69 |
|
---|
70 | try {
|
---|
71 | String myos = System.getProperty("os.name");
|
---|
72 |
|
---|
73 | // Windows has a 32k limit on total arg size, so
|
---|
74 | // create a temporary file to store all the arguments
|
---|
75 |
|
---|
76 | // There have been reports that 300 files could be compiled
|
---|
77 | // so 250 is a conservative approach
|
---|
78 | if (myos.toLowerCase().indexOf("windows") >= 0
|
---|
79 | && args.length > 250) {
|
---|
80 | PrintWriter out = null;
|
---|
81 | try {
|
---|
82 | String tempFileName = "jikes"
|
---|
83 | + (new Random(System.currentTimeMillis())).nextLong();
|
---|
84 | tmpFile = new File(tempFileName);
|
---|
85 | out = new PrintWriter(new FileWriter(tmpFile));
|
---|
86 | for (int i = 0; i < args.length; i++) {
|
---|
87 | out.println(args[i]);
|
---|
88 | }
|
---|
89 | out.flush();
|
---|
90 | commandArray = new String[] {command,
|
---|
91 | "@" + tmpFile.getAbsolutePath()};
|
---|
92 | } catch (IOException e) {
|
---|
93 | throw new BuildException("Error creating temporary file",
|
---|
94 | e);
|
---|
95 | } finally {
|
---|
96 | if (out != null) {
|
---|
97 | try {
|
---|
98 | out.close();
|
---|
99 | } catch (Throwable t) {
|
---|
100 | // ignore
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|
104 | } else {
|
---|
105 | commandArray = new String[args.length + 1];
|
---|
106 | commandArray[0] = command;
|
---|
107 | System.arraycopy(args, 0, commandArray, 1, args.length);
|
---|
108 | }
|
---|
109 |
|
---|
110 | // We assume, that everything jikes writes goes to
|
---|
111 | // standard output, not to standard error. The option
|
---|
112 | // -Xstdout that is given to Jikes in Javac.doJikesCompile()
|
---|
113 | // should guarantee this. At least I hope so. :)
|
---|
114 | try {
|
---|
115 | Execute exe = new Execute(jop);
|
---|
116 | exe.setAntRun(project);
|
---|
117 | exe.setWorkingDirectory(project.getBaseDir());
|
---|
118 | exe.setCommandline(commandArray);
|
---|
119 | exe.execute();
|
---|
120 | } catch (IOException e) {
|
---|
121 | throw new BuildException("Error running Jikes compiler", e);
|
---|
122 | }
|
---|
123 | } finally {
|
---|
124 | if (tmpFile != null) {
|
---|
125 | tmpFile.delete();
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|
129 | }
|
---|