Use the javax.tools API in axis-rt-jws.
diff --git a/axis-rt-jws/pom.xml b/axis-rt-jws/pom.xml
index fb885b1..1a8c266 100644
--- a/axis-rt-jws/pom.xml
+++ b/axis-rt-jws/pom.xml
@@ -34,6 +34,10 @@
<url>${baseSiteUrl}/jws</url>
</site>
</distributionManagement>
+ <properties>
+ <!-- We use the javax.tools API which was introduced in Java 6. -->
+ <javaVersion>1.6</javaVersion>
+ </properties>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
diff --git a/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/AbstractCompiler.java b/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/AbstractCompiler.java
deleted file mode 100644
index e159619..0000000
--- a/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/AbstractCompiler.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Copyright 2001-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.axis.components.compiler;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * This class implements the functionality common to all Java compilers.
- * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
- * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @since 2.0
- */
-public abstract class AbstractCompiler implements Compiler {
-
- /**
- * The source program filenames
- */
- protected ArrayList fileList = new ArrayList();
-
- /**
- * The name of the directory containing the source program file
- */
- protected String srcDir;
-
- /**
- * The name of the directory to contain the resulting object program file
- */
- protected String destDir;
-
- /**
- * The classpath to be used for compilation
- */
- protected String classpath;
-
- /**
- * The encoding of the source program or <code>null</code> to use the
- * platform's default encoding
- */
- protected String encoding = null;
-
- /**
- * The input stream to output compilation errors
- */
- protected InputStream errors;
-
- /**
- * Add the name of the file containing the source program to the file list
- *
- * @param file The name of the file containing the source program
- */
- public void addFile(String file) {
- this.fileList.add(file);
- }
-
- /**
- * Set the name of the directory containing the source program file
- *
- * @param srcDir The name of the directory containing the source program file
- */
- public void setSource(String srcDir) {
- this.srcDir = srcDir;
- }
-
- /**
- * Set the name of the directory to contain the resulting object program file
- *
- * @param destDir The name of the directory to contain the resulting object
- * program file
- */
- public void setDestination(String destDir) {
- this.destDir = destDir;
- }
-
- /**
- * Set the classpath to be used for this compilation
- *
- * @param classpath The classpath to be used for this compilation
- */
- public void setClasspath(String classpath) {
- this.classpath = classpath;
- }
-
- /**
- * Set the encoding of the input source file or <code>null</code> to use the
- * platform's default encoding
- *
- * @param encoding The encoding of the input source file or <code>null</code>
- * to use the platform's default encoding
- */
- public void setEncoding(String encoding) {
- this.encoding = encoding;
- }
-
- /**
- * Return the list of errors generated by this compilation
- *
- * @return The list of errors generated by this compilation
- * @exception IOException If an error occurs during message collection
- */
- public List getErrors() throws IOException {
- return parseStream(new BufferedReader(new InputStreamReader(errors)));
- }
-
- /**
- * Parse the compiler error stream to produce a list of
- * <code>CompilerError</code>s
- *
- * @param errors The error stream
- * @return The list of compiler error messages
- * @exception IOException If an error occurs during message collection
- */
- protected abstract List parseStream(BufferedReader errors)
- throws IOException;
-
- /**
- * Fill the arguments taken by the Java compiler
- *
- * @param arguments The list of compilation arguments
- * @return The prepared list of compilation arguments
- */
- protected List fillArguments(List arguments) {
- // destination directory
- arguments.add("-d");
- arguments.add(destDir);
-
- // classpath
- arguments.add("-classpath");
- arguments.add(classpath);
-
- // sourcepath
- if(srcDir != null) {
- arguments.add("-sourcepath");
- arguments.add(srcDir);
- }
-
- // add optimization (for what is worth)
- arguments.add("-O");
-
- // add debug option
- arguments.add("-g");
-
- // add encoding if set
- if (encoding != null) {
- arguments.add("-encoding");
- arguments.add(encoding);
- }
-
- return arguments;
- }
-
- /**
- * Copy arguments to a string array
- *
- * @param arguments The compiler arguments
- * @return A string array containing compilation arguments
- */
- protected String[] toStringArray(List arguments) {
- int i;
- String[] args = new String[arguments.size() + fileList.size()];
-
- for (i = 0; i < arguments.size(); i++) {
- args[i] = (String) arguments.get(i);
- }
-
- for (int j=0; j < fileList.size(); i++,j++) {
- args[i] = (String)fileList.get(j);
- }
- return args;
- }
-}
diff --git a/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/Compiler.java b/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/Compiler.java
deleted file mode 100644
index 92f34f5..0000000
--- a/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/Compiler.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright 2001-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.axis.components.compiler;
-
-import java.io.IOException;
-import java.util.List;
-
-/**
- * This interface defines a compiler's functionality for all
- * (Java-based) compiled languages
- * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
- * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @since 2.0
- */
-public interface Compiler {
- /**
- * Set the name of the file containing the source program
- *
- * @param file The name of the file containing the source program
- */
- void addFile(String file);
-
- /**
- * Set the name of the directory containing the source program file
- *
- * @param srcDir The name of the directory containing the source program file
- */
- void setSource(String srcDir);
-
- /**
- * Set the name of the directory to contain the resulting object program file
- *
- * @param destDir The name of the directory to contain the resulting object
- * program file
- */
- void setDestination(String destDir);
-
- /**
- * Set the classpath to be used for this compilation
- *
- * @param classpath The classpath to be used for this compilation
- */
- void setClasspath(String classpath);
-
- /**
- * Set the encoding of the input source file or <code>null</code> to use the
- * platform's default encoding
- *
- * @param encoding The encoding of the input source file or <code>null</code>
- * to use the platform's default encoding
- */
- void setEncoding(String encoding);
-
- /**
- * Compile a source file yielding a loadable program file.
- *
- * @param filename The object program base file name
- * @param baseDirectory The directory containing the object program file
- * @param encoding The encoding expected in the source file or
- * <code>null</code> if it is the platform's default encoding
- * @exception LanguageException If an error occurs during compilation
- */
- boolean compile() throws IOException;
-
- /**
- * Return the list of errors generated by this compilation
- *
- * @return The list of errors generated by this compilation
- * @exception IOException If an error occurs during message collection
- */
- List getErrors() throws IOException;
-}
diff --git a/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/CompilerError.java b/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/CompilerError.java
deleted file mode 100644
index bb006fd..0000000
--- a/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/CompilerError.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Copyright 2001-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.axis.components.compiler;
-
-/**
- * This class encapsulates an error message produced by a programming language
- * processor (whether interpreted or compiled)
- * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
- * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @since 2.0
- */
-
-public class CompilerError {
- /**
- * Is this a severe error or a warning?
- */
- private boolean error;
- /**
- * The start line number of the offending program text
- */
- private int startline;
- /**
- * The start column number of the offending program text
- */
- private int startcolumn;
- /**
- * The end line number of the offending program text
- */
- private int endline;
- /**
- * The end column number of the offending program text
- */
- private int endcolumn;
- /**
- * The name of the file containing the offending program text
- */
- private String file;
- /**
- * The actual error text produced by the language processor
- */
- private String message;
-
- /**
- * The error message constructor.
- *
- * @param file The name of the file containing the offending program text
- * @param error The actual error text produced by the language processor
- * @param startline The start line number of the offending program text
- * @param startcolumn The start column number of the offending program text
- * @param endline The end line number of the offending program text
- * @param endcolumn The end column number of the offending program text
- * @param message The actual error text produced by the language processor
- */
- public CompilerError(
- String file,
- boolean error,
- int startline,
- int startcolumn,
- int endline,
- int endcolumn,
- String message
- )
- {
- this.file = file;
- this.error = error;
- this.startline = startline;
- this.startcolumn = startcolumn;
- this.endline = endline;
- this.endcolumn = endcolumn;
- this.message = message;
- }
-
- /**
- * The error message constructor.
- *
- * @param message The actual error text produced by the language processor
- */
- public CompilerError(String message) {
- this.message = message;
- }
-
- /**
- * Return the filename associated with this compiler error.
- *
- * @return The filename associated with this compiler error
- */
- public String getFile() {
- return file;
- }
-
- /**
- * Assert whether this is a severe error or a warning
- *
- * @return Whether the error is severe
- */
- public boolean isError() {
- return error;
- }
-
- /**
- * Return the starting line number of the program text originating this error
- *
- * @return The starting line number of the program text originating this error
- */
- public int getStartLine() {
- return startline;
- }
-
- /**
- * Return the starting column number of the program text originating this
- * error
- *
- * @return The starting column number of the program text originating this
- * error
- */
- public int getStartColumn() {
- return startcolumn;
- }
-
- /**
- * Return the ending line number of the program text originating this error
- *
- * @return The ending line number of the program text originating this error
- */
- public int getEndLine() {
- return endline;
- }
-
- /**
- * Return the ending column number of the program text originating this
- * error
- *
- * @return The ending column number of the program text originating this
- * error
- */
- public int getEndColumn() {
- return endcolumn;
- }
-
- /**
- * Return the message produced by the language processor
- *
- * @return The message produced by the language processor
- */
- public String getMessage() {
- return message;
- }
-}
diff --git a/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/CompilerFactory.java b/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/CompilerFactory.java
deleted file mode 100644
index e2db8d8..0000000
--- a/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/CompilerFactory.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2001-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.axis.components.compiler;
-
-import org.apache.axis.AxisProperties;
-import org.apache.axis.components.logger.LogFactory;
-import org.apache.axis.utils.Messages;
-import org.apache.commons.logging.Log;
-
-
-/**
- * This class implements a factory to instantiate a Compiler.
- * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
- * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @since 2.0
- */
-public class CompilerFactory {
- protected static Log log =
- LogFactory.getLog(CompilerFactory.class.getName());
-
- static {
- AxisProperties.setClassOverrideProperty(Compiler.class, "axis.Compiler");
-
- AxisProperties.setClassDefault(Compiler.class,
- "org.apache.axis.components.compiler.Javac");
- }
-
- public static Compiler getCompiler() {
- Compiler compiler = (Compiler)AxisProperties.newInstance(Compiler.class);
-
- /**
- * This shouldn't be needed, but seems to be a common feel-good:
- */
- if (compiler == null) {
- log.debug(Messages.getMessage("defaultCompiler"));
- compiler = new Javac();
- }
-
- log.debug("axis.Compiler:" + compiler.getClass().getName());
-
- return compiler;
- }
-}
diff --git a/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/Javac.java b/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/Javac.java
deleted file mode 100644
index db20ee0..0000000
--- a/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/Javac.java
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- * Copyright 2001-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.axis.components.compiler;
-
-import org.apache.axis.components.logger.LogFactory;
-import org.apache.axis.utils.ClassUtils;
-import org.apache.axis.utils.Messages;
-import org.apache.commons.logging.Log;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.StringTokenizer;
-import java.net.URL;
-import java.net.MalformedURLException;
-import java.net.URLClassLoader;
-
-/**
- * This class wraps the Sun's Javac Compiler.
- *
- * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
- * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @since 2.0
- */
-
-public class Javac extends AbstractCompiler
-{
- protected static Log log =
- LogFactory.getLog(Javac.class.getName());
-
- public static final String CLASSIC_CLASS = "sun.tools.javac.Main";
- public static final String MODERN_CLASS = "com.sun.tools.javac.main.Main";
-
- private boolean modern = false;
-
- public Javac() {
- ClassLoader cl = getClassLoader();
- try {
- ClassUtils.forName(MODERN_CLASS, true, cl);
- modern = true;
- } catch (ClassNotFoundException e) {
- log.debug(Messages.getMessage("noModernCompiler"));
- try {
- ClassUtils.forName(CLASSIC_CLASS, true, cl);
- modern = false;
- } catch (Exception ex) {
- log.error(Messages.getMessage("noCompiler00"), ex);
- throw new RuntimeException(Messages.getMessage("noCompiler00"));
- }
- }
- log.debug(Messages.getMessage("compilerClass",
- (modern ? MODERN_CLASS : CLASSIC_CLASS)));
- }
-
- private ClassLoader getClassLoader() {
- // Use reflection to be able to build on all JDKs
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
-
- URL toolsURL = null;
- String tools = System.getProperty("java.home");
- if (tools != null) {
- File f = new File(tools + "/../lib/tools.jar");
- if (f.exists()) {
- try {
- toolsURL = f.toURL();
- cl = new URLClassLoader(new URL[]{toolsURL}, cl);
- } catch (MalformedURLException e) {
- }
- }
- }
-
- return cl;
- }
-
- /**
- * Compile a source file yielding a loadable class file.
- *
- * @exception IOException If an error occurs during compilation
- */
- public boolean compile() throws IOException {
- ByteArrayOutputStream err = new ByteArrayOutputStream();
- boolean result = false;
-
- try {
- // Create an instance of the compiler, redirecting output to err
- Class c = ClassUtils.forName(modern ? MODERN_CLASS : CLASSIC_CLASS,
- true,
- getClassLoader());
-
- Constructor cons;
- Object compiler;
- if (modern) {
- PrintWriter pw = new PrintWriter(new OutputStreamWriter(err));
- cons =
- c.getConstructor(new Class[] { String.class,
- PrintWriter.class});
-
- compiler = cons.newInstance(new Object[] { "javac", pw });
- }
- else {
- cons =
- c.getConstructor(new Class[] { OutputStream.class,
- String.class });
- compiler = cons.newInstance(new Object[] { err, "javac" });
-
- }
-
- // Call the compile() method
- Method compile = c.getMethod("compile",
- new Class [] { String[].class });
-
- if (modern) {
- int compilationResult =
- ((Integer)compile.invoke(compiler, new Object[]
- {
- toStringArray(fillArguments
- (new ArrayList()))})).intValue();
-
- result = (compilationResult == 0);
- log.debug("Compilation Returned: "
- + Integer.toString(compilationResult));
- }
- else {
- Boolean ok =
- (Boolean)compile.invoke(compiler, new Object[]
- {toStringArray(fillArguments(new ArrayList()))});
-
- result = ok.booleanValue();
- }
- } catch (Exception cnfe){
- log.error(Messages.getMessage("noCompiler00"), cnfe);
- throw new RuntimeException(Messages.getMessage("noCompiler00"));
- }
-
- this.errors = new ByteArrayInputStream(err.toByteArray());
- return result;
- }
-
- /**
- * Parse the compiler error stream to produce a list of
- * <code>CompilerError</code>s
- *
- * @param input The error stream
- * @return The list of compiler error messages
- * @exception IOException If an error occurs during message collection
- */
- protected List parseStream(BufferedReader input) throws IOException {
- if (modern) {
- return parseModernStream(input);
- } else {
- return parseClassicStream(input);
- }
- }
-
- /**
- * Parse the compiler error stream to produce a list of
- * <code>CompilerError</code>s
- *
- * @param input The error stream
- * @return The list of compiler error messages
- * @exception IOException If an error occurs during message collection
- */
- protected List parseModernStream(BufferedReader input) throws IOException {
- List errors = new ArrayList();
- String line = null;
- StringBuffer buffer = null;
-
- while (true) {
- // cleanup the buffer
- buffer = new StringBuffer(); // this is quicker than clearing it
-
- // most errors terminate with the '^' char
- do {
- if ((line = input.readLine()) == null)
- {
- if (buffer.length() > 0) {
- // There's an error which doesn't end with a '^'
- errors.add(new CompilerError("\n" + buffer.toString()));
- }
- return errors;
- }
- log.debug(line);
- buffer.append(line);
- buffer.append('\n');
- } while (!line.endsWith("^"));
-
- // add the error bean
- errors.add(parseModernError(buffer.toString()));
- }
- }
-
- /**
- * Parse an individual compiler error message with modern style.
- *
- * @param error The error text
- * @return A messaged <code>CompilerError</code>
- */
- private CompilerError parseModernError(String error) {
- StringTokenizer tokens = new StringTokenizer(error, ":");
- try {
- String file = tokens.nextToken();
- if (file.length() == 1) file = new StringBuffer(file).append(":").append(tokens.nextToken()).toString();
- int line = Integer.parseInt(tokens.nextToken());
-
- String message = tokens.nextToken("\n").substring(1);
- String context = tokens.nextToken("\n");
- String pointer = tokens.nextToken("\n");
- int startcolumn = pointer.indexOf("^");
- int endcolumn = context.indexOf(" ", startcolumn);
- if (endcolumn == -1) endcolumn = context.length();
- return new CompilerError(file, false, line, startcolumn, line, endcolumn, message);
- } catch(NoSuchElementException nse) {
- return new CompilerError(Messages.getMessage("noMoreTokens", error));
- } catch(Exception nse) {
- return new CompilerError(Messages.getMessage("cantParse", error));
- }
- }
-
- /**
- * Parse the compiler error stream to produce a list of
- * <code>CompilerError</code>s
- *
- * @param input The error stream
- * @return The list of compiler error messages
- * @exception IOException If an error occurs during message collection
- */
- protected List parseClassicStream(BufferedReader input) throws IOException {
- List errors = null;
- String line = null;
- StringBuffer buffer = null;
-
- while (true) {
- // cleanup the buffer
- buffer = new StringBuffer(); // this is faster than clearing it
-
- // each error has 3 lines
- for (int i = 0; i < 3 ; i++) {
- if ((line = input.readLine()) == null) return errors;
- log.debug(line);
- buffer.append(line);
- buffer.append('\n');
- }
-
- // if error is found create the vector
- if (errors == null) errors = new ArrayList();
-
- // add the error bean
- errors.add(parseClassicError(buffer.toString()));
- }
- }
-
- /**
- * Parse an individual compiler error message with classic style.
- *
- * @param error The error text
- * @return A messaged <code>CompilerError</code>
- */
- private CompilerError parseClassicError(String error) {
- StringTokenizer tokens = new StringTokenizer(error, ":");
- try {
- String file = tokens.nextToken();
- if (file.length() == 1) {
- file = new StringBuffer(file).append(":").
- append(tokens.nextToken()).toString();
- }
- int line = Integer.parseInt(tokens.nextToken());
-
- String last = tokens.nextToken();
- // In case the message contains ':', it should be reassembled
- while (tokens.hasMoreElements()) {
- last += tokens.nextToken();
- }
- tokens = new StringTokenizer(last.trim(), "\n");
- String message = tokens.nextToken();
- String context = tokens.nextToken();
- String pointer = tokens.nextToken();
- int startcolumn = pointer.indexOf("^");
- int endcolumn = context.indexOf(" ", startcolumn);
- if (endcolumn == -1) endcolumn = context.length();
-
- return new CompilerError(srcDir + File.separator + file, true,
- line, startcolumn, line, endcolumn, message);
- } catch(NoSuchElementException nse) {
- return new CompilerError(Messages.getMessage("noMoreTokens",
- error));
- } catch(Exception nse) {
- return new CompilerError(Messages.getMessage("cantParse", error));
- }
- }
-
- public String toString() {
- return Messages.getMessage("sunJavac");
- }
-}
diff --git a/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/Jikes.java b/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/Jikes.java
deleted file mode 100644
index d493701..0000000
--- a/axis-rt-jws/src/main/java/org/apache/axis/components/compiler/Jikes.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Copyright 2001-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.axis.components.compiler;
-
-import org.apache.axis.components.logger.LogFactory;
-import org.apache.axis.utils.Messages;
-import org.apache.commons.logging.Log;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.StringTokenizer;
-
-/**
- * This class wraps IBM's <i>Jikes</i> Java compiler
- * NOTE: inspired by the Apache Jasper implementation.
- * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
- * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @since 2.0
- */
-
-public class Jikes extends AbstractCompiler
-{
- protected static Log log =
- LogFactory.getLog(Jikes.class.getName());
-
- static final int OUTPUT_BUFFER_SIZE = 1024;
- static final int BUFFER_SIZE = 512;
-
- private class StreamPumper extends Thread {
-
- private BufferedInputStream stream;
- private boolean endOfStream = false;
- private boolean stopSignal = false;
- private int SLEEP_TIME = 5;
- private OutputStream out;
-
- public StreamPumper(BufferedInputStream is, OutputStream out) {
- this.stream = is;
- this.out = out;
- }
-
- public void pumpStream() throws IOException {
- byte[] buf = new byte[BUFFER_SIZE];
- if (!endOfStream) {
- int bytesRead = stream.read(buf, 0, BUFFER_SIZE);
-
- if (bytesRead > 0) {
- out.write(buf, 0, bytesRead);
- } else if (bytesRead == -1) {
- endOfStream = true;
- }
- }
- }
-
- public void run() {
- try {
- while (!endOfStream) {
- pumpStream();
- sleep(SLEEP_TIME);
- }
- } catch (Exception e) {
- // getLogger().warn("Jikes.run()", e);
- }
- }
- }
-
- /**
- * Copy arguments to a string array
- *
- * @param arguments The compiler arguments
- * @return A string array containing compilation arguments
- */
- protected String[] toStringArray(List arguments) {
- int i;
-
- for (i = 0; i < arguments.size(); i++) {
- String arg = (String) arguments.get(i);
- if (arg.equals("-sourcepath")) {
- // Remove -sourcepath option. Jikes does not understand that.
- arguments.remove(i);
- arguments.remove(i);
- break;
- }
- }
-
- String[] args = new String[arguments.size() + fileList.size()];
- for (i = 0; i < arguments.size(); i++) {
- args[i] = (String) arguments.get(i);
- }
-
- for (int j=0; j < fileList.size(); i++,j++) {
- args[i] = (String)fileList.get(j);
- }
-
- return args;
- }
-
- /**
- * Execute the compiler
- */
- public boolean compile() throws IOException {
-
- List args = new ArrayList();
- // command line name
- args.add("jikes");
- // indicate Emacs output mode must be used
- args.add("+E");
- // avoid warnings
- // Option nowarn with one hyphen only
- args.add("-nowarn");
-
- int exitValue;
- ByteArrayOutputStream tmpErr = new ByteArrayOutputStream(OUTPUT_BUFFER_SIZE);
-
- try {
- Process p = Runtime.getRuntime().exec(toStringArray(fillArguments(args)));
-
- BufferedInputStream compilerErr = new BufferedInputStream(p.getErrorStream());
-
- StreamPumper errPumper = new StreamPumper(compilerErr, tmpErr);
-
- errPumper.start();
-
- p.waitFor();
- exitValue = p.exitValue();
-
- // Wait until the complete error stream has been read
- errPumper.join();
- compilerErr.close();
-
- p.destroy();
-
- tmpErr.close();
- this.errors = new ByteArrayInputStream(tmpErr.toByteArray());
-
- } catch (InterruptedException somethingHappened) {
- log.debug("Jikes.compile():SomethingHappened", somethingHappened);
- return false;
- }
-
- // Jikes returns 0 even when there are some types of errors.
- // Check if any error output as well
- // Return should be OK when both exitValue and
- // tmpErr.size() are 0 ?!
- return ((exitValue == 0) && (tmpErr.size() == 0));
- }
-
- /**
- * Parse the compiler error stream to produce a list of
- * <code>CompilerError</code>s
- *
- * @param input The error stream
- * @return The list of compiler error messages
- * @exception IOException If an error occurs during message collection
- */
- protected List parseStream(BufferedReader input) throws IOException {
- List errors = null;
- String line = null;
- StringBuffer buffer = null;
-
- while (true) {
- // cleanup the buffer
- buffer = new StringBuffer(); // this is faster than clearing it
-
- // first line is not space-starting
- if (line == null) line = input.readLine();
- if (line == null) return errors;
- log.debug(line);
- buffer.append(line);
-
- // all other space-starting lines are one error
- while (true) {
- line = input.readLine();
- // EOF
- if (line == null)
- break;
- // Continuation of previous error starts with ' '
- if (line.length() > 0 && line.charAt(0) != ' ')
- break;
- log.debug(line);
- buffer.append('\n');
- buffer.append(line);
- }
-
- // if error is found create the vector
- if (errors == null) errors = new ArrayList();
-
- // add the error bean
- errors.add(parseError(buffer.toString()));
- }
- }
-
- /**
- * Parse an individual compiler error message
- *
- * @param error The error text
- * @return A mssaged <code>CompilerError</code>
- */
- private CompilerError parseError(String error) {
- StringTokenizer tokens = new StringTokenizer(error, ":");
- String file = tokens.nextToken();
- if (file.length() == 1) file = new StringBuffer(file).append(":").append(tokens.nextToken()).toString();
- StringBuffer message = new StringBuffer();
- String type = "";
- int startline = 0;
- int startcolumn = 0;
- int endline = 0;
- int endcolumn = 0;
-
- try {
- startline = Integer.parseInt(tokens.nextToken());
- startcolumn = Integer.parseInt(tokens.nextToken());
- endline = Integer.parseInt(tokens.nextToken());
- endcolumn = Integer.parseInt(tokens.nextToken());
- } catch (Exception e) {
- // FIXME: VG: This is not needed anymore?
- message.append(Messages.getMessage("compilerFail00"));
- type="error";
- log.error(Messages.getMessage("compilerFail00"), e);
- }
-
- if ("".equals(message)) {
- type = tokens.nextToken().trim().toLowerCase();
- message.append(tokens.nextToken("\n").substring(1).trim());
-
- while (tokens.hasMoreTokens())
- message.append("\n").append(tokens.nextToken());
- }
-
- return new CompilerError(file, type.equals("error"), startline, startcolumn, endline, endcolumn, message.toString());
- }
-
- public String toString() {
- return Messages.getMessage("ibmJikes");
- }
-}
diff --git a/axis-rt-jws/src/main/java/org/apache/axis/handlers/JWSHandler.java b/axis-rt-jws/src/main/java/org/apache/axis/handlers/JWSHandler.java
index cede9fe..6626e05 100644
--- a/axis-rt-jws/src/main/java/org/apache/axis/handlers/JWSHandler.java
+++ b/axis-rt-jws/src/main/java/org/apache/axis/handlers/JWSHandler.java
@@ -19,9 +19,6 @@
import org.apache.axis.AxisFault;
import org.apache.axis.Constants;
import org.apache.axis.MessageContext;
-import org.apache.axis.components.compiler.Compiler;
-import org.apache.axis.components.compiler.CompilerError;
-import org.apache.axis.components.compiler.CompilerFactory;
import org.apache.axis.components.logger.LogFactory;
import org.apache.axis.constants.Scope;
import org.apache.axis.handlers.soap.SOAPService;
@@ -38,11 +35,21 @@
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Hashtable;
-import java.util.List;
import java.util.Map;
+import javax.tools.Diagnostic;
+import javax.tools.Diagnostic.Kind;
+import javax.tools.DiagnosticCollector;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaCompiler.CompilationTask;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
+import javax.tools.ToolProvider;
+
/** A <code>JWSHandler</code> sets the target service and JWS filename
* in the context depending on the JWS configuration and the target URL.
*
@@ -192,13 +199,17 @@
log.debug("javac " + jFile );
// Process proc = rt.exec( "javac " + jFile );
// proc.waitFor();
- Compiler compiler = CompilerFactory.getCompiler();
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
- compiler.setClasspath(ClasspathUtils.getDefaultClasspath(msgContext));
- compiler.setDestination(outdir);
- compiler.addFile(jFile);
+ fileManager.setLocation(StandardLocation.CLASS_PATH, ClasspathUtils.getDefaultClasspath(msgContext));
+ fileManager.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singletonList(new File(outdir)));
- boolean result = compiler.compile();
+ DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<JavaFileObject>();
+ CompilationTask task = compiler.getTask(null, fileManager, diagnosticCollector, null, null,
+ fileManager.getJavaFileObjectsFromFiles(Collections.singletonList(new File(jFile))));
+
+ boolean result = task.call();
/* Delete the temporary *.java file and check return code */
/**********************************************************/
@@ -216,19 +227,17 @@
Element root = doc.createElementNS("", "Errors");
StringBuffer message = new StringBuffer("Error compiling ");
message.append(jFile);
- message.append(":\n");
-
- List errors = compiler.getErrors();
- int count = errors.size();
- for (int i = 0; i < count; i++) {
- CompilerError error = (CompilerError) errors.get(i);
- if (i > 0) message.append("\n");
- message.append("Line ");
- message.append(error.getStartLine());
- message.append(", column ");
- message.append(error.getStartColumn());
- message.append(": ");
- message.append(error.getMessage());
+ message.append(":");
+
+ for (Diagnostic<? extends JavaFileObject> diagnostic : diagnosticCollector.getDiagnostics()) {
+ if (diagnostic.getKind() == Kind.ERROR) {
+ message.append("\nLine ");
+ message.append(diagnostic.getLineNumber());
+ message.append(", column ");
+ message.append(diagnostic.getStartPosition());
+ message.append(": ");
+ message.append(diagnostic.getMessage(null));
+ }
}
root.appendChild( doc.createTextNode( message.toString() ) );
throw new AxisFault( "Server.compileError",
diff --git a/axis-rt-jws/src/main/java/org/apache/axis/utils/ClasspathUtils.java b/axis-rt-jws/src/main/java/org/apache/axis/utils/ClasspathUtils.java
index 1858b9a..3502628 100644
--- a/axis-rt-jws/src/main/java/org/apache/axis/utils/ClasspathUtils.java
+++ b/axis-rt-jws/src/main/java/org/apache/axis/utils/ClasspathUtils.java
@@ -27,6 +27,9 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import java.util.StringTokenizer;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
@@ -50,23 +53,19 @@
* @param dirPaths The string containing the directory path or list of
* directory paths.
* @return The file paths of the jar files in the directories. This is an
- * empty string if no files were found, and is terminated by an
- * additional pathSeparator in all other cases.
+ * empty list if no files were found.
*/
- public static String expandDirs(String dirPaths) {
+ public static List<File> expandDirs(String dirPaths) {
StringTokenizer st = new StringTokenizer(dirPaths, File.pathSeparator);
- StringBuffer buffer = new StringBuffer();
+ List<File> files = new ArrayList<File>();
while (st.hasMoreTokens()) {
String d = st.nextToken();
File dir = new File(d);
if (dir.isDirectory()) {
- File[] files = dir.listFiles(new JavaArchiveFilter());
- for (int i = 0; i < files.length; i++) {
- buffer.append(files[i]).append(File.pathSeparator);
- }
+ files.addAll(Arrays.asList(dir.listFiles(new JavaArchiveFilter())));
}
}
- return buffer.toString();
+ return files;
}
/**
@@ -90,8 +89,8 @@
* @param msgContext
* @return default classpath
*/
- public static String getDefaultClasspath(MessageContext msgContext) {
- StringBuffer classpath = new StringBuffer();
+ public static List<File> getDefaultClasspath(MessageContext msgContext) {
+ List<File> classpath = new ArrayList<File>();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
fillClassPath(cl, classpath);
@@ -100,8 +99,7 @@
String webBase = (String) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETLOCATION);
if (webBase != null) {
- classpath.append(webBase + File.separatorChar + "classes" +
- File.pathSeparatorChar);
+ classpath.add(new File(webBase, "classes"));
try {
String libBase = webBase + File.separatorChar + "lib";
File libDir = new File(libBase);
@@ -109,10 +107,7 @@
for (int i = 0; i < jarFiles.length; i++) {
String jarFile = jarFiles[i];
if (jarFile.endsWith(".jar")) {
- classpath.append(libBase +
- File.separatorChar +
- jarFile +
- File.pathSeparatorChar);
+ classpath.add(new File(libBase, jarFile));
}
}
} catch (Exception e) {
@@ -138,7 +133,8 @@
// boot classpath isn't found in above search
getClassPathFromProperty(classpath, "sun.boot.class.path");
- return classpath.toString();
+
+ return classpath;
}
/**
@@ -146,18 +142,13 @@
* @param classpath
* @param property
*/
- private static void getClassPathFromDirectoryProperty(StringBuffer classpath, String property) {
+ private static void getClassPathFromDirectoryProperty(List<File> classpath, String property) {
String dirs = AxisProperties.getProperty(property);
- String path = null;
try {
- path = ClasspathUtils.expandDirs(dirs);
+ classpath.addAll(ClasspathUtils.expandDirs(dirs));
} catch (Exception e) {
// Oh well. No big deal.
}
- if (path != null) {
- classpath.append(path);
- classpath.append(File.pathSeparatorChar);
- }
}
/**
@@ -165,11 +156,12 @@
* @param classpath
* @param property
*/
- private static void getClassPathFromProperty(StringBuffer classpath, String property) {
+ private static void getClassPathFromProperty(List<File> classpath, String property) {
String path = AxisProperties.getProperty(property);
if (path != null) {
- classpath.append(path);
- classpath.append(File.pathSeparatorChar);
+ for (String item : path.split(File.pathSeparator)) {
+ classpath.add(new File(item));
+ }
}
}
@@ -178,7 +170,7 @@
* @param cl
* @param classpath
*/
- private static void fillClassPath(ClassLoader cl, StringBuffer classpath) {
+ private static void fillClassPath(ClassLoader cl, List<File> classpath) {
while (cl != null) {
if (cl instanceof URLClassLoader) {
URL[] urls = ((URLClassLoader) cl).getURLs();
@@ -187,8 +179,7 @@
//If it is a drive letter, adjust accordingly.
if (path.length() >= 3 && path.charAt(0) == '/' && path.charAt(2) == ':')
path = path.substring(1);
- classpath.append(URLDecoder.decode(path));
- classpath.append(File.pathSeparatorChar);
+ classpath.add(new File(URLDecoder.decode(path)));
// if its a jar extract Class-Path entries from manifest
File file = new File(urls[i].getFile());
@@ -208,8 +199,7 @@
StringTokenizer st = new StringTokenizer(s, " ");
while (st.hasMoreTokens()) {
String t = st.nextToken();
- classpath.append(base + File.separatorChar + t);
- classpath.append(File.pathSeparatorChar);
+ classpath.add(new File(base, t));
}
}
}
diff --git a/pom.xml b/pom.xml
index 38a52a1..7ed626d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -330,6 +330,8 @@
artifactId = 'java14-sun'
} else if (javaVersion == '1.5') {
artifactId = 'java15-sun'
+ } else if (javaVersion == '1.6') {
+ artifactId = 'java16-sun'
}
project.properties['signatureArtifactId'] = artifactId
project.properties['signatureVersion'] = '1.0'
diff --git a/src/site/apt/changelogs/1_4_1.apt b/src/site/apt/changelogs/1_4_1.apt
index d9184ad..13ab1e8 100644
--- a/src/site/apt/changelogs/1_4_1.apt
+++ b/src/site/apt/changelogs/1_4_1.apt
@@ -51,3 +51,5 @@
* <<<AxisServlet>>> no longer attempts to register the Axis MBeans automatically. To enable them, add
<<<axis-rt-management>>> as a dependency and register <<<org.apache.axis.management.servlet.AxisServerMBeanExporter>>>
as a listener in <<<web.xml>>>.
+
+ * The JWS support was updated to use the <<<javax.tools>>> API, which requires Java 6.