List of usage examples for org.apache.maven.artifact DependencyResolutionRequiredException DependencyResolutionRequiredException
public DependencyResolutionRequiredException(Artifact artifact)
From source file:com.agilejava.docbkx.maven.AbstractTransformerMojo.java
License:Apache License
/** * Configures and executes the given ant tasks, mainly preprocess and postprocess defined in the pom configuration. * * @param antTasks The tasks to execute/* w ww . j a va2 s. c o m*/ * @param mavenProject The current maven project * @throws MojoExecutionException If something wrong occurs while executing the ant tasks. */ protected void executeTasks(Target antTasks, MavenProject mavenProject) throws MojoExecutionException { try { ExpressionEvaluator exprEvaluator = (ExpressionEvaluator) antTasks.getProject() .getReference("maven.expressionEvaluator"); Project antProject = antTasks.getProject(); PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(antProject); propertyHelper.setNext(new AntPropertyHelper(exprEvaluator, getLog())); DefaultLogger antLogger = new DefaultLogger(); antLogger.setOutputPrintStream(System.out); antLogger.setErrorPrintStream(System.err); antLogger.setMessageOutputLevel(2); antProject.addBuildListener(antLogger); antProject.setBaseDir(mavenProject.getBasedir()); Path p = new Path(antProject); p.setPath(StringUtils.join(mavenProject.getArtifacts().iterator(), File.pathSeparator)); antProject.addReference("maven.dependency.classpath", p); p = new Path(antProject); p.setPath(StringUtils.join(mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator)); antProject.addReference("maven.compile.classpath", p); p = new Path(antProject); p.setPath(StringUtils.join(mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator)); antProject.addReference("maven.runtime.classpath", p); p = new Path(antProject); p.setPath(StringUtils.join(mavenProject.getTestClasspathElements().iterator(), File.pathSeparator)); antProject.addReference("maven.test.classpath", p); List artifacts = getArtifacts(); List list = new ArrayList(artifacts.size()); File file; for (Iterator i = artifacts.iterator(); i.hasNext(); list.add(file.getPath())) { Artifact a = (Artifact) i.next(); file = a.getFile(); if (file == null) throw new DependencyResolutionRequiredException(a); } p = new Path(antProject); p.setPath(StringUtils.join(list.iterator(), File.pathSeparator)); antProject.addReference("maven.plugin.classpath", p); getLog().info("Executing tasks"); antTasks.execute(); getLog().info("Executed tasks"); } catch (Exception e) { throw new MojoExecutionException("Error executing ant tasks", e); } }
From source file:com.citytechinc.cq.component.maven.ComponentMojo.java
License:Apache License
@SuppressWarnings("unchecked") private List<String> getExcludedDependencyPaths() throws DependencyResolutionRequiredException { if (excludeDependencies != null && !excludeDependencies.isEmpty()) { getLog().debug("Exclusions Found"); List<Artifact> compileArtifacts = project.getCompileArtifacts(); List<String> excludedClasspathElements = new ArrayList<String>(); Set<String> excludedArtifactIdentifiers = new HashSet<String>(); for (Dependency curDependency : excludeDependencies) { excludedArtifactIdentifiers.add(curDependency.getGroupId() + ":" + curDependency.getArtifactId()); }/*from www. jav a 2s.c om*/ for (Artifact curArtifact : compileArtifacts) { String referenceIdentifier = curArtifact.getGroupId() + ":" + curArtifact.getArtifactId(); if (excludedArtifactIdentifiers.contains(referenceIdentifier)) { MavenProject identifiedProject = (MavenProject) project.getProjectReferences() .get(referenceIdentifier); if (identifiedProject != null) { excludedClasspathElements.add(identifiedProject.getBuild().getOutputDirectory()); getLog().debug("Excluding " + identifiedProject.getBuild().getOutputDirectory()); } else { File file = curArtifact.getFile(); if (file == null) { throw new DependencyResolutionRequiredException(curArtifact); } excludedClasspathElements.add(file.getPath()); getLog().debug("Excluding " + file.getPath()); } } } return excludedClasspathElements; } return null; }
From source file:com.excilys.ebi.gatling.mojo.GatlingMojo.java
License:Apache License
protected void append(Path classPath, List<?> artifacts) throws DependencyResolutionRequiredException { List<String> list = new ArrayList<String>(artifacts.size()); for (Object artifact : artifacts) { String path;//from ww w. j a v a 2s . c o m if (artifact instanceof Artifact) { Artifact a = (Artifact) artifact; File file = a.getFile(); if (file == null) { throw new DependencyResolutionRequiredException(a); } path = file.getPath(); } else { path = artifact.toString(); } list.add(path); } Path p = new Path(classPath.getProject()); p.setPath(join(list.iterator(), File.pathSeparator)); classPath.append(p); }
From source file:com.ning.maven.plugins.duplicatefinder.DuplicateFinderMojo.java
License:Apache License
private Map createArtifactsByFileMap(List artifacts) throws DependencyResolutionRequiredException { Map artifactsByFile = new HashMap(artifacts.size()); for (Iterator artifactIt = artifacts.iterator(); artifactIt.hasNext();) { Artifact artifact = (Artifact) artifactIt.next(); File localPath = getLocalProjectPath(artifact); File repoPath = artifact.getFile(); if ((localPath == null) && (repoPath == null)) { throw new DependencyResolutionRequiredException(artifact); }/*from ww w. j av a 2 s . c om*/ if (localPath != null) { artifactsByFile.put(localPath, artifact); } if (repoPath != null) { artifactsByFile.put(repoPath, artifact); } } return artifactsByFile; }
From source file:com.zelix.zkm_maven_plugin.ObfuscateMojo.java
License:Apache License
public String getRuntimeClasspathElements() throws DependencyResolutionRequiredException { StringBuilder build = new StringBuilder(); boolean first = true; for (Iterator i = mavenProject.getArtifacts().iterator(); i.hasNext();) { Artifact a = (Artifact) i.next(); if (a.getArtifactHandler().isAddedToClasspath()) { // TODO: let the scope handler deal with this if (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_RUNTIME.equals(a.getScope())) { File file = a.getFile(); if (file == null) { throw new DependencyResolutionRequiredException(a); }// w ww . ja v a 2 s. c om if (!first) build.append(File.pathSeparatorChar); else first = false; build.append(file.getPath()); } } } return build.toString(); }
From source file:de.jiac.micro.mojo.AbstractPackagingMojo.java
License:Open Source License
String getClassPath(MavenProject p) throws MojoExecutionException { try {/*from w ww . j a va 2s.c om*/ StringBuffer classPath = new StringBuffer(); HashSet<Artifact> artifacts = new HashSet<Artifact>(); artifacts.addAll(p.getCompileArtifacts()); HashSet<String> extractedDependencies = (HashSet<String>) getPluginContext() .get(ExtractionMojo.EXTRACTED_DEPENDENCIES); for (Artifact artifact : artifacts) { String artId = artifact.getDependencyConflictId(); if (extractedDependencies.contains(artId)) { getLog().debug("Skip " + artId); continue; } File file = artifact.getFile(); if (file == null) { throw new DependencyResolutionRequiredException(artifact); } String classpathElement = FileNameUtil.getAbsolutPath(file); if (classPath.length() > 0) { classPath.append(File.pathSeparator); } classPath.append(classpathElement); } getLog().debug("classpath: " + classPath); return classPath.toString(); } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException("failed to resolve dependency", e); } }
From source file:de.jiac.micro.mojo.ReflectorMojo.java
License:Open Source License
private ClassLoader createBinaryPath() throws MojoExecutionException { Set<URI> binaryPath = new HashSet<URI>(); try {/*from ww w . j a v a2 s .c om*/ binaryPath.add(outputDirectory.toURI()); HashSet<Artifact> artifacts = new HashSet<Artifact>(); HashSet<String> extractedDependencies = (HashSet<String>) getPluginContext() .get(ExtractionMojo.EXTRACTED_DEPENDENCIES); artifacts.addAll(project.getCompileArtifacts()); for (Artifact artifact : artifacts) { String artId = artifact.getDependencyConflictId(); if (extractedDependencies.contains(artId)) { getLog().debug("Skip " + artId); continue; } File file = artifact.getFile(); if (file == null) { throw new DependencyResolutionRequiredException(artifact); } binaryPath.add(file.toURI()); } URL[] urls = new URL[binaryPath.size()]; int i = 0; for (URI uri : binaryPath) { urls[i++] = uri.toURL(); } return new URLClassLoader(urls); } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException("failed to resolve dependency", e); } catch (MalformedURLException me) { throw new MojoExecutionException("failed to convert file to URL", me); } }
From source file:org.bsc.maven.plugin.findclass.ClassFinderMojo.java
License:Apache License
private Map<File, Artifact> createArtifactsByFileMap(List<Artifact> artifacts) throws DependencyResolutionRequiredException { final Map<File, Artifact> artifactsByFile = new HashMap<>(artifacts.size()); for (Artifact artifact : artifacts) { final File localPath = getLocalProjectPath(artifact); final File repoPath = artifact.getFile(); if ((localPath == null) && (repoPath == null)) { throw new DependencyResolutionRequiredException(artifact); }//from w w w. j av a 2s . co m if (localPath != null) { artifactsByFile.put(localPath, artifact); } if (repoPath != null) { artifactsByFile.put(repoPath, artifact); } } return artifactsByFile; }
From source file:org.codehaus.mojo.apt.MavenProjectUtils.java
License:Open Source License
private static void addArtifactPath(MavenProject project, Artifact artifact, List<String> list) throws DependencyResolutionRequiredException { String refId = getProjectReferenceId(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());// w w w . jav a 2 s. co m MavenProject refProject = (MavenProject) project.getProjectReferences().get(refId); boolean projectDirFound = false; if (refProject != null) { if (artifact.getType().equals("test-jar")) { File testOutputDir = new File(refProject.getBuild().getTestOutputDirectory()); if (testOutputDir.exists()) { list.add(testOutputDir.getAbsolutePath()); projectDirFound = true; } } else { list.add(refProject.getBuild().getOutputDirectory()); projectDirFound = true; } } if (!projectDirFound) { File file = artifact.getFile(); if (file == null) { throw new DependencyResolutionRequiredException(artifact); } list.add(file.getPath()); } }
From source file:org.codehaus.mojo.webtest.components.AntExecutor.java
License:Apache License
/** * Build a class path based on a list of artifacts. Please * not that this is copy & wasted from maven-antrun-plugin. * * @param artifacts the artifacts constituting the class path * @param antProject the ant project// w ww. ja v a2 s. co m * @return a path * @throws DependencyResolutionRequiredException * not dependencies were resolved */ public Path getPathFromArtifacts(Collection artifacts, Project antProject) throws DependencyResolutionRequiredException { if (artifacts == null) { return new Path(antProject); } List list = new ArrayList(artifacts.size()); for (Iterator i = artifacts.iterator(); i.hasNext();) { Artifact a = (Artifact) i.next(); File file = a.getFile(); if (file == null) { throw new DependencyResolutionRequiredException(a); } list.add(file.getPath()); } Path p = new Path(antProject); p.setPath(StringUtils.join(list.iterator(), File.pathSeparator)); return p; }