src/jdk.compiler/share/classes/com/sun/tools/sjavac/options/Options.java

Print this page
rev 2819 : imported patch my-classpath-deps-00


  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.ArrayList;
  30 import java.util.Arrays;
  31 import java.util.Collection;
  32 import java.util.HashMap;
  33 import java.util.List;
  34 import java.util.Map;
  35 import java.util.Set;
  36 import java.util.HashSet;
  37 
  38 import com.sun.tools.sjavac.Transformer;

  39 
  40 /**
  41  * Instances of this class represent values for sjavac command line options.
  42  *
  43  *  <p><b>This is NOT part of any supported API.
  44  *  If you write code that depends on this, you do so at your own risk.
  45  *  This code and its internal interfaces are subject to change or
  46  *  deletion without notice.</b>
  47  */
  48 public class Options {
  49 
  50     // Output directories
  51     private Path destDir, genSrcDir, headerDir, stateDir;
  52 
  53     // Input directories
  54     private List<SourceLocation> sources = new ArrayList<>();
  55     private List<SourceLocation> sourceSearchPaths = new ArrayList<>();
  56     private List<SourceLocation> classSearchPaths = new ArrayList<>();
  57     private List<SourceLocation> moduleSearchPaths = new ArrayList<>();
  58 


 269         if (permitUnidentifiedArtifacts)
 270             args.addArg(Option.PERMIT_UNIDENTIFIED_ARTIFACTS);
 271 
 272         // Translation rules
 273         for (Map.Entry<String, Transformer> tr : trRules.entrySet()) {
 274             String val = tr.getKey() + "=" + tr.getValue().getClass().getName();
 275             args.addArg(Option.TR, val);
 276         }
 277 
 278         // Javac args
 279         args.addAll(javacArgs);
 280 
 281         return args.getResult();
 282     }
 283 
 284 
 285     /** Extract the arguments to be passed on to javac. */
 286     public String[] prepJavacArgs() {
 287         List<String> args = new ArrayList<>();
 288 


 289         // Output directories
 290         args.add("-d");
 291         args.add(destDir.toString());
 292 
 293         if (getGenSrcDir() != null) {
 294             args.add("-s");
 295             args.add(genSrcDir.toString());
 296         }
 297 
 298         if (headerDir != null) {
 299             args.add("-h");
 300             args.add(headerDir.toString());
 301         }
 302 
 303         // Prep sourcepath
 304         List<SourceLocation> sourcepath = new ArrayList<>();
 305         sourcepath.addAll(sources);
 306         sourcepath.addAll(sourceSearchPaths);
 307         if (sourcepath.size() > 0) {
 308             args.add("-sourcepath");
 309             args.add(concatenateSourceLocations(sourcepath));
 310         }
 311 
 312         // Prep classpath
 313         if (classSearchPaths.size() > 0) {
 314             args.add("-classpath");
 315             args.add(concatenateSourceLocations(classSearchPaths));
 316         }
 317 
 318         // This can't be anything but 'none'. Enforced by sjavac main method.
 319         args.add("-implicit:" + implicitPolicy);
 320 












 321         // Append javac-options (i.e. pass through options not recognized by
 322         // sjavac to javac.)
 323         args.addAll(javacArgs);
 324 
 325         return args.toArray(new String[args.size()]);
 326     }
 327 
 328     // Helper method to join a list of source locations separated by
 329     // File.pathSeparator
 330     private static String concatenateSourceLocations(List<SourceLocation> locs) {
 331         String s = "";
 332         for (SourceLocation loc : locs)
 333             s += (s.isEmpty() ? "" : java.io.File.pathSeparator) + loc.getPath();
 334         return s;
 335     }
 336 
 337     // OptionHelper that records the traversed options in this Options instance.
 338     private class ArgDecoderOptionHelper extends OptionHelper {
 339 
 340         List<String> includes, excludes, includeFiles, excludeFiles;
 341         {
 342             resetFilters();
 343         }
 344 
 345         boolean headerProvided = false;
 346         boolean genSrcProvided = false;
 347         boolean stateProvided = false;
 348 
 349         @Override
 350         public void reportError(String msg) {
 351             throw new IllegalArgumentException(msg);
 352         }
 353 
 354         @Override
 355         public void sourceRoots(List<Path> paths) {
 356             sources.addAll(createSourceLocations(paths));
 357         }
 358 
 359         @Override
 360         public void exclude(String exclPattern) {

 361             excludes.add(exclPattern);
 362         }
 363 
 364         @Override
 365         public void include(String inclPattern) {

 366             includes.add(inclPattern);
 367         }
 368 
 369         @Override
 370         public void excludeFile(String exclFilePattern) {

 371             excludeFiles.add(exclFilePattern);
 372         }
 373 
 374         @Override
 375         public void includeFile(String inclFilePattern) {

 376             includeFiles.add(inclFilePattern);
 377         }
 378 
 379         @Override
 380         public void addTransformer(String suffix, Transformer tr) {
 381             if (trRules.containsKey(suffix)) {
 382                 reportError("More than one transformer specified for " +
 383                             "suffix " + suffix + ".");
 384                 return;
 385             }
 386             trRules.put(suffix, tr);
 387         }
 388 
 389         @Override
 390         public void sourcepath(List<Path> paths) {
 391             sourceSearchPaths.addAll(createSourceLocations(paths));
 392         }
 393 
 394         @Override
 395         public void modulepath(List<Path> paths) {




  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.ArrayList;
  30 import java.util.Arrays;
  31 import java.util.Collection;
  32 import java.util.HashMap;
  33 import java.util.List;
  34 import java.util.Map;
  35 import java.util.Set;
  36 import java.util.HashSet;
  37 
  38 import com.sun.tools.sjavac.Transformer;
  39 import com.sun.tools.sjavac.Util;
  40 
  41 /**
  42  * Instances of this class represent values for sjavac command line options.
  43  *
  44  *  <p><b>This is NOT part of any supported API.
  45  *  If you write code that depends on this, you do so at your own risk.
  46  *  This code and its internal interfaces are subject to change or
  47  *  deletion without notice.</b>
  48  */
  49 public class Options {
  50 
  51     // Output directories
  52     private Path destDir, genSrcDir, headerDir, stateDir;
  53 
  54     // Input directories
  55     private List<SourceLocation> sources = new ArrayList<>();
  56     private List<SourceLocation> sourceSearchPaths = new ArrayList<>();
  57     private List<SourceLocation> classSearchPaths = new ArrayList<>();
  58     private List<SourceLocation> moduleSearchPaths = new ArrayList<>();
  59 


 270         if (permitUnidentifiedArtifacts)
 271             args.addArg(Option.PERMIT_UNIDENTIFIED_ARTIFACTS);
 272 
 273         // Translation rules
 274         for (Map.Entry<String, Transformer> tr : trRules.entrySet()) {
 275             String val = tr.getKey() + "=" + tr.getValue().getClass().getName();
 276             args.addArg(Option.TR, val);
 277         }
 278 
 279         // Javac args
 280         args.addAll(javacArgs);
 281 
 282         return args.getResult();
 283     }
 284 
 285 
 286     /** Extract the arguments to be passed on to javac. */
 287     public String[] prepJavacArgs() {
 288         List<String> args = new ArrayList<>();
 289 
 290 //args.add("-doe");
 291 
 292         // Output directories
 293         args.add("-d");
 294         args.add(destDir.toString());
 295 
 296         if (getGenSrcDir() != null) {
 297             args.add("-s");
 298             args.add(genSrcDir.toString());
 299         }
 300 
 301         if (headerDir != null) {
 302             args.add("-h");
 303             args.add(headerDir.toString());
 304         }
 305 
 306         // Prep sourcepath
 307         List<SourceLocation> sourcepath = new ArrayList<>();
 308         sourcepath.addAll(sources);
 309         sourcepath.addAll(sourceSearchPaths);
 310         if (sourcepath.size() > 0) {
 311             args.add("-sourcepath");
 312             args.add(concatenateSourceLocations(sourcepath));
 313         }
 314 
 315         // Prep classpath
 316         if (classSearchPaths.size() > 0) {
 317             args.add("-classpath");
 318             args.add(concatenateSourceLocations(classSearchPaths));
 319         }
 320 
 321         // This can't be anything but 'none'. Enforced by sjavac main method.
 322         args.add("-implicit:" + implicitPolicy);
 323 
 324         // If this option is not used, Object for instance is picked up from
 325         // PLATFORM_CLASS_PATH.
 326         //
 327         // Turns out that bootclasspath = classpath, in the JDK build so it's
 328         // still actually the correct file that is looked up. However, we don't
 329         // want non-JDK-builds to track files on the bootclasspath, so we enable
 330         // this option, to allow us to ignore dependencies on bootclasspath.
 331         //
 332         // It may make more sense to use an empty bootclasspath when building
 333         // the JDK.
 334         //args.add("-XXuserPathsFirst");
 335 
 336         // Append javac-options (i.e. pass through options not recognized by
 337         // sjavac to javac.)
 338         args.addAll(javacArgs);
 339 
 340         return args.toArray(new String[args.size()]);
 341     }
 342 
 343     // Helper method to join a list of source locations separated by
 344     // File.pathSeparator
 345     private static String concatenateSourceLocations(List<SourceLocation> locs) {
 346         String s = "";
 347         for (SourceLocation loc : locs)
 348             s += (s.isEmpty() ? "" : java.io.File.pathSeparator) + loc.getPath();
 349         return s;
 350     }
 351 
 352     // OptionHelper that records the traversed options in this Options instance.
 353     private class ArgDecoderOptionHelper extends OptionHelper {
 354 
 355         List<String> includes, excludes, includeFiles, excludeFiles;
 356         {
 357             resetFilters();
 358         }
 359 
 360         boolean headerProvided = false;
 361         boolean genSrcProvided = false;
 362         boolean stateProvided = false;
 363 
 364         @Override
 365         public void reportError(String msg) {
 366             throw new IllegalArgumentException(msg);
 367         }
 368 
 369         @Override
 370         public void sourceRoots(List<Path> paths) {
 371             sources.addAll(createSourceLocations(paths));
 372         }
 373 
 374         @Override
 375         public void exclude(String exclPattern) {
 376             exclPattern = Util.normalizeDriveLetter(exclPattern);
 377             excludes.add(exclPattern);
 378         }
 379 
 380         @Override
 381         public void include(String inclPattern) {
 382             inclPattern = Util.normalizeDriveLetter(inclPattern);
 383             includes.add(inclPattern);
 384         }
 385 
 386         @Override
 387         public void excludeFile(String exclFilePattern) {
 388             exclFilePattern = Util.normalizeDriveLetter(exclFilePattern);
 389             excludeFiles.add(exclFilePattern);
 390         }
 391 
 392         @Override
 393         public void includeFile(String inclFilePattern) {
 394             inclFilePattern = Util.normalizeDriveLetter(inclFilePattern);
 395             includeFiles.add(inclFilePattern);
 396         }
 397 
 398         @Override
 399         public void addTransformer(String suffix, Transformer tr) {
 400             if (trRules.containsKey(suffix)) {
 401                 reportError("More than one transformer specified for " +
 402                             "suffix " + suffix + ".");
 403                 return;
 404             }
 405             trRules.put(suffix, tr);
 406         }
 407 
 408         @Override
 409         public void sourcepath(List<Path> paths) {
 410             sourceSearchPaths.addAll(createSourceLocations(paths));
 411         }
 412 
 413         @Override
 414         public void modulepath(List<Path> paths) {