Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 177676 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/internal/junit/ui/JUnitPlugin.java (-6 / +19 lines)
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 320-335 Link Here
320
	 * @since 3.2
320
	 * @since 3.2
321
	 */
321
	 */
322
	public Bundle getBundle(String bundleName) {
322
	public Bundle getBundle(String bundleName) {
323
		Bundle bundle= Platform.getBundle(bundleName);
323
		Bundle[] bundles= getBundles(bundleName, null);
324
		if (bundle != null)
324
		if (bundles != null && bundles.length > 0)
325
			return bundle;
325
			return bundles[0];
326
		return null;
327
	}
328
	
329
	/**
330
	 * Returns the bundles for a given bundle name,
331
	 * 
332
	 * @param bundleName the bundle name
333
	 * @return the bundles of the given name
334
	 */
335
	public Bundle[] getBundles(String bundleName, String version) {
336
		Bundle[] bundles= Platform.getBundles(bundleName, version);
337
		if (bundles != null)
338
			return bundles;
326
		
339
		
327
		// Accessing unresolved bundle
340
		// Accessing unresolved bundle
328
		ServiceReference serviceRef= fBundleContext.getServiceReference(PackageAdmin.class.getName());
341
		ServiceReference serviceRef= fBundleContext.getServiceReference(PackageAdmin.class.getName());
329
		PackageAdmin admin= (PackageAdmin)fBundleContext.getService(serviceRef);
342
		PackageAdmin admin= (PackageAdmin)fBundleContext.getService(serviceRef);
330
		Bundle[] bundles= admin.getBundles(bundleName, null);
343
		bundles= admin.getBundles(bundleName, version);
331
		if (bundles != null && bundles.length > 0)
344
		if (bundles != null && bundles.length > 0)
332
			return bundles[0];
345
			return bundles;
333
		return null;
346
		return null;
334
	}
347
	}
335
348
(-)src/org/eclipse/jdt/internal/junit/buildpath/JUnitHomeInitializer.java (-3 / +3 lines)
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 34-40 Link Here
34
34
35
	private void initializeHome() {
35
	private void initializeHome() {
36
		try {
36
		try {
37
			IPath location= BuildPathSupport.getBundleLocation(BuildPathSupport.JUNIT3_PLUGIN_ID);
37
			IPath location= BuildPathSupport.getBundleLocation(BuildPathSupport.JUNIT3_PLUGIN);
38
			if (location != null) {
38
			if (location != null) {
39
				JavaCore.setClasspathVariable(JUnitPlugin.JUNIT_HOME, location, null);
39
				JavaCore.setClasspathVariable(JUnitPlugin.JUNIT_HOME, location, null);
40
			} else {
40
			} else {
Lines 47-53 Link Here
47
	
47
	
48
	private void initializeSource() {
48
	private void initializeSource() {
49
		try {
49
		try {
50
			IPath sourceLocation= BuildPathSupport.getSourceLocation(BuildPathSupport.JUNIT3_PLUGIN_ID);
50
			IPath sourceLocation= BuildPathSupport.getSourceLocation(BuildPathSupport.JUNIT3_PLUGIN);
51
			if (sourceLocation != null) {
51
			if (sourceLocation != null) {
52
				JavaCore.setClasspathVariable(JUnitPlugin.JUNIT_SRC_HOME, sourceLocation, null);
52
				JavaCore.setClasspathVariable(JUnitPlugin.JUNIT_SRC_HOME, sourceLocation, null);
53
			} else {
53
			} else {
(-)src/org/eclipse/jdt/internal/junit/buildpath/BuildPathSupport.java (-13 / +49 lines)
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= { };

Return to bug 177676