List of usage examples for org.apache.maven.project MavenProject getCompileClasspathElements
public List<String> getCompileClasspathElements() throws DependencyResolutionRequiredException
From source file:org.mule.tools.maven.plugin.module.analyze.ModuleDiscoverer.java
License:Open Source License
/** * Discovers all the Mule modules used as dependencies on the Maven project under analysis * * @param project project being analyzed. * @param analyzerLogger collects all the logging information generated during the project analysis * @param projectModuleName name of the module that corresponds to the project being analyzed * @return a list containing all the Mule modules that are dependencies of the analyzed project. * @throws ModuleApiAnalyzerException//w w w . j av a 2s .com */ public List<Module> discoverExternalModules(MavenProject project, AnalyzerLogger analyzerLogger, String projectModuleName) throws ModuleApiAnalyzerException { final List<Module> result = new LinkedList<>(); Set<URL> urls = new HashSet<>(); List<String> elements; try { elements = project.getRuntimeClasspathElements(); elements.addAll(project.getCompileClasspathElements()); for (String element : elements) { urls.add(new File(element).toURI().toURL()); } ClassLoader contextClassLoader = URLClassLoader.newInstance(urls.toArray(new URL[0]), currentThread().getContextClassLoader()); try { final Enumeration<URL> resources = contextClassLoader.getResources(MULE_MODULE_PROPERTIES_LOCATION); while (resources.hasMoreElements()) { final URL url = resources.nextElement(); Properties properties = loadProperties(url); // Skips project module properties String moduleName = (String) properties.get("module.name"); if (!moduleName.equals(projectModuleName)) { result.add(moduleFactory.create(analyzerLogger, moduleName, properties)); } } } catch (Exception e) { throw new ModuleApiAnalyzerException("Cannot read " + MULE_MODULE_PROPERTIES_LOCATION, e); } } catch (Exception e) { throw new ModuleApiAnalyzerException("Error getting project resources", e); } return result; }
From source file:org.netbeans.modules.jackpot30.maven.RunJackpot30.java
License:Open Source License
@SuppressWarnings("unchecked") public static List<String> sourceAndCompileClassPaths(Iterable<? extends MavenProject> projects) throws DependencyResolutionRequiredException { List<String> compileSourceRoots = new ArrayList<String>(); List<String> compileClassPath = new ArrayList<String>(); for (MavenProject project : projects) { compileSourceRoots.addAll((List<String>) project.getCompileSourceRoots()); for (Resource r : (List<Resource>) project.getResources()) { compileSourceRoots.add(r.getDirectory()); }/*w w w . j av a 2 s. c o m*/ compileClassPath.addAll((List<String>) project.getCompileClasspathElements()); } return Arrays.asList("--sourcepath", toClassPathString(compileSourceRoots), "--classpath", toClassPathString(compileClassPath)); }
From source file:org.nuxeo.extractor.ExtractorMojo.java
License:Apache License
protected void initializeProjectClassLoader() throws MojoExecutionException, IOException { Set<String> compileClasspathElements = new HashSet<>(); if (!isStandaloneProject(project)) { try {/*w w w . j a v a 2 s .c om*/ compileClasspathElements.addAll(project.getCompileClasspathElements()); for (MavenProject child : project.getCollectedProjects()) { compileClasspathElements.addAll(child.getCompileClasspathElements()); } } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException(e.getMessage(), e); } } ExtractorContext.initCustomClassLoader(compileClasspathElements); }
From source file:org.rapidoid.plugin.app.AbstractRapidoidMojo.java
License:Apache License
protected String findMainClass(MavenProject project) { List<String> mainClasses = U.list(); try {/*from ww w . ja va 2 s. c o m*/ for (String path : project.getCompileClasspathElements()) { if (new File(path).isDirectory()) { getLog().info("Scanning classpath directory: " + path); scanForMainClass(path, mainClasses); } else if (!path.endsWith(".jar")) { getLog().warn("Ignoring classpath entry: " + path); } } } catch (Exception e) { throw U.rte(e); } switch (mainClasses.size()) { case 0: getLog().warn("Couldn't find the main class!"); return null; case 1: return U.first(mainClasses); default: getLog().warn("Found multiple main classes, trying to pick the right one: " + mainClasses); return pickMainClass(mainClasses, project); } }
From source file:org.richfaces.builder.mojo.AbstractCDKMojo.java
License:Open Source License
protected ClassLoader createProjectClassLoader(MavenProject project, boolean useCCL) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try {/*from ww w .j a v a2 s . c o m*/ 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.sonar.java.JavaClasspath.java
License:Open Source License
private List<File> getLibrariesFromMaven(MavenProject pom) { try {/*from w w w . j ava 2 s . c om*/ List<File> files = Lists.newArrayList(); if (pom.getCompileClasspathElements() != null) { for (String classPathString : (List<String>) pom.getCompileClasspathElements()) { files.add(new File(classPathString)); } } if (pom.getBuild().getOutputDirectory() != null) { File outputDirectoryFile = new File(pom.getBuild().getOutputDirectory()); if (outputDirectoryFile.exists()) { files.add(outputDirectoryFile); } } return files; } catch (DependencyResolutionRequiredException e) { throw new SonarException("Fail to create the project classloader", e); } }
From source file:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java
License:Open Source License
private static void populateLibraries(MavenProject pom, Properties props, boolean test) throws MojoExecutionException { List<File> libraries = new ArrayList<>(); try {/*from ww w. j av a 2 s. co m*/ List<String> classpathElements = test ? pom.getTestClasspathElements() : pom.getCompileClasspathElements(); if (classpathElements != null) { for (String classPathString : classpathElements) { if (!classPathString.equals( test ? pom.getBuild().getTestOutputDirectory() : pom.getBuild().getOutputDirectory())) { File libPath = resolvePath(classPathString, pom.getBasedir()); if (libPath != null && libPath.exists()) { libraries.add(libPath); } } } } } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException("Unable to populate" + (test ? " test" : "") + " libraries", e); } if (!libraries.isEmpty()) { String librariesValue = StringUtils.join(toPaths(libraries), SEPARATOR); if (test) { props.setProperty(JAVA_PROJECT_TEST_LIBRARIES, librariesValue); } else { // Populate both deprecated and new property for backward compatibility props.setProperty(PROJECT_LIBRARIES, librariesValue); props.setProperty(JAVA_PROJECT_MAIN_LIBRARIES, librariesValue); } } }
From source file:se.jguru.nazgul.tools.plugin.checkstyle.exec.DefaultCheckstyleExecutor.java
License:Apache License
private void prepareCheckstylePaths(CheckstyleExecutorRequest request, MavenProject project, List<String> classPathStrings, List<String> outputDirectories, Collection<File> sourceDirectories, Collection<File> testSourceDirectories) throws CheckstyleExecutorException { try {/*ww w. j a v a2 s . c o m*/ outputDirectories.add(project.getBuild().getOutputDirectory()); if (request.isIncludeTestSourceDirectory() && (testSourceDirectories != null) && anyDirectoryExists(testSourceDirectories)) { classPathStrings.addAll(project.getTestClasspathElements()); outputDirectories.add(project.getBuild().getTestOutputDirectory()); } else { classPathStrings.addAll(project.getCompileClasspathElements()); } } catch (DependencyResolutionRequiredException e) { throw new CheckstyleExecutorException(e.getMessage(), e); } }