public DiscoveryResponse discoverLatestVersion(DiscoveryRequest req)
      throws NoSuchRepositoryException, IOException {
    CLvoKey info = req.getLvoKey();

    IndexingContext localContext =
        indexerManager.getRepositoryLocalIndexContext(info.getRepositoryId());
    IndexingContext remoteContext =
        indexerManager.getRepositoryRemoteIndexContext(info.getRepositoryId());

    BooleanQuery bq = new BooleanQuery();
    bq.add(indexerManager.constructQuery(ArtifactInfo.GROUP_ID, info.getGroupId()), Occur.MUST);
    bq.add(
        indexerManager.constructQuery(ArtifactInfo.ARTIFACT_ID, info.getArtifactId()), Occur.MUST);

    // to have sorted results by version in descending order
    FlatSearchRequest sreq = new FlatSearchRequest(bq, ArtifactInfo.REPOSITORY_VERSION_COMPARATOR);

    sreq.getContexts().add(localContext);

    sreq.getContexts().add(remoteContext);

    FlatSearchResponse hits = indexerManager.getNexusIndexer().searchFlat(sreq);

    DiscoveryResponse response = new DiscoveryResponse(req);

    if (hits.getTotalHits() > 0) {
      // found it, they are sorted in descending order, so the 1st one is the newest
      response.setVersion(hits.getResults().iterator().next().version);

      response.setSuccessful(true);
    }

    return response;
  }
Beispiel #2
0
  public void testHostedRepositoryReindex() throws Exception {
    fillInRepo();

    indexerManager.reindexRepository(null, "releases", true);

    validateIndexWithIdentify(
        true,
        "86e12071021fa0be4ec809d4d2e08f07b80d4877",
        "org.sonatype.nexus",
        "nexus-indexer",
        "1.0-beta-4");
  }
Beispiel #3
0
  public void testProxyRepositoryReindex() throws Exception {
    fillInRepo();

    reindexRemoteRepositoryAndPublish(getRemoteRepositoryRoot("central"), "central", true, 0);

    makeCentralPointTo(
        "http://localhost:"
            + super.getContainer().getContext().get(PROXY_SERVER_PORT)
            + "/central/");

    indexerManager.reindexRepository(null, "central", true);

    validateIndexWithIdentify(
        true, "057b8740427ee6d7b0b60792751356cad17dc0d9", "log4j", "log4j", "1.2.12");
  }
Beispiel #4
0
  protected void validateIndexWithIdentify(
      boolean shouldBePresent, String sha1Hash, String gid, String aid, String version)
      throws Exception {
    ArtifactInfo ai = indexerManager.identifyArtifact(ArtifactInfo.SHA1, sha1Hash);

    if (shouldBePresent) {
      assertNotNull("Should find " + gid + ":" + aid + ":" + version, ai);

      assertEquals(gid, ai.groupId);
      assertEquals(aid, ai.artifactId);
      assertEquals(version, ai.version);
    } else {
      assertNull("Should not find " + gid + ":" + aid + ":" + version, ai);
    }
  }
Beispiel #5
0
  public void testV1IncrementalIndexes() throws Exception {
    // day 1
    makeCentralPointTo(
        "http://localhost:"
            + super.getContainer().getContext().get(PROXY_SERVER_PORT)
            + "/central-inc1-v1/");

    indexerManager.reindexRepository(null, "central", true);

    // validation
    validateIndexWithIdentify(
        true, "cf4f67dae5df4f9932ae7810f4548ef3e14dd35e", "antlr", "antlr", "2.7.6");
    validateIndexWithIdentify(
        false, "83cd2cd674a217ade95a4bb83a8a14f351f48bd0", "antlr", "antlr", "2.7.7");

    validateIndexWithIdentify(
        true, "3640dd71069d7986c9a14d333519216f4ca5c094", "log4j", "log4j", "1.2.8");
    validateIndexWithIdentify(
        false, "057b8740427ee6d7b0b60792751356cad17dc0d9", "log4j", "log4j", "1.2.12");
    validateIndexWithIdentify(
        false, "f0a0d2e29ed910808c33135a3a5a51bba6358f7b", "log4j", "log4j", "1.2.15");

    // day 2
    makeCentralPointTo(
        "http://localhost:"
            + super.getContainer().getContext().get(PROXY_SERVER_PORT)
            + "/central-inc2-v1/");

    indexerManager.reindexRepository(null, "central", true);

    // validation
    validateIndexWithIdentify(
        true, "cf4f67dae5df4f9932ae7810f4548ef3e14dd35e", "antlr", "antlr", "2.7.6");
    validateIndexWithIdentify(
        true, "83cd2cd674a217ade95a4bb83a8a14f351f48bd0", "antlr", "antlr", "2.7.7");

    validateIndexWithIdentify(
        true, "3640dd71069d7986c9a14d333519216f4ca5c094", "log4j", "log4j", "1.2.8");
    validateIndexWithIdentify(
        true, "057b8740427ee6d7b0b60792751356cad17dc0d9", "log4j", "log4j", "1.2.12");
    validateIndexWithIdentify(
        false, "f0a0d2e29ed910808c33135a3a5a51bba6358f7b", "log4j", "log4j", "1.2.15");

    // day 3
    makeCentralPointTo(
        "http://localhost:"
            + super.getContainer().getContext().get(PROXY_SERVER_PORT)
            + "/central-inc3-v1/");

    indexerManager.reindexRepository(null, "central", true);

    // validation
    validateIndexWithIdentify(
        true, "cf4f67dae5df4f9932ae7810f4548ef3e14dd35e", "antlr", "antlr", "2.7.6");
    validateIndexWithIdentify(
        true, "83cd2cd674a217ade95a4bb83a8a14f351f48bd0", "antlr", "antlr", "2.7.7");

    validateIndexWithIdentify(
        true, "3640dd71069d7986c9a14d333519216f4ca5c094", "log4j", "log4j", "1.2.8");
    validateIndexWithIdentify(
        true, "057b8740427ee6d7b0b60792751356cad17dc0d9", "log4j", "log4j", "1.2.12");
    validateIndexWithIdentify(
        true, "f0a0d2e29ed910808c33135a3a5a51bba6358f7b", "log4j", "log4j", "1.2.15");
  }
