org.eclipse.jdt.core.IClasspathEntry Java Examples

The following examples show how to use org.eclipse.jdt.core.IClasspathEntry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServletClasspathProviderTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testCached_noResolver() {
  IRuntime runtime = mock(IRuntime.class);
  IClasspathEntry[] entries = new IClasspathEntry[0];

  AtomicReference<IClasspathEntry[]> requestedUpdate = new AtomicReference<>(null);
  fixture =
      new ServletClasspathProvider(resolver) {
        @Override
        protected void requestClasspathContainerUpdate(
            IProject project, IRuntime runtime, IClasspathEntry[] entries) {
          requestedUpdate.set(entries);
        }
      };
  fixture.libraryEntries.put(WebFacetUtils.WEB_31, entries);

  IClasspathEntry[] result =
      fixture.resolveClasspathContainer(projectCreator.getProject(), runtime);
  assertSame(entries, result);
  assertNull(requestedUpdate.get());
  verifyNoMoreInteractions(resolver);
}
 
Example #2
Source File: Importer.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Sometimes the project configuration is corrupt and a Java runtime is not on the classpath
 * @param monitor
 * @param javaProject
 * @throws JavaModelException
 */
private void fixMissingJavaRuntime(IProgressMonitor monitor, IJavaProject javaProject) throws JavaModelException {
	
	if (!javaProject.getProject().getName().equals("config")) {
		IClasspathEntry[] classPathEntries = javaProject.getRawClasspath();
		boolean found = false;
		for (IClasspathEntry classpathEntry : classPathEntries) {
			// fix missing runtime
			if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
				if (classpathEntry.getPath().toString().startsWith("org.eclipse.jdt.launching.JRE_CONTAINER")) {
					found = true;
					break;
				}
			}
		}
		
		if (!found) {
			IClasspathEntry entry = JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER"),
					false);
			Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>(Arrays.asList(classPathEntries));
			entries.add(entry);
			FixProjectsUtils.setClasspath(entries.toArray(new IClasspathEntry[entries.size()]), javaProject,
					monitor);
		}
	}
}
 
Example #3
Source File: FixedFatJarExportPage.java    From sarl with Apache License 2.0 6 votes vote down vote up
private static boolean isRootAt(IPackageFragmentRoot root, IPath entry) {
	try {
		IClasspathEntry cpe= root.getRawClasspathEntry();
		if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
			IPath outputLocation= cpe.getOutputLocation();
			if (outputLocation == null)
				outputLocation= root.getJavaProject().getOutputLocation();

			IPath location= ResourcesPlugin.getWorkspace().getRoot().findMember(outputLocation).getLocation();
			if (entry.equals(location))
				return true;
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}

	IResource resource= root.getResource();
	if (resource != null && entry.equals(resource.getLocation()))
		return true;

	IPath path= root.getPath();
	if (path != null && entry.equals(path))
		return true;

	return false;
}
 
Example #4
Source File: JavadocConfigurationPropertyPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IRunnableWithProgress getRunnable(final Shell shell, final IJavaElement elem, final URL javadocLocation, final IClasspathEntry entry, final IPath containerPath) {
	return new IRunnableWithProgress() {
		public void run(IProgressMonitor monitor) throws InvocationTargetException {
			try {
				IJavaProject project= elem.getJavaProject();
				if (elem instanceof IPackageFragmentRoot) {
					CPListElement cpElem= CPListElement.createFromExisting(entry, project);
					String loc= javadocLocation != null ? javadocLocation.toExternalForm() : null;
					cpElem.setAttribute(CPListElement.JAVADOC, loc);
					IClasspathEntry newEntry= cpElem.getClasspathEntry();
					String[] changedAttributes= { CPListElement.JAVADOC };
					BuildPathSupport.modifyClasspathEntry(shell, newEntry, changedAttributes, project, containerPath, entry.getReferencingEntry() != null, monitor);
				} else {
					JavaUI.setProjectJavadocLocation(project, javadocLocation);
				}
			} catch (CoreException e) {
				throw new InvocationTargetException(e);
			}
		}
	};
}
 
Example #5
Source File: JavaProject.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see IJavaProject
 */
public IPath readOutputLocation() {
	// Read classpath file without creating markers nor logging problems
	IClasspathEntry[][] classpath = readFileEntries(null/*not interested in unknown elements*/);
	if (classpath[0] == JavaProject.INVALID_CLASSPATH)
		return defaultOutputLocation();

	// extract the output location
	IPath outputLocation = null;
	if (classpath[0].length > 0) {
		IClasspathEntry entry = classpath[0][classpath[0].length - 1];
		if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
			outputLocation = entry.getPath();
		}
	}
	return outputLocation;
}
 
