List of usage examples for org.apache.maven.project MavenProject getRuntimeArtifacts
@Deprecated
public List<Artifact> getRuntimeArtifacts()
From source file:com.opengamma.maven.MojoUtils.java
License:Open Source License
/** * Calculates the String classpath for the project. * // w ww .j a v a2s. c om * @param project the project, not null * @return the classpath string, not null */ public static String calculateRuntimeClasspath(MavenProject project) { @SuppressWarnings("unchecked") List<Artifact> artifacts = new ArrayList<>(project.getRuntimeArtifacts()); List<String> cpStrs = new ArrayList<>(); cpStrs.add(new File(project.getBuild().getOutputDirectory()).getAbsolutePath()); for (Artifact artifact : artifacts) { cpStrs.add(artifact.getFile().getAbsolutePath()); } cpStrs.removeAll(Collections.singleton("")); return Joiner.on(File.pathSeparator).join(cpStrs); }
From source file:com.opengamma.maven.MojoUtils.java
License:Open Source License
/** * Calculates the String classpath for the project. * //from ww w .j a v a 2 s.co m * @param project the project, not null * @return the classpath string, not null */ public static ClassLoader calculateRuntimeClassLoader(MavenProject project) { try { @SuppressWarnings("unchecked") List<Artifact> artifacts = new ArrayList<>(project.getRuntimeArtifacts()); List<URL> urlList = new ArrayList<>(); urlList.add(new File(project.getBuild().getOutputDirectory()).getAbsoluteFile().toURI().toURL()); for (Artifact artifact : artifacts) { urlList.add(artifact.getFile().getAbsoluteFile().toURI().toURL()); } URL[] urls = (URL[]) urlList.toArray(new URL[urlList.size()]); return new URLClassLoader(urls); } catch (MalformedURLException ex) { throw new RuntimeException(ex); } }
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 ww w .ja v a 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:org.codehaus.mojo.appassembler.daemon.generic.GenericDaemonGenerator.java
License:Open Source License
private Daemon createDaemon(MavenProject project, ArtifactRepositoryLayout layout) { Daemon complete = new Daemon(); complete.setClasspath(new Classpath()); // ----------------------------------------------------------------------- // Add the project itself as a dependency. // ----------------------------------------------------------------------- Dependency projectDependency = new Dependency(); Artifact projectArtifact = project.getArtifact(); projectArtifact.isSnapshot();//www .j av a2s. c om projectDependency.setGroupId(projectArtifact.getGroupId()); projectDependency.setArtifactId(projectArtifact.getArtifactId()); projectDependency.setVersion(projectArtifact.getVersion()); projectDependency.setClassifier(projectArtifact.getClassifier()); projectDependency.setRelativePath(layout.pathOf(projectArtifact)); complete.getClasspath().addDependency(projectDependency); // ----------------------------------------------------------------------- // Add all the dependencies of the project. // ----------------------------------------------------------------------- for (Iterator it = project.getRuntimeArtifacts().iterator(); it.hasNext();) { Artifact artifact = (Artifact) it.next(); artifact.isSnapshot(); Dependency dependency = new Dependency(); dependency.setGroupId(artifact.getGroupId()); dependency.setArtifactId(artifact.getArtifactId()); dependency.setVersion(artifact.getVersion()); dependency.setClassifier(artifact.getClassifier()); dependency.setRelativePath(layout.pathOf(artifact)); complete.getClasspath().addDependency(dependency); } return complete; }
From source file:org.codehaus.mojo.appassembler.daemon.jsw.JavaServiceWrapperDaemonGenerator.java
License:Open Source License
private void createClasspath(Daemon daemon, DaemonGenerationRequest request, FormattedProperties confFile, Properties configuration) { final String wrapperClassPathPrefix = "wrapper.java.classpath."; int counter = 1; confFile.setProperty(wrapperClassPathPrefix + counter++, "lib/wrapper.jar"); String configurationDirFirst = configuration.getProperty("configuration.directory.in.classpath.first"); if (configurationDirFirst != null) { confFile.setProperty(wrapperClassPathPrefix + counter++, configurationDirFirst); }// w ww . j a v a 2s .com MavenProject project = request.getMavenProject(); ArtifactRepositoryLayout layout = request.getRepositoryLayout(); if (daemon.isUseWildcardClassPath()) { confFile.setProperty(wrapperClassPathPrefix + counter++, "%REPO_DIR%/*"); } else { confFile.setProperty(wrapperClassPathPrefix + counter++, "%REPO_DIR%/" + createDependency(layout, project.getArtifact(), true).getRelativePath()); Iterator j = project.getRuntimeArtifacts().iterator(); while (j.hasNext()) { Artifact artifact = (Artifact) j.next(); confFile.setProperty(wrapperClassPathPrefix + counter, "%REPO_DIR%/" + createDependency(layout, artifact, daemon.isUseTimestampInSnapshotFileName()) .getRelativePath()); counter++; } } String configurationDirLast = configuration.getProperty("configuration.directory.in.classpath.last"); if (configurationDirLast != null) { confFile.setProperty(wrapperClassPathPrefix + counter++, configurationDirLast); } }
From source file:org.codehaus.mojo.gwt.ClasspathBuilder.java
License:Apache License
/** * Get artifacts for specific scope.// www . j a va 2 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 w w w . j a v a2 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.nbm.NetBeansManifestUpdateMojo.java
License:Apache License
/** * complete list of classes on project runtime classpath (excluding * jdk bit)/*from w w w . j a v a 2s . c o m*/ * @param project * @return * @throws java.io.IOException */ @SuppressWarnings("unchecked") private Set<String> allProjectClasses(MavenProject project) throws IOException { Set<String> projectClasses = new HashSet<String>(); DefaultClassAnalyzer analyzer = new DefaultClassAnalyzer(); String outputDirectory = project.getBuild().getOutputDirectory(); URL fl = new File(outputDirectory).toURI().toURL(); projectClasses.addAll(analyzer.analyze(fl)); List<Artifact> libs = project.getRuntimeArtifacts(); for (Artifact lib : libs) { URL url = lib.getFile().toURI().toURL(); projectClasses.addAll(analyzer.analyze(url)); } return projectClasses; }
From source file:org.codehaus.mojo.runtime.builder.MavenJarRuntimeBuilder.java
License:Open Source License
/** * put the dependencies that we are interested in using into the runtime object *///www . j ava 2 s.c o m private void prepareRuntimeDependencies(Runtime runtime, MavenProject project) { List artifactList = project.getRuntimeArtifacts(); List dependencies = runtime.getJar().getDependencies(); for (Iterator i = artifactList.iterator(); i.hasNext();) { Artifact artifact = (Artifact) i.next(); String dependency = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(); // let preexisting dependencies take precedence if (!dependencies.contains(dependency)) { runtime.getJar().addDependency(dependency); } } }