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

The following examples show how to use org.eclipse.core.resources.IFolder#delete() . 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: RecipeHelper.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
public static void processFile ( final IContainer parent, final Definition definition, final Profile profile, final IProgressMonitor monitor ) throws Exception
{
    monitor.beginTask ( makeJobLabel ( definition, profile ), 100 );

    final IFolder output = parent.getFolder ( new Path ( "output" ) ); //$NON-NLS-1$
    if ( output.exists () )
    {
        output.delete ( true, new SubProgressMonitor ( monitor, 9 ) );
    }
    output.create ( true, true, new SubProgressMonitor ( monitor, 1 ) );

    final Builder builder = new Builder ( definition, profile );
    final Recipe recipe = builder.build ();

    try
    {
        final Map<String, Object> initialContent = new HashMap<String, Object> ();
        initialContent.put ( "output", output ); //$NON-NLS-1$

        recipe.execute ( initialContent, new SubProgressMonitor ( monitor, 90 ) );
    }
    finally
    {
        monitor.done ();
    }
}
 
Example 2
Source File: ChildModuleWarPublishTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublishExploded_childModulePublished() throws CoreException {
  IFolder exploded = project.getFolder("exploded-war");
  IFolder tempDirectory = project.getFolder("temp");
  try {
    WarPublisher.publishExploded(project,
        exploded.getLocation(), tempDirectory.getLocation(), monitor);

    exploded.refreshLocal(IResource.DEPTH_INFINITE, monitor);
    for (String childModule : getExpectedChildModuleNames()) {
      assertTrue(exploded.getFile("WEB-INF/lib/" + childModule).exists());
    }
  } finally {
    exploded.delete(true, monitor);
    tempDirectory.delete(true, monitor);
  }
}
 
Example 3
Source File: JavaClassPathResourceForIEditorInputFactoryTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test(expected=CoreException.class) public void testBug463258_04() throws Throwable {
	IFolder externalFolder = createExternalFolder("externalFolder");
	IJavaProject project = createJavaProject("foo");
	
	addExternalFolderToClasspath(project, externalFolder);
	
	IPackageFragmentRoot root = project.getPackageFragmentRoot(externalFolder);
	IPackageFragment foo = root.getPackageFragment("foo");
	NonJavaResource fileInFolder = new NonJavaResource(foo, externalFolder.getFile("foo/doesNotExist.testlanguage"));
	
	externalFolder.delete(true, null);
	XtextReadonlyEditorInput editorInput = new XtextReadonlyEditorInput(fileInFolder);
	try {
		factory.createResource(editorInput);
	} catch(WrappedException e) {
		throw e.getCause();
	}
}
 
Example 4
Source File: AbstractRepositoryStore.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected T doImportIResource(final String fileName, final IResource resource) {
    try {
        if (resource instanceof IFile) {
            return importInputStream(fileName, ((IFile) resource).getContents());
        } else if (resource instanceof IFolder) {
            final IPath path = getResource().getFullPath().append(fileName);
            final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            final IFolder targetFolder = root.getFolder(path);
            if (targetFolder.exists()) {
                if (FileActionDialog.overwriteQuestion(fileName)) {
                    targetFolder.delete(true, Repository.NULL_PROGRESS_MONITOR);
                } else {
                    return createRepositoryFileStore(fileName);
                }
            }
            resource.copy(getResource().getFullPath().append(fileName), true, Repository.NULL_PROGRESS_MONITOR);
        }
    } catch (final Exception e) {
        BonitaStudioLog.error(e);
    }
    return createRepositoryFileStore(fileName);
}
 
Example 5
Source File: ExternalFoldersManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void cleanUp(IProgressMonitor monitor) throws CoreException {
	ArrayList toDelete = getFoldersToCleanUp(monitor);
	if (toDelete == null)
		return;
	for (Iterator iterator = toDelete.iterator(); iterator.hasNext();) {
		Map.Entry entry = (Map.Entry) iterator.next();
		IFolder folder = (IFolder) entry.getValue();
		folder.delete(true, monitor);
		IPath key = (IPath) entry.getKey();
		this.folders.remove(key);
	}
	IProject project = getExternalFoldersProject();
	if (project.isAccessible() && project.members().length == 1/*remaining member is .project*/)
		project.delete(true, monitor);
}
 
Example 6
Source File: BuildInstruction.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void deleteEmptyDirectories(IFolder folder, IProgressMonitor progressMonitor) throws CoreException {
	for (IResource member : folder.members()) {
		if (member instanceof IFolder) {
			deleteEmptyDirectories((IFolder) member, progressMonitor);
		}
	}
	if (folder.members().length == 0) {
		folder.delete(true, progressMonitor);
	}
}
 
