Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 201796
Collapse All | Expand All

(-)core.netigso/arch.xml (-1 / +6 lines)
 Lines 620-626    Link Here 
620
-->
620
-->
621
 <answer id="exec-property">
621
 <answer id="exec-property">
622
  <p>
622
  <p>
623
   XXX no answer for exec-property
623
   <api category="devel" group="branding" name="org.netbeans.core.netigso.FRAMEWORK_START_LEVEL"
624
   type="export">
625
   One can influence the initial OSGi framework start level by rebranding
626
   the <code>FRAMEWORK_START_LEVEL</code> key in <code>org/netbeans/core/netigso/Bundle.properties</code>.
627
   By default the key is empty, which means no change to default OSGi start level of <code>1</code>.
628
   </api>
624
  </p>
629
  </p>
625
 </answer>
630
 </answer>
626
631
(-)core.netigso/manifest.mf (-1 / +1 lines)
 Lines 2-8    Link Here 
2
OpenIDE-Module: org.netbeans.core.netigso
2
OpenIDE-Module: org.netbeans.core.netigso
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/netigso/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/netigso/Bundle.properties
4
OpenIDE-Module-Provides: org.netbeans.NetigsoFramework
4
OpenIDE-Module-Provides: org.netbeans.NetigsoFramework
5
OpenIDE-Module-Specification-Version: 1.10
5
OpenIDE-Module-Specification-Version: 1.11
6
OpenIDE-Module-Needs: org.osgi.framework.launch.FrameworkFactory
6
OpenIDE-Module-Needs: org.osgi.framework.launch.FrameworkFactory
7
AutoUpdate-Essential-Module: true
7
AutoUpdate-Essential-Module: true
8
8
(-)core.netigso/nbproject/project.xml (-1 / +1 lines)
 Lines 55-61    Link Here 
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>1</release-version>
57
                        <release-version>1</release-version>
58
                        <specification-version>2.37</specification-version>
58
                        <specification-version>2.43</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
(-)core.netigso/src/org/netbeans/core/netigso/Bundle.properties (+1 lines)
 Lines 40-42    Link Here 
40
# Version 2 license, then the option applies only if the new code is
40
# Version 2 license, then the option applies only if the new code is
41
# made subject to such option by the copyright holder.
41
# made subject to such option by the copyright holder.
42
OpenIDE-Module-Name=NetBeans OSGi Integration
42
OpenIDE-Module-Name=NetBeans OSGi Integration
43
FRAMEWORK_START_LEVEL=
(-)core.netigso/src/org/netbeans/core/netigso/Netigso.java (+43 lines)
 Lines 69-74    Link Here 
69
import org.openide.modules.ModuleInfo;
69
import org.openide.modules.ModuleInfo;
70
import org.openide.modules.Places;
70
import org.openide.modules.Places;
71
import org.openide.util.Lookup;
71
import org.openide.util.Lookup;
72
import org.openide.util.NbBundle;
72
import org.openide.util.lookup.ServiceProvider;
73
import org.openide.util.lookup.ServiceProvider;
73
import org.openide.util.lookup.ServiceProviders;
74
import org.openide.util.lookup.ServiceProviders;
74
import org.osgi.framework.Bundle;
75
import org.osgi.framework.Bundle;
 Lines 82-87    Link Here 
