List of usage examples for org.eclipse.jdt.core JavaCore newSourceEntry
public static IClasspathEntry newSourceEntry(IPath path, IPath[] exclusionPatterns)
CPE_SOURCE for the project's source folder identified by the given absolute workspace-relative path but excluding all source files with paths matching any of the given patterns. From source file:byke.tests.workspaceutils.JavaProject.java
License:Open Source License
private IPackageFragmentRoot createSourceFolder(final String path) throws CoreException, JavaModelException { IFolder folder = safeGetFolder(path); IPackageFragmentRoot root = _javaProject.getPackageFragmentRoot(folder); IClasspathEntry newSourceEntry = JavaCore.newSourceEntry(root.getPath(), new IPath[] {}); addClasspathEntry(newSourceEntry);/*w w w . ja v a2 s. co m*/ return root; }
From source file:com.google.gwt.eclipse.core.runtime.GWTRuntimeTest.java
License:Open Source License
/** * Tests that we find an {@link com.google.gdt.eclipse.core.sdk.Sdk} on the * gwt-user project.//from w w w . jav a 2 s . c o m * * @throws Exception */ public void testFindSdkFor_GwtUserProject() throws Exception { GwtRuntimeTestUtilities.importGwtSourceProjects(); try { IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); IJavaProject javaProject = javaModel.getJavaProject("gwt-user"); GWTRuntime sdk = GWTRuntime.findSdkFor(javaProject); IClasspathEntry gwtUserEntry = JavaCore.newSourceEntry( javaModel.getJavaProject("gwt-user").getPath().append("core/src"), new IPath[] { new Path("**/super/**") }); /* * NOTE: Passing null for the IClasspathAttribute array tickles a bug in * eclipse 3.3. */ IClasspathEntry gwtDevEntry = JavaCore.newProjectEntry(javaModel.getJavaProject("gwt-dev").getPath(), null, false, new IClasspathAttribute[0] /* */, false); IClasspathEntry[] expected = new IClasspathEntry[] { gwtUserEntry, gwtDevEntry }; assertEquals(expected, sdk.getClasspathEntries()); } finally { GwtRuntimeTestUtilities.removeGwtSourceProjects(); } }
From source file:com.microsoft.azure.hdinsight.projects.CreateProjectUtil.java
License:Open Source License
private static void createResourceStructForLocalRunScalaProject(IFolder sourceRootFolder, String rootPath, IProject project) throws CoreException { copyFileTo(Scala_Local_Run_Sample, rootPath); final IFolder dataFolder = sourceRootFolder.getParent().getFolder(new Path("data")); if (!dataFolder.exists()) { dataFolder.create(false, true, null); }/*www .j a v a 2 s . c o m*/ copyFileTo(Scala_Local_Run_Sample_Data, dataFolder.getLocation().toFile().getAbsolutePath()); IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] entries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); IPath dataPath = javaProject.getPath().append("data"); IClasspathEntry dataEntry = JavaCore.newSourceEntry(dataPath, null); newEntries[entries.length] = JavaCore.newSourceEntry(dataEntry.getPath()); javaProject.setRawClasspath(newEntries, null); }
From source file:com.redhat.ceylon.eclipse.code.wizard.ClassPathDetector.java
License:Open Source License
private void detectSourceFolders(ArrayList<IClasspathEntry> resEntries) { ArrayList<IClasspathEntry> res = new ArrayList<IClasspathEntry>(); Set<IPath> sourceFolderSet = fSourceFolders.keySet(); for (Iterator<IPath> iter = sourceFolderSet.iterator(); iter.hasNext();) { IPath path = iter.next();/*from w ww. ja v a2 s.c om*/ ArrayList<IPath> excluded = new ArrayList<IPath>(); for (Iterator<IPath> inner = sourceFolderSet.iterator(); inner.hasNext();) { IPath other = inner.next(); if (!path.equals(other) && path.isPrefixOf(other)) { IPath pathToExclude = other.removeFirstSegments(path.segmentCount()).addTrailingSeparator(); excluded.add(pathToExclude); } } IPath[] excludedPaths = excluded.toArray(new IPath[excluded.size()]); IClasspathEntry entry = JavaCore.newSourceEntry(path, excludedPaths); res.add(entry); } for (IPath p : fCeylonSourceFolders) { resEntries.add(JavaCore.newSourceEntry(p)); } // Collections.sort(res, new CPSorter()); resEntries.addAll(res); }
From source file:de.lynorics.eclipse.jangaroo.m2e.JangarooProjectConfigurator.java
License:Open Source License
private void addSourcePath(IJavaProject javaProject, List<IClasspathEntry> entries, String path) throws JavaModelException { IPath srcPath = javaProject.getPath().append(path); IClasspathEntry srcEntry = JavaCore.newSourceEntry(srcPath, null); boolean found = false; for (IClasspathEntry entry : entries) { if (entry.getPath().makeRelative().toString().equals(srcEntry.getPath().makeRelative().toString())) { found = true;/* w ww .j a v a 2 s .c o m*/ break; } } if (!found) { entries.add(JavaCore.newSourceEntry(srcEntry.getPath())); } }
From source file:org.ebayopensource.turmeric.eclipse.maven.sconfig.TurmerStandardProjectConfigurator.java
License:Open Source License
@Override public void configure(ProjectConfigurationRequest projRequest, IProgressMonitor monitor) throws CoreException { if (projRequest == null) { return;// w w w .j a va 2 s .com } SupportedProjectType projectType = null; IProject project = projRequest.getProject(); if (isInterfaceProject(projRequest)) { projectType = SupportedProjectType.INTERFACE; } else if (isImplementationProject(projRequest)) { projectType = SupportedProjectType.IMPL; } else if (isErrorLibProject(projRequest)) { projectType = SupportedProjectType.ERROR_LIBRARY; } else if (isTypeLibProject(projRequest)) { projectType = SupportedProjectType.TYPE_LIBRARY; } else if (isConsumerLibProject(projRequest)) { projectType = SupportedProjectType.CONSUMER; } else { return; } String natureId = GlobalRepositorySystem.instanceOf().getActiveRepositorySystem() .getProjectNatureId(projectType); JDTUtil.addNatures(project, monitor, natureId); List<IPath> additionalSrcDirs = new ArrayList<IPath>(); additionalSrcDirs.add(new Path("target/generated-sources/codegen")); additionalSrcDirs.add(new Path("target/generated-resources/codegen")); final IJavaProject javaProject = JavaCore.create(project); final List<IClasspathEntry> entries = ListUtil.arrayList(javaProject.readRawClasspath()); for (IPath path : additionalSrcDirs) { IFolder folder = project.getFolder(path); if (folder.exists()) { IPath srcPath = project.getFolder(path).getFullPath(); if (containsSourcePath(entries, srcPath) == false) { entries.add(JavaCore.newSourceEntry(srcPath, new IPath[0])); } } } javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[0]), monitor); }
From source file:org.eclipse.ajdt.core.buildpath.BuildConfigurationUtils.java
License:Open Source License
public static void applyBuildConfiguration(IFile ifile) { File file = ifile.getLocation().toFile(); BufferedReader br = null;//from www . j a v a2 s . c o m try { IJavaProject project = JavaCore.create(ifile.getProject()); List classpathEntries = new ArrayList(); IClasspathEntry[] originalEntries = project.getRawClasspath(); for (int i = 0; i < originalEntries.length; i++) { IClasspathEntry entry = originalEntries[i]; if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) { classpathEntries.add(entry); } } List srcFolders = new ArrayList(); Map srcFoldersToIncludes = new HashMap(); Map srcFoldersToExcludes = new HashMap(); br = new BufferedReader(new FileReader(file)); Properties properties = new Properties(); properties.load(ifile.getContents()); Enumeration iter = properties.keys(); // first stage - find any source folders while (iter.hasMoreElements()) { String name = iter.nextElement().toString(); String value = properties.get(name).toString(); String[] values = value.split(","); //$NON-NLS-1$ if (name.equals("src.includes")) { //$NON-NLS-1$ for (int i = 0; i < values.length; i++) { String inc = values[i]; if (inc.equals("/")) { //$NON-NLS-1$ srcFolders.add(inc); } else if (inc.indexOf("/") == inc.length() - 1) { //$NON-NLS-1$ if (project.getProject().getFolder(inc) != null && project.getProject().getFolder(inc).exists()) { srcFolders.add(inc); } } } } } // second stage - identify include and exclude filters iter = properties.keys(); if (srcFolders.isEmpty()) { srcFolders.add(""); //$NON-NLS-1$ } while (iter.hasMoreElements()) { String name = iter.nextElement().toString(); String value = properties.get(name).toString(); String[] values = value.split(","); //$NON-NLS-1$ if (name.equals("src.inclusionpatterns")) { //$NON-NLS-1$ for (int i = 0; i < values.length; i++) { String inc = values[i]; for (Iterator iterator = srcFolders.iterator(); iterator.hasNext();) { String srcFolder = (String) iterator.next(); if (inc.startsWith(srcFolder)) { List incs = (List) srcFoldersToIncludes.get(srcFolder); if (incs == null) { incs = new ArrayList(); } incs.add(inc); srcFoldersToIncludes.put(srcFolder, incs); } } } } else if (name.equals("src.excludes")) { //$NON-NLS-1$ for (int i = 0; i < values.length; i++) { String exc = values[i]; for (Iterator iterator = srcFolders.iterator(); iterator.hasNext();) { String srcFolder = (String) iterator.next(); if (srcFolder.equals("/") || exc.startsWith(srcFolder)) { //$NON-NLS-1$ List excs = (List) srcFoldersToExcludes.get(srcFolder); if (excs == null) { excs = new ArrayList(); } excs.add(exc); srcFoldersToExcludes.put(srcFolder, excs); } } } } } // third stage - create classpath entries IClasspathEntry[] entries = new IClasspathEntry[srcFolders.size() + classpathEntries.size()]; for (int i = 0; i < entries.length; i++) { if (srcFolders.size() > i) { String srcFolder = (String) srcFolders.get(i); IPath path = project.getPath().append(stripSlash(srcFolder)); List exclusions = (List) srcFoldersToExcludes.get(srcFolder); if (exclusions == null) { exclusions = Collections.EMPTY_LIST; } List inclusions = (List) srcFoldersToIncludes.get(srcFolder); if (inclusions == null) { inclusions = Collections.EMPTY_LIST; } IPath[] exclusionPatterns = new IPath[exclusions.size()]; for (int j = 0; j < exclusionPatterns.length; j++) { String exclusionPathStr = (String) exclusions.get(j); if (exclusionPathStr.startsWith(srcFolder)) { exclusionPathStr = exclusionPathStr.substring(srcFolder.length()); } IPath exclusionPath = new Path(exclusionPathStr); exclusionPatterns[j] = exclusionPath; } IPath[] inclusionPatterns = new IPath[inclusions.size()]; for (int j = 0; j < inclusionPatterns.length; j++) { String inclusionPathStr = (String) inclusions.get(j); if (inclusionPathStr.startsWith(srcFolder)) { inclusionPathStr = inclusionPathStr.substring(srcFolder.length()); } IPath inclusionPath = new Path(inclusionPathStr); inclusionPatterns[j] = inclusionPath; } IClasspathEntry classpathEntry = JavaCore.newSourceEntry(path, exclusionPatterns); //new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_SOURCE, path, ClasspathEntry.INCLUDE_ALL, exclusionPatterns, null, null, null, true, ClasspathEntry.NO_ACCESS_RULES, false, ClasspathEntry.NO_EXTRA_ATTRIBUTES); entries[i] = classpathEntry; } else { entries[i] = (IClasspathEntry) classpathEntries.get(i - srcFolders.size()); } } project.setRawClasspath(entries, null); } catch (FileNotFoundException e) { } catch (JavaModelException e) { } catch (IOException e) { } catch (CoreException e) { } finally { if (br != null) { try { br.close(); } catch (IOException e) { } } } }
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 {/*from w w w . jav a2 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.ajdt.internal.utils.AJDTUtils.java
License:Open Source License
private static void excludeAJfiles(IProject project) { IJavaProject jp = JavaCore.create(project); try {/*from w w w . ja va 2s .c o m*/ 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) { List<IPath> excludeList = new ArrayList<IPath>(); IPackageFragmentRoot[] roots = jp.findPackageFragmentRoots(entry); for (int j = 0; j < roots.length; j++) { IJavaElement[] rootFragments; try { rootFragments = roots[j].getChildren(); for (int k = 0; k < rootFragments.length; k++) { if (rootFragments[k] instanceof IPackageFragment) { IPackageFragment pack = (IPackageFragment) rootFragments[k]; ICompilationUnit[] files = pack.getCompilationUnits(); for (int l = 0; l < files.length; l++) { IResource resource = files[l].getResource(); if (resource.getFileExtension().equals("aj")) { //$NON-NLS-1$ IPath resPath = resource.getFullPath(); int seg = resPath.matchingFirstSegments(roots[j].getPath()); excludeList.add(resPath.removeFirstSegments(seg)); } } } } } catch (JavaModelException e) { } } if (excludeList.size() > 0) { IPath[] exc = new IPath[excludeList.size()]; excludeList.toArray(exc); IClasspathEntry classpathEntry = JavaCore.newSourceEntry(entry.getPath(), exc); cpEntry[i] = classpathEntry; changed = true; } } } if (changed) { jp.setRawClasspath(cpEntry, null); } } catch (JavaModelException e) { } }
From source file:org.eclipse.gemoc.execution.concurrent.ccsljavaxdsml.ui.builder.ToggleNatureAction.java
License:Open Source License
public void addSourceFolder(IProject project, String folder) { try {//from w w w. j a va2 s. co m IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] entries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); IPath srcPath = javaProject.getPath().append(folder); IClasspathEntry srcEntry = JavaCore.newSourceEntry(srcPath, null); boolean entryfound = false; for (IClasspathEntry cpe : entries) { if (cpe.equals(srcEntry)) { entryfound = true; } } if (!entryfound) { newEntries[entries.length] = JavaCore.newSourceEntry(srcEntry.getPath()); javaProject.setRawClasspath(newEntries, null); } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } }