private Map<String, Artifact> createManagedVersionMap() throws MojoExecutionException {
   Map<String, Artifact> map = new HashMap<String, Artifact>();
   DependencyManagement dependencyManagement = project.getDependencyManagement();
   if (dependencyManagement != null && dependencyManagement.getDependencies() != null) {
     for (Dependency d : dependencyManagement.getDependencies()) {
       try {
         VersionRange versionRange = VersionRange.createFromVersionSpec(d.getVersion());
         Artifact artifact =
             artifactFactory.createDependencyArtifact(
                 d.getGroupId(),
                 d.getArtifactId(),
                 versionRange,
                 d.getType(),
                 d.getClassifier(),
                 d.getScope(),
                 d.isOptional());
         handleExclusions(artifact, d);
         map.put(d.getManagementKey(), artifact);
       } catch (InvalidVersionSpecificationException e) {
         throw new MojoExecutionException(
             String.format(
                 "%1s: unable to parse version '%2s' for dependency '%3s': %4s",
                 project.getId(), d.getVersion(), d.getManagementKey(), e.getMessage()),
             e);
       }
     }
   }
   return map;
 }
예제 #2
0
  public Iterable<Dependency> getManagedDependencies(final ModelBase base) {
    final DependencyManagement dm = base.getDependencyManagement();
    if (dm == null || dm.getDependencies() == null) {
      return Collections.emptyList();
    }

    return dm.getDependencies();
  }
 /**
  * Adds dependency management information.
  *
  * @param pomDescriptor The descriptor for the current POM.
  * @param dependencyManagement The dependency management information.
  * @param scannerContext The scanner context.
  */
 private void addManagedDependencies(
     MavenDependentDescriptor pomDescriptor,
     DependencyManagement dependencyManagement,
     ScannerContext scannerContext,
     Class<? extends BaseDependencyDescriptor> relationClass) {
   if (null == dependencyManagement) {
     return;
   }
   List<Dependency> dependencies = dependencyManagement.getDependencies();
   addDependencies(pomDescriptor, dependencies, relationClass, scannerContext);
 }
 private boolean pomUsesSwitchYardBOM() {
   final MavenProject project = _switchYardProject.getMavenProject();
   DependencyManagement depMgmt = null;
   if (project != null && project.getOriginalModel() != null) {
     final Model originalModel = project.getOriginalModel();
     depMgmt = originalModel.getDependencyManagement();
   } else if (project != null && project.getModel() != null) {
     final Model originalModel = project.getOriginalModel();
     depMgmt = originalModel.getDependencyManagement();
   }
   if (depMgmt != null && !depMgmt.getDependencies().isEmpty()) {
     Iterator<Dependency> depIter = depMgmt.getDependencies().iterator();
     while (depIter.hasNext()) {
       Dependency tempDep = depIter.next();
       if (tempDep.getArtifactId().equals(M2EUtils.SWITCHYARD_BOM_ARTIFACT_ID)) {
         return true;
         //                } else if (tempDep.getArtifactId().equals("fuse-integration-bom")) {
         //                    return true;
       }
     }
   }
   return false;
 }
  private Map createManagedVersionMap(
      ArtifactFactory artifactFactory, String projectId, DependencyManagement dependencyManagement)
      throws MojoExecutionException {
    Map map;
    if (dependencyManagement != null && dependencyManagement.getDependencies() != null) {
      map = new HashMap();
      for (Iterator i = dependencyManagement.getDependencies().iterator(); i.hasNext(); ) {
        Dependency d = (Dependency) i.next();

        try {
          VersionRange versionRange = VersionRange.createFromVersionSpec(d.getVersion());
          Artifact artifact =
              artifactFactory.createDependencyArtifact(
                  d.getGroupId(),
                  d.getArtifactId(),
                  versionRange,
                  d.getType(),
                  d.getClassifier(),
                  d.getScope(),
                  d.isOptional());
          map.put(d.getManagementKey(), artifact);
        } catch (InvalidVersionSpecificationException e) {
          throw new MojoExecutionException(
              Messages.getString(
                  "unabletoparseversion",
                  new Object[] { // $NON-NLS-1$
                    projectId, d.getVersion(), d.getManagementKey(), e.getMessage()
                  }),
              e);
        }
      }
    } else {
      map = Collections.EMPTY_MAP;
    }
    return map;
  }
 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;
 }