Exemple #1
0
 /**
  * Ensures that the required ArtifactGrouping is present in the repository.
  *
  * @throws SrampAtomException
  * @throws SrampClientException
  */
 private BaseArtifactType ensureArtifactGrouping()
     throws SrampClientException, SrampAtomException {
   String groupingName = getParamFromRepositoryUrl("artifactGrouping"); // $NON-NLS-1$
   if (groupingName == null || groupingName.trim().length() == 0) {
     logger.warn(Messages.i18n.format("NO_ARTIFACT_GROUPING_NAME")); // $NON-NLS-1$
     return null;
   }
   QueryResultSet query =
       client
           .buildQuery("/s-ramp/ext/ArtifactGrouping[@name = ?]")
           .parameter(groupingName)
           .count(2)
           .query(); //$NON-NLS-1$
   if (query.size() > 1) {
     logger.warn(
         Messages.i18n.format("MULTIPLE_ARTIFACT_GROUPSING_FOUND", groupingName)); // $NON-NLS-1$
     return null;
   } else if (query.size() == 1) {
     ArtifactSummary summary = query.get(0);
     return client.getArtifactMetaData(summary.getType(), summary.getUuid());
   } else {
     ExtendedArtifactType groupingArtifact = new ExtendedArtifactType();
     groupingArtifact.setArtifactType(BaseArtifactEnum.EXTENDED_ARTIFACT_TYPE);
     groupingArtifact.setExtendedType("ArtifactGrouping"); // $NON-NLS-1$
     groupingArtifact.setName(groupingName);
     groupingArtifact.setDescription(
         Messages.i18n.format("ARTIFACT_GROUPING_DESCRIPTION")); // $NON-NLS-1$
     return client.createArtifact(groupingArtifact);
   }
 }
Exemple #2
0
 /**
  * Finds an existing artifact in the s-ramp repository using 'universal' form. This allows any
  * artifact in the s-ramp repository to be referenced as a Maven dependency using the model.type
  * and UUID of the artifact.
  *
  * @param client
  * @param artifactType
  * @param gavInfo
  * @return an existing s-ramp artifact (if found) or null (if not found)
  * @throws SrampClientException
  * @throws SrampAtomException
  * @throws JAXBException
  */
 private BaseArtifactType findExistingArtifactByUniversal(
     SrampAtomApiClient client, MavenGavInfo gavInfo)
     throws SrampAtomException, SrampClientException, JAXBException {
   String artifactType = gavInfo.getGroupId().substring(gavInfo.getGroupId().indexOf('.') + 1);
   String uuid = gavInfo.getArtifactId();
   try {
     return client.getArtifactMetaData(ArtifactType.valueOf(artifactType), uuid);
   } catch (Throwable t) {
     debug(t.getMessage());
   }
   return null;
 }
Exemple #3
0
  /** @see org.overlord.sramp.common.shell.ShellCommand#execute() */
  @Override
  public void execute() throws Exception {
    QName clientVarName = new QName("s-ramp", "client");
    QName artifactVarName = new QName("s-ramp", "artifact");
    QName feedVarName = new QName("s-ramp", "feed");

    SrampAtomApiClient client = (SrampAtomApiClient) getContext().getVariable(clientVarName);
    if (client == null) {
      print("No S-RAMP repository connection is currently open.");
      return;
    }

    BaseArtifactType artifact = null;
    String artifactIdArg = this.optionalArgument(0);
    if (artifactIdArg == null) {
      artifact = (BaseArtifactType) getContext().getVariable(artifactVarName);
      if (artifact == null) {
        print("No active S-RAMP artifact exists.  Use s-ramp:getMetaData.");
        return;
      }
    } else {
      String idType = artifactIdArg.substring(0, artifactIdArg.indexOf(':'));
      if ("feed".equals(idType)) {
        QueryResultSet rset = (QueryResultSet) getContext().getVariable(feedVarName);
        int feedIdx = Integer.parseInt(artifactIdArg.substring(artifactIdArg.indexOf(':') + 1)) - 1;
        if (feedIdx < 0 || feedIdx >= rset.size()) {
          throw new InvalidCommandArgumentException(0, "Feed index out of range.");
        }
        ArtifactSummary summary = rset.get(feedIdx);
        String artifactUUID = summary.getUuid();
        artifact = client.getArtifactMetaData(summary.getType(), artifactUUID);
      } else if ("uuid".equals(idType)) {
        throw new InvalidCommandArgumentException(
            0, "uuid: style artifact identifiers not yet implemented.");
      } else {
        throw new InvalidCommandArgumentException(0, "Invalid artifact id format.");
      }
    }

    try {
      client.deleteArtifact(artifact.getUuid(), ArtifactType.valueOf(artifact));
      print("Successfully deleted artifact '%1$s'.", artifact.getName());
    } catch (Exception e) {
      print("FAILED to delete the artifact.");
      print("\t" + e.getMessage());
    }
  }