82
import org.osgi.framework.launch.FrameworkFactory;
83
import org.osgi.framework.launch.FrameworkFactory;
83
import org.osgi.service.packageadmin.PackageAdmin;
84
import org.osgi.service.packageadmin.PackageAdmin;
84
import org.osgi.service.packageadmin.RequiredBundle;
85
import org.osgi.service.packageadmin.RequiredBundle;
86
import org.osgi.service.startlevel.StartLevel;
85
87
86
/**
88
/**
87
 *
89
 *
 Lines 162-167    Link Here 
162
    @Override
164
    @Override
163
    protected void start() {
165
    protected void start() {
164
        try {
166
        try {
167
            String startLevel = NbBundle.getMessage(Netigso.class, "FRAMEWORK_START_LEVEL");
168
            if (startLevel.length() > 0) {
169
                setFrameworkStartLevel(framework.getBundleContext(), Integer.parseInt(startLevel));
170
            }
165
            framework.start();
171
            framework.start();
166
        } catch (BundleException ex) {
172
        } catch (BundleException ex) {
167
            LOG.log(Level.WARNING, "Cannot start Container" + framework, ex);
173
            LOG.log(Level.WARNING, "Cannot start Container" + framework, ex);
 Lines 383-388    Link Here 
383
                    }
389
                    }
384
                    LOG.log(Level.FINE, "Installing bundle {0}", loc);
390
                    LOG.log(Level.FINE, "Installing bundle {0}", loc);
385
                    b = bc.installBundle(loc);
391
                    b = bc.installBundle(loc);
392
                    int startLevel = m.getStartLevel();
393
                    if (startLevel > 0) {
394
                        setBundleStartLevel(bc, b, startLevel);
395
                    }
386
                }
396
                }
387
            } else {
397
            } else {
388
                InputStream is = fakeBundle(m);
398
                InputStream is = fakeBundle(m);
 Lines 403-408    Link Here 
403
            throw new IOException(ex);
413
            throw new IOException(ex);
404
        }
414
        }
405
    }
415
    }
416
417
    private void setFrameworkStartLevel(BundleContext bc, int startLevel) {
418
        ServiceReference sr = bc.getServiceReference("org.osgi.service.startlevel.StartLevel"); // NOI18N
419
        StartLevel level = null;
420
        if (sr != null) {
421
            level = (StartLevel) bc.getService(sr);
422
            if (level != null) {
423
                level.setStartLevel(startLevel);
424
                return;
425
            }
426
        }
427
        LOG.log(
428
            Level.WARNING, 
429
            "Cannot set framewok startLevel to {1} reference: {2} level {3}", 
430
            new Object[]{null, startLevel, sr, level}
431
        );
432
    }
433
    private void setBundleStartLevel(BundleContext bc, Bundle b, int startLevel) {
434
        ServiceReference sr = bc.getServiceReference("org.osgi.service.startlevel.StartLevel"); // NOI18N
435
        StartLevel level = null;
436
        if (sr != null) {
437
            level = (StartLevel) bc.getService(sr);
438
            if (level != null) {
439
                level.setBundleStartLevel(b, startLevel);
440
                return;
441
            }
442
        }
443
        LOG.log(
444
            Level.WARNING, 
445
            "Cannot set startLevel for {0} to {1} reference: {2} level {3}", 
446
            new Object[]{b.getSymbolicName(), startLevel, sr, level}
447
        );
448
    }
406
    
449
    
407
    private static String threeDotsWithMajor(String version, String withMajor) {
450
    private static String threeDotsWithMajor(String version, String withMajor) {
408
        int indx = withMajor.indexOf('/');
451
        int indx = withMajor.indexOf('/');
(-)core.netigso/test/unit/src/org/netbeans/core/netigso/Bundle_te.properties (+41 lines)
Added Link Here 
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 2011 Oracle and/or its affiliates. All rights reserved.
4
#
5
# Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
# Other names may be trademarks of their respective owners.
7
#
8
# The contents of this file are subject to the terms of either the GNU
9
# General Public License Version 2 only ("GPL") or the Common
10
# Development and Distribution License("CDDL") (collectively, the
11
# "License"). You may not use this file except in compliance with the
12
# License. You can obtain a copy of the License at
13
# http://www.netbeans.org/cddl-gplv2.html
14
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
15
# specific language governing permissions and limitations under the
16
# License.  When distributing the software, include this License Header
17
# Notice in each file and include the License file at
18
# nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
19
# particular file as subject to the "Classpath" exception as provided
20
# by Oracle in the GPL Version 2 section of the License file that
21
# accompanied this code. If applicable, add the following below the
22
# License Header, with the fields enclosed by brackets [] replaced by
23
# your own identifying information:
24
# "Portions Copyrighted [year] [name of copyright owner]"
25
#
26
# If you wish your version of this file to be governed by only the CDDL
27
# or only the GPL Version 2, indicate your decision by adding
28
# "[Contributor] elects to include this software in this distribution
29
# under the [CDDL or GPL Version 2] license." If you do not indicate a
30
# single choice of license, a recipient has the option to distribute
31
# your version of this file under either the CDDL, the GPL Version 2 or
32
# to extend the choice of license to its licensees as provided above.
33
# However, if you add GPL Version 2 code and therefore, elected the GPL
34
# Version 2 license, then the option applies only if the new code is
35
# made subject to such option by the copyright holder.
36
#
37
# Contributor(s):
38
#
39
# Portions Copyrighted 2011 Sun Microsystems, Inc.
40
41
FRAMEWORK_START_LEVEL=20
(-)core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoDefaultStartLevelTest.java (+111 lines)
Added Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.core.netigso;
46
47
import java.io.File;
48
import java.io.IOException;
49
import java.util.Locale;
50
import org.netbeans.Module;
51
import org.netbeans.ModuleManager;
52
import org.netbeans.SetupHid;
53
import org.netbeans.core.startup.Main;
54
import org.netbeans.core.startup.ModuleSystem;
55
import org.osgi.framework.ServiceReference;
56
import org.osgi.framework.launch.Framework;
57
import org.osgi.service.startlevel.StartLevel;
58
59
/**
60
 * Do we correctly call the BundleActivators?
61
 *
62
 * @author Jaroslav Tulach
63
 */
