List of usage examples for org.apache.maven.artifact.repository.metadata RepositoryMetadata getMetadata
Metadata getMetadata();
From source file:com.aquent.mojo.delivery.RemoteVersionMojo.java
License:Open Source License
@SuppressWarnings("unchecked") public void execute() { defineVersionProperty("version", 0); defineVersionProperty("majorVersion", 0); defineVersionProperty("minorVersion", 0); defineVersionProperty("incrementalVersion", 0); try {// w w w. j a va2 s.com Artifact artifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), "", "", ""); RepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact); repositoryMetadataManager.resolveAlways(metadata, localRepository, getRemoteRepository()); if (metadata.getMetadata() != null && metadata.getMetadata().getVersioning() != null) { List<String> allVersions = metadata.getMetadata().getVersioning().getVersions(); ArtifactVersion foundVersion = null; for (String version : allVersions) { ArtifactVersion artifactVersion = new DefaultArtifactVersion(version); if (foundVersion == null || artifactVersion.compareTo(foundVersion) > 0) { foundVersion = artifactVersion; } } if (foundVersion != null) { defineVersionProperty("version", foundVersion.toString()); defineVersionProperty("majorVersion", foundVersion.getMajorVersion()); defineVersionProperty("minorVersion", foundVersion.getMinorVersion()); defineVersionProperty("incrementalVersion", foundVersion.getIncrementalVersion()); } } } catch (RepositoryMetadataResolutionException ex) { getLog().warn(ex.toString()); } }
From source file:hudson.maven.artifact.transform.AbstractVersionTransformation.java
License:Apache License
protected String resolveVersion(Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories) throws RepositoryMetadataResolutionException { RepositoryMetadata metadata; // Don't use snapshot metadata for LATEST (which isSnapshot returns true for) if (!artifact.isSnapshot() || Artifact.LATEST_VERSION.equals(artifact.getBaseVersion())) { metadata = new ArtifactRepositoryMetadata(artifact); } else {/*from w w w . j a va 2 s.co m*/ metadata = new SnapshotArtifactRepositoryMetadata(artifact); } repositoryMetadataManager.resolve(metadata, remoteRepositories, localRepository); artifact.addMetadata(metadata); Metadata repoMetadata = metadata.getMetadata(); String version = null; if (repoMetadata != null && repoMetadata.getVersioning() != null) { version = constructVersion(repoMetadata.getVersioning(), artifact.getBaseVersion()); } if (version == null) { // use the local copy, or if it doesn't exist - go to the remote repo for it version = artifact.getBaseVersion(); } // TODO: also do this logging for other metadata? // TODO: figure out way to avoid duplicated message if (getLogger().isDebugEnabled()) { if (!version.equals(artifact.getBaseVersion())) { String message = artifact.getArtifactId() + ": resolved to version " + version; if (artifact.getRepository() != null) { message += " from repository " + artifact.getRepository().getId(); } else { message += " from local repository"; } getLogger().debug(message); } else { // Locally installed file is newer, don't use the resolved version getLogger().debug(artifact.getArtifactId() + ": using locally installed snapshot"); } } return version; }
From source file:hudson.maven.artifact.transform.SnapshotTransformation.java
License:Apache License
public void transformForDeployment(Artifact artifact, ArtifactRepository remoteRepository, ArtifactRepository localRepository) throws ArtifactDeploymentException { if (artifact.isSnapshot()) { Snapshot snapshot = new Snapshot(); if (remoteRepository.isUniqueVersion()) { snapshot.setTimestamp(getDeploymentTimestamp()); }// ww w . j av a 2 s . c o m // 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); } }
From source file:hudson.maven.artifact.transform.SnapshotTransformation.java
License:Apache License
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(); }//w w w.j a va 2 s. c om return buildNumber; }
From source file:org.ck.maven.plugins.pom.versions.service.version.PomVersionRepositoryMetadataManager.java
License:Apache License
private void updateSnapshotMetadata(RepositoryMetadata metadata, Map previousMetadata, ArtifactRepository selected, ArtifactRepository localRepository) throws RepositoryMetadataStoreException { // TODO: this could be a lot nicer... should really be in the snapshot transformation? if (metadata.isSnapshot()) { Metadata prevMetadata = metadata.getMetadata(); for (Iterator i = previousMetadata.keySet().iterator(); i.hasNext();) { ArtifactRepository repository = (ArtifactRepository) i.next(); Metadata m = (Metadata) previousMetadata.get(repository); if (repository.equals(selected)) { if (m.getVersioning() == null) { m.setVersioning(new Versioning()); }//from w w w .j a v a 2s . c o m if (m.getVersioning().getSnapshot() == null) { m.getVersioning().setSnapshot(new Snapshot()); } /* if ( !m.getVersioning().getSnapshot().isLocalCopy() ) { // TODO: I think this is incorrect (it results in localCopy set in a remote profile). Probably // harmless so not removing at this point until full tests in place. m.getVersioning().getSnapshot().setLocalCopy( true ); metadata.setMetadata( m ); metadata.storeInLocalRepository( localRepository, repository ); } */ } else { if ((m.getVersioning() != null) && (m.getVersioning().getSnapshot() != null) && m.getVersioning().getSnapshot().isLocalCopy()) { m.getVersioning().getSnapshot().setLocalCopy(false); metadata.setMetadata(m); metadata.storeInLocalRepository(localRepository, repository); } } } metadata.setMetadata(prevMetadata); } }
From source file:org.ck.maven.plugins.pom.versions.service.version.PomVersionRepositoryMetadataManager.java
License:Apache License
private boolean loadMetadata(RepositoryMetadata repoMetadata, ArtifactRepository remoteRepository, ArtifactRepository localRepository, Map previousMetadata) throws RepositoryMetadataReadException { boolean setRepository = false; File metadataFile = new File(localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata(repoMetadata, remoteRepository)); if (metadataFile.exists()) { Metadata metadata = readMetadata(metadataFile); if (repoMetadata.isSnapshot() && (previousMetadata != null)) { previousMetadata.put(remoteRepository, metadata); }/*w w w . j av a 2 s . c o m*/ if (repoMetadata.getMetadata() != null) { setRepository = repoMetadata.getMetadata().merge(metadata); } else { repoMetadata.setMetadata(metadata); setRepository = true; } } return setRepository; }
From source file:org.codehaus.mojo.pomtools.helpers.MetadataHelper.java
License:Apache License
/** Returns whether the groupId and artifactId appear to be valid. * This differs from {@link #isValidDependencyArtifact(Artifact)} in that the version * can be null or even invalid and still get a positive result * /*from ww w . j av a 2 s.co m*/ * @param artifact * @return */ public boolean isValidGroupIdArtifactId(Artifact artifact) { if (isValidDependencyArtifact(artifact)) { return true; } try { RepositoryMetadata metadata = getMetadata(artifact); return metadata.getMetadata().getVersioning() != null; } catch (ArtifactMetadataRetrievalException e) { return false; } }
From source file:org.codehaus.mojo.pomtools.wrapper.custom.DependencyWrapper.java
License:Apache License
private List getMetadataVersions() throws PomToolsVersionException { metadataGroupId = getGroupId();/*from w w w . j av a 2 s .c o m*/ metadataArtifactId = getArtifactId(); try { PomToolsPluginContext context = PomToolsPluginContext.getInstance(); RepositoryMetadata repoMetadata = context.getMetadataHelper().getMetadata(getArtifact()); if (repoMetadata != null) { Metadata metadata = repoMetadata.getMetadata(); if (metadata != null && metadata.getVersioning() != null) { return metadata.getVersioning().getVersions(); } else if (metadata != null && metadata.getVersion() != null) { // Non provided jars like javax.mail and javax.servlet:servlet-api // don't have versioning sections, so create the list from the single version // specified by the artifact. if (isValidArtifact()) { List metadataVersions = new ArrayList(); metadataVersions.add(metadata.getVersion()); return metadataVersions; } } } return null; } catch (InvalidArtifactRTException e) { throw new PomToolsVersionException(e); } catch (ArtifactMetadataRetrievalException e) { throw new PomToolsVersionException(e); } }
From source file:org.eclipse.ebr.maven.ModelUtil.java
License:Open Source License
public ArtifactVersion resolveArtifactVersion(final String groupId, final String artifactId, final String artifactVersion) throws MojoExecutionException { getLog().debug(format("Reading version metadata for artifact %s:%s.", groupId, artifactId)); final RepositoryRequest request = new DefaultRepositoryRequest(); configureRepositoryRequest(request); final Artifact artifact = repositorySystem.createArtifact(groupId, artifactId, "", null, "pom"); try {/* ww w .j ava 2 s.c o m*/ final RepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact); getRepositoryMetadataManager().resolve(metadata, request); final Metadata repositoryMetadata = checkNotNull(metadata.getMetadata(), "No repository metadata loaded."); if (StringUtils.equals("LATEST", artifactVersion)) { final Versioning metadataVersions = checkNotNull(repositoryMetadata.getVersioning(), "No versioning information available in repository metadata."); getLog().debug(format("Resolving '%s' to latest version.", artifactVersion)); return new DefaultArtifactVersion(metadataVersions.getLatest()); } else if (StringUtils.equals("RELEASE", artifactVersion)) { final Versioning metadataVersions = checkNotNull(repositoryMetadata.getVersioning(), "No versioning information available in repository metadata."); getLog().debug(format("Resolving '%s' to release version.", artifactVersion)); return new DefaultArtifactVersion(metadataVersions.getRelease()); } else { getLog().debug(format("Resolving '%s' to version.", artifactVersion)); return new DefaultArtifactVersion(artifactVersion); } } catch (final Exception e) { getLog().debug(e); throw new MojoExecutionException( format("Unable to retrieve available versions for artifact %s:%s:%s. %s", groupId, artifactId, artifactVersion, e.getMessage())); } }
From source file:org.jetbrains.idea.maven.server.embedder.CustomMaven3RepositoryMetadataManager.java
License:Apache License
@Override public void resolve(RepositoryMetadata metadata, RepositoryRequest request) throws RepositoryMetadataResolutionException { super.resolve(metadata, request); MavenWorkspaceMap map = myWorkspaceMap; if (map == null) return;/*from ww w. ja v a 2s . c o m*/ Metadata data = metadata.getMetadata(); Versioning versioning = data.getVersioning(); if (versioning == null) { data.setVersioning(versioning = new Versioning()); } for (MavenId each : map.getAvailableIds()) { if (each.equals(data.getGroupId(), data.getArtifactId())) { versioning.addVersion(each.getVersion()); } } }