This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 58866
Collapse All | Expand All

(-)freeform/src/org/netbeans/modules/ant/freeform/Actions.java (+12 lines)
Lines 71-76 Link Here
71
     */
71
     */
72
    private static final Set/*<String>*/ COMMON_IDE_GLOBAL_ACTIONS = new HashSet(Arrays.asList(new String[] {
72
    private static final Set/*<String>*/ COMMON_IDE_GLOBAL_ACTIONS = new HashSet(Arrays.asList(new String[] {
73
        ActionProvider.COMMAND_DEBUG,
73
        ActionProvider.COMMAND_DEBUG,
74
        ActionProvider.COMMAND_DELETE,
74
    }));
75
    }));
75
    /**
76
    /**
76
     * Similar to {@link #COMMON_IDE_GLOBAL_ACTIONS}, but these are not IDE-specific.
77
     * Similar to {@link #COMMON_IDE_GLOBAL_ACTIONS}, but these are not IDE-specific.
Lines 113-122 Link Here
113
        }
114
        }
114
        // #46886: also always enable all common global actions, in case they should be selected:
115
        // #46886: also always enable all common global actions, in case they should be selected:
115
        names.addAll(COMMON_NON_IDE_GLOBAL_ACTIONS);
116
        names.addAll(COMMON_NON_IDE_GLOBAL_ACTIONS);
117
        names.add(COMMAND_DELETE);
116
        return (String[])names.toArray(new String[names.size()]);
118
        return (String[])names.toArray(new String[names.size()]);
117
    }
119
    }
118
    
120
    
119
    public boolean isActionEnabled(String command, Lookup context) throws IllegalArgumentException {
121
    public boolean isActionEnabled(String command, Lookup context) throws IllegalArgumentException {
122
        if (COMMAND_DELETE.equals(command)) {
123
            return true;
124
        }
125
        
120
        Element genldata = project.helper().getPrimaryConfigurationData(true);
126
        Element genldata = project.helper().getPrimaryConfigurationData(true);
121
        Element actionsEl = Util.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
127
        Element actionsEl = Util.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
122
        if (actionsEl == null) {
128
        if (actionsEl == null) {
Lines 166-171 Link Here
166
    }
172
    }
167
    
173
    
168
    public void invokeAction(String command, Lookup context) throws IllegalArgumentException {
174
    public void invokeAction(String command, Lookup context) throws IllegalArgumentException {
175
        if (COMMAND_DELETE.equals(command)) {
176
            project.helper().performDefaultDeleteOperation();
177
            return ;
178
        }
169
        Element genldata = project.helper().getPrimaryConfigurationData(true);
179
        Element genldata = project.helper().getPrimaryConfigurationData(true);
170
        Element actionsEl = Util.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
180
        Element actionsEl = Util.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
171
        if (actionsEl == null) {
181
        if (actionsEl == null) {
Lines 427-432 Link Here
427
        actions.add(CommonProjectActions.setAsMainProjectAction());
437
        actions.add(CommonProjectActions.setAsMainProjectAction());
428
        actions.add(CommonProjectActions.openSubprojectsAction());
438
        actions.add(CommonProjectActions.openSubprojectsAction());
429
        actions.add(CommonProjectActions.closeProjectAction());
439
        actions.add(CommonProjectActions.closeProjectAction());
440
        actions.add(null);
441
        actions.add(CommonProjectActions.deleteProjectAction());
430
        actions.add(null);
442
        actions.add(null);
431
        actions.add(SystemAction.get(FindAction.class));
443
        actions.add(SystemAction.get(FindAction.class));
432
        
444
        
(-)freeform/src/org/netbeans/modules/ant/freeform/FreeformProject.java (+1 lines)
Lines 82-87 Link Here
82
            new Subprojects(this), // SubprojectProvider
82
            new Subprojects(this), // SubprojectProvider
83
            new ArtifactProvider(this), // AntArtifactProvider
83
            new ArtifactProvider(this), // AntArtifactProvider
84
            new LookupMergerImpl(), // LookupMerger
84
            new LookupMergerImpl(), // LookupMerger
85
            new FreeformProjectOperation(this),
85
        });
86
        });
86
        return new FreeformLookup(baseLookup, this, helper, eval, aux);
87
        return new FreeformLookup(baseLookup, this, helper, eval, aux);
87
    }
88
    }
(-)freeform/src/org/netbeans/modules/ant/freeform/FreeformProjectOperation.java (+112 lines)
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.ant.freeform;
15
16
import java.io.File;
17
import java.io.IOException;
18
import java.util.ArrayList;
19
import java.util.Collections;
20
import java.util.Iterator;
21
import java.util.List;
22
import org.netbeans.modules.ant.freeform.spi.support.Util;
23
import org.netbeans.spi.project.ProjectOperationsImplementation.DeleteOperationImplementation;
24
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
25
import org.openide.filesystems.FileObject;
26
import org.openide.filesystems.FileUtil;
27
import org.w3c.dom.Element;
28
29
/**
30
 *
31
 * @author Jan Lahoda
32
 */
33
public class FreeformProjectOperation implements DeleteOperationImplementation {
34
    
35
    private FreeformProject project;
36
    
37
    public FreeformProjectOperation(FreeformProject project) {
38
        this.project = project;
39
    }
40
    
41
    private static void addFile(FileObject projectDirectory, String fileName, List/*<FileObject>*/ result) {
42
        FileObject file = projectDirectory.getFileObject(fileName);
43
        
44
        if (file != null) {
45
            result.add(file);
46
        }
47
    }
48
    
49
    public List/*<FileObject>*/ getMetadataFiles() {
50
        FileObject projectDirectory = project.getProjectDirectory();
51
        List/*<FileObject>*/ files = new ArrayList();
52
        
53
        addFile(projectDirectory, "nbproject", files); // NOI18N
54
        
55
        return files;
56
    }
57
    
58
    public List/*<FileObject>*/ getDataFiles() {
59
        Element genldata = project.helper().getPrimaryConfigurationData(true);
60
        Element foldersEl = Util.findElement(genldata, "folders", FreeformProjectType.NS_GENERAL); // NOI18N
61
        List/*<Element>*/ folders = Util.findSubElements(foldersEl);
62
        List/*<FileObject>*/ result = new ArrayList/*<FileObject>*/();
63
64
        for (Iterator i = folders.iterator(); i.hasNext(); ) {
65
            Element el = (Element) i.next();
66
            
67
            if ("source-folder".equals(el.getLocalName()) && FreeformProjectType.NS_GENERAL.equals(el.getNamespaceURI())) {
68
                addFile(el, result);
69
            }
70
        }
71
        
72
        addFile(project.getProjectDirectory(), "build.xml", result); // NOI18N
73
        
74
        return result;
75
    }
76
    
77
    private void addFile(Element folder, List/*<FileObject>*/ result) {
78
        Element location = Util.findElement(folder, "location", FreeformProjectType.NS_GENERAL);
79
        
80
        if (location == null) {
81
            return ;
82
        }
83
        
84
        PropertyEvaluator evaluator = project.evaluator();
85
        String val = evaluator.evaluate(Util.findText(location));
86
        
87
        if (val == null) {
88
            return ;
89
        }
90
        
91
        File f = project.helper().resolveFile(val);
92
            
93
        if (f == null) {
94
            return ;
95
        }
96
        
97
        FileObject fo = FileUtil.toFileObject(f);
98
        
99
        if (fo != null && FileUtil.isParentOf(project.getProjectDirectory(), fo)) {
100
            result.add(fo);
101
        }
102
    }
103
    
104
    public void performClean() throws IOException {
105
        //TODO: invoke clean action if bound.
106
    }
107
    
108
    public void notifyDeleted() throws IOException {
109
        project.helper().notifyDeleted();
110
    }
111
    
112
}
(-)project/apichanges.xml (+14 lines)
Lines 76-81 Link Here
76
76
77
    <changes>
