コード例 #1
0
  private String adjustUsingClientTimestamp(MavenSnapshotVersionAdapterContext context) {
    // artifact was uploaded with a timestamp, we use it for the unique snapshot timestamp and to
    // locate build number
    long timestamp = context.getTimestamp();
    String uniqueTimestamp = MavenModelUtils.dateToUniqueSnapshotTimestamp(new Date(timestamp));
    RepoPath repoPath = context.getRepoPath();
    String existingArtifact = findSnapshotFileByTimestamp(repoPath.getParent(), uniqueTimestamp);
    int buildNumber;
    if (existingArtifact != null) {
      buildNumber = MavenNaming.getUniqueSnapshotVersionBuildNumber(existingArtifact);
    } else {
      buildNumber = getLastBuildNumber(repoPath) + 1;
    }

    return buildUniqueSnapshotFileName(buildNumber, uniqueTimestamp, context.getModuleInfo());
  }
コード例 #2
0
  private String adjustUsingServerData(MavenSnapshotVersionAdapterContext context) {
    // Get the latest build number from the metadata
    RepoPath repoPath = context.getRepoPath();
    String filePath = repoPath.getPath();
    int metadataBuildNumber = getLastBuildNumber(repoPath);
    int nextBuildNumber = metadataBuildNumber + 1;

    RepoPath parentPath = repoPath.getParent();

    // determine if the next build number should be the one read from the metadata
    ModuleInfo moduleInfo = context.getModuleInfo();
    String classifier = moduleInfo.getClassifier();
    boolean isPomChecksum =
        MavenNaming.isChecksum(filePath) && MavenNaming.isPom(PathUtils.stripExtension(filePath));
    if (metadataBuildNumber > 0 && (StringUtils.isNotBlank(classifier) || isPomChecksum)) {
      // pom checksums and artifacts with classifier are always deployed after the pom (which
      // triggers the
      // maven-metadata.xml calculation) so use the metadata build number
      nextBuildNumber = metadataBuildNumber;
    }
    if (metadataBuildNumber > 0 && MavenNaming.isPom(filePath)) {
      // the metadata might already represent an existing main artifact (in case the
      // maven-metadata.xml was deployed after the main artifact and before the pom/classifier)
      // so first check if there's already a file with the next build number
      if (findSnapshotFileByBuildNumber(parentPath, metadataBuildNumber + 1) == null) {
        // no files deployed with the next build number so either this is a pom deployment (parent
        // pom)
        // or this is a pom of a main artifact for which the maven-metadata.xml was deployed before
        // this pom
        if (findSnapshotPomFile(parentPath, metadataBuildNumber) == null) {
          // this is a pom attached to a main artifact deployed after maven-metadata.xml
          nextBuildNumber = metadataBuildNumber;
        }
      }
    }

    String timestamp = getSnapshotTimestamp(parentPath, nextBuildNumber);
    if (timestamp == null) {
      // probably the first deployed file for this build, use now for the timestamp
      timestamp = MavenModelUtils.dateToUniqueSnapshotTimestamp(new Date());
    }
    return buildUniqueSnapshotFileName(nextBuildNumber, timestamp, moduleInfo);
  }