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 154427
Collapse All | Expand All

(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/FeatureProjectFactory.java (-7 / +1 lines)
Lines 115-121 Link Here
115
        @Override
115
        @Override
116
        protected void projectOpened() {
116
        protected void projectOpened() {
117
            RequestProcessor.getDefault ().post (this, 0, Thread.NORM_PRIORITY).waitFinished ();
117
            RequestProcessor.getDefault ().post (this, 0, Thread.NORM_PRIORITY).waitFinished ();
118
            ProjectOpenedHook hook;
119
            if (success) {
118
            if (success) {
120
                try {
119
                try {
121
                    state.notifyDeleted();
120
                    state.notifyDeleted();
Lines 124-135 Link Here
124
                        throw new IllegalStateException("New project shall be found! " + p); // NOI18N
123
                        throw new IllegalStateException("New project shall be found! " + p); // NOI18N
125
                    }
124
                    }
126
                    delegate.associate(p);
125
                    delegate.associate(p);
127
126
                } catch (IOException ex) {
128
                    hook = p.getLookup().lookup(ProjectOpenedHook.class);
129
                    Method m = ProjectOpenedHook.class.getDeclaredMethod("projectOpened"); // NOI18N
130
                    m.setAccessible(true);
131
                    m.invoke(hook);
132
                } catch (Exception ex) {
133
                    Exceptions.printStackTrace(ex);
127
                    Exceptions.printStackTrace(ex);
134
                }
128
                }
135
            }
129
            }
(-)a/projectui/src/org/netbeans/modules/project/ui/OpenProjectList.java (-16 / +29 lines)
Lines 60-65 Link Here
60
import java.util.Collections;
60
import java.util.Collections;
61
import java.util.Comparator;
61
import java.util.Comparator;
62
import java.util.HashMap;
62
import java.util.HashMap;
63
import java.util.HashSet;
63
import java.util.Iterator;
64
import java.util.Iterator;
64
import java.util.LinkedHashSet;
65
import java.util.LinkedHashSet;
65
import java.util.LinkedList;
66
import java.util.LinkedList;
Lines 1005-1026 Link Here
1005
    
1006
    
1006
    private static boolean notifyOpened(Project p) {
1007
    private static boolean notifyOpened(Project p) {
1007
        boolean ok = true;
1008
        boolean ok = true;
1008
        for (Iterator i = p.getLookup().lookupAll(ProjectOpenedHook.class).iterator(); i.hasNext(); ) {
1009
        Set<ProjectOpenedHook> notified = new HashSet<ProjectOpenedHook>();
1009
            ProjectOpenedHook hook = (ProjectOpenedHook) i.next();
1010
        for (;;) {
1010
            
1011
            int cnt = 0;
1011
            try {
1012
            for (Iterator i = p.getLookup().lookupAll(ProjectOpenedHook.class).iterator(); i.hasNext(); ) {
1012
                ProjectOpenedTrampoline.DEFAULT.projectOpened(hook);
1013
                ProjectOpenedHook hook = (ProjectOpenedHook) i.next();
1013
            } catch (RuntimeException e) {
1014
                if (!notified.add(hook)) {
1014
                LOGGER.log(Level.WARNING, null, e);
1015
                    continue;
1015
                // Do not try to call its close hook if its open hook already failed:
1016
                }
1016
                INSTANCE.openProjects.remove(p);
1017
                cnt++;
1017
                INSTANCE.removeModuleInfo(p);
1018
1018
                ok = false;
1019
                try {
1019
            } catch (Error e) {
1020
                    ProjectOpenedTrampoline.DEFAULT.projectOpened(hook);
1020
                LOGGER.log(Level.WARNING, null, e);
1021
                } catch (RuntimeException e) {
1021
                INSTANCE.openProjects.remove(p);
1022
                    LOGGER.log(Level.WARNING, null, e);
1022
                INSTANCE.removeModuleInfo(p);
1023
                    // Do not try to call its close hook if its open hook already failed:
1023
                ok = false;
1024
                    INSTANCE.openProjects.remove(p);
1025
                    INSTANCE.removeModuleInfo(p);
1026
                    ok = false;
1027
                } catch (Error e) {
1028
                    LOGGER.log(Level.WARNING, null, e);
1029
                    INSTANCE.openProjects.remove(p);
1030
                    INSTANCE.removeModuleInfo(p);
1031
                    ok = false;
1032
                }
1033
            }
1034
1035
            if (cnt == 0) {
1036
                break;
1024
            }
1037
            }
1025
        }
1038
        }
1026
        return ok;
1039
        return ok;
(-)6c6e7bf5b156 (+122 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2007 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.project.ui;
41
42
import org.netbeans.api.project.Project;
43
import org.netbeans.api.project.ProjectManager;
44
import org.netbeans.junit.MockServices;
45
import org.netbeans.junit.NbTestCase;
46
import org.netbeans.modules.project.ui.actions.TestSupport;
47
import org.netbeans.modules.project.ui.actions.TestSupport.TestProject;
48
import org.netbeans.spi.project.ui.ProjectOpenedHook;
49
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileUtil;
51
import org.openide.util.Lookup;
52
import org.openide.util.lookup.Lookups;
53
54
/** 
55
 *
56
 * @author Jaroslav Tulach
57
 */
58
public class OpenProjectHookAddedWhileOpenTest extends NbTestCase {
59
    private TestProjectOpenedHookImpl hook2;
60
    private TestProjectOpenedHookImpl hook1;
61
    private TestProject project;
62
    public OpenProjectHookAddedWhileOpenTest(String testName) {
63
        super(testName);
64
    }            
65
66
    @Override
67
    protected void setUp() throws Exception {
68
        clearWorkDir();
69
        
70
        MockServices.setServices(TestSupport.TestProjectFactory.class);
71
        
72
        FileObject workDir = FileUtil.toFileObject(getWorkDir());
73
        assertNotNull(workDir);
74
        
75
        FileObject prj = TestSupport.createTestProject(workDir, "prj0");
76
        project = (TestProject)ProjectManager.getDefault ().findProject (prj);
77
        assertNotNull("Project found", project);
78
79
        hook1 = new TestProjectOpenedHookImpl(project);
80
        hook2 = new TestProjectOpenedHookImpl(project);
81
82
        Lookup initialLookup = Lookups.singleton(hook1);
83
        hook1.newLookup = Lookups.fixed(hook1, hook2);
84
85
        project.setLookup(initialLookup);
86
    }
87
88
    public void testBehaviourOfProjectsLogicNode() throws Exception {
89
        OpenProjectList.getDefault().open(project);
90
91
        assertEquals("First hook opened once", 1, hook1.cnt);
92
        assertEquals("Second hook opened once", 1, hook2.cnt);
93
94
        OpenProjectList.getDefault().close(new Project[] { project }, true);
95
96
        assertEquals("First hook closed once", 1, hook1.close);
97
        assertEquals("Second hook closed once", 1, hook2.close);
98
    }
99
100
    private static class TestProjectOpenedHookImpl extends ProjectOpenedHook {
101
        private final TestProject project;
102
        Lookup newLookup;
103
        int cnt;
104
        int close;
105
        
106
        public TestProjectOpenedHookImpl(TestProject p) {
107
            this.project = p;
108
        }
109
        
110
        protected void projectClosed() {
111
            close++;
112
        }
113
        
114
        protected void projectOpened() {
115
            cnt++;
116
            if (newLookup != null) {
117
                project.setLookup(newLookup);
118
            }
119
        }
120
        
121
    }
122
}

Return to bug 154427