64
public class NetigsoDefaultStartLevelTest extends SetupHid {
65
    private static Module m1;
66
    private static ModuleManager mgr;
67
    private int cnt;
68
    private File simpleModule;
69
70
    public NetigsoDefaultStartLevelTest(String name) {
71
        super(name);
72
    }
73
74
    protected @Override void setUp() throws Exception {
75
        Locale.setDefault(new Locale("te", "ST"));
76
        clearWorkDir();
77
        File ud = new File(getWorkDir(), "ud");
78
        ud.mkdirs();
79
        System.setProperty("netbeans.user", ud.getPath());
80
        
81
        data = new File(getDataDir(), "jars");
82
        jars = new File(getWorkDir(), "space in path");
83
        jars.mkdirs();
84
        simpleModule = createTestJAR("activate", null);
85
    }
86
87
    public void testActivation() throws Exception {
88
        ModuleSystem ms = Main.getModuleSystem();
89
        mgr = ms.getManager();
90
        mgr.mutexPrivileged().enterWriteAccess();
91
        try {
92
            m1 = mgr.createBundle(simpleModule, null, false, false, false, 10);
93
            mgr.enable(m1);
94
95
            Class<?> main = m1.getClassLoader().loadClass("org.activate.Main");
96
            Object s = main.getField("start").get(null);
97
            s = main.getField("start").get(null);
98
            assertNotNull("Bundle started as default start level is 20, its context provided", s);
99
100
            mgr.disable(m1);
101
102
            Object e = main.getField("stop").get(null);
103
            assertNotNull("Bundle stopped, its context provided", e);
104
        } finally {
105
            mgr.mutexPrivileged().exitWriteAccess();
106
        }
107
    }
108
    private File createTestJAR(String name, String srcdir, File... classpath) throws IOException {
109
        return createTestJAR(data, jars, name, srcdir, classpath);
110
    }
111
}
(-)core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoServicesTest.java (-5 / +14 lines)
 Lines 44-50    Link Here 
44
44
45
package org.netbeans.core.netigso;
45
package org.netbeans.core.netigso;
46
46
47
import org.netbeans.core.startup.*;
48
import java.io.ByteArrayInputStream;
47
import java.io.ByteArrayInputStream;
49
import java.io.File;
48
import java.io.File;
50
import java.io.FileOutputStream;
49
import java.io.FileOutputStream;
 Lines 62-67    Link Here 
62
import org.netbeans.ModuleManager;
61
import org.netbeans.ModuleManager;
63
import org.netbeans.NetigsoFramework;
62
import org.netbeans.NetigsoFramework;
64
import org.netbeans.SetupHid;
63
import org.netbeans.SetupHid;
64
import org.netbeans.core.startup.Main;
65
import org.netbeans.core.startup.ModuleSystem;
65
import org.openide.filesystems.FileObject;
66
import org.openide.filesystems.FileObject;
66
import org.openide.filesystems.FileUtil;
67
import org.openide.filesystems.FileUtil;
67
import org.openide.util.Lookup;
68
import org.openide.util.Lookup;
 Lines 70-75    Link Here 
