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;
 }
  Map<String, Object> retrieveContext(MavenSession session) {
    Map<String, Object> context = null;

    if (session != null) {
      PluginDescriptor desc = new PluginDescriptor();
      desc.setGroupId(PluginDescriptor.getDefaultPluginGroupId());
      desc.setArtifactId(PluginDescriptor.getDefaultPluginArtifactId("toolchains"));

      MavenProject current = session.getCurrentProject();

      if (current != null) {
        // TODO: why is this using the context
        context = session.getPluginContext(desc, current);
      }
    }

    return (context != null) ? context : new HashMap<String, Object>();
  }
  /**
   * @return
   * @throws Exception
   */
  private Set<Artifact> getExtraJars() throws Exception {
    Set<Artifact> extraJars = new HashSet<Artifact>();

    List l = pluginArtifacts;
    Artifact pluginArtifact = null;

    if (l != null) {
      Iterator itor = l.iterator();
      while (itor.hasNext() && pluginArtifact == null) {
        Artifact a = (Artifact) itor.next();
        if (a.getArtifactId().equals(plugin.getArtifactId())) // get the jetty-maven-plugin jar
        {
          extraJars.add(a);
        }
      }
    }

    return extraJars;
  }
  @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();
    }
  }