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));
    }
  }
 public void releaseIndex(int id) throws MavenServerIndexerException {
   try {
     myIndexer.removeIndexingContext(getIndex(id), false);
   } catch (Exception e) {
     throw new MavenServerIndexerException(wrapException(e));
   }
 }
 public static void addArtifact(
     NexusIndexer indexer, IndexingContext index, ArtifactContext artifactContext)
     throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
   indexer.addArtifactToIndex(artifactContext, index);
   // this hack is necessary to invalidate searcher's and reader's cache (may not be required then
   // lucene or nexus library change
   Method m = index.getClass().getDeclaredMethod("closeReaders");
   m.setAccessible(true);
   m.invoke(index);
 }
Ejemplo n.º 4
0
  /**
   * Will reindex, shift if needed and publish indexes for a "remote" repository (published over
   * jetty component).
   *
   * @param repositoryRoot
   * @param repositoryId
   * @param deleteIndexFiles
   * @param shiftDays
   * @throws IOException
   */
  protected void reindexRemoteRepositoryAndPublish(
      File repositoryRoot, String repositoryId, boolean deleteIndexFiles, int shiftDays)
      throws IOException, ComponentLookupException {
    File indexDirectory = getIndexFamilyDirectory(repositoryId);

    Directory directory = FSDirectory.getDirectory(indexDirectory);

    IndexingContext ctx =
        nexusIndexer.addIndexingContextForced(
            repositoryId + "-temp",
            repositoryId,
            repositoryRoot,
            directory,
            null,
            null,
            new IndexCreatorHelper(getContainer()).getFullCreators());

    // shifting if needed (very crude way to do it, but heh)
    shiftContextInTime(ctx, shiftDays);

    // and scan "today"
    nexusIndexer.scan(ctx);

    ctx.updateTimestamp(true);

    // pack it up
    File targetDir = new File(repositoryRoot, ".index");

    targetDir.mkdirs();

    IndexPackingRequest ipr = new IndexPackingRequest(ctx, targetDir);

    ipr.setCreateIncrementalChunks(true);

    indexPacker.packIndex(ipr);

    nexusIndexer.removeIndexingContext(ctx, deleteIndexFiles);
  }
 public int createIndex(
     @NotNull String indexId,
     @NotNull String repositoryId,
     @Nullable File file,
     @Nullable String url,
     @NotNull File indexDir)
     throws MavenServerIndexerException {
   try {
     IndexingContext context =
         myIndexer.addIndexingContextForced(
             indexId,
             repositoryId,
             file,
             indexDir,
             url,
             null, // repo update url
             NexusIndexer.FULL_INDEX);
     int id = System.identityHashCode(context);
     myIndices.put(id, context);
     return id;
   } catch (Exception e) {
     throw new MavenServerIndexerException(wrapException(e));
   }
 }
 public int getIndexCount() {
   return myIndexer.getIndexingContexts().size();
 }