Example 7
Source File: CheckProjectFactory.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Overridden in order to change BundleVendor. {@inheritDoc}
 */
@SuppressWarnings("PMD.InsufficientStringBufferDeclaration")
@Override
protected void createManifest(final IProject project, final IProgressMonitor progressMonitor) throws CoreException {
  final StringBuilder content = new StringBuilder("Manifest-Version: 1.0\n");
  content.append("Bundle-ManifestVersion: 2\n");
  content.append("Bundle-Name: " + projectName + "\n");
  content.append("Bundle-Vendor: %Bundle-Vendor\n");
  content.append("Bundle-Version: 1.0.0.qualifier\n");
  content.append("Bundle-SymbolicName: " + projectName + ";singleton:=true\n");
  if (null != activatorClassName) {
    content.append("Bundle-Activator: " + activatorClassName + "\n");
  }
  content.append("Bundle-ActivationPolicy: lazy\n");

  addToContent(content, requiredBundles, "Require-Bundle");
  addToContent(content, exportedPackages, "Export-Package");
  addToContent(content, importedPackages, "Import-Package");

  content.append("Bundle-RequiredExecutionEnvironment: JavaSE-1.7\n");

  final IFolder metaInf = project.getFolder("META-INF");
  SubMonitor subMonitor = SubMonitor.convert(progressMonitor, 2);
  try {
    if (metaInf.exists()) {
      metaInf.delete(false, progressMonitor);
    }
    metaInf.create(false, true, subMonitor.newChild(1));
    createFile("MANIFEST.MF", metaInf, content.toString(), subMonitor.newChild(1));
  } finally {
    subMonitor.done();
  }
}
 
Example 8
Source File: JavaProjectHelper.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Imports resources from <code>bundleSourcePath</code> to
 * <code>importTarget</code>.
 *
 * @param importTarget
 *            the parent container
 * @param bundleSourcePath
 *            the path to a folder containing resources
 *
 * @throws CoreException
 *             import failed
 * @throws IOException
 *             import failed
 */
public static void importResources(IContainer importTarget, Bundle bundle, String bundleSourcePath) throws CoreException,
        IOException {
    Enumeration<?> entryPaths = bundle.getEntryPaths(bundleSourcePath);
    while (entryPaths.hasMoreElements()) {
        String path = (String) entryPaths.nextElement();
        IPath name = new Path(path.substring(bundleSourcePath.length()));
        if (path.endsWith("/.svn/")) {
            continue; // Ignore SVN folders
        } else if (path.endsWith("/")) {
            IFolder folder = importTarget.getFolder(name);
            if (folder.exists()) {
                folder.delete(true, null);
            }
            folder.create(true, true, null);
            importResources(folder, bundle, path);
        } else {
            URL url = bundle.getEntry(path);
            IFile file = importTarget.getFile(name);
            if (!file.exists()) {
                file.create(url.openStream(), true, null);
            } else {
                file.setContents(url.openStream(), true, false, null);
            }
        }
    }
}
 
Example 9
Source File: Repository.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void removeFolder(String folderName, final IProgressMonitor monitor) {
    IFolder resourceFolder = project.getFolder(folderName);
    if (resourceFolder.exists()) {
        try {
            resourceFolder.delete(true, monitor);
        } catch (CoreException e) {
            BonitaStudioLog.error(String.format("Failed to delete folder %s during migration", folderName),
                    CommonRepositoryPlugin.PLUGIN_ID);
        }
        BonitaStudioLog.info(String.format("Folder %s has been removed during migration", folderName),
                CommonRepositoryPlugin.PLUGIN_ID);
    }
}
 
Example 10
Source File: ExportConnectorArchiveOperation.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private IFolder createClasspathFolder(final IRepositoryStore implStore, final List<IResource> resourcesToExport) throws CoreException {
    final IFolder classpathFolder = implStore.getResource().getFolder(CLASSPATH_DIR) ;
    if(classpathFolder.exists()){
        classpathFolder.delete(true, Repository.NULL_PROGRESS_MONITOR) ;
    }

    classpathFolder.create(true, true, Repository.NULL_PROGRESS_MONITOR) ;
    resourcesToExport.add(classpathFolder) ;
    cleanAfterExport.add(classpathFolder) ;
    return classpathFolder;
}
 
Example 11
Source File: StandardImportAndReadSmokeTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create the empty archive from an empty folder
 */
private static String createEmptyArchive() throws CoreException, URISyntaxException {
    IFolder tempEmptyDirectory = createEmptyDirectory();
    String archivePath = createArchive(tempEmptyDirectory);
    tempEmptyDirectory.delete(true, null);
    return archivePath;
}
 
