KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > rmic > ForkingSunRmic


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
19
20 package org.apache.tools.ant.taskdefs.rmic;
21
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.Project;
24 import org.apache.tools.ant.util.JavaEnvUtils;
25 import org.apache.tools.ant.taskdefs.Rmic;
26 import org.apache.tools.ant.taskdefs.Execute;
27 import org.apache.tools.ant.taskdefs.LogStreamHandler;
28 import org.apache.tools.ant.types.Commandline;
29
30 import java.io.IOException JavaDoc;
31
32 /**
33  * This is an extension of the sun rmic compiler, which forks rather than
34  * executes it inline. Why so? Because rmic is dog slow, but if you fork the
35  * compiler you can have multiple copies compiling different bits of your project
36  * at the same time. Which, on a multi-cpu system results in significant speedups.
37  *
38  * Also, Java1.6 behaves oddly with -XNew, so we switch it on here if needed.
39  * @since ant1.7
40  */

41 public class ForkingSunRmic extends DefaultRmicAdapter {
42
43     /**
44      * the name of this adapter for users to select
45      */

46     public static final String JavaDoc COMPILER_NAME = "forking";
47
48     /**
49      * exec by creating a new command
50      * @return true if the command ran successfully
51      * @throws BuildException on error
52      */

53     public boolean execute() throws BuildException {
54         Rmic owner = getRmic();
55         Commandline cmd = setupRmicCommand();
56         Project project = owner.getProject();
57         //rely on RMIC being on the path
58
cmd.setExecutable(JavaEnvUtils.getJdkExecutable(getExecutableName()));
59
60         //set up the args
61
String JavaDoc[] args = cmd.getCommandline();
62
63         try {
64             Execute exe = new Execute(new LogStreamHandler(owner,
65                     Project.MSG_INFO,
66                     Project.MSG_WARN));
67             exe.setAntRun(project);
68             exe.setWorkingDirectory(project.getBaseDir());
69             exe.setCommandline(args);
70             exe.execute();
71             return !exe.isFailure();
72         } catch (IOException JavaDoc exception) {
73             throw new BuildException("Error running " + getExecutableName()
74                     + " -maybe it is not on the path", exception);
75         }
76     }
77
78     /**
79      * Override point.
80      * @return the executable name.
81      */

82     protected String JavaDoc getExecutableName() {
83         return SunRmic.RMIC_EXECUTABLE;
84     }
85 }
86
Popular Tags