Blame SOURCES/XJavac.java

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