Example 12
Source File: JavaProjectSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static IFolder createSubFolder(IProject project, String folderName) throws CoreException {
	IFolder folder = project.getFolder(folderName);
	if (folder.exists()) {
		folder.delete(true, null);
	}
	try {
		return createFolder(folder.getFullPath());
	} catch (Exception e) {
		throw new RuntimeIOException(e);
	}
}
 
Example 13
Source File: JavaProjectSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static IFolder deleteSourceFolder(IJavaProject project, String folderPath) throws JavaModelException,
		CoreException {
	IFolder folder = project.getProject().getFolder(folderPath);
	deleteClasspathEntry(project, folder.getFullPath());
	folder.delete(true, monitor());
	return folder;
}
 
Example 14
Source File: JavaProjectSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static IFolder deleteSourceFolder(IJavaProject project, String folderPath) throws JavaModelException,
		CoreException {
	IFolder folder = project.getProject().getFolder(folderPath);
	deleteClasspathEntry(project, folder.getFullPath());
	folder.delete(true, monitor());
	return folder;
}
 
Example 15
Source File: PluginProjectFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void createManifest(IProject project, IProgressMonitor progressMonitor) throws CoreException {
	final StringBuilder content = new StringBuilder("Manifest-Version: 1.0\n");
	content.append("Automatic-Module-Name: " + projectName + "\n");
	content.append("Bundle-ManifestVersion: 2\n");
	content.append("Bundle-Name: " + projectName + "\n");
	content.append("Bundle-Vendor: My Company\n");
	content.append("Bundle-Version: 1.0.0.qualifier\n");
	content.append("Bundle-SymbolicName: " + projectName + "; singleton:=true\n");
	if (null != activatorClassName) {
		content.append("Bundle-Activator: " + activatorClassName + "\n");
	}
	content.append("Bundle-ActivationPolicy: lazy\n");

	addToContent(content, requiredBundles, "Require-Bundle");
	addToContent(content, exportedPackages, "Export-Package");
	addToContent(content, importedPackages, "Import-Package");
	content.append("Bundle-RequiredExecutionEnvironment: ");
	content.append(getBreeToUse() + "\n");

	final IFolder metaInf = project.getFolder("META-INF");
	SubMonitor subMonitor = SubMonitor.convert(progressMonitor, 2);
	try {
		if (metaInf.exists())
			metaInf.delete(false, progressMonitor);
		metaInf.create(false, true, subMonitor.newChild(1));
		createFile("MANIFEST.MF", metaInf, content.toString(), subMonitor.newChild(1));
	} finally {
		subMonitor.done();
	}
}
 
Example 16
Source File: TracePackageExportOperation.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private IFolder createExportFolder(IProgressMonitor monitor) throws CoreException {
    IFolder folder = fTraceExportElements[0].getTraceElement().getProject().getResource().getFolder(TRACE_EXPORT_TEMP_FOLDER);
    if (folder.exists()) {
        folder.delete(true, null);
    }
    folder.create(IResource.FORCE | IResource.HIDDEN, true, SubMonitor.convert(monitor));
    return folder;
}
 
Example 17
Source File: BuildProjectOperation.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private IPath createBuildDestination(IProgressMonitor monitor) throws CoreException {
    monitor.beginTask("Creating target folder...", IProgressMonitor.UNKNOWN);
    IFolder targetFolder = repositoryAccessor.getCurrentRepository().getProject().getFolder("target");
    if (targetFolder.exists()) {
        targetFolder.delete(true, new NullProgressMonitor());
    }
    targetFolder.create(true, true, new NullProgressMonitor());
    targetFolder.getFolder(repositoryAccessor.getCurrentRepository().getName()).create(true, true,
            new NullProgressMonitor());
    monitor.done();
    return targetFolder.getLocation();
}
 
