コード例 #1
0
  @Override
  public void fillInputData(InputData inputData)
      throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {

    Resource resource = inputData.getResource();

    try {

      if (proxy != Proxy.NO_PROXY) {
        warn("proxy support is not implemented - ignoring proxy settings");
      }

      URLConnection urlConnection = newConnection(resource.getName());
      InputStream is = urlConnection.getInputStream();

      inputData.setInputStream(is);
      resource.setLastModified(urlConnection.getLastModified());
      resource.setContentLength(urlConnection.getContentLength());

    } catch (MalformedURLException e) {
      throw new TransferFailedException("Invalid repository URL: " + e.getMessage(), e);
    } catch (FileNotFoundException e) {
      throw new ResourceDoesNotExistException("Unable to locate resource in repository", e);
    } catch (IOException e) {
      throw new TransferFailedException("Error transferring file: " + e.getMessage(), e);
    }
  }
コード例 #2
0
ファイル: SrampWagon.java プロジェクト: rnc/s-ramp
  /**
   * Gets the hash data from the s-ramp repository and stores it in the {@link InputData} for use by
   * Maven.
   *
   * @param gavInfo
   * @param inputData
   * @throws TransferFailedException
   * @throws ResourceDoesNotExistException
   * @throws AuthorizationException
   */
  private void doGetHash(MavenGavInfo gavInfo, InputData inputData)
      throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
    String artyPath = gavInfo.getFullName();
    String hashPropName;
    if (gavInfo.getType().endsWith(".md5")) { // $NON-NLS-1$
      hashPropName = "maven.hash.md5"; // $NON-NLS-1$
      artyPath = artyPath.substring(0, artyPath.length() - 4);
    } else {
      hashPropName = "maven.hash.sha1"; // $NON-NLS-1$
      artyPath = artyPath.substring(0, artyPath.length() - 5);
    }
    // See the comment in {@link SrampWagon#fillInputData(InputData)} about why we're doing this
    // context classloader magic.
    ClassLoader oldCtxCL = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(SrampWagon.class.getClassLoader());
    try {
      SrampArchiveEntry entry = this.archive.getEntry(artyPath);
      if (entry == null) {
        throw new ResourceDoesNotExistException(
            Messages.i18n.format("MISSING_RESOURCE_HASH", gavInfo.getName())); // $NON-NLS-1$
      }
      BaseArtifactType metaData = entry.getMetaData();

      String hashValue = SrampModelUtils.getCustomProperty(metaData, hashPropName);
      if (hashValue == null) {
        throw new ResourceDoesNotExistException(
            Messages.i18n.format("MISSING_RESOURCE_HASH", gavInfo.getName())); // $NON-NLS-1$
      }
      inputData.setInputStream(IOUtils.toInputStream(hashValue));
    } finally {
      Thread.currentThread().setContextClassLoader(oldCtxCL);
    }
  }
コード例 #3
0
ファイル: GitWagon.java プロジェクト: kolotyluk/wagon-git
 /**
  * This will read from the working copy. File modification date would not be available as it does
  * not really have any meaningful value. {@inheritDoc}
  *
  * @throws ResourceDoesNotExistException when the file does not exist
  * @throws AuthorizationException when the file cannot be read
  */
 @Override
 public void fillInputData(final InputData inputData)
     throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
   try {
     final File file = getFileForResource(inputData.getResource().getName());
     if (!file.exists()) {
       throw new ResourceDoesNotExistException(
           format(R.getString("filenotfound"), file)); // $NON-NLS-1$
     }
     if (!file.canRead()) {
       throw new AuthorizationException(
           format(R.getString("cannotreadfile"), file)); // $NON-NLS-1$
     }
     inputData.setInputStream(new FileInputStream(file));
     inputData.getResource().setContentLength(file.length());
   } catch (final IOException e) {
     throw new TransferFailedException(e.getMessage(), e);
   } catch (final GitAPIException e) {
     throw new TransferFailedException(e.getMessage(), e);
   } catch (final URISyntaxException e) {
     throw new TransferFailedException(e.getMessage(), e);
   }
 }
