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

The following examples show how to use org.eclipse.core.resources.IFolder#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: Model.java    From tlaplus with MIT License 6 votes vote down vote up
public void rename(String newModelName, IProgressMonitor monitor) throws CoreException {
	final Collection<Model> snapshots = getSnapshots();
	
	// Rename the model directory to the new name.
	final IFolder modelDir = getTargetDirectory();
	if (modelDir != null && modelDir.exists()) {
		final IPath src = modelDir.getFullPath();
		final IPath dst = src.removeLastSegments(1).append(newModelName);
		modelDir.move(dst, true, monitor);
	}

	renameLaunch(getSpec(), sanitizeName(newModelName));
	
	for (Model snapshot : snapshots) {
		snapshot.rename(newModelName + snapshot.getSnapshotSuffix(), monitor);
	}
}
 
Example 2
Source File: GWTCompileRunnerTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create a source entry (including the dir structure) and add it to the raw
 * classpath.
 * 
 * @param javaProject The Java project that receives the source entry
 * @param directoryName The source directory name
 * @param outputDirectoryName The optional output location of this source
 *          directory. Pass null for the default output location.
 */
private static void addAndCreateSourceEntry(IJavaProject javaProject,
    String directoryName, String outputDirectoryName) throws CoreException {
  IFolder srcFolder = javaProject.getProject().getFolder(directoryName);
  ResourceUtils.createFolderStructure(javaProject.getProject(),
      srcFolder.getProjectRelativePath());
  
  IPath workspaceRelOutPath = null;
  if (outputDirectoryName != null) {
    // Ensure output directory exists
    IFolder outFolder = javaProject.getProject().getFolder(outputDirectoryName);
    ResourceUtils.createFolderStructure(javaProject.getProject(),
        outFolder.getProjectRelativePath());
    workspaceRelOutPath = outFolder.getFullPath();
  }
  
  JavaProjectUtilities.addRawClassPathEntry(javaProject,
      JavaCore.newSourceEntry(srcFolder.getFullPath(),
          ClasspathEntry.EXCLUDE_NONE, workspaceRelOutPath));
}
 
Example 3
Source File: ModuleFile.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * <p>
 * Returns whether a package is on the client source path of this module. The source paths include
 * the paths explicitly declared with <code>&lt;source&gt;</code> tags and all of their descendant
 * packages.
 * </p>
 * <p>
 * For example, if a module is located in <code>com.hello</code> and has the default client source
 * path "client", then <code>com.hello.client</code> and <code>com.hello.client.utils</code> would
 * both return true.
 * </p>
 *
 * @param pckg package to check
 * @return <code>true</code> if this package is on a client source path, and <code>false</code>
 *         otherwise
 */
public boolean isSourcePackage(IPackageFragment pckg) {
  IResource resource = pckg.getResource();
  if (resource.getType() == IResource.FOLDER) {
    IPath pckgFolderPath = resource.getFullPath();

    // Check each source path to see if it's an ancestor of this package
    for (IFolder clientFolder : getFolders(getSourcePaths())) {
      IPath clientFolderPath = clientFolder.getFullPath();
      if (clientFolderPath.isPrefixOf(pckgFolderPath)) {
        return true;
      }
    }
  }

  return false;
}
 
Example 4
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 5
Source File: TraceValidateAndImportOperation.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Extract all file system elements (Tar, Zip elements) to destination
 * folder (typically workspace/TraceProject/.traceImport or a subfolder of
 * it)
 */
