예제 #1
0
  private RepoPath getMetadataRepoPath(RepoPath parentRepoPath, String metadataName) {
    String path = parentRepoPath.getPath();
    boolean alreadyMetadataPath = NamingUtils.isMetadata(path);
    if (alreadyMetadataPath) {
      log.warn("Path {} is already a metadata path.", path);
    }
    // TODO: [by yl] Evaluate the impact of normalizing the path to use the standard metadata format
    // (a.jar#mdname)

    return InternalRepoPathFactory.create(
        parentRepoPath.getRepoKey(),
        alreadyMetadataPath ? path : NamingUtils.getMetadataPath(path, metadataName));
  }
예제 #2
0
 /**
  * Returns a list of {@link org.artifactory.aql.util.AqlSearchablePath} pointing to all files
  * contained in the current folder as well as all files under all subdirectories of that folder.
  *
  * <p>NOTE: use only with folders!
  *
  * @param path RepoPath of the folder to construct the search paths from
  */
 public static List<AqlSearchablePath> getSearchablePathForCurrentFolderAndSubfolders(
     RepoPath path) {
   List<AqlSearchablePath> artifactPaths = Lists.newArrayList();
   // Add *.* in filename for AqlSearchablePath creation - path is assumed to be a folder
   RepoPath searchPath = InternalRepoPathFactory.childRepoPath(path, "*.*");
   // All files in the folder containing the file
   AqlSearchablePath allFilesInCurrentFolder = new AqlSearchablePath(searchPath);
   // All files in all subfolders of folder containing the file
   AqlSearchablePath allFilesInSubFolders = new AqlSearchablePath(searchPath);
   if (".".equals(allFilesInSubFolders.getPath())) { // Special case for root folder
     allFilesInSubFolders.setPath("**");
   } else {
     allFilesInSubFolders.setPath(allFilesInSubFolders.getPath() + "/**");
   }
   // This will also find files without any extension (i.e. docker, lfs)
   allFilesInCurrentFolder.setFileName("*");
   allFilesInSubFolders.setFileName("*");
   artifactPaths.add(allFilesInCurrentFolder);
   artifactPaths.add(allFilesInSubFolders);
   return artifactPaths;
 }
  private String adjustChecksum(MavenSnapshotVersionAdapterContext context) {
    // find latest unique file matching the checksum coordinates
    RepositoryService repoService = ContextHelper.get().getRepositoryService();
    RepoPath repoPath = context.getRepoPath();
    RepoPath parentRepoPath = repoPath.getParent();
    RepoDescriptor repoDescriptor = repoService.repoDescriptorByKey(parentRepoPath.getRepoKey());
    RepoLayout repoLayout = repoDescriptor.getRepoLayout();

    String latestMatching = null;

    String originalChecksumRequestPath = repoPath.getPath();
    String originalRequestPathWithNoChecksum =
        PathUtils.stripExtension(originalChecksumRequestPath);

    if (repoService.exists(parentRepoPath)) {
      List<String> children = repoService.getChildrenNames(parentRepoPath);
      for (String child : children) {
        if (MavenNaming.isUniqueSnapshotFileName(child)) {

          ModuleInfo childModule =
              repoService.getItemModuleInfo(InternalRepoPathFactory.create(parentRepoPath, child));
          String fileRevisionIntegration = childModule.getFileIntegrationRevision();

          // Try to construct a new non-unique path as a descriptor
          String nonUniquePath =
              replaceIntegration(
                  ModuleInfoUtils.constructDescriptorPath(childModule, repoLayout, true),
                  fileRevisionIntegration);

          // If the path as a descriptor doesn't match, perhaps it's an artifact path
          if (!nonUniquePath.equals(originalRequestPathWithNoChecksum)) {
            // Try to construct a new non-unique path as an artifact
            nonUniquePath =
                replaceIntegration(
                    ModuleInfoUtils.constructArtifactPath(childModule, repoLayout),
                    fileRevisionIntegration);
          }

          if (nonUniquePath.equals(originalRequestPathWithNoChecksum)) {
            if (latestMatching == null
                || MavenNaming.getUniqueSnapshotVersionBuildNumber(latestMatching)
                    < MavenNaming.getUniqueSnapshotVersionBuildNumber(child)) {
              latestMatching = child;
            }
          }
        }
      }
    }

    // if latest not found, return invalid path which will fail and return a message to the client
    String timestamp =
        latestMatching != null
            ? MavenNaming.getUniqueSnapshotVersionTimestamp(latestMatching)
            : System.currentTimeMillis() + "";
    int buildNumber =
        latestMatching != null
            ? MavenNaming.getUniqueSnapshotVersionBuildNumber(latestMatching)
            : 0;

    // use the timestamp and build number from it. if not found return something that will fail?
    return buildUniqueSnapshotFileName(buildNumber, timestamp, context.getModuleInfo());
  }