77
    <changes>
78
78
79
        <change id="delete-support">
80
            <api name="general"/>
81
            <summary>Basic Support SPI for Project Delete</summary>
82
            <version major="1" minor="7"/>
83
            <date day="20" month="6" year="2005"/>
84
            <author login="jlahoda"/>
85
            <compatibility addition="yes"/>
86
            <description>
87
                <code>AntProjectHelper.notifyDeleted()</code> and <code>AntProjectHelper.performDefaultDeleteOperation()</code>
88
                added.
89
            </description>
90
            <issue number="51468"/>
91
        </change>
92
        
79
        <change id="StoreGroup">
93
        <change id="StoreGroup">
80
            <api name="general"/>
94
            <api name="general"/>
81
            <summary>Support SPI for creating/storing Swing models for simple Ant properties</summary>
95
            <summary>Support SPI for creating/storing Swing models for simple Ant properties</summary>
(-)project/nbproject/project.properties (-2 / +4 lines)
Lines 22-30 Link Here
22
22
23
test.unit.cp.extra=\
23
test.unit.cp.extra=\
24
    ${nb_all}/projects/projectapi/build/test/unit/classes:\
24
    ${nb_all}/projects/projectapi/build/test/unit/classes:\
25
    ${diff.dir}/modules/org-netbeans-modules-diff.jar
25
    ${diff.dir}/modules/org-netbeans-modules-diff.jar:\
26
    ${projects/projectui.dir}/modules/org-netbeans-modules-projectui.jar
26
# For XMLSerializer, needed for XMLUtil.write to work w/ namespaces:
27
# For XMLSerializer, needed for XMLUtil.write to work w/ namespaces:
27
test.unit.run.cp.extra=\
28
test.unit.run.cp.extra=\
28
    ${libs/xerces.dir}/modules/ext/xerces-2.6.2.jar:\
29
    ${libs/xerces.dir}/modules/ext/xerces-2.6.2.jar:\
29
    ${libs/xerces.dir}/modules/ext/xml-commons-dom-ranges-1.0.b2.jar:\
30
    ${libs/xerces.dir}/modules/ext/xml-commons-dom-ranges-1.0.b2.jar:\
30
    ${openide/masterfs.dir}/modules/org-netbeans-modules-masterfs.jar
31
    ${openide/masterfs.dir}/modules/org-netbeans-modules-masterfs.jar:\
32
    ${openide/options.dir}/modules/org-openide-options.jar
(-)project/nbproject/project.xml (+16 lines)
Lines 26-32 Link Here
26
                    </run-dependency>
26
                    </run-dependency>
27
                </dependency>
27
                </dependency>
28
                <dependency>
28
                <dependency>
29
                    <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
30
                    <build-prerequisite/>
31
                    <compile-dependency/>
32
                    <run-dependency>
33
                        <release-version>1</release-version>
34
                    </run-dependency>
35
                </dependency>
36
                <dependency>
29
                    <code-name-base>org.netbeans.modules.queries</code-name-base>
37
                    <code-name-base>org.netbeans.modules.queries</code-name-base>
38
                    <build-prerequisite/>
39
                    <compile-dependency/>
40
                    <run-dependency>
41
                        <release-version>1</release-version>
42
                    </run-dependency>
43
                </dependency>
44
                <dependency>
45
                    <code-name-base>org.netbeans.api.progress</code-name-base>
30
                    <build-prerequisite/>
46
                    <build-prerequisite/>
31
                    <compile-dependency/>
47
                    <compile-dependency/>
32
                    <run-dependency>
48
                    <run-dependency>
(-)project/src/org/netbeans/modules/project/ant/AntBasedProjectFactorySingleton.java (-1 / +41 lines)
Lines 15-27 Link Here
15
15
16
import java.io.File;
16
import java.io.File;
17
import java.io.IOException;
17
import java.io.IOException;
18
import java.io.InputStream;
19
import java.lang.ref.Reference;
18
import java.lang.ref.Reference;
20
import java.lang.ref.WeakReference;
19
import java.lang.ref.WeakReference;
21
import java.util.ArrayList;
20
import java.util.ArrayList;
22
import java.util.HashMap;
21
import java.util.HashMap;
22
import java.util.HashSet;
23
import java.util.Iterator;
23
import java.util.Iterator;
24
import java.util.List;
24
import java.util.Map;
25
import java.util.Map;
26
import java.util.Set;
25
import java.util.WeakHashMap;
27
import java.util.WeakHashMap;
26
import org.netbeans.api.project.Project;
28
import org.netbeans.api.project.Project;
27
import org.netbeans.spi.project.ProjectFactory;
29
import org.netbeans.spi.project.ProjectFactory;
Lines 55-60 Link Here
55
    
57
    
56
    private static final Map/*<Project,Reference<AntProjectHelper>>*/ project2Helper = new WeakHashMap();
58
    private static final Map/*<Project,Reference<AntProjectHelper>>*/ project2Helper = new WeakHashMap();
57
    private static final Map/*<AntProjectHelper,Reference<Project>>*/ helper2Project = new WeakHashMap();
59
    private static final Map/*<AntProjectHelper,Reference<Project>>*/ helper2Project = new WeakHashMap();
60
    private static final Map/*<AntBasedProjectType, List<Reference<AntProjectHelper>>>*/ type2Projects = new HashMap(); //for second part of #42738
58
    private static final Lookup.Result/*<AntBasedProjectType>*/ antBasedProjectTypes;
61
    private static final Lookup.Result/*<AntBasedProjectType>*/ antBasedProjectTypes;
59
    private static Map/*<String,AntBasedProjectType>*/ antBasedProjectTypesByType = null;
62
    private static Map/*<String,AntBasedProjectType>*/ antBasedProjectTypesByType = null;
