List of usage examples for org.apache.maven.artifact Artifact isSnapshot
boolean isSnapshot();
From source file:at.yawk.mdep.GenerateMojo.java
@Nullable @SneakyThrows({ MalformedURLException.class, NoSuchAlgorithmException.class }) @VisibleForTesting//from ww w . jav a2 s.co 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:ch.sourcepond.maven.plugin.repobuilder.RepositorySwitch.java
License:Apache License
/** * Determines the path where to create a Maven repository structure for the * artifact specified (see <a href=/*w w w . j a v a2 s . c o m*/ * "https://cwiki.apache.org/confluence/display/MAVENOLD/Repository+Layout+-+ * Final">Repository Layout - Final</a>, section "The new layout"). * * @param pArtifact * Artifact for which to create a repository layout, must not be * {@code null} * @return Directory where to create the repository layout, never * {@code null} */ public Path getRepository(final Artifact pArtifact) { final Path repository; if (snapshotRepositoryOrNull != null && pArtifact.isSnapshot()) { repository = root.resolve(snapshotRepositoryOrNull); } else if (releaseRepositoryOrNull != null && !pArtifact.isSnapshot()) { repository = root.resolve(releaseRepositoryOrNull); } else { repository = root; } return repository; }
From source file:com.actility.maven.plugin.cocoon.DestFileFilter.java
License:Apache License
public boolean isArtifactIncluded(ArtifactItem item) { Artifact artifact = item.getArtifact(); boolean overWrite = (artifact.isSnapshot() && this.overWriteSnapshots) || (!artifact.isSnapshot() && this.overWriteReleases); File destFolder = item.getOutputDirectory(); if (destFolder == null) { destFolder = DependencyUtil.getFormattedOutputDirectory(useSubDirectoryPerScope, useSubDirectoryPerType, useSubDirectoryPerArtifact, useRepositoryLayout, removeVersion, this.outputFileDirectory, artifact);// w ww . j a va2s.c om } File destFile = null; if (StringUtils.isEmpty(item.getDestFileName())) { destFile = new File(destFolder, DependencyUtil.getFormattedFileName(artifact, this.removeVersion)); } else { destFile = new File(destFolder, item.getDestFileName()); } return overWrite || !destFile.exists() || (overWriteIfNewer && artifact.getFile().lastModified() > destFile.lastModified()); }
From source file:com.ariatemplates.attester.maven.ArtifactExtractor.java
License:Apache License
public static File getOutputDirectory(Artifact artifact) { File tempDirectory = new File(System.getProperty("java.io.tmpdir")); String name = artifact.getGroupId() + "-" + artifact.getArtifactId() + "-" + artifact.getVersion() + "-" + artifact.getClassifier();/*w w w. j a va2 s. c o m*/ if (artifact.isSnapshot()) { name += "-" + artifact.getFile().lastModified(); } File res = new File(tempDirectory, name); return res; }
From source file:com.bugvm.maven.plugin.AbstractBugVMMojo.java
License:Apache License
protected File unpackBugVMDist() throws MojoExecutionException { Artifact distTarArtifact = resolveBugVMDistArtifact(); File distTarFile = distTarArtifact.getFile(); File unpackBaseDir;/*www . j a va 2 s .co m*/ if (home != null) { unpackBaseDir = home; } else { // by default unpack into the local repo directory unpackBaseDir = new File(distTarFile.getParent(), "unpacked"); } if (unpackBaseDir.exists() && distTarArtifact.isSnapshot()) { getLog().debug("Deleting directory for unpacked snapshots: " + unpackBaseDir); try { FileUtils.deleteDirectory(unpackBaseDir); } catch (IOException e) { throw new MojoExecutionException("Failed to delete " + unpackBaseDir, e); } } unpack(distTarFile, unpackBaseDir); File unpackedDir = new File(unpackBaseDir, "bugvm-" + getBugVMVersion()); return unpackedDir; }
From source file:com.bugvm.maven.plugin.AbstractBugVMMojo.java
License:Apache License
protected Artifact resolveArtifact(Artifact artifact) throws MojoExecutionException { ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact);/*from ww w.ja v a 2 s.c o m*/ if (artifact.isSnapshot()) { request.setForceUpdate(true); } request.setLocalRepository(localRepository); final List<ArtifactRepository> remoteRepositories = project.getRemoteArtifactRepositories(); request.setRemoteRepositories(remoteRepositories); getLog().debug("Resolving artifact " + artifact); ArtifactResolutionResult result = artifactResolver.resolve(request); if (!result.isSuccess()) { throw new MojoExecutionException("Unable to resolve artifact: " + artifact); } Collection<Artifact> resolvedArtifacts = result.getArtifacts(); artifact = (Artifact) resolvedArtifacts.iterator().next(); return artifact; }
From source file:com.ericsson.tools.cpp.compiler.dependencies.DependencyExtractor.java
License:Apache License
boolean isUpdatedSnapshot(final Artifact artifact, final File destination) { if (!artifact.isSnapshot()) return false; return artifact.getFile().lastModified() > destination.lastModified(); }
From source file:com.ericsson.tools.cpp.compiler.TargetCurrencyVerifier.java
License:Apache License
private void addMutableAncestorModelFiles(final Collection<File> collection, final MavenProject parent) { if (parent == null) return;/* w ww . j a v a 2 s. com*/ final Artifact parentPomArtifact = artifactManager.createProjectArtifact(parent); if (!parentPomArtifact.isSnapshot()) { log.debug("Parent " + parent + " isn't a SNAPSHOT. Ancenstry will not be searched for further mutable configurations."); return; } final File parentPomFile = artifactManager.getPomOfArtifact(parentPomArtifact); log.debug("Found mutable parent file " + parentPomFile); collection.add(parentPomFile); addMutableAncestorModelFiles(collection, parent.getParent()); }
From source file:com.github.maven.plugin.DeployGithubRepositoryArtifactMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { if (!skipUpload) { try {/*w w w. j a v a 2s .c o m*/ //if no artifacts are configured, upload main artifact and attached artifacts if (artifacts == null) { final String projectDescription = mavenProject.getDescription(); final Set<Artifact> githubArtifacts = new HashSet<Artifact>(); final DirectoryScanner scanner = new DirectoryScanner(); scanner.setExcludes(excludes); scanner.setBasedir(mavenProject.getBuild().getDirectory()); scanner.scan(); final List<String> includedFiles = Arrays.asList(scanner.getIncludedFiles()); //add main artifact if (includedFiles.contains(mavenProject.getArtifact().getFile().getName())) { boolean shouldOverride = mavenProject.getArtifact().isSnapshot() || overrideArtifacts; githubArtifacts.add(new Artifact(mavenProject.getArtifact().getFile(), projectDescription, shouldOverride)); } //add attached artifacts for (org.apache.maven.artifact.Artifact attachedArtifact : mavenProject .getAttachedArtifacts()) { if (includedFiles.contains(attachedArtifact.getFile().getName())) { boolean shouldOverride = attachedArtifact.isSnapshot() || overrideArtifacts; githubArtifacts.add( new Artifact(attachedArtifact.getFile(), projectDescription, shouldOverride)); } } artifacts = githubArtifacts.toArray(new Artifact[0]); } //upload artifacts to configured github repository uploadArtifacts(artifacts); } catch (GithubRepositoryNotFoundException e) { throw new MojoFailureException(e.getMessage(), e); } catch (GithubArtifactNotFoundException e) { throw new MojoFailureException(e.getMessage(), e); } catch (GithubArtifactAlreadyExistException e) { throw new MojoFailureException(e.getMessage(), e); } catch (GithubException e) { throw new MojoExecutionException("Unexpected error", e); } } }
From source file:com.github.maven_nar.AbstractDependencyMojo.java
License:Apache License
public final NarInfo getNarInfo(final Artifact dependency) throws MojoExecutionException { // FIXME reported to maven developer list, isSnapshot changes behaviour // of getBaseVersion, called in pathOf. dependency.isSnapshot(); if (dependency.getFile().isDirectory()) { getLog().debug("Dependency is not packaged: " + dependency.getFile()); return new NarInfo(dependency.getGroupId(), dependency.getArtifactId(), dependency.getBaseVersion(), getLog(), dependency.getFile()); }/* w w w. j a v a 2s . com*/ final File file = new File(getLocalRepository().getBasedir(), getLocalRepository().pathOf(dependency)); if (!file.exists()) { getLog().debug("Dependency nar file does not exist: " + file); return null; } ZipInputStream zipStream = null; try { zipStream = new ZipInputStream(new FileInputStream(file)); if (zipStream.getNextEntry() == null) { getLog().debug("Skipping unreadable artifact: " + file); return null; } } catch (IOException e) { throw new MojoExecutionException("Error while testing for zip file " + file, e); } finally { IOUtils.closeQuietly(zipStream); } JarFile jar = null; try { jar = new JarFile(file); final NarInfo info = new NarInfo(dependency.getGroupId(), dependency.getArtifactId(), dependency.getBaseVersion(), getLog()); if (!info.exists(jar)) { getLog().debug("Dependency nar file does not contain this artifact: " + file); return null; } info.read(jar); return info; } catch (final IOException e) { throw new MojoExecutionException("Error while reading " + file, e); } finally { IOUtils.closeQuietly(jar); } }