Java Code Examples for org.eclipse.core.resources.IProject#getFullPath()

The following examples show how to use org.eclipse.core.resources.IProject#getFullPath() . 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: BinFolderConfigurator.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
	IProject project = request.getProject();
	if (compileToBin(project)) {
		IPath projectRoot = project.getFullPath();
		IPath binPath = projectRoot.append("bin");
		IPath binTestPath = projectRoot.append("bin-test");
		IJavaProject javaProject = JavaCore.create(project);
		javaProject.setOutputLocation(binPath, monitor);
		
		IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
		for(int i = 0; i < rawClasspath.length; i++) {
			IClasspathEntry entry = rawClasspath[i];
			if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
				if (isTest(entry)) {
					rawClasspath[i] = copyWithOutput(entry, binTestPath);
				} else {
					rawClasspath[i] = copyWithOutput(entry, binPath);
				}
			}
		}
		javaProject.setRawClasspath(rawClasspath, monitor);
	}
}
 
Example 2
Source File: ExampleImporter.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public IProject importExample(ExampleData edata, IProgressMonitor monitor) {
	try {
		IProjectDescription original = ResourcesPlugin.getWorkspace()
				.loadProjectDescription(new Path(edata.getProjectDir().getAbsolutePath()).append("/.project"));
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(edata.getProjectDir().getName());

		IProjectDescription clone = ResourcesPlugin.getWorkspace().newProjectDescription(original.getName());
		clone.setBuildSpec(original.getBuildSpec());
		clone.setComment(original.getComment());
		clone.setDynamicReferences(original.getDynamicReferences());
		clone.setNatureIds(original.getNatureIds());
		clone.setReferencedProjects(original.getReferencedProjects());
		if (project.exists()) {
			return project;
		}
		project.create(clone, monitor);
		project.open(monitor);

		@SuppressWarnings("unchecked")
		List<IFile> filesToImport = FileSystemStructureProvider.INSTANCE.getChildren(edata.getProjectDir());
		ImportOperation io = new ImportOperation(project.getFullPath(), edata.getProjectDir(),
				FileSystemStructureProvider.INSTANCE, new IOverwriteQuery() {

					@Override
					public String queryOverwrite(String pathString) {
						return IOverwriteQuery.ALL;
					}

				}, filesToImport);
		io.setOverwriteResources(true);
		io.setCreateContainerStructure(false);
		io.run(monitor);
		project.refreshLocal(IProject.DEPTH_INFINITE, monitor);
		return project;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 3
Source File: BirtWizardUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check folder if exist. If not, create it.
 * 
 * @param project
 * @param webContentFolder
 * @param folderName
 */
private static void checkFolder( IProject project, String webContentFolder,
		String folderName )
{
	if ( folderName == null )
		return;

	try
	{
		File file = new File( folderName );
		if ( file != null )
		{
			if ( file.exists( ) )
				return;

			if ( file.isAbsolute( ) )
			{
				// create absolute folder
				file.mkdir( );
			}
			else
			{
				// create folder in web content folder
				final IWorkspace ws = ResourcesPlugin.getWorkspace( );
				final IPath pjPath = project.getFullPath( );

				IPath configPath = pjPath.append( webContentFolder );
				IPath path = configPath.append( folderName );
				BirtWizardUtil.mkdirs( ws.getRoot( ).getFolder( path ) );
			}
		}
	}
	catch ( Exception e )
	{
		Logger.logException( Logger.WARNING, e );
	}
}
 
Example 4
Source File: JavaProjectSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static IFolder addSourceFolder(IJavaProject javaProject, String folderName, String[] inclusionPatterns, String[] exclusionPatterns) 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);
	return srcFolder;
}
 
Example 5
Source File: BirtWizardUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check folder if exist. If not, create it.
 * 
 * @param project
 * @param webContentFolder
 * @param folderName
 */
private static void checkFolder( IProject project, String webContentFolder,
		String folderName )
{
	if ( folderName == null )
		return;

	try
	{
		File file = new File( folderName );
		if ( file != null )
		{
			if ( file.exists( ) )
				return;

			if ( file.isAbsolute( ) )
			{
				// create absolute folder
				file.mkdir( );
			}
			else
			{
				// create folder in web content folder
				final IWorkspace ws = ResourcesPlugin.getWorkspace( );
				final IPath pjPath = project.getFullPath( );

				IPath configPath = pjPath.append( webContentFolder );
				IPath path = configPath.append( folderName );
				BirtWizardUtil.mkdirs( ws.getRoot( ).getFolder( path ) );
			}
		}
	}
	catch ( Exception e )
	{
		Logger.logException( Logger.WARNING, e );
	}
}
 
Example 6
Source File: HybridProjectImportPage.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private IProject doCreateProject(ProjectCandidate pc, IProgressMonitor monitor) throws CoreException, InterruptedException {
	HybridProjectCreator projectCreator = new HybridProjectCreator();
	Widget w = pc.getWidget();
	String projectName = pc.getProjectName();
	URI location = null;
	if(!copyFiles){
		location = pc.wwwLocation.getParentFile().toURI();
	}
	IProject project = projectCreator.createProject(projectName, location, w.getName(), w.getId(), null, monitor);
	if(copyFiles){
		ImportOperation operation = new ImportOperation(project
				.getFullPath(), pc.wwwLocation.getParentFile(), FileSystemStructureProvider.INSTANCE
				, this);
		operation.setContext(getShell());
		operation.setOverwriteResources(true); 
		operation.setCreateContainerStructure(false);
		
		try {
			operation.run(monitor);
		} catch (InvocationTargetException e) {
			if(e.getCause() != null  && e.getCause() instanceof CoreException){
				CoreException corex = (CoreException) e.getCause();
				throw corex;
			}
		}
		IStatus status = operation.getStatus();
		if (!status.isOK())
			throw new CoreException(status);
	}
	return project;

}
 
Example 7
Source File: AddFolderToIndex.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public AddFolderToIndex(IPath folderPath, IProject project, char[][] inclusionPatterns, char[][] exclusionPatterns, IndexManager manager) {
	super(project.getFullPath(), manager);
	this.folderPath = folderPath;
	this.project = project;
	this.inclusionPatterns = inclusionPatterns;
	this.exclusionPatterns = exclusionPatterns;
}
 
Example 8
Source File: EditFilterAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IPath getOutputLocation(IJavaProject javaProject) {
	try {
		return javaProject.getOutputLocation();
	} catch (CoreException e) {
		IProject project= javaProject.getProject();
		IPath projPath= project.getFullPath();
		return projPath.append(PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME));
	}
}
 
Example 9
Source File: CreateSourceFolderAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IPath getOutputLocation(IJavaProject javaProject) {
  	try {
	return javaProject.getOutputLocation();
} catch (CoreException e) {
	IProject project= javaProject.getProject();
	IPath projPath= project.getFullPath();
	return projPath.append(PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME));
}
  }
 
Example 10
Source File: CreateLinkedSourceFolderAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IPath getOutputLocation(IJavaProject javaProject) {
  	try {
	return javaProject.getOutputLocation();
} catch (CoreException e) {
	IProject project= javaProject.getProject();
	IPath projPath= project.getFullPath();
	return projPath.append(PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME));
}
  }
 
Example 11
Source File: LibrariesWorkbookPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private CPListElement[] openNewClassFolderDialog(CPListElement existing) {
	String title= (existing == null) ? NewWizardMessages.LibrariesWorkbookPage_NewClassFolderDialog_new_title : NewWizardMessages.LibrariesWorkbookPage_NewClassFolderDialog_edit_title;
	IProject currProject= fCurrJProject.getProject();

	NewContainerDialog dialog= new NewContainerDialog(getShell(), title, currProject, getUsedContainers(existing), existing);
	IPath projpath= currProject.getFullPath();
	dialog.setMessage(Messages.format(NewWizardMessages.LibrariesWorkbookPage_NewClassFolderDialog_description, BasicElementLabels.getPathLabel(projpath, false)));
	if (dialog.open() == Window.OK) {
		IFolder folder= dialog.getFolder();
		return new CPListElement[] { newCPLibraryElement(folder) };
	}
	return null;
}
 
