List of usage examples for org.apache.maven.project MavenProject getCompileClasspathElements
public List<String> getCompileClasspathElements() throws DependencyResolutionRequiredException
From source file:io.wcm.devops.conga.tooling.maven.plugin.util.ClassLoaderUtil.java
License:Apache License
/** * Build class loader from dependency of a maven project. * @param project Maven project//from w ww. j a va 2 s.co m * @return Class loader * @throws MojoExecutionException */ public static ClassLoader buildDependencyClassLoader(MavenProject project) throws MojoExecutionException { try { List<URL> classLoaderUrls = new ArrayList<>(); for (String path : project.getCompileClasspathElements()) { classLoaderUrls.add(new File(path).toURI().toURL()); } return new URLClassLoader(classLoaderUrls.toArray(new URL[classLoaderUrls.size()])); } catch (MalformedURLException | DependencyResolutionRequiredException ex) { throw new MojoExecutionException("Unable to get classpath elements for class loader.", ex); } }
From source file:org.ajax4jsf.builder.mojo.AbstractCDKMojo.java
License:Open Source License
protected ClassLoader createProjectClassLoader(MavenProject project, boolean useCCL) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try {/* www . j a v a2s. com*/ List<?> compileClasspathElements = project.getCompileClasspathElements(); String outputDirectory = project.getBuild().getOutputDirectory(); URL[] urls = new URL[compileClasspathElements.size() + 1]; int i = 0; urls[i++] = new File(outputDirectory).toURI().toURL(); for (Iterator<?> iter = compileClasspathElements.iterator(); iter.hasNext();) { String element = (String) iter.next(); urls[i++] = new File(element).toURI().toURL(); } if (useCCL) { classLoader = new URLClassLoader(urls, classLoader); } else { classLoader = new URLClassLoader(urls); } } catch (MalformedURLException e) { getLog().error("Bad URL in classpath", e); } catch (DependencyResolutionRequiredException e) { getLog().error("Dependencies not resolved ", e); } return classLoader; }
From source file:org.apache.james.mailet.DefaultDescriptorsExtractor.java
License:Apache License
private URLClassLoader classLoader(MavenProject project, Log log) { URLClassLoader classLoader = null; try {//from w ww.j av a2s . c om @SuppressWarnings("unchecked") final List<String> cpes = project.getCompileClasspathElements(); final int size = cpes.size(); final URL[] urls = new URL[size]; for (int k = 0; k < size; k++) { if (log.isDebugEnabled()) { log.debug("CPE: " + cpes.get(k)); } urls[k] = new File(cpes.get(k)).toURI().toURL(); } classLoader = new URLClassLoader(urls); } catch (DependencyResolutionRequiredException e) { log.error("Failed to load project dependencies.", e); } catch (MalformedURLException e) { log.error("Cannot build classloader from project URLs.", e); } return classLoader; }
From source file:org.apache.myfaces.trinidadbuild.plugin.faces.AbstractFacesMojo.java
License:Apache License
private ClassLoader createCompileClassLoader(MavenProject project) throws MojoExecutionException { Thread current = Thread.currentThread(); ClassLoader cl = current.getContextClassLoader(); try {//from w w w .j a v a 2 s.co m List classpathElements = project.getCompileClasspathElements(); if (!classpathElements.isEmpty()) { String[] entries = (String[]) classpathElements.toArray(new String[0]); URL[] urls = new URL[entries.length]; for (int i = 0; i < urls.length; i++) { urls[i] = new File(entries[i]).toURL(); } cl = new URLClassLoader(urls, cl); } } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException("Error calculating scope classpath", e); } catch (MalformedURLException e) { throw new MojoExecutionException("Error calculating scope classpath", e); } return cl; }
From source file:org.apache.myfaces.trinidadbuild.plugin.tagdoc.TagdocReport.java
License:Apache License
private ClassLoader createCompileClassLoader(MavenProject project) throws MavenReportException { Thread current = Thread.currentThread(); ClassLoader cl = current.getContextClassLoader(); try {//from ww w .jav a 2 s. c om List classpathElements = project.getCompileClasspathElements(); if (!classpathElements.isEmpty()) { String[] entries = (String[]) classpathElements.toArray(new String[0]); URL[] urls = new URL[entries.length]; for (int i = 0; i < urls.length; i++) { urls[i] = new File(entries[i]).toURL(); } cl = new URLClassLoader(urls, cl); } } catch (DependencyResolutionRequiredException e) { throw new MavenReportException("Error calculating scope classpath", e); } catch (MalformedURLException e) { throw new MavenReportException("Error calculating scope classpath", e); } return cl; }
From source file:org.bridje.maven.plugin.ClassPathUtils.java
License:Apache License
public static ClassLoader createClassPath(MavenProject project) throws MalformedURLException, DuplicateRealmException, DependencyResolutionRequiredException { List<String> elements = project.getCompileClasspathElements(); Set<Artifact> artifacts = project.getDependencyArtifacts(); ClassWorld world = new ClassWorld(); ClassRealm newRealm = world.newRealm("projCp", null); for (Artifact artifact : artifacts) { File file = artifact.getFile(); newRealm.addConstituent(file.toURI().toURL()); }//from ww w .j av a2 s . co m for (String element : elements) { newRealm.addConstituent(new File(element).toURI().toURL()); } return newRealm.getClassLoader(); }
From source file:org.codehaus.mojo.jaxb2.SchemagenMojo.java
License:Apache License
@SuppressWarnings("unchecked") @Override//from w w w. jav a 2 s. c o m protected List<String> getClasspathElements(MavenProject project) throws DependencyResolutionRequiredException { return project.getCompileClasspathElements(); }
From source file:org.codehaus.mojo.jaxb2.XjcMojo.java
License:Apache License
@Override protected List getClasspathElements(MavenProject project) throws DependencyResolutionRequiredException { return project.getCompileClasspathElements(); }
From source file:org.codehaus.mojo.webtest.components.AntExecutor.java
License:Apache License
/** * Run an ANT script within the JVM../* ww w .j ava 2 s . c om*/ * * @param antFile the ANT scripts to be executed * @param userProperties the properties to be set for the ANT script * @param mavenProject the current maven project * @param artifacts the list of dependencies * @param target the ANT target to be executed * @throws DependencyResolutionRequiredException * not dependencies were resolved * @throws BuildException the build failed */ public AntExecutor(File antFile, Properties userProperties, MavenProject mavenProject, List artifacts, String target) throws BuildException, DependencyResolutionRequiredException { File antBaseDir = antFile.getParentFile(); Project antProject = new Project(); antProject.init(); antProject.addBuildListener(this.createLogger()); antProject.setBaseDir(antBaseDir); ProjectHelper2.configureProject(antProject, antFile); // ProjectHelper2 projectHelper = new ProjectHelper2(); // projectHelper.parse( antProject, antFile ); Enumeration propertyKeys = userProperties.keys(); while (propertyKeys.hasMoreElements()) { String key = (String) propertyKeys.nextElement(); String value = userProperties.getProperty(key); antProject.setUserProperty(key, value); } // NOTE: from maven-antrun-plugin Path p = new Path(antProject); p.setPath(StringUtils.join(mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator)); /* maven.dependency.classpath it's deprecated as it's equal to maven.compile.classpath */ antProject.addReference("maven.dependency.classpath", p); 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); /* set maven.plugin.classpath with plugin dependencies */ antProject.addReference("maven.plugin.classpath", getPathFromArtifacts(artifacts, antProject)); antProject.executeTarget(target); }
From source file:org.dojoserverfaces.build.mojo.widget.WidgetMojo.java
License:Open Source License
/** * Initializes the classpath elements for this widget Mojo. * //from www .jav a2s.co m * @throws MojoExecutionException * if an error occurs while initializing the classpath elements * for this widget Mojo. */ @SuppressWarnings("unchecked") private void initializeWidgetPluginClasspathElements() throws MojoExecutionException { String qualifiedPluginName = null; // Iterate over all the referenced plugins and figure out the exact // version of the widget plugin. for (Plugin plugin : this.plugins) { String artifactId = plugin.getArtifactId(); String groupId = plugin.getGroupId(); if (groupId.equals("org.dojoserverfaces")) { if (artifactId.equals("dojoserverfaces-maven-plugin")) { qualifiedPluginName = groupId + ":" + artifactId + ":" + plugin.getVersion(); break; } } } // No real way this variable can't be set, but just to be safe... if (qualifiedPluginName != null) { MavenProject pluginProject = (MavenProject) this.project.getProjectReferences() .get(qualifiedPluginName); try { this.widgetPluginClasspathElements = (List<Object>) pluginProject.getCompileClasspathElements(); } catch (Throwable e) { throw new MojoExecutionException("unable to get " + "classpath", e); } } }