60
    static {
63
    static {
Lines 62-73 Link Here
62
        antBasedProjectTypes.addLookupListener(new LookupListener() {
65
        antBasedProjectTypes.addLookupListener(new LookupListener() {
63
            public void resultChanged(LookupEvent ev) {
66
            public void resultChanged(LookupEvent ev) {
64
                synchronized (AntBasedProjectFactorySingleton.class) {
67
                synchronized (AntBasedProjectFactorySingleton.class) {
68
                    Set/*<AntBasedProjectType>*/ oldTypes = type2Projects.keySet();
69
                    Set/*<AntBasedProjectType>*/ removed  = new HashSet(oldTypes);
70
                    
71
                    removed.removeAll(antBasedProjectTypes.allInstances());
72
                    
73
                    antBasedProjectTypesRemoved(removed);
74
                    
65
                    antBasedProjectTypesByType = null;
75
                    antBasedProjectTypesByType = null;
66
                }
76
                }
67
            }
77
            }
68
        });
78
        });
69
    }
79
    }
70
    
80
    
81
    private static void antBasedProjectTypesRemoved(Set/*<AntBasedProjectType>*/ removed) {
82
        for (Iterator/*<AntBasedProjectType>*/ i = removed.iterator(); i.hasNext(); ){
83
            AntBasedProjectType type = (AntBasedProjectType) i.next();
84
            List/*<Reference<AntProjectHelper>>*/ projects = (List/*<Reference<AntProjectHelper>>*/) type2Projects.get(type);
85
            
86
            if (projects != null) {
87
                for (Iterator/*<Reference<AntProjectHelper>>*/ prjs = projects.iterator(); prjs.hasNext(); ) {
88
                    Reference/*<AntProjectHelper>*/ r = (Reference/*<AntProjectHelper>*/) prjs.next();
89
                    Object instance = r.get();
90
                    
91
                    if (instance != null) {
92
                        AntProjectHelper helper = (AntProjectHelper) instance;
93
                        
94
                        helper.notifyDeleted();
95
                    }
96
                }
97
            }
98
            
99
            type2Projects.remove(type);
100
        }
101
    }
102
    
