Example #1
0
 /**
  * converts an InputLocation to a file path on the local disk, null if not available. still the
  * input source's model value can be used further..
  *
  * @param location
  * @return
  */
 public static File fileForInputLocation(InputLocation location, MavenProject origin) {
   InputSource source = location.getSource();
   if (source != null) {
     // MNGECLIPSE-2539 apparently if maven can't resolve the model from local storage,
     // the location will be empty. not only applicable to local repo models but
     // apparently also to models in workspace not reachable by relativePath
     String loc = source.getLocation();
     File file = null;
     if (loc != null) {
       file = new File(loc);
     } else {
       // try to find pom by coordinates..
       String modelId = source.getModelId();
       if (origin.getModel().getId().equals(modelId) && origin.getFile() != null) {
         return origin.getFile();
       }
       String[] splitStrings = modelId.split(":");
       assert splitStrings.length == 3;
       IMavenProjectFacade facade =
           MavenPlugin.getMavenProjectRegistry()
               .getMavenProject(splitStrings[0], splitStrings[1], splitStrings[2]);
       if (facade != null) {
         file = facade.getPomFile();
       } else {
         // if not in the workspace, try looking into the local repository.
         IMaven maven = MavenPlugin.getMaven();
         try {
           String path =
               maven.getArtifactPath(
                   maven.getLocalRepository(),
                   splitStrings[0],
                   splitStrings[1],
                   splitStrings[2],
                   "pom",
                   null);
           if (path != null) {
             file = new File(maven.getLocalRepositoryPath(), path);
           }
         } catch (CoreException e) {
           log.error("Failed to calculate local repository path of artifact", e);
         }
       }
     }
     return file;
   }
   return null;
 }