List of usage examples for org.apache.maven.artifact.repository.metadata ArtifactRepositoryMetadata getMetadata
public Metadata getMetadata()
From source file:org.codehaus.mojo.mockrepo.ProxyRepository.java
License:Apache License
public Metadata getMetadata(String path) { if (StringUtils.isEmpty(path) || path.length() < 13) { return null; }/*w w w . ja va2 s. co m*/ String coordPath = StringUtils.chompLast(path, "/metadata.xml"); int index = coordPath.lastIndexOf('/'); String artifactId = index == -1 ? null : coordPath.substring(index + 1); String groupId = index == -1 ? null : coordPath.substring(0, index); String pluginGroupId = coordPath.replace('/', '.'); Metadata metadata = new Metadata(); // is this path a groupId:artifactId pair? if (!StringUtils.isEmpty(artifactId) && !StringUtils.isEmpty(groupId)) { final Artifact artifact = artifactFactory.createDependencyArtifact(groupId, artifactId, anyVersion, "pom", null, "compile"); final ArtifactRepositoryMetadata artifactRepositoryMetadata = new ArtifactRepositoryMetadata(artifact); try { repositoryMetadataManager.resolve(artifactRepositoryMetadata, remoteRepositories, localRepository); final Metadata artifactMetadata = artifactRepositoryMetadata.getMetadata(); if (artifactMetadata.getVersioning() != null) { metadata.setGroupId(groupId); metadata.setArtifactId(artifactId); metadata.merge(artifactMetadata); } } catch (RepositoryMetadataResolutionException e) { log.debug(e); } } // if this path a groupId on its own? final GroupRepositoryMetadata groupRepositoryMetadata = new GroupRepositoryMetadata(pluginGroupId); try { repositoryMetadataManager.resolve(groupRepositoryMetadata, remotePluginRepositories, localRepository); metadata.merge(groupRepositoryMetadata.getMetadata()); } catch (RepositoryMetadataResolutionException e) { log.debug(e); } return metadata; }
From source file:org.commonjava.emb.component.vfind.VersionFinder.java
License:Apache License
protected List<String> retrieveMatchingVersions(final String groupId, final String artifactId, final SchemeAwareVersionRange range, final Repository... remoteRepositories) throws VersionFinderException, EMBArtifactVersionException { final List<ArtifactRepository> repos = new ArrayList<ArtifactRepository>( remoteRepositories == null ? 0 : remoteRepositories.length); if (remoteRepositories != null) { for (final Repository repository : remoteRepositories) { try { repos.add(repositorySystem.buildArtifactRepository(repository)); } catch (final InvalidRepositoryException e) { throw new VersionFinderException("Failed to build ArtifactRepository from: %s\nReason: %s", e, repository, e.getMessage()); }// w ww.j a v a 2 s .com } } final Artifact artifact = repositorySystem.createArtifact(groupId, artifactId, range.toString(), "pom"); DefaultMetadataResolutionRequest req; try { req = new DefaultMetadataResolutionRequest().setArtifact(artifact).setForceUpdate(true) .setRemoteRepositories(repos) .setLocalRepository(repositorySystem.createDefaultLocalRepository()); } catch (final InvalidRepositoryException e) { throw new VersionFinderException("Failed to build LOCAL ArtifactRepository.\nReason: %s", e, e.getMessage()); } final ArtifactRepositoryMetadata arm = new ArtifactRepositoryMetadata(artifact); try { metadataManager.resolve(arm, req); } catch (final RepositoryMetadataResolutionException e) { throw new VersionFinderException("Failed to resolve available versions for: %s\nReason: %s", e, artifact, e.getMessage()); } if (arm.getMetadata() != null && arm.getMetadata().getVersioning() != null) { final List<String> versions = arm.getMetadata().getVersioning().getVersions(); if (versions != null && !versions.isEmpty()) { final List<String> result = new ArrayList<String>(versions.size()); for (final String version : versions) { final ArtifactVersion v = new SchemeAwareArtifactVersion(version, range.getVersionScheme()); if (range.containsVersion(v)) { result.add(version); } } return result; } } return null; }
From source file:org.echocat.jomon.maven.boot.ArtifactFactory.java
License:Mozilla Public License
@Nullable protected String selectLatestMatchingVersion(@Nonnull ArtifactRepositoryMetadata repositoryMetadata, @Nonnull Artifact artifact) {/*from www .ja v a 2s .c o m*/ final Metadata metadata = repositoryMetadata.getMetadata(); String latestMatchingVersion = null; final Versioning versioning = metadata.getVersioning(); if (versioning != null) { final List<String> versions = versioning.getVersions(); final ListIterator<String> i = versions.listIterator(versions.size()); final VersionRange versionRange = artifact.getVersionRange(); while (i.hasPrevious() && isEmpty(latestMatchingVersion)) { final String current = i.previous(); if (versionRange.containsVersion(new DefaultArtifactVersion(current))) { latestMatchingVersion = current; } } } return latestMatchingVersion; }