本文整理汇总了Java中org.apache.maven.artifact.repository.metadata.Snapshot类的典型用法代码示例。如果您正苦于以下问题:Java Snapshot类的具体用法?Java Snapshot怎么用?Java Snapshot使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Snapshot类属于org.apache.maven.artifact.repository.metadata包,在下文中一共展示了Snapshot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildSnapshotMavenMetadata
import org.apache.maven.artifact.repository.metadata.Snapshot; //导入依赖的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;
}
示例2: constructVersion
import org.apache.maven.artifact.repository.metadata.Snapshot; //导入依赖的package包/类
protected String constructVersion( Versioning versioning, String baseVersion )
{
String version = null;
Snapshot snapshot = versioning.getSnapshot();
if ( snapshot != null )
{
if ( snapshot.getTimestamp() != null && snapshot.getBuildNumber() > 0 )
{
String newVersion = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber();
version = StringUtils.replace( baseVersion, Artifact.SNAPSHOT_VERSION, newVersion );
}
else
{
version = baseVersion;
}
}
return version;
}
示例3: getBuildNumber
import org.apache.maven.artifact.repository.metadata.Snapshot; //导入依赖的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;
}
示例4: createMetadata
import org.apache.maven.artifact.repository.metadata.Snapshot; //导入依赖的package包/类
private static Metadata createMetadata( Artifact artifact, boolean legacyFormat )
{
Snapshot snapshot = new Snapshot();
snapshot.setLocalCopy( true );
Versioning versioning = new Versioning();
versioning.setSnapshot( snapshot );
Metadata metadata = new Metadata();
metadata.setVersioning( versioning );
metadata.setGroupId( artifact.getGroupId() );
metadata.setArtifactId( artifact.getArtifactId() );
metadata.setVersion( artifact.getBaseVersion() );
if ( !legacyFormat )
{
metadata.setModelVersion( "1.1.0" );
}
return metadata;
}
示例5: getSnapshot
import org.apache.maven.artifact.repository.metadata.Snapshot; //导入依赖的package包/类
public static List<Snapshot> getSnapshot( String response )
{
List<Snapshot> snapshots = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
try
{
snapshots = mapper.readValue( response, new TypeReference<List<Snapshot>>()
{
} );
}
catch ( IOException e )
{
e.printStackTrace();
}
return snapshots;
}
示例6: v
import org.apache.maven.artifact.repository.metadata.Snapshot; //导入依赖的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;
}
示例7: compare
import org.apache.maven.artifact.repository.metadata.Snapshot; //导入依赖的package包/类
@Override
public int compare(Snapshot o1, Snapshot o2) {
long time1 = MavenModelUtils.uniqueSnapshotTimestampToDate(o1.getTimestamp()).getTime();
long time2 = MavenModelUtils.uniqueSnapshotTimestampToDate(o2.getTimestamp()).getTime();
long dif = time1 - time2;
return dif > 0 ? 1 : dif < 0 ? -1 : 0;
}
示例8: getLastBuildNumber
import org.apache.maven.artifact.repository.metadata.Snapshot; //导入依赖的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;
}
示例9: transformForInstall
import org.apache.maven.artifact.repository.metadata.Snapshot; //导入依赖的package包/类
public void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
{
if ( artifact.isSnapshot() )
{
Snapshot snapshot = new Snapshot();
snapshot.setLocalCopy( true );
RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot );
artifact.addMetadata( metadata );
}
}
示例10: transformForDeployment
import org.apache.maven.artifact.repository.metadata.Snapshot; //导入依赖的package包/类
public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
ArtifactRepository localRepository )
throws ArtifactDeploymentException
{
if ( artifact.isSnapshot() )
{
Snapshot snapshot = new Snapshot();
snapshot.setTimestamp( getDeploymentTimestamp() );
// we update the build number anyway so that it doesn't get lost. It requires the timestamp to take effect
try
{
int buildNumber = resolveLatestSnapshotBuildNumber( artifact, localRepository, remoteRepository );
snapshot.setBuildNumber( buildNumber + 1 );
}
catch ( RepositoryMetadataResolutionException e )
{
throw new ArtifactDeploymentException( "Error retrieving previous build number for artifact '"
+ artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
}
RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot );
artifact.setResolvedVersion(
constructVersion( metadata.getMetadata().getVersioning(), artifact.getBaseVersion() ) );
artifact.addMetadata( metadata );
}
}
示例11: merge
import org.apache.maven.artifact.repository.metadata.Snapshot; //导入依赖的package包/类
private void merge( Artifact artifact, Map<String, VersionInfo> infos, Versioning versioning,
ArtifactRepository repository )
{
if ( StringUtils.isNotEmpty( versioning.getRelease() ) )
{
merge( RELEASE, infos, versioning.getLastUpdated(), versioning.getRelease(), repository );
}
if ( StringUtils.isNotEmpty( versioning.getLatest() ) )
{
merge( LATEST, infos, versioning.getLastUpdated(), versioning.getLatest(), repository );
}
for ( SnapshotVersion sv : versioning.getSnapshotVersions() )
{
if ( StringUtils.isNotEmpty( sv.getVersion() ) )
{
String key = getKey( sv.getClassifier(), sv.getExtension() );
merge( SNAPSHOT + key, infos, sv.getUpdated(), sv.getVersion(), repository );
}
}
Snapshot snapshot = versioning.getSnapshot();
if ( snapshot != null && versioning.getSnapshotVersions().isEmpty() )
{
String version = artifact.getVersion();
if ( snapshot.getTimestamp() != null && snapshot.getBuildNumber() > 0 )
{
String qualifier = snapshot.getTimestamp() + '-' + snapshot.getBuildNumber();
version = version.substring( 0, version.length() - SNAPSHOT.length() ) + qualifier;
}
merge( SNAPSHOT, infos, versioning.getLastUpdated(), version, repository );
}
}
示例12: generateMavenMetadata
import org.apache.maven.artifact.repository.metadata.Snapshot; //导入依赖的package包/类
/**
* Generate the maven-metadata-local.xml for the given Maven <code>Artifact</code>.
*
* @param artifact the Maven <code>Artifact</code>.
* @param target the target maven-metadata-local.xml file to generate.
* @throws IOException if the maven-metadata-local.xml can't be generated.
*/
static void generateMavenMetadata(Artifact artifact, File target) throws IOException {
target.getParentFile().mkdirs();
Metadata metadata = new Metadata();
metadata.setGroupId(artifact.getGroupId());
metadata.setArtifactId(artifact.getArtifactId());
metadata.setVersion(artifact.getVersion());
metadata.setModelVersion("1.1.0");
Versioning versioning = new Versioning();
versioning.setLastUpdatedTimestamp(new Date(System.currentTimeMillis()));
Snapshot snapshot = new Snapshot();
snapshot.setLocalCopy(true);
versioning.setSnapshot(snapshot);
SnapshotVersion snapshotVersion = new SnapshotVersion();
snapshotVersion.setClassifier(artifact.getClassifier());
snapshotVersion.setVersion(artifact.getVersion());
snapshotVersion.setExtension(artifact.getType());
snapshotVersion.setUpdated(versioning.getLastUpdated());
versioning.addSnapshotVersion(snapshotVersion);
metadata.setVersioning(versioning);
MetadataXpp3Writer metadataWriter = new MetadataXpp3Writer();
Writer writer = new FileWriter(target);
metadataWriter.write(writer, metadata);
}
示例13: readVersions
import org.apache.maven.artifact.repository.metadata.Snapshot; //导入依赖的package包/类
private Versioning readVersions( RepositorySystemSession session, RequestTrace trace, Metadata metadata,
ArtifactRepository repository, VersionResult result )
{
Versioning versioning = null;
FileInputStream fis = null;
try
{
if ( metadata != null )
{
SyncContext syncContext = syncContextFactory.newInstance( session, true );
try
{
syncContext.acquire( null, Collections.singleton( metadata ) );
if ( metadata.getFile() != null && metadata.getFile().exists() )
{
fis = new FileInputStream( metadata.getFile() );
org.apache.maven.artifact.repository.metadata.Metadata m =
new MetadataXpp3Reader().read( fis, false );
versioning = m.getVersioning();
/*
* NOTE: Users occasionally misuse the id "local" for remote repos which screws up the metadata
* of the local repository. This is especially troublesome during snapshot resolution so we try
* to handle that gracefully.
*/
if ( versioning != null && repository instanceof LocalRepository)
{
if ( versioning.getSnapshot() != null && versioning.getSnapshot().getBuildNumber() > 0 )
{
Versioning repaired = new Versioning();
repaired.setLastUpdated( versioning.getLastUpdated() );
Snapshot snapshot = new Snapshot();
snapshot.setLocalCopy( true );
repaired.setSnapshot( snapshot );
versioning = repaired;
throw new IOException( "Snapshot information corrupted with remote repository data"
+ ", please verify that no remote repository uses the id '" + repository.getId()
+ "'" );
}
}
}
}
finally
{
syncContext.release();
}
}
}
catch ( Exception e )
{
invalidMetadata( session, trace, metadata, repository, e );
result.addException( e );
}
finally
{
IOUtil.close(fis);
}
return ( versioning != null ) ? versioning : new Versioning();
}
示例14: createSnapshotsMetadata
import org.apache.maven.artifact.repository.metadata.Snapshot; //导入依赖的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;
}
示例15: compare
import org.apache.maven.artifact.repository.metadata.Snapshot; //导入依赖的package包/类
@Override
public int compare(Snapshot o1, Snapshot o2) {
int buildNumber1 = o1.getBuildNumber();
int buildNumber2 = o2.getBuildNumber();
return buildNumber1 - buildNumber2;
}