List of usage examples for org.apache.maven.project MavenProject getDependencies
public List<Dependency> getDependencies()
From source file:org.efaps.maven_java5.EfapsAnnotationDescriptorExtractor.java
License:Open Source License
/** * * @param _project maven project//from w ww.ja v a 2 s . c o m * @return * @throws InvalidPluginDescriptorException */ protected ClassLoader getClassLoader(final MavenProject _project) throws InvalidPluginDescriptorException { final List<URL> urls = new ArrayList<URL>(); // append all compile dependencies to the urls final Set<Artifact> toResolve = new HashSet<Artifact>(); for (final Object obj : _project.getDependencies()) { final Dependency dependency = (Dependency) obj; final String scope = dependency.getScope(); if (isCompileScope(scope)) { final Artifact artifact = this.artifactFactory.createArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), scope, dependency.getType()); toResolve.add(artifact); } } try { final ArtifactResolutionResult result = this.artifactResolver.resolveTransitively(toResolve, _project.getArtifact(), getManagedVersionMap(_project), getLocalRepository(), _project.getRemoteArtifactRepositories(), this.artifactMetadataSource, this.filter); for (final Object obj : result.getArtifacts()) { final Artifact artifact = (Artifact) obj; urls.add(artifact.getFile().toURL()); } } catch (final Exception e) { throw new InvalidPluginDescriptorException( "Failed to resolve transitively artifacts: " + e.getMessage(), e); } // append compile class path elements for (final Object obj : _project.getArtifacts()) { final Artifact cpe = (Artifact) obj; try { urls.add(cpe.getFile().toURL()); // URI().toURL() ); } catch (final MalformedURLException e) { getLogger().warn("Cannot convert '" + cpe + "' to URL", e); } } // append target output directory (where the compiled files are) try { urls.add(new File(_project.getBuild().getOutputDirectory()).toURL()); } catch (final MalformedURLException e) { getLogger().warn("Cannot convert '" + _project.getBuild().getOutputDirectory() + "' to URL", e); } if (getLogger().isDebugEnabled()) { getLogger().debug("URLS: \n" + urls.toString().replaceAll(",", "\n ")); } else if (getLogger().isInfoEnabled()) { getLogger().info("URLS: \n" + urls.toString().replaceAll(",", "\n ")); } return new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader()); }
From source file:org.fedoraproject.tycho.TychoBootstrapMojo.java
License:Open Source License
public void createProjectDepMap(Map<String, List<Dependency>> mappings) { for (MavenProject proj : session.getProjects()) { mappings.put(proj.getArtifactId(), proj.getDependencies()); }/* ww w . ja v a 2 s. c o m*/ }
From source file:org.fusesource.ide.camel.model.service.core.catalog.CamelModelFactory.java
License:Open Source License
public static String getRuntimeprovider(IProject camelProject, IProgressMonitor monitor) { if (camelProject != null) { IMavenProjectFacade m2prj = MavenPlugin.getMavenProjectRegistry().create(camelProject, monitor); try {//from w w w. j ava 2 s.c o m if (m2prj != null) { MavenProject mavenProject = m2prj.getMavenProject(monitor); if (mavenProject != null) { List<Dependency> dependencies = mavenProject.getDependencies(); if (hasSpringBootDependency(dependencies)) { return RUNTIME_PROVIDER_SPRINGBOOT; } else { return RUNTIME_PROVIDER_KARAF; } } } } catch (CoreException e) { CamelModelServiceCoreActivator.pluginLog().logWarning(e); } } return RUNTIME_PROVIDER_KARAF; }
From source file:org.fusesource.ide.camel.model.service.core.util.CamelCatalogUtils.java
License:Open Source License
public static String getRuntimeprovider(IProject camelProject, IProgressMonitor monitor) { SubMonitor subMonitor = SubMonitor.convert(monitor, 2); if (camelProject != null) { IMavenProjectFacade m2prj = MavenPlugin.getMavenProjectRegistry().create(camelProject, subMonitor.split(1));/* ww w . ja va 2 s . com*/ try { if (m2prj != null) { MavenProject mavenProject = m2prj.getMavenProject(subMonitor.split(1)); if (mavenProject != null) { List<org.apache.maven.model.Dependency> dependencies = mavenProject.getDependencies(); return getRuntimeProviderFromDependencyList(dependencies); } } } catch (CoreException e) { CamelModelServiceCoreActivator.pluginLog().logWarning(e); } } return RUNTIME_PROVIDER_KARAF; }
From source file:org.fusesource.ide.camel.model.service.core.util.CamelMavenUtils.java
License:Open Source License
/** * @param project//from w w w. j a v a2 s .c om * @param model * @return The dependencies for the supplied Maven model in the supplied * project */ public List<Dependency> getDependencies(IProject project, final Model model) { IMavenProjectFacade projectFacade = getMavenProjectFacade(project); List<Dependency> deps = new ArrayList<>(); if (projectFacade != null) { try { MavenProject mavenProject = projectFacade.getMavenProject(new NullProgressMonitor()); deps.addAll(mavenProject.getDependencies()); deps.addAll(mavenProject.getCompileDependencies()); } catch (CoreException e) { CamelModelServiceCoreActivator.pluginLog().logError( "Maven project has not been found (not imported?). Managed Dependencies won't be resolved.", e); deps.addAll(model.getDependencies()); } } else { // In case the project was not imported in the workspace deps.addAll(model.getDependencies()); } return deps; }
From source file:org.fusesource.ide.projecttemplates.maven.CamelProjectConfigurator.java
License:Open Source License
private String getCamelVersion(MavenProject mavenProject) throws CoreException { for (Dependency dep : mavenProject.getDependencies()) { if (isCamelDependency(dep)) { return dep.getVersion(); }/* ww w.j a va2s . co m*/ } if (mavenProject.getDependencyManagement() != null) { for (Dependency dep : mavenProject.getDependencyManagement().getDependencies()) { if (isCamelDependency(dep)) { return dep.getVersion(); } } } // use deprecated dependency method as a last resort if (mavenProject.getCompileDependencies() != null) { for (Dependency dep : mavenProject.getCompileDependencies()) { if (isCamelDependency(dep)) { return dep.getVersion(); } } } return CamelModelFactory.getLatestCamelVersion(); }
From source file:org.fusesource.ide.projecttemplates.maven.CamelProjectConfigurator.java
License:Open Source License
/** * checks whether the pom contains any apache camel dependency * /* ww w .j a v a 2 s . c om*/ * @param m2Project * @return */ private boolean checkCamelDependencies(MavenProject m2Project) { return m2Project.getDependencies().stream().anyMatch(this::isCamelDependency); }
From source file:org.gephi.maven.ModuleUtils.java
License:Apache License
/** * Investigate modules dependencies and return a map where keys are * top-level modules and values are all modules that it depends on plus the * key module.//www.j a v a2s.c om * * @param modules list of modules * @param log log * @return map that represents the tree of modules */ protected static Map<MavenProject, List<MavenProject>> getModulesTree(List<MavenProject> modules, Log log) { Map<MavenProject, List<MavenProject>> result = new LinkedHashMap<MavenProject, List<MavenProject>>(); for (MavenProject proj : modules) { List<Dependency> dependencies = proj.getDependencies(); log.debug("Investigating the " + dependencies.size() + " dependencies of project '" + proj.getName() + "'"); // Init List<MavenProject> deps = new ArrayList<MavenProject>(); deps.add(proj); result.put(proj, deps); // Add all module-based dependencies for (Dependency d : dependencies) { for (MavenProject projDependency : modules) { if (projDependency != proj && projDependency.getArtifactId().equals(d.getArtifactId()) && projDependency.getGroupId().equals(d.getGroupId()) && projDependency.getVersion().equals(d.getVersion())) { log.debug("Found a dependency that matches another module '" + proj.getName() + "' -> '" + projDependency.getName() + "'"); deps.add(projDependency); } } } } // Remove modules that are entirely dependencies of others List<MavenProject> toBeRemoved = new ArrayList<MavenProject>(); for (MavenProject proj : modules) { List<MavenProject> projDeps = result.get(proj); for (MavenProject proj2 : modules) { if (proj != proj2) { if (result.get(proj2).containsAll(projDeps)) { log.debug("Remove '" + proj.getName() + "' from list of top modules because is a dependency of '" + proj2.getName() + "'"); toBeRemoved.add(proj); break; } } } } for (MavenProject mp : toBeRemoved) { result.remove(mp); } return result; }
From source file:org.grails.maven.plugin.AbstractGrailsMojo.java
License:Apache License
/** * Generates the classpath to be used by the launcher to execute the requested Grails script. * @return An array of {@code URL} objects representing the dependencies required on the classpath to * execute the selected Grails script. * @throws MojoExecutionException if an error occurs while attempting to resolve the dependencies and * generate the classpath array./*from w ww . j a v a 2s.c om*/ */ @SuppressWarnings("unchecked") private URL[] generateGrailsExecutionClasspath() throws MojoExecutionException { try { final List<Dependency> unresolvedDependencies = new ArrayList<Dependency>(); final Set<Artifact> resolvedArtifacts = new HashSet<Artifact>(); /* * Get the Grails dependencies from the plugin's POM file first. */ final MavenProject pluginProject = getPluginProject(); /* * Add the plugin's dependencies and the project using the plugin's dependencies to the list * of unresolved dependencies. This is done so they can all be resolved at the same time so * that we get the benefit of Maven's conflict resolution. */ unresolvedDependencies.addAll(filterDependencies(pluginProject.getDependencies(), "org.grails")); unresolvedDependencies.addAll(this.project.getDependencies()); /* * Convert the Maven dependencies into Maven artifacts so that they can be resolved. */ final List<Artifact> unresolvedArtifacts = dependenciesToArtifacts(unresolvedDependencies); /* * Resolve each artifact. This will get all transitive artifacts AND eliminate conflicts. */ for (Artifact unresolvedArtifact : unresolvedArtifacts) { resolvedArtifacts .addAll(resolveDependenciesToArtifacts(unresolvedArtifact, unresolvedDependencies)); } /* * Remove any Grails plugins that may be in the resolved artifact set. This is because we * do not need them on the classpath, as they will be handled later on by a separate call to * "install" them. */ removePluginArtifacts(resolvedArtifacts); /* * Convert each resolved artifact into a URL/classpath element. */ final List<URL> classpath = new ArrayList<URL>(); int index = 0; for (Artifact resolvedArtifact : resolvedArtifacts) { final File file = resolvedArtifact.getFile(); if (file != null) { classpath.add(file.toURI().toURL()); } } /* * Add the "tools.jar" to the classpath so that the Grails scripts can run native2ascii. * First assume that "java.home" points to a JRE within a JDK. NOTE that this will not * provide a valid path on Mac OSX. This is not a big deal, as the JDK on Mac OSX already * adds the required JAR's to the classpath. This logic is really only for Windows/*Unix. */ final String javaHome = System.getProperty("java.home"); File toolsJar = new File(javaHome, "../lib/tools.jar"); if (!toolsJar.exists()) { // The "tools.jar" cannot be found with that path, so // now try with the assumption that "java.home" points // to a JDK. toolsJar = new File(javaHome, "tools.jar"); } if (toolsJar.exists()) { java.net.URL url = toolsJar.toURI().toURL(); if (url != null) { classpath.add(url); } } return classpath.toArray(new URL[classpath.size()]); } catch (final Exception e) { throw new MojoExecutionException("Failed to create classpath for Grails execution.", e); } }
From source file:org.grails.maven.plugin.AbstractGrailsMojo.java
License:Apache License
/** * Configures the launcher for execution. * @param launcher The {@code GrailsLauncher} instance to be configured. *//*from ww w. j av a2 s . co m*/ @SuppressWarnings("unchecked") private void configureBuildSettings(final GrailsLauncher launcher) throws ProjectBuildingException, MojoExecutionException { final String targetDir = this.project.getBuild().getDirectory(); launcher.setDependenciesExternallyConfigured(true); launcher.setCompileDependencies(artifactsToFiles(this.project.getCompileArtifacts())); launcher.setTestDependencies(artifactsToFiles(this.project.getTestArtifacts())); launcher.setRuntimeDependencies(artifactsToFiles(this.project.getRuntimeArtifacts())); launcher.setProjectWorkDir(new File(targetDir)); launcher.setClassesDir(new File(targetDir, "classes")); launcher.setTestClassesDir(new File(targetDir, "test-classes")); launcher.setResourcesDir(new File(targetDir, "resources")); launcher.setProjectPluginsDir(this.pluginsDir); final MavenProject pluginProject = getPluginProject(); final List<Dependency> unresolvedDependencies = new ArrayList<Dependency>(); final Set<Artifact> resolvedArtifacts = new HashSet<Artifact>(); unresolvedDependencies.addAll(filterDependencies(pluginProject.getDependencies(), "org.grails")); /* * Convert the Maven dependencies into Maven artifacts so that they can be resolved. */ final List<Artifact> unresolvedArtifacts = dependenciesToArtifacts(unresolvedDependencies); /* * Resolve each artifact. This will get all transitive artifacts AND eliminate conflicts. */ for (Artifact unresolvedArtifact : unresolvedArtifacts) { resolvedArtifacts.addAll(resolveDependenciesToArtifacts(unresolvedArtifact, unresolvedDependencies)); } List<File> files = artifactsToFiles(resolvedArtifacts); launcher.setBuildDependencies(files); }