langtools/src/share/classes/com/sun/tools/apt/main/Main.java
changeset 4937 2fc03fb01efa
parent 3378 22011d9a9398
child 5520 86e4b9a9da40
equal deleted inserted replaced
4936:abf1a22d9bcf 4937:2fc03fb01efa
    53 
    53 
    54 import com.sun.tools.apt.comp.AnnotationProcessingError;
    54 import com.sun.tools.apt.comp.AnnotationProcessingError;
    55 import com.sun.tools.apt.comp.UsageMessageNeededException;
    55 import com.sun.tools.apt.comp.UsageMessageNeededException;
    56 import com.sun.tools.apt.util.Bark;
    56 import com.sun.tools.apt.util.Bark;
    57 import com.sun.mirror.apt.AnnotationProcessorFactory;
    57 import com.sun.mirror.apt.AnnotationProcessorFactory;
       
    58 
       
    59 import static com.sun.tools.javac.file.Paths.pathToURLs;
    58 
    60 
    59 /** This class provides a commandline interface to the apt build-time
    61 /** This class provides a commandline interface to the apt build-time
    60  *  tool.
    62  *  tool.
    61  *
    63  *
    62  *  <p><b>This is NOT part of any API supported by Sun Microsystems.
    64  *  <p><b>This is NOT part of any API supported by Sun Microsystems.
  1274                     + "arguments={1}, {2}";
  1276                     + "arguments={1}, {2}";
  1275                 return MessageFormat.format(msg, (Object[]) args);
  1277                 return MessageFormat.format(msg, (Object[]) args);
  1276             }
  1278             }
  1277         }
  1279         }
  1278     }
  1280     }
  1279 
       
  1280     // Borrowed from DocletInvoker
       
  1281     /**
       
  1282      * Utility method for converting a search path string to an array
       
  1283      * of directory and JAR file URLs.
       
  1284      *
       
  1285      * @param path the search path string
       
  1286      * @return the resulting array of directory and JAR file URLs
       
  1287      */
       
  1288     static URL[] pathToURLs(String path) {
       
  1289         StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
       
  1290         URL[] urls = new URL[st.countTokens()];
       
  1291         int count = 0;
       
  1292         while (st.hasMoreTokens()) {
       
  1293             URL url = fileToURL(new File(st.nextToken()));
       
  1294             if (url != null) {
       
  1295                 urls[count++] = url;
       
  1296             }
       
  1297         }
       
  1298         if (urls.length != count) {
       
  1299             URL[] tmp = new URL[count];
       
  1300             System.arraycopy(urls, 0, tmp, 0, count);
       
  1301             urls = tmp;
       
  1302         }
       
  1303         return urls;
       
  1304     }
       
  1305 
       
  1306     /**
       
  1307      * Returns the directory or JAR file URL corresponding to the specified
       
  1308      * local file name.
       
  1309      *
       
  1310      * @param file the File object
       
  1311      * @return the resulting directory or JAR file URL, or null if unknown
       
  1312      */
       
  1313     static URL fileToURL(File file) {
       
  1314         String name;
       
  1315         try {
       
  1316             name = file.getCanonicalPath();
       
  1317         } catch (IOException e) {
       
  1318             name = file.getAbsolutePath();
       
  1319         }
       
  1320         name = name.replace(File.separatorChar, '/');
       
  1321         if (!name.startsWith("/")) {
       
  1322             name = "/" + name;
       
  1323         }
       
  1324         // If the file does not exist, then assume that it's a directory
       
  1325         if (!file.isFile()) {
       
  1326             name = name + "/";
       
  1327         }
       
  1328         try {
       
  1329             return new URL("file", "", name);
       
  1330         } catch (MalformedURLException e) {
       
  1331             throw new IllegalArgumentException("file");
       
  1332         }
       
  1333     }
       
  1334 }
  1281 }