private void extractArchiveContent(Iterator<TraceFileSystemElement> fileSystemElementsIter, IFolder tempFolder, IProgressMonitor progressMonitor) throws InterruptedException,
        InvocationTargetException {
    List<TraceFileSystemElement> subList = new ArrayList<>();
    // Collect all the elements
    while (fileSystemElementsIter.hasNext()) {
        ModalContext.checkCanceled(progressMonitor);
        TraceFileSystemElement element = fileSystemElementsIter.next();
        if (element.isDirectory()) {
            Object[] array = element.getFiles().getChildren();
            for (int i = 0; i < array.length; i++) {
                subList.add((TraceFileSystemElement) array[i]);
            }
        }
        subList.add(element);
    }

    if (subList.isEmpty()) {
        return;
    }

    TraceFileSystemElement root = getRootElement(subList.get(0));

    ImportProvider fileSystemStructureProvider = new ImportProvider();

    IOverwriteQuery myQueryImpl = file -> IOverwriteQuery.NO_ALL;

    progressMonitor.setTaskName(Messages.ImportTraceWizard_ExtractImportOperationTaskName);
    IPath containerPath = tempFolder.getFullPath();
    ImportOperation operation = new ImportOperation(containerPath, root, fileSystemStructureProvider, myQueryImpl, subList);
    operation.setContext(fShell);

    operation.setCreateContainerStructure(true);
    operation.setOverwriteResources(false);
    operation.setVirtualFolders(false);

    operation.run(SubMonitor.convert(progressMonitor).newChild(subList.size()));
}
 
Example 6
Source File: HostPagePathSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private HostPagePathTreeItem(IFolder folder, HostPagePathTreeItem parent) {
  this.parent = parent;
  this.path = folder.getFullPath();

  for (IFolder subfolder : getSubfolders(folder)) {
    this.children.add(new HostPagePathTreeItem(subfolder, this));
  }
}
 
Example 7
Source File: PackageExplorerLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private String getNameDelta(IFolder parent, IPackageFragment fragment) {
	IPath prefix= parent.getFullPath();
	IPath fullPath= fragment.getPath();
	if (prefix.isPrefixOf(fullPath)) {
		StringBuffer buf= new StringBuffer();
		for (int i= prefix.segmentCount(); i < fullPath.segmentCount(); i++) {
			if (buf.length() > 0)
				buf.append('.');
			buf.append(fullPath.segment(i));
		}
		return buf.toString();
	}
	return fragment.getElementName();
}
 
Example 8
Source File: OutputFolderFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the result of this filter, when applied to the
 * given element.
 *
 * @param viewer the viewer
 * @param parent the parent
 * @param element the element to test
 * @return <code>true</code> if element should be included
 * @since 3.0
 */
@Override
public boolean select(Viewer viewer, Object parent, Object element) {
	if (element instanceof IFolder) {
		IFolder folder= (IFolder)element;
		IProject proj= folder.getProject();
		try {
			if (!proj.hasNature(JavaCore.NATURE_ID))
				return true;

			IJavaProject jProject= JavaCore.create(folder.getProject());
			if (jProject == null || !jProject.exists())
				return true;

			// Check default output location
			IPath defaultOutputLocation= jProject.getOutputLocation();
			IPath folderPath= folder.getFullPath();
			if (defaultOutputLocation != null && defaultOutputLocation.equals(folderPath))
				return false;

			// Check output location for each class path entry
			IClasspathEntry[] cpEntries= jProject.getRawClasspath();
			for (int i= 0, length= cpEntries.length; i < length; i++) {
				IPath outputLocation= cpEntries[i].getOutputLocation();
				if (outputLocation != null && outputLocation.equals(folderPath))
					return false;
			}
		} catch (CoreException ex) {
			return true;
		}
	}
	return true;
}
 
