9
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
2
|
17 |
package com.nokia.cdt.debug.cw.symbian.tests;
|
|
18 |
|
|
19 |
import java.io.File;
|
|
20 |
import java.io.FilenameFilter;
|
|
21 |
import java.io.IOException;
|
|
22 |
import java.net.URL;
|
|
23 |
|
|
24 |
import junit.framework.TestCase;
|
|
25 |
|
|
26 |
import org.eclipse.core.runtime.FileLocator;
|
|
27 |
import org.eclipse.core.runtime.Path;
|
|
28 |
import org.eclipse.core.runtime.Platform;
|
|
29 |
import org.eclipse.core.runtime.Plugin;
|
|
30 |
import org.osgi.framework.Bundle;
|
|
31 |
import org.osgi.framework.BundleContext;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* The activator class controls the plug-in life cycle
|
|
35 |
*/
|
|
36 |
public class TestsPlugin extends Plugin {
|
|
37 |
|
|
38 |
// The plug-in ID
|
|
39 |
public static final String PLUGIN_ID = "com.nokia.cdt.debug.cw.symbian.tests";
|
|
40 |
|
|
41 |
// The shared instance
|
|
42 |
private static TestsPlugin plugin;
|
|
43 |
|
|
44 |
/**
|
|
45 |
* The constructor
|
|
46 |
*/
|
|
47 |
public TestsPlugin() {
|
|
48 |
}
|
|
49 |
|
|
50 |
/*
|
|
51 |
* (non-Javadoc)
|
|
52 |
* @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
|
|
53 |
*/
|
|
54 |
public void start(BundleContext context) throws Exception {
|
|
55 |
super.start(context);
|
|
56 |
plugin = this;
|
|
57 |
}
|
|
58 |
|
|
59 |
/*
|
|
60 |
* (non-Javadoc)
|
|
61 |
* @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
|
|
62 |
*/
|
|
63 |
public void stop(BundleContext context) throws Exception {
|
|
64 |
plugin = null;
|
|
65 |
super.stop(context);
|
|
66 |
}
|
|
67 |
|
|
68 |
/**
|
|
69 |
* Returns the shared instance
|
|
70 |
*
|
|
71 |
* @return the shared instance
|
|
72 |
*/
|
|
73 |
public static TestsPlugin getDefault() {
|
|
74 |
return plugin;
|
|
75 |
}
|
|
76 |
|
|
77 |
/************* Utility methods **********************/
|
|
78 |
|
|
79 |
public static String[] getFileNamesInFolder(final String folderName, final String fileExtention) {
|
|
80 |
File folder = new File(folderName);
|
|
81 |
|
|
82 |
String[] files = folder.list(new FilenameFilter() {
|
|
83 |
|
|
84 |
public boolean accept(File dir, String name) {
|
|
85 |
return name.endsWith(fileExtention);
|
|
86 |
}
|
|
87 |
|
|
88 |
});
|
|
89 |
|
|
90 |
return files;
|
|
91 |
}
|
|
92 |
|
|
93 |
public static String[] getFileFullNamesInFolder(final String folderName, final String fileExtention) {
|
|
94 |
String[] files = getFileNamesInFolder(folderName, fileExtention);
|
|
95 |
|
|
96 |
for (int i=0; i < files.length; i++) {
|
|
97 |
files[i] = folderName + "\\" + files[i];
|
|
98 |
}
|
|
99 |
|
|
100 |
return files;
|
|
101 |
}
|
|
102 |
|
|
103 |
/**
|
|
104 |
* Get location of this plugin.
|
|
105 |
*
|
|
106 |
* @return
|
|
107 |
* @throws IOException
|
|
108 |
*/
|
|
109 |
public static String getPluginPath() throws IOException {
|
|
110 |
if (!Platform.isRunning()) {
|
|
111 |
// get file relative to CWD (i.e. this project)
|
|
112 |
File f = new File(".");
|
|
113 |
f = f.getCanonicalFile();
|
|
114 |
return f.getAbsolutePath();
|
|
115 |
} else {
|
|
116 |
|
|
117 |
if (getDefault() == null)
|
|
118 |
return null;
|
|
119 |
Bundle bundle = getDefault().getBundle();
|
|
120 |
if (bundle == null)
|
|
121 |
return null;
|
|
122 |
URL url = FileLocator.find(bundle, new Path("."), null);
|
|
123 |
if (url == null)
|
|
124 |
TestCase.fail("could not find URL for bundle: " + bundle);
|
|
125 |
url = FileLocator.resolve(url);
|
|
126 |
TestCase.assertEquals("file", url.getProtocol());
|
|
127 |
|
|
128 |
return url.getPath();
|
|
129 |
}
|
|
130 |
}
|
|
131 |
|
|
132 |
/**
|
|
133 |
* Load a file relative to this plugin in the running workbench
|
|
134 |
*
|
|
135 |
* @param file
|
|
136 |
* @return File
|
|
137 |
* @throws IOException
|
|
138 |
*/
|
|
139 |
public static File pluginRelativeFile(String fileName) throws IOException {
|
|
140 |
String bundlePath = getPluginPath();
|
|
141 |
|
|
142 |
if (bundlePath == null)
|
|
143 |
return null;
|
|
144 |
|
|
145 |
return new File(bundlePath, fileName);
|
|
146 |
}
|
|
147 |
|
|
148 |
/**
|
|
149 |
* Find a file relative to the project. Works if running
|
|
150 |
* in the workbench or standalone.
|
|
151 |
* @param file the relative path (from the project) to the file
|
|
152 |
* @return File
|
|
153 |
*/
|
|
154 |
public static File projectRelativeFile(String file) throws Exception {
|
|
155 |
File f;
|
|
156 |
if (!Platform.isRunning()) {
|
|
157 |
// get file relative to CWD (i.e. this project)
|
|
158 |
f = new File(file);
|
|
159 |
f = f.getCanonicalFile();
|
|
160 |
} else {
|
|
161 |
// get file relative to running plugin (still this project)
|
|
162 |
f = pluginRelativeFile(file);
|
|
163 |
}
|
|
164 |
if (f == null)
|
|
165 |
TestCase.fail("Cannot find file " + file + " relative to project");
|
|
166 |
return f;
|
|
167 |
}
|
|
168 |
}
|