71
    private static synchronized AntBasedProjectType findAntBasedProjectType(String type) {
103
    private static synchronized AntBasedProjectType findAntBasedProjectType(String type) {
72
        if (antBasedProjectTypesByType == null) {
104
        if (antBasedProjectTypesByType == null) {
73
            Iterator it = new ArrayList(antBasedProjectTypes.allInstances()).iterator();
105
            Iterator it = new ArrayList(antBasedProjectTypes.allInstances()).iterator();
Lines 133-138 Link Here
133
        Project project = provider.createProject(helper);
165
        Project project = provider.createProject(helper);
134
        project2Helper.put(project, new WeakReference(helper));
166
        project2Helper.put(project, new WeakReference(helper));
135
        helper2Project.put(helper, new WeakReference(project));
167
        helper2Project.put(helper, new WeakReference(project));
168
        List/*<Reference<AntProjectHelper>>*/ l = (List/*<Reference<AntProjectHelper>>*/) type2Projects.get(provider);
169
        
170
        if (l == null) {
171
            type2Projects.put(provider, l = new ArrayList/*<Reference<AntProjectHelper>>*/());
172
        }
173
        
174
        l.add(new WeakReference(helper));
175
        
136
        return project;
176
        return project;
137
    }
177
    }
138
    
178
    
(-)project/src/org/netbeans/modules/project/ant/Bundle.properties (+20 lines)
Lines 18-20 Link Here
18
18
19
# UserQuestionHandler
19
# UserQuestionHandler
20
TITLE_CannotWriteFile=Cannot Write to File
20
TITLE_CannotWriteFile=Cannot Write to File
21
22
LBL_Progress_Cleaning_Project=Cleaning Project
23
24
LBL_Project_cannot_be_deleted.=Project {0} cannot be deleted.
25
26
LBL_Delete_Project_Caption=Delete Project
27
28
LBL_Project_Deletion_in_Progress_Caption=Project Deletion in Progress
29
30
LBL_Project_Deleted_Caption=Project {0} has been successfully deleted.
31
32
LBL_Deleting_Project=Deleting Project\:
33
34
LBL_Progress_Deleting_File=Deleting {0}
35
36
LBL_Pre_Delete_Warning=Are you sure you want to delete project "{0}"?
37
38
LBL_Delete_Also_Sources=Also Delete Sources Under "{0}" folder.
39
40
LBL_File_To_Delete=Files to Delete\:
(-)project/src/org/netbeans/modules/project/ant/DefaultAntProjectDeletePanel.form (+50 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.0" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
5
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
6
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
7
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
8
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
9
    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,46,0,0,1,-112"/>
10
  </AuxValues>
11
12
  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
13
  <SubComponents>
14
    <Component class="javax.swing.JTextArea" name="warningText">
15
      <Properties>
16
        <Property name="editable" type="boolean" value="false"/>
17
        <Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
18
          <Connection code="javax.swing.UIManager.getFont(&quot;Label.font&quot;)" type="code"/>
19
        </Property>
20
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
21
          <Connection code="getWarningText()" type="code"/>
22
        </Property>
23
        <Property name="disabledTextColor" type="java.awt.Color" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
24
          <Connection code="javax.swing.UIManager.getColor(&quot;Label.foreground&quot;)" type="code"/>
25
        </Property>
26
        <Property name="opaque" type="boolean" value="false"/>
27
      </Properties>
28
      <Constraints>
29
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
30
          <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="12" insetsBottom="0" insetsRight="12" anchor="18" weightX="1.0" weightY="0.0"/>
31
        </Constraint>
32
      </Constraints>
33
    </Component>
34
    <Component class="javax.swing.JCheckBox" name="deleteSourcesCheckBox">
35
      <Properties>
36
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
37
          <Connection code="getCheckboxText()" type="code"/>
38
        </Property>
39
        <Property name="enabled" type="boolean" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
40
          <Connection code="enableCheckbox" type="code"/>
41
        </Property>
42
      </Properties>
43
      <Constraints>
44
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
45
          <GridBagConstraints gridX="0" gridY="3" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="12" insetsLeft="12" insetsBottom="0" insetsRight="12" anchor="17" weightX="0.0" weightY="0.0"/>
46
        </Constraint>
47
      </Constraints>
48
    </Component>
49
  </SubComponents>
50
</Form>
(-)project/src/org/netbeans/modules/project/ant/DefaultAntProjectDeletePanel.java (+142 lines)
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.project.ant;
15
16
import java.awt.Component;
17
import java.awt.Window;
18
import java.text.MessageFormat;
19
import java.util.Iterator;
20
import java.util.List;
21
import org.openide.filesystems.FileObject;
22
import org.openide.filesystems.FileUtil;
23
import org.openide.util.NbBundle;
24
25
/**
26
 *
27
 * @author Jan Lahoda
28
 */
29
final class DefaultAntProjectDeletePanel extends javax.swing.JPanel {
30
    
31
    private String projectDisplaName;
32
    private String projectFolder;
33
    private boolean enableCheckbox;
34
//    private List/*<String>*/ metadataFileNames;
35
//    private List/*<String>*/ allFileNames;
36
    
37
    /**
38
     * Creates new form DefaultAntProjectDeletePanel
39
     */
40
    public DefaultAntProjectDeletePanel(String projectDisplaName, String projectFolder, boolean enableCheckbox) {
41
        this.projectDisplaName = projectDisplaName;
42
        this.projectFolder = projectFolder;
43
//        this.metadataFileNames = metadataFileNames;
44
//        this.allFileNames = allFileNames;
45
        this.enableCheckbox = enableCheckbox;
46
        initComponents();
47
//        updateSourcesList();
48
    }
49
    
50
    /** This method is called from within the constructor to
51
     * initialize the form.
52
     * WARNING: Do NOT modify this code. The content of this method is
53
     * always regenerated by the Form Editor.
54
     */
55
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
56
    private void initComponents() {
57
        java.awt.GridBagConstraints gridBagConstraints;
58
59
        warningText = new javax.swing.JTextArea();
60
        deleteSourcesCheckBox = new javax.swing.JCheckBox();
61
62
        setLayout(new java.awt.GridBagLayout());
63
64
        warningText.setEditable(false);
65
        warningText.setFont(javax.swing.UIManager.getFont("Label.font"));
66
        warningText.setText(getWarningText());
67
        warningText.setDisabledTextColor(javax.swing.UIManager.getColor("Label.foreground"));
68
        warningText.setOpaque(false);
69
        gridBagConstraints = new java.awt.GridBagConstraints();
70
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
71
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
72
        gridBagConstraints.weightx = 1.0;
73
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 12);
74
        add(warningText, gridBagConstraints);
75
76
        deleteSourcesCheckBox.setText(getCheckboxText());
77
        deleteSourcesCheckBox.setEnabled(enableCheckbox);
78
        gridBagConstraints = new java.awt.GridBagConstraints();
79
        gridBagConstraints.gridx = 0;
80
        gridBagConstraints.gridy = 3;
81
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
82
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 12);
83
        add(deleteSourcesCheckBox, gridBagConstraints);
84
85
    }
86
    // </editor-fold>//GEN-END:initComponents
87
    
88
    
89
    // Variables declaration - do not modify//GEN-BEGIN:variables
90
    private javax.swing.JCheckBox deleteSourcesCheckBox;
91
    private javax.swing.JTextArea warningText;
92
    // End of variables declaration//GEN-END:variables
93
    
94
    public boolean isDeleteSources() {
95
        return deleteSourcesCheckBox.isSelected();
96
    }
97
98
/*    private void updateSourcesList() {
99
        boolean enabled = deleteSourcesCheckBox.isSelected();
100
        
101
        if (enabled) {
102
            deleteList.setText(getTextForFiles(allFileNames));
103
        } else {
104
            deleteList.setText(getTextForFiles(metadataFileNames));
105
        }
106
        
107
        Component c = this;
108
        
109
        while (c != null && !(c instanceof Window)) {
110
            c = c.getParent();
111
        }
112
        
113
        if (c != null) {
114
            ((Window) c).pack();
115
        }
116
    }*/
117
    
118
//    private static String getTextForFiles(List/*<String>*/ files) {
119
//        StringBuffer result = new StringBuffer();
120
//        
121
//        for (Iterator/*<String>*/ i = files.iterator(); i.hasNext(); ) {
122
//            String file = (String) i.next();
123
//            
124
//            result.append(file);
125
//            
126
//            if (i.hasNext()) {
127
//                result.append("\n"); // NOI18N
128
//            }
129
//        }
130
//        
131
//        return result.toString();
132
//    }
133
134
    private String getWarningText() {
135
        return MessageFormat.format(NbBundle.getBundle(DefaultAntProjectDeletePanel.class).getString("LBL_Pre_Delete_Warning"), new Object[] {projectDisplaName});
136
    }
137
    
138
    private String getCheckboxText() {
139
        return MessageFormat.format(NbBundle.getBundle(DefaultAntProjectDeletePanel.class).getString("LBL_Delete_Also_Sources"), new Object[] {projectFolder});
140
    }
141
    
142
}
(-)project/src/org/netbeans/modules/project/ant/DefaultAntProjectOperation.java (+320 lines)
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.project.ant;
15
16
import java.awt.Dialog;
17
import java.awt.GridBagConstraints;
18
import java.awt.Insets;
19
import java.io.IOException;
20
import java.text.MessageFormat;
21
import java.util.ArrayList;
22
import java.util.Collections;
23
import java.util.Iterator;
24
import java.util.List;
25
import javax.swing.JComponent;
26
import javax.swing.JLabel;
27
import javax.swing.JPanel;
28
import javax.swing.SwingUtilities;
29
import org.netbeans.api.progress.ProgressHandle;
30
import org.netbeans.api.progress.ProgressHandleFactory;
31
import org.netbeans.api.project.Project;
32
import org.netbeans.api.project.ProjectUtils;
33
import org.netbeans.api.project.ui.OpenProjects;
34
import org.netbeans.api.project.ProjectOperations;
35
import org.netbeans.spi.project.support.ant.AntProjectHelper;
36
import org.openide.DialogDescriptor;
37
import org.openide.DialogDisplayer;
38
import org.openide.ErrorManager;
39
import org.openide.NotifyDescriptor;
40
import org.openide.filesystems.FileObject;
41
import org.openide.filesystems.FileUtil;
42
import org.openide.util.HelpCtx;
43
import org.openide.util.NbBundle;
44
import org.openide.util.RequestProcessor;
45
46
47
/**
48
 *
49
 * @author Jan Lahoda
50
 */
51
public final class DefaultAntProjectOperation {
52
    
53
    private static final ErrorManager ERR = ErrorManager.getDefault(); // NOI18N
54
    
55
    private DefaultAntProjectOperation() {
56
    }
57
    
58
    private static String getDisplayName(Project project) {
59
        return ProjectUtils.getInformation(project).getDisplayName();
60
    }
61
 
62
    //<editor-fold defaultstate="collapsed" desc="Delete Operation">
63
    /**
64
     * @return true if success
65
     */
66
    private static boolean performDelete(AntProjectHelper helper, Project project, List/*FileObject>*/ toDelete, ProgressHandle handle) {
67
        try {
68
            String progressFormat = NbBundle.getMessage(DefaultAntProjectOperation.class, "LBL_Progress_Deleting_File");
69
            
70
            handle.start(toDelete.size() + 1 /*clean*/);
71
            
72
            int done = 0;
73
            
74
            handle.progress(NbBundle.getMessage(DefaultAntProjectOperation.class, "LBL_Progress_Cleaning_Project"));
75
            
76
            ProjectOperations.getDefault().performClean(project);
77
            
78
            handle.progress(++done);
79
            
80
            for (Iterator i = toDelete.iterator(); i.hasNext(); ) {
81
                FileObject f = (FileObject) i.next();
82
                
83
                handle.progress(MessageFormat.format(progressFormat, new Object[] {FileUtil.getFileDisplayName(f)}));
84
                
85
                if (f != null)
86
                    f.delete();
87
                
88
                handle.progress(++done);
89
            }
90
            
91
            FileObject projectFolder = project.getProjectDirectory();
92
            
93
            if (projectFolder.getChildren().length == 0) {
94
                //empty, delete:
95
                projectFolder.delete();
96
            }
97
            
98
            handle.finish();
99
            
100
            ProjectOperations.getDefault().notifyDeleted(project);
101
            return true;
102
        } catch (IOException e) {
103
            String displayName = getDisplayName(project);
104
            String message     = NbBundle.getMessage(DefaultAntProjectOperation.class, "LBL_Project_cannot_be_deleted.", new Object[] {displayName});
105
            
106
            ErrorManager.getDefault().annotate(e, message);
107
            ErrorManager.getDefault().notify(ErrorManager.USER, e);
108
            
109
            return false;
110
        }
111
    }
112
    
113
    public static void deleteProject(final Project project) {
114
        Runnable r = new Runnable() {
115
            public void run() {
116
                deleteProject(project, new GUIUserInputHandler());
117
            }
118
        };
119
        
120
        if (SwingUtilities.isEventDispatchThread()) {
121
            r.run();
122
        } else {
123
            SwingUtilities.invokeLater(r);
124
        }
125
    }
126
    
127
    /*package private*/static void deleteProject(final Project project, final UserInputHandler handler) {
128
        String displayName = getDisplayName(project);
129
        String projectFolder = FileUtil.getFileDisplayName(project.getProjectDirectory());
130
        
131
        final AntProjectHelper helper = AntBasedProjectFactorySingleton.getHelperFor(project);
132
        
133
        assert helper != null;
134
        
135
        if (ERR.isLoggable(ErrorManager.INFORMATIONAL)) {
136
            ERR.log(ErrorManager.INFORMATIONAL, "delete started: " + displayName); // NOI18N
137
        }
138
        
139
        List/*<FileObject>*/ metadataFiles = ProjectOperations.getDefault().getMetadataFiles(project);
140
        List/*<FileObject>*/ dataFiles = ProjectOperations.getDefault().getDataFiles(project);
141
        List/*<FileObject>*/ allFiles = new ArrayList/*<FileObject>*/();
142
        
143
        allFiles.addAll(metadataFiles);
144
        allFiles.addAll(dataFiles);
145
        
146
        int userAnswer = handler.userConfirmation(displayName, projectFolder, !dataFiles.isEmpty());
147
        List/*<FileObject>*/ toDeleteImpl = null;
148
        
149
        switch (userAnswer) {
150
            case UserInputHandler.USER_CANCEL:
151
                return ;
152
            case UserInputHandler.USER_OK_METADATA:
153
                toDeleteImpl = metadataFiles;
154
                break;
155
            case UserInputHandler.USER_OK_ALL:
156
                toDeleteImpl = allFiles;
157
                break;
158
            default:
159
                throw new IllegalStateException("Invalid user answer: " + userAnswer);
160
        }
161
        
162
        final ProgressHandle handle = handler.getProgressHandle();
163
        final List/*<FileObject>*/ toDelete = toDeleteImpl;
164
        final boolean[] result = new boolean[1];
165
        
166
        OpenProjects.getDefault().close(new Project[] {project});
167
        
168
        handler.delete(new Runnable() {
169
            public void run() {
170
                result[0] = performDelete(helper, project, toDelete, handle);
171
            }
172
        });
173
        
174
/*        if (result[0]) {
175
            if (ERR.isLoggable(ErrorManager.INFORMATIONAL)) {
176
                ERR.log(ErrorManager.INFORMATIONAL, "delete successfull"); // NOI18N
177
            }
178
            
179
            String  message = NbBundle.getMessage(DefaultAntProjectOperation.class, "LBL_Project_Deleted_Caption", new Object[] {displayName});
180
            NotifyDescriptor nd = new NotifyDescriptor.Message(message);
181
            
182
            DialogDisplayer.getDefault().notify(nd);
183
        }*/
184
        
185
        if (ERR.isLoggable(ErrorManager.INFORMATIONAL)) {
186
            ERR.log(ErrorManager.INFORMATIONAL, "delete done: " + displayName); // NOI18N
187
        }
188
    }
189
    
190
    /*package private*/interface UserInputHandler {
191
        
192
        public int USER_CANCEL = 1;
193
        public int USER_OK_METADATA = 2;
194
        public int USER_OK_ALL = 3;
195
        
196
        public abstract int userConfirmation(String displayName, String projectFolder, boolean enableData);
197
        
198
        public abstract ProgressHandle getProgressHandle();
199
        
200
        public abstract void delete(Runnable r);
201
        
202
    }
203
    
204
    private static final class GUIUserInputHandler implements UserInputHandler {
205
        
206
        public int userConfirmation(String displayName, String projectFolder, boolean enableData) {
207
            DefaultAntProjectDeletePanel deletePanel = new DefaultAntProjectDeletePanel(displayName, projectFolder, enableData);
208
            
209
            String caption = NbBundle.getMessage(DefaultAntProjectOperation.class, "LBL_Delete_Project_Caption");
210
            
211
            DialogDescriptor dd = new DialogDescriptor(deletePanel, caption);
212
            
213
            DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
214
            
215
            if (dd.getValue() == DialogDescriptor.OK_OPTION) {
216
                if (deletePanel.isDeleteSources()) {
217
                    return USER_OK_ALL;
218
                } else {
219
                    return USER_OK_METADATA;
220
                }
221
            } else {
222
                return USER_CANCEL;
223
            }
224
        }
225
        
226
        private ProgressHandle handle = null;
227
        
228
        public synchronized ProgressHandle getProgressHandle() {
229
            if (handle == null) {
230
                handle = ProgressHandleFactory.createHandle(NbBundle.getMessage(DefaultAntProjectOperation.class, "LBL_Delete_Project_Caption"));
231
            }
232
            
233
            return handle;
234
        }
235
        
236
        public void delete(final Runnable r) {
237
            String inProgressCaption = NbBundle.getMessage(DefaultAntProjectOperation.class, "LBL_Project_Deletion_in_Progress_Caption");
238
            DialogDescriptor dd2 = new DialogDescriptor(createProgressDialog(handle), inProgressCaption, true, new Object[0], null, DialogDescriptor.BOTTOM_ALIGN, HelpCtx.DEFAULT_HELP, null);
239
            
240
            final Dialog dialog = DialogDisplayer.getDefault().createDialog(dd2);
241
            final boolean[] result = new boolean[1];
242
            
243
            RequestProcessor.getDefault().post(new Runnable() {
244
                public void run() {
245
                    r.run();
246
                    
247
                    if (ERR.isLoggable(ErrorManager.INFORMATIONAL)) {
248
                        ERR.log(ErrorManager.INFORMATIONAL, "delete finished"); // NOI18N
249
                    }
250
                    
251
                    SwingUtilities.invokeLater(new Runnable() {
252
                        public void run() {
253
                            if (ERR.isLoggable(ErrorManager.INFORMATIONAL)) {
254
                                ERR.log(ErrorManager.INFORMATIONAL, "calling hide on progress dialog"); // NOI18N
255
                            }
256
                            
257
                            dialog.hide();
258
                            
259
                            if (ERR.isLoggable(ErrorManager.INFORMATIONAL)) {
260
                                ERR.log(ErrorManager.INFORMATIONAL, "done"); // NOI18N
261
                            }
262
                        }
263
                    });
264
                }
265
            });
266
            
267
            if (ERR.isLoggable(ErrorManager.INFORMATIONAL)) {
268
                ERR.log(ErrorManager.INFORMATIONAL, "showing progress dialog"); // NOI18N
269
            }
270
            
271
            dialog.show();
272
            
273
            if (ERR.isLoggable(ErrorManager.INFORMATIONAL)) {
274
                ERR.log(ErrorManager.INFORMATIONAL, "progress dialog hidden"); // NOI18N
275
            }
276
        }
277
        
278
    }
279
    
280
    private static JComponent createProgressDialog(ProgressHandle handle) {
281
        JPanel dialog = new JPanel();
282
        
283
        GridBagConstraints gridBagConstraints;
284
        
285
        JLabel jLabel1 = new JLabel();
286
        JComponent progress = ProgressHandleFactory.createProgressComponent(handle);
287
        JPanel padding = new JPanel();
288
        
289
        dialog.setLayout(new java.awt.GridBagLayout());
290
        
291
        jLabel1.setText(NbBundle.getMessage(DefaultAntProjectOperation.class, "LBL_Deleting_Project"));
292
        gridBagConstraints = new GridBagConstraints();
293
        gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
294
        gridBagConstraints.insets = new Insets(12, 12, 0, 12);
295
        dialog.add(jLabel1, gridBagConstraints);
296
        
297
        gridBagConstraints = new GridBagConstraints();
298
        gridBagConstraints.gridx = 0;
299
        gridBagConstraints.gridy = 1;
300
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
301
        gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
302
        gridBagConstraints.weightx = 1.0;
303
        gridBagConstraints.insets = new Insets(12, 12, 0, 12);
304
        dialog.add(progress, gridBagConstraints);
305
306
        gridBagConstraints = new GridBagConstraints();
307
        gridBagConstraints.gridx = 0;
308
        gridBagConstraints.gridy = 2;
309
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL | GridBagConstraints.VERTICAL;
310
        gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
311
        gridBagConstraints.weightx = 1.0;
312
        gridBagConstraints.weighty = 1.0;
313
        gridBagConstraints.insets = new Insets(12, 12, 12, 12);
314
        dialog.add(padding, gridBagConstraints);
315
        
316
        return dialog;
317
    }
318
    //</editor-fold>
319
    
320
}
(-)project/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java (+32 lines)
Lines 29-34 Link Here
29
import org.netbeans.api.project.ProjectManager;
29
import org.netbeans.api.project.ProjectManager;
30
import org.netbeans.api.project.ant.AntArtifact;
30
import org.netbeans.api.project.ant.AntArtifact;
31
import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton;
31
import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton;
32
import org.netbeans.modules.project.ant.DefaultAntProjectOperation;
32
import org.netbeans.modules.project.ant.FileChangeSupport;
33
import org.netbeans.modules.project.ant.FileChangeSupport;
33
import org.netbeans.modules.project.ant.FileChangeSupportEvent;
34
import org.netbeans.modules.project.ant.FileChangeSupportEvent;
34
import org.netbeans.modules.project.ant.FileChangeSupportListener;
35
import org.netbeans.modules.project.ant.FileChangeSupportListener;
Lines 37-42 Link Here
37
import org.netbeans.spi.project.AuxiliaryConfiguration;
38
import org.netbeans.spi.project.AuxiliaryConfiguration;
38
import org.netbeans.spi.project.CacheDirectoryProvider;
39
import org.netbeans.spi.project.CacheDirectoryProvider;
39
import org.netbeans.spi.project.ProjectState;
40
import org.netbeans.spi.project.ProjectState;
41
import org.netbeans.api.project.ProjectOperations;
40
import org.netbeans.spi.queries.FileBuiltQueryImplementation;
42
import org.netbeans.spi.queries.FileBuiltQueryImplementation;
41
import org.netbeans.spi.queries.SharabilityQueryImplementation;
43
import org.netbeans.spi.queries.SharabilityQueryImplementation;
42
import org.openide.ErrorManager;
44
import org.openide.ErrorManager;
Lines 469-474 Link Here
469
     */
471
     */
470
    public FileObject getProjectDirectory() {
472
    public FileObject getProjectDirectory() {
471
        return dir;
473
        return dir;
474
    }
475
    
476
    /**Notification that this project has been deleted.
477
     * See {@link org.netbeans.api.projects.ProjectState#notifyDeleted}.
478
     *
479
     * @since 1.7
480
     */
481
    public void notifyDeleted() {
482
        state.notifyDeleted();
483
    }
484
    
485
    /**Perform default delete operation. Gathers all necessary data, shows a confirmation
486
     * dialog and deletes the project (if confirmed by the user).
487
     *
488
     * @since 1.7
489
     *
490
     * @throws IllegalStateException if
491
     * {@link org.netbeans.api.projects.ProjectOperations.getDefault().isDeleteOperationSupported}
492
     * returns false for this project.
493
     */
494
    public void performDefaultDeleteOperation() throws IllegalStateException {
495
        Project p = AntBasedProjectFactorySingleton.getProjectFor(this);
496
        
497
        assert p != null;
498
        
499
        if (!ProjectOperations.getDefault().isDeleteOperationSupported(p)) {
500
            throw new IllegalStateException("Attempt to delete project that does not support deletion.");
501
        }
502
        
503
        DefaultAntProjectOperation.deleteProject(p);
472
    }
504
    }
473
    
505
    
474
    /**
506
    /**
(-)project/test/unit/src/org/netbeans/modules/project/ant/AntBasedProjectFactorySingletonTest.java (+123 lines)
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.project.ant;
15
16
import java.lang.reflect.Method;
17
import junit.framework.Test;
18
import junit.framework.TestSuite;
19
import org.netbeans.api.project.Project;
20
import org.netbeans.api.project.ProjectManager;
21
import org.netbeans.api.project.TestUtil;
22
import org.netbeans.junit.NbTestCase;
23
import org.netbeans.spi.project.support.ant.AntBasedProjectType;
24
import org.netbeans.spi.project.support.ant.AntBasedTestUtil;
25
import org.netbeans.spi.project.support.ant.AntProjectHelper;
26
import org.netbeans.spi.project.support.ant.AntProjectHelperTest;
27
import org.openide.filesystems.FileObject;
28
import org.openide.util.lookup.Lookups;
29
30
31
/**
32
 *
33
 * @author Jan Lahoda
34
 */
35
public class AntBasedProjectFactorySingletonTest extends NbTestCase {
36
    
37
    public AntBasedProjectFactorySingletonTest(String testName) {
38
        super(testName);
39
    }
40
41
    private FileObject scratch;
42
    private FileObject projdir;
43
    
44
    protected void setUp() throws Exception {
45
        scratch = TestUtil.makeScratchDir(this);
46
        projdir = scratch.createFolder("proj");
47
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/project.xml"), projdir, "nbproject/project.xml");
48
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/private.xml"), projdir, "nbproject/private/private.xml");
49
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/project.properties"), projdir, "nbproject/project.properties");
50
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/private.properties"), projdir, "nbproject/private/private.properties");
51
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/global.properties"), scratch, "userdir/build.properties");
52
        TestUtil.setLookup(new Object[] {
53
            AntBasedTestUtil.testAntBasedProjectType(),
54
        });
55
    }
56
57
    protected void tearDown() throws Exception {
58
    }
59
60
    public static Test suite() {
61
        TestSuite suite = new TestSuite(AntBasedProjectFactorySingletonTest.class);
62
        
63
        return suite;
64
    }
65
66
    /**Test for second part of #42738.
67
     */
68
    public void testAntBasedProjectTypesChanged() throws Exception {
69
        AntBasedProjectFactorySingleton factory = new AntBasedProjectFactorySingleton();
70
        AntBasedProjectType type1 = AntBasedTestUtil.testAntBasedProjectType();
71
        AntBasedProjectType type2 = AntBasedTestUtil.testAntBasedProjectType();
72
        
73
        TestUtil.setLookup(Lookups.fixed(new Object[] {
74
            factory,
75
            type1,
76
            type2,
77
        }));
78
        
79
        Method getAntBasedProjectTypeMethod = AntProjectHelper.class.getDeclaredMethod("getType", new Class[0]);
80
        
81
        getAntBasedProjectTypeMethod.setAccessible(true);
82
        
83
        Project p = ProjectManager.getDefault().findProject(projdir);
84
        AntProjectHelper helper = (AntProjectHelper) p.getLookup().lookup(AntProjectHelper.class);
85
        
86
        assertTrue(getAntBasedProjectTypeMethod.invoke(helper, null) == type2);
87
        
88
        TestUtil.setLookup(Lookups.fixed(new Object[] {
89
            factory,
90
            type1,
91
        }));
92
        
93
        p = ProjectManager.getDefault().findProject(projdir);
94
        helper = (AntProjectHelper) p.getLookup().lookup(AntProjectHelper.class);
95
        
96
        assertTrue(getAntBasedProjectTypeMethod.invoke(helper, null) == type1);
97
        
98
        TestUtil.setLookup(Lookups.fixed(new Object[] {
99
            factory,
100
            type2,
101
        }));
102
        
103
        p = ProjectManager.getDefault().findProject(projdir);
104
        helper = (AntProjectHelper) p.getLookup().lookup(AntProjectHelper.class);
105
        
106
        assertTrue(getAntBasedProjectTypeMethod.invoke(helper, null) == type2);
107
        
108
        TestUtil.setLookup(Lookups.fixed(new Object[] {
109
            factory,
110
        }));
111
        
112
        assertNull(ProjectManager.getDefault().findProject(projdir));
113
114
        TestUtil.setLookup(Lookups.fixed(new Object[] {
115
            factory,
116
            type1,
117
            type2,
118
        }));
119
        
120
        assertTrue(getAntBasedProjectTypeMethod.invoke(helper, null) == type2);
121
    }
122
    
123
}
(-)project/test/unit/src/org/netbeans/modules/project/ant/DefaultAntProjectOperationTest.java (+169 lines)
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.project.ant;
15
16
import java.io.File;
17
import java.util.Arrays;
18
import junit.framework.*;
19
import org.netbeans.api.progress.ProgressHandle;
20
import org.netbeans.api.progress.ProgressHandleFactory;
21
import org.netbeans.api.project.Project;
22
import org.netbeans.api.project.ProjectManager;
23
import org.netbeans.api.project.TestUtil;
24
import org.netbeans.junit.NbTestCase;
25
import org.netbeans.modules.project.ant.DefaultAntProjectOperation.UserInputHandler;
26
import org.netbeans.modules.project.ui.OpenProjectsTrampolineImpl;
27
import org.netbeans.spi.project.support.ant.AntBasedTestUtil;
28
import org.netbeans.spi.project.support.ant.AntProjectHelperTest;
29
import org.openide.filesystems.FileObject;
30
import org.openide.filesystems.FileUtil;
31
32
33
/**
34
 *
35
 * @author Jan Lahoda
36
 */
37
public class DefaultAntProjectOperationTest extends NbTestCase {
38
    
39
    public DefaultAntProjectOperationTest(String testName) {
40
        super(testName);
41
    }
42
43
    private FileObject scratch;
44
    private FileObject projdir;
45
    private Project prj;
46
    private File projectDirectory;
47
    
48
    private void createProject(FileObject projdir) throws Exception {
49
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/project.xml"), projdir, "nbproject/project.xml");
50
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/private.xml"), projdir, "nbproject/private/private.xml");
51
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/project.properties"), projdir, "nbproject/project.properties");
52
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/private.properties"), projdir, "nbproject/private/private.properties");
53
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/test.txt"), projdir, "src/test/test.txt");
54
        TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/global.properties"), scratch, "userdir/build.properties");
55
    }
56
    
57
    protected void setUp() throws Exception {
58
        scratch = TestUtil.makeScratchDir(this);
59
        projdir = scratch.createFolder("proj");
60
        
61
        createProject(projdir);
62
        
63
        TestUtil.setLookup(new Object[] {
64
            AntBasedTestUtil.testAntBasedProjectType(),
65
                    new OpenProjectsTrampolineImpl(),
66
        });
67
        
68
        prj = ProjectManager.getDefault().findProject(projdir);
69
        
70
        assertNotNull(prj);
71
        
72
        projectDirectory = FileUtil.toFile(projdir);
73
        
74
        assertNotNull(projectDirectory);
75
    }
76
77
    public void testDeleteProjectDeleteAll() throws Exception {
78
        TestUserInputHandler handler = new TestUserInputHandler(UserInputHandler.USER_OK_ALL);
79
        
80
        DefaultAntProjectOperation.deleteProject(prj, handler);
81
        
82
        assertTrue(handler.userConfirmationCalled);
83
        assertTrue(handler.enableData);
84
        assertTrue(handler.getProgressHandleCalled);
85
        assertTrue(handler.deleteCalled);
86
        
87
        assertFalse(projectDirectory.exists());
88
    }
89
90
    public void testDeleteProjectDeleteMetadata() throws Exception {
91
        TestUserInputHandler handler = new TestUserInputHandler(UserInputHandler.USER_OK_METADATA);
92
        
93
        DefaultAntProjectOperation.deleteProject(prj, handler);
94
        
95
        assertTrue(handler.userConfirmationCalled);
96
        assertTrue(handler.enableData);
97
        assertTrue(handler.getProgressHandleCalled);
98
        assertTrue(handler.deleteCalled);
99
        
100
        assertTrue(projectDirectory.exists());
101
        assertTrue(Arrays.equals(new String[] {"src"}, projectDirectory.list()));
102
    }
103
    
104
    public void testDeleteProjectDoNotDelete() throws Exception {
105
        TestUserInputHandler handler = new TestUserInputHandler(UserInputHandler.USER_CANCEL);
106
        
107
        DefaultAntProjectOperation.deleteProject(prj, handler);
108
        
109
        assertTrue(handler.userConfirmationCalled);
110
        assertTrue(handler.enableData);
111
        assertFalse(handler.getProgressHandleCalled);
112
        assertFalse(handler.deleteCalled);
113
        
114
        assertTrue(projectDirectory.exists());
115
        assertTrue(Arrays.equals(new String[] {"nbproject", "src"}, projectDirectory.list()));
116
    }
117
    
118
    public void testDeleteProjectNestedProject() throws Exception {
119
        FileObject projdir2 = projdir.createFolder("proj2");
120
        
121
        createProject(projdir2);
122
        
123
        TestUserInputHandler handler = new TestUserInputHandler(UserInputHandler.USER_OK_ALL);
124
        
125
        DefaultAntProjectOperation.deleteProject(prj, handler);
126
        
127
        assertTrue(handler.userConfirmationCalled);
128
        assertTrue(handler.enableData);
129
        assertTrue(handler.getProgressHandleCalled);
130
        assertTrue(handler.deleteCalled);
131
        
132
        assertTrue(projectDirectory.exists());
133
        assertTrue(Arrays.equals(new String[] {"proj2"}, projectDirectory.list()));
134
    }
135
    
136
    private static final class TestUserInputHandler implements UserInputHandler {
137
        
138
        private int answer;
139
        private ProgressHandle handle;
140
        
141
        private boolean userConfirmationCalled;
142
        private boolean enableData;
143
        private boolean getProgressHandleCalled;
144
        private boolean deleteCalled;
145
        
146
        public TestUserInputHandler(int answer) {
147
            this.answer = answer;
148
            this.handle = ProgressHandleFactory.createHandle("test");
149
        }
150
        
151
        public int userConfirmation(String displayName, String projectFolder, boolean enableData) {
152
            userConfirmationCalled = true;
153
            this.enableData = enableData;
154
            return answer;
155
        }
156
        
157
        public ProgressHandle getProgressHandle() {
158
            getProgressHandleCalled = true;
159
            return handle;
160
        }
161
        
162
        public void delete(Runnable r) {
163
            deleteCalled = true;
164
            r.run();
165
        }
166
        
167
    }
168
    
169
}
(-)project/test/unit/src/org/netbeans/spi/project/support/ant/AntBasedTestUtil.java (-1 / +42 lines)
Lines 7-13 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 *
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
13
Lines 29-34 Link Here
29
import java.net.URISyntaxException;
29
import java.net.URISyntaxException;
30
import java.net.URL;
30
import java.net.URL;
31
import java.util.ArrayList;
31
import java.util.ArrayList;
32
import java.util.Collections;
32
import java.util.HashMap;
33
import java.util.HashMap;
33
import java.util.HashSet;
34
import java.util.HashSet;
34
import java.util.List;
35
import java.util.List;
Lines 50-55 Link Here
50
import org.netbeans.spi.project.AuxiliaryConfiguration;
51
import org.netbeans.spi.project.AuxiliaryConfiguration;
51
import org.netbeans.api.project.ProjectInformation;
52
import org.netbeans.api.project.ProjectInformation;
52
import org.netbeans.api.project.ProjectManager;
53
import org.netbeans.api.project.ProjectManager;
54
import org.netbeans.spi.project.ProjectOperationsImplementation;
55
import org.netbeans.spi.project.ProjectOperationsImplementation.DeleteOperationImplementation;
53
import org.netbeans.spi.project.ant.AntArtifactProvider;
56
import org.netbeans.spi.project.ant.AntArtifactProvider;
54
import org.netbeans.spi.queries.CollocationQueryImplementation;
57
import org.netbeans.spi.queries.CollocationQueryImplementation;
55
import org.openide.filesystems.FileObject;
58
import org.openide.filesystems.FileObject;
Lines 160-165 Link Here
160
                    }