Beispiel #6
0
  public void testCurrentIncrementalIndexes() throws Exception {
    // day 1
    reindexRemoteRepositoryAndPublish(getRemoteRepositoryRoot("central-inc1"), "central", false, 0);

    makeCentralPointTo(
        "http://localhost:"
            + super.getContainer().getContext().get(PROXY_SERVER_PORT)
            + "/central-inc1/");

    indexerManager.reindexRepository(null, "central", true);

    // validation
    validateIndexWithIdentify(
        true, "cf4f67dae5df4f9932ae7810f4548ef3e14dd35e", "antlr", "antlr", "2.7.6");
    validateIndexWithIdentify(
        false, "83cd2cd674a217ade95a4bb83a8a14f351f48bd0", "antlr", "antlr", "2.7.7");

    validateIndexWithIdentify(
        true, "3640dd71069d7986c9a14d333519216f4ca5c094", "log4j", "log4j", "1.2.8");
    validateIndexWithIdentify(
        false, "057b8740427ee6d7b0b60792751356cad17dc0d9", "log4j", "log4j", "1.2.12");
    validateIndexWithIdentify(
        false, "f0a0d2e29ed910808c33135a3a5a51bba6358f7b", "log4j", "log4j", "1.2.15");

    // day 2 (1 day passed), so shift both ctxes "in time"
    reindexRemoteRepositoryAndPublish(
        getRemoteRepositoryRoot("central-inc2"), "central", false, -1);
    shiftContextInTime(indexerManager.getRepositoryRemoteIndexContext("central"), -1);

    makeCentralPointTo(
        "http://localhost:"
            + super.getContainer().getContext().get(PROXY_SERVER_PORT)
            + "/central-inc2/");

    indexerManager.reindexRepository(null, "central", true);

    // validation
    validateIndexWithIdentify(
        true, "cf4f67dae5df4f9932ae7810f4548ef3e14dd35e", "antlr", "antlr", "2.7.6");
    validateIndexWithIdentify(
        true, "83cd2cd674a217ade95a4bb83a8a14f351f48bd0", "antlr", "antlr", "2.7.7");

    validateIndexWithIdentify(
        true, "3640dd71069d7986c9a14d333519216f4ca5c094", "log4j", "log4j", "1.2.8");
    validateIndexWithIdentify(
        true, "057b8740427ee6d7b0b60792751356cad17dc0d9", "log4j", "log4j", "1.2.12");
    validateIndexWithIdentify(
        false, "f0a0d2e29ed910808c33135a3a5a51bba6358f7b", "log4j", "log4j", "1.2.15");

    // day 3
    reindexRemoteRepositoryAndPublish(
        getRemoteRepositoryRoot("central-inc3"), "central", false, -1);
    shiftContextInTime(indexerManager.getRepositoryRemoteIndexContext("central"), -1);

    makeCentralPointTo(
        "http://localhost:"
            + super.getContainer().getContext().get(PROXY_SERVER_PORT)
            + "/central-inc3/");

    indexerManager.reindexRepository(null, "central", true);

    // validation
    validateIndexWithIdentify(
        true, "cf4f67dae5df4f9932ae7810f4548ef3e14dd35e", "antlr", "antlr", "2.7.6");
    validateIndexWithIdentify(
        true, "83cd2cd674a217ade95a4bb83a8a14f351f48bd0", "antlr", "antlr", "2.7.7");

    validateIndexWithIdentify(
        true, "3640dd71069d7986c9a14d333519216f4ca5c094", "log4j", "log4j", "1.2.8");
    validateIndexWithIdentify(
        true, "057b8740427ee6d7b0b60792751356cad17dc0d9", "log4j", "log4j", "1.2.12");
    validateIndexWithIdentify(
        true, "f0a0d2e29ed910808c33135a3a5a51bba6358f7b", "log4j", "log4j", "1.2.15");
  }