diff options
| author | Markus Keller | 2013-02-01 20:10:50 +0000 |
|---|---|---|
| committer | Markus Keller | 2013-02-04 16:39:18 +0000 |
| commit | 586eb3388af84b4262f1ffc03f6ee8d4d8f899aa (patch) | |
| tree | f5fa0290689254d262d5d31c407b530efda722f7 | |
| parent | d79155d1054134764d5883aa594c7cd7c1884ef1 (diff) | |
| download | eclipse.jdt.ui-586eb3388af84b4262f1ffc03f6ee8d4d8f899aa.tar.gz eclipse.jdt.ui-586eb3388af84b4262f1ffc03f6ee8d4d8f899aa.tar.xz eclipse.jdt.ui-586eb3388af84b4262f1ffc03f6ee8d4d8f899aa.zip | |
Bug 391433: [JUnit] Remove JUnit 3 from Eclipsev20130204-163918
Preparation: make Eclipse JUnit support work without JUnit 3
7 files changed, 70 insertions, 24 deletions
diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/JunitPreferenceInitializer.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/JunitPreferenceInitializer.java index ea45d6a13a..37e5ddf9f8 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/JunitPreferenceInitializer.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/JunitPreferenceInitializer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -44,7 +44,7 @@ public class JunitPreferenceInitializer extends AbstractPreferenceInitializer { // see http://sourceforge.net/tracker/index.php?func=detail&aid=1877429&group_id=15278&atid=115278 prefs.put(JUnitPreferencesConstants.JUNIT3_JAVADOC, "http://www.junit.org/junit/javadoc/3.8.1"); //$NON-NLS-1$ - prefs.put(JUnitPreferencesConstants.JUNIT4_JAVADOC, "http://www.junit.org/junit/javadoc/4.5"); //$NON-NLS-1$ + prefs.put(JUnitPreferencesConstants.JUNIT4_JAVADOC, "http://kentbeck.github.com/junit/javadoc/4.10"); //$NON-NLS-1$ // migrate old instance scope prefs try { diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/BuildPathSupport.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/BuildPathSupport.java index e88c1596d0..272c5a6ec8 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/BuildPathSupport.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/BuildPathSupport.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -72,8 +72,6 @@ public class BuildPathSupport { IPath bundleRootLocation= getLibraryLocation(bundleInfo, bundleLocation); IPath srcLocation= getSourceLocation(bundleInfo); - IAccessRule[] accessRules= { }; - String javadocLocation= Platform.getPreferencesService().getString(JUnitCorePlugin.CORE_PLUGIN_ID, javadocPreferenceKey, "", null); //$NON-NLS-1$ IClasspathAttribute[] attributes; if (javadocLocation.length() == 0) { @@ -82,11 +80,15 @@ public class BuildPathSupport { attributes= new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javadocLocation) }; } - return JavaCore.newLibraryEntry(bundleRootLocation, srcLocation, null, accessRules, attributes, false); + return JavaCore.newLibraryEntry(bundleRootLocation, srcLocation, null, getAccessRules(), attributes, false); } return null; } + public IAccessRule[] getAccessRules() { + return new IAccessRule[0]; + } + private IPath getLibraryLocation(BundleInfo bundleInfo, IPath bundleLocation) { IPath bundleRootLocation= null; if (bundleRoot != null) @@ -108,8 +110,11 @@ public class BuildPathSupport { } if (srcLocation == null) { - // Try exact version - BundleInfo sourceBundleInfo= P2Utils.findBundle(sourceBundleId, new Version(bundleInfo.getVersion()), true); + BundleInfo sourceBundleInfo= null; + if (bundleInfo != null) { + // Try exact version + sourceBundleInfo= P2Utils.findBundle(sourceBundleId, new Version(bundleInfo.getVersion()), true); + } if (sourceBundleInfo == null) { // Try version range sourceBundleInfo= P2Utils.findBundle(sourceBundleId, versionRange, true); @@ -157,12 +162,23 @@ public class BuildPathSupport { public static final JUnitPluginDescription JUNIT3_PLUGIN= new JUnitPluginDescription( "org.junit", new VersionRange("[3.8.2,3.9)"), "junit.jar", "junit.jar", "org.junit.source", "source-bundle/", JUnitPreferencesConstants.JUNIT3_JAVADOC); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ - private static final JUnitPluginDescription JUNIT4_PLUGIN= new JUnitPluginDescription( + public static final JUnitPluginDescription JUNIT4_PLUGIN= new JUnitPluginDescription( "org.junit", new VersionRange("[4.7.0,5.0.0)"), "junit.jar", "junit.jar", "org.junit.source", "source-bundle/", JUnitPreferencesConstants.JUNIT4_JAVADOC); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ private static final JUnitPluginDescription HAMCREST_CORE_PLUGIN= new JUnitPluginDescription( "org.hamcrest.core", new VersionRange("[1.1.0,2.0.0)"), null, "org.hamcrest.core_1.*.jar", "org.hamcrest.core.source", "source-bundle/", JUnitPreferencesConstants.HAMCREST_CORE_JAVADOC); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + public static final JUnitPluginDescription JUNIT4_AS_3_PLUGIN= new JUnitPluginDescription( + JUNIT4_PLUGIN.bundleId, JUNIT4_PLUGIN.versionRange, JUNIT4_PLUGIN.bundleRoot, JUNIT4_PLUGIN.binaryImportedRoot, + JUNIT4_PLUGIN.sourceBundleId, JUNIT4_PLUGIN.repositorySource, JUNIT4_PLUGIN.javadocPreferenceKey) { + public IAccessRule[] getAccessRules() { + return new IAccessRule[] { + JavaCore.newAccessRule(new Path("junit/"), IAccessRule.K_ACCESSIBLE), //$NON-NLS-1$ + JavaCore.newAccessRule(new Path("**/*"), IAccessRule.K_NON_ACCESSIBLE) //$NON-NLS-1$ + }; + } + }; + /** * @return the JUnit3 classpath container */ @@ -178,21 +194,28 @@ public class BuildPathSupport { } /** - * @return the org.junit library + * @return the org.junit version 3 library, or <code>null</code> if not available */ public static IClasspathEntry getJUnit3LibraryEntry() { return JUNIT3_PLUGIN.getLibraryEntry(); } /** - * @return the org.junit4 library + * @return the org.junit version 4 library, or <code>null</code> if not available */ public static IClasspathEntry getJUnit4LibraryEntry() { return JUNIT4_PLUGIN.getLibraryEntry(); } /** - * @return the org.hamcrest.core library + * @return the org.junit version 4 library with access rules for JUnit 3, or <code>null</code> if not available + */ + public static IClasspathEntry getJUnit4as3LibraryEntry() { + return JUNIT4_AS_3_PLUGIN.getLibraryEntry(); + } + + /** + * @return the org.hamcrest.core library, or <code>null</code> if not available */ public static IClasspathEntry getHamcrestCoreLibraryEntry() { return HAMCREST_CORE_PLUGIN.getLibraryEntry(); diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerInitializer.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerInitializer.java index e1e0f246ec..ea6fe8851d 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerInitializer.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerInitializer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 IBM Corporation and others. + * Copyright (c) 2006, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -96,6 +96,9 @@ public class JUnitContainerInitializer extends ClasspathContainerInitializer { String version= containerPath.segment(1); if (JUNIT3_8_1.equals(version) || JUNIT3.equals(version)) { entry= BuildPathSupport.getJUnit3LibraryEntry(); + if (entry == null) { // JUnit 4 includes most of JUnit 3, so let's cheat + entry= BuildPathSupport.getJUnit4as3LibraryEntry(); + } } else if (JUNIT4.equals(version)) { entry= BuildPathSupport.getJUnit4LibraryEntry(); entry2= BuildPathSupport.getHamcrestCoreLibraryEntry(); @@ -127,7 +130,7 @@ public class JUnitContainerInitializer extends ClasspathContainerInitializer { * @see org.eclipse.jdt.core.ClasspathContainerInitializer#getAccessRulesStatus(org.eclipse.core.runtime.IPath, org.eclipse.jdt.core.IJavaProject) */ public IStatus getAccessRulesStatus(IPath containerPath, IJavaProject project) { - return NOT_SUPPORTED; + return READ_ONLY; } /* (non-Javadoc) diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitHomeInitializer.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitHomeInitializer.java index 743c67bdc0..032bb30784 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitHomeInitializer.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitHomeInitializer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -35,6 +35,9 @@ public class JUnitHomeInitializer extends ClasspathVariableInitializer { private void initializeHome() { try { IPath location= BuildPathSupport.JUNIT3_PLUGIN.getBundleLocation(); + if (location == null) + location= BuildPathSupport.JUNIT4_PLUGIN.getBundleLocation(); // JUnit 4 includes most of JUnit 3, so let's cheat + if (location != null) { JavaCore.setClasspathVariable(JUnitCorePlugin.JUNIT_HOME, location, null); } else { @@ -48,6 +51,9 @@ public class JUnitHomeInitializer extends ClasspathVariableInitializer { private void initializeSource() { try { IPath sourceLocation= BuildPathSupport.JUNIT3_PLUGIN.getSourceBundleLocation(); + if (sourceLocation == null) + sourceLocation= BuildPathSupport.JUNIT4_PLUGIN.getSourceBundleLocation(); // JUnit 4 includes most of JUnit 3, so let's cheat + if (sourceLocation != null) { JavaCore.setClasspathVariable(JUnitCorePlugin.JUNIT_SRC_HOME, sourceLocation, null); } else { diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/P2Utils.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/P2Utils.java index 2a11bc221a..195e599728 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/P2Utils.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/P2Utils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 IBM Corporation and others. + * Copyright (c) 2009, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -60,7 +60,7 @@ class P2Utils { /** * Finds the bundle info for the given arguments. * <p> - * The first match will be returned if more than one bundle matches the arguments. + * The best match (latest version) will be returned if more than one bundle matches the arguments. * </p> * * @param symbolicName the symbolic name diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/util/CoreTestSearchEngine.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/util/CoreTestSearchEngine.java index f5ac897742..e5c430a7b0 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/util/CoreTestSearchEngine.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/util/CoreTestSearchEngine.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,11 +13,14 @@ package org.eclipse.jdt.internal.junit.util; import java.util.Collection; import java.util.Set; +import org.eclipse.jdt.junit.JUnitCore; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jdt.core.Flags; import org.eclipse.jdt.core.IClassFile; +import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IJavaProject; @@ -39,9 +42,9 @@ import org.eclipse.jdt.core.search.SearchParticipant; import org.eclipse.jdt.core.search.SearchPattern; import org.eclipse.jdt.core.search.SearchRequestor; +import org.eclipse.jdt.internal.junit.JUnitCorePlugin; import org.eclipse.jdt.internal.junit.launcher.ITestKind; import org.eclipse.jdt.internal.junit.launcher.TestKindRegistry; -import org.eclipse.jdt.internal.junit.JUnitCorePlugin; /** @@ -104,7 +107,16 @@ public class CoreTestSearchEngine { public static boolean hasTestAnnotation(IJavaProject project) { try { - return project != null && project.findType(JUnitCorePlugin.JUNIT4_ANNOTATION_NAME) != null; + if (project != null) { + IType type= project.findType(JUnitCorePlugin.JUNIT4_ANNOTATION_NAME); + if (type != null) { + // @Test annotation is not accessible if the JUnit classpath container is set to JUnit 3 + // (although it may resolve to a JUnit 4 JAR) + IPackageFragmentRoot root= (IPackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); + IClasspathEntry cpEntry= root.getRawClasspathEntry(); + return ! JUnitCore.JUNIT3_CONTAINER_PATH.equals(cpEntry.getPath()); + } + } } catch (JavaModelException e) { // not available } diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerWizardPage.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerWizardPage.java index 58e42c3024..540488f2a3 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerWizardPage.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 IBM Corporation and others. + * Copyright (c) 2006, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -123,10 +123,10 @@ public class JUnitContainerWizardPage extends NewElementWizardPage implements IC data.widthHint= converter.convertWidthInCharsToPixels(15); fVersionCombo.setLayoutData(data); - if (fContainerEntryResult != null && JUnitCore.JUNIT4_CONTAINER_PATH.equals(fContainerEntryResult.getPath())) { - fVersionCombo.select(1); - } else { + if (fContainerEntryResult != null && JUnitCore.JUNIT3_CONTAINER_PATH.equals(fContainerEntryResult.getPath())) { fVersionCombo.select(0); + } else { + fVersionCombo.select(1); } fVersionCombo.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { @@ -180,6 +180,8 @@ public class JUnitContainerWizardPage extends NewElementWizardPage implements IC } else { containerPath= JUnitCore.JUNIT3_CONTAINER_PATH; libEntry= BuildPathSupport.getJUnit3LibraryEntry(); + if (libEntry == null) + libEntry= BuildPathSupport.getJUnit4as3LibraryEntry(); // JUnit 4 includes most of JUnit 3, so let's cheat } if (libEntry == null) { |