Example #6
Source File: FatJarPackageWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean isRootAt(IPackageFragmentRoot root, IPath entry) {
	try {
		IClasspathEntry cpe= root.getRawClasspathEntry();
		if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
			IPath outputLocation= cpe.getOutputLocation();
			if (outputLocation == null)
				outputLocation= root.getJavaProject().getOutputLocation();

			IPath location= ResourcesPlugin.getWorkspace().getRoot().findMember(outputLocation).getLocation();
			if (entry.equals(location))
				return true;
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}

	IResource resource= root.getResource();
	if (resource != null && entry.equals(resource.getLocation()))
		return true;

	IPath path= root.getPath();
	if (path != null && entry.equals(path))
		return true;

	return false;
}
 
Example #7
Source File: WebAppProjectCreator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
protected void setProjectClasspath(IJavaProject javaProject, IFolder srcFolder, IProgressMonitor monitor)
    throws JavaModelException {
  List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
  classpathEntries.add(JavaCore.newSourceEntry(srcFolder.getFullPath()));

  // Add the "test" folder as a src path, if it exists
  IProject project = javaProject.getProject();
  IFolder testFolder = project.getFolder("test");
  if (testFolder.exists()) {
    classpathEntries.add(JavaCore.newSourceEntry(testFolder.getFullPath(), new IPath[0],
        project.getFullPath().append("test-classes")));
  }

  // Add our container entries to the path
  for (IPath containerPath : containerPaths) {
    classpathEntries.add(JavaCore.newContainerEntry(containerPath));
  }

  classpathEntries.addAll(Arrays.asList(PreferenceConstants.getDefaultJRELibrary()));

  javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[0]), monitor);
}
 
Example #8
Source File: FixProjectsUtils.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
public static void addToClassPath(IResource res, int type, IJavaProject javaProject, IProgressMonitor monitor) throws JavaModelException
{
	Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>(Arrays.asList(javaProject.getRawClasspath()));
	IClasspathEntry entry = null;
	switch (type) {
	case IClasspathEntry.CPE_SOURCE: 
		entry = JavaCore.newSourceEntry(res.getFullPath());
		break;
	case IClasspathEntry.CPE_LIBRARY: 
		entry = JavaCore.newLibraryEntry(res.getFullPath(), null, null, true);
		break;
	case IClasspathEntry.CPE_PROJECT: 
		entry = JavaCore.newProjectEntry(res.getFullPath(), true);
		break;
	}
		
	entries.add(entry);
	setClasspath(entries.toArray(new IClasspathEntry[entries.size()]), javaProject, monitor);
}
 
Example #9
Source File: ResetAllAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean hasChange(IJavaProject project) throws JavaModelException {
	if (!project.getOutputLocation().equals(fOutputLocation))
           return true;

	IClasspathEntry[] currentEntries= project.getRawClasspath();
       if (currentEntries.length != fEntries.size())
           return true;

       int i= 0;
       for (Iterator<CPListElement> iterator= fEntries.iterator(); iterator.hasNext();) {
        CPListElement oldEntrie= iterator.next();
        if (!oldEntrie.getClasspathEntry().equals(currentEntries[i]))
        	return true;
        i++;
       }
       return false;
}
 
Example #10
Source File: ProjectsWorkbookPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private CPListElement[] addProjectDialog() {

		try {
			Object[] selectArr= getNotYetRequiredProjects();
			new JavaElementComparator().sort(null, selectArr);

			ListSelectionDialog dialog= new ListSelectionDialog(getShell(), Arrays.asList(selectArr), new ArrayContentProvider(), new JavaUILabelProvider(), NewWizardMessages.ProjectsWorkbookPage_chooseProjects_message);
			dialog.setTitle(NewWizardMessages.ProjectsWorkbookPage_chooseProjects_title);
			dialog.setHelpAvailable(false);
			if (dialog.open() == Window.OK) {
				Object[] result= dialog.getResult();
				CPListElement[] cpElements= new CPListElement[result.length];
				for (int i= 0; i < result.length; i++) {
					IJavaProject curr= (IJavaProject) result[i];
					cpElements[i]= new CPListElement(fCurrJProject, IClasspathEntry.CPE_PROJECT, curr.getPath(), curr.getResource());
				}
				return cpElements;
			}
		} catch (JavaModelException e) {
			return null;
		}
		return null;
	}
 
