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