List of usage examples for org.eclipse.jdt.core IClasspathEntry getExclusionPatterns
IPath[] getExclusionPatterns();
From source file:monolipse.core.internal.BooNature.java
License:Open Source License
private Map<IClasspathEntry, IClasspathEntry> addExclusionPatternsTo(IClasspathEntry[] classpath) { Map<IClasspathEntry, IClasspathEntry> modified = new HashMap<IClasspathEntry, IClasspathEntry>(); for (int i = 0; i < classpath.length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) continue; IPath[] exclusionPatterns = entry.getExclusionPatterns(); IPath[] newExclusionPatterns = addExclusionPatternsTo(exclusionPatterns); if (exclusionPatterns == newExclusionPatterns) continue; IClasspathEntry newSourceEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), newExclusionPatterns, entry.getOutputLocation(), entry.getExtraAttributes()); modified.put(entry, newSourceEntry); }//from w ww . j av a2 s . com return modified; }
From source file:net.sf.refactorit.eclipse.vfs.EclipseSourcePath.java
License:Open Source License
private IClasspathEntry[] getSourcePathEntries() throws JavaModelException { IJavaProject jProject = getJavaProject(); List result = new ArrayList(); IClasspathEntry[] pathEntries = jProject.getResolvedClasspath(true); for (int i = 0; i < pathEntries.length; i++) { IClasspathEntry entry = pathEntries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE /*|| entry.getEntryKind() == IClasspathEntry.CPE_PROJECT*/) { result.add(entry);/* w ww . j a v a2 s . c o m*/ if (debug) { log.debug("exclusion patterns = " + Arrays.asList(entry.getExclusionPatterns())); } } } return (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]); }
From source file:org.continuousassurance.swamp.eclipse.BuildfileGenerator.java
License:Apache License
/** * Returns an image descriptor for the image file at the given * plug-in relative path// w w w . j ava 2s .com * * @param doc the document * @param root the root element * @param prjOutputDirectory the output directory * @param list the list of projects that the calling project * depends on * @param projectName the name of the calling project * @param isRoot is this project the root * @return the image descriptor */ private static void setBuildTarget(Document doc, Element root, String outputDirectory, List<ImprovedClasspathHandler> dependentProjects, List<IClasspathEntry> srcEntries, String projectName, Set<String> filePaths, String prjEncoding) { String prjOutputDirectory = outputDirectory.substring(1); // unroot it System.out.println("Relative output directory: " + prjOutputDirectory); Element target = doc.createElement(ANT_TARGET); target.setAttribute(ANT_NAME, ANT_BUILD); //if (isRoot) { Element init = setInitTarget(doc, root, prjOutputDirectory); target.setAttribute(ANT_DEPENDS, ANT_INIT); //} root.appendChild(target); for (ImprovedClasspathHandler ich : dependentProjects) { BuildfileGenerator.generateBuildFile(ich, filePaths); String buildFilePath = ich.getProjectName() + BUILDFILE_EXT; // this will be in the same directory Element ant = doc.createElement(ANT_ANT); ant.setAttribute(ANT_ANTFILE, buildFilePath); ant.setAttribute(ANT_TARGET, ANT_BUILD); target.appendChild(ant); } // includesfile and excludesfile attributes - http://ant.apache.org/manual/Tasks/javac.html for (IClasspathEntry entry : srcEntries) { IPath[] inclusionPatterns = entry.getInclusionPatterns(); IPath[] exclusionPatterns = entry.getExclusionPatterns(); Element javac = doc.createElement(ANT_JAVAC); javac.setAttribute(ANT_INCLUDE_ANT_RUNTIME, ANT_FALSE); javac.setAttribute(ANT_CLASSPATHREF, CLASSPATH_NAME); javac.setAttribute(ANT_BOOTCLASSPATHREF, BOOTCLASSPATH_NAME); if (inclusionPatterns.length == 0 && exclusionPatterns.length == 0) { javac.setAttribute(ANT_SOURCEPATHREF, SOURCEPATH_NAME); } else { javac.setAttribute(ANT_SOURCEPATH, getModifiedSourcePath(entry, srcEntries)); } String srcEncoding = getEncodingAttribute(entry); if (!("").equals(srcEncoding)) { javac.setAttribute(ANT_ENCODING, srcEncoding); } else if (!("".equals(prjEncoding)) && prjEncoding != null) { System.out.println("Project encoding: " + prjEncoding); javac.setAttribute(ANT_ENCODING, prjEncoding); } // Source entries may have a specific output location associated with them, otherwise, we use the project's default location IPath destPath = entry.getOutputLocation(); String destDir; if (destPath != null) { String strPath = destPath.toOSString(); destDir = strPath.substring(1); } else { destDir = prjOutputDirectory; } Element mkdir = doc.createElement(ANT_MKDIR); mkdir.setAttribute(ANT_DIR, destDir); // TODO Become smarter about when we actually need this init.appendChild(mkdir); javac.setAttribute(ANT_DESTDIR, destDir); javac.setAttribute(ANT_SOURCE, "${source}"); javac.setAttribute(ANT_TARGET, "${target}"); Element src = doc.createElement(ANT_SRC); addInclusionExclusionPatterns(doc, javac, ANT_INCLUDE, entry.getInclusionPatterns()); addInclusionExclusionPatterns(doc, javac, ANT_EXCLUDE, entry.getExclusionPatterns()); String absPath = entry.getPath().toOSString(); String strRelPath = absPath.substring(1); System.out.println("Relative path: " + strRelPath); src.setAttribute(ANT_PATH, strRelPath); javac.appendChild(src); target.appendChild(javac); } }
From source file:org.ebayopensource.turmeric.repositorysystem.imp.impl.TurmericProjectConfigurer.java
License:Open Source License
private void mavenizeAndCleanUp(final IProject project, final ProjectMavenizationRequest request, final IProgressMonitor monitor) throws CoreException, MavenEclipseApiException, IOException, InterruptedException, TemplateException { if (SOALogger.DEBUG) logger.entering(project, request); final IMavenEclipseApi api = MavenCoreUtils.mavenEclipseAPI(); try {/*from w w w. j a va2 s. c o m*/ // It seems that the pom.xml is not updated in the Eclipse Workspace by the mavenize project operation // Util.refresh( project.getFile( "pom.xml" ) ); // Project Mavenization doesn't seem to care that the output directory is set here and set in the pom.xml // it will use the maven default of target-eclipse no matter what. IJavaProject javaProject = null; try { api.mavenizeProject(request, monitor); logger.info("Mavenization finished->" + project); ProgressUtil.progressOneStep(monitor); javaProject = JavaCore.create(project); //javaProject.setOutputLocation( project.getFolder( SOAProjectConstants.FOLDER_OUTPUT_DIR).getFullPath(), null ); FileUtils.deleteDirectory(project.getFolder("target-eclipse").getLocation().toFile()); //Util.delete( project.getFolder( "target-eclipse" ), null ); final Map<?, ?> options = javaProject.getOptions(false); options.clear(); javaProject.setOptions(options); } catch (NullPointerException e) { throw new CoreException(EclipseMessageUtils.createErrorStatus( "NPE occured during projects mavenization.\n\n" + "The possible cause is that the M2Eclipse Maven indexes in your current workspace might be corrupted. " + "Please remove folder {workspace}/.metadata/.plugins/org.maven.ide.eclipse/, and then restart your IDE.", e)); } // The Mavenization also seemed to take the META-SRC src directory and add an exclusion pattern along with // setting its output location to itself. Maybe they wanted to do a class library folder? Either way its // no good for us. Secondly, we are setting the Maven classpath container to have its entries exported by default. // Finally, we are adding the classpath entry attribute 'org.eclipse.jst.component.dependency' in case the project // is a WTP web project so that WTP will use the maven classpath container when deploying to its runtime servers. boolean changed = false; final List<IClasspathEntry> newEntries = ListUtil.list(); final IPath containerPath = new Path(SOAMavenConstants.MAVEN_CLASSPATH_CONTAINER_ID); for (final IClasspathEntry cpEntry : JDTUtil.rawClasspath(javaProject, true)) { if (cpEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (cpEntry.getPath().equals(containerPath)) { newEntries.add(JavaCore.newContainerEntry(containerPath, true)); changed |= true; } } else if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (!ArrayUtils.isEmpty(cpEntry.getExclusionPatterns()) || cpEntry.getOutputLocation() != null) { newEntries.add(JavaCore.newSourceEntry(cpEntry.getPath())); changed |= true; } else { newEntries.add(cpEntry); } } else { newEntries.add(cpEntry); } } ProgressUtil.progressOneStep(monitor, 15); if (changed) { javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), null); ProgressUtil.progressOneStep(monitor); //This is a hot fix for the Maven classpath container issue, //should be removed as soon as the M2Eclipse guys fix it int count = 0; //we only go to sleep 5 times. while (MavenCoreUtils.getMaven2ClasspathContainer(javaProject).getClasspathEntries().length == 0 && count < 5) { logger.warning("Maven Classpath is empty->", SOAMavenConstants.MAVEN_CLASSPATH_CONTAINER_ID, ", going to sleep..."); Thread.sleep(1000); ProgressUtil.progressOneStep(monitor, 10); count++; } } } finally { if (SOALogger.DEBUG) logger.exiting(); } }
From source file:org.eclipse.ajdt.core.buildpath.BuildConfigurationUtils.java
License:Open Source License
public static void saveBuildConfiguration(IFile ifile) { File file = ifile.getLocation().toFile(); IProject project = ifile.getProject(); try {// ww w .j a v a 2s . c om IJavaProject jp = JavaCore.create(project); IClasspathEntry[] entries = jp.getRawClasspath(); List srcIncludes = new ArrayList(); List srcExcludes = new ArrayList(); List srcInclusionpatterns = new ArrayList(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath srcpath = entry.getPath(); srcpath = srcpath.removeFirstSegments(1); String path = srcpath.toString().trim(); if (!path.endsWith("/")) { //$NON-NLS-1$ path = path + "/"; //$NON-NLS-1$ } srcIncludes.add(path); IPath[] inclusions = entry.getInclusionPatterns(); for (int j = 0; j < inclusions.length; j++) { srcInclusionpatterns.add((path.length() > 1 ? path : "") + inclusions[j]); //$NON-NLS-1$ } IPath[] exclusions = entry.getExclusionPatterns(); for (int j = 0; j < exclusions.length; j++) { srcExcludes.add((path.length() > 1 ? path : "") + exclusions[j]); //$NON-NLS-1$ } } } BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(file)); printProperties(bw, "src.includes", srcIncludes); //$NON-NLS-1$ printProperties(bw, "src.excludes", srcExcludes); //$NON-NLS-1$ printProperties(bw, "src.inclusionpatterns", srcInclusionpatterns); //$NON-NLS-1$ } catch (IOException e) { } finally { if (bw != null) { try { bw.close(); } catch (IOException e) { } } } } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.internal.core.ClasspathModifier.java
License:Open Source License
/** * Find out whether the <code>IResource</code> excluded or not. * // w w w. jav a 2 s . co m * @param resource * the resource to be checked * @param project * the Java project * @return <code>true</code> if the resource is excluded, <code> * false</code> * otherwise * @throws JavaModelException */ public static boolean isExcluded(IResource resource, IJavaProject project) throws JavaModelException { IPackageFragmentRoot root = getFragmentRoot(resource, project, null); if (root == null) return false; String fragmentName = getName(resource.getFullPath(), root.getPath()); fragmentName = completeName(fragmentName); IClasspathEntry entry = root.getRawClasspathEntry(); return entry != null && contains(new Path(fragmentName), entry.getExclusionPatterns()); }
From source file:org.eclipse.ajdt.internal.core.ClasspathModifier.java
License:Open Source License
/** * Find out whether one of the <code>IResource</code>'s parents * is excluded./*from w w w . j a va 2 s. c o m*/ * * @param resource check the resources parents whether they are * excluded or not * @param project the Java project * @return <code>true</code> if there is an excluded parent, * <code>false</code> otherwise * @throws JavaModelException */ public static boolean parentExcluded(IResource resource, IJavaProject project) throws JavaModelException { if (resource.getFullPath().equals(project.getPath())) return false; IPackageFragmentRoot root = getFragmentRoot(resource, project, null); if (root == null) { return true; } IPath path = resource.getFullPath().removeFirstSegments(root.getPath().segmentCount()); IClasspathEntry entry = root.getRawClasspathEntry(); if (entry == null) return true; // there is no build path entry, this is equal to the fact that the parent is excluded while (path.segmentCount() > 0) { if (contains(path, entry.getExclusionPatterns())) return true; path = path.removeLastSegments(1); } return false; }
From source file:org.eclipse.ajdt.internal.utils.AJDTUtils.java
License:Open Source License
private static void includeAJfiles(IProject project, boolean prompt) { IJavaProject jp = JavaCore.create(project); try {/* w w w . jav a 2 s . c om*/ boolean changed = false; IClasspathEntry[] cpEntry = jp.getRawClasspath(); for (int i = 0; i < cpEntry.length; i++) { IClasspathEntry entry = cpEntry[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath[] exc = entry.getExclusionPatterns(); if (exc != null) { List<IPath> removeList = new ArrayList<IPath>(); for (int j = 0; j < exc.length; j++) { String ext = exc[j].getFileExtension(); if ((ext != null) && ext.equals("aj")) { //$NON-NLS-1$ removeList.add(exc[j]); } } if (removeList.size() > 0) { IPath[] exc2 = new IPath[exc.length - removeList.size()]; int ind = 0; for (int j = 0; j < exc.length; j++) { if (!removeList.contains(exc[j])) { exc2[ind++] = exc[j]; } } IClasspathEntry classpathEntry = JavaCore.newSourceEntry(entry.getPath(), exc2); cpEntry[i] = classpathEntry; changed = true; } } } } if (changed) { boolean restore = true; if (prompt) { IWorkbenchWindow window = AspectJUIPlugin.getDefault().getWorkbench() .getActiveWorkbenchWindow(); restore = MessageDialog.openQuestion(window.getShell(), UIMessages.ExcludedAJ_title, UIMessages.ExcludedAJ_message); } if (restore) { jp.setRawClasspath(cpEntry, null); } } } catch (JavaModelException e) { } }
From source file:org.eclipse.ant.internal.ui.datatransfer.EclipseClasspath.java
License:Open Source License
private void handleSources(IClasspathEntry entry) throws JavaModelException { String projectRoot = ExportUtil.getProjectRoot(project); String defaultClassDir = project.getOutputLocation().toString(); String defaultClassDirAbsolute = ExportUtil.resolve(project.getOutputLocation()); if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { // found source path IPath srcDirPath = entry.getPath(); IPath classDirPath = entry.getOutputLocation(); String srcDir = handleLinkedResource(srcDirPath); ExportUtil.removeProjectRoot((srcDirPath != null) ? srcDirPath.toString() : projectRoot, project.getProject());// ww w. ja v a2 s . c o m String classDir = ExportUtil.removeProjectRoot( (classDirPath != null) ? classDirPath.toString() : defaultClassDir, project.getProject()); srcDirs.add(srcDir); classDirs.add(classDir); String classDirAbsolute = (classDirPath != null) ? ExportUtil.resolve(classDirPath) : defaultClassDirAbsolute; rawClassPathEntries.add(classDir); rawClassPathEntriesAbsolute.add(classDirAbsolute); IPath[] inclusions = entry.getInclusionPatterns(); List<String> inclusionList = new ArrayList<>(); for (int j = 0; j < inclusions.length; j++) { if (inclusions[j] != null) { inclusionList.add(ExportUtil.removeProjectRoot(inclusions[j].toString(), project.getProject())); } } inclusionLists.add(inclusionList); IPath[] exclusions = entry.getExclusionPatterns(); List<String> exclusionList = new ArrayList<>(); for (int j = 0; j < exclusions.length; j++) { if (exclusions[j] != null) { exclusionList.add(ExportUtil.removeProjectRoot(exclusions[j].toString(), project.getProject())); } } exclusionLists.add(exclusionList); } }
From source file:org.eclipse.che.plugin.maven.server.core.classpath.ClasspathEntryHelper.java
License:Open Source License
private void setClasspathEntry(IClasspathEntry entry) { this.kind = entry.getEntryKind(); this.path = entry.getPath(); this.exported = entry.isExported(); this.outputLocation = entry.getOutputLocation(); this.accessRules = new ArrayList<>(); for (IAccessRule rule : entry.getAccessRules()) { this.accessRules.add(rule); }/*from w w w . j av a2s .c o m*/ this.attributes = new HashMap<>(); for (IClasspathAttribute attribute : entry.getExtraAttributes()) { attributes.put(attribute.getName(), attribute.getValue()); } this.sourcePath = entry.getSourceAttachmentPath(); this.sourceRootPath = entry.getSourceAttachmentRootPath(); setInclusionPatterns(entry.getInclusionPatterns()); setExclusionPatterns(entry.getExclusionPatterns()); this.combineAccessRules = entry.combineAccessRules(); String groupId = attributes.get(ClasspathManager.GROUP_ID_ATTRIBUTE); String artifactId = attributes.get(ClasspathManager.ARTIFACT_ID_ATTRIBUTE); String version = attributes.get(ClasspathManager.VERSION_ATTRIBUTE); String packaging = attributes.get(ClasspathManager.PACKAGING_ATTRIBUTE); String classifier = attributes.get(ClasspathManager.CLASSIFIER_ATTRIBUTE); if (groupId != null && artifactId != null && version != null) { this.artifactKey = new MavenArtifactKey(groupId, artifactId, version, packaging, classifier); } }