Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/rmi/rmic/Util.java
38831 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* Licensed Materials - Property of IBM27* RMI-IIOP v1.028* Copyright IBM Corp. 1998 1999 All Rights Reserved29*30*/3132package sun.rmi.rmic;3334import java.io.File;35import sun.tools.java.Identifier;3637/**38* Util provides static utility methods used by other rmic classes.39*40* WARNING: The contents of this source file are not part of any41* supported API. Code that depends on them does so at its own risk:42* they are subject to change or removal without notice.43*44* @author Bryan Atsatt45*/4647public class Util implements sun.rmi.rmic.Constants {4849/**50* Return the directory that should be used for output for a given51* class.52* @param theClass The fully qualified name of the class.53* @param rootDir The directory to use as the root of the54* package hierarchy. May be null, in which case the current55* working directory is used as the root.56*/57public static File getOutputDirectoryFor(Identifier theClass,58File rootDir,59BatchEnvironment env) {6061File outputDir = null;62String className = theClass.getFlatName().toString().replace('.', SIGC_INNERCLASS);63String qualifiedClassName = className;64String packagePath = null;65String packageName = theClass.getQualifier().toString();6667if (packageName.length() > 0) {68qualifiedClassName = packageName + "." + className;69packagePath = packageName.replace('.', File.separatorChar);70}7172// Do we have a root directory?7374if (rootDir != null) {7576// Yes, do we have a package name?7778if (packagePath != null) {7980// Yes, so use it as the root. Open the directory...8182outputDir = new File(rootDir, packagePath);8384// Make sure the directory exists...8586ensureDirectory(outputDir,env);8788} else {8990// Default package, so use root as output dir...9192outputDir = rootDir;93}94} else {9596// No root directory. Get the current working directory...9798String workingDirPath = System.getProperty("user.dir");99File workingDir = new File(workingDirPath);100101// Do we have a package name?102103if (packagePath == null) {104105// No, so use working directory...106107outputDir = workingDir;108109} else {110111// Yes, so use working directory as the root...112113outputDir = new File(workingDir, packagePath);114115// Make sure the directory exists...116117ensureDirectory(outputDir,env);118}119}120121// Finally, return the directory...122123return outputDir;124}125126private static void ensureDirectory (File dir, BatchEnvironment env) {127if (!dir.exists()) {128dir.mkdirs();129if (!dir.exists()) {130env.error(0,"rmic.cannot.create.dir",dir.getAbsolutePath());131throw new InternalError();132}133}134}135}136137138