List of usage examples for org.apache.maven.project MavenProject getCompileSourceRoots
public List<String> getCompileSourceRoots()
From source file:org.jsweet.JSweetJettyWatchMojo.java
License:Apache License
private WatchService createJSweetWatcher(MavenProject project) { WatchService watchService = null; try {/*from ww w . ja v a2 s . c o m*/ @SuppressWarnings("unchecked") List<String> sourcePaths = project.getCompileSourceRoots(); getLog().info("Updating jsweet source paths"); ResourceScanner sourceScanner = new ResourceScanner(this, sourcePaths, includes, excludes, sharedIncludes ); watchService = FileSystems.getDefault().newWatchService(); WatcherUtils.registerPaths(this, watchService, sourceScanner.scan()); /* */ } catch (IOException ioException) { getLog().info(ioException); } return watchService; }
From source file:org.jsweet.JSweetJettyWatchMojo.java
License:Apache License
private WatchService createJettyWatcher(MavenProject project) { WatchService watchService = null; try {/*from ww w . j a v a2 s .c o m*/ @SuppressWarnings("unchecked") List<String> sourcePaths = project.getCompileSourceRoots(); getLog().info("Updating server source paths"); ResourceScanner sourceScanner = new ResourceScanner(this, sourcePaths, excludes, includes, sharedIncludes ); watchService = FileSystems.getDefault().newWatchService(); WatcherUtils.registerPaths(this, watchService, sourceScanner.scan()); /* */ } catch (IOException ioException) { getLog().info(ioException); } return watchService; }
From source file:org.jvnet.sorcerer.maven_plugin.SorcererReport.java
License:Apache License
protected List<String> getSourceRoots(MavenProject project) { return project.getCompileSourceRoots(); }
From source file:org.maven.ide.eclipse.checkstyle.MavenCheckstyleProjectConfigurator.java
License:Open Source License
private void configure(final MavenProject mavenProject, final IProject project, final IProgressMonitor monitor) throws CoreException { monitor.beginTask("Checkstyle configuration update", 2); try {//from w ww .j a v a2 s .co m final Plugin plugin = getCheckstylePlugin(mavenProject); if (plugin != null) { final URL ruleset = getCheckstyleConfiguration(mavenProject, plugin, monitor); final Properties properties = extractCustomProperties(plugin); final List<String> compileSource = mavenProject.getCompileSourceRoots(); checkstyleProjectConfigurator.updateProjectConfiguration(project, ruleset, properties, compileSource, CONFIGURATION_NAME, monitor); addNature(project, CheckstyleNature.NATURE_ID, monitor); } else { // TODO remove CheckStyle Nature } } finally { monitor.done(); } }
From source file:org.maven.ide.eclipse.embedder.BuildPathManager.java
License:Apache License
private void addDirs(IContainer project, Set sources, List sourceEntries, MavenProject mavenProject, File basedir, File projectBaseDir) { addSourceDirs(project, sources, sourceEntries, mavenProject.getCompileSourceRoots(), basedir, projectBaseDir);/*from w ww.j a va 2s. c om*/ addSourceDirs(project, sources, sourceEntries, mavenProject.getTestCompileSourceRoots(), basedir, projectBaseDir); addResourceDirs(project, sources, sourceEntries, mavenProject.getBuild().getResources(), basedir, projectBaseDir); addResourceDirs(project, sources, sourceEntries, mavenProject.getBuild().getTestResources(), basedir, projectBaseDir); // HACK to support xmlbeans generated classes MNGECLIPSE-374 File generatedClassesDir = new File(mavenProject.getBuild().getDirectory(), "generated-classes" + File.separator + "xmlbeans"); IResource generatedClasses = project.findMember(toRelativeAndFixSeparator(projectBaseDir, // generatedClassesDir.getAbsolutePath())); if (generatedClasses != null && generatedClasses.isAccessible() && generatedClasses.getType() == IResource.FOLDER) { sourceEntries.add(JavaCore.newLibraryEntry(generatedClasses.getFullPath(), null, null)); } }
From source file:org.maven.ide.eclipse.wtp.AbstractProjectConfiguratorDelegate.java
License:Open Source License
protected void configureWtpUtil(IMavenProjectFacade facade, IProgressMonitor monitor) throws CoreException { // Adding utility facet on JEE projects is not allowed IProject project = facade.getProject(); MavenProject mavenProject = facade.getMavenProject(); if (!WTPProjectsUtil.isJavaProject(facade) || WTPProjectsUtil.isJavaEEProject(project) || WTPProjectsUtil.isQualifiedAsWebFragment(facade)) { return;/*from w ww . j a v a2s. c om*/ } //MECLIPSEWTP-66 delete extra MANIFEST.MF // 1 - predict where the MANIFEST.MF will be created IFolder firstInexistentfolder = null; IPath[] sourceRoots = MavenProjectUtils.getSourceLocations(project, mavenProject.getCompileSourceRoots()); IPath[] resourceRoots = MavenProjectUtils.getResourceLocations(project, mavenProject.getResources()); //MECLIPSEWTP-182 check if the Java Project configurator has been successfully run before doing anything : if (!checkJavaConfiguration(project, sourceRoots, resourceRoots)) { LOG.warn("{} Utility Facet configuration is aborted as the Java Configuration is inconsistent", project.getName()); return; } boolean isDebugEnabled = DebugUtilities.isDebugEnabled(); if (isDebugEnabled) { DebugUtilities.debug(DebugUtilities.dumpProjectState("Before configuration ", project)); } IPath sourceFolder = null; if ((sourceRoots == null || sourceRoots.length == 0) || !project.getFolder(sourceRoots[0]).exists()) { sourceRoots = MavenProjectUtils.getResourceLocations(project, mavenProject.getResources()); } if ((sourceRoots != null && sourceRoots.length > 0 && project.getFolder(sourceRoots[0]).exists())) { sourceFolder = sourceRoots[0]; } IContainer contentFolder = sourceFolder == null ? project : project.getFolder(sourceFolder); IFile manifest = contentFolder.getFile(new Path("META-INF/MANIFEST.MF")); // 2 - check if the manifest already exists, and its parent folder boolean manifestAlreadyExists = manifest.exists(); if (!manifestAlreadyExists) { firstInexistentfolder = findFirstInexistentFolder(project, contentFolder, manifest); } IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor); Set<Action> actions = new LinkedHashSet<Action>(); installJavaFacet(actions, project, facetedProject); if (!facetedProject.hasProjectFacet(WTPProjectsUtil.UTILITY_FACET)) { actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, WTPProjectsUtil.UTILITY_10, null)); } else if (!facetedProject.hasProjectFacet(WTPProjectsUtil.UTILITY_10)) { actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.VERSION_CHANGE, WTPProjectsUtil.UTILITY_10, null)); } if (!actions.isEmpty()) { facetedProject.modify(actions, monitor); } fixMissingModuleCoreNature(project, monitor); if (isDebugEnabled) { DebugUtilities.debug(DebugUtilities.dumpProjectState("after configuration ", project)); } //MNGECLIPSE-904 remove tests folder links for utility jars removeTestFolderLinks(project, mavenProject, monitor, "/"); //Remove "library unavailable at runtime" warning. if (isDebugEnabled) { DebugUtilities.debug(DebugUtilities.dumpProjectState("after removing test folders ", project)); } setNonDependencyAttributeToContainer(project, monitor); //MECLIPSEWTP-66 delete extra MANIFEST.MF // 3 - Remove extra manifest if necessary and its the parent hierarchy if (firstInexistentfolder != null && firstInexistentfolder.exists()) { firstInexistentfolder.delete(true, monitor); } if (!manifestAlreadyExists && manifest.exists()) { manifest.delete(true, monitor); } WTPProjectsUtil.removeWTPClasspathContainer(project); }
From source file:org.maven.ide.eclipse.wtp.ConnectorProjectConfiguratorDelegate.java
License:Open Source License
private void removeSourceLinks(IProject project, MavenProject mavenProject, IProgressMonitor monitor, String folder) throws CoreException { IVirtualComponent component = ComponentCore.createComponent(project); if (component != null) { IVirtualFolder jsrc = component.getRootFolder().getFolder(folder); for (IPath location : MavenProjectUtils.getSourceLocations(project, mavenProject.getCompileSourceRoots())) { jsrc.removeLink(location, 0, monitor); }// w ww .j a va2 s. co m for (IPath location : MavenProjectUtils.getResourceLocations(project, mavenProject.getResources())) { jsrc.removeLink(location, 0, monitor); } } }
From source file:org.mobicents.maven.plugin.eclipse.ClasspathWriter.java
License:Open Source License
/** * Writes the source roots for the given project. * /*ww w .java2 s. c om*/ * @param project * the project for which to write the source roots. * @param rootDirectory * the root project's base directory * @param writer * the XMLWriter used to write the source roots. * @param includeResourcesDirectory */ private Set<String> collectSourceRoots(final MavenProject project, final String rootDirectory, final XMLWriter writer, boolean includeResourcesDirectory) { Set<String> sourcePaths = new TreeSet<String>(); // collect source roots List<String> sourceRoots = new ArrayList<String>(); sourceRoots.addAll(project.getCompileSourceRoots()); sourceRoots.addAll(project.getTestCompileSourceRoots()); for (String s : sourceRoots) { final String sourceRoot = PathNormalizer.normalizePath(s); if (new File(sourceRoot).isDirectory()) { String sourceRootPath = StringUtils.replace(sourceRoot, rootDirectory, ""); if (sourceRootPath.startsWith("/")) { sourceRootPath = sourceRootPath.substring(1, sourceRootPath.length()); } sourcePaths.add(sourceRootPath); } } if (includeResourcesDirectory) { // collect resources List<Resource> resources = new ArrayList<Resource>(); resources.addAll(project.getResources()); resources.addAll(project.getTestResources()); for (Resource resource : resources) { final String resourceRoot = PathNormalizer.normalizePath(resource.getDirectory()); File resourceDirectory = new File(resourceRoot); if (resourceDirectory.exists() && resourceDirectory.isDirectory()) { String resourceSourceRootPath = StringUtils.replace(resourceRoot, rootDirectory, ""); if (resourceSourceRootPath.startsWith("/")) { resourceSourceRootPath = resourceSourceRootPath.substring(1, resourceSourceRootPath.length()); } // we need to avoid nested paths, eclipse doesn't // support them // check if there is already a parent resource path boolean add = true; for (String resourcePath : sourcePaths) { if (resourceSourceRootPath.startsWith(resourcePath)) { // the one we are processing is a child folder, // ignore it add = false; break; } } if (add) { for (String resourcePath : sourcePaths) { if (resourcePath.startsWith(resourceSourceRootPath)) { // the one we are processing is a parent // folder, remove the child sourcePaths.remove(resourcePath); } } sourcePaths.add(resourceSourceRootPath); } } } } return sourcePaths; }
From source file:org.mobicents.maven.plugin.EclipseMojo.java
License:Open Source License
/** * @see org.apache.maven.plugin.Mojo#execute() */// ww w.j a v a 2s .co m public void execute() throws MojoExecutionException { if (!project.isExecutionRoot() && !generateProjectsForModules) { getLog().warn( "Skipping module because execution root project didn't configured generateProjectsForModules property as true"); return; } try { final MavenProject rootProject = this.getRootProject(); final ProjectWriter projectWriter = new ProjectWriter(rootProject, this.getLog()); projectWriter.write(eclipseProjectName != null ? eclipseProjectName : project.getArtifactId()); final Map originalCompileSourceRoots = this.collectProjectCompileSourceRoots(); final List projects = this.collectProjects(); this.processCompileSourceRoots(projects); final ClasspathWriter classpathWriter = new ClasspathWriter(rootProject, this.getLog()); //TODO refactor to pass all arguments as an Options class or this will keep increasing the method signature classpathWriter.write(projects, this.repositoryVariableName, this.artifactFactory, this.artifactResolver, this.localRepository, this.artifactMetadataSource, this.classpathArtifactTypes, this.project.getRemoteArtifactRepositories(), this.resolveTransitiveDependencies, this.classpathMerge, this.classpathExcludes, this.includeResourcesDirectory); // - reset to the original source roots for (final Iterator iterator = projects.iterator(); iterator.hasNext();) { final MavenProject project = (MavenProject) iterator.next(); project.getCompileSourceRoots().clear(); project.getCompileSourceRoots().addAll((List) originalCompileSourceRoots.get(project)); } } catch (Throwable throwable) { throwable.printStackTrace(); throw new MojoExecutionException("Error creating eclipse configuration", throwable); } }
From source file:org.mobicents.maven.plugin.EclipseMojo.java
License:Open Source License
/** * Collects all existing project compile source roots. * * @return a collection of collections/*w w w . java 2s.c om*/ */ private Map collectProjectCompileSourceRoots() throws Exception { final Map sourceRoots = new LinkedHashMap(); for (final Iterator iterator = this.collectProjects().iterator(); iterator.hasNext();) { final MavenProject project = (MavenProject) iterator.next(); sourceRoots.put(project, new ArrayList(project.getCompileSourceRoots())); } return sourceRoots; }