Example #11
Source File: JavaProjectHelper.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates and adds a class folder to the class path.
 *
 * @param jproject
 *            The parent project
 * @param containerName
 * @param sourceAttachPath
 *            The source attachment path
 * @param sourceAttachRoot
 *            The source attachment root path
 * @return The handle of the created root
 * @throws CoreException
 */
public static IPackageFragmentRoot addClassFolder(IJavaProject jproject, String containerName, IPath sourceAttachPath,
        IPath sourceAttachRoot) throws CoreException {
    IProject project = jproject.getProject();
    IContainer container = null;
    if (containerName == null || containerName.length() == 0) {
        container = project;
    } else {
        IFolder folder = project.getFolder(containerName);
        if (!folder.exists()) {
            CoreUtility.createFolder(folder, false, true, null);
        }
        container = folder;
    }
    IClasspathEntry cpe = JavaCore.newLibraryEntry(container.getFullPath(), sourceAttachPath, sourceAttachRoot);
    addToClasspath(jproject, cpe);
    return jproject.getPackageFragmentRoot(container);
}
 
Example #12
Source File: ClassPathDetector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void detectLibraries(ArrayList<IClasspathEntry> cpEntries, IPath outputLocation) {
	ArrayList<IClasspathEntry> res= new ArrayList<IClasspathEntry>();
	Set<IPath> sourceFolderSet= fSourceFolders.keySet();
	for (Iterator<IPath> iter= fJARFiles.iterator(); iter.hasNext();) {
		IPath path= iter.next();
		if (isNested(path, sourceFolderSet.iterator())) {
			continue;
		}
		if (outputLocation != null && outputLocation.isPrefixOf(path)) {
			continue;
		}
		IClasspathEntry entry= JavaCore.newLibraryEntry(path, null, null);
		res.add(entry);
	}
	Collections.sort(res, new CPSorter());
	cpEntries.addAll(res);
}
 
Example #13
Source File: CloudLibrariesPageTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testPreventMultipleContainers() {
  IClasspathEntry existingEntry = mock(IClasspathEntry.class);
  when(existingEntry.getEntryKind()).thenReturn(IClasspathEntry.CPE_CONTAINER);
  when(existingEntry.getPath()).thenReturn(MASTER_CONTAINER_PATH);
  assertTrue(LibraryClasspathContainer.isEntry(existingEntry));

  // explicitly configure App Engine and GCP libraries
  IJavaProject javaProject = plainJavaProjectCreator.getJavaProject();

  page.initialize(javaProject, new IClasspathEntry[] {existingEntry});
  page.setSelection(null);
  page.createControl(shellTestResource.getShell());

  assertTrue(page.finish()); // should be ok
  assertNull(page.getSelection()); // no new container created
}
 
Example #14
Source File: JavaClasspathParser.java    From sarl with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the kind of a <code>PackageFragmentRoot</code> from its <code>String</code> form.
 *
 * @param kindStr
 *            - string to test
 * @return the integer identifier of the type of the specified string: CPE_PROJECT, CPE_VARIABLE, CPE_CONTAINER, etc.
 */
@SuppressWarnings("checkstyle:equalsavoidnull")
private static int kindFromString(String kindStr) {

    if (kindStr.equalsIgnoreCase("prj")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_PROJECT;
    }
    if (kindStr.equalsIgnoreCase("var")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_VARIABLE;
    }
    if (kindStr.equalsIgnoreCase("con")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_CONTAINER;
    }
    if (kindStr.equalsIgnoreCase("src")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_SOURCE;
    }
    if (kindStr.equalsIgnoreCase("lib")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_LIBRARY;
    }
    if (kindStr.equalsIgnoreCase("output")) { //$NON-NLS-1$
        return ClasspathEntry.K_OUTPUT;
    }
    return -1;
}
 
Example #15
Source File: SourceAttacherJob.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
LibraryClasspathContainer attachSource(IClasspathContainer container) throws Exception {
  if (!(container instanceof LibraryClasspathContainer)) {
    logger.log(Level.FINE, Messages.getString("ContainerClassUnexpected",
        container.getClass().getName(), LibraryClasspathContainer.class.getName()));
    return null;
  }

  LibraryClasspathContainer libraryClasspathContainer = (LibraryClasspathContainer) container;
  IPath sourceArtifactPath = sourceArtifactPathProvider.call();
  List<IClasspathEntry> newClasspathEntries = new ArrayList<>();

  for (IClasspathEntry entry : libraryClasspathContainer.getClasspathEntries()) {
    if (!entry.getPath().equals(libraryPath)) {
      newClasspathEntries.add(entry);
    } else {
      newClasspathEntries.add(JavaCore.newLibraryEntry(
          entry.getPath(), sourceArtifactPath, null /* sourceAttachmentRootPath */,
          entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported()));
    }
  }

  return libraryClasspathContainer.copyWithNewEntries(newClasspathEntries);
}
 
