List of usage examples for org.apache.maven.artifact Artifact getBaseVersion
String getBaseVersion();
From source file:at.yawk.mdep.GenerateMojo.java
@Nullable
@SneakyThrows({ MalformedURLException.class, NoSuchAlgorithmException.class })
@VisibleForTesting// w ww . ja va 2 s . c om
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:at.yawk.mdep.GenerateMojo.java
private static String getArtifactPath(Artifact artifact, String version) { StringBuilder builder = new StringBuilder().append(artifact.getGroupId().replace('.', '/')).append('/') .append(artifact.getArtifactId()).append('/').append(artifact.getBaseVersion()).append('/') .append(artifact.getArtifactId()).append('-').append(version); if (artifact.getArtifactHandler().getClassifier() != null) { builder.append('-').append(artifact.getArtifactHandler().getClassifier()); }/* www . j a v a 2 s . c om*/ String extension = artifact.getArtifactHandler().getExtension(); if (extension == null) { extension = "jar"; } return builder.append('.').append(extension).toString(); }
From source file:br.com.uggeri.maven.builder.mojo.ArtifactUtil.java
public final static String artifactName(Artifact artifact) { StringBuilder sb = new StringBuilder(); sb.append(artifact.getArtifactId()).append('-'); if (artifact.getVersion().isEmpty()) { sb.append(artifact.getBaseVersion()); } else {//from ww w. jav a 2s . co m sb.append(artifact.getVersion()); } if (artifact.hasClassifier()) { sb.append('-').append(artifact.getClassifier()); } sb.append('.').append(artifact.getType()); return sb.toString(); }
From source file:br.com.uggeri.maven.builder.mojo.ArtifactUtil.java
public final static String artifactPomName(Artifact artifact) { StringBuilder sb = new StringBuilder(); sb.append(artifact.getArtifactId()).append('-'); if (artifact.getVersion().isEmpty()) { sb.append(artifact.getBaseVersion()); } else {/*from www .j a v a2s . c o m*/ sb.append(artifact.getVersion()); } if (artifact.hasClassifier()) { sb.append('-').append(artifact.getClassifier()); } sb.append(".pom"); return sb.toString(); }
From source file:ch.sourcepond.maven.plugin.repobuilder.TargetPathFactory.java
License:Apache License
/** * @param pArtifact/*from ww w. ja v a2s .co m*/ * @return */ private String toArtifactFileName(final Artifact pArtifact) { final StringBuilder b = new StringBuilder(pArtifact.getArtifactId()).append("-") .append(pArtifact.getBaseVersion()); if (!isBlank(pArtifact.getClassifier())) { b.append("-").append(pArtifact.getClassifier()); } return b.append(".").append(pArtifact.getArtifactHandler().getExtension()).toString(); }
From source file:ch.sourcepond.maven.plugin.repobuilder.TargetPathFactory.java
License:Apache License
/** * @param pRepository//from w ww.java 2s . c om * @param pArtifact * @return */ public Path createTargetPath(final Path pRepository, final Artifact pArtifact) { return createGroupFolders(pRepository, pArtifact.getGroupId()).resolve(pArtifact.getArtifactId()) .resolve(pArtifact.getBaseVersion()).resolve(toArtifactFileName(pArtifact)); }
From source file:com.actility.maven.plugin.cocoon.DependencyUtil.java
License:Apache License
/** * Formats the outputDirectory based on type. * * @param useSubdirsPerType if a new sub directory should be used for each type. * @param useSubdirPerArtifact if a new sub directory should be used for each artifact. * @param useRepositoryLayout if dependencies must be moved into a Maven repository layout, if set, other settings will be * ignored.//from ww w. ja v a2 s . c o m * @param removeVersion if the version must not be mentioned in the filename * @param outputDirectory base outputDirectory. * @param artifact information about the artifact. * @return a formatted File object to use for output. */ public static File getFormattedOutputDirectory(boolean useSubdirsPerScope, boolean useSubdirsPerType, boolean useSubdirPerArtifact, boolean useRepositoryLayout, boolean removeVersion, File outputDirectory, Artifact artifact) { StringBuffer sb = new StringBuffer(128); if (useRepositoryLayout) { // group id sb.append(artifact.getGroupId().replace('.', File.separatorChar)).append(File.separatorChar); // artifact id sb.append(artifact.getArtifactId()).append(File.separatorChar); // version sb.append(artifact.getBaseVersion()).append(File.separatorChar); } else { if (useSubdirsPerScope) { sb.append(artifact.getScope()).append(File.separatorChar); } if (useSubdirsPerType) { sb.append(artifact.getType()).append("s").append(File.separatorChar); } if (useSubdirPerArtifact) { String artifactString = getDependencyId(artifact, removeVersion); sb.append(artifactString).append(File.separatorChar); } } return new File(outputDirectory, sb.toString()); }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.EclipsePlugin.java
License:Apache License
/** {@inheritDoc} */ public String getProjectNameForArifact(Artifact artifact) { IdeDependency[] workspaceArtefacts = getWorkspaceArtefacts(); for (int index = 0; workspaceArtefacts != null && index < workspaceArtefacts.length; index++) { IdeDependency workspaceArtefact = workspaceArtefacts[index]; if (workspaceArtefact.isAddedToClasspath() && workspaceArtefact.getGroupId().equals(artifact.getGroupId()) && workspaceArtefact.getArtifactId().equals(artifact.getArtifactId())) { if (workspaceArtefact.getVersion().equals(artifact.getBaseVersion())) { return workspaceArtefact.getEclipseProjectName(); }//w w w . java 2 s .c om } } MavenProject reactorProject = getReactorProject(artifact); if (reactorProject != null) { return IdeUtils.getProjectName(getProjectNameTemplateForMavenProject(reactorProject), artifact); } return IdeUtils.getProjectName(getProjectNameTemplate(), artifact); }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.EclipsePlugin.java
License:Apache License
/** * Utility method that locates a project in the workspace for the given artifact. * * @param artifact the artifact a project should produce. * @return <code>true</code> if the artifact is produced by a reactor projectart. *///from w ww . j a v a 2 s.c o m private boolean isAvailableAsAWorkspaceProject(Artifact artifact) { IdeDependency[] workspaceArtefacts = getWorkspaceArtefacts(); for (int index = 0; workspaceArtefacts != null && index < workspaceArtefacts.length; index++) { IdeDependency workspaceArtefact = workspaceArtefacts[index]; if (workspaceArtefact.getGroupId().equals(artifact.getGroupId()) && workspaceArtefact.getArtifactId().equals(artifact.getArtifactId())) { if (workspaceArtefact.getVersion().equals(artifact.getBaseVersion())) { workspaceArtefact.setAddedToClasspath(true); getLog().debug("Using workspace project: " + workspaceArtefact.getEclipseProjectName()); return true; } else { getLog().info("Artifact " + artifact.getId() + " already available as a workspace project, but with different version. Expected: " + artifact.getBaseVersion() + ", found: " + workspaceArtefact.getVersion()); } } } return false; }
From source file:com.coderplus.utils.apache.DependencyUtil.java
License:Apache License
/** * Builds the file name. If removeVersion is set, then the file name must be * reconstructed from the groupId (if <b>prependGroupId</b> is true) artifactId, * Classifier (if used) and Type.//from ww w . j a v a2 s. c o m * Otherwise, this method returns the artifact file name. * * @param artifact * File to be formatted. * @param removeVersion * Specifies if the version should be removed from the file name. * @param prependGroupId * Specifies if the groupId should be prepended to the file name. * @param useBaseVersion * Specifies if the baseVersion of the artifact should be used instead of the version. * @param removeClassifier * Specifies if the classifier of the artifact should be remved from the file name. * @return Formatted file name in the format * [groupId].artifactId-[version]-[classifier].[type] */ public static String getFormattedFileName(Artifact artifact, boolean removeVersion, boolean prependGroupId, boolean useBaseVersion, boolean removeClassifier) { StringBuilder destFileName = new StringBuilder(); if (prependGroupId) { destFileName.append(artifact.getGroupId()).append("."); } String versionString; if (!removeVersion) { if (useBaseVersion) { versionString = "-" + artifact.getBaseVersion(); } else { versionString = "-" + artifact.getVersion(); } } else { versionString = ""; } String classifierString = ""; if (!removeClassifier && StringUtils.isNotEmpty(artifact.getClassifier())) { classifierString = "-" + artifact.getClassifier(); } destFileName.append(artifact.getArtifactId()).append(versionString); destFileName.append(classifierString).append("."); destFileName.append(artifact.getArtifactHandler().getExtension()); return destFileName.toString(); }