本文整理汇总了Java中org.apache.maven.artifact.repository.metadata.Metadata.getVersioning方法的典型用法代码示例。如果您正苦于以下问题:Java Metadata.getVersioning方法的具体用法?Java Metadata.getVersioning怎么用?Java Metadata.getVersioning使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.maven.artifact.repository.metadata.Metadata
的用法示例。
在下文中一共展示了Metadata.getVersioning方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: retrieveLatestReleasedVersion
import org.apache.maven.artifact.repository.metadata.Metadata; //导入方法依赖的package包/类
private String retrieveLatestReleasedVersion(final Artifact artifact) {
final RepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact);
try {
repositoryMetadataManager.resolve(metadata, currentProject.getRemoteArtifactRepositories(), localRepository);
} catch (final RepositoryMetadataResolutionException e1) {
e1.printStackTrace();
}
final Metadata repoMetadata = metadata.getMetadata();
if (repoMetadata.getVersioning() != null) {
final String releasedVersion = repoMetadata.getVersioning().getRelease();
if (releasedVersion != null) {
return releasedVersion;
}
final String latestVersion = repoMetadata.getVersioning().getLatest();
if (latestVersion != null) {
return latestVersion;
}
}
return repoMetadata.getVersion();
}
示例2: a
import org.apache.maven.artifact.repository.metadata.Metadata; //导入方法依赖的package包/类
private Metadata a(final String groupId,
final String artifactId,
final String lastUpdated,
final String latest,
final String release,
final String... versions)
{
final Metadata m = new Metadata();
m.setGroupId(groupId);
m.setArtifactId(artifactId);
m.setVersioning(new Versioning());
final Versioning mv = m.getVersioning();
if (!Strings.isNullOrEmpty(lastUpdated)) {
mv.setLastUpdated(lastUpdated);
}
if (!Strings.isNullOrEmpty(latest)) {
mv.setLatest(latest);
}
if (!Strings.isNullOrEmpty(release)) {
mv.setRelease(release);
}
mv.getVersions().addAll(Arrays.asList(versions));
return m;
}
示例3: getMetadataLastModified
import org.apache.maven.artifact.repository.metadata.Metadata; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public long getMetadataLastModified( String path )
throws IOException, MetadataNotFoundException
{
Metadata metadata = getMetadata( path );
if ( metadata != null )
{
if ( !StringUtils.isEmpty( metadata.getGroupId() ) || !StringUtils.isEmpty( metadata.getArtifactId() )
|| !StringUtils.isEmpty( metadata.getVersion() )
|| ( metadata.getPlugins() != null && !metadata.getPlugins().isEmpty() ) || (
metadata.getVersioning() != null && ( !StringUtils.isEmpty( metadata.getVersioning().getLastUpdated() )
|| !StringUtils.isEmpty( metadata.getVersioning().getLatest() )
|| !StringUtils.isEmpty( metadata.getVersioning().getRelease() )
|| ( metadata.getVersioning().getVersions() != null
&& !metadata.getVersioning().getVersions().isEmpty() ) || ( metadata.getVersioning().getSnapshot()
!= null ) ) ) )
{
return System.currentTimeMillis();
}
}
throw new MetadataNotFoundException( path );
}
示例4: validStringToMetadata
import org.apache.maven.artifact.repository.metadata.Metadata; //导入方法依赖的package包/类
public void validStringToMetadata() throws IOException {
Metadata metadata = MavenModelUtils.toMavenMetadata(
"<metadata>\n" +
"<groupId>boo</groupId>\n" +
"<artifactId>boo</artifactId>\n" +
"<version>0.7.0.1921</version>\n" +
"<versioning>\n" +
"<versions>\n" +
"<version>0.7.0.1921</version>\n" +
"</versions>\n" +
"</versioning>\n" +
"</metadata>");
assertEquals(metadata.getGroupId(), "boo");
Versioning versioning = metadata.getVersioning();
assertNotNull(versioning);
assertEquals(versioning.getVersions().size(), 1);
}
示例5: resolveLatestSnapshotBuildNumber
import org.apache.maven.artifact.repository.metadata.Metadata; //导入方法依赖的package包/类
private int resolveLatestSnapshotBuildNumber( Artifact artifact, ArtifactRepository localRepository,
ArtifactRepository remoteRepository )
throws RepositoryMetadataResolutionException
{
RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
getLogger().info( "Retrieving previous build number from " + remoteRepository.getId() );
repositoryMetadataManager.resolveAlways( metadata, localRepository, remoteRepository );
int buildNumber = 0;
Metadata repoMetadata = metadata.getMetadata();
if ( ( repoMetadata != null )
&& ( repoMetadata.getVersioning() != null && repoMetadata.getVersioning().getSnapshot() != null ) )
{
buildNumber = repoMetadata.getVersioning().getSnapshot().getBuildNumber();
}
return buildNumber;
}
示例6: getBuildNumber
import org.apache.maven.artifact.repository.metadata.Metadata; //导入方法依赖的package包/类
private static int getBuildNumber( Metadata metadata )
{
int number = 0;
Versioning versioning = metadata.getVersioning();
if ( versioning != null )
{
Snapshot snapshot = versioning.getSnapshot();
if ( snapshot != null && snapshot.getBuildNumber() > 0 )
{
number = snapshot.getBuildNumber();
}
}
return number;
}
示例7: merge
import org.apache.maven.artifact.repository.metadata.Metadata; //导入方法依赖的package包/类
@Override
protected void merge( Metadata recessive )
{
Versioning versioning = metadata.getVersioning();
versioning.updateTimestamp();
if ( recessive.getVersioning() != null )
{
if ( versioning.getLatest() == null )
{
versioning.setLatest( recessive.getVersioning().getLatest() );
}
if ( versioning.getRelease() == null )
{
versioning.setRelease( recessive.getVersioning().getRelease() );
}
Collection<String> versions = new LinkedHashSet<String>( recessive.getVersioning().getVersions() );
versions.addAll( versioning.getVersions() );
versioning.setVersions( new ArrayList<String>( versions ) );
}
}
示例8: retrieveAvailableVersionsFromMetadata
import org.apache.maven.artifact.repository.metadata.Metadata; //导入方法依赖的package包/类
private List<ArtifactVersion> retrieveAvailableVersionsFromMetadata( Metadata repoMetadata,
List<String> availableVersions )
{
Collection<String> versions = new LinkedHashSet<String>();
if ( ( repoMetadata != null ) && ( repoMetadata.getVersioning() != null ) )
{
versions.addAll( repoMetadata.getVersioning().getVersions() );
}
versions.addAll( availableVersions );
List<ArtifactVersion> artifactVersions = new ArrayList<ArtifactVersion>( versions.size() );
for ( String version : versions )
{
artifactVersions.add( new DefaultArtifactVersion( version ) );
}
return artifactVersions;
}
示例9: v
import org.apache.maven.artifact.repository.metadata.Metadata; //导入方法依赖的package包/类
private Metadata v(final String groupId,
final String artifactId,
final String versionPrefix,
final String timestamp,
final int buildNumber)
{
final Metadata m = new Metadata();
m.setGroupId(groupId);
m.setArtifactId(artifactId);
m.setVersion(versionPrefix + "-SNAPSHOT");
m.setVersioning(new Versioning());
final Versioning mv = m.getVersioning();
mv.setLastUpdated(timestamp.replace(".", ""));
final Snapshot snapshot = new Snapshot();
snapshot.setTimestamp(timestamp);
snapshot.setBuildNumber(buildNumber);
mv.setSnapshot(snapshot);
final SnapshotVersion pom = new SnapshotVersion();
pom.setExtension("pom");
pom.setVersion(versionPrefix + "-" + timestamp + "-" + buildNumber);
pom.setUpdated(timestamp);
mv.getSnapshotVersions().add(pom);
final SnapshotVersion jar = new SnapshotVersion();
jar.setExtension("jar");
jar.setVersion(versionPrefix + "-" + timestamp + "-" + buildNumber);
jar.setUpdated(timestamp);
mv.getSnapshotVersions().add(jar);
final SnapshotVersion sources = new SnapshotVersion();
sources.setExtension("jar");
sources.setClassifier("sources");
sources.setVersion(versionPrefix + "-" + timestamp + "-" + buildNumber);
sources.setUpdated(timestamp);
mv.getSnapshotVersions().add(sources);
return m;
}
示例10: isSnapshotMavenMetadata
import org.apache.maven.artifact.repository.metadata.Metadata; //导入方法依赖的package包/类
private boolean isSnapshotMavenMetadata(Metadata metadata) {
Versioning versioning = metadata.getVersioning();
if (versioning == null) {
return false;
}
List<SnapshotVersion> snapshots = versioning.getSnapshotVersions();
return snapshots != null && !snapshots.isEmpty();
}
示例11: resolveMavenMetadataForCompatibility
import org.apache.maven.artifact.repository.metadata.Metadata; //导入方法依赖的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;
}
示例12: getLastBuildNumber
import org.apache.maven.artifact.repository.metadata.Metadata; //导入方法依赖的package包/类
/**
* @return The last build number for snapshot version. 0 if maven-metadata not found for the path.
*/
private int getLastBuildNumber(RepoPath repoPath) {
int buildNumber = 0;
try {
// get the parent path which should contains the maven-metadata
RepoPath parentRepoPath = repoPath.getParent();
RepositoryService repoService = ContextHelper.get().getRepositoryService();
RepoPathImpl mavenMetadataPath = new RepoPathImpl(parentRepoPath, MavenNaming.MAVEN_METADATA_NAME);
if (repoService.exists(mavenMetadataPath)) {
String mavenMetadataStr = repoService.getStringContent(mavenMetadataPath);
Metadata metadata = MavenModelUtils.toMavenMetadata(mavenMetadataStr);
Versioning versioning = metadata.getVersioning();
if (versioning != null) {
Snapshot snapshot = versioning.getSnapshot();
if (snapshot != null) {
buildNumber = snapshot.getBuildNumber();
}
}
} else {
// ok probably not found. just log
log.debug("No maven metadata found for {}.", repoPath);
}
} catch (Exception e) {
log.error("Cannot obtain build number from metadata.", e);
}
return buildNumber;
}
示例13: mergeMetadata
import org.apache.maven.artifact.repository.metadata.Metadata; //导入方法依赖的package包/类
private void mergeMetadata( Versions versions, Metadata source, ArtifactRepository repository )
{
Versioning versioning = source.getVersioning();
if ( versioning != null )
{
String timestamp = StringUtils.clean( versioning.getLastUpdated() );
if ( StringUtils.isNotEmpty( versioning.getRelease() )
&& timestamp.compareTo( versions.releaseTimestamp ) > 0 )
{
versions.releaseVersion = versioning.getRelease();
versions.releaseTimestamp = timestamp;
versions.releaseRepository = repository;
}
if ( StringUtils.isNotEmpty( versioning.getLatest() )
&& timestamp.compareTo( versions.latestTimestamp ) > 0 )
{
versions.latestVersion = versioning.getLatest();
versions.latestTimestamp = timestamp;
versions.latestRepository = repository;
}
for ( String version : versioning.getVersions() )
{
if ( !versions.versions.containsKey( version ) )
{
versions.versions.put( version, repository );
}
}
}
}
示例14: merge
import org.apache.maven.artifact.repository.metadata.Metadata; //导入方法依赖的package包/类
/**
* Merges Maven2 repository metadata in received order. Returns {@code null} if passed in iterable is
* empty. The passed in instances are not mutated.
*/
@Nullable
public Metadata merge(final Iterable<Envelope> metadatas) {
checkNotNull(metadatas);
Metadata result = null;
for (Envelope envelope : metadatas) {
if (result == null) {
result = envelope.getData().clone();
}
else {
try {
result = merge(result, envelope.getData().clone());
}
catch (IllegalArgumentException e) {
// leave out, log it
log.warn("Bad data {}", envelope.getOrigin(), e);
}
}
}
if (result == null) {
return null;
}
if (result.getVersioning() != null && !result.getVersioning().getVersions().isEmpty()) {
Collections.sort(result.getVersioning().getVersions(), VersionComparator.INSTANCE);
// the last in ordered list
String latest = result.getVersioning().getVersions().get(result.getVersioning().getVersions().size() - 1);
// the last non-snapshot in ordered list, may be null
String release = null;
for (int i = result.getVersioning().getVersions().size() - 1; i >= 0; i--) {
if (!result.getVersioning().getVersions().get(i).endsWith(Constants.SNAPSHOT_VERSION_SUFFIX)) {
release = result.getVersioning().getVersions().get(i);
break;
}
}
result.getVersioning().setLatest(latest);
result.getVersioning().setRelease(release);
}
if (!result.getPlugins().isEmpty()) {
Collections.sort(result.getPlugins(), pluginComparator);
}
// model version, just set it to latest, we don't care about it now
result.setModelVersion(ModelVersion.V1_1_0.getVersionString());
return result;
}
示例15: merge
import org.apache.maven.artifact.repository.metadata.Metadata; //导入方法依赖的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);
}
}
}
}
}