List of usage examples for org.apache.maven.project MavenProject getTestArtifacts
@Deprecated
public List<Artifact> getTestArtifacts()
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. java 2 s .co m*/ * * 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 ww w . j a va 2 s . 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: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//from www. ja v a 2 s. c o m * @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 w w w . j a v a2 s . c o m * @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.//www.j a va2 s . 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 ava2 s . c om * * @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.jfrog.jade.plugins.idea.IdeaModuleMojo.java
License:Apache License
private void addEjbModule(Element module) { module.addAttribute("type", "J2EE_EJB_MODULE"); MavenProject executedProject = getExecutedProject(); String explodedDir = executedProject.getBuild().getDirectory() + "/" + getIdeProjectName(); Element component = findComponent(module, "EjbModuleBuildComponent"); Element setting = findSetting(component, "EXPLODED_URL"); setting.addAttribute("value", getModuleFileUrl(explodedDir)); component = findComponent(module, "EjbModuleProperties"); addDeploymentDescriptor(component, "ejb-jar.xml", "2.x", "src/main/resources/META-INF/ejb-jar.xml"); removeOldElements(component, "containerElement"); List artifacts = executedProject.getTestArtifacts(); for (Iterator i = artifacts.iterator(); i.hasNext();) { Artifact artifact = (Artifact) i.next(); Element containerElement = createElement(component, "containerElement"); if (isLinkModules() && isReactorProject(artifact.getGroupId(), artifact.getArtifactId())) { containerElement.addAttribute("type", "module"); containerElement.addAttribute("name", getNameProvider().getProjectName(artifact)); Element methodAttribute = createElement(containerElement, "attribute"); methodAttribute.addAttribute("name", "method"); methodAttribute.addAttribute("value", "6"); Element uriAttribute = createElement(containerElement, "attribute"); uriAttribute.addAttribute("name", "URI"); uriAttribute.addAttribute("value", "/WEB-INF/classes"); } else if (artifact.getFile() != null) { containerElement.addAttribute("type", "library"); containerElement.addAttribute("level", "module"); containerElement.addAttribute("name", getNameProvider().getProjectName(artifact)); Element methodAttribute = createElement(containerElement, "attribute"); methodAttribute.addAttribute("name", "method"); methodAttribute.addAttribute("value", "2"); Element uriAttribute = createElement(containerElement, "attribute"); uriAttribute.addAttribute("name", "URI"); uriAttribute.addAttribute("value", "/WEB-INF/lib/" + artifact.getFile().getName()); }// w w w . j av a2 s. co m } }
From source file:org.jfrog.jade.plugins.idea.IdeaModuleMojo.java
License:Apache License
/** * Adds the Web module to the (.iml) project file. * * @param module Xpp3Dom element//from w w w . j av a2 s . c o m */ private void addWebModule(Element module) { // TODO: this is bad - reproducing war plugin defaults, etc! // --> this is where the OGNL out of a plugin would be helpful as we could run package first and // grab stuff from the mojo MavenProject executedProject = getExecutedProject(); String warWebapp = executedProject.getBuild().getDirectory() + "/" + executedProject.getArtifactId(); String warSrc = getPluginSetting("maven-war-plugin", "warSourceDirectory", "src/main/webapp"); String webXml = warSrc + "/WEB-INF/web.xml"; module.addAttribute("type", "J2EE_WEB_MODULE"); Element component = findComponent(module, "WebModuleBuildComponent"); Element setting = findSetting(component, "EXPLODED_URL"); setting.addAttribute("value", getModuleFileUrl(warWebapp)); component = findComponent(module, "WebModuleProperties"); removeOldElements(component, "containerElement"); List artifacts = executedProject.getTestArtifacts(); for (Iterator i = artifacts.iterator(); i.hasNext();) { Artifact artifact = (Artifact) i.next(); Element containerElement = createElement(component, "containerElement"); if (isLinkModules() && isReactorProject(artifact.getGroupId(), artifact.getArtifactId())) { containerElement.addAttribute("type", "module"); containerElement.addAttribute("name", getNameProvider().getProjectName(artifact)); Element methodAttribute = createElement(containerElement, "attribute"); methodAttribute.addAttribute("name", "method"); methodAttribute.addAttribute("value", "5"); Element uriAttribute = createElement(containerElement, "attribute"); uriAttribute.addAttribute("name", "URI"); // TODO: Find a way to get this info from the war plugin uriAttribute.addAttribute("value", "/WEB-INF/lib/" + artifact.getArtifactId() + "-" + artifact.getVersion() + ".jar"); } else if (artifact.getFile() != null) { containerElement.addAttribute("type", "library"); containerElement.addAttribute("level", "module"); Element methodAttribute = createElement(containerElement, "attribute"); methodAttribute.addAttribute("name", "method"); if (Artifact.SCOPE_PROVIDED.equalsIgnoreCase(artifact.getScope())) { methodAttribute.addAttribute("value", "0");// If scope is provided, do not package. } else { methodAttribute.addAttribute("value", "1");// IntelliJ 5.0.2 is bugged and doesn't read it } Element uriAttribute = createElement(containerElement, "attribute"); uriAttribute.addAttribute("name", "URI"); uriAttribute.addAttribute("value", "/WEB-INF/lib/" + artifact.getFile().getName()); Element url = createElement(containerElement, "url"); url.setText(getLibraryUrl(artifact)); } } addDeploymentDescriptor(component, "web.xml", "2.3", webXml); Element element = findElement(component, "webroots"); removeOldElements(element, "root"); element = createElement(element, "root"); element.addAttribute("relative", "/"); element.addAttribute("url", getModuleFileUrl(warSrc)); }