Example 12
Source File: ClasspathModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static BuildpathDelta setOutputLocation(CPListElement elementToChange, IPath outputPath, boolean allowInvalidCP, CPJavaProject cpProject) throws CoreException {
	BuildpathDelta result= new BuildpathDelta(NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_EditOutput_tooltip);

	IJavaProject javaProject= cpProject.getJavaProject();
	IProject project= javaProject.getProject();
	IWorkspace workspace= project.getWorkspace();

	IPath projectPath= project.getFullPath();

	if (!allowInvalidCP && cpProject.getDefaultOutputLocation().segmentCount() == 1 && !projectPath.equals(elementToChange.getPath())) {
		String outputFolderName= PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME);
		cpProject.setDefaultOutputLocation(cpProject.getDefaultOutputLocation().append(outputFolderName));
		List<CPListElement> existingEntries= cpProject.getCPListElements();
		CPListElement elem= ClasspathModifier.getListElement(javaProject.getPath(), existingEntries);
           if (elem != null) {
           	existingEntries.remove(elem);
           	result.removeEntry(elem);
           }
	}

	if (outputPath != null)
		exclude(outputPath, cpProject.getCPListElements(), new ArrayList<CPListElement>(), cpProject.getJavaProject(), null);

	IPath oldOutputLocation= (IPath)elementToChange.getAttribute(CPListElement.OUTPUT);
       if (oldOutputLocation != null && oldOutputLocation.segmentCount() > 1 && !oldOutputLocation.equals(cpProject.getDefaultOutputLocation())) {
		include(cpProject, oldOutputLocation);
       	result.addDeletedResource(workspace.getRoot().getFolder(oldOutputLocation));
       }
	elementToChange.setAttribute(CPListElement.OUTPUT, outputPath);

	result.setDefaultOutputLocation(cpProject.getDefaultOutputLocation());
	result.setNewEntries(cpProject.getCPListElements().toArray(new CPListElement[cpProject.getCPListElements().size()]));
	if (outputPath != null && outputPath.segmentCount() > 1) {
		result.addCreatedResource(workspace.getRoot().getFolder(outputPath));
	}

	return result;
}
 
Example 13
Source File: DynamicWorkingSetUpdaterPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
private IProject renameProjectTo( IProject project, String name ) throws ExecutionException {
  IProject result = project.getWorkspace().getRoot().getProject( name );
  IPath path = result.getFullPath();
  AbstractOperation operation = new MoveResourcesOperation( project, path, "Rename project" );
  operation.execute( new NullProgressMonitor(), null );
  renamedProjects.add( result );
  return result;
}
 
Example 14
Source File: JavaProjectHelper.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a IJavaProject.
 *
 * @param projectName
 *            The name of the project
 * @param binFolderName
 *            Name of the output folder
 * @return Returns the Java project handle
 * @throws CoreException
 *             Project creation failed
 */
public static IJavaProject createJavaProject(String projectName, String binFolderName) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(projectName);
    if (!project.exists()) {
        project.create(null);
    } else {
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
    }

    if (!project.isOpen()) {
        project.open(null);
    }

    IPath outputLocation;
    if (binFolderName != null && binFolderName.length() > 0) {
        IFolder binFolder = project.getFolder(binFolderName);
        if (!binFolder.exists()) {
            CoreUtility.createFolder(binFolder, false, true, null);
        }
        outputLocation = binFolder.getFullPath();
    } else {
        outputLocation = project.getFullPath();
    }

    if (!project.hasNature(JavaCore.NATURE_ID)) {
        addNatureToProject(project, JavaCore.NATURE_ID, null);
    }

    IJavaProject jproject = JavaCore.create(project);

    jproject.setOutputLocation(outputLocation, null);
    jproject.setRawClasspath(new IClasspathEntry[0], null);

    return jproject;
}
 
