Package org.sonatype.nexus.proxy.maven.maven2

Examples of org.sonatype.nexus.proxy.maven.maven2.M2LayoutedM1ShadowRepository


  }

  public StorageFileItem requestWithPolicy(ChecksumPolicy policy, String requestPath)
      throws Exception
  {
    M2Repository repo = getRepository();

    ResourceStoreRequest request = new ResourceStoreRequest(requestPath, false, false);

    repo.setChecksumPolicy(policy);
    repo.getCurrentCoreConfiguration().commitChanges();

    StorageFileItem item = (StorageFileItem) repo.retrieveItem(request);

    return item;
  }
View Full Code Here


  @Test
  public void testPoliciesWithRetrieve()
      throws Exception
  {
    M2Repository repository = (M2Repository) getResourceStore();

    // a "release"
    repository.setRepositoryPolicy(RepositoryPolicy.RELEASE);
    repository.getCurrentCoreConfiguration().commitChanges();

    StorageItem item = getResourceStore().retrieveItem(new ResourceStoreRequest(SPOOF_RELEASE, false));
    checkForFileAndMatchContents(item);

    try {
      item = getResourceStore().retrieveItem(new ResourceStoreRequest(SPOOF_SNAPSHOT, false));

      assertThat("Should not be able to get snapshot from release repo", false);
    }
    catch (ItemNotFoundException e) {
      // good
    }

    // reset NFC
    repository.expireCaches(new ResourceStoreRequest(RepositoryItemUid.PATH_ROOT, true));

    // a "snapshot"
    repository.setRepositoryPolicy(RepositoryPolicy.SNAPSHOT);
    repository.getCurrentCoreConfiguration().commitChanges();

    item = getResourceStore().retrieveItem(new ResourceStoreRequest(SPOOF_SNAPSHOT, false));
    checkForFileAndMatchContents(item);

    try {
View Full Code Here

  @Test
  public void testPoliciesWithStore()
      throws Exception
  {
    M2Repository repository = (M2Repository) getResourceStore();

    // a "release"
    repository.setRepositoryPolicy(RepositoryPolicy.RELEASE);
    repository.getCurrentCoreConfiguration().commitChanges();

    DefaultStorageFileItem item = new DefaultStorageFileItem(
        repository, new ResourceStoreRequest(SPOOF_RELEASE), true, true, new StringContentLocator(SPOOF_RELEASE)
    );

    repository.storeItem(false, item);

    try {
      item = new DefaultStorageFileItem(
          repository, new ResourceStoreRequest(SPOOF_SNAPSHOT), true, true, new StringContentLocator(SPOOF_SNAPSHOT)
      );

      repository.storeItem(false, item);

      assertThat("Should not be able to store snapshot to release repo", false);
    }
    catch (UnsupportedStorageOperationException e) {
      // good
    }

    // reset NFC
    repository.expireCaches(new ResourceStoreRequest(RepositoryItemUid.PATH_ROOT, true));

    // a "snapshot"
    repository.setRepositoryPolicy(RepositoryPolicy.SNAPSHOT);
    repository.getCurrentCoreConfiguration().commitChanges();

    item = new DefaultStorageFileItem(
        repository, new ResourceStoreRequest(SPOOF_SNAPSHOT), true, true, new StringContentLocator(SPOOF_SNAPSHOT)
    );

    repository.storeItem(false, item);

    try {
      item = new DefaultStorageFileItem(
          repository, new ResourceStoreRequest(SPOOF_RELEASE), true, true, new StringContentLocator(SPOOF_RELEASE)
      );

      repository.storeItem(false, item);

      assertThat("Should not be able to store release to snapshot repo", false);
    }
    catch (UnsupportedStorageOperationException e) {
      // good
View Full Code Here

  @Test
  public void testShouldServeByPolicies()
      throws Exception
  {
    M2Repository repository = (M2Repository) getResourceStore();

    String releasePom =
        "/org/codehaus/plexus/plexus-container-default/1.0-alpha-40/plexus-container-default-1.0-alpha-40.pom";
    String releaseArtifact =
        "/org/codehaus/plexus/plexus-container-default/1.0-alpha-40/plexus-container-default-1.0-alpha-40.jar";
    String snapshotPom =
        "/org/codehaus/plexus/plexus-container-default/1.0-alpha-41-SNAPSHOT/plexus-container-default-1.0-alpha-41-20071205.190351-1.pom";
    String snapshotArtifact =
        "/org/codehaus/plexus/plexus-container-default/1.0-alpha-41-SNAPSHOT/plexus-container-default-1.0-alpha-41-20071205.190351-1.jar";
    String metadata1 = "/org/codehaus/plexus/plexus-container-default/maven-metadata.xml";
    String metadataR = "/org/codehaus/plexus/plexus-container-default/1.0-alpha-40/maven-metadata.xml";
    String metadataS = "/org/codehaus/plexus/plexus-container-default/1.0-alpha-41-SNAPSHOT/maven-metadata.xml";
    String someDirectory = "/classworlds/";
    String anyNonArtifactFile = "/any/file.txt";

    ResourceStoreRequest request = new ResourceStoreRequest("");

    // it is equiv of repo type: RELEASE
    repository.setRepositoryPolicy(RepositoryPolicy.RELEASE);
    repository.getCurrentCoreConfiguration().commitChanges();

    request.setRequestPath(releasePom);
    assertThat(repository.shouldServeByPolicies(request), is(true));
    request.setRequestPath(releaseArtifact);
    assertThat(repository.shouldServeByPolicies(request), is(true));
    request.setRequestPath(snapshotPom);
    assertThat(repository.shouldServeByPolicies(request), is(false));
    request.setRequestPath(snapshotArtifact);
    assertThat(repository.shouldServeByPolicies(request), is(false));
    request.setRequestPath(metadata1);
    assertThat(repository.shouldServeByPolicies(request), is(true));
    request.setRequestPath(metadataR);
    assertThat(repository.shouldServeByPolicies(request), is(true));
    request.setRequestPath(metadataS);
    assertThat(repository.shouldServeByPolicies(request), is(false));
    request.setRequestPath(someDirectory);
    assertThat(repository.shouldServeByPolicies(request), is(true));
    request.setRequestPath(anyNonArtifactFile);
    assertThat(repository.shouldServeByPolicies(request), is(true));

    // it is equiv of repo type: SNAPSHOT
    repository.setRepositoryPolicy(RepositoryPolicy.SNAPSHOT);
    repository.getCurrentCoreConfiguration().commitChanges();

    request.setRequestPath(releasePom);
    assertThat(repository.shouldServeByPolicies(request), is(false));
    request.setRequestPath(releaseArtifact);
    assertThat(repository.shouldServeByPolicies(request), is(false));
    request.setRequestPath(snapshotPom);
    assertThat(repository.shouldServeByPolicies(request), is(true));
    request.setRequestPath(snapshotArtifact);
    assertThat(repository.shouldServeByPolicies(request), is(true));
    request.setRequestPath(metadata1);
    assertThat(repository.shouldServeByPolicies(request), is(true));
    request.setRequestPath(metadataR);
    assertThat(repository.shouldServeByPolicies(request), is(true));
    request.setRequestPath(metadataS);
    assertThat(repository.shouldServeByPolicies(request), is(true));
    request.setRequestPath(someDirectory);
    assertThat(repository.shouldServeByPolicies(request), is(true));
    request.setRequestPath(anyNonArtifactFile);
    assertThat(repository.shouldServeByPolicies(request), is(true));
  }
View Full Code Here

  @Test
  public void testGetLatestVersionSimple()
      throws Exception
  {
    M2Repository repository = (M2Repository) getResourceStore();

    List<String> versions = new ArrayList<String>();
    versions.add("1.0.0");
    versions.add("1.0.1");
    versions.add("1.0.2");
    versions.add("1.1.2");
    assertThat(repository.getLatestVersion(versions), is("1.1.2"));
  }
View Full Code Here

  @Test
  public void testGetLatestVersionClassifiers()
      throws Exception
  {
    M2Repository repository = (M2Repository) getResourceStore();

    List<String> versions = new ArrayList<String>();
    versions.add("1.0-alpha-19");
    versions.add("1.0-alpha-9-stable-1");
    versions.add("1.0-alpha-20");
    versions.add("1.0-alpha-21");
    versions.add("1.0-alpha-22");
    versions.add("1.0-alpha-40");
    assertThat(repository.getLatestVersion(versions), is("1.0-alpha-40"));
  }
View Full Code Here

  private void doTestExpiration(String path, final int age, final int... expectedHits)
      throws Exception
  {
    CounterListener ch = new CounterListener();

    M2Repository repository = (M2Repository) getResourceStore();

    eventBus().register(ch);

    File mdFile = new File(new File(getBasedir()), "target/test-classes/repo1" + path);
    long fileTimestamp = mdFile.lastModified();

    assertThat(mdFile, exists());

    try {
      repository.deleteItem(new ResourceStoreRequest("/spoof", true));
    }
    catch (ItemNotFoundException e) {
      // ignore
    }

    repository.setMetadataMaxAge(age);
    repository.setArtifactMaxAge(age);
    repository.getCurrentCoreConfiguration().commitChanges();

    for (int i = 0; i < 10 && !mdFile.setLastModified(System.currentTimeMillis() - (3L * A_DAY)); i++) {
      System.gc(); // helps with FS sync'ing on Windows
      Thread.sleep(500); // wait for FS
    }


    assertThat("File timestamp did not change, first pass", mdFile.lastModified(), not(equalTo(fileTimestamp)));
    fileTimestamp = mdFile.lastModified();

    // We need to wait a bit to avoid the check that last remote check = current time
    Thread.sleep(500);
    final StorageItem item = repository.retrieveItem(new ResourceStoreRequest(path, false));
    getLogger().info(
        path + " -> BEFORE assert 1 requestCount=" + expectedHits[0] + " at (" + System.currentTimeMillis() + ")");
    assertThat("Remote hits count fail after first request at (" + System.currentTimeMillis() + ")",
        ch.getRequestCount(), equalTo(expectedHits[0]));
    getLogger().info(
        path + " -> AFTER assert 1 requestCount=" + expectedHits[0] + " at (" + System.currentTimeMillis() + ")");

    for (int i = 0; i < 10 && !mdFile.setLastModified(System.currentTimeMillis() - (2L * A_DAY)); i++) {
      System.gc(); // helps with FS sync'ing on Windows
      Thread.sleep(500); // wait for FS
    }

    assertThat("File timestamp did not change, second pass", mdFile.lastModified(), not(equalTo(fileTimestamp)));
    fileTimestamp = mdFile.lastModified();

    // We need to wait a bit to avoid the check that last remote check = current time
    Thread.sleep(500);
    // this goes remote depending on age setting
    repository.retrieveItem(new ResourceStoreRequest(path, false));
    getLogger().info(
        path + " -> BEFORE assert 2 requestCount=" + expectedHits[1] + " at (" + System.currentTimeMillis() + ")");
    assertThat("Remote hits count fail after second request at (" + System.currentTimeMillis() + ")",
        ch.getRequestCount(), equalTo(expectedHits[1]));
    getLogger().info(
        path + " -> AFTER assert 2 requestCount=" + expectedHits[1] + " at (" + System.currentTimeMillis() + ")");

    for (int i = 0; i < 10 && !mdFile.setLastModified(System.currentTimeMillis() - (1L * A_DAY)); i++) {
      System.gc(); // helps with FS sync'ing on Windows
      Thread.sleep(500); // wait for FS
    }

    assertThat("File timestamp did not change, third pass", mdFile.lastModified(), not(equalTo(fileTimestamp)));
    fileTimestamp = mdFile.lastModified();

    // set up last checked timestamp so that nexus should go remote
    final RepositoryItemUid uid = item.getRepositoryItemUid();
    final AttributeStorage storage = uid.getRepository().getAttributesHandler().getAttributeStorage();
    final Attributes attributes = item.getRepositoryItemAttributes();
    attributes.setCheckedRemotely(System.currentTimeMillis() - ((Math.abs(age) + 1) * 60 * 1000));
    storage.putAttributes(uid, attributes);

    // We need to wait a bit to avoid the check that last remote check = current time
    Thread.sleep(500);
    repository.retrieveItem(new ResourceStoreRequest(path, false));
    getLogger().info(
        path + " -> BEFORE assert 3 requestCount=" + expectedHits[2] + " at (" + System.currentTimeMillis() + ")");
    assertThat("Remote hits count fail after third request at (" + System.currentTimeMillis() + ")",
        ch.getRequestCount(), equalTo(expectedHits[2]));
    getLogger().info(
View Full Code Here

  @Test
  public void testLocalStorageChanges()
      throws Exception
  {
    M2Repository repository = (M2Repository) getResourceStore();

    String changedUrl = repository.getLocalUrl() + "foo";

    repository.setLocalUrl(changedUrl);

    assertFalse("Should not be the same!", changedUrl.equals(repository.getLocalUrl()));

    repository.getCurrentCoreConfiguration().commitChanges();

    assertTrue("Should be the same!", changedUrl.equals(repository.getLocalUrl()));
  }
View Full Code Here

  @Test
  public void testRemoteStorageChanges()
      throws Exception
  {
    M2Repository repository = (M2Repository) getResourceStore();

    String changedUrl = repository.getRemoteUrl() + "/foo/";

    repository.setRemoteUrl(changedUrl);

    assertFalse("Should not be the same!", changedUrl.equals(repository.getRemoteUrl()));

    repository.getCurrentCoreConfiguration().commitChanges();

    assertTrue("Should be the same!", changedUrl.equals(repository.getRemoteUrl()));
  }
View Full Code Here

  @Test
  public void testProxyLastRequestedAttribute()
      throws Exception
  {
    M2Repository repository = (M2Repository) this.getRepositoryRegistry().getRepository("repo1");

    String item = "/org/slf4j/slf4j-api/1.4.3/slf4j-api-1.4.3.pom";
    ResourceStoreRequest request = new ResourceStoreRequest(item);
    request.getRequestContext().put(AccessManager.REQUEST_REMOTE_ADDRESS, "127.0.0.1");
    StorageItem storageItem = repository.retrieveItem(request);
    long lastRequest = System.currentTimeMillis() - 10 * A_DAY;
    storageItem.setLastRequested(lastRequest);
    repository.storeItem(false, storageItem);

    // now request the object, the lastRequested timestamp should be updated
    StorageItem resultItem = repository.retrieveItem(request);
    Assert.assertTrue(resultItem.getLastRequested() > lastRequest);

    // check the shadow attributes
    Attributes shadowStorageItem =
        repository.getAttributesHandler().getAttributeStorage().getAttributes(
            repository.createUid(request.getRequestPath()));
    assertThat(shadowStorageItem.getLastRequested(), is(resultItem.getLastRequested()));
  }
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.proxy.maven.maven2.M2LayoutedM1ShadowRepository

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.