コード例 #4
0
ファイル: SrampWagon.java プロジェクト: rnc/s-ramp
  /**
   * * Gets the artifact content from the s-ramp repository and stores it in the {@link InputData}
   * object for use by Maven.
   *
   * @param gavInfo
   * @param inputData
   * @throws TransferFailedException
   * @throws ResourceDoesNotExistException
   * @throws AuthorizationException
   */
  private void doGetArtifact(MavenGavInfo gavInfo, InputData inputData)
      throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
    // RESTEasy uses the current thread's context classloader to load its logger class.  This
    // fails in Maven because the context classloader is the wagon plugin's classloader, which
    // doesn't know about any of the RESTEasy JARs.  So here we're temporarily setting the
    // context classloader to the s-ramp wagon extension's classloader, which should have access
    // to all the right stuff.
    ClassLoader oldCtxCL = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(SrampWagon.class.getClassLoader());
    try {
      // Query the artifact meta data using GAV info
      BaseArtifactType artifact = findExistingArtifact(client, gavInfo);
      if (artifact == null)
        throw new ResourceDoesNotExistException(
            Messages.i18n.format("ARTIFACT_NOT_FOUND", gavInfo.getName())); // $NON-NLS-1$
      this.archive.addEntry(gavInfo.getFullName(), artifact, null);
      ArtifactType type = ArtifactType.valueOf(artifact);

      // Get the artifact content as an input stream
      InputStream artifactContent = client.getArtifactContent(type, artifact.getUuid());
      inputData.setInputStream(artifactContent);
    } catch (ResourceDoesNotExistException e) {
      throw e;
    } catch (SrampClientException e) {
      if (e.getCause() instanceof HttpHostConnectException) {
        this.debug(Messages.i18n.format("SRAMP_CONNECTION_FAILED", e.getMessage())); // $NON-NLS-1$
      } else {
        this.error(e.getMessage(), e);
      }
      throw new ResourceDoesNotExistException(
          Messages.i18n.format(
              "FAILED_TO_GET_RESOURCE_FROM_SRAMP", gavInfo.getName())); // $NON-NLS-1$
    } catch (Throwable t) {
      this.error(t.getMessage(), t);
    } finally {
      Thread.currentThread().setContextClassLoader(oldCtxCL);
    }
  }
コード例 #5
0
ファイル: SrampWagon.java プロジェクト: rnc/s-ramp
  /** @see org.apache.maven.wagon.StreamWagon#fillInputData(org.apache.maven.wagon.InputData) */
  @Override
  public void fillInputData(InputData inputData)
      throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
    Resource resource = inputData.getResource();
    MavenGavInfo gavInfo = MavenGavInfo.fromResource(resource);
    if (gavInfo.isMavenMetaData() && gavInfo.getVersion() == null) {
      doGenerateArtifactDirMavenMetaData(gavInfo, inputData);
      return;
    }

    if (gavInfo.isMavenMetaData() && gavInfo.getVersion() != null) {
      doGenerateSnapshotMavenMetaData(gavInfo, inputData);
      return;
    }

    debug(Messages.i18n.format("LOOKING_UP_RESOURCE_IN_SRAMP", resource)); // $NON-NLS-1$

    if (gavInfo.isHash()) {
      doGetHash(gavInfo, inputData);
    } else {
      doGetArtifact(gavInfo, inputData);
    }
  }
