List of usage examples for org.apache.maven.artifact.repository ArtifactRepository pathOfRemoteRepositoryMetadata
String pathOfRemoteRepositoryMetadata(ArtifactMetadata artifactMetadata);
From source file:at.yawk.mdep.GenerateMojo.java
@Nullable @SneakyThrows({ MalformedURLException.class, NoSuchAlgorithmException.class }) @VisibleForTesting/*w ww. j a v a2 s.c o m*/ Dependency findArtifactInRepository(Artifact artifact, ArtifactRepository repository) throws MojoExecutionException { String artifactPath = getArtifactPath(artifact, artifact.getVersion()); if (artifact.isSnapshot()) { ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact) { // maven is weird - i have yet to find a better solution. @Override public boolean storedInArtifactVersionDirectory() { return true; } @Override public String getBaseVersion() { return artifact.getBaseVersion(); } }; // try to load maven-metadata.xml in case we need to use a different version for snapshots URL metaUrl = new URL(repository.getUrl() + '/' + repository.pathOfRemoteRepositoryMetadata(metadata)); Metadata loadedMetadata; try (InputStream input = openStream(metaUrl)) { loadedMetadata = new MetadataXpp3Reader().read(input, true); } catch (IOException e) { // could not find metadata loadedMetadata = null; } catch (XmlPullParserException e) { throw new MojoExecutionException("Failed to parse metadata", e); } if (loadedMetadata != null) { Snapshot snapshot = loadedMetadata.getVersioning().getSnapshot(); String versionWithoutSuffix = artifact.getVersion().substring(0, artifact.getBaseVersion().lastIndexOf('-')); artifactPath = getArtifactPath(artifact, versionWithoutSuffix + '-' + snapshot.getTimestamp() + '-' + snapshot.getBuildNumber()); } } URL url = new URL(repository.getUrl() + '/' + artifactPath); try (InputStream input = openStream(url)) { getLog().info("Getting checksum for " + artifact); MessageDigest digest = MessageDigest.getInstance("SHA-512"); byte[] buf = new byte[4096]; int len; while ((len = input.read(buf)) >= 0) { digest.update(buf, 0, len); } Dependency dependency = new Dependency(); dependency.setUrl(url); dependency.setSha512sum(digest.digest()); return dependency; } catch (IOException ignored) { // not in this repo return null; } }
From source file:org.apache.archiva.converter.artifact.LegacyToDefaultConverter.java
License:Apache License
private boolean validateMetadata(Artifact artifact) throws ArtifactConversionException { ArtifactRepository repository = artifact.getRepository(); boolean result = true; RepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata(artifact); File file = new File(repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata(repositoryMetadata)); if (file.exists()) { Metadata metadata = readMetadata(file); result = validateMetadata(metadata, repositoryMetadata, artifact); }/*from ww w .ja va 2 s . c o m*/ repositoryMetadata = new SnapshotArtifactRepositoryMetadata(artifact); file = new File(repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata(repositoryMetadata)); if (file.exists()) { Metadata metadata = readMetadata(file); result = result && validateMetadata(metadata, repositoryMetadata, artifact); } return result; }
From source file:org.apache.archiva.converter.artifact.LegacyToDefaultConverter.java
License:Apache License
private void updateMetadata(RepositoryMetadata artifactMetadata, ArtifactRepository targetRepository, Metadata newMetadata, FileTransaction transaction) throws ArtifactConversionException { File file = new File(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(artifactMetadata)); Metadata metadata;/*from w w w .j a v a 2 s . com*/ boolean changed; if (file.exists()) { metadata = readMetadata(file); changed = metadata.merge(newMetadata); } else { changed = true; metadata = newMetadata; } if (changed) { try (StringWriter writer = new StringWriter()) { MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer(); mappingWriter.write(writer, metadata); transaction.createFile(writer.toString(), file, digesters); } catch (IOException e) { throw new ArtifactConversionException(Messages.getString("error.writing.target.metadata"), e); //$NON-NLS-1$ } } }