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