Example #16
Source File: ClassPathContainer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ClassPathContainer(IJavaProject parent, IClasspathEntry entry) {
	super(parent);
	fClassPathEntry= entry;
	try {
		fContainer= JavaCore.getClasspathContainer(entry.getPath(), parent);
	} catch (JavaModelException e) {
		fContainer= null;
	}
}
 
Example #17
Source File: BuildPath.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the entry of {@code library} to be added to the classpath of {@code javaProject}, if
 * the project does not already have it. (Note that this does not add it to the classpath.)
 * Returns {@code null} otherwise.
 */
public static IClasspathEntry computeEntry(IJavaProject javaProject, Library library,
    IProgressMonitor monitor) throws CoreException {
  SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.getString("computing.entries"), 1); //$NON-NLS-1$
  
  IClasspathEntry libraryContainer = makeClasspathEntry(library);
  subMonitor.worked(1);

  IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
  boolean alreadyExists = Arrays.asList(rawClasspath).contains(libraryContainer);
  return alreadyExists ? null : libraryContainer;
}
 
Example #18
Source File: BinaryRefactoringHistoryWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the location URI of the classpath entry
 *
 * @param entry
 *            the classpath entry
 * @return the location URI
 */
public static URI getLocationURI(final IClasspathEntry entry) {
	IPath path= null;
	if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE)
		path= JavaCore.getResolvedVariablePath(entry.getPath());
	else
		path= entry.getPath();
	final IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
	URI location= null;
	if (root.exists(path)) {
		location= root.getFile(path).getRawLocationURI();
	} else
		location= URIUtil.toURI(path);
	return location;
}
 
Example #19
Source File: WorkspaceScenariosTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected IClasspathEntry addJarToProject(final IProject project, final byte[] jarData) {
  try {
    IClasspathEntry _xblockexpression = null;
    {
      final IFile jarFile = project.getFile("mydependency.jar");
      ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(jarData);
      jarFile.create(_byteArrayInputStream, true, null);
      _xblockexpression = JavaProjectSetupUtil.addJarToClasspath(JavaCore.create(project), jarFile);
    }
    return _xblockexpression;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #20
Source File: JDTAwareEclipseResourceFileSystemAccess2.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void addClasspathEntry(IContainer folder, IJavaProject project) throws JavaModelException {
	IClasspathEntry srcFolderClasspathEntry = JavaCore.newSourceEntry(folder.getFullPath());
	IClasspathEntry[] classPath = project.getRawClasspath();
	IClasspathEntry[] newClassPath = new IClasspathEntry[classPath.length + 1];
	System.arraycopy(classPath, 0, newClassPath, 0, classPath.length);
	newClassPath[newClassPath.length - 1] = srcFolderClasspathEntry;
	project.setRawClasspath(newClassPath, getMonitor());
}
 
Example #21
Source File: AddSourceFolderWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void addExclusionPatterns(CPListElement newEntry, List<CPListElement> existing, Set<CPListElement> modifiedEntries) {
	IPath entryPath= newEntry.getPath();
	for (int i= 0; i < existing.size(); i++) {
		CPListElement curr= existing.get(i);
		IPath currPath= curr.getPath();
		if (curr != newEntry && curr.getEntryKind() == IClasspathEntry.CPE_SOURCE && currPath.isPrefixOf(entryPath)) {
			boolean added= curr.addToExclusions(entryPath);
			if (added) {
				modifiedEntries.add(curr);
			}
		}
	}
}
 
Example #22
Source File: ProjectUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static IPath[] listSourcePaths(IJavaProject project) throws JavaModelException {
	List<IPath> result = new ArrayList<>();
	for (IClasspathEntry entry : project.getRawClasspath()) {
		if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
			result.add(entry.getPath());
		}
	}

	return result.toArray(new IPath[0]);
}
 
Example #23
Source File: LibraryClasspathContainerInitializerTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testInitialize_ifArtifactJarPathIsInvalidContainerResolvedFromScratch()
    throws CoreException, IOException {
  assertFalse(new File(NON_EXISTENT_FILE).exists());

  IClasspathEntry entry = mock(IClasspathEntry.class);
  when(entry.getPath()).thenReturn(new Path(NON_EXISTENT_FILE));
  IClasspathEntry[] entries = new IClasspathEntry[]{ entry };
  LibraryClasspathContainer container = mock(LibraryClasspathContainer.class);
  when(container.getClasspathEntries()).thenReturn(entries);
  when(serializer.loadContainer(any(IJavaProject.class), any(IPath.class))).thenReturn(container);

  boolean[] called = new boolean[] {false};
  LibraryClasspathContainerInitializer containerInitializer =
      new LibraryClasspathContainerInitializer(TEST_CONTAINER_PATH, serializer, resolverService) {
        @Override
        public void requestClasspathContainerUpdate(
            IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion)
            throws CoreException {
          called[0] = true;
        }
      };
  assertFalse(called[0]);
  containerInitializer.initialize(new Path(TEST_LIBRARY_PATH), testProject.getJavaProject());
  assertTrue(called[0]);
  verifyResolveServiceResolveContainerNotCalled();
}
 
Example #24
Source File: ClasspathContainerPreferencePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static int indexInClasspath(IClasspathEntry[] entries, IClasspathEntry entry) {
	for (int i= 0; i < entries.length; i++) {
		if (entries[i].equals(entry)) {
			return i;
		}
	}
	return -1;
}
 
Example #25
Source File: JavaProjectSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @deprecated {@link #addJreClasspathEntry(IJavaProject)} should be used instead of this method
 */
@Deprecated
public static void addJre15ClasspathEntry(IJavaProject javaProject) throws JavaModelException {
	IClasspathEntry existingJreContainerClasspathEntry = getJreContainerClasspathEntry(javaProject);
	if (existingJreContainerClasspathEntry == null) {
		addToClasspath(javaProject, JavaCore.newContainerEntry(new Path(JRE_CONTAINER_1_5)));
	}
}
 
Example #26
Source File: ProjectUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean isOnSourcePath(IPath sourcePath, IJavaProject project) throws JavaModelException {
	for (IClasspathEntry entry : project.getRawClasspath()) {
		if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getPath().equals(sourcePath)) {
			return true;
		}
	}

	return false;
}
 
Example #27
Source File: LibrariesWorkbookPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void attributeUpdated(CPListElement selElement, String[] changedAttributes) {
	Object parentContainer= selElement.getParentContainer();
	if (parentContainer instanceof CPListElement) { // inside a container: apply changes right away
		IClasspathEntry updatedEntry= selElement.getClasspathEntry();
		updateContainerEntry(updatedEntry, changedAttributes, fCurrJProject, ((CPListElement) parentContainer).getPath());
	}
}
 
Example #28
Source File: JavaProjectSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.17
 */
public static IFolder addSourceFolder(IJavaProject javaProject, String folderName, String[] inclusionPatterns, String[] exclusionPatterns, boolean build) throws CoreException,
		JavaModelException {
	
	IProject project = javaProject.getProject();
	IPath projectPath = project.getFullPath();
	
	deleteClasspathEntry(javaProject, projectPath);
	
	IFolder srcFolder = createSubFolder(project, folderName); //$NON-NLS-1$
	IClasspathEntry srcFolderClasspathEntry = JavaCore.newSourceEntry(srcFolder.getFullPath(), getInclusionPatterns(inclusionPatterns), getExclusionPatterns(exclusionPatterns), null);
	addToClasspath(javaProject, srcFolderClasspathEntry, build);
	return srcFolder;
}
 
Example #29
Source File: ClasspathModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find out whether the <code>IResource</code> excluded or not.
 *
 * @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(), null);
}
 
Example #30
Source File: IDEClassPathBlock.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private Object[] getNotYetRequiredProjects( ) throws JavaModelException
{
	ArrayList selectable = new ArrayList( );
	IWorkspaceRoot root = ResourcesPlugin.getWorkspace( ).getRoot( );
	IProject[] projects = root.getProjects( );
	for ( int i = 0; i < projects.length; i++ )
	{
		if ( isJavaProject( projects[i] ) )
		{
			selectable.add( JavaCore.create( projects[i] ) );
		}
	}

	if ( isJavaProject( getProject( ) ) )
	{
		selectable.remove( JavaCore.create( getProject( ) ) );
	}
	List elements = fLibrariesList.getElements( );
	for ( int i = 0; i < elements.size( ); i++ )
	{
		IDECPListElement curr = (IDECPListElement) elements.get( i );
		if ( curr.getEntryKind( ) != IClasspathEntry.CPE_PROJECT )
		{
			continue;
		}
		IJavaProject proj = (IJavaProject) JavaCore.create( curr.getResource( ) );
		selectable.remove( proj );
	}
	Object[] selectArr = selectable.toArray( );
	return selectArr;
}