List of usage examples for org.apache.maven.artifact.repository ArtifactRepository find
Artifact find(Artifact artifact);
From source file:com.ariatemplates.attester.maven.ArtifactExtractor.java
License:Apache License
public String inplaceExtractDependency(ArtifactRepository localRepository, Dependency dependency) throws Exception { Artifact artifact = new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getScope(), dependency.getType(), dependency.getClassifier(), new DefaultArtifactHandler("zip")); artifact = localRepository.find(artifact); File zipFile = artifact.getFile(); File outputDirectory = getOutputDirectory(artifact); if (outputDirectory.exists()) { // if the directory already exists, don't touch it (by the way, it // may currently be in use by some other process) getLog().info("Artifact " + artifact + " is already extracted in " + outputDirectory); } else {// w w w. j a va 2 s . co m getLog().info("Extracting artifact " + artifact + " to " + outputDirectory); File tempDirectory = null; try { // temporary directory where to extract tempDirectory = File.createTempFile("extract", null, outputDirectory.getParentFile()); tempDirectory.delete(); // delete the file created by // createTempFile // (to replace it with a directory) unzip(zipFile, tempDirectory); // Move the temporary directory to its final location if (outputDirectory.exists()) { // the output directory was created in the mean time // (probably by another build running in parallel) getLog().info("Another process probably extracted the artifact at the same time."); } else if (!tempDirectory.renameTo(outputDirectory)) { throw new Exception( "Failed to rename directory " + tempDirectory + " to " + outputDirectory + "."); } } catch (Exception e) { getLog().error("An exception occurred while extracting the " + artifact + " artifact.", e); throw e; } finally { if (tempDirectory != null && tempDirectory.exists()) { getLog().info("Deleting temporary directory " + tempDirectory); FileUtils.deleteQuietly(tempDirectory); } } } return outputDirectory.getAbsolutePath(); }
From source file:com.github.sdorra.buildfrontend.AbstractNodeMojo.java
License:Open Source License
/** * Method description//from w ww. j a v a2s. c o m * * * @param repository * @param artifact * * @return */ private boolean isInstalled(ArtifactRepository repository, Artifact artifact) { boolean result = false; Artifact installed = repository.find(artifact); if (installed != null) { File file = installed.getFile(); result = (file != null) && file.exists(); } return result; }
From source file:io.github.divinespear.maven.plugin.JpaSchemaGeneratorMojo.java
License:Apache License
private ClassLoader getProjectClassLoader() throws MojoExecutionException { try {/*from w w w . j a va 2s. c o m*/ // compiled classes List<String> classfiles = this.project.getCompileClasspathElements(); if (this.scanTestClasses) { classfiles.addAll(this.project.getTestClasspathElements()); } // classpath to url List<URL> classURLs = new ArrayList<URL>(classfiles.size()); for (String classfile : classfiles) { classURLs.add(new File(classfile).toURI().toURL()); } // dependency artifacts to url ArtifactResolutionRequest sharedreq = new ArtifactResolutionRequest().setResolveRoot(true) .setResolveTransitively(true).setLocalRepository(this.session.getLocalRepository()) .setRemoteRepositories(this.project.getRemoteArtifactRepositories()); ArtifactRepository repository = this.session.getLocalRepository(); Set<Artifact> artifacts = this.project.getDependencyArtifacts(); for (Artifact artifact : artifacts) { if (!Artifact.SCOPE_TEST.equalsIgnoreCase(artifact.getScope())) { ArtifactResolutionRequest request = new ArtifactResolutionRequest(sharedreq) .setArtifact(artifact); ArtifactResolutionResult result = this.resolver.resolve(request); if (result.isSuccess()) { File file = repository.find(artifact).getFile(); if (file != null) { classURLs.add(file.toURI().toURL()); } } } } for (URL url : classURLs) { this.log.info(" * classpath: " + url); } return new URLClassLoader(classURLs.toArray(EMPTY_URLS), this.getClass().getClassLoader()); } catch (Exception e) { this.log.error(e); throw new MojoExecutionException("Error while creating classloader", e); } }
From source file:one.util.huntbugs.maven.plugin.HuntBugsMojo.java
License:Apache License
private Repository constructRepository() throws IOException { Repository repo = new DirRepository(classesDirectory.toPath()); if (!quiet) { getLog().info("HuntBugs: +dir " + classesDirectory); }/* ww w . j a v a2 s .co m*/ List<ITypeLoader> deps = new ArrayList<>(); ArtifactRepository localRepository = session.getLocalRepository(); Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts(); if (dependencyArtifacts != null) { for (Artifact art : dependencyArtifacts) { if (art.getScope().equals("compile")) { File f = localRepository.find(art).getFile(); if (f != null) { Path path = f.toPath(); if (!quiet) { getLog().info("HuntBugs: +dep " + path); } if (Files.isRegularFile(path) && art.getType().equals("jar")) { deps.add(new JarTypeLoader(new JarFile(path.toFile()))); } else if (Files.isDirectory(path)) { deps.add(new ClasspathTypeLoader(path.toString())); } } } } } if (deps.isEmpty()) { return repo; } return new CompositeRepository( Arrays.asList(repo, new AuxRepository(new CompositeTypeLoader(deps.toArray(new ITypeLoader[0]))))); }
From source file:org.neo4j.build.plugins.ease.AttachMojo.java
License:Apache License
private void findAndAttachExternalArtifact(Artifact findArtifact, ArtifactRepository repository) throws MojoExecutionException { Artifact artifactToAttach = repository.find(findArtifact); if (!artifactToAttach.getFile().exists()) { throw new MojoExecutionException("Missing artifact file: " + findArtifact.getFile()); }/*from w w w.j ava2 s .co m*/ String fileName = artifactToAttach.getFile().getName(); File destination = new File(new File(project.getBuild().getDirectory()), fileName); try { FileUtils.copyFileIfModified(artifactToAttach.getFile(), destination); } catch (IOException ioe) { throw new MojoExecutionException("Could not copy file: " + fileName, ioe); } artifactToAttach.setFile(destination); project.addAttachedArtifact(artifactToAttach); getLog().info("Attached: " + artifactToAttach); }