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/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 (-12 / +44 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 18-23 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;
21
24
22
import org.eclipse.jdt.core.IAccessRule;
25
import org.eclipse.jdt.core.IAccessRule;
23
import org.eclipse.jdt.core.IClasspathAttribute;
26
import org.eclipse.jdt.core.IClasspathAttribute;
Lines 28-44 Link Here
28
import org.eclipse.jdt.internal.junit.ui.JUnitPreferencesConstants;
31
import org.eclipse.jdt.internal.junit.ui.JUnitPreferencesConstants;
29
32
30
import org.osgi.framework.Bundle;
33
import org.osgi.framework.Bundle;
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
	private static class JUnitPluginDescription {
38
	public static final String JUNIT4_PLUGIN_ID= "org.junit4"; //$NON-NLS-1$
42
		public String bundleId;
43
		public VersionRange versionRange;
44
		
45
		public JUnitPluginDescription(String bundleId, VersionRange versionRange) {
46
			this.bundleId= bundleId;
47
			this.versionRange= versionRange;
48
		}
49
		
50
		public Bundle getBundle() {
51
			Bundle[] bundles= Platform.getBundles(this.bundleId, 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("Bundle-Version"); //$NON-NLS-1$
56
					try {
57
						if (this.versionRange.isIncluded(Version.parseVersion(version))) {
58
							return curr;
59
						}
60
					} catch (IllegalArgumentException e) {
61
						// ignore
62
					}
63
				}
64
			}
65
			return null;
66
		}
67
	}
68
	
69
	public static final JUnitPluginDescription JUNIT3_PLUGIN= new JUnitPluginDescription("org.junit", new VersionRange("[3.8.2,3.9)")); //$NON-NLS-1$ //$NON-NLS-2$
70
	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
	
71
	
40
	public static IPath getBundleLocation(String bundleName) {
72
	public static IPath getBundleLocation(JUnitPluginDescription pluginDesc) {
41
		Bundle bundle= JUnitPlugin.getDefault().getBundle(bundleName);
73
		Bundle bundle= pluginDesc.getBundle();
42
		if (bundle == null)
74
		if (bundle == null)
43
			return null;
75
			return null;
44
		
76
		
Lines 52-59 Link Here
52
		return Path.fromOSString(fullPath);
84
		return Path.fromOSString(fullPath);
53
	}
85
	}
54
	
86
	
55
	public static IPath getSourceLocation(String bundleName) {
87
	public static IPath getSourceLocation(JUnitPluginDescription pluginDesc) {
56
		Bundle bundle= JUnitPlugin.getDefault().getBundle(bundleName);
88
		Bundle bundle= pluginDesc.getBundle();
57
		if (bundle == null)
89
		if (bundle == null)
58
			return null;
90
			return null;
59
			
91
			
Lines 72-78 Link Here
72
			return null;
104
			return null;
73
		}
105
		}
74
		String fullPath= new File(local.getPath()).getAbsolutePath() 
106
		String fullPath= new File(local.getPath()).getAbsolutePath() 
75
			+ File.separator + "src" + File.separator + bundleName + "_" + version;   //$NON-NLS-1$ //$NON-NLS-2$
107
			+ File.separator + "src" + File.separator + pluginDesc.bundleId + "_" + version;   //$NON-NLS-1$ //$NON-NLS-2$
76
		return Path.fromOSString(fullPath);
108
		return Path.fromOSString(fullPath);
77
	}
109
	}
78
	
110
	
Lines 85-95 Link Here
85
	}
117
	}
86
	
118
	
87
	public static IClasspathEntry getJUnit3LibraryEntry() {
119
	public static IClasspathEntry getJUnit3LibraryEntry() {
88
		IPath bundleBase= getBundleLocation(JUNIT3_PLUGIN_ID);
120
		IPath bundleBase= getBundleLocation(JUNIT3_PLUGIN);
89
		if (bundleBase != null) {
121
		if (bundleBase != null) {
90
			IPath jarLocation= bundleBase.append("junit.jar"); //$NON-NLS-1$
122
			IPath jarLocation= bundleBase.append("junit.jar"); //$NON-NLS-1$
91
			
123
			
92
			IPath sourceBase= getSourceLocation(JUNIT3_PLUGIN_ID);
124
			IPath sourceBase= getSourceLocation(JUNIT3_PLUGIN);
93
			IPath srcLocation= sourceBase != null ? sourceBase.append("junitsrc.zip") : null; //$NON-NLS-1$
125
			IPath srcLocation= sourceBase != null ? sourceBase.append("junitsrc.zip") : null; //$NON-NLS-1$
94
			
126
			
95
			IAccessRule[] accessRules= { };
127
			IAccessRule[] accessRules= { };
Lines 103-113 Link Here
103
	}
135
	}
104
	
136
	
105
	public static IClasspathEntry getJUnit4LibraryEntry() {
137
	public static IClasspathEntry getJUnit4LibraryEntry() {
106
		IPath bundleBase= getBundleLocation(JUNIT4_PLUGIN_ID);
138
		IPath bundleBase= getBundleLocation(JUNIT4_PLUGIN);
107
		if (bundleBase != null) {
139
		if (bundleBase != null) {
108
			IPath jarLocation= bundleBase.append("junit.jar"); //$NON-NLS-1$
140
			IPath jarLocation= bundleBase.append("junit.jar"); //$NON-NLS-1$
109
			
141
			
110
			IPath sourceBase= getSourceLocation(JUNIT4_PLUGIN_ID);
142
			IPath sourceBase= getSourceLocation(JUNIT4_PLUGIN);
111
			IPath srcLocation= sourceBase != null ? sourceBase.append("junitsrc.zip") : null; //$NON-NLS-1$
143
			IPath srcLocation= sourceBase != null ? sourceBase.append("junitsrc.zip") : null; //$NON-NLS-1$
112
			
144
			
113
			IAccessRule[] accessRules= { };
145
			IAccessRule[] accessRules= { };

Return to bug 177676