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

(-)a/nbbuild/cluster.properties (+1 lines)
Lines 318-323 Link Here
318
        libs.xerces,\
318
        libs.xerces,\
319
        localhistory,\
319
        localhistory,\
320
        mercurial,\
320
        mercurial,\
321
        netbinox,\
321
        o.apache.xml.resolver,\
322
        o.apache.xml.resolver,\
322
        o.mozilla.rhino.patched,\
323
        o.mozilla.rhino.patched,\
323
        o.n.swing.dirchooser,\
324
        o.n.swing.dirchooser,\
(-)5cee832cf3ae (+5 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project basedir="." default="netbeans" name="netbinox">
3
    <description>Builds, tests, and runs the project org.netbeans.modules.netbinox</description>
4
    <import file="../nbbuild/templates/projectized.xml"/>
5
</project>
(-)5cee832cf3ae (+1 lines)
Added Link Here
1
1D63B972926D053DFA427CA03841F67D4EAC6DB2 org.eclipse.osgi_3.6.0.v20100517.jar
(-)5cee832cf3ae (+73 lines)
Added Link Here
1
Name: Equinox
2
Version: 3.6.0
3
Description: Eclipse OSGi container
4
License: EPL-v10
5
OSR: XXX
6
Files: org.eclipse.osgi_3.6.0.v20100517.jar
7
Origin: http://www.eclipse.org/equinox/
8
9
Eclipse Public License - v 1.0
10
11
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
12
13
1. DEFINITIONS
14
15
"Contribution" means:
16
17
a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
18
b) in the case of each subsequent Contributor:
19
20
i) changes to the Program, and
21
ii) additions to the Program;
22
23
where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
24
"Contributor" means any person or entity that distributes the Program.
25
"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
26
"Program" means the Contributions distributed in accordance with this Agreement.
27
"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
28
29
2. GRANT OF RIGHTS
30
31
a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
32
b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
33
c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
34
d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
35
36
3. REQUIREMENTS
37
38
A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
39
a) it complies with the terms and conditions of this Agreement; and
40
b) its license agreement:
41
i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
42
ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
43
iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
44
iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
45
46
When the Program is made available in source code form:
47
a) it must be made available under this Agreement; and
48
b) a copy of this Agreement must be included with each copy of the Program.
49
50
Contributors may not remove or alter any copyright notices contained within the Program.
51
Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
52
53
4. COMMERCIAL DISTRIBUTION
54
55
Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
56
57
For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
58
59
5. NO WARRANTY
60
61
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
62
63
6. DISCLAIMER OF LIABILITY
64
65
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
66
67
7. GENERAL
68
69
If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
70
If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
71
All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
72
Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
73
This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
(-)5cee832cf3ae (+73 lines)
Added Link Here
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.netbinox
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/netbinox/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.22
5
OpenIDE-Module-Provides: org.osgi.framework.launch.FrameworkFactory
6
OpenIDE-Module-Hide-Classpath-Packages: org.eclipse.core.runtime.**,org.eclipse.osgi.**
7
Covered-Packages: META-INF,,org.netbeans.modules.netbinox,
8
 /MANIFEST.MF,/generated-layer.xml,META-INF.services,
9
 /services/org.osgi.framework.launch.FrameworkFactory,
10
 org.osgi.service.framework,
11
 META-INF.services,
12
 org.eclipse,
13
 org.eclipse.core,
14
 org.eclipse.core.runtime,
15
 org.eclipse.core.runtime.adaptor,
16
 org.eclipse.core.runtime.internal,
17
 org.eclipse.core.runtime.internal.adaptor,
18
 org.eclipse.core.runtime.internal.stats,
19
 org.eclipse.osgi,
20
 org.eclipse.osgi.baseadaptor,
21
 org.eclipse.osgi.baseadaptor.bundlefile,
22
 org.eclipse.osgi.baseadaptor.hooks,
23
 org.eclipse.osgi.baseadaptor.loader,
24
 org.eclipse.osgi.event,
25
 org.eclipse.osgi.framework,
26
 org.eclipse.osgi.framework.adaptor,
27
 org.eclipse.osgi.framework.console,
28
 org.eclipse.osgi.framework.debug,
29
 org.eclipse.osgi.framework.eventmgr,
30
 org.eclipse.osgi.framework.internal,
31
 org.eclipse.osgi.framework.internal.core,
32
 org.eclipse.osgi.framework.internal.protocol,
33
 org.eclipse.osgi.framework.internal.protocol.bundleentry,
34
 org.eclipse.osgi.framework.internal.protocol.bundleresource,
35
 org.eclipse.osgi.framework.internal.protocol.reference,
36
 org.eclipse.osgi.framework.internal.reliablefile,
37
 org.eclipse.osgi.framework.log,
38
 org.eclipse.osgi.framework.util,
39
 org.eclipse.osgi.internal,
40
 org.eclipse.osgi.internal.baseadaptor,
41
 org.eclipse.osgi.internal.composite,
42
 org.eclipse.osgi.internal.loader,
43
 org.eclipse.osgi.internal.loader.buddy,
44
 org.eclipse.osgi.internal.module,
45
 org.eclipse.osgi.internal.permadmin,
46
 org.eclipse.osgi.internal.profile,
47
 org.eclipse.osgi.internal.provisional,
48
 org.eclipse.osgi.internal.provisional.service,
49
 org.eclipse.osgi.internal.provisional.service.security,
50
 org.eclipse.osgi.internal.provisional.verifier,
51
 org.eclipse.osgi.internal.resolver,
52
 org.eclipse.osgi.internal.service,
53
 org.eclipse.osgi.internal.service.security,
54
 org.eclipse.osgi.internal.serviceregistry,
55
 org.eclipse.osgi.internal.signedcontent,
56
 org.eclipse.osgi.launch,
57
 org.eclipse.osgi.service,
58
 org.eclipse.osgi.service.datalocation,
59
 org.eclipse.osgi.service.debug,
60
 org.eclipse.osgi.service.environment,
61
 org.eclipse.osgi.service.internal,
62
 org.eclipse.osgi.service.internal.composite,
63
 org.eclipse.osgi.service.localization,
64
 org.eclipse.osgi.service.pluginconversion,
65
 org.eclipse.osgi.service.resolver,
66
 org.eclipse.osgi.service.runnable,
67
 org.eclipse.osgi.service.security,
68
 org.eclipse.osgi.service.urlconversion,
69
 org.eclipse.osgi.signedcontent,
70
 org.eclipse.osgi.storagemanager,
71
 org.eclipse.osgi.util
