List of usage examples for org.apache.maven.project MavenProject getCompileArtifacts
@Deprecated
public List<Artifact> getCompileArtifacts()
From source file:com.totsp.mavenplugin.gwt.util.BuildClasspathUtil.java
License:Open Source License
/** * Build classpath list using either gwtHome (if present) or using *project* dependencies. Note * that this is ONLY used for the script/cmd writers (so the scopes are not for the compiler, or * war plugins, etc)./*from w w w .j ava 2 s. c om*/ * * This is required so that the script writers can get the dependencies they need regardless of * the Maven scopes (still want to use the Maven scopes for everything else Maven, but for * GWT-Maven we need to access deps differently - directly at times). * * * @param mojo * @param scope * @return file collection for classpath * @throws DependencyResolutionRequiredException */ public static Collection<File> buildClasspathList(final AbstractGWTMojo mojo, final DependencyScope scope) throws DependencyResolutionRequiredException, MojoExecutionException { mojo.getLog().info("establishing classpath list (buildClaspathList - scope = " + scope + ")"); File gwtHome = mojo.getGwtHome(); MavenProject project = mojo.getProject(); Set<File> items = new LinkedHashSet<File>(); // inject GWT jars and relative native libs for all scopes // (gwt-user and gwt-dev should be scoped provided to keep them out of // other maven stuff - not end up in war, etc - this util is only used for GWT-Maven // scripts) // TODO filter the rest of the stuff so we don't double add these if (gwtHome != null) { mojo.getLog().info("google.webtoolkit.home (gwtHome) set, using it for GWT dependencies - " + gwtHome.getAbsolutePath()); items.addAll(BuildClasspathUtil.injectGwtDepsFromGwtHome(gwtHome, mojo)); } else { mojo.getLog() .info("google.webtoolkit.home (gwtHome) *not* set, using project POM for GWT dependencies"); items.addAll(BuildClasspathUtil.injectGwtDepsFromRepo(mojo)); } // add sources if (mojo.getSourcesOnPath()) { BuildClasspathUtil.addSourcesWithActiveProjects(project, items, DependencyScope.COMPILE); } // add resources if (mojo.getResourcesOnPath()) { BuildClasspathUtil.addResourcesWithActiveProjects(project, items, DependencyScope.COMPILE); } // add classes dir items.add(new File(project.getBuild().getDirectory() + File.separator + "classes")); // if runtime add runtime if (scope == DependencyScope.RUNTIME) { // use Collection<Artifact> because sometimes it's LinkedHashSet, sometimes it's List, and NO TIMES is it documented for (Artifact a : (Collection<Artifact>) project.getRuntimeArtifacts()) { items.add(a.getFile()); } } // if test add test if (scope == DependencyScope.TEST) { for (Artifact a : (Collection<Artifact>) project.getTestArtifacts()) { items.add(a.getFile()); } // add test classes dir items.add(new File(project.getBuild().getDirectory() + File.separator + "test-classes")); // add test sources and resources BuildClasspathUtil.addSourcesWithActiveProjects(project, items, scope); BuildClasspathUtil.addResourcesWithActiveProjects(project, items, scope); } // add compile (even when scope is other than) for (Artifact a : (Collection<Artifact>) project.getCompileArtifacts()) { items.add(a.getFile()); } // add all source artifacts for (Artifact a : (Collection<Artifact>) project.getArtifacts()) { if ("sources".equals(a.getClassifier())) { items.add(a.getFile()); } } mojo.getLog().debug("SCRIPT INJECTION CLASSPATH LIST"); for (File f : items) { mojo.getLog().debug(" " + f.getAbsolutePath()); } return items; }
From source file:com.totsp.mavenplugin.gwt.util.BuildClasspathUtil.java
License:Open Source License
/** * Get artifacts for specific scope./*from w w w . ja v a 2s . c om*/ * * @param project * @param scope * @return */ @SuppressWarnings("unchecked") private static List<Artifact> getScopeArtifacts(final MavenProject project, final DependencyScope scope) { if (DependencyScope.COMPILE.equals(scope)) { return project.getCompileArtifacts(); } else if (DependencyScope.TEST.equals(scope)) { return project.getTestArtifacts(); } else { throw new RuntimeException("Not allowed scope " + scope); } }
From source file:de.jiac.micro.mojo.AbstractPackagingMojo.java
License:Open Source License
String getClassPath(MavenProject p) throws MojoExecutionException { try {/* w w w .j ava 2 s. com*/ 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:org.apache.cxf.maven_plugin.ClassLoaderSwitcher.java
License:Apache License
/** * Create and set the classloader that is needed for creating the java sources from wsdl * * @param project//ww w . jav a 2 s. com * @param useCompileClasspath * @param classesDir */ public String switchClassLoader(MavenProject project, boolean useCompileClasspath, String classpath, List<?> classpathElements) { List<URL> urlList = new ArrayList<>(); StringBuilder buf = new StringBuilder(); try { buf.append(classpath); buf.append(File.pathSeparatorChar); urlList.add(new File(project.getBuild().getOutputDirectory()).toURI().toURL()); } catch (MalformedURLException e) { // ignore } for (Object classpathElement : classpathElements) { buf.append(classpathElement.toString()); buf.append(File.pathSeparatorChar); } buf.append(File.pathSeparatorChar); @SuppressWarnings("deprecation") List<?> artifacts = useCompileClasspath ? project.getCompileArtifacts() : project.getTestArtifacts(); for (Artifact a : CastUtils.cast(artifacts, Artifact.class)) { try { if (a.getFile() != null && a.getFile().exists()) { urlList.add(a.getFile().toURI().toURL()); buf.append(a.getFile().getAbsolutePath()); buf.append(File.pathSeparatorChar); // System.out.println(" " + // a.getFile().getAbsolutePath()); } } catch (MalformedURLException e) { // ignore } } origContextClassloader = Thread.currentThread().getContextClassLoader(); ClassLoader loader = ClassLoaderUtils.getURLClassLoader(urlList, origContextClassloader); String newCp = buf.toString(); log.debug("Classpath: " + urlList.toString()); origProps = new HashMap<>(System.getProperties()); origClassPath = System.getProperty("java.class.path"); Thread.currentThread().setContextClassLoader(loader); System.setProperty("java.class.path", newCp); return newCp; }
From source file:org.apache.cxf.maven_plugin.common.ClassLoaderSwitcher.java
License:Apache License
/** * Create and set the classloader that is needed for creating the java sources from wsdl * * @param project//from ww w. ja v a2s.c om * @param useCompileClasspath * @param classesDir */ public Set<URI> switchClassLoader(MavenProject project, boolean useCompileClasspath, File classesDir) { List<URL> urlList = new ArrayList<>(); StringBuilder buf = new StringBuilder(); Set<URI> ret = new LinkedHashSet<URI>(); try { urlList.add(classesDir.toURI().toURL()); if (!useCompileClasspath) { urlList.add(new File(project.getBuild().getOutputDirectory()).toURI().toURL()); } } catch (MalformedURLException e) { // ignore } buf.append(classesDir.getAbsolutePath()); ret.add(classesDir.toURI()); buf.append(File.pathSeparatorChar); if (!useCompileClasspath) { buf.append(project.getBuild().getOutputDirectory()); ret.add(new File(project.getBuild().getOutputDirectory()).toURI()); buf.append(File.pathSeparatorChar); } @SuppressWarnings("deprecation") List<?> artifacts = useCompileClasspath ? project.getCompileArtifacts() : project.getTestArtifacts(); for (Artifact a : CastUtils.cast(artifacts, Artifact.class)) { try { if (a.getFile() != null && a.getFile().exists()) { urlList.add(a.getFile().toURI().toURL()); buf.append(a.getFile().getAbsolutePath()); ret.add(a.getFile().toURI()); buf.append(File.pathSeparatorChar); // System.out.println(" " + // a.getFile().getAbsolutePath()); } } catch (MalformedURLException e) { // ignore } } origContextClassloader = Thread.currentThread().getContextClassLoader(); ClassLoader loader = ClassLoaderUtils.getURLClassLoader(urlList, origContextClassloader); String newCp = buf.toString(); log.debug("Classpath: " + urlList.toString()); origProps = new HashMap<>(System.getProperties()); origClassPath = System.getProperty("java.class.path"); Thread.currentThread().setContextClassLoader(loader); System.setProperty("java.class.path", newCp); return ret; }
From source file:org.codehaus.mojo.gwt.ClasspathBuilder.java
License:Apache License
/** * Get artifacts for specific scope.// ww w . j a v a2s. c o m * * @param project * @param scope * @return */ private List<Artifact> getScopeArtifacts(final MavenProject project, final String scope) { if (SCOPE_COMPILE.equals(scope)) { return project.getCompileArtifacts(); } if (SCOPE_RUNTIME.equals(scope)) { return project.getRuntimeArtifacts(); } else if (SCOPE_TEST.equals(scope)) { return project.getTestArtifacts(); } else { throw new RuntimeException("Not allowed scope " + scope); } }
From source file:org.codehaus.mojo.gwt.shell.ClasspathBuilder.java
License:Apache License
/** * Get artifacts for specific scope.//from ww w. j a v a 2 s. c o m * * @param project * @param scope * @return */ @SuppressWarnings("unchecked") private List<Artifact> getScopeArtifacts(final MavenProject project, final String scope) { if (SCOPE_COMPILE.equals(scope)) { return project.getCompileArtifacts(); } if (SCOPE_RUNTIME.equals(scope)) { return project.getRuntimeArtifacts(); } else if (SCOPE_TEST.equals(scope)) { return project.getTestArtifacts(); } else { throw new RuntimeException("Not allowed scope " + scope); } }
From source file:org.codehaus.mojo.jdiff.JDiffUtils.java
License:Apache License
public static List<String> getClasspathElements(MavenProject project) { List<String> classpathElements = new ArrayList<String>(); for (Artifact a : (List<Artifact>) project.getCompileArtifacts()) { classpathElements.add(a.getFile().getPath()); }//w ww.j a v a 2 s . c o m return classpathElements; }
From source file:org.codehaus.mojo.nbm.AbstractNbmMojo.java
License:Apache License
static List<ModuleWrapper> getModuleDependencyArtifacts(DependencyNode treeRoot, NetBeansModule module, Dependency[] customDependencies, MavenProject project, Map<Artifact, ExamineManifest> examinerCache, List<Artifact> libraryArtifacts, Log log, boolean useOsgiDependencies) throws MojoExecutionException { List<Dependency> deps = new ArrayList<Dependency>(); if (customDependencies != null) { deps.addAll(Arrays.asList(customDependencies)); }//ww w . j a v a 2 s . c o m if (module != null && !module.getDependencies().isEmpty()) { log.warn( "dependencies in module descriptor are deprecated, use the plugin's parameter moduleDependencies"); //we need to make sure a dependency is not twice there, module deps override the config (as is the case with other //configurations) for (Dependency d : module.getDependencies()) { Dependency found = null; for (Dependency d2 : deps) { if (d2.getId().equals(d.getId())) { found = d2; break; } } if (found != null) { deps.remove(found); } deps.add(d); } } List<ModuleWrapper> include = new ArrayList<ModuleWrapper>(); @SuppressWarnings("unchecked") List<Artifact> artifacts = project.getCompileArtifacts(); for (Artifact artifact : artifacts) { if (libraryArtifacts.contains(artifact)) { continue; } ExamineManifest depExaminator = examinerCache.get(artifact); if (depExaminator == null) { depExaminator = new ExamineManifest(log); depExaminator.setArtifactFile(artifact.getFile()); depExaminator.checkFile(); examinerCache.put(artifact, depExaminator); } Dependency dep = resolveNetBeansDependency(artifact, deps, depExaminator, log); if (dep != null) { ModuleWrapper wr = new ModuleWrapper(); wr.dependency = dep; wr.artifact = artifact; wr.transitive = false; //only direct deps matter to us.. if (depExaminator.isNetBeansModule() && artifact.getDependencyTrail().size() > 2) { log.debug(artifact.getId() + " omitted as NetBeans module dependency, not a direct one. Declare it in the pom for inclusion."); wr.transitive = true; } include.add(wr); } else { if (useOsgiDependencies && depExaminator.isOsgiBundle()) { ModuleWrapper wr = new ModuleWrapper(); wr.osgi = true; String id = artifact.getGroupId() + ":" + artifact.getArtifactId(); for (Dependency depe : deps) { if (id.equals(depe.getId())) { wr.dependency = depe; } } boolean print = false; if (wr.dependency == null) { Dependency depe = new Dependency(); depe.setId(id); depe.setType("spec"); wr.dependency = depe; print = true; } wr.artifact = artifact; wr.transitive = false; //only direct deps matter to us.. if (artifact.getDependencyTrail().size() > 2) { log.debug(artifact.getId() + " omitted as NetBeans module OSGi dependency, not a direct one. Declare it in the pom for inclusion."); wr.transitive = true; } else { if (print) { log.info("Adding OSGi bundle dependency - " + id); } } include.add(wr); } } } return include; }
From source file:org.ebayopensource.turmeric.plugins.maven.util.ProjectClassLoader.java
License:Open Source License
private static URL[] getMavenProjectClassLoaderURLS(MavenProject project) throws MalformedURLException { List<File> searchPaths = new ArrayList<File>(); // Project Compile Artifacts @SuppressWarnings("unchecked") final List<Artifact> arts = project.getCompileArtifacts(); if (arts != null) { for (Artifact arti : arts) { File artiFile = arti.getFile(); if ((artiFile != null) && (artiFile.exists())) { searchPaths.add(artiFile); }// ww w . ja v a 2s. co m } } // Project Resources @SuppressWarnings("unchecked") final List<Resource> resources = project.getBuild().getResources(); for (Resource resource : resources) { String resDir = resource.getDirectory(); File dir = new File(resDir); if (!dir.isAbsolute()) { dir = new File(project.getBasedir(), resDir); } searchPaths.add(dir); } // The Classes Dir File classesDir = new File(project.getBuild().getOutputDirectory()); if (!classesDir.isAbsolute()) { classesDir = new File(project.getBasedir(), project.getBuild().getOutputDirectory()); } searchPaths.add(classesDir); // Compile Source Roots - (needed for codegen javac) @SuppressWarnings("unchecked") List<String> sourceRoots = project.getCompileSourceRoots(); if (sourceRoots != null) { for (String srcRoot : sourceRoots) { if (StringUtils.isBlank(srcRoot)) { // skip continue; } File src = new File(srcRoot); if (src.exists()) { searchPaths.add(new File(srcRoot)); } } } int count = searchPaths.size(); URL urls[] = new URL[count]; for (int i = 0; i < count; i++) { urls[i] = searchPaths.get(i).toURI().toURL(); System.out.printf("### ProjectClassLoader[%d]: %s%n", i, urls[i].toExternalForm()); } return urls; }