Package org.sonatype.nexus.proxy.maven

Examples of org.sonatype.nexus.proxy.maven.ArtifactStoreRequest


    // put some proxied content
    // we need GavBuilder-like class, this below is hilarious!
    final Gav gav =
        new Gav("org.slf4j", "slf4j-api", "1.4.3", null, "jar", null, null, null, false, null, false, null);
    m2Repo.getArtifactStoreHelper().retrieveArtifact(new ArtifactStoreRequest(m2Repo, gav, false));
    // get GAV metadata (is present)
    m2Repo.retrieveItem(new ResourceStoreRequest("/org/slf4j/slf4j-api/1.4.3/maven-metadata.xml"));
    // get GA metadat (not present, will go into NFC
    try {
      m2Repo.retrieveItem(new ResourceStoreRequest("/org/slf4j/slf4j-api/maven-metadata.xml"));
View Full Code Here


   * update policy, that correspondos to Maven CLI "-U" option.
   */
  public File findArtifact(Artifact artifact) {
    Gav gav = toGav(artifact);

    ArtifactStoreRequest gavRequest;

    for (MavenRepository mavenRepository : nexusWorkspace.getRepositories()) {
      gavRequest = new ArtifactStoreRequest(mavenRepository, gav, false, false);

      try {
        StorageFileItem artifactFile = mavenRepository.getArtifactStoreHelper().retrieveArtifact(gavRequest);

        // this will work with local FS storage only, since Aether wants java.io.File
View Full Code Here

   */
  public List<String> findVersions(Artifact artifact) {
    Gav gav = toGav(artifact);

    if (gav.isSnapshot()) {
      ArtifactStoreRequest gavRequest;

      for (MavenRepository mavenRepository : nexusWorkspace.getRepositories()) {
        gavRequest = new ArtifactStoreRequest(mavenRepository, gav, false, false);

        try {
          Gav snapshot = mavenRepository.getMetadataManager().resolveSnapshot(gavRequest, gav);
          return Collections.singletonList(snapshot.getVersion());
        }
View Full Code Here

    // a flag that will prevent actual download as happens as sideeffect if this is proxy repository
    // and artifact being resolved is not present. This will not affect metadata download, since those are
    // needed for resolution!
    boolean isLocalOnly = isLocal(request, null);

    ArtifactStoreRequest gavRequest =
        getResourceStoreRequest(request, false, false, repositoryId, groupId, artifactId, version, packaging,
            classifier, extension);

    try {
      final MavenRepository mavenRepository = getMavenRepository(repositoryId);
View Full Code Here

      c = null;
    }

    Gav gav = new Gav(g, a, v, c, e, null, null, null, false, null, false, null);

    ArtifactStoreRequest result = new ArtifactStoreRequest(mavenRepository, gav, localOnly, remoteOnly);

    if (getLogger().isDebugEnabled()) {
      getLogger().debug("Created ArtifactStoreRequest request for " + result.getRequestPath());
    }

    // stuff in the originating remote address
    result.getRequestContext().put(AccessManager.REQUEST_REMOTE_ADDRESS, getValidRemoteIPAddress(request));

    // stuff in the user id if we have it in request
    Subject subject = securitySystem.getSubject();
    if (subject != null && subject.getPrincipal() != null) {
      result.getRequestContext().put(AccessManager.REQUEST_USER, subject.getPrincipal().toString());
    }
    result.getRequestContext().put(AccessManager.REQUEST_AGENT, request.getClientInfo().getAgent());

    // this is HTTPS, get the cert and stuff it too for later
    if (request.isConfidential()) {
      result.getRequestContext().put(AccessManager.REQUEST_CONFIDENTIAL, Boolean.TRUE);

      List<?> certs = (List<?>) request.getAttributes().get("org.restlet.https.clientCertificates");

      if (certs != null) {
        result.getRequestContext().put(AccessManager.REQUEST_CERTIFICATES, certs);
      }
    }

    // put the incoming URLs
    result.setRequestUrl(request.getOriginalRef().toString());

    return result;
  }
View Full Code Here

    if (groupId == null || artifactId == null || version == null || repositoryId == null) {
      throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
    }

    ArtifactStoreRequest gavRequest =
        getResourceStoreRequest(request, false, false, repositoryId, groupId, artifactId, version, null, null,
            "pom");

    gavRequest.setRequestLocalOnly(isLocal(request, gavRequest.getRequestPath()));

    try {
      MavenRepository mavenRepository = getMavenRepository(repositoryId);

      ArtifactStoreHelper helper = mavenRepository.getArtifactStoreHelper();
View Full Code Here

    // default the packaging
    if (StringUtils.isBlank(packaging)) {
      packaging = "jar";
    }

    ArtifactStoreRequest gavRequest =
        getResourceStoreRequest(request, false, false, repositoryId, groupId, artifactId, version, packaging,
            classifier, extension);

    gavRequest.setRequestLocalOnly(isLocal(request, gavRequest.getRequestPath()));

    try {
      MavenRepository mavenRepository = getMavenRepository(repositoryId);

      ArtifactStoreHelper helper = mavenRepository.getArtifactStoreHelper();
View Full Code Here

          // a file, this means NO parameters will income anymore
          // we either received all the GAVs as params, or we have a POM to work with (file1)
          boolean isPom = fi.getName().endsWith(".pom") || fi.getName().endsWith("pom.xml");
          InputStream is = null;

          ArtifactStoreRequest gavRequest = null;

          if (uploadContext.isPomAvailable()) {
            if (isPom) {
              // this is file1, the POM file content
              // let it "thru" the pomManager to be able to get GAV from it on later pass
              pomManager.storeTempPomFile(fi.getInputStream());
              is = pomManager.getTempPomFileInputStream();
            }
            else {
              // this is file2, POM already stored into pomManager
              is = fi.getInputStream();
            }

            try {
              // parse and read GAVs from stored POM, fill in them all into context
              final ArtifactCoordinate coords = pomManager.getArtifactCoordinateFromTempPomFile();
              uploadContext.setGroupId(coords.getGroupId());
              uploadContext.setArtifactId(coords.getArtifactId());
              uploadContext.setVersion(coords.getVersion());
              uploadContext.setPackaging(coords.getPackaging());
            }
            catch (IOException e) {
              getLogger().info("Error occurred while reading the POM file. Malformed POM?", e);
              throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
                  "Error occurred while reading the POM file. Malformed POM?", e);
            }

            if (isPom) {
              uploadGavParametersAvailable(request, uploadContext);
              gavRequest =
                  getResourceStoreRequest(request, true, false, uploadContext.getRepositoryId(),
                      uploadContext.getGroupId(), uploadContext.getArtifactId(),
                      uploadContext.getVersion(), uploadContext.getPackaging(), null, null);
            }
            else {
              gavRequest =
                  getResourceStoreRequest(request, true, false, uploadContext.getRepositoryId(),
                      uploadContext.getGroupId(), uploadContext.getArtifactId(),
                      uploadContext.getVersion(), uploadContext.getPackaging(),
                      uploadContext.getClassifier(), uploadContext.getExtension());
            }
          }
          else {
            uploadGavParametersAvailable(request, uploadContext);
            is = fi.getInputStream();
            gavRequest =
                getResourceStoreRequest(request, true, false, uploadContext.getRepositoryId(),
                    uploadContext.getGroupId(), uploadContext.getArtifactId(), uploadContext.getVersion(),
                    uploadContext.getPackaging(), uploadContext.getClassifier(),
                    uploadContext.getExtension());
          }

          final MavenRepository mr = gavRequest.getMavenRepository();
          final ArtifactStoreHelper helper = mr.getArtifactStoreHelper();

          // temporarily we disable SNAPSHOT upload
          // check is it a Snapshot repo
          if (RepositoryPolicy.SNAPSHOT.equals(mr.getRepositoryPolicy())) {
            getLogger().info("Upload to SNAPSHOT maven repository {} attempted, returning Bad Request.",
                mr);
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
                "This is a Maven SNAPSHOT repository, and manual upload against it is forbidden!");
          }

          if (!versionMatchesPolicy(gavRequest.getVersion(), mr.getRepositoryPolicy())) {
            getLogger().info("Artifact version {} and {} Repository Policy {} mismatch",
                gavRequest.getVersion(), mr, mr.getRepositoryPolicy());
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "The version "
                + gavRequest.getVersion() + " does not match the repository policy!");
          }

          if (isPom) {
            helper.storeArtifactPom(gavRequest, is, null);
            isPom = false;
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.proxy.maven.ArtifactStoreRequest

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.