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