Added
Link Here
|
1 |
/* |
2 |
* Sun Public License Notice |
3 |
* |
4 |
* The contents of this file are subject to the Sun Public License |
5 |
* Version 1.0 (the "License"). You may not use this file except in |
6 |
* compliance with the License. A copy of the License is available at |
7 |
* http://www.sun.com/ |
8 |
* |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
13 |
|
14 |
package org.netbeans.modules.java.j2seproject; |
15 |
|
16 |
import java.io.IOException; |
17 |
import java.util.ArrayList; |
18 |
import java.util.List; |
19 |
import java.util.Properties; |
20 |
import org.apache.tools.ant.module.api.support.ActionUtils; |
21 |
import org.netbeans.spi.project.ActionProvider; |
22 |
import org.netbeans.spi.project.ProjectOperationsImplementation.DeleteOperationImplementation; |
23 |
import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; |
24 |
import org.openide.ErrorManager; |
25 |
import org.openide.filesystems.FileObject; |
26 |
import org.openide.filesystems.FileUtil; |
27 |
import org.openide.util.Lookup; |
28 |
import org.openide.util.lookup.Lookups; |
29 |
|
30 |
/** |
31 |
* |
32 |
* @author Jan Lahoda |
33 |
*/ |
34 |
public class J2SEProjectOperation implements DeleteOperationImplementation { |
35 |
|
36 |
private J2SEProject project; |
37 |
|
38 |
public J2SEProjectOperation(J2SEProject project) { |
39 |
this.project = project; |
40 |
} |
41 |
|
42 |
private static void addFile(FileObject projectDirectory, String fileName, List/*<FileObject>*/ result) { |
43 |
FileObject file = projectDirectory.getFileObject(fileName); |
44 |
|
45 |
if (file != null) { |
46 |
result.add(file); |
47 |
} |
48 |
} |
49 |
|
50 |
public List/*<FileObject>*/ getMetadataFiles() { |
51 |
FileObject projectDirectory = project.getProjectDirectory(); |
52 |
List/*<FileObject>*/ files = new ArrayList(); |
53 |
|
54 |
addFile(projectDirectory, "nbproject", files); // NOI18N |
55 |
addFile(projectDirectory, "build.xml", files); // NOI18N |
56 |
|
57 |
return files; |
58 |
} |
59 |
|
60 |
public List/*<FileObject>*/ getDataFiles() { |
61 |
FileObject projectDirectory = project.getProjectDirectory(); |
62 |
List/*<FileObject>*/ files = new ArrayList(); |
63 |
|
64 |
SourceRoots src = project.getSourceRoots(); |
65 |
FileObject[] srcRoots = src.getRoots(); |
66 |
|
67 |
for (int cntr = 0; cntr < srcRoots.length; cntr++) { |
68 |
if (FileUtil.isParentOf(projectDirectory, srcRoots[cntr])) |
69 |
files.add(srcRoots[cntr]); |
70 |
} |
71 |
|
72 |
SourceRoots test = project.getTestSourceRoots(); |
73 |
FileObject[] testRoots = test.getRoots(); |
74 |
|
75 |
for (int cntr = 0; cntr < testRoots.length; cntr++) { |
76 |
if (FileUtil.isParentOf(projectDirectory, testRoots[cntr])) |
77 |
files.add(testRoots[cntr]); |
78 |
} |
79 |
|
80 |
addFile(projectDirectory, "manifest.mf", files); // NOI18N |
81 |
|
82 |
return files; |
83 |
} |
84 |
|
85 |
public void performClean() throws IOException { |
86 |
J2SEActionProvider ap = (J2SEActionProvider) project.getLookup().lookup(J2SEActionProvider.class); |
87 |
|
88 |
assert ap != null; |
89 |
|
90 |
Lookup context = Lookups.fixed(new Object[0]); |
91 |
Properties p = new Properties(); |
92 |
String[] targetNames = ap.getTargetNames(ActionProvider.COMMAND_CLEAN, context, p); |
93 |
FileObject buildXML = project.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_XML_PATH); |
94 |
|
95 |
assert targetNames != null; |
96 |
assert targetNames.length > 0; |
97 |
|
98 |
ActionUtils.runTarget(buildXML, targetNames, p).waitFinished(); |
99 |
} |
100 |
|
101 |
public void notifyDeleted() throws IOException { |
102 |
project.getAntProjectHelper().notifyDeleted(); |
103 |
} |
104 |
|
105 |
} |