|
|
22fe22 |
/*
|
|
|
22fe22 |
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
22fe22 |
* contributor license agreements. See the NOTICE file distributed with
|
|
|
22fe22 |
* this work for additional information regarding copyright ownership.
|
|
|
22fe22 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
22fe22 |
* (the "License"); you may not use this file except in compliance with
|
|
|
22fe22 |
* the License. You may obtain a copy of the License at
|
|
|
22fe22 |
*
|
|
|
22fe22 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
22fe22 |
*
|
|
|
22fe22 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
22fe22 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
22fe22 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
22fe22 |
* See the License for the specific language governing permissions and
|
|
|
22fe22 |
* limitations under the License.
|
|
|
22fe22 |
*/
|
|
|
22fe22 |
|
|
|
22fe22 |
package org.apache.xerces.util;
|
|
|
22fe22 |
|
|
|
22fe22 |
import org.apache.tools.ant.BuildException;
|
|
|
22fe22 |
import org.apache.tools.ant.Project;
|
|
|
22fe22 |
import org.apache.tools.ant.types.Path;
|
|
|
22fe22 |
import org.apache.tools.ant.util.JavaEnvUtils;
|
|
|
22fe22 |
import org.apache.tools.ant.taskdefs.Javac;
|
|
|
22fe22 |
|
|
|
22fe22 |
import java.lang.StringBuffer;
|
|
|
22fe22 |
import java.util.Properties;
|
|
|
22fe22 |
import java.util.Locale;
|
|
|
22fe22 |
|
|
|
22fe22 |
/**
|
|
|
22fe22 |
* The implementation of the javac compiler for JDK 1.4 and above
|
|
|
22fe22 |
*
|
|
|
22fe22 |
* The purpose of this task is to diagnose whether we're
|
|
|
22fe22 |
* running on a 1.4 or above JVM; if we are, to
|
|
|
22fe22 |
* set up the bootclasspath such that the build will
|
|
|
22fe22 |
* succeed; if we aren't, then invoke the Javac12
|
|
|
22fe22 |
* task.
|
|
|
22fe22 |
*
|
|
|
22fe22 |
* @author Neil Graham, IBM
|
|
|
22fe22 |
*/
|
|
|
22fe22 |
public class XJavac extends Javac {
|
|
|
22fe22 |
|
|
|
22fe22 |
/**
|
|
|
22fe22 |
* Run the compilation.
|
|
|
22fe22 |
*
|
|
|
22fe22 |
* @exception BuildException if the compilation has problems.
|
|
|
22fe22 |
*/
|
|
|
22fe22 |
public void execute() throws BuildException {
|
|
|
22fe22 |
if(isJDK14OrHigher()) {
|
|
|
22fe22 |
// maybe the right one; check vendor:
|
|
|
22fe22 |
// by checking system properties:
|
|
|
22fe22 |
Properties props = null;
|
|
|
22fe22 |
try {
|
|
|
22fe22 |
props = System.getProperties();
|
|
|
22fe22 |
} catch (Exception e) {
|
|
|
22fe22 |
throw new BuildException("unable to determine java vendor because could not access system properties!");
|
|
|
22fe22 |
}
|
|
|
22fe22 |
// this is supposed to be provided by all JVM's from time immemorial
|
|
|
22fe22 |
String vendor = ((String)props.get("java.vendor")).toUpperCase(Locale.ENGLISH);
|
|
|
22fe22 |
if (vendor.indexOf("IBM") >= 0) {
|
|
|
22fe22 |
// we're on an IBM 1.4 or higher; fiddle with the bootclasspath.
|
|
|
22fe22 |
setBootclasspath(createIBMJDKBootclasspath());
|
|
|
22fe22 |
}
|
|
|
22fe22 |
// need to do special things for Sun too and also
|
|
|
22fe22 |
// for Apple, HP, FreeBSD, SableVM, Kaffe and Blackdown: a Linux port of Sun Java
|
|
|
22fe22 |
else if( (vendor.indexOf("SUN") >= 0) ||
|
|
|
22fe22 |
(vendor.indexOf("BLACKDOWN") >= 0) ||
|
|
|
22fe22 |
(vendor.indexOf("APPLE") >= 0) ||
|
|
|
22fe22 |
(vendor.indexOf("HEWLETT-PACKARD") >= 0) ||
|
|
|
22fe22 |
(vendor.indexOf("KAFFE") >= 0) ||
|
|
|
22fe22 |
(vendor.indexOf("SABLE") >= 0) ||
|
|
|
22fe22 |
(vendor.indexOf("FREEBSD") >= 0)) {
|
|
|
22fe22 |
// we're on an SUN 1.4 or higher; fiddle with the bootclasspath.
|
|
|
22fe22 |
// since we can't eviscerate XML-related info here,
|
|
|
22fe22 |
// we must use the classpath
|
|
|
22fe22 |
Path bcp = createBootclasspath();
|
|
|
22fe22 |
Path clPath = getClasspath();
|
|
|
22fe22 |
bcp.append(clPath);
|
|
|
22fe22 |
String currBCP = (String)props.get("sun.boot.class.path");
|
|
|
22fe22 |
Path currBCPath = new Path(null);
|
|
|
22fe22 |
currBCPath.createPathElement().setPath(currBCP);
|
|
|
22fe22 |
bcp.append(currBCPath);
|
|
|
22fe22 |
setBootclasspath(bcp);
|
|
|
22fe22 |
}
|
|
|
22fe22 |
}
|
|
|
22fe22 |
// now just do the normal thing:
|
|
|
22fe22 |
super.execute();
|
|
|
22fe22 |
}
|
|
|
22fe22 |
|
|
|
22fe22 |
/**
|
|
|
22fe22 |
* Creates bootclasspath for IBM JDK 1.4 and above.
|
|
|
22fe22 |
*/
|
|
|
22fe22 |
private Path createIBMJDKBootclasspath() {
|
|
|
22fe22 |
Path bcp = createBootclasspath();
|
|
|
22fe22 |
String javaHome = System.getProperty("java.home");
|
|
|
22fe22 |
StringBuffer bcpMember = new StringBuffer();
|
|
|
22fe22 |
bcpMember.append(javaHome).append("/lib/charsets.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/core.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/vm.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/java.util.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/rt.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/graphics.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/javaws.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/jaws.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/security.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/server.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/ext/JawBridge.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/ext/gskikm.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/ext/ibmjceprovider.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/ext/indicim.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/ext/jaccess.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/ext/ldapsec.jar:");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
bcpMember.replace(javaHome.length(), bcpMember.length(), "/lib/ext/oldcertpath.jar");
|
|
|
22fe22 |
bcp.createPathElement().setPath(bcpMember.toString());
|
|
|
22fe22 |
return bcp;
|
|
|
22fe22 |
}
|
|
|
22fe22 |
|
|
|
22fe22 |
/**
|
|
|
22fe22 |
* Checks whether the JDK version is 1.4 or higher. If it's not
|
|
|
22fe22 |
* JDK 1.4 we check whether we're on a future JDK by checking
|
|
|
22fe22 |
* that we're not on JDKs 1.0, 1.1, 1.2 or 1.3. This check by
|
|
|
22fe22 |
* exclusion should future proof this task from new versions of
|
|
|
22fe22 |
* Ant which are aware of higher JDK versions.
|
|
|
22fe22 |
*
|
|
|
22fe22 |
* @return true if the JDK version is 1.4 or higher.
|
|
|
22fe22 |
*/
|
|
|
22fe22 |
private boolean isJDK14OrHigher() {
|
|
|
22fe22 |
final String version = JavaEnvUtils.getJavaVersion();
|
|
|
22fe22 |
return version.equals(JavaEnvUtils.JAVA_1_4) ||
|
|
|
22fe22 |
(!version.equals(JavaEnvUtils.JAVA_1_3) &&
|
|
|
22fe22 |
!version.equals(JavaEnvUtils.JAVA_1_2) &&
|
|
|
22fe22 |
!version.equals(JavaEnvUtils.JAVA_1_1) &&
|
|
|
22fe22 |
!version.equals(JavaEnvUtils.JAVA_1_0));
|
|
|
22fe22 |
}
|
|
|
22fe22 |
}
|