Blame SOURCES/XJavac.java

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