src/share/classes/com/sun/tools/doclets/internal/toolkit/util/SourcePath.java

Mon, 02 May 2011 02:13:02 -0700

author
bpatel
date
Mon, 02 May 2011 02:13:02 -0700
changeset 995
62bc3775d5bb
parent 554
9d9f26857129
child 1372
78962d89f283
permissions
-rw-r--r--

6492694: @deprecated tag doesn't work in package-info files.
Reviewed-by: jjg

duke@1 1 /*
ohair@554 2 * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.internal.toolkit.util;
duke@1 27
duke@1 28 import java.io.File;
duke@1 29
duke@1 30 /**
duke@1 31 * This class is used to represent a source path which can contain only
duke@1 32 * directories no zip files. If a zip file is specified in the command line it
duke@1 33 * will not get reflected in the SourcePath.
duke@1 34 *
duke@1 35 * This code is not part of an API.
duke@1 36 * It is implementation that is subject to change.
duke@1 37 * Do not use it as an API
duke@1 38 *
duke@1 39 * @author Atul M Dambalkar
duke@1 40 */
duke@1 41 public
duke@1 42 class SourcePath {
duke@1 43 private final char dirSeparator = File.pathSeparatorChar;
duke@1 44
duke@1 45 /**
duke@1 46 * The original class path string
duke@1 47 */
duke@1 48 private String pathstr;
duke@1 49
duke@1 50 /**
duke@1 51 * List of source path entries. Each entry is a directory.
duke@1 52 */
duke@1 53 private File[] sourcePath;
duke@1 54
duke@1 55
duke@1 56 /**
duke@1 57 * Build a source path from the specified path string on the command line.
duke@1 58 */
duke@1 59 public SourcePath(String pathstr) {
duke@1 60 init(pathstr);
duke@1 61 }
duke@1 62
duke@1 63 /**
duke@1 64 * Build a default source path from the path strings specified by
duke@1 65 * the properties env.class.path.
duke@1 66 */
duke@1 67 public SourcePath() {
duke@1 68 init(System.getProperty("env.class.path"));
duke@1 69 }
duke@1 70
duke@1 71 /**
duke@1 72 * Initialize the SourcePath File array, which will contain only the
duke@1 73 * directory names from the given path string.
duke@1 74 *
duke@1 75 * @param pathstr Path String.
duke@1 76 */
duke@1 77 private void init(String pathstr) {
duke@1 78 if (pathstr == null || pathstr.length() == 0) {
duke@1 79 pathstr = ".";
duke@1 80 }
duke@1 81
duke@1 82 int noOfFileSep = 0;
duke@1 83 int index = 0;
duke@1 84 this.pathstr = pathstr; // Save original class path string
duke@1 85
duke@1 86 // Count the number of path separators
duke@1 87 while ((index = pathstr.indexOf(dirSeparator, index)) != -1) {
duke@1 88 noOfFileSep++;
duke@1 89 index++;
duke@1 90 }
duke@1 91 // Build the source path
duke@1 92 File[] tempPath = new File[noOfFileSep + 1];
duke@1 93 int tempPathIndex = 0;
duke@1 94 int len = pathstr.length();
duke@1 95 int sepPos = 0;
duke@1 96 for (index = 0; index < len; index = sepPos + 1) {
duke@1 97 sepPos = pathstr.indexOf(dirSeparator, index);
duke@1 98 if (sepPos < 0) {
duke@1 99 sepPos = len;
duke@1 100 }
duke@1 101 File file = new File(pathstr.substring(index, sepPos));
duke@1 102 if (file.isDirectory()) {
duke@1 103 tempPath[tempPathIndex++] = file;
duke@1 104 } // if it is really a file, ignore it.
duke@1 105 }
duke@1 106 sourcePath = new File[tempPathIndex];
duke@1 107 System.arraycopy((Object)tempPath, 0, (Object)sourcePath,
duke@1 108 0, tempPathIndex);
duke@1 109 }
duke@1 110
duke@1 111 /**
duke@1 112 * Find the specified directory in the source path.
duke@1 113 *
duke@1 114 * @param name Name of the directory to be searched for in the source path.
duke@1 115 * @return File Return the directory if found else return null.
duke@1 116 */
duke@1 117 public File getDirectory(String name) {
duke@1 118 for (int i = 0; i < sourcePath.length; i++) {
duke@1 119 File directoryNeeded = new File(sourcePath[i], name);
duke@1 120 if (directoryNeeded.isDirectory()) {
duke@1 121 return directoryNeeded;
duke@1 122 }
duke@1 123 }
duke@1 124 return null;
duke@1 125 }
duke@1 126
duke@1 127 /**
duke@1 128 * Return original source path string.
duke@1 129 */
duke@1 130 public String toString() {
duke@1 131 return pathstr;
duke@1 132 }
duke@1 133 }

mercurial