private void validateConfiguration(ComponentSetDescriptor componentSetDescriptor)
      throws ComponentDescriptorCreatorException {
    List dependencies = componentSetDescriptor.getDependencies();

    if (dependencies == null) {
      return;
    }

    for (Iterator it = dependencies.iterator(); it.hasNext(); ) {
      ComponentDependency dependency = (ComponentDependency) it.next();

      if (StringUtils.isEmpty(dependency.getGroupId())) {
        throw new ComponentDescriptorCreatorException("Missing dependency element: 'groupId'.");
      }

      if (StringUtils.isEmpty(dependency.getArtifactId())) {
        throw new ComponentDescriptorCreatorException("Missing dependency element: 'artifactId'.");
      }

      if (StringUtils.isEmpty(dependency.getVersion())) {
        throw new ComponentDescriptorCreatorException("Missing dependency element: 'version'.");
      }

      if (StringUtils.isEmpty(dependency.getType())) {
        throw new ComponentDescriptorCreatorException("Missing dependency element: 'type'.");
      }
    }
  }
 protected boolean isTychoP2Plugin(PluginDescriptor pluginDescriptor) {
   if (pluginDescriptor.getArtifactMap().containsKey("org.eclipse.tycho:tycho-p2-facade")) {
     return true;
   }
   for (ComponentDependency dependency : pluginDescriptor.getDependencies()) {
     if ("org.eclipse.tycho".equals(dependency.getGroupId())
         && "tycho-p2-facade".equals(dependency.getArtifactId())) {
       return true;
     }
   }
   return false;
 }
Example #3
0
  public static ComponentSetDescriptor buildComponentSet(PlexusConfiguration c) throws Exception {
    ComponentSetDescriptor csd = new ComponentSetDescriptor();

    // ----------------------------------------------------------------------
    // Components
    // ----------------------------------------------------------------------

    PlexusConfiguration[] components = c.getChild("components").getChildren("component");

    for (int i = 0; i < components.length; i++) {
      PlexusConfiguration component = components[i];

      csd.addComponentDescriptor(buildComponentDescriptor(component));
    }

    // ----------------------------------------------------------------------
    // Dependencies
    // ----------------------------------------------------------------------

    PlexusConfiguration[] dependencies = c.getChild("dependencies").getChildren("dependency");

    for (int i = 0; i < dependencies.length; i++) {
      PlexusConfiguration d = dependencies[i];

      ComponentDependency cd = new ComponentDependency();

      cd.setArtifactId(d.getChild("artifact-id").getValue());

      cd.setGroupId(d.getChild("group-id").getValue());

      cd.setType(d.getChild("type").getValue());

      cd.setVersion(d.getChild("version").getValue());

      csd.addDependency(cd);
    }

    return csd;
  }
  private void writeDependencyElement(ComponentDependency dependency, XMLWriter w) {
    w.startElement("dependency");

    String groupId = dependency.getGroupId();

    element(w, "groupId", groupId);

    String artifactId = dependency.getArtifactId();

    element(w, "artifactId", artifactId);

    String type = dependency.getType();

    if (type != null) {
      element(w, "type", type);
    }

    String version = dependency.getVersion();

    element(w, "version", version);

    w.endElement();
  }
  @Override
  public Collection<MavenArtifact> resolvePlugin(
      @NotNull MavenPlugin plugin,
      @NotNull List<MavenRemoteRepository> repositories,
      int nativeMavenProjectId,
      boolean transitive)
      throws RemoteException, MavenServerProcessCanceledException {
    try {
      Plugin mavenPlugin = new Plugin();
      mavenPlugin.setGroupId(plugin.getGroupId());
      mavenPlugin.setArtifactId(plugin.getArtifactId());
      mavenPlugin.setVersion(plugin.getVersion());
      MavenProject project = RemoteNativeMavenProjectHolder.findProjectById(nativeMavenProjectId);

      MavenExecutionRequest request =
          createRequest(
              null,
              Collections.<String>emptyList(),
              Collections.<String>emptyList(),
              Collections.<String>emptyList());

      DefaultMaven maven = (DefaultMaven) getComponent(Maven.class);
      RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);

      if (plugin.getVersion() == null) {
        PluginVersionRequest versionRequest =
            new DefaultPluginVersionRequest(
                mavenPlugin, repositorySystemSession, project.getRemotePluginRepositories());
        mavenPlugin.setVersion(
            getComponent(PluginVersionResolver.class).resolve(versionRequest).getVersion());
      }

      PluginDescriptor result =
          getComponent(MavenPluginManager.class)
              .getPluginDescriptor(
                  mavenPlugin, project.getRemotePluginRepositories(), repositorySystemSession);

      Map<MavenArtifactInfo, MavenArtifact> resolvedArtifacts =
          new THashMap<MavenArtifactInfo, MavenArtifact>();

      Artifact pluginArtifact = result.getPluginArtifact();

      MavenArtifactInfo artifactInfo =
          new MavenArtifactInfo(
              pluginArtifact.getGroupId(),
              pluginArtifact.getArtifactId(),
              pluginArtifact.getVersion(),
              pluginArtifact.getType(),
              null);

      resolveIfNecessary(artifactInfo, repositories, resolvedArtifacts);

      if (transitive) {
        // todo try to use parallel downloading
        for (Artifact each : result.getIntroducedDependencyArtifacts()) {
          resolveIfNecessary(
              new MavenArtifactInfo(
                  each.getGroupId(), each.getArtifactId(), each.getVersion(), each.getType(), null),
              repositories,
              resolvedArtifacts);
        }
        for (ComponentDependency each : result.getDependencies()) {
          resolveIfNecessary(
              new MavenArtifactInfo(
                  each.getGroupId(), each.getArtifactId(), each.getVersion(), each.getType(), null),
              repositories,
              resolvedArtifacts);
        }
      }

      return new THashSet<MavenArtifact>(resolvedArtifacts.values());
    } catch (Exception e) {
      Maven3ServerGlobals.getLogger().info(e);
      return Collections.emptyList();
    }
  }