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


Java Snapshot类代码示例

本文整理汇总了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;
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:33,代码来源:MavenModelUtils.java

示例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;
}
 
开发者ID:gems-uff,项目名称:oceano,代码行数:19,代码来源:SnapshotTransformation.java

示例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;
}
 
开发者ID:gems-uff,项目名称:oceano,代码行数:17,代码来源:RemoteSnapshotMetadata.java

示例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;
}
 
开发者ID:gems-uff,项目名称:oceano,代码行数:21,代码来源:LocalSnapshotMetadata.java

示例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;
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:17,代码来源:JsonConverter.java

示例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;
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:39,代码来源:RepositoryMetadataMergerTest.java

示例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;
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:8,代码来源:TimestampSnapshotComparator.java

示例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;
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:30,代码来源:UniqueSnapshotVersionAdapter.java

示例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 );
    }
}
 
开发者ID:gems-uff,项目名称:oceano,代码行数:12,代码来源:SnapshotTransformation.java

示例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 );
    }
}
 
开发者ID:gems-uff,项目名称:oceano,代码行数:32,代码来源:SnapshotTransformation.java

示例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 );
    }
}
 
开发者ID:gems-uff,项目名称:oceano,代码行数:35,代码来源:DefaultVersionResolver.java

示例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);
}
 
开发者ID:retog,项目名称:karaf-maven-plugin,代码行数:34,代码来源:MavenUtil.java

示例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();
}
 
开发者ID:cloudbees,项目名称:bees-maven-components,代码行数:65,代码来源:VersionResolverImpl.java

示例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;
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:52,代码来源:MavenMetadataCalculator.java

示例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;
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:7,代码来源:BuildNumberSnapshotComparator.java


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