|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2007 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2006 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 18-26
Link Here
|
| 18 |
import org.eclipse.core.runtime.FileLocator; |
18 |
import org.eclipse.core.runtime.FileLocator; |
| 19 |
import org.eclipse.core.runtime.IPath; |
19 |
import org.eclipse.core.runtime.IPath; |
| 20 |
import org.eclipse.core.runtime.Path; |
20 |
import org.eclipse.core.runtime.Path; |
| 21 |
import org.eclipse.core.runtime.Platform; |
|
|
| 22 |
|
| 23 |
import org.eclipse.osgi.service.resolver.VersionRange; |
| 24 |
|
21 |
|
| 25 |
import org.eclipse.jdt.core.IAccessRule; |
22 |
import org.eclipse.jdt.core.IAccessRule; |
| 26 |
import org.eclipse.jdt.core.IClasspathAttribute; |
23 |
import org.eclipse.jdt.core.IClasspathAttribute; |
|
Lines 31-81
Link Here
|
| 31 |
import org.eclipse.jdt.internal.junit.ui.JUnitPreferencesConstants; |
28 |
import org.eclipse.jdt.internal.junit.ui.JUnitPreferencesConstants; |
| 32 |
|
29 |
|
| 33 |
import org.osgi.framework.Bundle; |
30 |
import org.osgi.framework.Bundle; |
| 34 |
import org.osgi.framework.Constants; |
|
|
| 35 |
import org.osgi.framework.Version; |
| 36 |
|
31 |
|
| 37 |
/** |
32 |
/** |
| 38 |
* |
33 |
* |
| 39 |
*/ |
34 |
*/ |
| 40 |
public class BuildPathSupport { |
35 |
public class BuildPathSupport { |
| 41 |
|
36 |
|
| 42 |
public static class JUnitPluginDescription { |
37 |
public static final String JUNIT3_PLUGIN_ID= "org.junit"; //$NON-NLS-1$ |
| 43 |
private final String fBundleId; |
38 |
public static final String JUNIT4_PLUGIN_ID= "org.junit4"; //$NON-NLS-1$ |
| 44 |
private final VersionRange fVersionRange; |
|
|
| 45 |
|
| 46 |
public JUnitPluginDescription(String bundleId, VersionRange versionRange) { |
| 47 |
fBundleId= bundleId; |
| 48 |
fVersionRange= versionRange; |
| 49 |
} |
| 50 |
|
| 51 |
public Bundle getBundle() { |
| 52 |
Bundle[] bundles= Platform.getBundles(fBundleId, null); |
| 53 |
if (bundles != null) { |
| 54 |
for (int i= 0; i < bundles.length; i++) { |
| 55 |
Bundle curr= bundles[i]; |
| 56 |
String version= (String) curr.getHeaders().get(Constants.BUNDLE_VERSION); |
| 57 |
try { |
| 58 |
if (fVersionRange.isIncluded(Version.parseVersion(version))) { |
| 59 |
return curr; |
| 60 |
} |
| 61 |
} catch (IllegalArgumentException e) { |
| 62 |
// ignore |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
return null; |
| 67 |
} |
| 68 |
|
| 69 |
public String getBundleId() { |
| 70 |
return fBundleId; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
public static final JUnitPluginDescription JUNIT3_PLUGIN= new JUnitPluginDescription("org.junit", new VersionRange("[3.8.2,3.9)")); //$NON-NLS-1$ //$NON-NLS-2$ |
| 75 |
public static final JUnitPluginDescription JUNIT4_PLUGIN= new JUnitPluginDescription("org.junit4", new VersionRange("[4.3.1,4.4.0)")); //$NON-NLS-1$ //$NON-NLS-2$ |
| 76 |
|
39 |
|
| 77 |
public static IPath getBundleLocation(JUnitPluginDescription pluginDesc) { |
40 |
public static IPath getBundleLocation(String bundleName) { |
| 78 |
Bundle bundle= pluginDesc.getBundle(); |
41 |
Bundle bundle= JUnitPlugin.getDefault().getBundle(bundleName); |
| 79 |
if (bundle == null) |
42 |
if (bundle == null) |
| 80 |
return null; |
43 |
return null; |
| 81 |
|
44 |
|
|
Lines 89-96
Link Here
|
| 89 |
return Path.fromOSString(fullPath); |
52 |
return Path.fromOSString(fullPath); |
| 90 |
} |
53 |
} |
| 91 |
|
54 |
|
| 92 |
public static IPath getSourceLocation(JUnitPluginDescription pluginDesc) { |
55 |
public static IPath getSourceLocation(String bundleName) { |
| 93 |
Bundle bundle= pluginDesc.getBundle(); |
56 |
Bundle bundle= JUnitPlugin.getDefault().getBundle(bundleName); |
| 94 |
if (bundle == null) |
57 |
if (bundle == null) |
| 95 |
return null; |
58 |
return null; |
| 96 |
|
59 |
|
|
Lines 109-115
Link Here
|
| 109 |
return null; |
72 |
return null; |
| 110 |
} |
73 |
} |
| 111 |
String fullPath= new File(local.getPath()).getAbsolutePath() |
74 |
String fullPath= new File(local.getPath()).getAbsolutePath() |
| 112 |
+ File.separator + "src" + File.separator + pluginDesc.getBundleId() + "_" + version; //$NON-NLS-1$ //$NON-NLS-2$ |
75 |
+ File.separator + "src" + File.separator + bundleName + "_" + version; //$NON-NLS-1$ //$NON-NLS-2$ |
| 113 |
return Path.fromOSString(fullPath); |
76 |
return Path.fromOSString(fullPath); |
| 114 |
} |
77 |
} |
| 115 |
|
78 |
|
|
Lines 122-132
Link Here
|
| 122 |
} |
85 |
} |
| 123 |
|
86 |
|
| 124 |
public static IClasspathEntry getJUnit3LibraryEntry() { |
87 |
public static IClasspathEntry getJUnit3LibraryEntry() { |
| 125 |
IPath bundleBase= getBundleLocation(JUNIT3_PLUGIN); |
88 |
IPath bundleBase= getBundleLocation(JUNIT3_PLUGIN_ID); |
| 126 |
if (bundleBase != null) { |
89 |
if (bundleBase != null) { |
| 127 |
IPath jarLocation= bundleBase.append("junit.jar"); //$NON-NLS-1$ |
90 |
IPath jarLocation= bundleBase.append("junit.jar"); //$NON-NLS-1$ |
| 128 |
|
91 |
|
| 129 |
IPath sourceBase= getSourceLocation(JUNIT3_PLUGIN); |
92 |
IPath sourceBase= getSourceLocation(JUNIT3_PLUGIN_ID); |
| 130 |
IPath srcLocation= sourceBase != null ? sourceBase.append("junitsrc.zip") : null; //$NON-NLS-1$ |
93 |
IPath srcLocation= sourceBase != null ? sourceBase.append("junitsrc.zip") : null; //$NON-NLS-1$ |
| 131 |
|
94 |
|
| 132 |
IAccessRule[] accessRules= { }; |
95 |
IAccessRule[] accessRules= { }; |
|
Lines 140-150
Link Here
|
| 140 |
} |
103 |
} |
| 141 |
|
104 |
|
| 142 |
public static IClasspathEntry getJUnit4LibraryEntry() { |
105 |
public static IClasspathEntry getJUnit4LibraryEntry() { |
| 143 |
IPath bundleBase= getBundleLocation(JUNIT4_PLUGIN); |
106 |
IPath bundleBase= getBundleLocation(JUNIT4_PLUGIN_ID); |
| 144 |
if (bundleBase != null) { |
107 |
if (bundleBase != null) { |
| 145 |
IPath jarLocation= bundleBase.append("junit.jar"); //$NON-NLS-1$ |
108 |
IPath jarLocation= bundleBase.append("junit.jar"); //$NON-NLS-1$ |
| 146 |
|
109 |
|
| 147 |
IPath sourceBase= getSourceLocation(JUNIT4_PLUGIN); |
110 |
IPath sourceBase= getSourceLocation(JUNIT4_PLUGIN_ID); |
| 148 |
IPath srcLocation= sourceBase != null ? sourceBase.append("junitsrc.zip") : null; //$NON-NLS-1$ |
111 |
IPath srcLocation= sourceBase != null ? sourceBase.append("junitsrc.zip") : null; //$NON-NLS-1$ |
| 149 |
|
112 |
|
| 150 |
IAccessRule[] accessRules= { }; |
113 |
IAccessRule[] accessRules= { }; |