Example 9
Source File: TracePackageImportOperation.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
private IStatus importSupplFiles(TracePackageTraceElement packageElement, IProgressMonitor monitor) {
    List<Pair<String, String>> fileNameAndLabelPairs = new ArrayList<>();
    Map<String, String> suppFilesRename = new HashMap<>();
    for (TracePackageElement element : packageElement.getChildren()) {
        if (element instanceof TracePackageSupplFilesElement) {
            for (TracePackageElement child : element.getChildren()) {
                if (child.isChecked()) {
                    TracePackageSupplFileElement supplFile = (TracePackageSupplFileElement) child;
                    if (packageElement instanceof TracePackageExperimentElement) {
                        String oldExpName = getOldExpName(supplFile);
                        if (!packageElement.getImportName().equals(oldExpName)) {
                            suppFilesRename.put(supplFile.getText(), supplFile.getText().replace(oldExpName, packageElement.getImportName()));
                        }
                    }
                    fileNameAndLabelPairs.add(new Pair<>(checkNotNull(supplFile.getText()), checkNotNull(new Path(supplFile.getText()).lastSegment())));
                }
            }
        }
    }

    if (!fileNameAndLabelPairs.isEmpty()) {
        TmfCommonProjectElement projectElement = getMatchingProjectElement(packageElement);
        if (projectElement != null) {
            ArchiveFile archiveFile = getSpecifiedArchiveFile();
            projectElement.refreshSupplementaryFolder();
            IPath destinationContainerPath;
            if (packageElement instanceof TracePackageExperimentElement) {
                destinationContainerPath = projectElement.getProject().getSupplementaryFolder().getFullPath();
            } else {
                // Project/Traces/A/B -> A/B
                final TmfTraceFolder tracesFolder = fTmfTraceFolder.getProject().getTracesFolder();
                if (tracesFolder == null) {
                    return new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation);
                }
                IPath traceFolderRelativePath = fTmfTraceFolder.getPath().makeRelativeTo(tracesFolder.getPath());
                // Project/.tracing/A/B/
                IFolder traceSupplementaryFolder = fTmfTraceFolder.getTraceSupplementaryFolder(traceFolderRelativePath.toString());
                destinationContainerPath = traceSupplementaryFolder.getFullPath();
            }
            // Remove the .tracing segment at the beginning so that a file
            // in folder .tracing/A/B/ imports to destinationContainerPath/A/B/
            Path baseSourcePath = new Path(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER_NAME);
            return importFiles(archiveFile, fileNameAndLabelPairs, destinationContainerPath, baseSourcePath, suppFilesRename, monitor);
        }
    }

    return Status.OK_STATUS;
}
 
Example 10
Source File: BirtFacetInstallDelegate.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Invoke "INSTALL" event for project facet
 * 
 * @see org.eclipse.wst.common.project.facet.core.IDelegate#execute(org.eclipse.core.resources.IProject,
 *      org.eclipse.wst.common.project.facet.core.IProjectFacetVersion,
 *      java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
 */
public void execute( IProject project, IProjectFacetVersion fv,
		Object config, IProgressMonitor monitor ) throws CoreException
{
	if ( monitor != null )
	{
		monitor.beginTask( "", 1 ); //$NON-NLS-1$
	}

	try
	{
		final IDataModel model = (IDataModel) config;

		// get destination path
		IDataModel dataModel = (IDataModel) model.getProperty( "FacetInstallDataModelProvider.MASTER_PROJECT_DM" ); //$NON-NLS-1$
		IPath destPath = null;

		if ( dataModel != null )
		{
			String dest = BirtWizardUtil.getConfigFolder( dataModel );
			IFolder folder = BirtWizardUtil.getFolder( project, dest );

			if ( folder != null )
				destPath = folder.getFullPath( );
		}

		if ( destPath == null )
		{
			destPath = BirtWizardUtil.getWebContentPath( project );
		}

		// import birt runtime componenet
		BirtWizardUtil.doImports( project,
				null,
				destPath,
				monitor,
				new SimpleImportOverwriteQuery( ) );

		Map properties = new HashMap( );

		// initialize webapp settings from Extension
		BirtWizardUtil.initWebapp( properties );

		// initialize webapp settings from existed web.xml
		WebArtifactUtil.initializeWebapp( properties, project );

		// process defined folders
		BirtWizardUtil.processCheckFolder( properties,
				project,
				destPath.toFile( ).getName( ),
				monitor );

		// configurate web.xml
		processConfiguration( properties, project, monitor );
	}
	finally
	{
		if ( monitor != null )
		{
			monitor.done( );
		}
	}
}
 