70
import org.openide.util.LookupListener;
71
import org.openide.util.LookupListener;
71
import org.osgi.framework.Bundle;
72
import org.osgi.framework.Bundle;
72
import org.osgi.framework.ServiceRegistration;
73
import org.osgi.framework.ServiceRegistration;
74
import org.osgi.framework.launch.Framework;
73
75
74
/**
76
/**
75
 * How does OSGi integration deals with layer registration?
77
 * How does OSGi integration deals with layer registration?
 Lines 79-84    Link Here 
79
public class NetigsoServicesTest extends SetupHid implements LookupListener {
81
public class NetigsoServicesTest extends SetupHid implements LookupListener {
80
    private static Module m1;
82
    private static Module m1;
81
    private static ModuleManager mgr;
83
    private static ModuleManager mgr;
84
82
    private int cnt;
85
    private int cnt;
83
86
84
    public NetigsoServicesTest(String name) {
87
    public NetigsoServicesTest(String name) {
 Lines 166-175    Link Here 
166
169
167
170
168
    static Bundle findBundle(String bsn) throws Exception {
171
    static Bundle findBundle(String bsn) throws Exception {
169
        Object o = Lookup.getDefault().lookup(NetigsoFramework.class);
172
        Bundle[] arr = findFramework().getBundleContext().getBundles();
170
        assertEquals("The right class", Netigso.class, o.getClass());
171
        Netigso f = (Netigso)o;
172
        Bundle[] arr = f.getFramework().getBundleContext().getBundles();
173
        for (Bundle b : arr) {
173
        for (Bundle b : arr) {
174
            if (bsn.equals(b.getSymbolicName())) {
174
            if (bsn.equals(b.getSymbolicName())) {
175
                return b;
175
                return b;
 Lines 202-208    Link Here 
202
        return f;
202
        return f;
203
    }
203
    }
204
204
205
    @Override
205
    public void resultChanged(LookupEvent ev) {
206
    public void resultChanged(LookupEvent ev) {
206
        cnt++;
207
        cnt++;
207
    }
208
    }
209
210
    static Framework findFramework() {
211
        Object o = Lookup.getDefault().lookup(NetigsoFramework.class);
212
        assertEquals("The right class", Netigso.class, o.getClass());
213
        Netigso f = (Netigso)o;
214
        final Framework frame = f.getFramework();
215
        return frame;
216
    }
208
}
217
}
(-)core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoStartLevelTest.java (+147 lines)
Added Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.core.netigso;
46
47
import java.io.File;
48
import java.io.IOException;
49
import java.util.Locale;
50
import org.netbeans.Module;
51
import org.netbeans.ModuleManager;
52
import org.netbeans.SetupHid;
53
import org.netbeans.core.startup.Main;
54
import org.netbeans.core.startup.ModuleSystem;
55
import org.osgi.framework.BundleContext;
56
import org.osgi.framework.FrameworkEvent;
57
import org.osgi.framework.FrameworkListener;
58
import org.osgi.framework.ServiceReference;
59
import org.osgi.framework.launch.Framework;
60
import org.osgi.service.startlevel.StartLevel;
61
62
/**
63
 * Do we correctly use start levels?
64
 *
65
 * @author Jaroslav Tulach
66
 */
67
public class NetigsoStartLevelTest extends SetupHid 
68
implements FrameworkListener {
69
    private static Module m1;
70
    private static ModuleManager mgr;
71
    private int cnt;
72
    private File simpleModule;
73
    private boolean levelChanged;
74
75
    public NetigsoStartLevelTest(String name) {
76
        super(name);
77
    }
78
79
    protected @Override void setUp() throws Exception {
80
        Locale.setDefault(Locale.US);
81
        clearWorkDir();
82
        File ud = new File(getWorkDir(), "ud");
83
        ud.mkdirs();
84
        System.setProperty("netbeans.user", ud.getPath());
85
        
86
        data = new File(getDataDir(), "jars");
87
        jars = new File(getWorkDir(), "space in path");
88
        jars.mkdirs();
89
        simpleModule = createTestJAR("activate", null);
90
    }
91
92
    public void testActivation() throws Exception {
93
        ModuleSystem ms = Main.getModuleSystem();
94
        mgr = ms.getManager();
95
        mgr.mutexPrivileged().enterWriteAccess();
96
        try {
97
            m1 = mgr.createBundle(simpleModule, null, false, false, false, 10);
98
            mgr.enable(m1);
99
        } finally {
100
            mgr.mutexPrivileged().exitWriteAccess();
101
        }
102
103
        Class<?> main = m1.getClassLoader().loadClass("org.activate.Main");
104
        Object s = main.getField("start").get(null);
105
        assertNull("Not started yet", s);
106
107
        Framework f = NetigsoServicesTest.findFramework();
108
        final BundleContext fc = f.getBundleContext();
109
        fc.addFrameworkListener(this);
110
        ServiceReference sr = fc.getServiceReference(StartLevel.class.getName());
111
        assertNotNull("Start level service found", sr);
112
        StartLevel level = (StartLevel) fc.getService(sr);
113
        assertNotNull("Start level found", level);
114
        level.setStartLevel(10);
115
        waitLevelChanged();
116
            
117
        s = main.getField("start").get(null);
118
        assertNotNull("Bundle started, its context provided", s);
119
120
        mgr.mutexPrivileged().enterWriteAccess();
121
        try {
122
            mgr.disable(m1);
123
124
            Object e = main.getField("stop").get(null);
125
            assertNotNull("Bundle stopped, its context provided", e);
126
        } finally {
127
            mgr.mutexPrivileged().exitWriteAccess();
128
        }
129
    }
130
    private File createTestJAR(String name, String srcdir, File... classpath) throws IOException {
131
        return createTestJAR(data, jars, name, srcdir, classpath);
132
    }
133
134
    @Override
135
    public synchronized void frameworkEvent(FrameworkEvent fe) {
136
        if (fe.getType() == FrameworkEvent.STARTLEVEL_CHANGED) {
137
            levelChanged = true;
138
            notifyAll();
139
        }
140
    }
141
    
142
    private synchronized void waitLevelChanged() throws InterruptedException {
143
        while (!levelChanged) {
144
            wait();
145
        }
146
    }
147
}
(-)core.startup/src/org/netbeans/core/startup/ModuleList.java (-12 / +34 lines)
 Lines 93-99    Link Here 
