aoqi@0: /* aoqi@0: * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * Licensed Materials - Property of IBM aoqi@0: * RMI-IIOP v1.0 aoqi@0: * Copyright IBM Corp. 1998 1999 All Rights Reserved aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: package sun.rmi.rmic.iiop; aoqi@0: aoqi@0: import java.io.File; aoqi@0: import sun.tools.java.Identifier; aoqi@0: aoqi@0: import com.sun.corba.se.impl.util.PackagePrefixChecker; aoqi@0: aoqi@0: /** aoqi@0: * Util provides static utility methods used by other rmic classes. aoqi@0: * @author Bryan Atsatt aoqi@0: */ aoqi@0: aoqi@0: public final class Util implements sun.rmi.rmic.Constants { aoqi@0: aoqi@0: aoqi@0: public static String packagePrefix(){ return PackagePrefixChecker.packagePrefix();} aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Return the directory that should be used for output for a given aoqi@0: * class. aoqi@0: * @param theClass The fully qualified name of the class. aoqi@0: * @param rootDir The directory to use as the root of the aoqi@0: * package heirarchy. May be null, in which case the current aoqi@0: * working directory is used as the root. aoqi@0: */ aoqi@0: private static File getOutputDirectoryFor(Identifier theClass, aoqi@0: File rootDir, aoqi@0: BatchEnvironment env, aoqi@0: boolean idl ) { aoqi@0: File outputDir = null; aoqi@0: String className = theClass.getFlatName().toString().replace('.', SIGC_INNERCLASS); aoqi@0: String qualifiedClassName = className; aoqi@0: String packagePath = null; aoqi@0: String packageName = theClass.getQualifier().toString(); aoqi@0: //Shift package names for stubs generated for interfaces. aoqi@0: /*if(type.isInterface())*/ aoqi@0: packageName = correctPackageName(packageName, idl, env.getStandardPackage()); aoqi@0: //Done. aoqi@0: if (packageName.length() > 0) { aoqi@0: qualifiedClassName = packageName + "." + className; aoqi@0: packagePath = packageName.replace('.', File.separatorChar); aoqi@0: } aoqi@0: aoqi@0: // Do we have a root directory? aoqi@0: aoqi@0: if (rootDir != null) { aoqi@0: aoqi@0: // Yes, do we have a package name? aoqi@0: aoqi@0: if (packagePath != null) { aoqi@0: aoqi@0: // Yes, so use it as the root. Open the directory... aoqi@0: aoqi@0: outputDir = new File(rootDir, packagePath); aoqi@0: aoqi@0: // Make sure the directory exists... aoqi@0: aoqi@0: ensureDirectory(outputDir,env); aoqi@0: aoqi@0: } else { aoqi@0: aoqi@0: // Default package, so use root as output dir... aoqi@0: aoqi@0: outputDir = rootDir; aoqi@0: } aoqi@0: } else { aoqi@0: aoqi@0: // No root directory. Get the current working directory... aoqi@0: aoqi@0: String workingDirPath = System.getProperty("user.dir"); aoqi@0: File workingDir = new File(workingDirPath); aoqi@0: aoqi@0: // Do we have a package name? aoqi@0: aoqi@0: if (packagePath == null) { aoqi@0: aoqi@0: // No, so use working directory... aoqi@0: aoqi@0: outputDir = workingDir; aoqi@0: aoqi@0: } else { aoqi@0: aoqi@0: // Yes, so use working directory as the root... aoqi@0: aoqi@0: outputDir = new File(workingDir, packagePath); aoqi@0: aoqi@0: // Make sure the directory exists... aoqi@0: aoqi@0: ensureDirectory(outputDir,env); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Finally, return the directory... aoqi@0: aoqi@0: return outputDir; aoqi@0: } aoqi@0: aoqi@0: public static File getOutputDirectoryForIDL(Identifier theClass, aoqi@0: File rootDir, aoqi@0: BatchEnvironment env) { aoqi@0: return getOutputDirectoryFor(theClass, rootDir, env, true); aoqi@0: } aoqi@0: aoqi@0: public static File getOutputDirectoryForStub(Identifier theClass, aoqi@0: File rootDir, aoqi@0: BatchEnvironment env) { aoqi@0: return getOutputDirectoryFor(theClass, rootDir, env, false); aoqi@0: } aoqi@0: aoqi@0: private static void ensureDirectory (File dir, BatchEnvironment env) { aoqi@0: if (!dir.exists()) { aoqi@0: dir.mkdirs(); aoqi@0: if (!dir.exists()) { aoqi@0: env.error(0,"rmic.cannot.create.dir",dir.getAbsolutePath()); aoqi@0: throw new InternalError(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public static String correctPackageName( aoqi@0: String p, boolean idl, boolean standardPackage){ aoqi@0: if (idl){ aoqi@0: return p; aoqi@0: } else { aoqi@0: if (standardPackage) { aoqi@0: return p; aoqi@0: } else { aoqi@0: return PackagePrefixChecker.correctPackageName(p); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public static boolean isOffendingPackage(String p){ aoqi@0: return PackagePrefixChecker.isOffendingPackage(p); aoqi@0: } aoqi@0: aoqi@0: public static boolean hasOffendingPrefix(String p){ aoqi@0: return PackagePrefixChecker.hasOffendingPrefix(p); aoqi@0: } aoqi@0: aoqi@0: }