コード例 #6
0
ファイル: SrampWagon.java プロジェクト: rnc/s-ramp
  /**
   * Generates the maven-metadata.xml file dynamically for a given
   * groupId/artifactId/snapshot-version. This will list all of the snapshot versions available.
   *
   * @param gavInfo
   * @param inputData
   * @throws ResourceDoesNotExistException
   */
  private void doGenerateSnapshotMavenMetaData(MavenGavInfo gavInfo, InputData inputData)
      throws ResourceDoesNotExistException {
    // See the comment in {@link SrampWagon#fillInputData(InputData)} about why we're doing this
    // context classloader magic.
    ClassLoader oldCtxCL = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(SrampWagon.class.getClassLoader());
    try {
      String artyPath = gavInfo.getFullName();
      if (gavInfo.isHash()) {
        artyPath = artyPath.substring(0, artyPath.lastIndexOf('.'));
      }
      SrampArchiveEntry entry = this.archive.getEntry(artyPath);
      if (entry == null) {
        QueryResultSet resultSet =
            client
                .buildQuery(
                    "/s-ramp[@maven.groupId = ? and @maven.artifactId = ? and @maven.version = ?]") //$NON-NLS-1$
                .parameter(gavInfo.getGroupId())
                .parameter(gavInfo.getArtifactId())
                .parameter(gavInfo.getVersion())
                .propertyName("maven.classifier")
                .propertyName("maven.type") // $NON-NLS-1$ //$NON-NLS-2$
                .count(500)
                .orderBy("createdTimestamp")
                .ascending()
                .query(); //$NON-NLS-1$
        if (resultSet.size() == 0) {
          throw new Exception(Messages.i18n.format("NO_ARTIFACTS_FOUND")); // $NON-NLS-1$
        }

        SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyyMMdd.HHmmss"); // $NON-NLS-1$
        SimpleDateFormat updatedFormat = new SimpleDateFormat("yyyyMMddHHmmss"); // $NON-NLS-1$

        StringBuilder snapshotVersions = new StringBuilder();
        snapshotVersions.append("    <snapshotVersions>\n"); // $NON-NLS-1$
        Set<String> processed = new HashSet<String>();
        Date latestDate = null;
        for (ArtifactSummary artifactSummary : resultSet) {
          String extension = artifactSummary.getCustomPropertyValue("maven.type"); // $NON-NLS-1$
          String classifier =
              artifactSummary.getCustomPropertyValue("maven.classifier"); // $NON-NLS-1$
          String value = gavInfo.getVersion();
          Date updatedDate = artifactSummary.getLastModifiedTimestamp();
          String updated = updatedFormat.format(updatedDate);
          String pkey = classifier + "::" + extension; // $NON-NLS-1$
          if (processed.add(pkey)) {
            snapshotVersions.append("      <snapshotVersion>\n"); // $NON-NLS-1$
            if (classifier != null)
              snapshotVersions
                  .append("        <classifier>")
                  .append(classifier)
                  .append("</classifier>\n"); // $NON-NLS-1$ //$NON-NLS-2$
            snapshotVersions
                .append("        <extension>")
                .append(extension)
                .append("</extension>\n"); // $NON-NLS-1$ //$NON-NLS-2$
            snapshotVersions
                .append("        <value>")
                .append(value)
                .append("</value>\n"); // $NON-NLS-1$ //$NON-NLS-2$
            snapshotVersions
                .append("        <updated>")
                .append(updated)
                .append("</updated>\n"); // $NON-NLS-1$ //$NON-NLS-2$
            snapshotVersions.append("      </snapshotVersion>\n"); // $NON-NLS-1$
            if (latestDate == null || latestDate.before(updatedDate)) {
              latestDate = updatedDate;
            }
          }
        }
        snapshotVersions.append("    </snapshotVersions>\n"); // $NON-NLS-1$

        String groupId = gavInfo.getGroupId();
        String artifactId = gavInfo.getArtifactId();
        String version = gavInfo.getVersion();
        String lastUpdated = updatedFormat.format(latestDate);

        StringBuilder mavenMetadata = new StringBuilder();
        mavenMetadata.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); // $NON-NLS-1$
        mavenMetadata.append("<metadata>\n"); // $NON-NLS-1$
        mavenMetadata
            .append("  <groupId>")
            .append(groupId)
            .append("</groupId>\n"); // $NON-NLS-1$ //$NON-NLS-2$
        mavenMetadata
            .append("  <artifactId>")
            .append(artifactId)
            .append("</artifactId>\n"); // $NON-NLS-1$ //$NON-NLS-2$
        mavenMetadata
            .append("  <version>")
            .append(version)
            .append("</version>\n"); // $NON-NLS-1$ //$NON-NLS-2$
        mavenMetadata.append("  <versioning>\n"); // $NON-NLS-1$
        mavenMetadata.append("    <snapshot>\n"); // $NON-NLS-1$
        mavenMetadata
            .append("      <timestamp>")
            .append(timestampFormat.format(latestDate))
            .append("</timestamp>\n"); // $NON-NLS-1$ //$NON-NLS-2$
        mavenMetadata.append("      <buildNumber>1</buildNumber>\n"); // $NON-NLS-1$
        mavenMetadata.append("    </snapshot>\n"); // $NON-NLS-1$
        mavenMetadata
            .append("    <lastUpdated>")
            .append(lastUpdated)
            .append("</lastUpdated>\n"); // $NON-NLS-1$ //$NON-NLS-2$
        mavenMetadata.append(snapshotVersions.toString());
        mavenMetadata.append("  </versioning>\n"); // $NON-NLS-1$
        mavenMetadata.append("</metadata>\n"); // $NON-NLS-1$

        BaseArtifactType artifact =
            ArtifactType.ExtendedDocument("MavenMetaData").newArtifactInstance(); // $NON-NLS-1$
        this.archive.addEntry(artyPath, artifact, IOUtils.toInputStream(mavenMetadata.toString()));

        entry = this.archive.getEntry(artyPath);
      }

      if (!gavInfo.isHash()) {
        inputData.setInputStream(this.archive.getInputStream(entry));
      } else {
        String hash = generateHash(this.archive.getInputStream(entry), gavInfo.getHashAlgorithm());
        inputData.setInputStream(IOUtils.toInputStream(hash));
      }
    } catch (Exception e) {
      throw new ResourceDoesNotExistException(
          Messages.i18n.format("FAILED_TO_GENERATE_METADATA"), e); // $NON-NLS-1$
    } finally {
      Thread.currentThread().setContextClassLoader(oldCtxCL);
    }
  }