93
import org.openide.modules.Dependency;
93
import org.openide.modules.Dependency;
94
import org.openide.modules.InstalledFileLocator;
94
import org.openide.modules.InstalledFileLocator;
95
import org.openide.modules.SpecificationVersion;
95
import org.openide.modules.SpecificationVersion;
96
import org.openide.util.Exceptions;
97
import org.openide.util.Parameters;
96
import org.openide.util.Parameters;
98
import org.openide.util.RequestProcessor;
97
import org.openide.util.RequestProcessor;
99
import org.openide.util.Utilities;
98
import org.openide.util.Utilities;
 Lines 164-170    Link Here 
164
     * enable as needed. All discovered modules are returned.
163
     * enable as needed. All discovered modules are returned.
165
     * Write mutex only.
164
     * Write mutex only.
166
     */
165
     */
167
    public Set readInitial() {
166
    public Set<Module> readInitial() {
168
        ev.log(Events.START_READ);
167
        ev.log(Events.START_READ);
169
        final Set<Module> read = new HashSet<Module>();
168
        final Set<Module> read = new HashSet<Module>();
170
        try {
169
        try {
 Lines 175-180    Link Here 
175
        return read;
174
        return read;
176
    }
175
    }
177
    
176
    
177
    final Module createModule(
178
        File jarFile, ModuleHistory hist, boolean reloadable, boolean autoload, 
179
        boolean eager, Integer startLevel
180
    ) throws IOException {
181
        Module m;
182
        try {
183
            if (startLevel != null) {
184
                m = mgr.createBundle(jarFile, hist, reloadable, autoload, eager, startLevel);
185
            } else {
186
                m = mgr.create(jarFile, hist, reloadable, autoload, eager);
187
            }
188
        } catch (DuplicateException dupe) {
189
            // XXX should this be tolerated somehow? In case the original is
190
            // in fact scheduled for deletion anyway?
191
            throw new IOException(dupe);
192
        }
193
        return m;
194
    }
195
    
178
    /**
196
    /**
179
     * Try to find a module JAR by an XML-supplied name.
197
     * Try to find a module JAR by an XML-supplied name.
180
     * @param jar the JAR name (relative to an install dir, or a full path)
198
     * @param jar the JAR name (relative to an install dir, or a full path)
 Lines 427-432    Link Here 
427
                   ) {
445
                   ) {
428
            return Boolean.valueOf(v);
446
            return Boolean.valueOf(v);
429
        } else {
447
        } else {
448
            if (k == "startlevel") { // NOI18N 
449
                return Integer.valueOf(v);
450
            }
430
            // Other properties are of type String.
451
            // Other properties are of type String.
431
            // Intern the smaller ones which are likely to be repeated somewhere.
452
            // Intern the smaller ones which are likely to be repeated somewhere.
432
            if (v.length() < 100) v = v.intern();
453
            if (v.length() < 100) v = v.intern();
 Lines 657-665    Link Here 
657
        Stamps.getModulesJARs().scheduleSave(this, "all-modules.dat", false);
678
        Stamps.getModulesJARs().scheduleSave(this, "all-modules.dat", false);
658
    }
679
    }
659
    
680
    
681
    @Override
660
    public void cacheReady() {
682
    public void cacheReady() {
661
    }
683
    }
662
684
685
    @Override
663
    public void flushCaches(DataOutputStream os) throws IOException {
686
    public void flushCaches(DataOutputStream os) throws IOException {
664
        ObjectOutputStream oss = new ObjectOutputStream(os);
687
        ObjectOutputStream oss = new ObjectOutputStream(os);
665
        for (Module m : mgr.getModules()) {
688
        for (Module m : mgr.getModules()) {
 Lines 957-962    Link Here 
957
        p.put("autoload", m.isAutoload()); // NOI18N
980
        p.put("autoload", m.isAutoload()); // NOI18N
958
        p.put("eager", m.isEager()); // NOI18N
981
        p.put("eager", m.isEager()); // NOI18N
959
        p.put("reloadable", m.isReloadable()); // NOI18N
982
        p.put("reloadable", m.isReloadable()); // NOI18N
983
        if (m.getStartLevel() > 0) {
984
            p.put("startlevel", m.getStartLevel()); // NOI18N
985
        }
960
        if (m.getHistory() instanceof ModuleHistory) {
986
        if (m.getHistory() instanceof ModuleHistory) {
961
            ModuleHistory hist = (ModuleHistory) m.getHistory();
987
            ModuleHistory hist = (ModuleHistory) m.getHistory();
962
            p.put("jar", hist.getJar()); // NOI18N
988
            p.put("jar", hist.getJar()); // NOI18N
 Lines 1087-1093    Link Here 
1087
            fileDeleted0(ev.getName(), ev.getExt()/*, ev.getTime()*/);
1113
            fileDeleted0(ev.getName(), ev.getExt()/*, ev.getTime()*/);
1088
            fileCreated0(fo.getName(), fo.getExt()/*, ev.getTime()*/);
1114
            fileCreated0(fo.getName(), fo.getExt()/*, ev.getTime()*/);
1089
        }
