当前位置: 首页>>代码示例>>Java>>正文


Java Versioning.setSnapshotVersions方法代码示例

本文整理汇总了Java中org.apache.maven.artifact.repository.metadata.Versioning.setSnapshotVersions方法的典型用法代码示例。如果您正苦于以下问题:Java Versioning.setSnapshotVersions方法的具体用法?Java Versioning.setSnapshotVersions怎么用?Java Versioning.setSnapshotVersions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.maven.artifact.repository.metadata.Versioning的用法示例。


在下文中一共展示了Versioning.setSnapshotVersions方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildSnapshotMavenMetadata

import org.apache.maven.artifact.repository.metadata.Versioning; //导入方法依赖的package包/类
/**
 * Build custom maven-metadata.xml according to a specific version.
 *
 * @param moduleInfo The original {@code ModuleInfo} to assemble the maven metadata according to the same
 *                   gid,aid,and version, {@link org.apache.maven.artifact.repository.metadata.Versioning#setLastUpdatedTimestamp(java.util.Date)} is updated to now. and
 *                   the build number and timestamp in the {@link org.apache.maven.artifact.repository.metadata.Snapshot} is set according to the name.
 * @param fileName   The file name
 * @return The custom maven-metadata.xml
 */
public static Metadata buildSnapshotMavenMetadata(ModuleInfo moduleInfo, String fileName) {
    Metadata metadata = new Metadata();
    metadata.setGroupId(moduleInfo.getOrganization());
    metadata.setArtifactId(moduleInfo.getModule());
    metadata.setVersion(moduleInfo.getBaseRevision() + "-" + moduleInfo.getFolderIntegrationRevision());
    Versioning versioning = new Versioning();
    metadata.setVersioning(versioning);
    versioning.setLastUpdatedTimestamp(new Date());
    Snapshot snapshot = new Snapshot();
    versioning.setSnapshot(snapshot);
    snapshot.setBuildNumber(MavenNaming.getUniqueSnapshotVersionBuildNumber(fileName));
    snapshot.setTimestamp(MavenNaming.getUniqueSnapshotVersionTimestamp(fileName));
    if (ConstantValues.mvnMetadataVersion3Enabled.getBoolean()) {
        SnapshotVersion snapshotVersion = new SnapshotVersion();
        snapshotVersion.setUpdated(StringUtils.remove(snapshot.getTimestamp(), '.'));
        snapshotVersion.setVersion(moduleInfo.getBaseRevision() + "-" +
                moduleInfo.getFileIntegrationRevision());
        //Should always be a pom, since this method is called only by PropertiesAddonImpl.assembleDynamicMetadata
        snapshotVersion.setExtension(moduleInfo.getExt());
        versioning.setSnapshotVersions(Lists.newArrayList(snapshotVersion));
    }
    return metadata;
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:33,代码来源:MavenModelUtils.java

示例2: addSnapshotVersions

import org.apache.maven.artifact.repository.metadata.Versioning; //导入方法依赖的package包/类
private void addSnapshotVersions(Versioning existingVersioning, Versioning otherMetadataVersioning) {
    //Maven metadata merge function does not include snapshot version (https://jira.codehaus.org/browse/MNG-5180)
    SnapshotComparator comparator = MavenMetadataCalculator.createSnapshotComparator();
    List<SnapshotVersion> otherSnapshotVersions = otherMetadataVersioning.getSnapshotVersions();
    if ((otherSnapshotVersions != null) && !otherSnapshotVersions.isEmpty()) {

        List<SnapshotVersion> existingSnapshotVersions = existingVersioning.getSnapshotVersions();
        if ((existingSnapshotVersions == null) || existingSnapshotVersions.isEmpty()) {
            existingVersioning.setSnapshotVersions(otherSnapshotVersions);
        } else {
            for (SnapshotVersion otherSnapshotVersion : otherSnapshotVersions) {
                for (SnapshotVersion existingSnapshotVersion : existingSnapshotVersions) {
                    if (snapshotVersionClassifiersEqual(otherSnapshotVersion, existingSnapshotVersion) &&
                            snapshotVersionExtensionEqual(otherSnapshotVersion, existingSnapshotVersion)) {
                        if (comparator.compare(otherSnapshotVersion, existingSnapshotVersion) > 0) {
                            existingSnapshotVersion.setUpdated(otherSnapshotVersion.getUpdated());
                            existingSnapshotVersion.setVersion(otherSnapshotVersion.getVersion());
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:25,代码来源:MergeableMavenMetadata.java

示例3: writeMetadata

import org.apache.maven.artifact.repository.metadata.Versioning; //导入方法依赖的package包/类
private void writeMetadata(File folder, List<MavenCoordinates> coordinates) {
	List<SnapshotVersion> snapshotVersions = getSnapshotVersionMetadata(coordinates);
	if (!snapshotVersions.isEmpty()) {
		Metadata metadata = new Metadata();
		Versioning versioning = new Versioning();
		versioning.setSnapshotVersions(snapshotVersions);
		metadata.setVersioning(versioning);
		metadata.setGroupId(coordinates.get(0).getGroupId());
		metadata.setArtifactId(coordinates.get(0).getArtifactId());
		metadata.setVersion(coordinates.get(0).getVersion());
		writeMetadataFile(metadata, new File(folder, "maven-metadata.xml"));
	}
}
 
开发者ID:spring-io,项目名称:artifactory-resource,代码行数:14,代码来源:MavenMetadataGenerator.java

示例4: resolveMavenMetadataForCompatibility

import org.apache.maven.artifact.repository.metadata.Versioning; //导入方法依赖的package包/类
private RepoResource resolveMavenMetadataForCompatibility(FileResource metadataResource,
        InternalRequestContext context) {
    if (ConstantValues.mvnMetadataVersion3Enabled.getBoolean() && !context.clientSupportsM3SnapshotVersions()) {
        RepoRequests.logToContext("Use of v3 Maven metadata is enabled, but the requesting client doesn't " +
                "support it - checking if the response should be modified for compatibility");
        FileInfo info = metadataResource.getInfo();
        try {
            Metadata metadata = MavenModelUtils.toMavenMetadata(repositoryService.getStringContent(info));
            Versioning versioning = metadata.getVersioning();
            if (versioning != null) {
                List<SnapshotVersion> snapshotVersions = versioning.getSnapshotVersions();
                if ((snapshotVersions != null) && !snapshotVersions.isEmpty()) {
                    RepoRequests.logToContext("Found snapshot versions - modifying the response for compatibility");
                    versioning.setSnapshotVersions(null);
                    return new ResolvedResource(metadataResource, MavenModelUtils.mavenMetadataToString(metadata));
                }
            }
        } catch (IOException e) {
            RepoPath repoPath = info.getRepoPath();
            log.error("An error occurred while filtering Maven metadata '{}' for compatibility: " +
                    "{}\nReturning original content.", repoPath, e.getMessage());
            RepoRequests.logToContext("An error occurred while filtering for compatibility. Returning the " +
                    "original content: %s", e.getMessage());
        }
    }
    //In case none of the above apply, or if we encountered an error, return the original resource
    return metadataResource;
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:29,代码来源:DbStoringRepoMixin.java

示例5: createSnapshotsMetadata

import org.apache.maven.artifact.repository.metadata.Versioning; //导入方法依赖的package包/类
private boolean createSnapshotsMetadata(RepoPath repoPath, ItemNode treeNode) {
    if (!folderContainsPoms(treeNode)) {
        return false;
    }
    List<ItemNode> folderItems = treeNode.getChildren();
    Iterable<ItemNode> poms = Iterables.filter(folderItems, new Predicate<ItemNode>() {
        @Override
        public boolean apply(@Nullable ItemNode input) {
            return (input != null) && MavenNaming.isPom(input.getItemInfo().getName());
        }
    });

    RepoPath firstPom = poms.iterator().next().getRepoPath();
    MavenArtifactInfo artifactInfo = MavenArtifactInfo.fromRepoPath(firstPom);
    if (!artifactInfo.isValid()) {
        return true;
    }
    Metadata metadata = new Metadata();
    metadata.setGroupId(artifactInfo.getGroupId());
    metadata.setArtifactId(artifactInfo.getArtifactId());
    metadata.setVersion(artifactInfo.getVersion());
    Versioning versioning = new Versioning();
    metadata.setVersioning(versioning);
    versioning.setLastUpdatedTimestamp(new Date());
    Snapshot snapshot = new Snapshot();
    versioning.setSnapshot(snapshot);

    LocalRepoDescriptor localRepoDescriptor =
            getRepositoryService().localOrCachedRepoDescriptorByKey(repoPath.getRepoKey());
    SnapshotVersionBehavior snapshotBehavior = localRepoDescriptor.getSnapshotVersionBehavior();
    String latestUniquePom = getLatestUniqueSnapshotPomName(poms);
    if (snapshotBehavior.equals(SnapshotVersionBehavior.NONUNIQUE) ||
            (snapshotBehavior.equals(SnapshotVersionBehavior.DEPLOYER) && latestUniquePom == null)) {
        snapshot.setBuildNumber(1);
    } else if (snapshotBehavior.equals(SnapshotVersionBehavior.UNIQUE)) {
        // take the latest unique snapshot file file
        if (latestUniquePom != null) {
            snapshot.setBuildNumber(MavenNaming.getUniqueSnapshotVersionBuildNumber(latestUniquePom));
            snapshot.setTimestamp(MavenNaming.getUniqueSnapshotVersionTimestamp(latestUniquePom));
        }

        if (ConstantValues.mvnMetadataVersion3Enabled.getBoolean()) {
            List<SnapshotVersion> snapshotVersions = Lists.newArrayList(getFolderItemSnapshotVersions(folderItems));
            if (!snapshotVersions.isEmpty()) {
                versioning.setSnapshotVersions(snapshotVersions);
            }
        }
    }
    saveMetadata(repoPath, metadata);
    return true;
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:52,代码来源:MavenMetadataCalculator.java

示例6: merge

import org.apache.maven.artifact.repository.metadata.Versioning; //导入方法依赖的package包/类
public void merge(Metadata otherMetadata, RepoResource foundResource) {
    long otherLastModified = foundResource.getLastModified();
    if (metadata == null) {
        metadata = otherMetadata;
        lastModified = otherLastModified;
        if (!mergeSnapshotVersions) {
            Versioning versioning = metadata.getVersioning();
            if (versioning != null) {
                versioning.setSnapshotVersions(null);
            }
        }
    } else {
        metadata.merge(otherMetadata);
        lastModified = Math.max(otherLastModified, lastModified);

        Versioning existingVersioning = metadata.getVersioning();
        if (existingVersioning != null) {
            List<String> versions = existingVersioning.getVersions();
            if (!CollectionUtils.isNullOrEmpty(versions)) {
                try {
                    Collections.sort(versions, new MavenVersionComparator());
                } catch (IllegalArgumentException e) {
                    // New Java 7 TimSort is pointing out the non transitive behavior
                    // of the Mercury version comparator => Doing fallback to natural string order
                    log.info(
                            "Hitting Mercury version comparator non transitive behavior message='" + e.getMessage() + "'");
                    if (log.isDebugEnabled()) {
                        log.debug("The lists of versions is: " + versions);
                    }
                    Collections.sort(versions);
                }
                // latest is simply the last (be it snapshot or release version)
                String latestVersion = versions.get(versions.size() - 1);
                existingVersioning.setLatest(latestVersion);

                // release is the latest non snapshot version
                for (String version : versions) {
                    if (!MavenNaming.isSnapshot(version)) {
                        existingVersioning.setRelease(version);
                    }
                }
            }
            SnapshotComparator comparator = MavenMetadataCalculator.createSnapshotComparator();
            // if there's a unique snapshot version prefer the one with the bigger build number
            Snapshot snapshot = existingVersioning.getSnapshot();
            Versioning otherMetadataVersioning = otherMetadata.getVersioning();
            if (otherMetadataVersioning != null) {
                Snapshot otherSnapshot = otherMetadataVersioning.getSnapshot();
                if (snapshot != null && otherSnapshot != null) {
                    if (comparator.compare(otherSnapshot, snapshot) > 0) {
                        snapshot.setBuildNumber(otherSnapshot.getBuildNumber());
                        snapshot.setTimestamp(otherSnapshot.getTimestamp());
                    }
                }
                if (mergeSnapshotVersions) {
                    addSnapshotVersions(existingVersioning, otherMetadataVersioning);
                }
            }
        }
    }
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:62,代码来源:MergeableMavenMetadata.java


注:本文中的org.apache.maven.artifact.repository.metadata.Versioning.setSnapshotVersions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。