8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 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 * 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. 24 */ 25 26 package com.sun.tools.sjavac.options; 27 28 import java.nio.file.Path; 29 import java.util.List; 30 import java.util.Map; 31 import java.util.Set; 32 33 import com.sun.tools.sjavac.Module; 34 import com.sun.tools.sjavac.ProblemException; 35 import com.sun.tools.sjavac.Source; 36 37 /** 38 * Represents a directory to be used for input to sjavac. (For instance a 39 * sourcepath or classpath.) 40 */ 41 public class SourceLocation { 42 43 // Path to the root directory 44 private Path path; 45 46 // Package include / exclude patterns and file includes / excludes. 47 List<String> includes, excludes, includedFiles, excludedFiles; 48 49 public SourceLocation(Path path, 50 List<String> includes, 51 List<String> excludes, 93 } 94 95 /** Get the package include patterns */ 96 public List<String> getIncludes() { 97 return includes; 98 } 99 100 /** Get the package exclude patterns */ 101 public List<String> getExcludes() { 102 return excludes; 103 } 104 105 /** Get the file include patterns */ 106 public List<String> getIncludedFiles() { 107 return includedFiles; 108 } 109 110 /** Get the file exclude patterns */ 111 public List<String> getExcludedFiles() { 112 return excludedFiles; 113 } 114 115 } | 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 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 * 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. 24 */ 25 26 package com.sun.tools.sjavac.options; 27 28 import java.io.File; 29 import java.io.BufferedReader; 30 import java.io.FileReader; 31 import java.io.IOException; 32 import java.io.FileNotFoundException; 33 import java.nio.file.Path; 34 import java.util.List; 35 import java.util.Map; 36 import java.util.Set; 37 import java.util.HashSet; 38 39 import com.sun.tools.sjavac.Module; 40 import com.sun.tools.sjavac.ProblemException; 41 import com.sun.tools.sjavac.Source; 42 43 /** 44 * Represents a directory to be used for input to sjavac. (For instance a 45 * sourcepath or classpath.) 46 */ 47 public class SourceLocation { 48 49 // Path to the root directory 50 private Path path; 51 52 // Package include / exclude patterns and file includes / excludes. 53 List<String> includes, excludes, includedFiles, excludedFiles; 54 55 public SourceLocation(Path path, 56 List<String> includes, 57 List<String> excludes, 99 } 100 101 /** Get the package include patterns */ 102 public List<String> getIncludes() { 103 return includes; 104 } 105 106 /** Get the package exclude patterns */ 107 public List<String> getExcludes() { 108 return excludes; 109 } 110 111 /** Get the file include patterns */ 112 public List<String> getIncludedFiles() { 113 return includedFiles; 114 } 115 116 /** Get the file exclude patterns */ 117 public List<String> getExcludedFiles() { 118 return excludedFiles; 119 } 120 121 /** Load a list of source files from a file. */ 122 public static Set<String> loadList(File sourceList) { 123 // If we are building on win32 using for example cygwin the paths in the makefile source list 124 // might be /cygdrive/c/.... which does not match c:\.... 125 // We need to adjust our calculated sources to be identical, if necessary. 126 boolean mightNeedRewriting = java.io.File.pathSeparatorChar == ';'; 127 Set<String> loadedSources = new HashSet<>(); 128 // Read in the file and create another set of filenames with full paths. 129 try { 130 BufferedReader in = new BufferedReader(new FileReader(sourceList)); 131 for (;;) { 132 String l = in.readLine(); 133 if (l==null) break; 134 l = l.trim(); 135 if (mightNeedRewriting) { 136 if (l.indexOf(":") == 1 && l.indexOf("\\") == 2) { 137 // Everything a-ok, the format is already C:\foo\bar 138 } else if (l.indexOf(":") == 1 && l.indexOf("/") == 2) { 139 // The format is C:/foo/bar, rewrite into the above format. 140 l = l.replaceAll("/","\\\\"); 141 } else if (l.charAt(0) == '/' && l.indexOf("/",1) != -1) { 142 // The format might be: /cygdrive/c/foo/bar, rewrite into the above format. 143 // Do not hardcode the name cygdrive here. 144 int slash = l.indexOf("/",1); 145 l = l.replaceAll("/","\\\\"); 146 l = ""+l.charAt(slash+1)+":"+l.substring(slash+2); 147 } 148 if (Character.isLowerCase(l.charAt(0))) { 149 l = Character.toUpperCase(l.charAt(0))+l.substring(1); 150 } 151 } 152 loadedSources.add(l); 153 } 154 } catch (FileNotFoundException e) { 155 System.err.println("Could not open "+sourceList.getPath()+" since it does not exist!"); 156 return null; 157 } catch (IOException e) { 158 System.err.println("Could not read "+sourceList.getPath()); 159 return null; 160 } 161 return loadedSources; 162 } 163 164 } |