72
AutoUpdate-Show-In-Client: false
73
(-)5cee832cf3ae (+45 lines)
Added Link Here
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 1997-2010 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
# Contributor(s):
27
#
28
# The Original Software is NetBeans. The Initial Developer of the Original
29
# Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
30
# Microsystems, Inc. All Rights Reserved.
31
#
32
# If you wish your version of this file to be governed by only the CDDL
33
# or only the GPL Version 2, indicate your decision by adding
34
# "[Contributor] elects to include this software in this distribution
35
# under the [CDDL or GPL Version 2] license." If you do not indicate a
36
# single choice of license, a recipient has the option to distribute
37
# your version of this file under either the CDDL, the GPL Version 2 or
38
# to extend the choice of license to its licensees as provided above.
39
# However, if you add GPL Version 2 code and therefore, elected the GPL
40
# Version 2 license, then the option applies only if the new code is
41
# made subject to such option by the copyright holder.
42
43
release.external/org.eclipse.osgi_3.6.0.v20100517.jar=modules/ext/org.eclipse.osgi_3.6.0.v20100517.jar
44
javac.source=1.6
45
javac.compilerargs=-Xlint -Xlint:-serial
(-)5cee832cf3ae (+93 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://www.netbeans.org/ns/project/1">
3
    <type>org.netbeans.modules.apisupport.project</type>
4
    <configuration>
5
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
6
            <code-name-base>org.netbeans.modules.netbinox</code-name-base>
7
            <module-dependencies>
8
                <dependency>
9
                    <code-name-base>org.netbeans.core.netigso</code-name-base>
10
                    <build-prerequisite/>
11
                    <compile-dependency/>
12
                    <run-dependency>
13
                        <specification-version>1.4.2</specification-version>
14
                    </run-dependency>
15
                </dependency>
16
                <dependency>
17
                    <code-name-base>org.netbeans.libs.osgi</code-name-base>
18
                    <build-prerequisite/>
19
                    <compile-dependency/>
20
                    <run-dependency>
21
                        <specification-version>1.0</specification-version>
22
                    </run-dependency>
23
                </dependency>
24
                <dependency>
25
                    <code-name-base>org.openide.modules</code-name-base>
26
                    <build-prerequisite/>
27
                    <compile-dependency/>
28
                    <run-dependency>
29
                        <specification-version>7.11</specification-version>
30
                    </run-dependency>
31
                </dependency>
32
                <dependency>
33
                    <code-name-base>org.openide.util.lookup</code-name-base>
34
                    <build-prerequisite/>
35
                    <compile-dependency/>
36
                    <run-dependency>
37
                        <specification-version>8.0.0.1</specification-version>
38
                    </run-dependency>
39
                </dependency>
40
            </module-dependencies>
41
            <test-dependencies>
42
                <test-type>
43
                    <name>unit</name>
44
                    <test-dependency>
45
                        <code-name-base>org.netbeans.core.netigso</code-name-base>
46
                        <recursive/>
47
                        <compile-dependency/>
48
                    </test-dependency>
49
                    <test-dependency>
50
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
51
                        <compile-dependency/>
52
                    </test-dependency>
53
                    <test-dependency>
54
                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
55
                        <recursive/>
56
                        <compile-dependency/>
57
                    </test-dependency>
58
                </test-type>
59
            </test-dependencies>
60
            <public-packages>
61
                <package>org.eclipse.core.runtime.adaptor</package>
62
                <package>org.eclipse.osgi.baseadaptor</package>
63
                <package>org.eclipse.osgi.baseadaptor.bundlefile</package>
64
                <package>org.eclipse.osgi.baseadaptor.hooks</package>
65
                <package>org.eclipse.osgi.baseadaptor.loader</package>
66
                <package>org.eclipse.osgi.event</package>
67
                <package>org.eclipse.osgi.framework.adaptor</package>
68
                <package>org.eclipse.osgi.framework.console</package>
69
                <package>org.eclipse.osgi.framework.debug</package>
70
                <package>org.eclipse.osgi.framework.eventmgr</package>
71
                <package>org.eclipse.osgi.framework.log</package>
72
                <package>org.eclipse.osgi.framework.util</package>
73
                <package>org.eclipse.osgi.service.datalocation</package>
74
                <package>org.eclipse.osgi.service.debug</package>
75
                <package>org.eclipse.osgi.service.environment</package>
76
                <package>org.eclipse.osgi.service.internal.composite</package>
77
                <package>org.eclipse.osgi.service.localization</package>
78
                <package>org.eclipse.osgi.service.pluginconversion</package>
79
                <package>org.eclipse.osgi.service.resolver</package>
80
                <package>org.eclipse.osgi.service.runnable</package>
81
                <package>org.eclipse.osgi.service.security</package>
82
                <package>org.eclipse.osgi.service.urlconversion</package>
83
                <package>org.eclipse.osgi.signedcontent</package>
84
                <package>org.eclipse.osgi.storagemanager</package>
85
                <package>org.eclipse.osgi.util</package>
86
            </public-packages>
87
            <class-path-extension>
88
                <runtime-relative-path>ext/org.eclipse.osgi_3.6.0.v20100517.jar</runtime-relative-path>
89
                <binary-origin>external/org.eclipse.osgi_3.6.0.v20100517.jar</binary-origin>
90
            </class-path-extension>
91
        </data>
92
    </configuration>
93
</project>
(-)5cee832cf3ae (+18 lines)
Added Link Here
1
#
2
#  Copyright (C) 2009 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3
#
4
#  This program is free software; you can redistribute it and/or
5
#  modify it under the terms of the GNU General Public License
6
#  as published by the Free Software Foundation; version 2
7
#  of the License.
8
#
9
#  This program is distributed in the hope that it will be useful,
10
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
#  GNU General Public License for more details.
13
#
14
#  You should have received a copy of the GNU General Public License
15
#  along with this program; if not, write to the Free Software
16
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
#
18
OpenIDE-Module-Name=Netigso Equinox Integration
(-)5cee832cf3ae (+65 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2010 Jaroslav Tulach <jtulach@netbeans.org>
3
 * 
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; either version 2
7
 *  of the License, or (at your option) any later version.
8
 * 
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 * 
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.io.File;
22
import java.io.IOException;
23
import java.util.Collections;
24
import java.util.Enumeration;
25
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
26
import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
27
28
/**
29
 *
30
 * @author Jaroslav Tulach <jtulach@netbeans.org>
31
 */
32
final class EmptyBundleFile extends BundleFile {
33
    public static final BundleFile EMPTY = new EmptyBundleFile();
34
35
    private EmptyBundleFile() {
36
    }
37
38
    @Override
39
    public File getFile(String string, boolean bln) {
40
        return null;
41
    }
42
43
    @Override
44
    public BundleEntry getEntry(String string) {
45
        return null;
46
    }
47
48
    @Override
49
    public Enumeration getEntryPaths(String string) {
50
        return Collections.enumeration(Collections.emptyList());
51
    }
52
53
    @Override
54
    public void close() throws IOException {
55
    }
56
57
    @Override
58
    public void open() throws IOException {
59
    }
60
61
    @Override
62
    public boolean containsDir(String string) {
63
        return false;
64
    }
65
}
(-)5cee832cf3ae (+282 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2010 Jaroslav Tulach <jtulach@netbeans.org>
3
 * 
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; either version 2
7
 *  of the License, or (at your option) any later version.
8
 * 
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 * 
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.io.ByteArrayInputStream;
22
import java.io.File;
23
import java.io.IOException;
24
import java.io.InputStream;
25
import java.net.MalformedURLException;
26
import java.net.URL;
27
import java.util.Collections;
28
import java.util.Enumeration;
29
import java.util.HashMap;
30
import java.util.Map;
31
import java.util.logging.Level;
32
import org.eclipse.osgi.baseadaptor.BaseData;
33
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
34
import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
35
import org.eclipse.osgi.baseadaptor.bundlefile.DirBundleFile;
36
import org.eclipse.osgi.baseadaptor.bundlefile.MRUBundleFileList;
37
import org.eclipse.osgi.baseadaptor.bundlefile.ZipBundleFile;
38
import org.netbeans.core.netigso.spi.BundleContent;
39
import org.netbeans.core.netigso.spi.NetigsoArchive;
40
41
/** This is fake bundle. It is created by the Netbinox infrastructure to 
42
 * use the {@link NetigsoArchive} to get cached data and speed up the start.
43
 *
44
 * @author Jaroslav Tulach <jtulach@netbeans.org>
45
 */
46
final class JarBundleFile extends BundleFile implements BundleContent {
47
    private BundleFile delegate;
48
49
    private static Map<Long,File> usedIds;
50
51
    private final MRUBundleFileList mru;
52
    private final BaseData data;
53
    private final NetigsoArchive archive;
54
    
55
    JarBundleFile(
56
        File base, BaseData data, NetigsoArchive archive,
57
        MRUBundleFileList mru, boolean isBase
58
    ) {
59
        super(base);
60
61
        long id;
62
        if (isBase) {
63
            id = data.getBundleID();
64
        } else {
65
            id = 100000 + base.getPath().hashCode();
66
        }
67
68
        boolean assertOn = false;
69
        assert assertOn = true;
70
        if (assertOn) {
71
            if (usedIds == null) {
72
                usedIds =  new HashMap<Long, File>();
73
            }
74
            File prev = usedIds.put(id, base);
75
            if (prev != null && !prev.equals(base)) {
76
                NetbinoxFactory.LOG.log(
77
                    Level.WARNING,
78
                    "same id: {0} for {1} and {2}", // NOI18N
79
                    new Object[]{id, base, prev}
80
                );
81
            }
82
        }
83
84
        this.archive = archive.forBundle(id, this);
85
        this.data = data;
86
        this.mru = mru;
87
    }
88
89
90
    private synchronized BundleFile delegate(String who, String what) {
91
        if (delegate == null) {
92
            NetbinoxFactory.LOG.log(Level.FINE, "opening {0} because of {1} needing {2}", new Object[]{data.getLocation(), who, what});
93
            try {
94
                delegate = new ZipBundleFile(getBaseFile(), data, mru) {
95
                    @Override
96
                    protected boolean checkedOpen() {
97
                        try {
98
                            return getZipFile() != null;
99
                        } catch (IOException ex) {
100
                            final File bf = new File(getBaseFile().getPath());
101
                            if (bf.isDirectory()) {
102
                                try {
103
                                    delegate = new DirBundleFile(bf);
104
                                    return false;
105
                                } catch (IOException dirEx) {
106
                                    NetbinoxFactory.LOG.log(Level.WARNING, 
107
                                        "Cannot create DirBundleFile for " + bf,
108
                                        dirEx
109
                                    );
110
                                }
111
                            }
112
                            NetbinoxFactory.LOG.log(Level.WARNING, "Cannot open file {0}", bf);
113
                            if (!bf.isFile() || !bf.canRead()) {
114
                                delegate = EmptyBundleFile.EMPTY;
115
                                return false;
116
                            }
117
                        }
118
                        // no optimizations
119
                        return super.checkedOpen();
120
                    }
121
                };
122
            } catch (IOException ex) {
123
                NetbinoxFactory.LOG.log(Level.FINE, "Error creating delegate for {0}", getBaseFile());
124
                delegate = EmptyBundleFile.EMPTY;
125
            }
126
        }
127
        return delegate;
128
    }
129
130
    @Override
131
    public File getBaseFile() {
132
        final File file = super.getBaseFile();
133
        class VFile extends File {
134
135
            public VFile() {
136
                super(file.getPath());
137
            }
138
139
            @Override
140
            public boolean isDirectory() {
141
                return false;
142
            }
143
144
            @Override
145
            public File getAbsoluteFile() {
146
                return this;
147
            }
148
            }
149
        return new VFile();
150
    }
151
152
    @Override
153
    public File getFile(String file, boolean bln) {
154
        byte[] exists = getCachedEntry(file);
155
        if (exists == null) {
156
            return null;
157
        }
158
        BundleFile d = delegate("getFile", file);
159
        return d == null ? null : d.getFile(file, bln);
160
    }
161
162
    public byte[] resource(String name) throws IOException {
163
        BundleEntry u = findEntry("resource", name);
164
        if (u == null) {
165
            return null;
166
        }
167
        InputStream is = u.getInputStream();
168
        if (is == null) {
169
            return new byte[0];
170
        }
171
        byte[] arr = null;
172
        try {
173
            arr = new byte[is.available()];
174
            int pos = 0;
175
            for (;;) {
176
                int toRead = arr.length - pos;
177
                if (toRead == 0) {
178
                    break;
179
                }
180
                int len = is.read(arr, pos, toRead);
181
                if (len == -1) {
182
                    break;
183
                }
184
                pos += len;
185
            }
186
            if (pos != arr.length) {
187
                throw new IOException("Not read enough: " + pos + " should have been: " + arr.length); // NOI18N
188
            }
189
        } finally {
190
            is.close();
191
        }
192
        return arr;
193
    }
194
195
    private BundleEntry findEntry(String why, String name) {
196
        BundleEntry u;
197
        for (;;) {
198
            BundleFile d = delegate(why, name);
199
            u = d.getEntry(name);
200
            if (u != null || d == delegate) {
201
                break;
202
            }
203
        }
204
        return u;
205
    }
206
207
208
    private byte[] getCachedEntry(String name) {
209
        try {
210
            return archive.fromArchive(name);
211
        } catch (IOException ex) {
212
            return null;
213
        }
214
    }
215
216
    @Override
217
    public BundleEntry getEntry(final String name) {
218
        final byte[] arr = getCachedEntry(name);
219
        if (arr == null && !name.equals("/")) {
220
            return null;
221
        }
222
        return new BundleEntry() {
223
            @Override
224
            public InputStream getInputStream() throws IOException {
225
                return new ByteArrayInputStream(arr);
226
            }
227
228
            @Override
229
            public long getSize() {
230
                return arr.length;
231
            }
232
233
            @Override
234
            public String getName() {
235
                return name;
236
            }
237
238
            @Override
239
            public long getTime() {
240
                return getBaseFile().lastModified();
241
            }
242
243
            @Override
244
            public URL getLocalURL() {
245
                return findEntry("getLocalURL", name).getLocalURL(); // NOI18N
246
            }
247
248
            @Override
249
            public URL getFileURL() {
250
                return findEntry("getFileURL", name).getFileURL(); // NOI18N
251
            }
252
        };
253
    }
254
255
    @Override
256
    public Enumeration getEntryPaths(String prefix) {
257
        BundleFile d = delegate("getEntryPaths", prefix);
258
        if (d == null) {
259
            return Collections.enumeration(Collections.emptyList());
260
        }
261
        return d.getEntryPaths(prefix);
262
    }
263
264
    @Override
265
    public synchronized void close() throws IOException {
266
        if (delegate != null) {
267
            delegate.close();
268
        }
269
    }
270
271
    @Override
272
    public void open() throws IOException {
273
        if (delegate != null) {
274
            delegate.open();
275
        }
276
    }
277
278
    @Override
279
    public boolean containsDir(String path) {
280
        return path.endsWith("/") && getEntry(path) != null;
281
    }
282
}
(-)5cee832cf3ae (+177 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3
 *
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; version 2
7
 *  of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.io.File;
22
import java.io.InputStream;
23
import java.lang.reflect.Field;
24
import java.util.Dictionary;
25
import java.util.Map;
26
import java.util.Properties;
27
import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
28
import org.eclipse.osgi.launch.Equinox;
29
import org.osgi.framework.Bundle;
30
import org.osgi.framework.BundleContext;
31
import org.osgi.framework.BundleException;
32
import org.osgi.framework.BundleListener;
33
import org.osgi.framework.Filter;
34
import org.osgi.framework.FrameworkListener;
35
import org.osgi.framework.InvalidSyntaxException;
36
import org.osgi.framework.ServiceListener;
37
import org.osgi.framework.ServiceReference;
38
import org.osgi.framework.ServiceRegistration;
39
40
/**
41
 *
42
 * @author Jaroslav Tulach <jtulach@netbeans.org>
43
 */
44
class Netbinox extends Equinox {
45
    public Netbinox(Map configuration) {
46
        super(configuration);
47
    }
48
    
49
    @Override
50
    public void init() throws BundleException {
51
        super.init();
52
        if (Boolean.getBoolean("osgi.framework.useSystemProperties")) {
53
            Properties prev = FrameworkProperties.getProperties();
54
            try {
55
                Field f = FrameworkProperties.class.getDeclaredField("properties"); // NOI18N
56
                f.setAccessible(true);
57
                f.set(null, null);
58
            } catch (Exception ex) {
59
                throw new IllegalStateException(ex);
60
            }
61
            Properties newP = FrameworkProperties.getProperties();
62
            for (Map.Entry en : prev.entrySet()) {
63
                if (en.getKey() instanceof String && en.getValue() instanceof String) {
64
                    newP.setProperty((String)en.getKey(), (String)en.getValue());
65
                }
66
            }
67
            assert System.getProperties() == FrameworkProperties.getProperties();
68
        }
69
    }
70
    
71
    
72
73
    @Override
74
    public BundleContext getBundleContext() {
75
        return new Context(super.getBundleContext());
76
    }
77
    
78
    private static final class Context implements BundleContext {
79
        private final BundleContext delegate;
80
81
        public Context(BundleContext delegate) {
82
            this.delegate = delegate;
83
        }
84
85
        public boolean ungetService(ServiceReference sr) {
86
            return delegate.ungetService(sr);
87
        }
88
89
        public void removeServiceListener(ServiceListener sl) {
90
            delegate.removeServiceListener(sl);
91
        }
92
93
        public void removeFrameworkListener(FrameworkListener fl) {
94
            delegate.removeFrameworkListener(fl);
95
        }
96
97
        public void removeBundleListener(BundleListener bl) {
98
            delegate.removeBundleListener(bl);
99
        }
100
101
        public ServiceRegistration registerService(String string, Object o, Dictionary dctnr) {
102
            return delegate.registerService(string, o, dctnr);
103
        }
104
105
        public ServiceRegistration registerService(String[] strings, Object o, Dictionary dctnr) {
106
            return delegate.registerService(strings, o, dctnr);
107
        }
108
109
        public Bundle installBundle(String string) throws BundleException {
110
            return installBundle(string, null);
111
        }
112
113
        public Bundle installBundle(String url, InputStream in) throws BundleException {
114
            if (url.startsWith("reference:")) {
115
                // workaround for problems with space in path
116
                url = url.replaceAll("%20", " ");
117
            }
118
            return delegate.installBundle(url, in);
119
        }
120
121
        public ServiceReference[] getServiceReferences(String string, String string1) throws InvalidSyntaxException {
122
            return delegate.getServiceReferences(string, string1);
123
        }
124
125
        public ServiceReference getServiceReference(String string) {
126
            return delegate.getServiceReference(string);
127
        }
128
129
        public Object getService(ServiceReference sr) {
130
            return delegate.getService(sr);
131
        }
132
133
        public String getProperty(String string) {
134
            return delegate.getProperty(string);
135
        }
136
137
        public File getDataFile(String string) {
138
            return delegate.getDataFile(string);
139
        }
140
141
        public Bundle[] getBundles() {
142
            return delegate.getBundles();
143
        }
144
145
        public Bundle getBundle(long l) {
146
            return delegate.getBundle(l);
147
        }
148
149
        public Bundle getBundle() {
150
            return delegate.getBundle();
151
        }
152
153
        public ServiceReference[] getAllServiceReferences(String string, String string1) throws InvalidSyntaxException {
154
            return delegate.getAllServiceReferences(string, string1);
155
        }
156
157
        public Filter createFilter(String string) throws InvalidSyntaxException {
158
            return delegate.createFilter(string);
159
        }
160
161
        public void addServiceListener(ServiceListener sl) {
162
            delegate.addServiceListener(sl);
163
        }
164
165
        public void addServiceListener(ServiceListener sl, String string) throws InvalidSyntaxException {
166
            delegate.addServiceListener(sl, string);
167
        }
168
169
        public void addFrameworkListener(FrameworkListener fl) {
170
            delegate.addFrameworkListener(fl);
171
        }
172
173
        public void addBundleListener(BundleListener bl) {
174
            delegate.addBundleListener(bl);
175
        }
176
    } // end of Context
177
}
(-)5cee832cf3ae (+83 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2009 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3
 *
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; version 2
7
 *  of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.util.HashMap;
22
import java.util.Map;
23
import java.util.logging.Logger;
24
import org.eclipse.osgi.launch.EquinoxFactory;
25
import org.netbeans.core.netigso.spi.NetigsoArchive;
26
import org.openide.util.lookup.ServiceProvider;
27
import org.osgi.framework.Bundle;
28
import org.osgi.framework.Constants;
29
import org.osgi.framework.launch.Framework;
30
import org.osgi.framework.launch.FrameworkFactory;
31
32
/**
33
 *
34
 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
35
 */
36
@ServiceProvider(
37
    service=FrameworkFactory.class,
38
    supersedes={ "org.eclipse.osgi.launch.EquinoxFactory" },
39
    position=-10
40
)
41
public class NetbinoxFactory implements FrameworkFactory {
42
    static final Logger LOG = Logger.getLogger("org.netbeans.modules.netbinox"); // NOI18N
43
44
    @SuppressWarnings("unchecked")
45
    public Framework newFramework(Map map) {
46
        Map<String,Object> configMap = new HashMap<String,Object>();
47
        configMap.putAll(map);
48
        configMap.put("osgi.hook.configurators.exclude", // NOI18N
49
            "org.eclipse.core.runtime.internal.adaptor.EclipseLogHook" // NOI18N
50
//            + ",org.eclipse.core.runtime.internal.adaptor.EclipseClassLoadingHook" // NOI18N
51
        );
52
        configMap.put("osgi.hook.configurators.include", NetbinoxHooks.class.getName()); // NOI18N
53
        configMap.put("osgi.user.area.default", configMap.get(Constants.FRAMEWORK_STORAGE)); // NOI18N
54
        configMap.put("osgi.instance.area.default", System.getProperty("netbeans.user")); // NOI18N
55
        configMap.put("osgi.install.area", System.getProperty("netbeans.home")); // NOI18N
56
        // some useless value
57
        configMap.put("osgi.framework.properties", System.getProperty("netbeans.user")); // NOI18N
58
59
        Object rawBundleMap = configMap.get("felix.bootdelegation.classloaders"); // NOI18N
60
61
        Map<Bundle,ClassLoader> bundleMap;
62
        if (rawBundleMap == null) {
63
            bundleMap = null;
64
        } else {
65
            bundleMap = (Map<Bundle,ClassLoader>)rawBundleMap;
66
        }
67
68
        NetbinoxHooks.registerMap(bundleMap);
69
        NetbinoxHooks.registerArchive((NetigsoArchive)configMap.get("netigso.archive")); // NOI18N
70
71
        String loc = EquinoxFactory.class.getProtectionDomain().getCodeSource().getLocation().toExternalForm();
72
        int file = loc.indexOf("file:");
73
        if (file > 0) {
74
            loc = loc.substring(file);
75
        }
76
        int exclaim = loc.indexOf("!");
77
        if (exclaim > 0) {
78
            loc = loc.substring(0, exclaim);
79
        }
80
        configMap.put("osgi.framework", loc);
81
        return new Netbinox(configMap);
82
    }
83
}
(-)5cee832cf3ae (+286 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2009 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3
 *
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; version 2
7
 *  of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.io.File;
22
import java.io.IOException;
23
import java.io.Writer;
24
import java.net.URL;
25
import java.net.URLConnection;
26
import java.security.ProtectionDomain;
27
import java.util.ArrayList;
28
import java.util.Enumeration;
29
import java.util.Map;
30
import java.util.Properties;
31
import java.util.logging.Level;
32
import java.util.logging.LogRecord;
33
import org.eclipse.osgi.baseadaptor.BaseAdaptor;
34
import org.eclipse.osgi.baseadaptor.BaseData;
35
import org.eclipse.osgi.baseadaptor.HookConfigurator;
36
import org.eclipse.osgi.baseadaptor.HookRegistry;
37
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
38
import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
39
import org.eclipse.osgi.baseadaptor.bundlefile.MRUBundleFileList;
40
import org.eclipse.osgi.baseadaptor.hooks.AdaptorHook;
41
import org.eclipse.osgi.baseadaptor.hooks.BundleFileFactoryHook;
42
import org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook;
43
import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;
44
import org.eclipse.osgi.baseadaptor.loader.ClasspathEntry;
45
import org.eclipse.osgi.baseadaptor.loader.ClasspathManager;
46
import org.eclipse.osgi.framework.adaptor.BundleData;
47
import org.eclipse.osgi.framework.adaptor.BundleProtectionDomain;
48
import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate;
49
import org.eclipse.osgi.framework.log.FrameworkLog;
50
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
51
import org.netbeans.core.netigso.spi.NetigsoArchive;
52
import org.openide.util.Lookup;
53
import org.osgi.framework.Bundle;
54
import org.osgi.framework.BundleContext;
55
import org.osgi.framework.BundleException;
56
import org.osgi.framework.FrameworkEvent;
57
58
/**
59
 *
60
 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
61
 */
62
public final class NetbinoxHooks implements HookConfigurator, ClassLoadingHook,
63
BundleFileFactoryHook, FrameworkLog, AdaptorHook {
64
    private static transient Map<Bundle,ClassLoader> map;
65
    private static transient NetigsoArchive archive;
66
    static void clear() {
67
        map = null;
68
        archive = null;
69
    }
70
71
    static void registerMap(Map<Bundle, ClassLoader> bundleMap) {
72
        map = bundleMap;
73
    }
74
75
    static void registerArchive(NetigsoArchive netigsoArchive) {
76
        archive = netigsoArchive;
77
    }
78
79
    public void addHooks(HookRegistry hr) {
80
        hr.addClassLoadingHook(this);
81
        hr.addBundleFileFactoryHook(this);
82
        hr.addAdaptorHook(this);
83
        for (HookConfigurator hc : Lookup.getDefault().lookupAll(HookConfigurator.class)) {
84
            hc.addHooks(hr);
85
        }
86
    }
87
88
    public byte[] processClass(String string, byte[] bytes, ClasspathEntry ce, BundleEntry be, ClasspathManager cm) {
89
        return bytes;
90
    }
91
92
    public boolean addClassPathEntry(ArrayList al, String string, ClasspathManager cm, BaseData bd, ProtectionDomain pd) {
93
        return false;
94
    }
95
96
    public String findLibrary(BaseData bd, String string) {
97
        return null;
98
    }
99
100
    public ClassLoader getBundleClassLoaderParent() {
101
        return null;
102
    }
103
104
    public BaseClassLoader createClassLoader(ClassLoader parent, final ClassLoaderDelegate delegate, final BundleProtectionDomain bpd, BaseData bd, String[] classpath) {
105
        String loc = bd.getBundle().getLocation();
106
        //NetigsoModule.LOG.log(Level.FINER, "createClassLoader {0}", bd.getLocation());
107
        final String pref = "netigso://"; // NOI18N
108
        ClassLoader ml = null;
109
        if (loc != null && loc.startsWith(pref)) {
110
            String cnb = loc.substring(pref.length());
111
            ml = map.get(bd.getBundle());
112
        }
113
        if (ml == null) {
114
            return new NetbinoxLoader(parent, delegate, bpd, bd, classpath);
115
        }
116
        class Del extends ClassLoader implements BaseClassLoader {
117
            public Del(ClassLoader parent) {
118
                super(parent);
119
            }
120
121
            public ProtectionDomain getDomain() {
122
                return bpd;
123
            }
124
125
            public ClasspathEntry createClassPathEntry(BundleFile bf, ProtectionDomain pd) {
126
                return null;
127
            }
128
129
            public Class defineClass(String string, byte[] bytes, ClasspathEntry ce, BundleEntry be) {
130
                throw new UnsupportedOperationException();
131
            }
132
133
            public Class publicFindLoaded(String name) {
134
                return super.findLoadedClass(name);
135
            }
136
137
            public Object publicGetPackage(String name) {
138
                return super.getPackage(name);
139
            }
140
141
            public Object publicDefinePackage(String s1, String s2, String s3, String s4, String s5, String s6, String s7, URL url) {
142
                return super.definePackage(s1, s2, s3, s4, s5, s6, s7, url);
143
            }
144
145
            public ClasspathManager getClasspathManager() {
146
                throw new UnsupportedOperationException("Not supported yet.");
147
            }
148
149
            public void initialize() {
150
            }
151
152
            public URL findLocalResource(String name) {
153
                return null;
154
                /*
155
                ProxyClassLoader pcl = (ProxyClassLoader)getParent();
156
                return pcl.findResource(name);
157
                 *
158
                 */
159
            }
160
161
            public Enumeration<URL> findLocalResources(String name) {
162
                return null;
163
                /*
164
                ProxyClassLoader pcl = (ProxyClassLoader)getParent();
165
                try {
166
                    return pcl.findResources(name);
167
                } catch (IOException ex) {
168
                    return Enumerations.empty();
169
                }
170
                 */
171
            }
172
173
            @Override
174
            protected URL findResource(String name) {
175
                return findLocalResource(name);
176
            }
177
178
            @Override
179
            protected Enumeration<URL> findResources(String name) throws IOException {
180
                return findLocalResources(name);
181
            }
182
183
            public Class findLocalClass(String name) throws ClassNotFoundException {
184
                return getParent().loadClass(name);
185
            }
186
187
            public void close() {
188
            }
189
190
            public void attachFragment(BundleData bd, ProtectionDomain pd, String[] strings) {
191
            }
192
193
            public ClassLoaderDelegate getDelegate() {
194
                return delegate;
195
            }
196
197
            public Bundle getBundle() {
198
                throw new UnsupportedOperationException("Not supported yet.");
199
            }
200
        }
201
        return new Del(ml);
202
    }
203
204
    public void initializedClassLoader(BaseClassLoader bcl, BaseData bd) {
205
    }
206
207
    private final MRUBundleFileList mruList = new MRUBundleFileList();
208
    public BundleFile createBundleFile(Object file, final BaseData bd, boolean isBase) throws IOException {
209
210
        if (file instanceof File) {
211
            final File f = (File)file;
212
// running with fake manifest fails for some reason, disabling for now
213
//            final String loc = bd.getLocation();
214
//            if (loc != null && loc.startsWith("netigso://")) {
215
//                return new NetigsoBundleFile(f, bd);
216
//            }
217
            return new JarBundleFile(f, bd, archive, mruList, isBase);
218
        }
219
        return null;
220
    }
221
222
    public void log(FrameworkEvent fe) {
223
        Level l = Level.FINE;
224
        if ((fe.getType() & FrameworkEvent.ERROR) != 0) {
225
            l = Level.SEVERE;
226
        } else if ((fe.getType() & FrameworkEvent.WARNING) != 0) {
227
            l = Level.WARNING;
228
        } else if ((fe.getType() & FrameworkEvent.INFO) != 0) {
229
            l = Level.INFO;
230
        }
231
        LogRecord lr = new LogRecord(l, "framework event {0} type {1}");
232
        lr.setParameters(new Object[]{fe.getBundle().getSymbolicName(), fe.getType()});
233
        lr.setThrown(fe.getThrowable());
234
        lr.setLoggerName(NetbinoxFactory.LOG.getName());
235
        NetbinoxFactory.LOG.log(lr);
236
    }
237
238
    public void log(FrameworkLogEntry fle) {
239
        NetbinoxFactory.LOG.log(Level.FINE, "entry {0}", fle);
240
    }
241
242
    public void setWriter(Writer writer, boolean bln) {
243
    }
244
245
    public void setFile(File file, boolean bln) throws IOException {
246
    }
247
248
    public File getFile() {
249
        return null;
250
    }
251
252
    public void setConsoleLog(boolean bln) {
253
    }
254
255
    public void close() {
256
    }
257
258
    // adaptor hooks
259
260
    public void initialize(BaseAdaptor ba) {
261
    }
262
263
    public void frameworkStart(BundleContext bc) throws BundleException {
264
    }
265
266
    public void frameworkStop(BundleContext bc) throws BundleException {
267
    }
268
269
    public void frameworkStopping(BundleContext bc) {
270
    }
271
272
    public void addProperties(Properties prprts) {
273
    }
274
275
    public URLConnection mapLocationToURLConnection(String string) throws IOException {
276
        return null;
277
    }
278
279
    public void handleRuntimeError(Throwable thrwbl) {
280
        NetbinoxFactory.LOG.log(Level.WARNING, thrwbl.getMessage(), thrwbl);
281
    }
282
283
    public FrameworkLog createFrameworkLog() {
284
        return this;
285
    }
286
}
(-)5cee832cf3ae (+116 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2010 Jaroslav Tulach <jtulach@netbeans.org>
3
 * 
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; either version 2
7
 *  of the License, or (at your option) any later version.
8
 * 
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 * 
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.io.File;
22
import java.io.IOException;
23
import java.net.URI;
24
import java.net.URISyntaxException;
25
import java.security.ProtectionDomain;
26
import java.util.logging.Level;
27
import org.eclipse.osgi.baseadaptor.BaseData;
28
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
29
import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
30
import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;
31
import org.eclipse.osgi.baseadaptor.loader.ClasspathEntry;
32
import org.eclipse.osgi.baseadaptor.loader.ClasspathManager;
33
import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate;
34
import org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader;
35
import org.osgi.framework.FrameworkEvent;
36
37
/** Classloader that eliminates some unnecessary disk touches.
38
 *
39
 * @author Jaroslav Tulach <jtulach@netbeans.org>
40
 */
41
final class NetbinoxLoader extends DefaultClassLoader {
42
    public NetbinoxLoader(ClassLoader parent, ClassLoaderDelegate delegate, ProtectionDomain domain, BaseData bd, String[] classpath) {
43
        super(parent, delegate, domain, bd, classpath);
44
        this.manager = new NoTouchCPM(bd, classpath, this);
45
    }
46
47
    @Override
48
    public String toString() {
49
        return "NetbinoxLoader delegating to " + delegate;
50
    }
51
    
52
    private static class NoTouchCPM extends ClasspathManager {
53
        public NoTouchCPM(BaseData data, String[] classpath, BaseClassLoader classloader) {
54
            super(data, classpath, classloader);
55
        }
56
57
        @Override
58
        public ClasspathEntry getClasspath(String cp, BaseData sourcedata, ProtectionDomain sourcedomain) {
59
            BundleFile bundlefile = null;
60
            File file;
61
            BundleEntry cpEntry = sourcedata.getBundleFile().getEntry(cp);
62
            // check for internal library directories in a bundle jar file
63
            if (cpEntry != null && cpEntry.getName().endsWith("/")) //$NON-NLS-1$
64
            {
65
                bundlefile = createBundleFile(cp, sourcedata);
66
            } // check for internal library jars
67
            else if ((file = sourcedata.getBundleFile().getFile(cp, false)) != null) {
68
                bundlefile = createBundleFile(file, sourcedata);
69
            }
70
            if (bundlefile != null) {
71
                return createClassPathEntry(bundlefile, sourcedomain, sourcedata);
72
            }
73
            return null;
74
        }
75
76
        @Override
77
        public ClasspathEntry getExternalClassPath(String cp, BaseData sourcedata, ProtectionDomain sourcedomain) {
78
            File file;
79
            if (cp.startsWith("file:")) { // NOI18N
80
                try {
81
                    file = new File(new URI(cp));
82
                } catch (URISyntaxException ex) {
83
                    NetbinoxFactory.LOG.log(Level.SEVERE, "Cannot convert to file: " + cp, ex); // NOI18N
84
                    return null;
85
                }
86
            } else {
87
                file = new File(cp);
88
            }
89
            if (!file.isAbsolute() && !cp.startsWith("file:")) { // NOI18N
90
                return null;
91
            }
92
            BundleFile bundlefile = createBundleFile(file, sourcedata);
93
            if (bundlefile != null) {
94
                return createClassPathEntry(bundlefile, sourcedomain, sourcedata);
95
            }
96
            return null;
97
        }
98
99
        private static BundleFile createBundleFile(Object content, BaseData sourcedata) {
100
            try {
101
                return sourcedata.getAdaptor().createBundleFile(content, sourcedata);
102
            } catch (IOException e) {
103
                sourcedata.getAdaptor().getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, sourcedata.getBundle(), e);
104
            }
105
            return null;
106
        }
107
        private ClasspathEntry createClassPathEntry(BundleFile bundlefile, ProtectionDomain cpDomain, final BaseData data) {
108
            return new ClasspathEntry(bundlefile, createProtectionDomain(bundlefile, cpDomain)) {
109
                @Override
110
                public BaseData getBaseData() {
111
                    return data;
112
                }
113
            };
114
        }
115
    } // end of NoTouchCPM
116
}
(-)5cee832cf3ae (+147 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2010 Jaroslav Tulach <jtulach@netbeans.org>
3
 * 
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; either version 2
7
 *  of the License, or (at your option) any later version.
8
 * 
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 * 
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.io.ByteArrayInputStream;
22
import java.io.ByteArrayOutputStream;
23
import java.io.File;
24
import java.io.IOException;
25
import java.io.InputStream;
26
import java.net.URL;
27
import java.util.Collections;
28
import java.util.Enumeration;
29
import java.util.jar.Manifest;
30
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
31
import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
32
import org.eclipse.osgi.framework.adaptor.BundleData;
33
import org.openide.modules.ModuleInfo;
34
import org.openide.util.Lookup;
35
36
/** This is fake bundle, created by the Netigso infrastructure.
37
 *
38
 * @author Jaroslav Tulach <jtulach@netbeans.org>
39
 */
40
final class NetigsoBundleFile extends BundleFile {
41
    private final BundleData data;
42
    NetigsoBundleFile(File base, BundleData data) {
43
        super(base);
44
        this.data = data;
45
    }
46
47
    @Override
48
    public File getFile(String string, boolean bln) {
49
        return null;
50
    }
51
52
    @Override
53
    public BundleEntry getEntry(String entry) {
54
        if ("META-INF/MANIFEST.MF".equals(entry)) { // NOI18N
55
            return new BundleEntry() {
56
                @Override
57
                public InputStream getInputStream() throws IOException {
58
                    for (ModuleInfo mi : Lookup.getDefault().lookupAll(ModuleInfo.class)) {
59
                        if (data.getLocation().endsWith(mi.getCodeNameBase())) {
60
                            return fakeManifest(mi);
61
                        }
62
                    }
63
                    throw new IOException("Cannot find " + data.getLocation());
64
                }
65
66
                @Override
67
                public long getSize() {
68
                    throw new UnsupportedOperationException("Not supported yet.");
69
                }
70
71
                @Override
72
                public String getName() {
73
                    return "META-INF/MANIFEST.MF"; // NOI18N
74
                }
75
76
                @Override
77
                public long getTime() {
78
                    throw new UnsupportedOperationException("Not supported yet.");
79
                }
80
81
                @Override
82
                public URL getLocalURL() {
83
                    throw new UnsupportedOperationException("Not supported yet.");
84
                }
85
86
                @Override
87
                public URL getFileURL() {
88
                    throw new UnsupportedOperationException("Not supported yet.");
89
                }
90
            };
91
        }
92
        return null;
93
    }
94
95
    @Override
96
    public Enumeration getEntryPaths(String string) {
97
        return Collections.enumeration(Collections.emptyList());
98
    }
99
100
    @Override
101
    public void close() throws IOException {
102
    }
103
104
    @Override
105
    public void open() throws IOException {
106
    }
107
108
    @Override
109
    public boolean containsDir(String string) {
110
        return false;
111
    }
112
113
    private static InputStream fakeManifest(ModuleInfo m) throws IOException {
114
        String exp = (String) m.getAttribute("OpenIDE-Module-Public-Packages"); // NOI18N
115
        if ("-".equals(exp)) { // NOI18N
116
            return null;
117
        }
118
        ByteArrayOutputStream os = new ByteArrayOutputStream();
119
        Manifest man = new Manifest();
120
        man.getMainAttributes().putValue("Manifest-Version", "1.0"); // workaround for JDK bug
121
        man.getMainAttributes().putValue("Bundle-ManifestVersion", "2"); // NOI18N
122
        man.getMainAttributes().putValue("Bundle-SymbolicName", m.getCodeNameBase()); // NOI18N
123
124
        if (m.getSpecificationVersion() != null) {
125
            String spec = threeDotsWithMajor(m.getSpecificationVersion().toString(), m.getCodeName());
126
            man.getMainAttributes().putValue("Bundle-Version", spec.toString()); // NOI18N
127
        }
128
        if (exp != null) {
129
            man.getMainAttributes().putValue("Export-Package", exp.replaceAll("\\.\\*", "")); // NOI18N
130
        } else {
131
            man.getMainAttributes().putValue("Export-Package", m.getCodeNameBase()); // NOI18N
132
        }
133
        man.write(os);
134
        return new ByteArrayInputStream(os.toByteArray());
135
    }
136
    private static String threeDotsWithMajor(String version, String withMajor) {
137
        int indx = withMajor.indexOf('/');
138
        int major = 0;
139
        if (indx > 0) {
140
            major = Integer.parseInt(withMajor.substring(indx + 1));
141
        }
142
        String[] segments = (version + ".0.0.0").split("\\.");
143
        assert segments.length >= 3 && segments[0].length() > 0;
144
145
        return (Integer.parseInt(segments[0]) + major * 100) + "."  + segments[1] + "." + segments[2];
146
    }
147
}
(-)5cee832cf3ae (+7 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-SymbolicName: org.activate
3
Bundle-Version: 1.2
4
Import-Package: org.osgi.framework
5
Bundle-Activator: org.activate.Main
6
OpenIDE-Module-Layer: org/activate/layer.xml
7
(-)5cee832cf3ae (+85 lines)
Added Link Here
1
package org.activate;
2
3
import java.io.BufferedReader;
4
import java.io.InputStreamReader;
5
import java.net.URL;
6
import java.net.URLConnection;
7
import java.util.logging.Level;
8
import java.util.logging.Logger;
9
import org.osgi.framework.BundleActivator;
10
import org.osgi.framework.BundleContext;
11
12
public class Main implements BundleActivator {
13
    public static BundleContext start;
14
    public static BundleContext stop;
15
    public static ClassLoader loader;
16
    private static final Logger LOG = Logger.getLogger(Main.class.getName());
17
18
    public void start(BundleContext bc) throws Exception {
19
        LOG.log(Level.INFO, "start {0}", bc);
20
        assert start == null;
21
        start = bc;
22
        final String v = System.getProperty("activated.count");
23
        if (v != null) {
24
            int x = Integer.parseInt(v);
25
            System.setProperty("activated.count", "" + (x + 1));
26
        }
27
        System.setProperty("activated.ok", "true");
28
        loader = Thread.currentThread().getContextClassLoader();
29
        String t = System.getProperty("activated.throw");
30
        if (t != null) {
31
            LOG.log(Level.INFO, "Throwing exception {0}", t);
32
            throw new IllegalStateException(t);
33
        }
34
        LOG.info("start finished");
35
        
36
        String lib = System.getProperty("activated.library");
37
        if (lib != null) {
38
            try {
39
                System.loadLibrary(lib);
40
                throw new IllegalStateException("Library " + lib + " should not be available");
41
            } catch (UnsatisfiedLinkError ex) {
42
                System.setProperty("activated.library", ex.getMessage());
43
            }
44
        }
45
                
46
47
        String seekFor = System.getProperty("activated.checkentries");
48
        if (seekFor != null) {
49
            LOG.info("loading bundleentry:");
50
            URL u = getClass().getResource(seekFor);
51
            assert "bundleresource".equals(u.getProtocol()) : "Protocol: " + u.getProtocol();
52
            BufferedReader r = new BufferedReader(new InputStreamReader(u.openStream()));
53
            String c = r.readLine();
54
            r.close();
55
            System.setProperty("activated.entry", c);
56
            LOG.log(Level.INFO, "entry loaded: {0}", c);
57
58
            URLConnection buc = u.openConnection();
59
            System.setProperty("activated.entry.local", ((URL)call(buc, "getLocalURL")).toExternalForm());
60
            System.setProperty("activated.entry.file", ((URL)call(buc, "getFileURL")).toExternalForm());
61
62
            LOG.log(Level.INFO, "BundleURLConnection is OK");
63
        }
64
    }
65
66
    public void stop(BundleContext bc) throws Exception {
67
        LOG.log(Level.INFO, "stop {0}", bc);
68
        assert stop == null;
69
        stop = bc;
70
    }
71
    
72
    private static Object call(Object obj, String name) throws Exception {
73
        Class<?> c = obj.getClass();
74
        return c.getMethod(name).invoke(obj);
75
    }
76
    
77
    public static Class<?> loadClass(String name, ClassLoader ldr) throws ClassNotFoundException {
78
        LOG.log(Level.INFO, "Trying to load from {0} class named: {1}", new Object[]{ldr, name});
79
        if (ldr == null) {
80
            return Class.forName(name);
81
        }
82
        return Class.forName(name, true, ldr);
83
    }
84
}
85
(-)5cee832cf3ae (+1 lines)
Added Link Here
1
Ahoj
(-)5cee832cf3ae (+4 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
3
<filesystem>
4
</filesystem>
(-)5cee832cf3ae (+5 lines)
Added Link Here
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.bar2/1
3
OpenIDE-Module-Name: Depends on foo test module #2
4
OpenIDE-Module-Module-Dependencies: org.foo/1
5
(-)5cee832cf3ae (+5 lines)
Added Link Here
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.bar/1
3
OpenIDE-Module-Name: Depends on foo test module
4
OpenIDE-Module-Module-Dependencies: org.foo/1
5
(-)5cee832cf3ae (+7 lines)
Added Link Here
1
package org.bar;
2
import org.foo.Something;
3
public class SomethingElse extends Something {
4
    public String message() {
5
        return something();
6
    }
7
}
(-)5cee832cf3ae (+47 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
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.  Sun designates this
19
particular file as subject to the "Classpath" exception as provided
20
by Sun 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
Contributor(s):
27
28
The Original Software is NetBeans. The Initial Developer of the Original
29
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
30
Microsystems, Inc. All Rights Reserved.
31
32
If you wish your version of this file to be governed by only the CDDL
33
or only the GPL Version 2, indicate your decision by adding
34
"[Contributor] elects to include this software in this distribution
35
under the [CDDL or GPL Version 2] license." If you do not indicate a
36
single choice of license, a recipient has the option to distribute
37
your version of this file under either the CDDL, the GPL Version 2 or
38
to extend the choice of license to its licensees as provided above.
39
However, if you add GPL Version 2 code and therefore, elected the GPL
40
Version 2 license, then the option applies only if the new code is
41
made subject to such option by the copyright holder.
42
-->
43
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
44
<filesystem>
45
    <folder name="TestImplFolder">
46
    </folder>
47
</filesystem>
(-)5cee832cf3ae (+47 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
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.  Sun designates this
19
particular file as subject to the "Classpath" exception as provided
20
by Sun 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
Contributor(s):
27
28
The Original Software is NetBeans. The Initial Developer of the Original
29
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
30
Microsystems, Inc. All Rights Reserved.
31
32
If you wish your version of this file to be governed by only the CDDL
33
or only the GPL Version 2, indicate your decision by adding
34
"[Contributor] elects to include this software in this distribution
35
under the [CDDL or GPL Version 2] license." If you do not indicate a
36
single choice of license, a recipient has the option to distribute
37
your version of this file under either the CDDL, the GPL Version 2 or
38
to extend the choice of license to its licensees as provided above.
39
However, if you add GPL Version 2 code and therefore, elected the GPL
40
Version 2 license, then the option applies only if the new code is
41
made subject to such option by the copyright holder.
42
-->
43
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
44
<filesystem>
45
    <folder name="TestFolder">
46
    </folder>
47
</filesystem>
(-)5cee832cf3ae (+8 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-SymbolicName: org.external
3
Bundle-Version: 2.33
4
Import-Package: org.osgi.framework
5
Bundle-Activator: org.activate.Main
6
OpenIDE-Module-Layer: org/activate/layer.xml
7
Bundle-ClassPath: external:$ext.dir$/ext.jar
8
(-)5cee832cf3ae (+8 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-SymbolicName: org.externaldir
3
Bundle-Version: 2.33
4
Import-Package: org.osgi.framework
5
Bundle-Activator: org.activate.Main
6
OpenIDE-Module-Layer: org/activate/layer.xml
7
Bundle-ClassPath: external:$ext.dir$/activate/
8
(-)5cee832cf3ae (+5 lines)
Added Link Here
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.hook
3
OpenIDE-Module-Module-Dependencies: org.netbeans.modules.netbinox > 1.16.7
4
OpenIDE-Module-Specification-Version: 1.2
5
OpenIDE-Module-Public-Packages: - 
(-)5cee832cf3ae (+14 lines)
Added Link Here
1
package org.activate;
2
3
import org.eclipse.osgi.baseadaptor.HookConfigurator;
4
import org.eclipse.osgi.baseadaptor.HookRegistry;
5
import org.openide.util.lookup.ServiceProvider;
6
7
@ServiceProvider(service=HookConfigurator.class)
8
public class Main implements HookConfigurator {
9
    public void addHooks(HookRegistry hr) {
10
        assert hr != null;
11
        System.setProperty("main.hook", "true");
12
    }
13
}
14
(-)5cee832cf3ae (+5 lines)
Added Link Here
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.foo/1
3
OpenIDE-Module-Name: Foo test module
4
OpenIDE-Module-Specification-Version: 1.2
5
(-)5cee832cf3ae (+20 lines)
Added Link Here
1
package org.foo;
2
// Does not do anything, just needs to be here & loadable.
3
4
import java.util.logging.Level;
5
import java.util.logging.Logger;
6
7
public class Something {
8
    protected String something() {
9
        return "hello";
10
    }
11
12
    private static final Logger LOG = Logger.getLogger(Something.class.getName());
13
    public static Class<?> loadClass(String name, ClassLoader ldr) throws ClassNotFoundException {
14
        LOG.log(Level.INFO, "Trying to load from {0} class named: {1}", new Object[]{ldr, name});
15
        if (ldr == null) {
16
            return Class.forName(name);
17
        }
18
        return Class.forName(name, true, ldr);
19
    }
20
}
(-)5cee832cf3ae (+6 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-SymbolicName: org.barwing
3
Bundle-Version: 1.2
4
Import-Package: javax.swing
5
6
(-)5cee832cf3ae (+8 lines)
Added Link Here
1
package org.barwing;
2
import javax.swing.JFrame;
3
public class Main extends JFrame implements Runnable {
4
    public void run() {
5
        new Main().setVisible(true);
6
    }
7
}
8
(-)5cee832cf3ae (+27 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 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") (the
8
 * "License"). You may not use this file except in compliance with the
9
 * License. 
10
 *
11
 * Contributor(s):
12
 *
13
 * The Original Software is NetBeans. The Initial Developer of the Original
14
 * Software is Sun Microsystems, Inc. Portions Copyright 2009 Sun
15
 * Microsystems, Inc. All Rights Reserved.
16
 *
17
 * Jaroslav Tulach elects to include this software in this distribution
18
 * under the GPL Version 2 license.
19
 */
20
21
package org.netbeans;
22
23
public final class MockEvents extends Events {
24
25
    protected void logged(String message, Object[] args) {}
26
27
}
(-)5cee832cf3ae (+82 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 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") (the
8
 * "License"). You may not use this file except in compliance with the
9
 * License.
10
 *
11
 * Contributor(s):
12
 *
13
 * The Original Software is NetBeans. The Initial Developer of the Original
14
 * Software is Sun Microsystems, Inc. Portions Copyright 2009 Sun
15
 * Microsystems, Inc. All Rights Reserved.
16
 *
17
 * Jaroslav Tulach elects to include this software in this distribution
18
 * under the GPL Version 2 license.
19
 */
20
21
package org.netbeans;
22
23
import java.util.ArrayList;
24
import java.util.HashSet;
25
import java.util.List;
26
import java.util.Set;
27
28
public class MockModuleInstaller extends ModuleInstaller {
29
30
    // For examining results of what happened:
31
    public final List<String> actions = new ArrayList<String>();
32
    public final List<Object> args = new ArrayList<Object>();
33
34
    public void clear() {
35
        actions.clear();
36
        args.clear();
37
    }
38
    // For adding invalid modules:
39
    public final Set<Module> delinquents = new HashSet<Module>();
40
    // For adding modules that don't want to close:
41
    public final Set<Module> wontclose = new HashSet<Module>();
42
43
    public void prepare(Module m) throws InvalidException {
44
        if (delinquents.contains(m)) {
45
            throw new InvalidException(m, "not supposed to be installed");
46
        }
47
        actions.add("prepare");
48
        args.add(m);
49
    }
50
51
    public void dispose(Module m) {
52
        actions.add("dispose");
53
        args.add(m);
54
    }
55
56
    public void load(List<Module> modules) {
57
        actions.add("load");
58
        args.add(new ArrayList<Module>(modules));
59
    }
60
61
    public void unload(List<Module> modules) {
62
        actions.add("unload");
63
        args.add(new ArrayList<Module>(modules));
64
    }
65
66
    public boolean closing(List<Module> modules) {
67
        actions.add("closing");
68
        args.add(new ArrayList<Module>(modules));
69
        for (Module m : modules) {
70
            if (wontclose.contains(m)) {
71
                return false;
72
            }
73
        }
74
        return true;
75
    }
76
77
    public void close(List<Module> modules) {
78
        actions.add("close");
79
        args.add(new ArrayList<Module>(modules));
80
    }
81
82
}
(-)5cee832cf3ae (+436 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 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") (the
8
 * "License"). You may not use this file except in compliance with the
9
 * License.
10
 *
11
 * Contributor(s):
12
 *
13
 * The Original Software is NetBeans. The Initial Developer of the Original
14
 * Software is Sun Microsystems, Inc. Portions Copyright 2009 Sun
15
 * Microsystems, Inc. All Rights Reserved.
16
 *
17
 * Jaroslav Tulach elects to include this software in this distribution
18
 * under the GPL Version 2 license.
19
 */
20
21
package org.netbeans;
22
23
import java.io.ByteArrayOutputStream;
24
import java.io.File;
25
import java.io.FileInputStream;
26
import java.io.FileNotFoundException;
27
import java.io.FileOutputStream;
28
import java.io.IOException;
29
import java.io.InputStream;
30
import java.io.OutputStream;
31
import java.util.ArrayList;
32
import java.util.Arrays;
33
import java.util.Iterator;
34
import java.util.List;
35
import java.util.Locale;
36
import java.util.Map;
37
import java.util.jar.JarEntry;
38
import java.util.jar.JarOutputStream;
39
import java.util.jar.Manifest;
40
import java.util.logging.Level;
41
import java.util.zip.CRC32;
42
import javax.tools.JavaCompiler;
43
import javax.tools.StandardJavaFileManager;
44
import javax.tools.ToolProvider;
45
import org.netbeans.junit.NbTestCase;
46
47
/** Some infrastructure for module system tests.
48
 * @author Jesse Glick
49
 */
50
public abstract class SetupHid extends NbTestCase {
51
52
53
    public SetupHid(String name) {
54
        super(name);
55
    }
56
57
    /** directory of data files for JARs */
58
    protected File data;
59
    /** directory full of JAR files to test */
60
    protected File jars;
61
    /** shall the generated JARs have all dir entries? */
62
    protected static boolean generateAllDirs;
63
64
    protected @Override void setUp() throws Exception {
65
        Locale.setDefault(Locale.US);
66
        clearWorkDir();
67
        data = new File(getDataDir(), "jars");
68
        jars = new File(getWorkDir(), "jars");
69
        jars.mkdirs();
70
        createTestJARs();
71
        
72
        File ud = new File(getWorkDir(), "ud");
73
        ud.mkdirs();
74
        
75
        System.setProperty("netbeans.user", ud.getPath());
76
    }
77
78
    @Override
79
    protected Level logLevel() {
80
        return Level.FINE;
81
    }
82
83
    protected static void deleteRec(File f) throws IOException {
84
        if (f.isDirectory()) {
85
            File[] kids = f.listFiles();
86
            if (kids == null) throw new IOException("Could not list: " + f);
87
            for (int i = 0; i < kids.length; i++) {
88
                deleteRec(kids[i]);
89
            }
90
        }
91
        if (! f.delete()) throw new IOException("Could not delete: " + f);
92
    }
93
94
    /** same as FileUtil.copy */
95
    protected static void copyStreams(InputStream is, OutputStream os) throws IOException {
96
        final byte[] BUFFER = new byte[4096];
97
        int len;
98
        for (;;) {
99
            len = is.read(BUFFER);
100
            if (len == -1) {
101
                return;
102
            }
103
            os.write(BUFFER, 0, len);
104
        }
105
    }
106
107
    protected static void copy(File a, File b) throws IOException {
108
        OutputStream os = new FileOutputStream(b);
109
        try {
110
            copyStreams(new FileInputStream(a), os);
111
        } finally {
112
            os.close();
113
        }
114
    }
115
116
    /**
117
     * Create a fresh JAR file.
118
     * @param jar the file to create
119
     * @param contents keys are JAR entry paths, values are text contents (will be written in UTF-8)
120
     * @param manifest a manifest to store (key/value pairs for main section)
121
     */
122
    public static void createJar(File jar, Map<String,String> contents, Map<String,String> manifest) throws IOException {
123
        // XXX use TestFileUtils.writeZipFile
124
        Manifest m = new Manifest();
125
        m.getMainAttributes().putValue("Manifest-Version", "1.0"); // workaround for JDK bug
126
        for (Map.Entry<String,String> line : manifest.entrySet()) {
127
            m.getMainAttributes().putValue(line.getKey(), line.getValue());
128
        }
129
        jar.getParentFile().mkdirs();
130
        OutputStream os = new FileOutputStream(jar);
131
        try {
132
            JarOutputStream jos = new JarOutputStream(os, m);
133
            Iterator it = contents.entrySet().iterator();
134
            while (it.hasNext()) {
135
                Map.Entry entry = (Map.Entry) it.next();
136
                String path = (String) entry.getKey();
137
                byte[] data = ((String) entry.getValue()).getBytes("UTF-8");
138
                JarEntry je = new JarEntry(path);
139
                je.setSize(data.length);
140
                CRC32 crc = new CRC32();
141
                crc.update(data);
142
                je.setCrc(crc.getValue());
143
                jos.putNextEntry(je);
144
                jos.write(data);
145
            }
146
            jos.close();
147
        } finally {
148
            os.close();
149
        }
150
    }
151
152
    private void createTestJARs() throws IOException {
153
        File simpleModule = createTestJAR("simple-module", null);
154
        File dependsOnSimpleModule = createTestJAR("depends-on-simple-module", null, simpleModule);
155
        createTestJAR("dep-on-dep-on-simple", null, simpleModule, dependsOnSimpleModule);
156
        File cyclic1;
157
        { // cyclic-1
158
            File cyclic1Src = new File(data, "cyclic-1");
159
            File cyclic2Src = new File(data, "cyclic-2");
160
            compile(Arrays.asList(
161
                    "-sourcepath", cyclic1Src + File.pathSeparator + cyclic2Src,
162
                    "-d", cyclic1Src.getAbsolutePath()),
163
                    findSourceFiles(cyclic1Src, cyclic2Src));
164
            cyclic1 = new File(jars, "cyclic-1.jar");
165
            OutputStream os = new FileOutputStream(cyclic1);
166
            try {
167
                JarOutputStream jos = new JarOutputStream(os, loadManifest(new File(data, "cyclic-1.mf")));
168
                try {
169
                    jarUp(jos, new File(cyclic1Src, "org/foo"), "org/foo/");
170
                } finally {
171
                    jos.close();
172
                }
173
            } finally {
174
                os.close();
175
            }
176
        }
177
        File cyclic2 = createTestJAR("cyclic-2", null, cyclic1);
178
        createTestJAR("depends-on-cyclic-1", null, cyclic1, cyclic2);
179
        File libraryUndecl = createTestJAR("library-undecl", "library-src");
180
        createTestJAR("library-unvers", "library-src");
181
        createTestJAR("library-vers", "library-src");
182
        createTestJAR("library-vers-partial", "library-src");
183
        createTestJAR("depends-on-lib-undecl", "depends-on-library-src", libraryUndecl);
184
        createTestJAR("depends-on-lib-unvers", "depends-on-library-src", libraryUndecl);
185
        createTestJAR("depends-on-lib-vers", "depends-on-library-src", libraryUndecl);
186
        createTestJAR("depends-on-lib-vers-partial", "depends-on-library-src", libraryUndecl);
187
        createTestJAR("fails-on-lib-undecl", "depends-on-library-src", libraryUndecl);
188
        createTestJAR("fails-on-non-existing-package", "depends-on-library-src", libraryUndecl);
189
        createTestJAR("fails-on-lib-unvers", "depends-on-library-src", libraryUndecl);
190
        createTestJAR("fails-on-lib-old", "depends-on-library-src", libraryUndecl);
191
        createTestJAR("prov-foo", null);
192
        createTestJAR("req-foo", null);
193
        createTestJAR("prov-foo-bar", null);
194
        createTestJAR("req-foo-baz", null);
195
        createTestJAR("prov-baz", null);
196
        createTestJAR("prov-foo-req-bar", null);
197
        createTestJAR("prov-bar-req-foo", null);
198
        createTestJAR("prov-bar-dep-cyclic", null);
199
        createTestJAR("rel-ver-2", null);
200
        createTestJAR("dep-on-relvertest-1", null);
201
        createTestJAR("dep-on-relvertest-1-2", null);
202
        createTestJAR("dep-on-relvertest-1-2-nospec", null);
203
        createTestJAR("dep-on-relvertest-2", null);
204
        createTestJAR("dep-on-relvertest-2-3", null);
205
        createTestJAR("dep-on-relvertest-2-3-late", null);
206
        createTestJAR("dep-on-relvertest-2-impl", null);
207
        createTestJAR("dep-on-relvertest-2-impl-wrong", null);
208
        createTestJAR("dep-on-relvertest-2-late", null);
209
        createTestJAR("dep-on-relvertest-3-4", null);
210
        createTestJAR("dep-on-relvertest-some", null);
211
        createTestJAR("depends-on-simple-module-2", null);
212
        createTestJAR("needs-foo", null);
213
        createTestJAR("recommends-foo", null);
214
        createTestJAR("prov-foo-depends-needs_foo", "prov-foo");
215
        createTestJAR("api-mod-export-all", "exposes-api");
216
        createTestJAR("api-mod-export-none", "exposes-api");
217
        File exposesAPI = createTestJAR("api-mod-export-api", "exposes-api");
218
        createTestJAR("api-mod-export-friend", "exposes-api");
219
        createTestJAR("uses-api-simple-dep", "uses-api", exposesAPI);
220
        createTestJAR("uses-api-impl-dep", "uses-api", exposesAPI);
221
        createTestJAR("uses-api-impl-dep-for-friends", "uses-api", exposesAPI);
222
        createTestJAR("uses-api-spec-dep", "uses-api", exposesAPI);
223
        createTestJAR("dep-on-two-modules", null);
224
        File usesAPI = createTestJAR("uses-and-exports-api", "uses-api", exposesAPI);
225
        createTestJAR("uses-api-transitively", null, exposesAPI, usesAPI);
226
        createTestJAR("uses-api-directly", "uses-api-transitively", exposesAPI, usesAPI);
227
        createTestJAR("uses-api-transitively-old", "uses-api-transitively", exposesAPI, usesAPI);
228
        createTestJAR("uses-api-directly-old", "uses-api-transitively", exposesAPI, usesAPI);
229
        createTestJAR("look-for-myself", null);
230
        createTestJAR("uses-api-friend", "uses-api", exposesAPI);
231
        createTestJAR("little-manifest", null);
232
        createTestJAR("medium-manifest", null);
233
        createTestJAR("big-manifest", null);
234
        createTestJAR("patchable", null);
235
        { // Make the patch JAR specially:
236
            File src = new File(data, "patch");
237
            String srcS = src.getAbsolutePath();
238
            compile(Arrays.asList("-sourcepath", srcS, "-d", srcS), findSourceFiles(src));
239
            File jar = new File(jars, "patches/pkg-subpkg/some-patch.jar");
240
            jar.getParentFile().mkdirs();
241
            OutputStream os = new FileOutputStream(jar);
242
            try {
243
                JarOutputStream jos = new JarOutputStream(os, loadManifest(null));
244
                try {
245
                    jarUp(jos, src, "");
246
                } finally {
247
                    jos.close();
248
                }
249
            } finally {
250
                os.close();
251
            }
252
        }
253
        File locale = new File(jars, "locale");
254
        locale.mkdirs();
255
        {
256
            OutputStream os = new FileOutputStream(new File(jars, "localized-manifest.jar"));
257
            try {
258
                JarOutputStream jos = new JarOutputStream(os, loadManifest(new File(data, "localized-manifest.mf")));
259
                try {
260
                    writeJarEntry(jos, "locmani/Bundle.properties", new File(data, "localized-manifest/locmani/Bundle.properties"));
261
                } finally {
262
                    jos.close();
263
                }
264
            } finally {
265
                os.close();
266
            }
267
            os = new FileOutputStream(new File(locale, "localized-manifest_cs.jar"));
268
            try {
269
                JarOutputStream jos = new JarOutputStream(os, loadManifest(null));
270
                try {
271
                    writeJarEntry(jos, "locmani/Bundle_cs.properties", new File(data, "localized-manifest/locmani/Bundle_cs.properties"));
272
                } finally {
273
                    jos.close();
274
                }
275
            } finally {
276
                os.close();
277
            }
278
        }
279
        {
280
            OutputStream os = new FileOutputStream(new File(jars, "base-layer-mod.jar"));
281
            try {
282
                JarOutputStream jos = new JarOutputStream(os, loadManifest(new File(data, "base-layer-mod.mf")));
283
                try {
284
                    writeJarEntry(jos, "baselayer/layer.xml", new File(data, "base-layer-mod/baselayer/layer.xml"));
285
                } finally {
286
                    jos.close();
287
                }
288
            } finally {
289
                os.close();
290
            }
291
            os = new FileOutputStream(new File(locale, "base-layer-mod_cs.jar"));
292
            try {
293
                JarOutputStream jos = new JarOutputStream(os, loadManifest(null));
294
                try {
295
                    writeJarEntry(jos, "baselayer/layer_cs.xml", new File(data, "base-layer-mod/baselayer/layer_cs.xml"));
296
                } finally {
297
                    jos.close();
298
                }
299
            } finally {
300
                os.close();
301
            }
302
            os = new FileOutputStream(new File(locale, "base-layer-mod_foo.jar"));
303
            try {
304
                JarOutputStream jos = new JarOutputStream(os, loadManifest(null));
305
                try {
306
                    writeJarEntry(jos, "baselayer/layer_foo.xml", new File(data, "base-layer-mod/baselayer/layer_foo.xml"));
307
                } finally {
308
                    jos.close();
309
                }
310
            } finally {
311
                os.close();
312
            }
313
            createTestJAR("override-layer-mod", null);
314
        }
315
    }
316
    private static void compile(List<String> options, Iterable<File> files) throws IOException {
317
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
318
        StandardJavaFileManager mgr = compiler.getStandardFileManager(null, null, null);
319
        List<String> fullOptions = new ArrayList<String>(options);
320
        fullOptions.addAll(Arrays.asList("-source", "1.5", "-target", "1.5"));
321
        if (!compiler.getTask(null, mgr, null, fullOptions, null, mgr.getJavaFileObjectsFromFiles(files)).call()) {
322
            throw new IOException("compilation failed");
323
        }
324
    }
325
    private File createTestJAR(String name, String srcdir, File... classpath) throws IOException {
326
        return createTestJAR(data, jars, name, srcdir, classpath);
327
    }
328
    public static File createTestJAR(File data, File jars, String name, String srcdir, File... classpath) throws IOException {
329
        File srcdirF = null;
330
        File d = new File(data, srcdir != null ? srcdir : name);
331
        if (d.isDirectory()) {
332
            srcdirF = d;
333
        }
334
        File manifestF = null;
335
        File f = new File(data, name + ".mf");
336
        if (f.isFile()) {
337
            manifestF = f;
338
        }
339
        if (srcdirF != null) {
340
            assert srcdirF.isDirectory();
341
            List<File> sourceFiles = findSourceFiles(srcdirF);
342
            if (!sourceFiles.isEmpty()) {
343
                StringBuilder cp = new StringBuilder(System.getProperty("java.class.path")); // o.o.util, o.o.modules
344
                for (File j : classpath) {
345
                    cp.append(File.pathSeparatorChar);
346
                    cp.append(j);
347
                }
348
                compile(Arrays.asList(
349
                        "-classpath", cp.toString(),
350
                        "-sourcepath", srcdirF.getAbsolutePath(),
351
                        "-d", srcdirF.getAbsolutePath()),
352
                        sourceFiles);
353
            }
354
        }
355
        // Cannot trivially use TestFileUtils.writeZipFile here since we have binary content (classes).
356
        File jar = new File(jars, name + ".jar");
357
        jars.mkdirs();
358
        OutputStream os = new FileOutputStream(jar);
359
        try {
360
            JarOutputStream jos = new JarOutputStream(os, loadManifest(manifestF));
361
            try {
362
                if (srcdirF != null) {
363
                    jarUp(jos, srcdirF, "");
364
                }
365
            } finally {
366
                jos.close();
367
            }
368
        } finally {
369
            os.close();
370
        }
371
        return jar;
372
    }
373
    private static Manifest loadManifest(File mani) throws IOException {
374
        Manifest m = new Manifest();
375
        if (mani != null) {
376
            InputStream is = new FileInputStream(mani);
377
            try {
378
                m.read(is);
379
            } finally {
380
                is.close();
381
            }
382
        }
383
        m.getMainAttributes().putValue("Manifest-Version", "1.0"); // workaround for JDK bug
384
        return m;
385
    }
386
    private static List<File> findSourceFiles(File... roots) {
387
        List<File> sourceFiles = new ArrayList<File>();
388
        for (File root : roots) {
389
            doFindSourceFiles(sourceFiles, root);
390
        }
391
        return sourceFiles;
392
    }
393
    private static void doFindSourceFiles(List<File> sourceFiles, File srcdir) {
394
        for (File k : srcdir.listFiles()) {
395
            if (k.getName().endsWith(".java")) {
396
                sourceFiles.add(k);
397
            } else if (k.isDirectory()) {
398
                doFindSourceFiles(sourceFiles, k);
399
            }
400
        }
401
    }
402
    private static void jarUp(JarOutputStream jos, File dir, String prefix) throws IOException {
403
        for (File f : dir.listFiles()) {
404
            String path = prefix + f.getName();
405
            if (f.getName().endsWith(".java")) {
406
                continue;
407
            } else if (f.isDirectory()) {
408
                if (generateAllDirs) {
409
                    JarEntry je = new JarEntry(path + "/");
410
                    jos.putNextEntry(je);
411
                }
412
                jarUp(jos, f, path + "/");
413
            } else {
414
                writeJarEntry(jos, path, f);
415
            }
416
        }
417
    }
418
    private static void writeJarEntry(JarOutputStream jos, String path, File f) throws IOException, FileNotFoundException {
419
        JarEntry je = new JarEntry(path);
420
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
421
        InputStream is = new FileInputStream(f);
422
        try {
423
            copyStreams(is, baos);
424
        } finally {
425
            is.close();
426
        }
427
        byte[] data = baos.toByteArray();
428
        je.setSize(data.length);
429
        CRC32 crc = new CRC32();
430
        crc.update(data);
431
        je.setCrc(crc.getValue());
432
        jos.putNextEntry(je);
433
        jos.write(data);
434
    }
435
436
}
(-)5cee832cf3ae (+121 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2010 Jaroslav Tulach <jtulach@netbeans.org>
3
 * 
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; either version 2
7
 *  of the License, or (at your option) any later version.
8
 * 
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 * 
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.awt.GraphicsEnvironment;
22
import java.io.BufferedReader;
23
import java.io.File;
24
import java.io.InputStreamReader;
25
import java.lang.reflect.Method;
26
import java.net.URL;
27
import java.util.logging.Level;
28
import junit.framework.Test;
29
import org.netbeans.modules.netbinox.ContextClassLoaderTest.Compile;
30
import org.netbeans.Module;
31
import org.netbeans.ModuleManager;
32
import org.netbeans.NetigsoFramework;
33
import org.netbeans.core.startup.Main;
34
import org.netbeans.junit.NbModuleSuite;
35
import org.netbeans.junit.NbTestCase;
36
import org.netbeans.junit.NbTestSuite;
37
import org.openide.util.Lookup;
38
import org.osgi.framework.Bundle;
39
import org.osgi.framework.launch.Framework;
40
41
/**
42
 *
43
 * @author Jaroslav Tulach <jtulach@netbeans.org>
44
 */
45
public class BundleURLConnectionTest extends NbTestCase {
46
    static {
47
        System.setProperty("java.awt.headless", "true");
48
    }
49
    
50
    public BundleURLConnectionTest(String name) {
51
        super(name);
52
    }
53
54
    public static Test suite() {
55
        System.setProperty("java.awt.headless", "true");
56
        assertTrue("In headless mode", GraphicsEnvironment.isHeadless());
57
        NbTestSuite s = new NbTestSuite();
58
        s.addTest(new Compile("testCompileJAR"));
59
        s.addTest(NbModuleSuite.create(
60
            NbModuleSuite.emptyConfiguration().addTest(
61
                BundleURLConnectionTest.class
62
            ).honorAutoloadEager(true).failOnException(Level.WARNING)/*.failOnMessage(Level.WARNING)*/
63
            .gui(false)
64
        ));
65
        return s;
66
    }
67
68
    public void testVariousURLs() throws Exception {
69
        File j1 = new File(System.getProperty("activate.jar"));
70
        assertTrue("File " + j1 + " exists", j1.exists());
71
        
72
        ModuleManager mgr = Main.getModuleSystem().getManager();
73
        mgr.mutexPrivileged().enterWriteAccess();
74
        Module m1;
75
        m1 = mgr.create(j1, null, false, false, false);
76
        System.setProperty("activated.checkentries", "/org/activate/entry.txt");
77
        mgr.enable(m1);
78
79
        assertTrue("OSGi module is now enabled", m1.isEnabled());
80
        mgr.mutexPrivileged().exitWriteAccess();
81
82
        Object obj = Lookup.getDefault().lookup(NetigsoFramework.class);
83
        final Method m = obj.getClass().getDeclaredMethod("getFramework");
84
        m.setAccessible(true);
85
        Framework w = (Framework) m.invoke(obj);
86
        assertNotNull("Framework found", w);
87
        assertEquals("Felix is not in its name", -1, w.getClass().getName().indexOf("felix"));
88
        StringBuilder sb = new StringBuilder();
89
        boolean found = false;
90
        for (Bundle b : w.getBundleContext().getBundles()) {
91
            sb.append("\n").append(b.getSymbolicName());
92
            if (b.getSymbolicName().equals("org.eclipse.osgi")) {
93
                found = true;
94
                break;
95
            }
96
        }
97
        if (!found) {
98
            fail("Expecting equinox among list of enabled bundles:" + sb);
99
        }
100
        String text = System.getProperty("activated.entry");
101
        assertEquals("Ahoj", text);
102
        
103
        
104
        String localURL = System.getProperty("activated.entry.local");
105
        assertNotNull("bundleentry read OK", localURL);
106
        // <[jar:file:/home/jarda/src/netbeans/netbinox/netbinox/build/test/unit/work/o.a.n.C/testCompileJAR/jars/activate.jar!/org/activate/entry.txt]>
107
        assertEquals("Ahoj", readLine(localURL));
108
        
109
        String fileURL = System.getProperty("activated.entry.file");
110
        assertNotNull("fileURL found", fileURL);
111
        // file:/home/jarda/src/netbeans/netbinox/netbinox/build/test/unit/work/userdir0/var/cache/netigso/org.eclipse.osgi/bundles/46/1/.cp/org/activate/entry.txt
112
        assertEquals("Ahoj", readLine(fileURL));
113
    }
114
    
115
    static String readLine(String url) throws Exception {
116
        assertNotNull("url cannot be null", url);
117
        URL u = new URL(url);
118
        BufferedReader r = new BufferedReader(new InputStreamReader(u.openStream()));
119
        return r.readLine();
120
    }
121
}
(-)5cee832cf3ae (+252 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2009 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
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.netbinox;
43
44
import java.io.File;
45
import java.io.IOException;
46
import java.io.OutputStream;
47
import java.util.HashSet;
48
import java.util.Locale;
49
import java.util.Set;
50
import java.util.logging.Level;
51
import java.util.logging.Logger;
52
import junit.framework.Test;
53
import org.netbeans.SetupHid;
54
import org.netbeans.junit.NbModuleSuite;
55
import org.netbeans.junit.NbTestCase;
56
import org.netbeans.junit.NbTestSuite;
57
import org.openide.filesystems.FileObject;
58
import org.openide.filesystems.FileSystem;
59
import org.openide.filesystems.FileUtil;
60
import org.openide.util.Lookup;
61
62
/**
63
 * Read access test
64
 * see details on http://wiki.netbeans.org/FitnessViaWhiteAndBlackList
65
 */
66
public class CachingAndExternalPathsTest extends NbTestCase {
67
    static {
68
        System.setProperty("java.awt.headless", "true");
69
    }
70
    private static final Logger LOG = Logger.getLogger(CachingAndExternalPathsTest.class.getName());
71
72
    private static void initCheckReadAccess() throws IOException {
73
        Set<String> allowedFiles = new HashSet<String>();
74
        CountingSecurityManager.initialize(null, CountingSecurityManager.Mode.CHECK_READ, allowedFiles);
75
    }
76
    
77
    public CachingAndExternalPathsTest(String name) {
78
        super(name);
79
    }
80
    
81
    public static Test suite() throws IOException {
82
        return create(new SetExtDirProperty() {
83
            public void setExtDirProperty(File value) {
84
                System.setProperty("ext.dir", value.getPath());
85
            }
86
        });
87
    }
88
    static Test create(SetExtDirProperty setter) throws IOException {
89
        Locale.setDefault(Locale.US);
90
        CountingSecurityManager.initialize("none", CountingSecurityManager.Mode.CHECK_READ, null);
91
        System.setProperty("org.netbeans.Stamps.level", "ALL");
92
        System.setProperty(NbModuleSuite.class.getName() + ".level", "FINE");
93
        System.setProperty("org.netbeans.modules.netbinox.level", "FINE");
94
95
        NbTestSuite suite = new NbTestSuite();
96
        Compile compile = new Compile("testCompile", setter);
97
        suite.addTest(compile);
98
        NbModuleSuite.Configuration common = NbModuleSuite.emptyConfiguration().clusters(".*").enableClasspathModules(false)
99
                .gui(false).honorAutoloadEager(true);
100
        {
101
            NbModuleSuite.Configuration conf = common.reuseUserDir(false).addTest(CachingAndExternalPathsTest.class, "testInitUserDir");
102
            suite.addTest(NbModuleSuite.create(conf));
103
        }
104
        {
105
            NbModuleSuite.Configuration conf = common.reuseUserDir(true).addTest(CachingAndExternalPathsTest.class, "testStartAgain");
106
            suite.addTest(NbModuleSuite.create(conf));
107
        }
108
109
        suite.addTest(new CachingAndExternalPathsTest("testInMiddle"));
110
111
        {
112
            NbModuleSuite.Configuration conf = common.reuseUserDir(true).addTest(CachingAndExternalPathsTest.class, "testReadAccess", "testVerifyActivatorExecuted");
113
            suite.addTest(NbModuleSuite.create(conf));
114
        }
115
116
        return suite;
117
    }
118
119
    public void testInitUserDir() throws Exception {
120
        File simpleModule = new File(System.getProperty("external.jar"));
121
122
        File newModule = new File(new File(new File(System.getProperty("netbeans.user")), "modules"), "org-external.jar");
123
        newModule.getParentFile().mkdirs();
124
        simpleModule.renameTo(newModule);
125
        assertTrue("New module correctly created", newModule.exists());
126
127
        class Activate implements FileSystem.AtomicAction {
128
            FileObject fo;
129
130
            public Activate() throws IOException {
131
            }
132
            
133
            public void run() throws IOException {
134
                fo = FileUtil.getConfigFile("Modules").createData("org-external.xml");
135
                OutputStream os = fo.getOutputStream();
136
                os.write((
137
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
138
        "<!DOCTYPE module PUBLIC \"-//NetBeans//DTD Module Status 1.0//EN\"\n" +
139
        "                        \"http://www.netbeans.org/dtds/module-status-1_0.dtd\">\n" +
140
        "<module name=\"org.external\">\n" +
141
        "    <param name=\"autoload\">false</param>\n" +
142
        "    <param name=\"eager\">false</param>\n" +
143
        "    <param name=\"enabled\">true</param>\n" +
144
        "    <param name=\"jar\">modules/org-external.jar</param>\n" +
145
        "    <param name=\"reloadable\">false</param>\n" +
146
        "</module>\n" +
147
        "").getBytes());
148
                os.close();
149
            }
150
        }
151
        Activate a = new Activate();
152
        System.getProperties().remove("activated.ok");
153
154
        LOG.log(Level.INFO, "Creating config file");
155
        FileUtil.runAtomicAction(a);
156
        LOG.log(Level.INFO, "Done creating {0}", a.fo);
157
158
159
        for (int i = 0; i < 360 && System.getProperty("activated.ok") == null; i++) {
160
            LOG.log(Level.INFO, "Not found, but activated.ok: {0}", System.getProperty("activated.ok"));
161
            Thread.sleep(500);
162
        }
163
        LOG.log(Level.INFO, "activated.ok: {0}", System.getProperty("activated.ok"));
164
        assertEquals("true", System.getProperty("activated.ok"));
165
        doNecessarySetup();
166
        
167
        LOG.info("testInitUserDir - finished");
168
    }
169
170
    public void testStartAgain() throws Exception {
171
        doNecessarySetup();
172
        // will be reset next time the system starts
173
        System.getProperties().remove("netbeans.dirs");
174
        // initializes counting, but waits till netbeans.dirs are provided
175
        // by NbModuleSuite
176
        LOG.info("testStartAgain - enabling initCheckReadAccess");
177
        initCheckReadAccess();
178
        LOG.info("testStartAgain - finished");
179
    }
180
181
    static void doNecessarySetup() throws ClassNotFoundException, IOException {
182
        ClassLoader l = Lookup.getDefault().lookup(ClassLoader.class);
183
        try {
184
            Class<?> c = Class.forName("javax.help.HelpSet", true, l);
185
        } catch (ClassNotFoundException ok) {
186
        }
187
        try {
188
            Class<?> d = Class.forName("org.openide.DialogDescriptor", true, l);
189
        } catch (ClassNotFoundException ok) {
190
        }
191
        FileObject fo = FileUtil.getConfigFile("Services/Browsers");
192
        if (fo != null) {
193
            fo.delete();
194
        }
195
    }
196
197
    public void testInMiddle() {
198
        LOG.info("Previous run finished, starting another one");
199
        System.setProperty("activated.count", "0");
200
    }
201
202
    public void testReadAccess() throws Exception {
203
        LOG.info("Inside testReadAccess");
204
        ClassLoader l = Lookup.getDefault().lookup(ClassLoader.class);
205
        try {
206
            Class<?> c = Class.forName("javax.help.HelpSet", true, l);
207
        } catch (ClassNotFoundException ex) {
208
            // never mind
209
        }
210
        try {
211
            if (CountingSecurityManager.isEnabled()) {
212
                CountingSecurityManager.assertCounts("No reads during startup", 0);
213
            } else {
214
               LOG.warning("Initialization mode, counting is disabled");
215
            }
216
        } catch (Error e) {
217
            e.printStackTrace(getLog("file-reads-report.txt"));
218
            throw e;
219
        }
220
    }
221
222
    public void testVerifyActivatorExecuted() {
223
        assertEquals("1", System.getProperty("activated.count"));
224
    }
225
226
    public static class Compile extends NbTestCase {
227
        private File simpleModule;
228
        private SetExtDirProperty set;
229
230
        public Compile(String name, SetExtDirProperty p) {
231
            super(name);
232
            set = p;
233
        }
234
235
        public void testCompile() throws Exception {
236
            File data = new File(getDataDir(), "jars");
237
            File jars = new File(getWorkDir(), "jars");
238
            simpleModule = SetupHid.createTestJAR(data, jars, "external", null);
239
240
            File ext = new File(getWorkDir(), "extjars");
241
            ext.mkdirs();
242
            File extJAR = SetupHid.createTestJAR(data, ext, "ext", "activate");
243
244
            System.setProperty("external.jar", simpleModule.getPath());
245
            set.setExtDirProperty(ext);
246
        }
247
    }
248
    
249
    protected interface SetExtDirProperty {
250
        public void setExtDirProperty(File value);
251
    }
252
}
(-)5cee832cf3ae (+33 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2010 Jaroslav Tulach <jtulach@netbeans.org>
3
 * 
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; either version 2
7
 *  of the License, or (at your option) any later version.
8
 * 
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 * 
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.io.File;
22
import java.io.IOException;
23
import junit.framework.Test;
24
25
public class CachingAndExternalURLTest {
26
    public static Test suite() throws IOException {
27
        return CachingAndExternalPathsTest.create(new CachingAndExternalPathsTest.SetExtDirProperty() {
28
            public void setExtDirProperty(File value) {
29
                System.setProperty("ext.dir", value.toURI().toString());
30
            }
31
        });
32
    }
33
}
(-)5cee832cf3ae (+226 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2009 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
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.netbinox;
43
44
import java.io.File;
45
import java.io.IOException;
46
import java.io.OutputStream;
47
import java.util.HashSet;
48
import java.util.Locale;
49
import java.util.Set;
50
import java.util.logging.Level;
51
import java.util.logging.Logger;
52
import junit.framework.Test;
53
import org.netbeans.SetupHid;
54
import org.netbeans.junit.NbModuleSuite;
55
import org.netbeans.junit.NbTestCase;
56
import org.netbeans.junit.NbTestSuite;
57
import org.openide.filesystems.FileObject;
58
import org.openide.filesystems.FileSystem;
59
import org.openide.filesystems.FileUtil;
60
import org.openide.util.Lookup;
61
62
/**
63
 * Read access test
64
 * see details on http://wiki.netbeans.org/FitnessViaWhiteAndBlackList
65
 */
66
public class CachingPreventsFileTouchesTest extends NbTestCase {
67
    private static final Logger LOG = Logger.getLogger(CachingPreventsFileTouchesTest.class.getName());
68
    static {
69
        System.setProperty("java.awt.headless", "true");
70
    }
71
72
    private static void initCheckReadAccess() throws IOException {
73
        Set<String> allowedFiles = new HashSet<String>();
74
        CountingSecurityManager.initialize(null, CountingSecurityManager.Mode.CHECK_READ, allowedFiles);
75
    }
76
    
77
    public CachingPreventsFileTouchesTest(String name) {
78
        super(name);
79
    }
80
    
81
    public static Test suite() throws IOException {
82
        Locale.setDefault(Locale.US);
83
        CountingSecurityManager.initialize("none", CountingSecurityManager.Mode.CHECK_READ, null);
84
        System.setProperty("org.netbeans.Stamps.level", "ALL");
85
        System.setProperty(NbModuleSuite.class.getName() + ".level", "FINE");
86
        System.setProperty("org.netbeans.modules.netbinox.level", "FINE");
87
88
        NbTestSuite suite = new NbTestSuite();
89
        Compile compile = new Compile("testCompile");
90
        suite.addTest(compile);
91
        NbModuleSuite.Configuration common = NbModuleSuite.emptyConfiguration().clusters(".*").enableClasspathModules(false)
92
                .gui(false).honorAutoloadEager(true);
93
        {
94
            NbModuleSuite.Configuration conf = common.reuseUserDir(false).addTest(CachingPreventsFileTouchesTest.class, "testInitUserDir");
95
            suite.addTest(NbModuleSuite.create(conf));
96
        }
97
        {
98
            NbModuleSuite.Configuration conf = common.reuseUserDir(true).addTest(CachingPreventsFileTouchesTest.class, "testStartAgain");
99
            suite.addTest(NbModuleSuite.create(conf));
100
        }
101
102
        suite.addTest(new CachingPreventsFileTouchesTest("testInMiddle"));
103
104
        {
105
            NbModuleSuite.Configuration conf = common.reuseUserDir(true).addTest(CachingPreventsFileTouchesTest.class, "testReadAccess", "testVerifyActivatorExecuted");
106
            suite.addTest(NbModuleSuite.create(conf));
107
        }
108
109
        return suite;
110
    }
111
112
    public void testInitUserDir() throws Exception {
113
        File simpleModule = new File(System.getProperty("activate.jar"));
114
115
        File newModule = new File(new File(new File(System.getProperty("netbeans.user")), "modules"), "org-activate.jar");
116
        newModule.getParentFile().mkdirs();
117
        simpleModule.renameTo(newModule);
118
        assertTrue("New module correctly created", newModule.exists());
119
120
        class Activate implements FileSystem.AtomicAction {
121
            public void run() throws IOException {
122
                FileObject fo = FileUtil.getConfigFile("Modules").createData("org-activate.xml");
123
                OutputStream os = fo.getOutputStream();
124
                os.write((
125
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
126
        "<!DOCTYPE module PUBLIC \"-//NetBeans//DTD Module Status 1.0//EN\"\n" +
127
        "                        \"http://www.netbeans.org/dtds/module-status-1_0.dtd\">\n" +
128
        "<module name=\"org.activate\">\n" +
129
        "    <param name=\"autoload\">false</param>\n" +
130
        "    <param name=\"eager\">false</param>\n" +
131
        "    <param name=\"enabled\">true</param>\n" +
132
        "    <param name=\"jar\">modules/org-activate.jar</param>\n" +
133
        "    <param name=\"reloadable\">false</param>\n" +
134
        "</module>\n" +
135
        "").getBytes());
136
                os.close();
137
            }
138
        }
139
140
        FileUtil.runAtomicAction(new Activate());
141
142
143
        Class<?> main = null;
144
        Object s = null;
145
        for (int i = 0; i < 360; i++) {
146
            LOG.log(Level.INFO, "testInitUserDir - waiting for activation {0}", i);
147
            try {
148
                main = Thread.currentThread().getContextClassLoader().loadClass("org.activate.Main");
149
                s = main.getField("start").get(null);
150
                if (s == null) {
151
                    Thread.sleep(500);
152
                    continue;
153
                }
154
            } catch (ClassNotFoundException ex) {
155
                Thread.sleep(500);
156
                continue;
157
            }
158
            break;
159
        }
160
        LOG.log(Level.INFO, "testInitUserDir - waiting for activation over. Testing.");
161
        assertNotNull("Activate module shall start", main);
162
        LOG.log(Level.INFO, "checking field from {0}", main);
163
        s = main.getField("start").get(null);
164
        assertNotNull("Bundle started, its context provided", s);
165
166
        CachingAndExternalPathsTest.doNecessarySetup();
167
        
168
        LOG.info("testInitUserDir - finished");
169
    }
170
171
    public void testStartAgain() throws Exception {
172
        CachingAndExternalPathsTest.doNecessarySetup();
173
        // will be reset next time the system starts
174
        System.getProperties().remove("netbeans.dirs");
175
        // initializes counting, but waits till netbeans.dirs are provided
176
        // by NbModuleSuite
177
        LOG.info("testStartAgain - enabling initCheckReadAccess");
178
        initCheckReadAccess();
179
        LOG.info("testStartAgain - finished");
180
    }
181
182
    public void testInMiddle() {
183
        LOG.info("Previous run finished, starting another one");
184
        System.setProperty("activated.count", "0");
185
    }
186
187
    public void testReadAccess() throws Exception {
188
        LOG.info("Inside testReadAccess");
189
        ClassLoader l = Lookup.getDefault().lookup(ClassLoader.class);
190
        try {
191
            Class<?> c = Class.forName("javax.help.HelpSet", true, l);
192
        } catch (ClassNotFoundException ex) {
193
            // never mind
194
        }
195
        try {
196
            if (CountingSecurityManager.isEnabled()) {
197
                CountingSecurityManager.assertCounts("No reads during startup", 0);
198
            } else {
199
               Logger.getLogger("TEST.testReadAccess").warning("Initialization mode, counting is disabled");
200
            }
201
        } catch (Error e) {
202
            e.printStackTrace(getLog("file-reads-report.txt"));
203
            throw e;
204
        }
205
    }
206
207
    public void testVerifyActivatorExecuted() {
208
        assertEquals("1", System.getProperty("activated.count"));
209
    }
210
211
    public static class Compile extends NbTestCase {
212
        private File simpleModule;
213
214
        public Compile(String name) {
215
            super(name);
216
        }
217
218
        public void testCompile() throws Exception {
219
            File data = new File(getDataDir(), "jars");
220
            File jars = new File(getWorkDir(), "jars");
221
            simpleModule = SetupHid.createTestJAR(data, jars, "activate", "activate");
222
223
            System.setProperty("activate.jar", simpleModule.getPath());
224
        }
225
    }
226
}
(-)5cee832cf3ae (+130 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2010 Jaroslav Tulach <jtulach@netbeans.org>
3
 * 
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; either version 2
7
 *  of the License, or (at your option) any later version.
8
 * 
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 * 
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.awt.GraphicsEnvironment;
22
import java.io.File;
23
import java.io.IOException;
24
import java.util.Locale;
25
import java.util.logging.Level;
26
import junit.framework.Test;
27
import org.netbeans.Module;
28
import org.netbeans.ModuleManager;
29
import org.netbeans.SetupHid;
30
import org.netbeans.core.startup.Main;
31
import org.netbeans.junit.NbModuleSuite;
32
import org.netbeans.junit.NbTestCase;
33
import org.netbeans.junit.NbTestSuite;
34
35
/**
36
 *
37
 * @author Jaroslav Tulach <jtulach@netbeans.org>
38
 */
39
public class ContextClassLoaderTest extends NbTestCase {
40
    static {
41
        System.setProperty("java.awt.headless", "true");
42
    }
43
    
44
    public ContextClassLoaderTest(String name) {
45
        super(name);
46
    }
47
48
    public static Test suite() {
49
        System.setProperty("java.awt.headless", "true");
50
        assertTrue("In headless mode", GraphicsEnvironment.isHeadless());
51
        NbTestSuite s = new NbTestSuite();
52
        s.addTest(new Compile("testCompileJAR"));
53
        s.addTest(NbModuleSuite.create(
54
            NbModuleSuite.emptyConfiguration().addTest(
55
                ContextClassLoaderTest.class
56
            ).honorAutoloadEager(true).clusters(
57
                ".*"
58
            ).failOnException(Level.WARNING)/*.failOnMessage(Level.WARNING)*/
59
            .gui(false)
60
        ));
61
        return s;
62
    }
63
64
    public void testCheckWhichContainerIsRunning() throws Exception {
65
        File j1 = new File(System.getProperty("activate.jar"));
66
        assertTrue("File " + j1 + " exists", j1.exists());
67
68
69
        ModuleManager mgr = Main.getModuleSystem().getManager();
70
        mgr.mutexPrivileged().enterWriteAccess();
71
        Module m1;
72
73
        m1 = mgr.create(j1, null, false, false, false);
74
        mgr.enable(m1);
75
76
        assertTrue("OSGi module is now enabled", m1.isEnabled());
77
        mgr.mutexPrivileged().exitWriteAccess();
78
79
80
        Class<?> main = m1.getClassLoader().loadClass("org.activate.Main");
81
        Object s = main.getField("start").get(null);
82
        assertNotNull("Bundle started, its context provided", s);
83
84
        ClassLoader l = (ClassLoader) main.getField("loader").get(null);
85
        assertNotNull("Classloader is provided", l);
86
        Class<?> c = l.loadClass("org.netbeans.modules.favorites.Tab");
87
        assertNotNull("Class from favorites module found in " + l, c);
88
89
        Class<?> main2 = Thread.currentThread().getContextClassLoader().loadClass(main.getName());
90
        assertSame("Context classloader loads the same class", main, main2);
91
92
        Class<?> main3 = l.loadClass(main.getName());
93
        assertSame("Bundle's context classloader loads the same class", main, main3);
94
    }
95
96
    public void testContextClassLoaderIsOK() throws ClassNotFoundException {
97
        ClassLoader l = Thread.currentThread().getContextClassLoader();
98
        assertNotNull("Context class loader is found", l);
99
100
        Class<?> c = l.loadClass("org.netbeans.modules.favorites.Tab");
101
        assertNotNull("Class from favorites module found in " + l, c);
102
    }
103
104
    public static class Compile extends SetupHid {
105
106
        public Compile(String name) {
107
            super(name);
108
        }
109
        @Override
110
        protected void setUp() throws Exception {
111
            Locale.setDefault(Locale.US);
112
            clearWorkDir();
113
        }
114
115
        public void testCompileJAR() throws Exception {
116
            data = new File(getDataDir(), "jars");
117
            jars = new File(getWorkDir(), "jars");
118
            jars.mkdirs();
119
120
            jars.mkdirs();
121
            File j1 = createTestJAR("activate", null);
122
            assertNotNull("file found: " + j1);
123
            System.setProperty("activate.jar", j1.getPath());
124
        }
125
        
126
        private File createTestJAR(String name, String srcdir, File... classpath) throws IOException {
127
            return createTestJAR(data, jars, name, srcdir, classpath);
128
        }
129
    }
130
}
(-)5cee832cf3ae (+545 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2009 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 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.netbinox;
41
42
import java.io.File;
43
import java.io.FileDescriptor;
44
import java.io.IOException;
45
import java.io.PrintWriter;
46
import java.io.StringWriter;
47
import java.lang.reflect.Field;
48
import java.security.Permission;
49
import java.util.Arrays;
50
import java.util.Collections;
51
import java.util.HashMap;
52
import java.util.Map;
53
import java.util.Properties;
54
import java.util.Set;
55
import java.util.TreeSet;
56
import java.util.concurrent.Callable;
57
import java.util.logging.Level;
58
import java.util.logging.Logger;
59
import junit.framework.Assert;
60
61
/**
62
 *
63
 * @author Jaroslav Tulach <jaroslav.tulach@netbeans.org>
64
 */
65
final class CountingSecurityManager extends SecurityManager implements Callable<Integer> {
66
    private static int cnt;
67
    private static StringWriter msgs;
68
    private static PrintWriter pw;
69
    private static String prefix;
70
    private static Map<String,Exception> who = new HashMap<String, Exception>();
71
    private static Set<String> allowed = Collections.emptySet();
72
    private static SecurityManager man;
73
    private static Mode mode;
74
75
    public enum Mode {
76
        CHECK_READ, CHECK_WRITE
77
    };
78
    
79
    public static void initialize(String prefix, Mode mode, Set<String> allowedFiles) {
80
        System.setProperty("counting.security.disabled", "true");
81
82
        if (System.getSecurityManager() instanceof CountingSecurityManager) {
83
            // ok
84
        } else {
85
            System.setSecurityManager(new CountingSecurityManager());
86
        }
87
        setCnt(0);
88
        msgs = new StringWriter();
89
        pw = new PrintWriter(msgs);
90
        CountingSecurityManager.prefix = prefix;
91
        CountingSecurityManager.mode = mode;
92
        allowed = allowedFiles;
93
94
        Logger.getLogger("org.netbeans.TopSecurityManager").setLevel(Level.OFF);
95
        System.setProperty("org.netbeans.TopSecurityManager.level", "3000");
96
        System.setProperty("counting.security.disabled", "false");
97
    }
98
99
    static void assertReflection(int maxCount, String whitelist) {
100
        System.setProperty("counting.reflection.whitelist", whitelist);
101
        System.getSecurityManager().checkMemberAccess(null, maxCount);
102
        System.getProperties().remove("counting.reflection.whitelist");
103
    }
104
105
    @Override
106
    public String toString() {
107
        return msgs.toString();
108
    }
109
110
    public Integer call() throws Exception {
111
        return cnt;
112
    }
113
114
    public static boolean isEnabled() {
115
        return System.getSecurityManager() instanceof Callable<?>;
116
    }
117
    
118
    public static void assertCounts(String msg, int expectedCnt) throws Exception {
119
        int c = (Integer)((Callable<?>)System.getSecurityManager()).call();
120
        Assert.assertEquals(msg + "\n" + System.getSecurityManager().toString(), expectedCnt, c);
121
        setCnt(0);
122
        msgs = new StringWriter();
123
        pw = new PrintWriter(msgs);
124
    }
125
126
    /**
127
     * @return the cnt
128
     */
129
    public static int getCnt() {
130
        return cnt;
131
    }
132
133
    /**
134
     * @param aCnt the cnt to set
135
     */
136
    public static void setCnt(int aCnt) {
137
        cnt = aCnt;
138
    }
139
140
    @Override
141
    public void checkPermission(Permission p) {
142
        if (isDisabled()) {
143
            return;
144
        }
145
        if (p instanceof RuntimePermission && "setSecurityManager".equals(p.getName())) {
146
            try {
147
                ClassLoader l = Thread.currentThread().getContextClassLoader();
148
                Class<?> manClass = Class.forName("org.netbeans.TopSecurityManager", false, l);
149
                man = (SecurityManager) manClass.newInstance();
150
            } catch (Exception ex) {
151
                throw new IllegalStateException(ex);
152
            }
153
            throw new SecurityException();
154
        }
155
    }
156
157
    @Override
158
    public final void checkPropertyAccess(String x) {
159
        if (man != null) {
160
            man.checkPropertyAccess(x);
161
        }
162
    }
163
    
164
    @Override
165
    public void checkRead(String file) {
166
        if (mode == Mode.CHECK_READ && acceptFileRead(file)) {
167
            String dirs = System.getProperty("netbeans.dirs");
168
            if (dirs == null) {
169
                // not initialized yet
170
                return;
171
            }
172
173
            setCnt(getCnt() + 1);
174
            pw.println("checkRead: " + file);
175
            if (who.get(file) == null) {
176
                Exception now = new Exception("checkRead: " + file);
177
                who.put(file, now);
178
                now.printStackTrace(pw);
179
                pw.flush();
180
            }
181
        }
182
    }
183
184
    @Override
185
    public void checkRead(String file, Object context) {
186
        /*
187
        if (file.startsWith(prefix)) {
188
            cnt++;
189
            pw.println("checkRead2: " + file);
190
        }
191
         */
192
    }
193
194
    private void assertMembers(int cnt) {
195
        String res = System.getProperty("counting.reflection.whitelist");
196
        if (res == null) {
197
            Assert.fail("Please provide whitelist: " + res);
198
        }
199
        Properties okAccess = new Properties();
200
        try {
201
            okAccess.load(CountingSecurityManager.class.getResourceAsStream(res));
202
        } catch (IOException ex) {
203
            throw new IllegalStateException(ex);
204
        }
205
206
        int myCnt = 0;
207
        StringWriter w = new StringWriter();
208
        PrintWriter p = new PrintWriter(w);
209
        Set<Who> m;
210
        synchronized (members) {
211
            m = new TreeSet<Who>(members.values());
212
        }
213
        for (Who wh : m) {
214
            if (wh.isIgnore()) {
215
                continue;
216
            }
217
            String howMuchIsOK = okAccess.getProperty(wh.clazz.getName());
218
            if (howMuchIsOK != null && Integer.parseInt(howMuchIsOK) >= wh.count) {
219
                continue;
220
            }
221
222
                myCnt += wh.count;
223
            wh.printStackTrace(p);
224
            wh.count = 0;
225
        }
226
        if (myCnt > cnt) {
227
            Assert.fail("Expected at much " + cnt + " reflection efforts, but was: " + myCnt + "\n" + w);
228
        }
229
    }
230
231
    private final Map<Class,Who> members = Collections.synchronizedMap(new HashMap<Class, Who>());
232
    @Override
233
    public void checkMemberAccess(Class<?> clazz, int which) {
234
        if (clazz == null) {
235
            assertMembers(which);
236
        }
237
238
        Who w = members.get(clazz);
239
        if (w == null) {
240
            w = new Who(clazz);
241
            members.put(clazz, w);
242
        }
243
        w.count++;
244
    }
245
246
    private static class Who extends Exception implements Comparable<Who> {
247
        int hashCode;
248
        final Class<?> clazz;
249
        int count;
250
251
        public Who(Class<?> who) {
252
            super("");
253
            this.clazz = who;
254
        }
255
256
        @Override
257
        public void printStackTrace(PrintWriter s) {
258
            s.println(clazz.getName() + "=" + count);
259
            super.printStackTrace(s);
260
        }
261
262
        @Override
263
        public int hashCode() {
264
            if (hashCode != 0) {
265
                return hashCode;
266
            }
267
            hashCode = clazz.hashCode();
268
            for (StackTraceElement stackTraceElement : getStackTrace()) {
269
                hashCode = hashCode * 2 + stackTraceElement.hashCode();
270
            }
271
            return hashCode;
272
        }
273
274
        @Override
275
        public boolean equals(Object obj) {
276
            if (obj == null) {
277
                return false;
278
            }
279
            if (getClass() != obj.getClass()) {
280
                return false;
281
            }
282
            final Who other = (Who) obj;
283
            if (this.clazz != other.clazz) {
284
                return false;
285
            }
286
            if (this.hashCode() != other.hashCode()) {
287
                return false;
288
            }
289
            return Arrays.equals(getStackTrace(), other.getStackTrace());
290
        }
291
292
        public int compareTo(Who o) {
293
            if (o == this) {
294
                return 0;
295
            }
296
            if (o.count < this.count) {
297
                return -1;
298
            }
299
            if (o.count > this.count) {
300
                return 1;
301
            }
302
            return this.clazz.getName().compareTo(o.clazz.getName());
303
        }
304
305
        private boolean isIgnore() {
306
            if (clazz.getName().startsWith("sun.reflect.Generated")) {
307
                return true;
308
            }
309
            if (clazz.getName().startsWith("$Proxy")) {
310
                return true;
311
            }
312
            if (clazz.getName().startsWith("org.apache.tools.ant.")) {
313
                return true;
314
            }
315
            if (clazz.getName().startsWith("sun.nio.")) {
316
                return true;
317
            }
318
319
            for (StackTraceElement stackTraceElement : getStackTrace()) {
320
                if (stackTraceElement.getClassName().contains("CountingSecurityManager")) {
321
                    continue;
322
                }
323
                if (stackTraceElement.getClassName().equals("java.lang.Class")) {
324
                    continue;
325
                }
326
                if (stackTraceElement.getClassName().startsWith("java.lang.Thread")) {
327
                    if (stackTraceElement.getMethodName().equals("auditSubclass")) {
328
                        return true;
329
                    }
330
                    continue;
331
                }
332
                if (stackTraceElement.getClassName().startsWith("java.security.AccessController")) {
333
                    continue;
334
                }
335
                if (stackTraceElement.getClassName().equals("sun.swing.SwingLazyValue")) {
336
                    // ignore createValue method
337
                    return true;
338
                }
339
                if (
340
                        stackTraceElement.getClassName().equals("java.awt.Component") &&
341
                        stackTraceElement.getMethodName().equals("isCoalesceEventsOverriden")
342
                ) {
343
                    return true;
344
                }
345
                if (stackTraceElement.getClassName().startsWith("java.util.ResourceBundle")) {
346
                    // ignore these invocations
347
                    return true;
348
                }
349
                if (stackTraceElement.getClassName().equals("org.netbeans.jellytools")) {
350
                    // ignore these invocations
351
                    return true;
352
                }
353
                if (stackTraceElement.getClassName().equals("org.openide.util.lookup.MetaInfServicesLookup$P")) {
354
                    // ignore these invocations
355
                    return true;
356
                }
357
                if (stackTraceElement.getClassName().equals("org.openide.util.WeakListenerImpl$ListenerReference")) {
358
                    // ignore: removeXYZListener is done using reflection
359
                    return true;
360
                }
361
                return false;
362
            }
363
            return false;
364
        }
365
    }
366
367
    @Override
368
    public void checkWrite(FileDescriptor fd) {
369
        //setCnt(getCnt() + 1);
370
        //pw.println("Fd: " + fd);
371
    }
372
373
    @Override
374
    public void checkWrite(String file) {
375
        if (mode == Mode.CHECK_WRITE && acceptFileWrite(file)) {
376
            setCnt(getCnt() + 1);
377
            pw.println("checkWrite: " + file);
378
            if (who.get(file) == null) {
379
                Exception now = new Exception("checkWrite: " + file);
380
                who.put(file, now);
381
                now.printStackTrace(pw);
382
            }
383
        }
384
    }
385
386
    @Override
387
    public void checkDelete(String file) {
388
        if (mode == Mode.CHECK_WRITE && acceptFileWrite(file)) {
389
            setCnt(getCnt() + 1);
390
            pw.println("checkDelete: " + file);
391
        }
392
    }
393
    
394
    private boolean acceptFileWrite(String file) {
395
        String ud = System.getProperty("netbeans.user");
396
        if (ud == null) {
397
            // still initializing
398
            return false;
399
        }
400
        if (!file.startsWith(ud)) {
401
            return false;
402
        }
403
404
        String f = file.substring(ud.length()).replace(File.separatorChar, '/');
405
        if (f.contains("config/Modules")) {
406
            return false;
407
        }
408
        if (f.contains("config/Windows2Local")) {
409
            return false;
410
        }
411
        if (f.endsWith(".hg")) {
412
            try {
413
                Class<?> ref = Class.forName("org.netbeans.modules.versioning.util.Utils", true, Thread.currentThread().getContextClassLoader());
414
                Field unver = ref.getDeclaredField("unversionedFolders");
415
                unver.setAccessible(true);
416
                unver.set(null, new File[]{new File(ud).getParentFile()});
417
                return false;
418
            } catch (Exception ex) {
419
                throw new RuntimeException(ex);
420
            }
421
        }
422
        
423
        if (file.startsWith(ud)) {
424
            if (f.startsWith("/")) {
425
                f = f.substring(1);
426
            }
427
            if (allowed.contains(f)) {
428
                return false;
429
            }
430
        }
431
432
        return prefix == null || file.startsWith(prefix);
433
    }
434
435
    private boolean acceptFileRead(String file) {
436
        if (prefix != null && !file.startsWith(prefix)) {
437
            return false;
438
        }
439
        if (file.contains("/var/cache/netigso/org.eclipse.osgi/.")) {
440
            // Just finite number of files in a cache
441
            return false;
442
        }
443
        if (
444
            file.equals(System.getProperty("netbeans.user")) ||
445
            file.equals(System.getProperty("netbeans.home")) ||
446
            file.matches(".*/modules/ext/org\\.eclipse\\.osgi_[0-9\\.]*v[0-9]*\\.jar") ||
447
            file.endsWith("modules/org-netbeans-modules-netbinox.jar") ||
448
            file.endsWith("var/cache/netigso") ||
449
            file.endsWith("var/cache/netigso/org.eclipse.osgi")
450
        ) {
451
            // equinox just needs to touch some files, preferrably leave them
452
            // under our directory
453
            return false;
454
        }
455
        for (Class<?> onStack : getClassContext()) {
456
            if (onStack.getName().startsWith("org.eclipse.osgi.internal.permadmin.SecurityAdmin")) {
457
                // this is caused by our CountingSecurityManager being on
458
                return false;
459
            }
460
        }
461
        for (Class<?> onStack : getClassContext()) {
462
            if (onStack.getName().startsWith("org.eclipse")) {
463
                return true;
464
            }
465
        }
466
467
        if (!file.endsWith(".jar") && !file.endsWith("bundlefile")) {
468
            return false;
469
        }
470
        if (file.endsWith("tests.jar")) {
471
            return false;
472
        }
473
        if (file.endsWith("org-netbeans-modules-nbjunit.jar")) {
474
            return false;
475
        }
476
        if (file.startsWith(System.getProperty("java.home").replaceAll("[/\\\\][^/\\\\]*$", ""))) {
477
            return false;
478
        }
479
        if (file.startsWith(System.getProperty("netbeans.home") + File.separator + "lib")) {
480
            return false;
481
        }
482
        if (file.startsWith(System.getProperty("netbeans.home") + File.separator + "core")) {
483
            return false;
484
        }
485
        String dirs = System.getProperty("netbeans.dirs");
486
        if (dirs != null) {
487
            for (String dir : dirs.split(File.pathSeparator)) {
488
                if (file.startsWith(dir + File.separator + "lib")) {
489
                    return false;
490
                }
491
                if (file.startsWith(dir + File.separator + "core")) {
492
                    return false;
493
                }
494
            }
495
        }
496
        // mac osx
497
        dirs = System.getProperty("java.ext.dirs");
498
        if (dirs != null) {
499
            for (String dir : dirs.split(File.pathSeparator)) {
500
                if (file.startsWith(dir)) {
501
                    return false;
502
                }
503
            }
504
        }
505
506
        for (Class<?> onStack : getClassContext()) {
507
            if (onStack.getName().equals("org.netbeans.Stamps")) {
508
                return false;
509
            }
510
        }
511
        return true;
512
    }
513
514
    @Override
515
    public void checkExec(String cmd) {
516
        if (cmd.contains("chmod")) {
517
            return;
518
        }
519
        if (cmd.equals("hg")) {
520
            return;
521
        }
522
        if (cmd.endsWith("/hg")) {
523
            return;
524
        }
525
        if (cmd.endsWith("hg.exe")) {
526
            return;
527
        }
528
529
        super.checkExec(cmd);
530
        setCnt(getCnt() + 1);
531
        pw.println("checkExec: " + cmd);
532
        new Exception().printStackTrace(pw);
533
    }
534
535
    @Override
536
    public void checkPermission(Permission perm, Object context) {
537
    }
538
539
    /**
540
     * @return the disabled
541
     */
542
    private static boolean isDisabled() {
543
        return Boolean.getBoolean("counting.security.disabled");
544
    }
545
}
(-)5cee832cf3ae (+92 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2010 Jaroslav Tulach <jtulach@netbeans.org>
3
 *
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; either version 2
7
 *  of the License, or (at your option) any later version.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.io.File;
22
import java.util.logging.Level;
23
import junit.framework.Test;
24
import org.netbeans.Module;
25
import org.netbeans.ModuleManager;
26
import org.netbeans.SetupHid;
27
import org.netbeans.core.startup.Main;
28
import org.netbeans.junit.Log;
29
import org.netbeans.junit.NbModuleSuite;
30
import org.netbeans.junit.NbTestCase;
31
32
/**
33
 *
34
 * @author Jaroslav Tulach <jtulach@netbeans.org>
35
 */
36
public class EnabledAutoloadTest extends NbTestCase {
37
    private File j1;
38
39
    public EnabledAutoloadTest(String name) {
40
        super(name);
41
    }
42
43
    public static Test suite() {
44
        return NbModuleSuite.create(
45
            NbModuleSuite.emptyConfiguration().addTest(
46
                EnabledAutoloadTest.class
47
            ).honorAutoloadEager(true).clusters("platform.*").failOnException(Level.WARNING)/*.failOnMessage(Level.WARNING)*/
48
            .gui(false)
49
        );
50
    }
51
52
    @Override
53
    protected void setUp() throws Exception {
54
        clearWorkDir();
55
        
56
        File jars = new File(getWorkDir(), "jars");
57
        jars.mkdirs();
58
59
        j1 = SetupHid.createTestJAR(getDataDir(), jars, "simple-module.jar", null);
60
    }
61
62
    public void testDependOnAutoload() throws Exception {
63
        ModuleManager mgr = Main.getModuleSystem().getManager();
64
        mgr.mutexPrivileged().enterWriteAccess();
65
        try {
66
            Module m1;
67
            String mf = "Bundle-SymbolicName: org.require.autoload\n" +
68
                "Bundle-Version: 33.0.3\n" +
69
                "Bundle-ManifestVersion: 2\n" +
70
                "Require-Bundle: org.openide.compat\n\n";
71
            /*
72
            mf = "OpenIDE-Module: org.require.autoload\n" +
73
                "OpenIDE-Module-Module-Dependencies: org.openide.compat\n\n";
74
            /**/
75
            File jj1 = NetigsoHid.changeManifest(getWorkDir(), j1, mf);
76
            m1 = mgr.create(jj1, null, false, false, false);
77
78
            CharSequence log = Log.enable("org.netbeans.core.modules", Level.WARNING);
79
            mgr.enable(m1);
80
81
            assertTrue("OSGi module is now enabled", m1.isEnabled());
82
83
            Class<?> wl = m1.getClassLoader().loadClass("org.openide.util.WeakListener");
84
            assertNotNull("Weak listener found", wl);
85
86
            Module compat = mgr.get("org.openide.compat");
87
            assertTrue("Compat module is turned on too", compat.isEnabled());
88
        } finally {
89
            mgr.mutexPrivileged().exitWriteAccess();
90
        }
91
    }
92
}
(-)5cee832cf3ae (+174 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
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.netbinox;
43
44
import java.util.Enumeration;
45
import org.netbeans.core.startup.*;
46
import java.io.File;
47
import java.io.FileOutputStream;
48
import java.net.URL;
49
import java.util.Locale;
50
import org.netbeans.Module;
51
import org.netbeans.ModuleManager;
52
import org.netbeans.SetupHid;
53
import org.osgi.framework.Bundle;
54
import org.osgi.framework.BundleContext;
55
56
/**
57
 * Do we correctly call the BundleActivators?
58
 *
59
 * @author Jaroslav Tulach
60
 */
61
public class ExternalDirectoryTest extends SetupHid {
62
    private static Module m1;
63
    private static ModuleManager mgr;
64
    private File simpleModule;
65
66
    public ExternalDirectoryTest(String name) {
67
        super(name);
68
    }
69
70
    protected @Override void setUp() throws Exception {
71
        Locale.setDefault(Locale.US);
72
        clearWorkDir();
73
        File ud = new File(getWorkDir(), "ud");
74
        ud.mkdirs();
75
        System.setProperty("netbeans.user", ud.getPath());
76
        
77
        data = new File(getDataDir(), "jars");
78
        File activate = new File(data, "activate");
79
        assertTrue("Directory exists", activate.isDirectory());
80
        System.setProperty("ext.dir", data.getPath());
81
        
82
        File entry = new File(new File(new File(new File(data, "activate"), "org"), "test"), "x.txt");
83
        entry.getParentFile().mkdirs();
84
        FileOutputStream os = new FileOutputStream(entry);
85
        os.write("Ahoj".getBytes());
86
        os.close();
87
        
88
        jars = new File(getWorkDir(), "space in path");
89
        jars.mkdirs();
90
        File activateModule = SetupHid.createTestJAR(data, jars, "activate", null);
91
        // we need just the compiled clases, not the JAR
92
        activateModule.delete();
93
        simpleModule = SetupHid.createTestJAR(data, jars, "externaldir", null);
94
    }
95
96
    public void testActivation() throws Exception {
97
        ModuleSystem ms = Main.getModuleSystem();
98
        mgr = ms.getManager();
99
        mgr.mutexPrivileged().enterWriteAccess();
100
        Enumeration en;
101
        int checks = 0;
102
        
103
        System.setProperty("activated.checkentries", "/org/test/x.txt");
104
        try {
105
            m1 = mgr.create(simpleModule, null, false, false, false);
106
            mgr.enable(m1);
107
108
            Class<?> main = m1.getClassLoader().loadClass("org.activate.Main");
109
            Object s = main.getField("start").get(null);
110
            assertNotNull("Bundle started, its context provided", s);
111
112
            BundleContext bc = (BundleContext)s;
113
            StringBuilder sb = new StringBuilder();
114
            for (Bundle b : bc.getBundles()) {
115
                URL root = b.getEntry("/");
116
                if (root == null) {
117
                    sb.append("No root URL for ").append(b.getSymbolicName()).append("\n");
118
                }
119
                
120
                en = b.findEntries("/", null, true);
121
                if (en == null) {
122
                    sb.append("No entries for ").append(b.getSymbolicName()).append("\n");
123
                    continue;
124
                }
125
                while (en.hasMoreElements()) {
126
                    URL u = (URL) en.nextElement();
127
                    final String ef = u.toExternalForm();
128
                    int pref = ef.indexOf("/org/");
129
                    int last = ef.lastIndexOf("/");
130
                    if (pref != -1 && last != -1) {
131
                        String entry = ef.substring(pref + 1, last + 1);
132
                        assertTrue("/ is at the end", entry.endsWith("/"));
133
                        checks++;
134
                        final URL found = b.getEntry(entry);
135
                        assertNotNull("Entry found " + entry + " in " + b.getSymbolicName(), found);
136
                        
137
                        URL notFound = b.getEntry("non/existent/entry/");
138
                        assertNull("Entries for non-existing entries are not found", notFound);
139
                    }
140
                }
141
            }
142
            if (sb.length() > 0) {
143
                fail(sb.toString());
144
            }
145
            if (checks == 0) {
146
                fail("There shall be some checks for entries");
147
            }
148
            String text = System.getProperty("activated.entry");
149
            assertEquals("Ahoj", text);
150
151
            String localURL = System.getProperty("activated.entry.local");
152
            assertNotNull("bundleentry read OK", localURL);
153
            assertTrue("external file is referred as file:/.... = " + localURL, localURL.startsWith("file:/"));
154
            assertEquals("Ahoj", readLine(localURL));
155
156
            String fileURL = System.getProperty("activated.entry.file");
157
            assertNotNull("fileURL found", fileURL);
158
            assertTrue("file:/..... = " + fileURL, fileURL.startsWith("file:/"));
159
            assertEquals("Ahoj", readLine(fileURL));
160
161
            mgr.disable(m1);
162
163
            Object e = main.getField("stop").get(null);
164
            assertNotNull("Bundle stopped, its context provided", e);
165
        } finally {
166
            mgr.mutexPrivileged().exitWriteAccess();
167
        }
168
    }
169
170
    static String readLine(String url) throws Exception {
171
        return BundleURLConnectionTest.readLine(url);
172
    }
173
    
174
}
(-)5cee832cf3ae (+132 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
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.netbinox;
43
44
import java.util.Enumeration;
45
import org.netbeans.core.startup.*;
46
import java.io.File;
47
import java.io.FileOutputStream;
48
import java.net.URL;
49
import java.util.Locale;
50
import org.netbeans.Module;
51
import org.netbeans.ModuleManager;
52
import org.netbeans.SetupHid;
53
import org.osgi.framework.Bundle;
54
import org.osgi.framework.BundleContext;
55
56
/**
57
 * Do we correctly call the BundleActivators?
58
 *
59
 * @author Jaroslav Tulach
60
 */
61
public class ExternalJARTest extends SetupHid {
62
    private static ModuleManager mgr;
63
    private File simpleModule;
64
    private File dependsOnSimple;
65
66
    public ExternalJARTest(String name) {
67
        super(name);
68
    }
69
70
    protected @Override void setUp() throws Exception {
71
        Locale.setDefault(Locale.US);
72
        clearWorkDir();
73
        File ud = new File(getWorkDir(), "ud");
74
        ud.mkdirs();
75
        System.setProperty("netbeans.user", ud.getPath());
76
        
77
        data = new File(getDataDir(), "jars");
78
        File activate = new File(data, "activate");
79
        assertTrue("Directory exists", activate.isDirectory());
80
        
81
        jars = new File(getWorkDir(), "space in path");
82
        jars.mkdirs();
83
        File activateLib = SetupHid.createTestJAR(data, jars, "activate", null);
84
        System.setProperty("ext.jar", activateLib.getPath());
85
        
86
        String bundleMan = "Bundle-SymbolicName: org.foo\n" +
87
                "Bundle-Version: 1.1.0\n" +
88
                "Bundle-ManifestVersion: 2\n" +
89
                "Bundle-ClassPath: external:$ext.jar$\n" +
90
                "Import-Package: org.osgi.framework\n" +
91
                "Export-Package: org.activate\n\n\n";
92
        simpleModule = NetigsoHid.changeManifest(
93
            getWorkDir(), 
94
            SetupHid.createTestJAR(data, jars, "simple-module", null),
95
            bundleMan
96
        );
97
        String depMan = "Manifest-Version: 1.0\n" +
98
            "OpenIDE-Module: org.bar2/1\n" +
99
            "OpenIDE-Module-Module-Dependencies: org.foo\n\n\n";
100
        dependsOnSimple = NetigsoHid.changeManifest(
101
            getWorkDir(),
102
            SetupHid.createTestJAR(data, jars, "depends-on-simple-module", null, simpleModule),
103
            depMan
104
        );
105
    }
106
107
    public void testActivation() throws Exception {
108
        ModuleSystem ms = Main.getModuleSystem();
109
        mgr = ms.getManager();
110
        mgr.mutexPrivileged().enterWriteAccess();
111
        
112
        try {
113
            Module m1 = mgr.create(simpleModule, null, false, true, false);
114
            Module m2 = mgr.create(dependsOnSimple, null, false, false, false);
115
            mgr.enable(m2);
116
117
            {
118
                Class<?> main = m1.getClassLoader().loadClass("org.activate.Main");
119
                assertNotNull("m1 can load class from external library of m1", main);
120
            }
121
            
122
            {
123
                Class<?> main = m2.getClassLoader().loadClass("org.activate.Main");
124
                assertNotNull("m2 can load class from external library of m1", main);
125
            }
126
127
            mgr.disable(m2);
128
        } finally {
129
            mgr.mutexPrivileged().exitWriteAccess();
130
        }
131
    }
132
}
(-)5cee832cf3ae (+119 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2010 Jaroslav Tulach <jtulach@netbeans.org>
3
 * 
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; either version 2
7
 *  of the License, or (at your option) any later version.
8
 * 
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 * 
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.awt.GraphicsEnvironment;
22
import java.io.File;
23
import java.io.IOException;
24
import java.util.Locale;
25
import java.util.logging.Level;
26
import junit.framework.Test;
27
import org.netbeans.Module;
28
import org.netbeans.ModuleManager;
29
import org.netbeans.SetupHid;
30
import org.netbeans.core.startup.Main;
31
import org.netbeans.junit.NbModuleSuite;
32
import org.netbeans.junit.NbTestCase;
33
import org.netbeans.junit.NbTestSuite;
34
35
/**
36
 *
37
 * @author Jaroslav Tulach <jtulach@netbeans.org>
38
 */
39
public class HookConfiguratorTest extends NbTestCase {
40
    static {
41
        System.setProperty("java.awt.headless", "true");
42
    }
43
    
44
    public HookConfiguratorTest(String name) {
45
        super(name);
46
    }
47
48
    public static Test suite() {
49
        System.setProperty("java.awt.headless", "true");
50
        assertTrue("In headless mode", GraphicsEnvironment.isHeadless());
51
        NbTestSuite s = new NbTestSuite();
52
        s.addTest(new Compile("testCompileJAR"));
53
        s.addTest(NbModuleSuite.create(
54
            NbModuleSuite.emptyConfiguration().addTest(
55
                HookConfiguratorTest.class
56
            ).honorAutoloadEager(true).clusters(
57
                ".*"
58
            ).failOnException(Level.WARNING)/*.failOnMessage(Level.WARNING)*/
59
            .gui(false)
60
        ));
61
        return s;
62
    }
63
64
    public void testCheckWhichContainerIsRunning() throws Exception {
65
        File j1 = new File(System.getProperty("activate.jar"));
66
        assertTrue("File " + j1 + " exists", j1.exists());
67
        File j2 = new File(System.getProperty("hook.jar"));
68
        assertTrue("File " + j2 + " exists", j2.exists());
69
70
71
        ModuleManager mgr = Main.getModuleSystem().getManager();
72
        try {
73
            mgr.mutexPrivileged().enterWriteAccess();
74
            Module m1, m2;
75
76
            m1 = mgr.create(j1, null, false, false, false);
77
            m2 = mgr.create(j2, null, false, false, false);
78
            mgr.enable(m2);
79
            mgr.enable(m1);
80
81
            assertTrue("OSGi module is now enabled", m1.isEnabled());
82
        } finally {
83
            mgr.mutexPrivileged().exitWriteAccess();
84
        }
85
86
        assertEquals("true", System.getProperty("main.hook"));
87
88
    }
89
90
    public static class Compile extends SetupHid {
91
92
        public Compile(String name) {
93
            super(name);
94
        }
95
        @Override
96
        protected void setUp() throws Exception {
97
            Locale.setDefault(Locale.US);
98
            clearWorkDir();
99
        }
100
101
        public void testCompileJAR() throws Exception {
102
            data = new File(getDataDir(), "jars");
103
            jars = new File(getWorkDir(), "jars");
104
            jars.mkdirs();
105
106
            jars.mkdirs();
107
            File j1 = createTestJAR("activate", null);
108
            assertNotNull("file found: " + j1);
109
            File j2 = createTestJAR("hook", null);
110
            assertNotNull("file found: " + j2);
111
            System.setProperty("activate.jar", j1.getPath());
112
            System.setProperty("hook.jar", j2.getPath());
113
        }
114
        
115
        private File createTestJAR(String name, String srcdir, File... classpath) throws IOException {
116
            return createTestJAR(data, jars, name, srcdir, classpath);
117
        }
118
    }
119
}
(-)5cee832cf3ae (+98 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2010 Jaroslav Tulach <jtulach@netbeans.org>
3
 * 
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; either version 2
7
 *  of the License, or (at your option) any later version.
8
 * 
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 * 
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.io.File;
22
import java.lang.reflect.Method;
23
import java.util.logging.Level;
24
import junit.framework.Test;
25
import org.netbeans.Module;
26
import org.netbeans.ModuleManager;
27
import org.netbeans.NetigsoFramework;
28
import org.netbeans.SetupHid;
29
import org.netbeans.core.startup.Main;
30
import org.netbeans.junit.NbModuleSuite;
31
import org.netbeans.junit.NbTestCase;
32
import org.openide.util.Lookup;
33
import org.osgi.framework.Bundle;
34
import org.osgi.framework.launch.Framework;
35
36
/**
37
 *
38
 * @author Jaroslav Tulach <jtulach@netbeans.org>
39
 */
40
public class IntegrationTest extends NbTestCase {
41
    private File j1;
42
43
    public IntegrationTest(String name) {
44
        super(name);
45
    }
46
47
    public static Test suite() {
48
        return NbModuleSuite.create(
49
            NbModuleSuite.emptyConfiguration().addTest(
50
                IntegrationTest.class
51
            ).honorAutoloadEager(true).clusters(
52
                ".*"
53
            ).failOnException(Level.WARNING)/*.failOnMessage(Level.WARNING)*/
54
            .gui(false)
55
        );
56
    }
57
58
    @Override
59
    protected void setUp() throws Exception {
60
        File jars = new File(getWorkDir(), "jars");
61
        jars.mkdirs();
62
63
        j1 = SetupHid.createTestJAR(getDataDir(), jars, "simple-module.jar", null);
64
    }
65
66
67
    public void testCheckWhichContainerIsRunning() throws Exception {
68
        ModuleManager mgr = Main.getModuleSystem().getManager();
69
        mgr.mutexPrivileged().enterWriteAccess();
70
        Module m1;
71
        String mf = "Bundle-SymbolicName: org.foo\n" +
72
            "Bundle-Version: 1.1.0\n" +
73
            "Bundle-ManifestVersion: 2\n" +
74
            "Export-Package: org.foo";
75
76
        File jj1 = NetigsoHid.changeManifest(getWorkDir(), j1, mf);
77
        m1 = mgr.create(jj1, null, false, false, false);
78
        mgr.enable(m1);
79
80
        assertTrue("OSGi module is now enabled", m1.isEnabled());
81
        mgr.mutexPrivileged().exitWriteAccess();
82
83
        Object obj = Lookup.getDefault().lookup(NetigsoFramework.class);
84
        final Method m = obj.getClass().getDeclaredMethod("getFramework");
85
        m.setAccessible(true);
86
        Framework w = (Framework) m.invoke(obj);
87
        assertNotNull("Framework found", w);
88
        assertEquals("Felix is not in its name", -1, w.getClass().getName().indexOf("felix"));
89
        StringBuilder sb = new StringBuilder();
90
        for (Bundle b : w.getBundleContext().getBundles()) {
91
            sb.append("\n").append(b.getSymbolicName());
92
            if (b.getSymbolicName().equals("org.eclipse.osgi")) {
93
                return;
94
            }
95
        }
96
        fail("Expecting equinox among list of enabled bundles:" + sb);
97
    }
98
}
(-)5cee832cf3ae (+124 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2010 Jaroslav Tulach <jtulach@netbeans.org>
3
 * 
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; either version 2
7
 *  of the License, or (at your option) any later version.
8
 * 
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 * 
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import org.netbeans.core.startup.*;
22
import java.io.File;
23
import java.io.IOException;
24
import java.lang.reflect.Method;
25
import java.util.Locale;
26
import org.netbeans.Module;
27
import org.netbeans.ModuleManager;
28
import org.netbeans.SetupHid;
29
import org.osgi.framework.Bundle;
30
import org.osgi.framework.BundleContext;
31
32
/**
33
 * Does context classloader in NetBeans honour the Equinox buddy policy?
34
 *
35
 * @author Jaroslav Tulach
36
 */
37
public class NetbinoxBuddyClassLoaderTest extends SetupHid {
38
    private static Module m1;
39
    private Module m2;
40
    private static ModuleManager mgr;
41
    private int cnt;
42
    private File simpleBundle;
43
    private File activate;
44
45
    public NetbinoxBuddyClassLoaderTest(String name) {
46
        super(name);
47
    }
48
49
    protected @Override void setUp() throws Exception {
50
        Locale.setDefault(Locale.US);
51
        clearWorkDir();
52
        File ud = new File(getWorkDir(), "ud");
53
        ud.mkdirs();
54
        System.setProperty("netbeans.user", ud.getPath());
55
        
56
        data = new File(getDataDir(), "jars");
57
        jars = new File(getWorkDir(), "space in path");
58
        jars.mkdirs();
59
60
        File act = createTestJAR("activate", null); 
61
        String amf = "Manifest-Version: 1.0\n" +
62
            "Bundle-SymbolicName: org.activate\n" +
63
            "Bundle-Version: 1.2\n" +
64
            "Eclipse-BuddyPolicy: registered\n" + 
65
            "Import-Package: org.osgi.framework\n" +
66
            "Bundle-Activator: org.activate.Main\n" +
67
            "\n";
68
        activate = NetigsoHid.changeManifest(getWorkDir(), act, amf);
69
        
70
        File simpleModule = createTestJAR("simple-module", null);
71
        String mf = "Bundle-SymbolicName: org.snd.module\n" +
72
            "Export-Package: org.foo\n" + 
73
            "Require-Bundle: org.activate\n" +
74
            "Eclipse-RegisterBuddy: org.activate\n" +
75
            "Bundle-Version: 33.0.3\n" +
76
            "Bundle-ManifestVersion: 2\n";
77
        simpleBundle = NetigsoHid.changeManifest(getWorkDir(), simpleModule, mf);
78
    }
79
80
    public void testActivation() throws Exception {
81
        ModuleSystem ms = Main.getModuleSystem();
82
        mgr = ms.getManager();
83
        mgr.mutexPrivileged().enterWriteAccess();
84
        BundleContext bc;
85
        Method loadClass = null;
86
        try {
87
            m1 = mgr.create(activate, null, false, false, false);
88
            m2 = mgr.create(simpleBundle, null, false, false, false);
89
            
90
            mgr.enable(m1);
91
92
            Class<?> main = m1.getClassLoader().loadClass("org.activate.Main");
93
            Object s = main.getField("start").get(null);
94
            assertNotNull("Bundle started, its context provided", s);
95
            bc = (BundleContext) s;
96
            loadClass = main.getMethod("loadClass", String.class, ClassLoader.class);
97
        } finally {
98
            mgr.mutexPrivileged().exitWriteAccess();
99
        }
100
        Bundle toEnable = null;
101
        for (Bundle b : bc.getBundles()) {
102
            if (b.getSymbolicName().equals("org.snd.module")) {
103
                toEnable = b;
104
                break;
105
            }
106
        }
107
        
108
        assertNotNull("org.snd.module bundle found", toEnable);
109
        assertEquals("Just resolved", Bundle.RESOLVED, toEnable.getState());
110
        assertFalse("not started", m2.isEnabled());
111
112
        Class<?> directly = (Class<?>) loadClass.invoke(null, "org.foo.Something", null);
113
        assertNotNull("Bundle knows how to load the class from its buddy", directly);
114
        
115
        Class<?> someFromBundle = (Class<?>) loadClass.invoke(null, "org.foo.Something", m1.getClassLoader());
116
        assertNotNull("Bundle knows how to load the class from its buddy", someFromBundle);
117
118
        Class<?> some = (Class<?>) loadClass.invoke(null, "org.foo.Something", Thread.currentThread().getContextClassLoader());
119
        assertNotNull("Context class loader deals with buddies too", some);
120
    }
121
    private File createTestJAR(String name, String srcdir, File... classpath) throws IOException {
122
        return createTestJAR(data, jars, name, srcdir, classpath);
123
    }
124
}
(-)5cee832cf3ae (+121 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
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.netbinox;
43
44
import java.util.Enumeration;
45
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
46
import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
47
import org.netbeans.core.startup.*;
48
import java.io.File;
49
import java.io.IOException;
50
import java.net.URL;
51
import java.util.Locale;
52
import org.eclipse.osgi.baseadaptor.BaseData;
53
import org.eclipse.osgi.framework.adaptor.BundleData;
54
import org.eclipse.osgi.framework.internal.core.AbstractBundle;
55
import org.netbeans.Module;
56
import org.netbeans.ModuleManager;
57
import org.netbeans.SetupHid;
58
import org.osgi.framework.Bundle;
59
import org.osgi.framework.BundleContext;
60
61
/**
62
 * Is loading of libraries OK?
63
 *
64
 * @author Jaroslav Tulach
65
 */
66
public class NetbinoxLibraryTest extends SetupHid {
67
    private static Module m1;
68
    private static ModuleManager mgr;
69
    
70
    public NetbinoxLibraryTest(String name) {
71
        super(name);
72
    }
73
74
    protected @Override void setUp() throws Exception {
75
        Locale.setDefault(Locale.US);
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
        File 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
        Enumeration en;
92
        int checks = 0;
93
        try {
94
            System.setProperty("activated.library", "does.not.exist");
95
            
96
            File simpleModule = new File(jars, "activate.jar");
97
            m1 = mgr.create(simpleModule, null, false, false, false);
98
            mgr.enable(m1);
99
100
            Class<?> main = m1.getClassLoader().loadClass("org.activate.Main");
101
            Object s = main.getField("start").get(null);
102
            assertNotNull("Bundle started, its context provided", s);
103
104
            String err = System.getProperty("activated.library");
105
            // the error is taken from ClassLoader.loadLibrary
106
            if (err == null || err.indexOf("in java.library.path") == -1) {
107
                fail("The make sure the ClassLoader.findLibrary returns null: " + err);
108
            }
109
            
110
            mgr.disable(m1);
111
112
            Object e = main.getField("stop").get(null);
113
            assertNotNull("Bundle stopped, its context provided", e);
114
        } finally {
115
            mgr.mutexPrivileged().exitWriteAccess();
116
        }
117
    }
118
    private File createTestJAR(String name, String srcdir, File... classpath) throws IOException {
119
        return createTestJAR(data, jars, name, srcdir, classpath);
120
    }
121
}
(-)5cee832cf3ae (+86 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3
 *
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; version 2
7
 *  of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import org.netbeans.core.startup.*;
22
import java.io.File;
23
import java.io.IOException;
24
import java.util.Locale;
25
import org.netbeans.Module;
26
import org.netbeans.ModuleManager;
27
import org.netbeans.SetupHid;
28
import org.osgi.framework.BundleContext;
29
30
/**
31
 * Are system properties properly initialized when specifying 
32
 * osgi.framework.useSystemProperties?
33
 *
34
 * @author Jaroslav Tulach
35
 */
36
public class NetbinoxUseSystemPropertiesTest extends SetupHid {
37
    private static Module m1;
38
    private static ModuleManager mgr;
39
    static {
40
        System.setProperty("osgi.framework.useSystemProperties", "true");
41
    }
42
43
    public NetbinoxUseSystemPropertiesTest(String name) {
44
        super(name);
45
    }
46
47
    protected @Override void setUp() throws Exception {
48
        Locale.setDefault(Locale.US);
49
        clearWorkDir();
50
        File ud = new File(getWorkDir(), "ud");
51
        ud.mkdirs();
52
        System.setProperty("netbeans.user", ud.getPath());
53
        
54
        data = new File(getDataDir(), "jars");
55
        jars = new File(getWorkDir(), "space in path");
56
        jars.mkdirs();
57
        File simpleModule = createTestJAR("activate", null);
58
    }
59
60
    public void testActivation() throws Exception {
61
        ModuleSystem ms = Main.getModuleSystem();
62
        mgr = ms.getManager();
63
        mgr.mutexPrivileged().enterWriteAccess();
64
        try {
65
            File simpleModule = new File(jars, "activate.jar");
66
            m1 = mgr.create(simpleModule, null, false, false, false);
67
            mgr.enable(m1);
68
69
            Class<?> main = m1.getClassLoader().loadClass("org.activate.Main");
70
            Object s = main.getField("start").get(null);
71
            assertNotNull("Bundle started, its context provided", s);
72
73
            BundleContext bc = (BundleContext)s;
74
            assertNotNull("OSGi version available to contexts", bc.getProperty("osgi.framework.version"));
75
            String version = System.getProperty("osgi.framework.version");
76
            assertNotNull("OSGi version available to System.properties", version);
77
            
78
            mgr.disable(m1);
79
        } finally {
80
            mgr.mutexPrivileged().exitWriteAccess();
81
        }
82
    }
83
    private File createTestJAR(String name, String srcdir, File... classpath) throws IOException {
84
        return createTestJAR(data, jars, name, srcdir, classpath);
85
    }
86
}
(-)5cee832cf3ae (+172 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
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.netbinox;
43
44
import java.util.Enumeration;
45
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
46
import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
47
import org.netbeans.core.startup.*;
48
import java.io.File;
49
import java.io.IOException;
50
import java.net.URL;
51
import java.util.Locale;
52
import org.eclipse.osgi.baseadaptor.BaseData;
53
import org.eclipse.osgi.framework.adaptor.BundleData;
54
import org.eclipse.osgi.framework.internal.core.AbstractBundle;
55
import org.netbeans.Module;
56
import org.netbeans.ModuleManager;
57
import org.netbeans.SetupHid;
58
import org.osgi.framework.Bundle;
59
import org.osgi.framework.BundleContext;
60
61
/**
62
 * Do we correctly call the BundleActivators?
63
 *
64
 * @author Jaroslav Tulach
65
 */
66
public class NetigsoActivationTest extends SetupHid {
67
    private static Module m1;
68
    private static ModuleManager mgr;
69
    
70
    public NetigsoActivationTest(String name) {
71
        super(name);
72
    }
73
74
    protected @Override void setUp() throws Exception {
75
        Locale.setDefault(Locale.US);
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
        File 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
        Enumeration en;
92
        int checks = 0;
93
        try {
94
            File simpleModule = new File(jars, "activate.jar");
95
            m1 = mgr.create(simpleModule, null, false, false, false);
96
            mgr.enable(m1);
97
98
            Class<?> main = m1.getClassLoader().loadClass("org.activate.Main");
99
            Object s = main.getField("start").get(null);
100
            assertNotNull("Bundle started, its context provided", s);
101
102
            BundleContext bc = (BundleContext)s;
103
            StringBuilder sb = new StringBuilder();
104
            for (Bundle b : bc.getBundles()) {
105
                URL root = b.getEntry("/");
106
                if (root == null) {
107
                    sb.append("No root URL for ").append(b.getSymbolicName()).append("\n");
108
                }
109
                BundleFile bFile = null;
110
                if (b instanceof AbstractBundle) {
111
                    BundleData bd = ((AbstractBundle) b).getBundleData();
112
                    if (bd instanceof BaseData) {
113
                        bFile = ((BaseData) bd).getBundleFile();
114
                    }
115
                }
116
                assertNotNull("All our bundles have BundleFile", bFile);
117
                
118
                en = b.findEntries("/", null, true);
119
                if (en == null) {
120
                    sb.append("No entries for ").append(b.getSymbolicName()).append("\n");
121
                    continue;
122
                }
123
                while (en.hasMoreElements()) {
124
                    URL u = (URL) en.nextElement();
125
                    final String ef = u.toExternalForm();
126
                    int pref = ef.indexOf("/org/");
127
                    int last = ef.lastIndexOf("/");
128
                    if (pref != -1 && last != -1) {
129
                        String entry = ef.substring(pref + 1, last + 1);
130
                        assertTrue("/ is at the end", entry.endsWith("/"));
131
                        checks++;
132
                        final URL found = b.getEntry(entry);
133
                        assertNotNull("Entry found " + entry + " in " + b.getSymbolicName(), found);
134
                        assertTrue("Directory found", bFile.containsDir(entry));
135
                        BundleEntry ee = bFile.getEntry(entry);
136
                        URL local = ee.getLocalURL();
137
                        assertEquals("JAR protocol used", "jar", local.getProtocol());
138
                        if (!local.toExternalForm().contains("!/")) {
139
                            fail("!/ shall be in the URL: " + local);
140
                        }
141
                        
142
                        final String nonExist = "non/existent/entry/";
143
                        URL notFound = b.getEntry(nonExist);
144
                        assertNull("Entries for non-existing entries are not found", notFound);
145
                        assertFalse("Non-existent not found", bFile.containsDir(nonExist));
146
                    }
147
                }
148
            }
149
            if (sb.length() > 0) {
150
                fail(sb.toString());
151
            }
152
            if (checks == 0) {
153
                fail("There shall be some checks for entries");
154
            }
155
156
            assertNotNull("OSGi version available to contexts", bc.getProperty("osgi.framework.version"));
157
            
158
            String version = System.getProperty("osgi.framework.version");
159
            assertNull("Version is not available in system properties by default", version);
160
            
161
            mgr.disable(m1);
162
163
            Object e = main.getField("stop").get(null);
164
            assertNotNull("Bundle stopped, its context provided", e);
165
        } finally {
166
            mgr.mutexPrivileged().exitWriteAccess();
167
        }
168
    }
169
    private File createTestJAR(String name, String srcdir, File... classpath) throws IOException {
170
        return createTestJAR(data, jars, name, srcdir, classpath);
171
    }
172
}
(-)5cee832cf3ae (+57 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
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.netbinox;
43
44
/**
45
 * Do we correctly call the BundleActivators?
46
 *
47
 * @author Jaroslav Tulach
48
 */
49
public class NetigsoActivationWithAllDirsTest extends NetigsoActivationTest {
50
    static {
51
        generateAllDirs = true;
52
    }
53
54
    public NetigsoActivationWithAllDirsTest(String name) {
55
        super(name);
56
    }
57
}
(-)5cee832cf3ae (+80 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2009 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3
 *
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; version 2
7
 *  of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.io.File;
22
import java.util.Arrays;
23
import java.util.HashSet;
24
import org.netbeans.MockModuleInstaller;
25
import org.netbeans.MockEvents;
26
import org.netbeans.Module;
27
import org.netbeans.ModuleManager;
28
29
/**
30
 * Tests that dashnames are properly converted to underscores.
31
 *
32
 * @author Jaroslav Tulach
33
 */
34
public class NetigsoDashnamesTest extends NetigsoHid {
35
    public NetigsoDashnamesTest(String name) {
36
        super(name);
37
    }
38
39
    public void testDashnames() throws Exception {
40
        MockModuleInstaller installer = new MockModuleInstaller();
41
        MockEvents ev = new MockEvents();
42
        ModuleManager mgr = new ModuleManager(installer, ev);
43
        mgr.mutexPrivileged().enterWriteAccess();
44
        Module m2;
45
        Module m1;
46
        HashSet<Module> both = null;
47
        try {
48
            String mf = "Bundle-SymbolicName: org.foo-bar\n" +
49
                "Bundle-Version: 1.1.0\n" +
50
                "Bundle-ManifestVersion: 2\n" +
51
                "Export-Package: org.foo";
52
            String mfBar =
53
                "OpenIDE-Module: org.bar/1\n" +
54
                "OpenIDE-Module-Name: Depends on bar test module\n" +
55
                "OpenIDE-Module-Module-Dependencies: org.foo_bar\n" +
56
                "some";
57
58
            File j1 = changeManifest(new File(jars, "simple-module.jar"), mf);
59
            File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar);
60
            m1 = mgr.create(j1, null, false, false, false);
61
            m2 = mgr.create(j2, null, false, false, false);
62
            HashSet<Module> b = new HashSet<Module>(Arrays.asList(m1, m2));
63
            mgr.enable(b);
64
            both = b;
65
66
67
            Class<?> clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse");
68
            Class<?> sprclass = m2.getClassLoader().loadClass("org.foo.Something");
69
70
            assertEquals("Correct parent is used", sprclass, clazz.getSuperclass());
71
72
        } finally {
73
            if (both != null) {
74
                mgr.disable(both);
75
            }
76
            mgr.mutexPrivileged().exitWriteAccess();
77
        }
78
79
    }
80
}
(-)5cee832cf3ae (+158 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2009 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3
 *
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; version 2
7
 *  of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.io.ByteArrayInputStream;
22
import java.io.File;
23
import java.io.FileOutputStream;
24
import java.io.IOException;
25
import java.io.InputStream;
26
import java.util.Collections;
27
import java.util.Enumeration;
28
import java.util.List;
29
import java.util.Locale;
30
import java.util.Set;
31
import java.util.jar.JarEntry;
32
import java.util.jar.JarFile;
33
import java.util.jar.JarOutputStream;
34
import java.util.jar.Manifest;
35
import org.netbeans.Events;
36
import org.netbeans.JarClassLoader;
37
import org.netbeans.Module;
38
import org.netbeans.ModuleManager;
39
import org.netbeans.SetupHid;
40
import org.openide.filesystems.FileUtil;
41
42
/**
43
 * Basic infrastructure for testing OSGi functionality.
44
 *
45
 * @author Jaroslav Tulach
46
 */
47
public class NetigsoHid extends SetupHid {
48
    public NetigsoHid(String name) {
49
        super(name);
50
    }
51
52
    protected @Override void setUp() throws Exception {
53
        Locale.setDefault(Locale.US);
54
        clearWorkDir();
55
        
56
        data = new File(getDataDir(), "jars");
57
        jars = new File(getWorkDir(), "jars");
58
        jars.mkdirs();
59
        File simpleModule = createTestJAR("simple-module", null);
60
        File dependsOnSimpleModule = createTestJAR("depends-on-simple-module", null, simpleModule);
61
62
        File ud = new File(getWorkDir(), "ud");
63
        ud.mkdirs();
64
65
        System.setProperty("netbeans.user", ud.getPath());
66
    }
67
    @Override
68
    protected void tearDown() throws Exception {
69
        super.tearDown();
70
    }
71
    private File createTestJAR(String name, String srcdir, File... classpath) throws IOException {
72
        return createTestJAR(data, jars, name, srcdir, classpath);
73
    }
74
75
    
76
    protected final File changeManifest(File orig, String manifest) throws IOException {
77
        return changeManifest(getWorkDir(), orig, manifest);
78
    }
79
80
    protected static File changeManifest(File dir, File orig, String manifest) throws IOException {
81
        File f = new File(dir, orig.getName());
82
        Manifest mf = new Manifest(new ByteArrayInputStream(manifest.getBytes("utf-8")));
83
        mf.getMainAttributes().putValue("Manifest-Version", "1.0");
84
        JarOutputStream os = new JarOutputStream(new FileOutputStream(f), mf);
85
        JarFile jf = new JarFile(orig);
86
        Enumeration<JarEntry> en = jf.entries();
87
        InputStream is;
88
        while (en.hasMoreElements()) {
89
            JarEntry e = en.nextElement();
90
            if (e.getName().equals("META-INF/MANIFEST.MF")) {
91
                continue;
92
            }
93
            os.putNextEntry(e);
94
            is = jf.getInputStream(e);
95
            FileUtil.copy(is, os);
96
            is.close();
97
            os.closeEntry();
98
        }
99
        os.close();
100
101
        return f;
102
    }
103
    private static final class DummyModule extends Module {
104
        private final Manifest manifest;
105
        public DummyModule(ModuleManager mgr, Events ev, Object history, boolean reloadable, boolean autoload, boolean eager) throws IOException {
106
            super(mgr, ev, history, reloadable, autoload, eager);
107
            manifest = new Manifest();
108
            manifest.getMainAttributes().putValue("OpenIDE-Module", "boom");
109
            parseManifest();
110
        }
111
        @Override
112
        public List<File> getAllJars() {
113
            return Collections.emptyList();
114
        }
115
        @Override
116
        public void setReloadable(boolean r) {
117
        }
118
        @Override
119
        public void reload() throws IOException {
120
        }
121
        @Override
122
        protected void classLoaderUp(Set parents) throws IOException {
123
            classloader = new JarClassLoader(Collections.<File>emptyList(), new ClassLoader[] {new NoOpClassLoader()});
124
        }
125
        @Override
126
        protected void classLoaderDown() {
127
        }
128
        @Override
129
        protected void cleanup() {
130
        }
131
        @Override
132
        protected void destroy() {
133
        }
134
        @Override
135
        public boolean isFixed() {
136
            return true;
137
        }
138
        @Override
139
        public Object getLocalizedAttribute(String attr) {
140
            return null;
141
        }
142
        public @Override Manifest getManifest() {
143
            return manifest;
144
        }
145
    }
146
    
147
    private static final class NoOpClassLoader extends ClassLoader {
148
        NoOpClassLoader() {
149
	    super(ClassLoader.getSystemClassLoader());
150
	}
151
        protected @Override Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
152
            if ("java.lang.String".equals(name)) {
153
                throw new ClassNotFoundException("NoOpClassLoader cannot load " + name);
154
            }
155
            return super.loadClass(name, resolve);
156
        }
157
    }
158
}
(-)5cee832cf3ae (+170 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2009 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3
 *
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; version 2
7
 *  of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import org.netbeans.core.startup.*;
22
import java.io.ByteArrayInputStream;
23
import java.io.File;
24
import java.io.FileOutputStream;
25
import java.io.IOException;
26
import java.io.InputStream;
27
import java.net.URL;
28
import java.util.Collections;
29
import java.util.Enumeration;
30
import java.util.Locale;
31
import java.util.jar.JarEntry;
32
import java.util.jar.JarFile;
33
import java.util.jar.JarOutputStream;
34
import java.util.jar.Manifest;
35
import junit.framework.Test;
36
import org.netbeans.Module;
37
import org.netbeans.ModuleManager;
38
import org.netbeans.SetupHid;
39
import org.netbeans.junit.NbTestSuite;
40
import org.openide.filesystems.FileObject;
41
import org.openide.filesystems.FileUtil;
42
43
/**
44
 * How does OSGi integration deals with layer registration?
45
 *
46
 * @author Jaroslav Tulach
47
 */
48
public class NetigsoLayerTest extends SetupHid {
49
    private static Module m1;
50
    private static ModuleManager mgr;
51
52
    public NetigsoLayerTest(String name) {
53
        super(name);
54
    }
55
56
    public static Test suite() {
57
        Test t = null;
58
//        t = new NetigsoTest("testOSGiCanRequireBundleOnNetBeans");
59
        if (t == null) {
60
            t = new NbTestSuite(NetigsoLayerTest.class);
61
        }
62
        return t;
63
    }
64
65
    protected @Override void setUp() throws Exception {
66
        Locale.setDefault(Locale.US);
67
        clearWorkDir();
68
//        NetigsoModuleFactory.clear();
69
70
        
71
        data = new File(getDataDir(), "jars");
72
        jars = new File(getWorkDir(), "jars");
73
        jars.mkdirs();
74
        File simpleModule = createTestJAR("simple-module", null);
75
        File dependsOnSimpleModule = createTestJAR("depends-on-simple-module", null, simpleModule);
76
77
        if (System.getProperty("netbeans.user") == null) {
78
            File ud = new File(getWorkDir(), "ud");
79
            ud.mkdirs();
80
81
            System.setProperty("netbeans.user", ud.getPath());
82
83
84
            ModuleSystem ms = Main.getModuleSystem();
85
            mgr = ms.getManager();
86
            mgr.mutexPrivileged().enterWriteAccess();
87
            try {
88
                File j1 = new File(jars, "simple-module.jar");
89
                m1 = mgr.create(j1, null, false, false, false);
90
                mgr.enable(Collections.<Module>singleton(m1));
91
            } finally {
92
                mgr.mutexPrivileged().exitWriteAccess();
93
            }
94
        }
95
96
    }
97
    private File createTestJAR(String name, String srcdir, File... classpath) throws IOException {
98
        return createTestJAR(data, jars, name, srcdir, classpath);
99
    }
100
    public void testOSGiCanProvideLayer() throws Exception {
101
        mgr.mutexPrivileged().enterWriteAccess();
102
        FileObject fo;
103
        try {
104
            String mfBar = "Bundle-SymbolicName: org.bar\n" +
105
                "Bundle-Version: 1.1.0\n" +
106
                "Bundle-ManifestVersion: 2\n" +
107
                "Import-Package: org.foo\n" +
108
                "OpenIDE-Module-Layer: org/bar/layer.xml\n" +
109
                "\n\n";
110
111
            File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar);
112
            Module m2 = mgr.create(j2, null, false, false, false);
113
            mgr.enable(m2);
114
        } finally {
115
            mgr.mutexPrivileged().exitWriteAccess();
116
        }
117
        fo = FileUtil.getConfigFile("TestFolder");
118
        assertNotNull("Folder found", fo);
119
120
        URL u = mgr.getClassLoader().getResource("org/bar/layer.xml");
121
        assertNotNull("System ClassLoader can load resources", u);
122
    }
123
/* Looks like non-exported packages do not work, as the URLHandlersBundleStreamHandler gets
124
 * somehow confused.
125
 * 
126
    public void testOSGiCanProvideImpl() throws Exception {
127
        mgr.mutexPrivileged().enterWriteAccess();
128
        FileObject fo;
129
        try {
130
            String mfBar = "Bundle-SymbolicName: org.kuk\n" +
131
                "Bundle-Version: 1.1.0\n" +
132
                "Bundle-ManifestVersion: 2\n" +
133
                "Import-Package: org.foo\n" +
134
                "OpenIDE-Module-Layer: org/bar/impl/layer.xml\n" +
135
                "\n\n";
136
137
            File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar);
138
            Module m2 = mgr.create(j2, null, false, false, false);
139
            mgr.enable(m2);
140
        } finally {
141
            mgr.mutexPrivileged().exitWriteAccess();
142
        }
143
        fo = Repository.getDefault().getDefaultFileSystem().findResource("TestImplFolder");
144
        assertNotNull("Folder found", fo);
145
    }
146
*/
147
    private File changeManifest(File orig, String manifest) throws IOException {
148
        File f = new File(getWorkDir(), orig.getName());
149
        Manifest mf = new Manifest(new ByteArrayInputStream(manifest.getBytes("utf-8")));
150
        mf.getMainAttributes().putValue("Manifest-Version", "1.0");
151
        JarOutputStream os = new JarOutputStream(new FileOutputStream(f), mf);
152
        JarFile jf = new JarFile(orig);
153
        Enumeration<JarEntry> en = jf.entries();
154
        InputStream is;
155
        while (en.hasMoreElements()) {
156
            JarEntry e = en.nextElement();
157
            if (e.getName().equals("META-INF/MANIFEST.MF")) {
158
                continue;
159
            }
160
            os.putNextEntry(e);
161
            is = jf.getInputStream(e);
162
            FileUtil.copy(is, os);
163
            is.close();
164
            os.closeEntry();
165
        }
166
        os.close();
167
168
        return f;
169
    }
170
}
(-)5cee832cf3ae (+115 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
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.netbinox;
43
44
import org.netbeans.core.startup.*;
45
import java.io.File;
46
import java.io.IOException;
47
import java.net.URL;
48
import java.util.Locale;
49
import java.util.logging.Level;
50
import junit.framework.Test;
51
import org.netbeans.Module;
52
import org.netbeans.ModuleManager;
53
import org.netbeans.SetupHid;
54
import org.netbeans.junit.Log;
55
import org.netbeans.junit.NbTestSuite;
56
import org.osgi.framework.Bundle;
57
import org.osgi.framework.BundleContext;
58
59
/**
60
 * Do we correctly call the BundleActivators?
61
 *
62
 * @author Jaroslav Tulach
63
 */
64
public class NetigsoLoggingTest extends SetupHid {
65
    private static Module m1;
66
    private static ModuleManager mgr;
67
    private int cnt;
68
69
    public NetigsoLoggingTest(String name) {
70
        super(name);
71
    }
72
73
    public static Test suite() {
74
        Test t = null;
75
//        t = new NetigsoTest("testOSGiCanRequireBundleOnNetBeans");
76
        if (t == null) {
77
            t = new NbTestSuite(NetigsoLoggingTest.class);
78
        }
79
        return t;
80
    }
81
82
    protected @Override void setUp() throws Exception {
83
        Locale.setDefault(Locale.US);
84
        clearWorkDir();
85
        File ud = new File(getWorkDir(), "ud");
86
        ud.mkdirs();
87
        System.setProperty("netbeans.user", ud.getPath());
88
        
89
        data = new File(getDataDir(), "jars");
90
        jars = new File(getWorkDir(), "jars");
91
        jars.mkdirs();
92
        File simpleModule = createTestJAR("activate", null);
93
    }
94
95
    public void testActivation() throws Exception {
96
        ModuleSystem ms = Main.getModuleSystem();
97
        mgr = ms.getManager();
98
        mgr.mutexPrivileged().enterWriteAccess();
99
        try {
100
            File simpleModule = new File(jars, "activate.jar");
101
            m1 = mgr.create(simpleModule, null, false, false, false);
102
            System.setProperty("activated.throw", "error!");
103
            CharSequence log = Log.enable("", Level.WARNING);
104
            mgr.enable(m1);
105
            if (!log.toString().contains("error!")) {
106
                fail("There shall be a warning in the log:\n" + log);
107
            }
108
        } finally {
109
            mgr.mutexPrivileged().exitWriteAccess();
110
        }
111
    }
112
    private File createTestJAR(String name, String srcdir, File... classpath) throws IOException {
113
        return createTestJAR(data, jars, name, srcdir, classpath);
114
    }
115
}
(-)5cee832cf3ae (+150 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.modules.netbinox;
46
47
import java.lang.reflect.Method;
48
import org.netbeans.core.startup.*;
49
import java.io.File;
50
import java.io.IOException;
51
import java.util.Locale;
52
import org.netbeans.Module;
53
import org.netbeans.ModuleManager;
54
import org.netbeans.SetupHid;
55
import org.osgi.framework.Bundle;
56
import org.osgi.framework.BundleContext;
57
58
/**
59
 * Are modules turned on by OSGi framework directly marked as enabled?
60
 * Can we load classes from them?
61
 *
62
 * @author Jaroslav Tulach
63
 */
64
public class NetigsoOSGiActivationVisibleTest extends SetupHid {
65
    private static Module m1;
66
    private Module m2;
67
    private static ModuleManager mgr;
68
    private int cnt;
69
    private File simpleBundle;
70
    private File activate;
71
72
    public NetigsoOSGiActivationVisibleTest(String name) {
73
        super(name);
74
    }
75
    
76
    protected boolean autoload() {
77
        return false;
78
    }
79
80
    protected @Override void setUp() throws Exception {
81
        Locale.setDefault(Locale.US);
82
        clearWorkDir();
83
        File ud = new File(getWorkDir(), "ud");
84
        ud.mkdirs();
85
        System.setProperty("netbeans.user", ud.getPath());
86
        
87
        data = new File(getDataDir(), "jars");
88
        jars = new File(getWorkDir(), "space in path");
89
        jars.mkdirs();
90
        activate = createTestJAR("activate", null);
91
        File simpleModule = createTestJAR("simple-module", null);
92
        
93
        String mf = "Bundle-SymbolicName: org.snd.module\n" +
94
            "Bundle-Version: 33.0.3\n" +
95
            "Bundle-ManifestVersion: 2\n";
96
        simpleBundle = NetigsoHid.changeManifest(getWorkDir(), simpleModule, mf);
97
    }
98
99
    public void testActivation() throws Exception {
100
        ModuleSystem ms = Main.getModuleSystem();
101
        mgr = ms.getManager();
102
        mgr.mutexPrivileged().enterWriteAccess();
103
        BundleContext bc;
104
        try {
105
            m1 = mgr.create(activate, null, false, false, false);
106
            m2 = mgr.create(simpleBundle, null, false, autoload(), false);
107
            
108
            mgr.enable(m1);
109
110
            Class<?> main = m1.getClassLoader().loadClass("org.activate.Main");
111
            Object s = main.getField("start").get(null);
112
            assertNotNull("Bundle started, its context provided", s);
113
            bc = (BundleContext) s;
114
        } finally {
115
            mgr.mutexPrivileged().exitWriteAccess();
116
        }
117
        Bundle toEnable = null;
118
        for (Bundle b : bc.getBundles()) {
119
            if (b.getSymbolicName().equals("org.snd.module")) {
120
                toEnable = b;
121
                break;
122
            }
123
        }
124
        assertNotNull("org.snd.module bundle found", toEnable);
125
            
126
        assertFalse("not started yet", m2.isEnabled());
127
        toEnable.start();
128
129
        Class<?> directBundle = toEnable.loadClass("org.foo.Something");
130
        assertNotNull("Bundle knows how to load the class", directBundle);
131
        
132
        Class<?> someModule = m2.getClassLoader().loadClass("org.foo.Something");
133
        assertNotNull("Something loaded from module CL", someModule);
134
        
135
        Method loadClass = directBundle.getMethod("loadClass", String.class, ClassLoader.class);
136
        Class<?> directly = (Class<?>) loadClass.invoke(null, "org.foo.Something", null);
137
        assertNotNull("Bundle knows how to load the class from itself without problems", directly);
138
        
139
        Class<?> someFromBundle = (Class<?>) loadClass.invoke(null, "org.foo.Something", someModule.getClassLoader());
140
        assertNotNull("Bundle knows how to load the class from its using own classloader", someFromBundle);
141
142
        Class<?> some = (Class<?>) loadClass.invoke(null, "org.foo.Something", Thread.currentThread().getContextClassLoader());
143
        assertNotNull("Context class loader loads from disabled module bundles too", some);
144
145
        assertFalse("still disabled from NetBeans view point", m2.isEnabled());
146
    }
147
    private File createTestJAR(String name, String srcdir, File... classpath) throws IOException {
148
        return createTestJAR(data, jars, name, srcdir, classpath);
149
    }
150
}
(-)5cee832cf3ae (+73 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2009 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3
 *
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; version 2
7
 *  of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.io.File;
22
import java.util.Arrays;
23
import java.util.HashSet;
24
import org.netbeans.MockEvents;
25
import org.netbeans.MockModuleInstaller;
26
import org.netbeans.Module;
27
import org.netbeans.ModuleManager;
28
29
/**
30
 *
31
 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
32
 */
33
public class NetigsoOSGiCanDependTest extends NetigsoHid {
34
35
    public NetigsoOSGiCanDependTest(String name) {
36
        super(name);
37
    }
38
39
    public void testOSGiCanDependOnNetBeans() throws Exception {
40
        MockModuleInstaller installer = new MockModuleInstaller();
41
        MockEvents ev = new MockEvents();
42
        ModuleManager mgr = new ModuleManager(installer, ev);
43
        mgr.mutexPrivileged().enterWriteAccess();
44
        HashSet<Module> both = null;
45
        try {
46
            String mfBar = "Bundle-SymbolicName: org.bar\n" +
47
                "Bundle-Version: 1.1.0\n" +
48
                "Bundle-ManifestVersion: 2\n" +
49
                "Export-Package: org.bar\n" +
50
                "Import-Package: org.foo\n" +
51
                "\n\n";
52
53
            File j1 = new File(jars, "simple-module.jar");
54
            File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar);
55
            Module m1 = mgr.create(j1, null, false, false, false);
56
            Module m2 = mgr.create(j2, null, false, false, false);
57
            HashSet<Module> b = new HashSet<Module>(Arrays.asList(m1, m2));
58
            mgr.enable(b);
59
            both = b;
60
61
            Class<?> clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse");
62
            Class<?> sprclass = m2.getClassLoader().loadClass("org.foo.Something");
63
64
            assertEquals("Correct parent is used", sprclass, clazz.getSuperclass());
65
        } finally {
66
            if (both != null) {
67
                mgr.disable(both);
68
            }
69
            mgr.mutexPrivileged().exitWriteAccess();
70
        }
71
    }
72
73
}
(-)5cee832cf3ae (+73 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2009 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3
 *
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; version 2
7
 *  of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.io.File;
22
import java.util.Arrays;
23
import java.util.HashSet;
24
import org.netbeans.MockEvents;
25
import org.netbeans.MockModuleInstaller;
26
import org.netbeans.Module;
27
import org.netbeans.ModuleManager;
28
29
/**
30
 *
31
 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
32
 */
33
public class NetigsoOSGiCanRequestTest extends NetigsoHid {
34
35
    public NetigsoOSGiCanRequestTest(String name) {
36
        super(name);
37
    }
38
39
    public void testOSGiCanRequireBundleOnNetBeans() throws Exception {
40
        MockModuleInstaller installer = new MockModuleInstaller();
41
        MockEvents ev = new MockEvents();
42
        ModuleManager mgr = new ModuleManager(installer, ev);
43
        mgr.mutexPrivileged().enterWriteAccess();
44
        HashSet<Module> both = null;
45
        try {
46
            String mfBar = "Bundle-SymbolicName: org.bar\n" +
47
                "Bundle-Version: 1.1.0\n" +
48
                "Bundle-ManifestVersion: 2\n" +
49
                "Export-Package: org.bar\n" +
50
                "Require-Bundle: org.foo;bundle-version=\"[100.0,102.0)\"\n" +
51
                "\n\n";
52
53
            File j1 = new File(jars, "simple-module.jar");
54
            File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar);
55
            Module m1 = mgr.create(j1, null, false, false, false);
56
            Module m2 = mgr.create(j2, null, false, false, false);
57
            HashSet<Module> b = new HashSet<Module>(Arrays.asList(m1, m2));
58
            mgr.enable(b);
59
            both = b;
60
61
            Class<?> sprclass = m1.getClassLoader().loadClass("org.foo.Something");
62
            Class<?> clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse");
63
64
            assertEquals("Correct parent is used", sprclass, clazz.getSuperclass());
65
        } finally {
66
            if (both != null) {
67
                mgr.disable(both);
68
            }
69
            mgr.mutexPrivileged().exitWriteAccess();
70
        }
71
    }
72
73
}
(-)5cee832cf3ae (+181 lines)
Added Link Here
1
/*
2
 *  Copyright (C) 2009 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3
 *
4
 *  This program is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU General Public License
6
 *  as published by the Free Software Foundation; version 2
7
 *  of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 */
18
19
package org.netbeans.modules.netbinox;
20
21
import java.io.File;
22
import java.util.Arrays;
23
import java.util.HashSet;
24
import junit.framework.Test;
25
import org.netbeans.MockModuleInstaller;
26
import org.netbeans.MockEvents;
27
import org.netbeans.Module;
28
import org.netbeans.ModuleManager;
29
import org.netbeans.junit.NbTestSuite;
30
31
/**
32
 * Basic tests to verify the basic interaction between NetBeans module
33
 * system and OSGi.
34
 *
35
 * @author Jaroslav Tulach
36
 */
37
public class NetigsoTest extends NetigsoHid {
38
    public NetigsoTest(String name) {
39
        super(name);
40
    }
41
42
    public static Test suite() {
43
        Test t = null;
44
//        t = new NetigsoTest("testOSGiCanRequireBundleOnNetBeans");
45
        if (t == null) {
46
            t = new NbTestSuite(NetigsoTest.class);
47
        }
48
        return t;
49
    }
50
51
    public void testFactoryCreatesOurModules() throws Exception {
52
        MockModuleInstaller installer = new MockModuleInstaller();
53
        MockEvents ev = new MockEvents();
54
        ModuleManager mgr = new ModuleManager(installer, ev);
55
        mgr.mutexPrivileged().enterWriteAccess();
56
        Module m2;
57
        Module m1;
58
        HashSet<Module> both = null;
59
        try {
60
            String mf = "Bundle-SymbolicName: org.foo\n" +
61
                "Bundle-Version: 1.1.0\n" +
62
                "Bundle-ManifestVersion: 2\n" +
63
                "Export-Package: org.foo";
64
            String mfBar =
65
                "OpenIDE-Module: org.bar/1\n" +
66
                "OpenIDE-Module-Name: Depends on bar test module\n" +
67
                "OpenIDE-Module-Module-Dependencies: org.foo\n" +
68
                "some";
69
70
            File j1 = changeManifest(new File(jars, "simple-module.jar"), mf);
71
            File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar);
72
            m1 = mgr.create(j1, null, false, false, false);
73
            m2 = mgr.create(j2, null, false, false, false);
74
            HashSet<Module> b = new HashSet<Module>(Arrays.asList(m1, m2));
75
            mgr.enable(b);
76
            both = b;
77
78
            
79
            Class<?> clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse");
80
            Class<?> sprclass = m2.getClassLoader().loadClass("org.foo.Something");
81
82
            assertEquals("Correct parent is used", sprclass, clazz.getSuperclass());
83
84
        } finally {
85
            if (both != null) {
86
                mgr.disable(both);
87
            }
88
            mgr.mutexPrivileged().exitWriteAccess();
89
        }
90
91
    }
92
93
    public void testFactoryCreatesOurModulesWithDeps() throws Exception {
94
        MockModuleInstaller installer = new MockModuleInstaller();
95
        MockEvents ev = new MockEvents();
96
        ModuleManager mgr = new ModuleManager(installer, ev);
97
        mgr.mutexPrivileged().enterWriteAccess();
98
        HashSet<Module> both = null;
99
        try {
100
            String mf = "Bundle-SymbolicName: org.foo\n" +
101
                "Bundle-Version: 1.1.0\n" +
102
                "Bundle-ManifestVersion: 2\n" +
103
                "Export-Package: org.foo";
104
            String mfBar =
105
                "OpenIDE-Module: org.bar/1\n" +
106
                "OpenIDE-Module-Name: Depends on bar test module\n" +
107
                "OpenIDE-Module-Module-Dependencies: org.foo > 1.0\n" +
108
                "some";
109
110
            File j1 = changeManifest(new File(jars, "simple-module.jar"), mf);
111
            File j2 = changeManifest(new File(jars, "depends-on-simple-module.jar"), mfBar);
112
            Module m1 = mgr.create(j1, null, false, false, false);
113
            Module m2 = mgr.create(j2, null, false, false, false);
114
            HashSet<Module> b = new HashSet<Module>(Arrays.asList(m1, m2));
115
            mgr.enable(b);
116
            both = b;
117
118
            Class<?> clazz = m2.getClassLoader().loadClass("org.bar.SomethingElse");
119
            Class<?> sprclass = m2.getClassLoader().loadClass("org.foo.Something");
120
121