コード例 #1
0
 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();
  }
コード例 #3
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;
 }
コード例 #4
0
 /**
  * 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);
 }
コード例 #5
0
 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;
 }
コード例 #6
0
  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;
  }
コード例 #7
0
ファイル: Project.java プロジェクト: sveryovka/polyglot-maven
  public Model toMavenModel() {
    Model model = new Model();
    model.setBuild(new Build());
    model.setDescription(description);
    model.setUrl(url);
    model.setName(projectId.getArtifact());
    model.setGroupId(projectId.getGroup());
    model.setVersion(projectId.getVersion());
    model.setArtifactId(projectId.getArtifact());
    model.setModelVersion("4.0.0");

    // parent
    if (parent != null) {
      model.setParent(parent);
    }

    model.setPackaging(packaging);

    if (properties != null) {
      Properties modelProperties = new Properties();
      for (Property p : properties) {
        modelProperties.setProperty(p.getKey(), p.getValue());
      }
      model.setProperties(modelProperties);
    }

    // Add jar repository urls.
    if (null != repositories) {
      for (String repoUrl : repositories.getRepositories()) {
        Repository repository = new Repository();
        repository.setId(Integer.toString(repoUrl.hashCode()));
        repository.setUrl(repoUrl);
        model.addRepository(repository);
      }
    }

    // Add dependency management
    if (overrides != null) {
      DependencyManagement depMan = new DependencyManagement();
      for (Id dep : overrides) {
        Dependency dependency = new Dependency();
        dependency.setGroupId(dep.getGroup());
        dependency.setArtifactId(dep.getArtifact());
        dependency.setVersion(dep.getVersion());
        // JVZ: We need to parse these
        dependency.setType("jar");

        if (null != dep.getClassifier()) {
          dependency.setClassifier(dep.getClassifier());
        }
        depMan.addDependency(dependency);
      }
      model.setDependencyManagement(depMan);
    }

    // Add project dependencies.
    if (deps != null) {
      for (Id dep : deps) {
        Dependency dependency = new Dependency();
        dependency.setGroupId(dep.getGroup());
        dependency.setArtifactId(dep.getArtifact());
        dependency.setVersion(dep.getVersion());
        // JVZ: We need to parse these
        dependency.setType("jar");

        if (null != dep.getClassifier()) {
          dependency.setClassifier(dep.getClassifier());
        }
        model.addDependency(dependency);
      }
    }

    if (modules != null) {
      model.setModules(modules);
    }

    if (pluginOverrides != null) {
      PluginManagement management = new PluginManagement();
      management.setPlugins(pluginOverrides);
      model.getBuild().setPluginManagement(management);
    }

    if (plugins != null) {
      model.getBuild().setPlugins(plugins);
    }

    // Optional source dirs customization.
    if (dirs != null) {
      Build build = new Build();
      String srcDir = dirs.get("src");
      String testDir = dirs.get("test");

      if (null != srcDir) build.setSourceDirectory(srcDir);

      if (null != testDir) build.setTestSourceDirectory(testDir);

      model.setBuild(build);
    }

    if (null != scm) {
      Scm scm = new Scm();
      scm.setConnection(this.scm.getConnection());
      scm.setDeveloperConnection(this.scm.getDeveloperConnection());
      scm.setUrl(this.scm.getUrl());

      model.setScm(scm);
    }

    return model;
  }