Example 11
Source File: UIUtil.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a folder resource given the folder handle.
 * 
 * @param folderHandle
 *            the folder handle to create a folder resource for
 * @param monitor
 *            the progress monitor to show visual progress with
 * @exception CoreException
 *                if the operation fails
 * @exception OperationCanceledException
 *                if the operation is canceled
 */
public static void createFolder( IFolder folderHandle,
		IProgressMonitor monitor ) throws CoreException
{
	try
	{
		// Create the folder resource in the workspace
		// Update: Recursive to create any folders which do not exist
		// already
		if ( !folderHandle.exists( ) )
		{
			IPath path = folderHandle.getFullPath( );
			IWorkspaceRoot root = ResourcesPlugin.getWorkspace( ).getRoot( );
			int numSegments = path.segmentCount( );
			if ( numSegments > 2
					&& !root.getFolder( path.removeLastSegments( 1 ) )
							.exists( ) )
			{
				// If the direct parent of the path doesn't exist, try
				// to create the
				// necessary directories.
				for ( int i = numSegments - 2; i > 0; i-- )
				{
					IFolder folder = root.getFolder( path.removeLastSegments( i ) );
					if ( !folder.exists( ) )
					{
						folder.create( false, true, monitor );
					}
				}
			}
			folderHandle.create( false, true, monitor );
		}
	}
	catch ( CoreException e )
	{
		// If the folder already existed locally, just refresh to get
		// contents
		if ( e.getStatus( ).getCode( ) == IResourceStatus.PATH_OCCUPIED )
			folderHandle.refreshLocal( IResource.DEPTH_INFINITE,
					new SubProgressMonitor( monitor, 500 ) );
		else
			throw e;
	}

	if ( monitor.isCanceled( ) )
		throw new OperationCanceledException( );
}
 
Example 12
Source File: BirtFacetInstallDelegate.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Invoke "INSTALL" event for project facet
 * 
 * @see org.eclipse.wst.common.project.facet.core.IDelegate#execute(org.eclipse.core.resources.IProject,
 *      org.eclipse.wst.common.project.facet.core.IProjectFacetVersion,
 *      java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
 */
public void execute( IProject project, IProjectFacetVersion fv,
		Object config, IProgressMonitor monitor ) throws CoreException
{
	monitor.beginTask( "", 4 ); //$NON-NLS-1$

	try
	{
		IDataModel facetDataModel = (IDataModel) config;
		IDataModel masterDataModel = (IDataModel) facetDataModel
				.getProperty( FacetInstallDataModelProvider.MASTER_PROJECT_DM );

		IPath destPath = null;
		// get web content folder
		if ( masterDataModel != null )
		{
			String configFolder = BirtWizardUtil
					.getConfigFolder( masterDataModel );

			if ( configFolder != null )
			{
				IFolder folder = BirtWizardUtil.getFolder( project, configFolder );
				if ( folder != null )
					destPath = folder.getFullPath( );
			}
		}
		else
		{
			destPath = BirtWizardUtil.getWebContentPath( project );
		}

		if ( destPath == null )
		{
			String message = BirtWTPMessages.BIRTErrors_wrong_webcontent;
			Logger.log( Logger.ERROR, message );
			throw BirtCoreException.getException( message, null );
		}			
		
		Map birtProperties = (Map) facetDataModel
				.getProperty( BirtFacetInstallDataModelProvider.BIRT_CONFIG );

		monitor.worked( 1 );

		// process BIRT Configuration
		preConfiguration( project, birtProperties, destPath.toFile( ).getName( ), monitor );

		monitor.worked( 1 );

		processConfiguration( project, birtProperties, monitor );

		monitor.worked( 1 );
		
		// import birt runtime componenet
		BirtWizardUtil.doImports( project, null, destPath, monitor,
				new SimpleImportOverwriteQuery( ) );

		monitor.worked( 1 );
	}
	finally
	{
		monitor.done( );
	}
}