163
                    }
161
                },
164
                },
162
                "hello",
165
                "hello",
166
                new DeleteProjectOperationImpl(this),
163
            });
167
            });
164
        }
168
        }
165
        
169
        
Lines 238-243 Link Here
238
            
242
            
239
            public void setBuildArtifacts(AntArtifact[] arts) {
243
            public void setBuildArtifacts(AntArtifact[] arts) {
240
                this.arts = arts;
244
                this.arts = arts;
245
            }
246
            
247
        }
248
        
249
        public final class DeleteProjectOperationImpl implements DeleteOperationImplementation {
250
            
251
            private boolean wasCleaned = false;
252
            private boolean wasNotified = false;
253
            
254
            private TestAntBasedProject project;
255
            
256
            public DeleteProjectOperationImpl(TestAntBasedProject project) {
257
                this.project = project;
258
            }
259
            
260
            public List getMetadataFiles() {
261
                return Collections.singletonList(project.getProjectDirectory().getFileObject("nbproject"));
262
            }
263
            
264
            public List getDataFiles() {
265
                return Collections.singletonList(project.getProjectDirectory().getFileObject("src"));
266
            }
267
            
268
            public synchronized boolean getWasCleaned() {
269
                return wasCleaned;
270
            }
271
            
272
            public synchronized void performClean() throws IOException {
273
                wasCleaned = true;
274
            }
275
            
276
            public synchronized boolean getWasNotified() {
277
                return wasNotified;
278
            }
279
            
280
            public synchronized void notifyDeleted() throws IOException {
281
                wasNotified = true;
241
            }
282
            }
242
            
283
            
243
        }
284
        }

Return to bug 58866