1 | /*
|
---|
2 | * Copyright 2001-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 |
|
---|
18 | package org.apache.tools.ant.taskdefs.compilers;
|
---|
19 |
|
---|
20 | import java.lang.reflect.Method;
|
---|
21 | import org.apache.tools.ant.BuildException;
|
---|
22 | import org.apache.tools.ant.Project;
|
---|
23 | import org.apache.tools.ant.types.Commandline;
|
---|
24 |
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * The implementation of the javac compiler for JDK 1.3
|
---|
28 | * This is primarily a cut-and-paste from the original javac task before it
|
---|
29 | * was refactored.
|
---|
30 | *
|
---|
31 | * @since Ant 1.3
|
---|
32 | */
|
---|
33 | public class Javac13 extends DefaultCompilerAdapter {
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Integer returned by the "Modern" jdk1.3 compiler to indicate success.
|
---|
37 | */
|
---|
38 | private static final int MODERN_COMPILER_SUCCESS = 0;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Run the compilation.
|
---|
42 | *
|
---|
43 | * @exception BuildException if the compilation has problems.
|
---|
44 | */
|
---|
45 | public boolean execute() throws BuildException {
|
---|
46 | attributes.log("Using modern compiler", Project.MSG_VERBOSE);
|
---|
47 | Commandline cmd = setupModernJavacCommand();
|
---|
48 |
|
---|
49 | // Use reflection to be able to build on all JDKs >= 1.1:
|
---|
50 | try {
|
---|
51 | Class c = Class.forName ("com.sun.tools.javac.Main");
|
---|
52 | Object compiler = c.newInstance ();
|
---|
53 | Method compile = c.getMethod ("compile",
|
---|
54 | new Class [] {(new String [] {}).getClass ()});
|
---|
55 | int result = ((Integer) compile.invoke
|
---|
56 | (compiler, new Object[] {cmd.getArguments()}))
|
---|
57 | .intValue ();
|
---|
58 | return (result == MODERN_COMPILER_SUCCESS);
|
---|
59 | } catch (Exception ex) {
|
---|
60 | if (ex instanceof BuildException) {
|
---|
61 | throw (BuildException) ex;
|
---|
62 | } else {
|
---|
63 | throw new BuildException("Error starting modern compiler",
|
---|
64 | ex, location);
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|