Example 18
Source File: HttpTraceImportOperation.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
    int importOptionFlags = ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES |
            ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE;

    // Temporary directory to contain any downloaded files
    IFolder tempDestination = fDestinationFolder.getProject().getResource().getFolder(TRACE_HTTP_IMPORT_TEMP_FOLDER);
    String tempDestinationFolderPath = tempDestination.getLocation().toOSString();
    if (tempDestination.exists()) {
        tempDestination.delete(true, monitor);
    }
    tempDestination.create(IResource.HIDDEN, true, monitor);

    // Download trace/traces
    List<File> downloadedTraceList = new ArrayList<>();
    TraceDownloadStatus status = DownloadTraceHttpHelper.downloadTraces(fSourceUrl, tempDestinationFolderPath);
    if (status.isOk()) {
        List<TraceDownloadStatus> children = status.getChildren();
        for (TraceDownloadStatus traceDownloadStatus : children) {
            downloadedTraceList.add(traceDownloadStatus.getDownloadedFile());
        }
    } else if (status.isTimeout()) {
        if (tempDestination.exists()) {
            tempDestination.delete(true, monitor);
        }
        throw new InterruptedException();
    }

    boolean isArchive = false;
    if (!downloadedTraceList.isEmpty()) {
        isArchive = ArchiveUtil.isArchiveFile(downloadedTraceList.get(0));
    }

    FileSystemObjectImportStructureProvider provider = null;
    IFileSystemObject object = null;

    String archiveFolderName = null;
    if (isArchive) {
        // If it's an archive there is only 1 element in this list
        File downloadedTrace = downloadedTraceList.get(0);
        Pair<IFileSystemObject, FileSystemObjectImportStructureProvider> rootObjectAndProvider = ArchiveUtil.getRootObjectAndProvider(downloadedTrace, null);
        provider = rootObjectAndProvider.getSecond();
        object = rootObjectAndProvider.getFirst();
        archiveFolderName = downloadedTrace.getName();
    } else {
        provider = new FileSystemObjectImportStructureProvider(FileSystemStructureProvider.INSTANCE, null);
        object = provider.getIFileSystemObject(new File(tempDestinationFolderPath));
    }

    TraceFileSystemElement root = TraceFileSystemElement.createRootTraceFileElement(object, provider);

    List<TraceFileSystemElement> fileSystemElements = new ArrayList<>();
    root.getAllChildren(fileSystemElements);

    IPath sourceContainerPath = new Path(tempDestinationFolderPath);
    IPath destinationContainerPath = fDestinationFolder.getPath();

    TraceValidateAndImportOperation validateAndImportOperation = new TraceValidateAndImportOperation(null, fileSystemElements, null, sourceContainerPath, destinationContainerPath, isArchive, importOptionFlags, fDestinationFolder, null, null, archiveFolderName, false);
    validateAndImportOperation.run(monitor);
    provider.dispose();

    // Clean the temporary directory
    if (tempDestination.exists()) {
        tempDestination.delete(true, monitor);
    }
}
 
Example 19
Source File: ImportBirtRuntimeAction.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * handle action to clear some old birt runtime files
 * 
 * @param webContentPath
 * @param monitor
 * @throws Exception
 */
protected void doClearAction( IPath webContentPath, IProgressMonitor monitor )
		throws Exception
{
	// remove the root folder
	IPath webPath = webContentPath;
	if ( webPath.segmentCount( ) > 0 )
		webPath = webPath.removeFirstSegments( 1 );

	// get conflict resources
	Map map = BirtWizardUtil.initConflictResources( null );

	// clear
	Iterator it = map.entrySet( ).iterator( );
	while ( it.hasNext( ) )
	{
		Map.Entry entry = (Map.Entry)it.next( );
		String folder = (String) entry.getKey( );
		if ( folder == null )
			continue;

		// get the target folder
		IPath path = webPath.append( folder );
		IFolder tempFolder = project.getFolder( path );
		if ( tempFolder == null || !tempFolder.exists( ) )
			continue;

		List files = (List) entry.getValue( );
		if ( files == null || files.size( ) <= 0 )
		{
			// delete the whole folder
			tempFolder.delete( true, monitor );
		}
		else
		{
			// delete the defined files
			tempFolder.accept( new LibResourceVisitor( monitor, files ),
					IResource.DEPTH_INFINITE, false );
		}
	}
}
 
Example 20
Source File: ImportChartRuntimeAction.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * handle action to clear some old chart runtime files
 * 
 * @param webContentPath
 * @param monitor
 * @throws Exception
 */
protected void doClearAction( IPath webContentPath, IProgressMonitor monitor )
		throws Exception
{
	// remove the root folder
	IPath webPath = webContentPath;
	if ( webPath.segmentCount( ) > 0 )
		webPath = webPath.removeFirstSegments( 1 );

	// get conflict resources
	Map<String, List<String>> map = BirtWizardUtil.initConflictResources( null );

	// clear
	Iterator<Entry<String, List<String>>> it = map.entrySet( ).iterator( );
	while ( it.hasNext( ) )
	{
		Entry<String, List<String>> entry = it.next();
		String folder = (String) entry.getKey( );
		if ( folder == null )
			continue;

		// get the target folder
		IPath path = webPath.append( folder );
		IFolder tempFolder = project.getFolder( path );
		if ( tempFolder == null || !tempFolder.exists( ) )
			continue;

		List<String> files = (List<String>) entry.getValue( );
		if ( files == null || files.size( ) <= 0 )
		{
			// delete the whole folder
			tempFolder.delete( true, monitor );
		}
		else
		{
			// delete the defined files
			tempFolder.accept( new LibResourceVisitor( monitor, files ),
					IResource.DEPTH_INFINITE, false );
		}
	}
}