/
CleanOutFoldersOperation.java
83 lines (69 loc) · 2.74 KB
/
CleanOutFoldersOperation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2003-2005 by Leif Frenzel - see http://leiffrenzel.de
package net.sf.eclipsefp.haskell.core.builder;
import net.sf.eclipsefp.haskell.core.internal.util.CoreTexts;
import net.sf.eclipsefp.haskell.scion.client.ScionPlugin;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.resources.IResourceProxyVisitor;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
/** <p>Operation for cleaning output and binary folders of a Haskell
* project.</p>
*
* @author Leif Frenzel
*/
class CleanOutFoldersOperation implements IWorkspaceRunnable {
private static IResourceProxyVisitor folderCleaner = new FolderCleaner();
private final IProject project;
CleanOutFoldersOperation( final IProject project ) {
this.project = project;
}
public void run( final IProgressMonitor mon ) throws CoreException {
mon.beginTask( CoreTexts.cleanOutFoldersOperation_cleaning, 12 );
try {
//deleteExe( mon ); // (3)
shrubOutFolder( mon ); // (12)
} finally {
mon.done();
}
}
// helping methods
//////////////////
private void shrubOutFolder( final IProgressMonitor mon )
throws CoreException {
mon.subTask( CoreTexts.cleanOutFoldersOperation_shrubbingOut );
IContainer outFolder = project.getFolder( ScionPlugin.DIST_FOLDER );
//ResourceUtil.getOutFolder( project );
if( outFolder != null && !outFolder.equals( project ) ) {
outFolder.accept( folderCleaner, IContainer.INCLUDE_PHANTOMS );
}
mon.worked( 12 );
}
// private void deleteExe( final IProgressMonitor mon ) throws CoreException {
// mon.subTask( CoreTexts.cleanOutFoldersOperation_removingExes );
// IFile[] files = ResourceUtil.getProjectExecutables( project );
// for( IFile file: files ) {
// if( file != null && file.isAccessible() ) {
// file.delete( true, new SubProgressMonitor( mon, 3 ) );
// }
// }
// }
// inner classes
////////////////
private static class FolderCleaner implements IResourceProxyVisitor {
public boolean visit( final IResourceProxy proxy ) throws CoreException {
if( proxy.getType() == IResource.FILE ) {
IResource resource = proxy.requestResource();
// TODO need more general approach here
String name = resource.getName();
if( !name.equals( ".project" ) && !name.equals( ".hsproject" ) ) { //$NON-NLS-1$ //$NON-NLS-2$
resource.delete( IResource.FORCE, null );
}
}
return true;
}
}
}