本文整理汇总了Java中org.apache.maven.artifact.repository.metadata.Metadata类的典型用法代码示例。如果您正苦于以下问题:Java Metadata类的具体用法?Java Metadata怎么用?Java Metadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Metadata类属于org.apache.maven.artifact.repository.metadata包,在下文中一共展示了Metadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatJarNameFromMeta
import org.apache.maven.artifact.repository.metadata.Metadata; //导入依赖的package包/类
@NotNull
@Contract("null, null -> fail")
private static String formatJarNameFromMeta(Dependency dependency, Metadata metadata) {
/* Explicit NPE */
//noinspection ResultOfMethodCallIgnored
dependency.getClass();
//noinspection ResultOfMethodCallIgnored
metadata.getClass();
try {
return dependency.getArtifactId()
+ "-" +
dependency.getVersion().replaceAll("-SNAPSHOT", "")
+ "-" +
metadata.getVersioning().getSnapshot().getTimestamp()
+ "-" +
metadata.getVersioning().getSnapshot().getBuildNumber()
+ ".jar";
} catch (NullPointerException e) {
/* Dear god, there are so many different formats of maven metadatas... */
return formatJarNameFromDependency(dependency);
}
}
示例2: 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();
}
示例3: mergePlugins
import org.apache.maven.artifact.repository.metadata.Metadata; //导入依赖的package包/类
/**
* Merges "right" plugins into "left", the instances are mutated.
*/
private void mergePlugins(final Metadata left, final Metadata right) {
nullElementFilter(left.getPlugins());
nullElementFilter(right.getPlugins());
for (Plugin plugin : right.getPlugins()) {
boolean found = false;
for (Plugin preExisting : left.getPlugins()) {
if (Objects.equals(preExisting.getArtifactId(), plugin.getArtifactId())
&& Objects.equals(preExisting.getPrefix(), plugin.getPrefix())) {
found = true;
preExisting.setName(plugin.getName());
break;
}
}
if (!found) {
Plugin newPlugin = new Plugin();
newPlugin.setArtifactId(plugin.getArtifactId());
newPlugin.setPrefix(plugin.getPrefix());
newPlugin.setName(plugin.getName());
left.addPlugin(newPlugin);
}
}
}
示例4: write
import org.apache.maven.artifact.repository.metadata.Metadata; //导入依赖的package包/类
/**
* Writes passed in metadata as XML.
*/
public static void write(final Repository repository, final MavenPath mavenPath, final Metadata metadata)
throws IOException
{
MavenFacet mavenFacet = repository.facet(MavenFacet.class);
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
MavenModels.writeMetadata(buffer, metadata);
mavenFacet.put(mavenPath, new BytesPayload(buffer.toByteArray(),
MavenMimeRulesSource.METADATA_TYPE));
final Map<HashAlgorithm, HashCode> hashCodes = mavenFacet.get(mavenPath).getAttributes()
.require(Content.CONTENT_HASH_CODES_MAP, Content.T_CONTENT_HASH_CODES_MAP);
checkState(hashCodes != null, "hashCodes");
for (HashType hashType : HashType.values()) {
MavenPath checksumPath = mavenPath.hash(hashType);
HashCode hashCode = hashCodes.get(hashType.getHashAlgorithm());
checkState(hashCode != null, "hashCode: type=%s", hashType);
mavenFacet.put(checksumPath, new StringPayload(hashCode.toString(), Constants.CHECKSUM_CONTENT_TYPE));
}
}
示例5: 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;
}
示例6: groupLevelMd
import org.apache.maven.artifact.repository.metadata.Metadata; //导入依赖的package包/类
@Test
public void groupLevelMd() throws Exception {
final Metadata m1 = g("foo");
final Metadata m2 = g("foo", "bar");
final Metadata m3 = g("baz");
final Metadata m = merger.merge(
ImmutableList.of(new Envelope("1", m1), new Envelope("2", m2), new Envelope("3", m3))
);
assertThat(m, notNullValue());
assertThat(m.getModelVersion(), equalTo("1.1.0"));
assertThat(m.getPlugins(), hasSize(3));
final List<String> prefixes = Lists.newArrayList(Iterables.transform(m.getPlugins(), new Function<Plugin, String>()
{
@Override
public String apply(final Plugin input) {
return input.getArtifactId();
}
}));
assertThat(prefixes, containsInAnyOrder("foo-maven-plugin", "bar-maven-plugin", "baz-maven-plugin"));
}
示例7: artifactLevelMd
import org.apache.maven.artifact.repository.metadata.Metadata; //导入依赖的package包/类
@Test
public void artifactLevelMd() throws Exception {
final Metadata m1 = a("org.foo", "some-project", "20150324121500", "1.0.1", "1.0.1", "1.0.0", "1.0.1");
final Metadata m2 = a("org.foo", "some-project", "20150324121700", "1.0.2", "1.0.2", "1.0.2");
final Metadata m3 = a("org.foo", "some-project", "20150324121600", "1.1.0-SNAPSHOT", null, "1.1.0-SNAPSHOT");
final Metadata m = merger.merge(
ImmutableList.of(new Envelope("1", m1), new Envelope("2", m2), new Envelope("3", m3))
);
assertThat(m, notNullValue());
assertThat(m.getModelVersion(), equalTo("1.1.0"));
assertThat(m.getGroupId(), equalTo("org.foo"));
assertThat(m.getArtifactId(), equalTo("some-project"));
assertThat(m.getVersioning().getLastUpdated(), equalTo("20150324121700"));
assertThat(m.getVersioning().getSnapshot(), nullValue());
assertThat(m.getVersioning().getRelease(), equalTo("1.0.2"));
assertThat(m.getVersioning().getLatest(), equalTo("1.1.0-SNAPSHOT"));
assertThat(m.getVersioning().getVersions(), contains("1.0.0", "1.0.1", "1.0.2", "1.1.0-SNAPSHOT"));
}
示例8: versionLevelMd
import org.apache.maven.artifact.repository.metadata.Metadata; //导入依赖的package包/类
@Test
public void versionLevelMd() throws Exception {
final Metadata m1 = v("org.foo", "some-project", "1.0.0", "20150324.121500", 3);
final Metadata m2 = v("org.foo", "some-project", "1.0.0", "20150323.121500", 2);
final Metadata m3 = v("org.foo", "some-project", "1.0.0", "20150322.121500", 1);
final Metadata m = merger.merge(
ImmutableList.of(new Envelope("1", m1), new Envelope("2", m2), new Envelope("3", m3))
);
assertThat(m, notNullValue());
assertThat(m.getModelVersion(), equalTo("1.1.0"));
assertThat(m.getGroupId(), equalTo("org.foo"));
assertThat(m.getArtifactId(), equalTo("some-project"));
assertThat(m.getVersioning().getLastUpdated(), equalTo("20150324121500"));
assertThat(m.getVersioning().getSnapshot(), notNullValue());
assertThat(m.getVersioning().getSnapshot().getTimestamp(), equalTo("20150324.121500"));
assertThat(m.getVersioning().getSnapshot().getBuildNumber(), equalTo(3));
}
示例9: allowVersionInArtifactLevelMetadata
import org.apache.maven.artifact.repository.metadata.Metadata; //导入依赖的package包/类
/**
* NEXUS-13085
* Some maven-metadata.xml files are contrary to the present spec
* (http://maven.apache.org/ref/3.3.9/maven-repository-metadata/repository-metadata.html) and contain a 'version'
* element for non-SNAPSHOT artifacts, allowing for lax validation.
*/
@Test
public void allowVersionInArtifactLevelMetadata() {
Metadata m1 = a("org.foo", "some-project", "20150324121500", "1.0.0","1.0.0", "1.0.0");
m1.setVersion("1.0.0");
Metadata m2 = a("org.foo", "some-project", "20150324121501", "1.0.1","1.0.1", "1.0.1");
m2.setVersion("1.0.1");
final Metadata m = merger.merge(
ImmutableList.of(new Envelope("1", m1), new Envelope("2", m2))
);
assertThat(m.getVersion(), is(m1.getVersion())); // target version is left intact, no attempt to merge
assertThat(m.getVersioning().getRelease(), is(m2.getVersion()));
assertThat(m.getVersioning().getLastUpdated(), is(m2.getVersioning().getLastUpdated()));
assertThat(m.getVersioning().getVersions(), contains("1.0.0", "1.0.1"));
}
示例10: getSize
import org.apache.maven.artifact.repository.metadata.Metadata; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public long getSize()
throws IOException
{
try
{
Metadata metadata = store.getMetadata( path );
MetadataXpp3Writer writer = new MetadataXpp3Writer();
StringWriter stringWriter = new StringWriter();
writer.write( stringWriter, metadata );
return stringWriter.toString().getBytes().length;
}
catch ( MetadataNotFoundException e )
{
IOException ioe = new IOException( "File not found" );
ioe.initCause( e );
throw ioe;
}
}
示例11: getInputStream
import org.apache.maven.artifact.repository.metadata.Metadata; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public InputStream getInputStream()
throws IOException
{
try
{
Metadata metadata = store.getMetadata( path );
MetadataXpp3Writer writer = new MetadataXpp3Writer();
StringWriter stringWriter = new StringWriter();
writer.write( stringWriter, metadata );
return new ByteArrayInputStream( stringWriter.toString().getBytes() );
}
catch ( MetadataNotFoundException e )
{
return null;
}
}
示例12: 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 );
}
示例13: buildSnapshotMavenMetadata
import org.apache.maven.artifact.repository.metadata.Metadata; //导入依赖的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;
}
示例14: buildReleasesMavenMetadata
import org.apache.maven.artifact.repository.metadata.Metadata; //导入依赖的package包/类
public static Metadata buildReleasesMavenMetadata(String organization, String module,
SortedSet<String> sortedVersions) {
Metadata metadata = new Metadata();
metadata.setGroupId(organization);
metadata.setArtifactId(module);
if (!sortedVersions.isEmpty()) {
metadata.setVersion(sortedVersions.first());
Versioning versioning = new Versioning();
metadata.setVersioning(versioning);
versioning.setVersions(Lists.newArrayList(sortedVersions));
versioning.setLastUpdatedTimestamp(new Date());
versioning.setLatest(sortedVersions.last());
versioning.setRelease(sortedVersions.last());
}
return metadata;
}
示例15: 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);
}