Added
Link Here
|
1 |
/* |
2 |
* Sun Public License Notice |
3 |
* |
4 |
* The contents of this file are subject to the Sun Public License |
5 |
* Version 1.0 (the "License"). You may not use this file except in |
6 |
* compliance with the License. A copy of the License is available at |
7 |
* http://www.sun.com/ |
8 |
* |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
13 |
|
14 |
package org.netbeans.core.modules; |
15 |
|
16 |
import java.io.*; |
17 |
import java.io.File; |
18 |
import java.util.Collections; |
19 |
import java.util.Locale; |
20 |
import java.util.jar.*; |
21 |
import org.netbeans.junit.*; |
22 |
import junit.textui.TestRunner; |
23 |
import org.openide.filesystems.Repository; |
24 |
import org.netbeans.core.NbTopManager; |
25 |
|
26 |
/** Checks whether a module with generated |
27 |
* @author Jaroslav Tulach |
28 |
*/ |
29 |
public class PlatformDependencySatisfiedTest extends SetupHid { |
30 |
private File moduleJarFile; |
31 |
|
32 |
public PlatformDependencySatisfiedTest(String name) { |
33 |
super(name); |
34 |
} |
35 |
|
36 |
public static void main(String[] args) { |
37 |
TestRunner.run(new NbTestSuite(PlatformDependencySatisfiedTest.class)); |
38 |
} |
39 |
|
40 |
protected void setUp() throws Exception { |
41 |
super.setUp(); |
42 |
System.setProperty("org.netbeans.core.modules.NbInstaller.noAutoDeps", "true"); |
43 |
|
44 |
File tmp = File.createTempFile ("PlatformDependencySatisfiedModule", ".jar"); |
45 |
moduleJarFile = tmp; |
46 |
|
47 |
Manifest man = new Manifest (); |
48 |
man.getMainAttributes ().putValue ("Manifest-Version", "1.0"); |
49 |
man.getMainAttributes ().putValue ("OpenIDE-Module", "org.test.PlatformDependency/1"); |
50 |
|
51 |
String req = null; |
52 |
if (org.openide.util.Utilities.isWindows ()) { |
53 |
req = "org.openide.modules.os.Windows"; |
54 |
} else if ((org.openide.util.Utilities.getOperatingSystem () & org.openide.util.Utilities.OS_MAC) != 0) { |
55 |
req = "org.openide.modules.os.MacOSX"; |
56 |
} else if (org.openide.util.Utilities.isUnix ()) { |
57 |
req = "org.openide.modules.os.Unix"; |
58 |
} |
59 |
assertNotNull ("This test is supposed to run on windows, unix and macosx, fail otherwise on this line", req); |
60 |
|
61 |
man.getMainAttributes ().putValue ("OpenIDE-Module-Requires", req); |
62 |
|
63 |
JarOutputStream os = new JarOutputStream (new FileOutputStream (tmp), man); |
64 |
os.putNextEntry (new JarEntry ("empty/test.txt")); |
65 |
os.close (); |
66 |
} |
67 |
|
68 |
/** */ |
69 |
public void testTryToInstallTheModuleWhichRequiresTheOS () throws Exception { |
70 |
NbTopManager.get(); // init module system |
71 |
final FakeEvents ev = new FakeEvents(); |
72 |
NbInstaller installer = new NbInstaller(ev); |
73 |
ModuleManager mgr = new ModuleManager(installer, ev); |
74 |
installer.registerManager(mgr); |
75 |
mgr.mutexPrivileged().enterWriteAccess(); |
76 |
try { |
77 |
addOpenide(mgr); |
78 |
Module m1 = mgr.create(moduleJarFile, null, false, false, false); |
79 |
assertEquals(Collections.EMPTY_SET, m1.getProblems()); |
80 |
mgr.enable(m1); |
81 |
mgr.disable(m1); |
82 |
mgr.delete(m1); |
83 |
} finally { |
84 |
mgr.mutexPrivileged().exitWriteAccess(); |
85 |
} |
86 |
} |
87 |
|
88 |
} |