Exemple #4
0
  /**
   * Updates an artifact by storing its hash value as an S-RAMP property.
   *
   * @param gavInfo
   * @param resourceInputStream
   * @throws TransferFailedException
   */
  private void doPutHash(MavenGavInfo gavInfo, InputStream resourceInputStream)
      throws TransferFailedException {
    logger.info(Messages.i18n.format("STORING_HASH_AS_PROP", gavInfo.getName())); // $NON-NLS-1$
    try {
      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);
      }
      String hashValue = IOUtils.toString(resourceInputStream);

      // 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);
        // Re-fetch the artifact meta-data in case it changed on the server since we uploaded it.
        BaseArtifactType metaData = client.getArtifactMetaData(entry.getMetaData().getUuid());
        SrampModelUtils.setCustomProperty(metaData, hashPropName, hashValue);
        this.archive.updateEntry(entry, null);

        // The meta-data has been updated in the local/temp archive - now send it to the remote repo
        client.updateArtifactMetaData(metaData);
      } catch (Throwable t) {
        throw new TransferFailedException(t.getMessage(), t);
      } finally {
        Thread.currentThread().setContextClassLoader(oldCtxCL);
      }
    } catch (Exception e) {
      throw new TransferFailedException(
          Messages.i18n.format("FAILED_TO_STORE_HASH", gavInfo.getName()), e); // $NON-NLS-1$
    }
  }
Exemple #5
0
  /**
   * Finds an existing artifact in the s-ramp repository that matches the GAV information.
   *
   * @param client
   * @param gavInfo
   * @return an s-ramp artifact (if found) or null (if not found)
   * @throws SrampClientException
   * @throws SrampAtomException
   * @throws JAXBException
   */
  private BaseArtifactType findExistingArtifactByGAV(
      SrampAtomApiClient client, MavenGavInfo gavInfo)
      throws SrampAtomException, SrampClientException, JAXBException {
    SrampClientQuery clientQuery = null;

    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append("/s-ramp"); // $NON-NLS-1$
    List<String> criteria = new ArrayList<String>();
    List<Object> params = new ArrayList<Object>();

    criteria.add("@maven.groupId = ?"); // $NON-NLS-1$
    params.add(gavInfo.getGroupId());
    criteria.add("@maven.artifactId = ?"); // $NON-NLS-1$
    params.add(gavInfo.getArtifactId());
    criteria.add("@maven.version = ?"); // $NON-NLS-1$
    params.add(gavInfo.getVersion());

    if (StringUtils.isNotBlank(gavInfo.getType())) {
      criteria.add("@maven.type = ?"); // $NON-NLS-1$
      params.add(gavInfo.getType());
    }
    if (StringUtils.isNotBlank(gavInfo.getClassifier())) {
      criteria.add("@maven.classifier = ?"); // $NON-NLS-1$
      params.add(gavInfo.getClassifier());
    }
    if (StringUtils.isNotBlank(gavInfo.getSnapshotId())) {
      return null;
    } else {
      criteria.add("xp2:not(@maven.snapshot.id)"); // $NON-NLS-1$
    }

    if (criteria.size() > 0) {
      queryBuilder.append("["); // $NON-NLS-1$
      queryBuilder.append(StringUtils.join(criteria, " and ")); // $NON-NLS-1$
      queryBuilder.append("]"); // $NON-NLS-1$
    }
    clientQuery = client.buildQuery(queryBuilder.toString());
    for (Object param : params) {
      if (param instanceof String) {
        clientQuery.parameter((String) param);
      }
      if (param instanceof Calendar) {
        clientQuery.parameter((Calendar) param);
      }
    }

    QueryResultSet rset = clientQuery.count(100).query();
    if (rset.size() > 0) {
      for (ArtifactSummary summary : rset) {
        String uuid = summary.getUuid();
        ArtifactType artifactType = summary.getType();
        BaseArtifactType arty = client.getArtifactMetaData(artifactType, uuid);
        // If no classifier in the GAV info, only return the artifact that also has no classifier
        // TODO replace this with "not(@maven.classifer)" in the query, then force the result set to
        // return 2 items (expecting only 1)
        if (gavInfo.getClassifier() == null) {
          String artyClassifier =
              SrampModelUtils.getCustomProperty(arty, "maven.classifier"); // $NON-NLS-1$
          if (artyClassifier == null) {
            return arty;
          }
        } else {
          // If classifier was supplied in the GAV info, we'll get the first artifact <shrug>
          return arty;
        }
      }
    }
    return null;
  }