public Maven2ServerIndexerImpl() throws RemoteException {
    myEmbedder = Maven2ServerEmbedderImpl.create(new MavenServerSettings());

    myIndexer = myEmbedder.getComponent(NexusIndexer.class);
    myUpdater = myEmbedder.getComponent(IndexUpdater.class);
    myArtifactContextProducer = myEmbedder.getComponent(ArtifactContextProducer.class);

    ShutDownTracker.getInstance()
        .registerShutdownTask(
            new Runnable() {
              @Override
              public void run() {
                release();
              }
            });
  }
  public void updateIndex(
      int id, MavenServerSettings settings, MavenServerProgressIndicator indicator)
      throws MavenServerIndexerException, MavenServerProcessCanceledException, RemoteException {
    IndexingContext index = getIndex(id);

    try {
      if (isLocal(index)) {
        File repository = index.getRepository();

        if (repository != null && repository.exists()) {
          indicator.setIndeterminate(true);
          try {
            myIndexer.scan(index, new MyScanningListener(indicator), false);
          } finally {
            indicator.setIndeterminate(false);
          }
        }
      } else {
        IndexUpdateRequest request = new IndexUpdateRequest(index);
        Maven2ServerEmbedderImpl embedder = Maven2ServerEmbedderImpl.create(settings);
        try {
          request.setResourceFetcher(
              new Maven2ServerIndexFetcher(
                  index.getRepositoryId(),
                  index.getRepositoryUrl(),
                  embedder.getComponent(WagonManager.class),
                  new TransferListenerAdapter(indicator) {
                    @Override
                    protected void downloadProgress(long downloaded, long total) {
                      super.downloadProgress(downloaded, total);
                      try {
                        myIndicator.setFraction(((double) downloaded) / total);
                      } catch (RemoteException e) {
                        throw new RuntimeRemoteException(e);
                      }
                    }

                    @Override
                    public void transferCompleted(TransferEvent event) {
                      super.transferCompleted(event);
                      try {
                        myIndicator.setText2("Processing indices...");
                      } catch (RemoteException e) {
                        throw new RuntimeRemoteException(e);
                      }
                    }
                  }));
          myUpdater.fetchAndUpdateIndex(request);
        } finally {
          embedder.release();
        }
      }
    } catch (RuntimeRemoteException e) {
      throw e.getCause();
    } catch (ProcessCanceledException e) {
      throw new MavenServerProcessCanceledException();
    } catch (Exception e) {
      throw new MavenServerIndexerException(wrapException(e));
    }
  }
  private void doCollectArchetypes(String roleHint, Set<MavenArchetype> result)
      throws RemoteException {
    try {
      ArchetypeDataSource source = myEmbedder.getComponent(ArchetypeDataSource.class, roleHint);
      ArchetypeCatalog catalog = source.getArchetypeCatalog(new Properties());

      for (Archetype each : (Iterable<? extends Archetype>) catalog.getArchetypes()) {
        result.add(Maven2ModelConverter.convertArchetype(each));
      }
    } catch (ArchetypeDataSourceException e) {
      Maven2ServerGlobals.getLogger().warn(e);
    }
  }