Пример #1
0
  /**
   * Should serve by policies.
   *
   * @param uid the uid
   * @return true, if successful
   */
  public boolean shouldServeByPolicies(ResourceStoreRequest request) {
    if (M1ArtifactRecognizer.isMetadata(request.getRequestPath())) {
      if (M1ArtifactRecognizer.isSnapshot(request.getRequestPath())) {
        return RepositoryPolicy.SNAPSHOT.equals(getRepositoryPolicy());
      } else {
        // metadatas goes always
        return true;
      }
    }

    // we are using Gav to test the path
    Gav gav = null;

    try {
      gav = getGavCalculator().pathToGav(request.getRequestPath());
    } catch (IllegalArtifactCoordinateException e) {
      getLogger()
          .info("Illegal artifact path: '" + request.getRequestPath() + "'" + e.getMessage());

      return false;
    }

    if (gav == null) {
      return true;
    } else {
      if (gav.isSnapshot()) {
        // snapshots goes if enabled
        return RepositoryPolicy.SNAPSHOT.equals(getRepositoryPolicy());
      } else {
        return RepositoryPolicy.RELEASE.equals(getRepositoryPolicy());
      }
    }
  }
 protected void createRepository(final String repoId) throws IOException {
   RepositoryResource repo = new RepositoryResource();
   repo.setId(repoId);
   repo.setRepoType("hosted");
   repo.setName(repoId);
   repo.setProvider("maven2");
   repo.setFormat("maven2");
   repo.setRepoPolicy(RepositoryPolicy.RELEASE.name());
   repoUtil.createRepository(repo, false);
 }
  protected boolean versionMatchesPolicy(String version, RepositoryPolicy policy) {
    boolean result = false;

    if ((RepositoryPolicy.SNAPSHOT.equals(policy) && VersionUtils.isSnapshot(version))
        || (RepositoryPolicy.RELEASE.equals(policy) && !VersionUtils.isSnapshot(version))) {
      result = true;
    }

    return result;
  }
  @Test
  public void hostedTestRelRepoAndDeployFile() throws IOException, Exception {
    // create a release repository
    String repoId = "tmp-releases";
    RepositoryResource repo = new RepositoryResource();
    repo.setProvider("ivy");
    repo.setFormat("maven2");
    repo.setRepoPolicy("release");
    repo.setChecksumPolicy("ignore");
    repo.setBrowseable(false);

    repo.setId(repoId);
    repo.setName(repoId);
    repo.setRepoType("hosted");
    repo.setWritePolicy(RepositoryWritePolicy.ALLOW_WRITE.name());
    repo.setDownloadRemoteIndexes(true);
    repo.setBrowseable(true);
    repo.setRepoPolicy(RepositoryPolicy.RELEASE.name());
    repo.setChecksumPolicy(ChecksumPolicy.IGNORE.name());

    repo.setIndexable(true); // being sure!!!
    repoUtil.createRepository(repo);

    // firstly assert that repository is there
    repo = (RepositoryResource) repoUtil.getRepository(repoId);
    Assert.assertTrue(repo.isIndexable());

    TaskScheduleUtil.waitForAllTasksToStop();

    // then deploy a release artifact
    Gav gav = GavUtil.newGav("ivyRemover", "auth-mod", "1.0");
    getDeployUtils().deployUsingGavWithRest(repoId, gav, getTestFile("simple-artifact.jar"));

    TaskScheduleUtil.waitForAllTasksToStop();
    getEventInspectorsUtil().waitForCalmPeriod();

    // secondly assert that the artifact is in the release repository
    List<NexusArtifact> result = getSearchMessageUtil().searchForGav(gav, repoId);
    Assert.assertEquals(
        result.size(), 1, "Results: \n" + XStreamFactory.getXmlXStream().toXML(result));

    // thirdly assert that there is at least alltogether one release artifact in the release
    // repository
    result = getSearchMessageUtil().searchFor(Collections.singletonMap("q", "ivyRemover"), repoId);
    Assert.assertEquals(
        result.size(), 1, "Results: \n" + XStreamFactory.getXmlXStream().toXML(result));
  }
  protected void createProxyRepository() throws Exception {
    RepositoryResource resource = new RepositoryResource();

    resource.setProvider("maven2");
    resource.setFormat("maven2");
    resource.setRepoPolicy("release");
    resource.setChecksumPolicy("ignore");
    resource.setBrowseable(false);
    resource.setIndexable(false);

    resource.setId(PROXY_REPO_ID);
    resource.setName(PROXY_REPO_ID);
    resource.setRepoType("proxy");
    resource.setWritePolicy(RepositoryWritePolicy.READ_ONLY.name());
    resource.setDownloadRemoteIndexes(true);
    RepositoryResourceRemoteStorage remoteStorage = new RepositoryResourceRemoteStorage();
    remoteStorage.setRemoteStorageUrl(
        getBaseNexusUrl() + "content/repositories/nexus-test-harness-repo/");
    resource.setRemoteStorage(remoteStorage);
    resource.setRepoPolicy(RepositoryPolicy.RELEASE.name());
    resource.setChecksumPolicy(ChecksumPolicy.IGNORE.name());
    new RepositoryMessageUtil(this, this.getJsonXStream(), MediaType.APPLICATION_JSON)
        .createRepository(resource);
  }
Пример #6
0
    public boolean releaseExistsForSnapshot(Gav snapshotGav, Map<String, Object> context) {
      for (Repository repository : repositoryRegistry.getRepositories()) {
        // we need to filter for:
        // repository that is MavenRepository and is hosted or proxy
        // repository that has release policy
        if (repository.getRepositoryKind().isFacetAvailable(MavenHostedRepository.class)
            || repository.getRepositoryKind().isFacetAvailable(MavenProxyRepository.class)) {
          // actually, we don't care is it proxy or hosted, we only need to filter out groups and
          // other
          // "composite" reposes like shadows
          MavenRepository mrepository = repository.adaptToFacet(MavenRepository.class);

          // look in release reposes only
          if (mrepository.isUserManaged()
              && RepositoryPolicy.RELEASE.equals(mrepository.getRepositoryPolicy())) {
            try {
              String releaseVersion = null;

              // NEXUS-3148
              if (snapshotGav.getBaseVersion().endsWith("-SNAPSHOT")) {
                // "-SNAPSHOT" :== 9 chars
                releaseVersion =
                    snapshotGav
                        .getBaseVersion()
                        .substring(0, snapshotGav.getBaseVersion().length() - 9);
              } else {
                // "SNAPSHOT" :== 8 chars
                releaseVersion =
                    snapshotGav
                        .getBaseVersion()
                        .substring(0, snapshotGav.getBaseVersion().length() - 8);
              }

              Gav releaseGav =
                  new Gav(
                      snapshotGav.getGroupId(),
                      snapshotGav.getArtifactId(),
                      releaseVersion,
                      snapshotGav.getClassifier(),
                      snapshotGav.getExtension(),
                      null,
                      null,
                      null,
                      false,
                      null,
                      false,
                      null);

              String path = mrepository.getGavCalculator().gavToPath(releaseGav);

              ResourceStoreRequest req = new ResourceStoreRequest(path, true);

              req.getRequestContext().putAll(context);

              mrepository.retrieveItem(false, req);

              return true;
            } catch (ItemNotFoundException e) {
              // nothing
            } catch (Exception e) {
              // nothing
            }
          }
        }
      }

      return false;
    }