1115
        }
1090
        
1116
1091
        private void fileCreated0(String name, String ext/*, long time*/) {
1117
        private void fileCreated0(String name, String ext/*, long time*/) {
1092
            if ("xml".equals(ext)) { // NOI18N
1118
            if ("xml".equals(ext)) { // NOI18N
1093
                String codenamebase = name.replace('-', '.');
1119
                String codenamebase = name.replace('-', '.');
 Lines 1340-1353    Link Here 
1340
                    boolean autoload = (autoloadB != null ? autoloadB.booleanValue() : false);
1366
                    boolean autoload = (autoloadB != null ? autoloadB.booleanValue() : false);
1341
                    Boolean eagerB = (Boolean)props.get("eager"); // NOI18N
1367
                    Boolean eagerB = (Boolean)props.get("eager"); // NOI18N
1342
                    boolean eager = (eagerB != null ? eagerB.booleanValue() : false);
1368
                    boolean eager = (eagerB != null ? eagerB.booleanValue() : false);
1343
                    Module m;
1369
                    Integer startLevel = (Integer)props.get("startlevel"); // NOI18N
1344
                    try {
1370
                    ModuleHistory hist = new ModuleHistory(jar, "created from " + xmlfile);
1345
                        m = mgr.create(jarFile, new ModuleHistory(jar, "created from " + xmlfile), reloadable, autoload, eager);
1371
                    Module m = createModule(jarFile, hist, reloadable, autoload, eager, startLevel);
1346
                    } catch (DuplicateException dupe) {
1347
                        // XXX should this be tolerated somehow? In case the original is
1348
                        // in fact scheduled for deletion anyway?
1349
                        throw (IOException) new IOException(dupe.toString()).initCause(dupe);
1350
                    }
1351
                    m.addPropertyChangeListener(this);
1372
                    m.addPropertyChangeListener(this);
1352
                    // Mark the status as disabled for the moment, so in step 3 it will be turned on
1373
                    // Mark the status as disabled for the moment, so in step 3 it will be turned on
1353
                    // if in dirtyprops it was marked enabled.
1374
                    // if in dirtyprops it was marked enabled.
 Lines 1641-1647    Link Here 
1641
                    Boolean eagerB = (Boolean) props.get("eager"); // NOI18N
1662
                    Boolean eagerB = (Boolean) props.get("eager"); // NOI18N
1642
                    boolean eager = eagerB != null ? eagerB.booleanValue() : false;
1663
                    boolean eager = eagerB != null ? eagerB.booleanValue() : false;
1643
                    NbInstaller.register(name, props.get("deps")); // NOI18N
1664
                    NbInstaller.register(name, props.get("deps")); // NOI18N
1644
                    Module m = mgr.create(jarFile, history, reloadable, autoload, eager);
1665
                    Integer startLevel = (Integer)props.get("startlevel"); // NOI18N
1666
                    Module m = createModule(jarFile, history, reloadable, autoload, eager, startLevel);
1645
                    NbInstaller.register(null, null);
1667
                    NbInstaller.register(null, null);
1646
                    read.add(m);
1668
                    read.add(m);
1647
                    DiskStatus status = new DiskStatus();
1669
                    DiskStatus status = new DiskStatus();
(-)core.startup/test/unit/src/org/netbeans/core/startup/ModuleList-com-jscraft-jsch.xml (+10 lines)
Added Link Here 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE module PUBLIC "-//NetBeans//DTD Module Status 1.0//EN"
3
                        "http://www.netbeans.org/dtds/module-status-1_0.dtd">
4
<module name="com.jcraft.jsch">
5
    <param name="autoload">true</param>
6
    <param name="eager">false</param>
7
    <param name="jar">modules/com-jcraft-jsch.jar</param>
8
    <param name="reloadable">false</param>
9
    <param name="startlevel">4</param>
10
</module>
(-)core.startup/test/unit/src/org/netbeans/core/startup/ModuleListStartLevelTest.java (+148 lines)
Added Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.core.startup;
46
47
import org.netbeans.SetupHid;
48
import java.io.File;
49
import java.io.IOException;
50
import java.io.InputStream;
51
import java.io.OutputStream;
52
import java.lang.reflect.Method;
53
import java.util.HashMap;
54
import java.util.Map;
55
import java.util.Set;
56
import org.netbeans.*;
57
import org.openide.filesystems.FileObject;
58
import org.openide.filesystems.FileUtil;
59
import org.openide.filesystems.LocalFileSystem;
60
import org.openide.modules.InstalledFileLocator;
61
import org.openide.modules.api.PlacesTestUtils;
62
import org.openide.util.test.MockLookup;
63
64
/** Do we recognize startlevel?
65
 * @author Jaroslav Tulach
66
 */
67
public class ModuleListStartLevelTest extends SetupHid {
68
    
69
    private static final String PREFIX = "wherever/";
70
    private LocalFileSystem fs;
71
    private MockEvents ev;
72
    private File ud;
73
74
    private final class IFL extends InstalledFileLocator {
75
        public IFL() {}
76
        public File locate(String relativePath, String codeNameBase, boolean localized) {
77
            if (relativePath.startsWith(PREFIX)) {
78
                File f = new File(jars, relativePath.substring(PREFIX.length()).replace('/', File.separatorChar));
79
                if (f.exists()) {
80
                    return f;
81
                }
82
            }
83
            return null;
84
        }
85
    }
86
    
87
    public ModuleListStartLevelTest(String name) {
88
        super(name);
89
    }
90
    
91
    private ModuleManager mgr;
92
    private FileObject modulesfolder;
93
    @Override
94
    protected void setUp() throws Exception {
95
        super.setUp();
96
97
        MockLookup.setInstances(new IFL());
98
99
        ud = new File(getWorkDir(), "ud");
100
        PlacesTestUtils.setUserDirectory(ud);
101
        
102
        MockModuleInstaller installer = new MockModuleInstaller();
103
        ev = new MockEvents();
104
        mgr = new ModuleManager(installer, ev);
105
        File dir = new File(ud, "config");
106
        File modulesdir = new File(dir, "Modules");
107
        if (! modulesdir.mkdirs()) throw new IOException("Making " + modulesdir);
108
        fs = new LocalFileSystem();
109
        fs.setRootDirectory(dir);
110
        modulesfolder = fs.findResource("Modules");
111
        assertNotNull(modulesfolder);
112
    }
113
    
114
    public void testParsesStartLevel() throws Exception {
115
        FileObject fo = modulesfolder.createData("com-jcraft-jsch.xml");
116
        File mod = new File(new File(ud, "modules"), "com-jcraft-jsch.jar");
117
        final HashMap<String, String> man = new HashMap<String, String>();
118
        man.put("Bundle-SymbolicName", "com.jcraft.jsch");
119
        createJar(mod, new HashMap<String, String>(), man);
120
        
121
        InputStream is = ModuleListStartLevelTest.class.getResourceAsStream("ModuleList-com-jscraft-jsch.xml");
122
        assertNotNull("Module definition found", is);
123
        final OutputStream os = fo.getOutputStream();
124
        FileUtil.copy(is, os);
125
        os.close();
126
        is.close();
127
        
128
        ModuleList list = new ModuleList(mgr, modulesfolder, ev);
129
        Set<Module> set = list.readInitial();
130
        
131
        assertEquals("One module: " + set, 1, set.size());
132
        Module m = set.iterator().next();
133
        
134
        assertEquals("Start level has been specified to four", 4, m.getStartLevel());
135
        
136
        Stamps.getModulesJARs().flush(0);
137
        Stamps.getModulesJARs().shutdown();
138
        
139
        Map<String, Map<String, Object>> cache = list.readCache();
140
        assertNotNull("Cache read", cache);
141
        Map<String, Object> module = cache.get("com.jcraft.jsch");
142
        assertNotNull("Module info found", module);
143
        Object level = module.get("startlevel");
144
        assertEquals("Start level is remembered", Integer.valueOf(4), level);
145
    }
146
    
147
148
}
(-)o.n.bootstrap/manifest.mf (-1 / +1 lines)
 Lines 1-6    Link Here 
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.bootstrap/1
2
OpenIDE-Module: org.netbeans.bootstrap/1
3
OpenIDE-Module-Specification-Version: 2.41
3
OpenIDE-Module-Specification-Version: 2.43
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/Bundle.properties
5
OpenIDE-Module-Recommends: org.netbeans.NetigsoFramework
5
OpenIDE-Module-Recommends: org.netbeans.NetigsoFramework
6
6
(-)o.n.bootstrap/src/org/netbeans/Module.java (+14 lines)
 Lines 609-614    Link Here 
609
    public final Object getHistory() {
609
    public final Object getHistory() {
610
        return history;
610
        return history;
611
    }
611
    }
612
613
    /** Finds out if a module has been assigned with a specific start level.
614
     * Start level is only useful for OSGi bundles. Otherwise it is always zero.
615
     * 
616
     * @return zero, if no specific level is assigned, positive integer if so
617
     * @since 2.43
618
     */
619
    public final int getStartLevel() {
620
        return getStartLevelImpl();
621
    }
622
    
623
    int getStartLevelImpl() {
624
        return 0;
625
    }
612
    
626
    
613
    /** String representation for debugging. */
627
    /** String representation for debugging. */
614
    public @Override String toString() {
628
    public @Override String toString() {
(-)o.n.bootstrap/src/org/netbeans/ModuleFactory.java (-1 / +1 lines)
 Lines 80-86    Link Here 
80
            throw ex;
80
            throw ex;
81
        }
81
        }
82
    }
82
    }
83
83
    
84
    /**
84
    /**
85
     * This method creates a "fixed" module. Fixed modules cannot be
85
     * This method creates a "fixed" module. Fixed modules cannot be
86
     * realoaded, are always enabled and are typically present on the
86
     * realoaded, are always enabled and are typically present on the
(-)o.n.bootstrap/src/org/netbeans/ModuleManager.java (+28 lines)
 Lines 598-603    Link Here 
598
        subCreate(m);
598
        subCreate(m);
599
        return m;
599
        return m;
600
    }
600
    }
601
    
602
    /** Create a module from a JAR representing an OSGi bundle 
603
     * and adds it to the managed set.
604
     * Behavior is the same as {@link #create(java.io.File, java.lang.Object, boolean, boolean, boolean)}
605
     * just adds additional start level info.
606
     * 
607
     * @param startLevel an OSGi start level. Zero indicates, no changes to default level.
608
     * @throws InvalidException if the JAR does not represent an OSGi bundle
609
     * @since 2.43
610
     */
611
    public Module createBundle(
612
        File jar, Object history, boolean reloadable, boolean autoload, 
613
        boolean eager, int startLevel
614
    ) throws IOException, DuplicateException {
615
        assertWritable();
616
        ev.log(Events.START_CREATE_REGULAR_MODULE, jar);
617
        Module m = moduleFactory.create(jar.getAbsoluteFile(),
618
                        history, reloadable, autoload, eager, this, ev);
619
        if (m instanceof NetigsoModule) {
620
            NetigsoModule nm = (NetigsoModule)m;
621
            nm.setStartLevel(startLevel);
622
        } else {
623
            throw new InvalidException("Expecting an OSGI bundle in " + jar);
624
        }
625
        ev.log(Events.FINISH_CREATE_REGULAR_MODULE, jar);
626
        subCreate(m);
627
        return m;
628
    }
601
629
602
    /** Create a fixed module (e.g. from classpath).
630
    /** Create a fixed module (e.g. from classpath).
603
     * Will initially be disabled.
631
     * Will initially be disabled.
(-)o.n.bootstrap/src/org/netbeans/NetigsoModule.java (-2 / +12 lines)
 Lines 63-70    Link Here 
63
final class NetigsoModule extends Module {
63
final class NetigsoModule extends Module {
64
    static final Logger LOG = Logger.getLogger(NetigsoModule.class.getPackage().getName());
64
    static final Logger LOG = Logger.getLogger(NetigsoModule.class.getPackage().getName());
65
65
66
    private File jar;
66
    private final File jar;
67
    private Manifest manifest;
67
    private final Manifest manifest;
68
    private int startLevel;
68
69
69
    public NetigsoModule(Manifest mani, File jar, ModuleManager mgr, Events ev, Object history, boolean reloadable, boolean autoload, boolean eager) throws IOException {
70
    public NetigsoModule(Manifest mani, File jar, ModuleManager mgr, Events ev, Object history, boolean reloadable, boolean autoload, boolean eager) throws IOException {
70
        super(mgr, ev, history, reloadable, autoload, eager);
71
        super(mgr, ev, history, reloadable, autoload, eager);
 Lines 224-229    Link Here 
224
        return s.replaceFirst(";.*$", "");
225
        return s.replaceFirst(";.*$", "");
225
    }
226
    }
226
227
228
    @Override
229
    final int getStartLevelImpl() {
230
        return startLevel;
231
    }
232
233
    final void setStartLevel(int startLevel) {
234
        this.startLevel = startLevel;
235
    }
236
227
    private final class DelegateCL extends ProxyClassLoader 
237
    private final class DelegateCL extends ProxyClassLoader 
228
    implements Util.ModuleProvider {
238
    implements Util.ModuleProvider {
229
        public DelegateCL() {
239
        public DelegateCL() {

Return to bug 201796
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo