Java Code Examples for org.eclipse.jdt.core.IJavaProject#getPath()

The following examples show how to use org.eclipse.jdt.core.IJavaProject#getPath() . 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: EclipseTestBase_No_ResponseDuirngTypeResolve.java    From depends with MIT License 6 votes vote down vote up
/**
 * Extract lib/annotations.jar from the test bundle and add it to the specified project
 */
private static void addAnnotationJar(IJavaProject jproj, boolean addToModulePath) throws Exception {
	final String resName = "lib/annotations.jar"; // name in bundle
	final String libName = resName; // name in destination project
	InputStream is = null;
	URL resURL = Apt6TestsPlugin.thePlugin().getBundle().getEntry(resName);
	is = resURL.openStream();
	IPath projPath = jproj.getPath();
	IProject proj = jproj.getProject();
	IFile libFile = proj.getFile(libName);
	env.addFolder(projPath, "lib");
	if (libFile.exists()) {
		libFile.setContents(is, true, false, null);
	} else {
		libFile.create(is, true, null);
	}
	if (addToModulePath) {
		IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
		env.addEntry(projPath, JavaCore.newLibraryEntry(libFile.getFullPath(), null, null,
				ClasspathEntry.NO_ACCESS_RULES, attributes, false));
	} else {
		env.addLibrary(projPath, libFile.getFullPath(), null, null);
	}
}
 
Example 2
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 3
Source File: ClasspathModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static BuildpathDelta removeFromBuildpath(CPListElement[] toRemove, CPJavaProject cpProject) {

        IJavaProject javaProject= cpProject.getJavaProject();
		IPath projectPath= javaProject.getPath();
        IWorkspaceRoot workspaceRoot= javaProject.getProject().getWorkspace().getRoot();

    	List<CPListElement> existingEntries= cpProject.getCPListElements();
		BuildpathDelta result= new BuildpathDelta(NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_RemoveFromCP_tooltip);

		for (int i= 0; i < toRemove.length; i++) {
	        CPListElement element= toRemove[i];
	        existingEntries.remove(element);
	        result.removeEntry(element);
	        IPath path= element.getPath();
			removeFilters(path, javaProject, existingEntries);
			if (!path.equals(projectPath)) {
	            IResource member= workspaceRoot.findMember(path);
	            if (member != null)
	            	result.addDeletedResource(member);
            } else if (cpProject.getDefaultOutputLocation().equals(projectPath) && containsSourceFolders(cpProject)) {
            	String outputFolderName= PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME);
    			cpProject.setDefaultOutputLocation(cpProject.getDefaultOutputLocation().append(outputFolderName));
            }
        }

		result.setDefaultOutputLocation(cpProject.getDefaultOutputLocation());
    	result.setNewEntries(existingEntries.toArray(new CPListElement[existingEntries.size()]));

	    return result;
    }
 
Example 4
Source File: ProblemsLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isIgnoringOptionalProblems(IJavaProject project) throws JavaModelException {
	IPath projectPath= project.getPath();
	IClasspathEntry[] rawClasspath= project.getRawClasspath();
	for (IClasspathEntry entry : rawClasspath) {
		if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && projectPath.equals(entry.getPath()) && isIgnoringOptionalProblems(entry))
			return true;
	}
	return false;
}
 
Example 5
Source File: IDEClassPathBlock.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private IDECPListElement[] addProjectDialog( )
{

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

		ListSelectionDialog dialog = new ListSelectionDialog( getShell( ),
				Arrays.asList( selectArr ),
				new ArrayContentProvider( ),
				new ProjectLabelProvider( ),
				Messages.getString("IDEClassPathBlock.ProjectDialog_message") ); //$NON-NLS-1$
		dialog.setTitle( Messages.getString("IDEClassPathBlock.ProjectDialog_title") ); //$NON-NLS-1$
		dialog.setHelpAvailable( false );
		if ( dialog.open( ) == Window.OK )
		{
			Object[] result = dialog.getResult( );
			IDECPListElement[] cpElements = new IDECPListElement[result.length];
			for ( int i = 0; i < result.length; i++ )
			{
				IJavaProject curr = ( (IJavaProject) result[i] );
				cpElements[i] = new IDECPListElement( IClasspathEntry.CPE_PROJECT,
						curr.getPath( ),
						curr.getResource( ) );
			}
			return cpElements;
		}
	}
	catch ( JavaModelException e )
	{
		return null;
	}
	return null;
}
 
Example 6
Source File: RenameJavaProjectChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public RenameJavaProjectChange(IJavaProject project, String newName, boolean updateReferences) {
	this(project.getPath(), project.getElementName(), newName, IResource.NULL_STAMP, updateReferences);
	Assert.isTrue(!project.isReadOnly(), "should not be read only"); //$NON-NLS-1$
}
 
Example 7
Source File: ClasspathModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Remove <code>path</code> from inclusion/exlusion filters in all <code>existingEntries</code>
 *
 * @param path the path to remove
 * @param project the Java project
 * @param existingEntries a list of <code>CPListElement</code> representing the build path
 * entries of the project.
 * @return returns a <code>List</code> of <code>CPListElement</code> of modified elements, not null.
 */
public static List<CPListElement> removeFilters(IPath path, IJavaProject project, List<CPListElement> existingEntries) {
	if (path == null)
		return Collections.emptyList();

	IPath projPath= project.getPath();
	if (projPath.isPrefixOf(path)) {
		path= path.removeFirstSegments(projPath.segmentCount()).addTrailingSeparator();
	}

	List<CPListElement> result= new ArrayList<CPListElement>();
	for (Iterator<CPListElement> iter= existingEntries.iterator(); iter.hasNext();) {
		CPListElement element= iter.next();
		boolean hasChange= false;
		IPath[] exlusions= (IPath[])element.getAttribute(CPListElement.EXCLUSION);
		if (exlusions != null) {
			List<IPath> exlusionList= new ArrayList<IPath>(exlusions.length);
			for (int i= 0; i < exlusions.length; i++) {
				if (!exlusions[i].equals(path)) {
					exlusionList.add(exlusions[i]);
				} else {
					hasChange= true;
				}
			}
			element.setAttribute(CPListElement.EXCLUSION, exlusionList.toArray(new IPath[exlusionList.size()]));
		}

		IPath[] inclusion= (IPath[])element.getAttribute(CPListElement.INCLUSION);
		if (inclusion != null) {
			List<IPath> inclusionList= new ArrayList<IPath>(inclusion.length);
			for (int i= 0; i < inclusion.length; i++) {
				if (!inclusion[i].equals(path)) {
					inclusionList.add(inclusion[i]);
				} else {
					hasChange= true;
				}
			}
			element.setAttribute(CPListElement.INCLUSION, inclusionList.toArray(new IPath[inclusionList.size()]));
		}
		if (hasChange) {
			result.add(element);
		}
	}
	return result;
}