Example 15
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 16
Source File: RemoveFolderFromIndex.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public RemoveFolderFromIndex(IPath folderPath, char[][] inclusionPatterns, char[][] exclusionPatterns, IProject project, IndexManager manager) {
	super(project.getFullPath(), manager);
	this.folderPath = folderPath;
	this.inclusionPatterns = inclusionPatterns;
	this.exclusionPatterns = exclusionPatterns;
}
 
Example 17
Source File: IndexAllProject.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public IndexAllProject(IProject project, IndexManager manager) {
	super(project.getFullPath(), manager);
	this.project = project;
}
 
Example 18
Source File: DeltaProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private boolean validateClasspaths(IResourceDelta delta) {
	HashSet affectedProjects = new HashSet(5);
	validateClasspaths(delta, affectedProjects);
	boolean needCycleValidation = false;

	// validate classpaths of affected projects (dependent projects
	// or projects that reference a library in one of the projects that have changed)
	if (!affectedProjects.isEmpty()) {
		IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
		IProject[] projects = workspaceRoot.getProjects();
		int length = projects.length;
		for (int i = 0; i < length; i++){
			IProject project = projects[i];
			JavaProject javaProject = (JavaProject)JavaCore.create(project);
			try {
				IPath projectPath = project.getFullPath();
				IClasspathEntry[] classpath = javaProject.getResolvedClasspath(); // allowed to reuse model cache
				for (int j = 0, cpLength = classpath.length; j < cpLength; j++) {
					IClasspathEntry entry = classpath[j];
					switch (entry.getEntryKind()) {
						case IClasspathEntry.CPE_PROJECT:
							if (affectedProjects.contains(entry.getPath())) {
								this.state.addClasspathValidation(javaProject);
								needCycleValidation = true;
							}
							break;
						case IClasspathEntry.CPE_LIBRARY:
							IPath entryPath = entry.getPath();
							IPath libProjectPath = entryPath.removeLastSegments(entryPath.segmentCount()-1);
							if (!libProjectPath.equals(projectPath) // if library contained in another project
									&& affectedProjects.contains(libProjectPath)) {
								this.state.addClasspathValidation(javaProject);
							}
							break;
					}
				}
			} catch(JavaModelException e) {
					// project no longer exists
			}
		}
	}
	return needCycleValidation;
}
 
Example 19
Source File: AddProjectNature.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // TODO Auto-generated method stub    	

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
        IStructuredSelection selection = (IStructuredSelection) window.getSelectionService()
                .getSelection();
        Object firstElement = selection.getFirstElement();
        if (firstElement instanceof IAdaptable) {
            IProject project = (IProject) ((IAdaptable) firstElement).getAdapter(IProject
                    .class);
            if (project == null) {
            	Logger.log(IStatus.INFO, "Not a project.");
                return null;
            }
            IPath path = project.getFullPath();
            Logger.log(IStatus.INFO, "" + path);

            try {
                if (project.hasNature(CodeCheckerNature.NATURE_ID)) {                    	
                    return null;
                }

                IProjectDescription description = project.getDescription();
                String[] prevNatures = description.getNatureIds();
                String[] newNatures = new String[prevNatures.length + 1];
                System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
                newNatures[prevNatures.length] = CodeCheckerNature.NATURE_ID;
                description.setNatureIds(newNatures);

                IProgressMonitor monitor = null;
                project.setDescription(description, monitor);
                ConsoleFactory.consoleWrite(project.getName() + ": Sucessfully added CodeChecker Nature");
                Logger.log(IStatus.INFO, "Project nature added!");

            } catch (CoreException e) {
                // TODO Auto-generated catch block
            	Logger.log(IStatus.ERROR,  e.toString());
            	Logger.log(IStatus.INFO, e.getStackTrace().toString());
            }

        }
    }

    return null;
}