コード例 #7
0
ファイル: SrampWagon.java プロジェクト: rnc/s-ramp
  /**
   * Generates the maven-metadata.xml file dynamically for a given groupId/artifactId pair. This
   * will list all of the versions available for that groupId+artifactId, along with the latest
   * release and snapshot versions.
   *
   * @param gavInfo
   * @param inputData
   * @throws ResourceDoesNotExistException
   */
  private void doGenerateArtifactDirMavenMetaData(MavenGavInfo gavInfo, InputData inputData)
      throws ResourceDoesNotExistException {
    // See the comment in {@link SrampWagon#fillInputData(InputData)} about why we're doing this
    // context classloader magic.
    ClassLoader oldCtxCL = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(SrampWagon.class.getClassLoader());
    try {
      String artyPath = gavInfo.getFullName();
      if (gavInfo.isHash()) {
        artyPath = artyPath.substring(0, artyPath.lastIndexOf('.'));
      }
      SrampArchiveEntry entry = this.archive.getEntry(artyPath);
      if (entry == null) {
        QueryResultSet resultSet =
            client
                .buildQuery("/s-ramp[@maven.groupId = ? and @maven.artifactId = ?]") // $NON-NLS-1$
                .parameter(gavInfo.getGroupId())
                .parameter(gavInfo.getArtifactId())
                .propertyName("maven.version") // $NON-NLS-1$
                .count(500)
                .orderBy("createdTimestamp")
                .ascending()
                .query(); //$NON-NLS-1$
        if (resultSet.size() == 0) {
          throw new Exception(Messages.i18n.format("NO_ARTIFACTS_FOUND")); // $NON-NLS-1$
        }

        String groupId = gavInfo.getGroupId();
        String artifactId = gavInfo.getArtifactId();
        String latest = null;
        String release = null;
        String lastUpdated = null;

        LinkedHashSet<String> versions = new LinkedHashSet<String>();
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); // $NON-NLS-1$
        for (ArtifactSummary artifactSummary : resultSet) {
          String version = artifactSummary.getCustomPropertyValue("maven.version"); // $NON-NLS-1$
          if (versions.add(version)) {
            latest = version;
            if (!version.endsWith("-SNAPSHOT")) { // $NON-NLS-1$
              release = version;
            }
          }
          lastUpdated = format.format(artifactSummary.getCreatedTimestamp());
        }

        StringBuilder mavenMetadata = new StringBuilder();
        mavenMetadata.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); // $NON-NLS-1$
        mavenMetadata.append("<metadata>\n"); // $NON-NLS-1$
        mavenMetadata
            .append("  <groupId>")
            .append(groupId)
            .append("</groupId>\n"); // $NON-NLS-1$ //$NON-NLS-2$
        mavenMetadata
            .append("  <artifactId>")
            .append(artifactId)
            .append("</artifactId>\n"); // $NON-NLS-1$ //$NON-NLS-2$
        mavenMetadata.append("  <versioning>\n"); // $NON-NLS-1$
        mavenMetadata
            .append("    <latest>")
            .append(latest)
            .append("</latest>\n"); // $NON-NLS-1$ //$NON-NLS-2$
        mavenMetadata
            .append("    <release>")
            .append(release)
            .append("</release>\n"); // $NON-NLS-1$ //$NON-NLS-2$
        mavenMetadata.append("    <versions>\n"); // $NON-NLS-1$
        for (String version : versions) {
          mavenMetadata
              .append("      <version>")
              .append(version)
              .append("</version>\n"); // $NON-NLS-1$ //$NON-NLS-2$
        }
        mavenMetadata.append("    </versions>\n"); // $NON-NLS-1$
        mavenMetadata
            .append("    <lastUpdated>")
            .append(lastUpdated)
            .append("</lastUpdated>\n"); // $NON-NLS-1$ //$NON-NLS-2$
        mavenMetadata.append("  </versioning>\n"); // $NON-NLS-1$
        mavenMetadata.append("</metadata>\n"); // $NON-NLS-1$

        BaseArtifactType artifact =
            ArtifactType.ExtendedDocument("MavenMetaData").newArtifactInstance(); // $NON-NLS-1$
        this.archive.addEntry(artyPath, artifact, IOUtils.toInputStream(mavenMetadata.toString()));

        entry = this.archive.getEntry(artyPath);
      }

      if (!gavInfo.isHash()) {
        inputData.setInputStream(this.archive.getInputStream(entry));
      } else {
        String hash = generateHash(this.archive.getInputStream(entry), gavInfo.getHashAlgorithm());
        inputData.setInputStream(IOUtils.toInputStream(hash));
      }
    } catch (Exception e) {
      throw new ResourceDoesNotExistException(
          Messages.i18n.format("FAILED_TO_GENERATE_METADATA"), e); // $NON-NLS-1$
    } finally {
      Thread.currentThread().setContextClassLoader(oldCtxCL);
    }
  }