コード例 #1
0
  /**
   * Compare the list of selected dependencies against the selected targetPOM. If one of the
   * dependencies is already under dependencyManagement, but has a different version than the
   * selected dependency, warn the user about this. returns true if the user has been warned (but
   * this method updates the status itself)
   *
   * @param model
   * @param dependencies
   */
  protected boolean checkDependencies(
      org.apache.maven.model.Model model, LinkedList<Dependency> dependencies) {
    if (this.status != null && this.status.getCode() == IStatus.ERROR) {
      // Don't warn the user if there is already an error
      return false;
    }
    if (model == null
        || model.getDependencyManagement() == null
        || model.getDependencyManagement().getDependencies() == null
        || model.getDependencyManagement().getDependencies().isEmpty()) {
      return false;
    }

    for (Dependency selectedDep : dependencies) {
      for (org.apache.maven.model.Dependency targetDep :
          model.getDependencyManagement().getDependencies()) {
        if (selectedDep.getGroupId().equals(targetDep.getGroupId())
            && selectedDep.getArtifactId().equals(targetDep.getArtifactId())
            && !selectedDep.getVersion().equals(targetDep.getVersion())) {
          String modelID =
              model.getGroupId()
                  + ":"
                  + model.getArtifactId()
                  + ":"
                  + model.getVersion(); // $NON-NLS-1$ //$NON-NLS-2$
          if (targetDep.getLocation("") != null
              && targetDep.getLocation("").getSource() != null) { // $NON-NLS-1$ //$NON-NLS-2$
            modelID = targetDep.getLocation("").getSource().getModelId(); // $NON-NLS-1$
          }
          Object[] arguments = {
            selectedDep.getArtifactId() + "-" + selectedDep.getVersion(), // $NON-NLS-1$
            targetDep.getVersion(),
            modelID
          };
          String message =
              NLS.bind(Messages.ManageDependenciesDialog_dependencyExistsWarning, arguments);
          updateStatus(new Status(IStatus.WARNING, MavenEditorPlugin.PLUGIN_ID, message));
          return true;
        }
      }
    }
    return false;
  }
コード例 #2
0
 static InputLocation findLocationForManagedArtifact(
     final ManagedArtifactRegion region, MavenProject mavprj) {
   Model mdl = mavprj.getModel();
   InputLocation openLocation = null;
   if (region.isDependency) {
     DependencyManagement dm = mdl.getDependencyManagement();
     if (dm != null) {
       List<Dependency> list = dm.getDependencies();
       String id = region.groupId + ":" + region.artifactId + ":"; // $NON-NLS-1$ //$NON-NLS-2$
       if (list != null) {
         for (Dependency dep : list) {
           if (dep.getManagementKey().startsWith(id)) {
             InputLocation location = dep.getLocation(ARTIFACT_ID); // $NON-NLS-1$
             // when would this be null?
             if (location != null) {
               openLocation = location;
               break;
             }
           }
         }
       }
     }
   }
   if (region.isPlugin) {
     Build build = mdl.getBuild();
     if (build != null) {
       PluginManagement pm = build.getPluginManagement();
       if (pm != null) {
         List<Plugin> list = pm.getPlugins();
         String id = Plugin.constructKey(region.groupId, region.artifactId);
         if (list != null) {
           for (Plugin plg : list) {
             if (id.equals(plg.getKey())) {
               InputLocation location = plg.getLocation(ARTIFACT_ID); // $NON-NLS-1$
               // when would this be null?
               if (location != null) {
                 openLocation = location;
                 break;
               }
             }
           }
         }
       }
     }
   }
   return openLocation;
 }