diff --git a/ui/org.eclipse.pde.ui.tests/META-INF/MANIFEST.MF b/ui/org.eclipse.pde.ui.tests/META-INF/MANIFEST.MF index 6fe132806c..f023ede4b2 100644 --- a/ui/org.eclipse.pde.ui.tests/META-INF/MANIFEST.MF +++ b/ui/org.eclipse.pde.ui.tests/META-INF/MANIFEST.MF @@ -40,7 +40,18 @@ Require-Bundle: org.eclipse.pde.ui, org.eclipse.pde.genericeditor.extension, org.eclipse.equinox.simpleconfigurator.manipulator;bundle-version="2.1.300", org.eclipse.platform, - org.eclipse.ui.ide.application + org.eclipse.ui.ide.application, + org.eclipse.pde.api.tools, + org.eclipse.jsch.core, + org.eclipse.jdt.doc.user, + org.junit.source;resolution:=optional, + org.eclipse.pde.ui.source;resolution:=optional, + org.apache.ant.source;resolution:=optional, + org.eclipse.jdt.debug.source;resolution:=optional, + org.eclipse.jsch.core.source;resolution:=optional, + org.eclipse.core.filebuffers.source;resolution:=optional, + org.eclipse.jdt.doc.user;resolution:=optional, + org.eclipse.pde.build.source;resolution:=optional Import-Package: javax.annotation;version="[1.3.0,2.0.0)", javax.inject;version="[1.0.0,2.0.0)", org.assertj.core.api;version="3.14.0", diff --git a/ui/org.eclipse.pde.ui.tests/pom.xml b/ui/org.eclipse.pde.ui.tests/pom.xml index 74f53c06b5..bbc8251291 100644 --- a/ui/org.eclipse.pde.ui.tests/pom.xml +++ b/ui/org.eclipse.pde.ui.tests/pom.xml @@ -25,7 +25,7 @@ -warn:-discouraged true ${project.artifactId} - org.eclipse.pde.ui.tests.AllPDEMinimalTests + org.eclipse.pde.ui.tests.AllPDETests diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/AllPDEMinimalTests.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/AllPDEMinimalTests.java deleted file mode 100644 index d7f7ecb091..0000000000 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/AllPDEMinimalTests.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.pde.ui.tests; - -import org.eclipse.pde.core.tests.internal.AllPDECoreTests; -import org.eclipse.pde.core.tests.internal.classpath.ClasspathResolutionTest; -import org.eclipse.pde.core.tests.internal.core.builders.BundleErrorReporterTest; -import org.eclipse.pde.core.tests.internal.util.PDESchemaHelperTest; -import org.eclipse.pde.ui.tests.build.properties.AllValidatorTests; -import org.eclipse.pde.ui.tests.classpathresolver.ClasspathResolverTest; -import org.eclipse.pde.ui.tests.launcher.AllLauncherTests; -import org.eclipse.pde.ui.tests.model.bundle.AllBundleModelTests; -import org.eclipse.pde.ui.tests.model.xml.AllXMLModelTests; -import org.eclipse.pde.ui.tests.nls.AllNLSTests; -import org.eclipse.pde.ui.tests.preferences.AllPreferenceTests; -import org.eclipse.pde.ui.tests.project.BundleRootTests; -import org.eclipse.pde.ui.tests.project.DynamicPluginProjectReferencesTest; -import org.eclipse.pde.ui.tests.project.PluginRegistryTestsMinimal; -import org.eclipse.pde.ui.tests.project.ProjectCreationTests; -import org.eclipse.pde.ui.tests.runtime.AllPDERuntimeTests; -import org.eclipse.pde.ui.tests.target.AllTargetMinimalTests; -import org.eclipse.pde.ui.tests.views.log.AllLogViewTests; -import org.eclipse.pde.ui.tests.wizards.AllNewProjectMinimalTests; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * They run on minimal plugin bundles and dont require the whole SDK ( for - * hudson gerrit). This class is refactored out of AllPDETests - * - */ - -@RunWith(Suite.class) -@SuiteClasses({ AllTargetMinimalTests.class, AllNewProjectMinimalTests.class, AllPreferenceTests.class, - // AllImportTests.class, - AllBundleModelTests.class, AllXMLModelTests.class, AllValidatorTests.class, AllNLSTests.class, - AllPDERuntimeTests.class, - // ExportBundleTests.class, - AllLauncherTests.class, AllLogViewTests.class, ProjectCreationTests.class, BundleRootTests.class, - PluginRegistryTestsMinimal.class, ClasspathResolverTest.class, PDESchemaHelperTest.class, - DynamicPluginProjectReferencesTest.class, - // ClasspathContributorTest.class - ClasspathResolutionTest.class, - BundleErrorReporterTest.class, - AllPDECoreTests.class -}) -public class AllPDEMinimalTests { - -} diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/AllPDETests.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/AllPDETests.java index e4f7f8e59f..1efac64e24 100644 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/AllPDETests.java +++ b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/AllPDETests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005,2021 IBM Corporation and others. + * Copyright (c) 2005, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -15,6 +15,8 @@ import org.eclipse.pde.core.tests.internal.AllPDECoreTests; import org.eclipse.pde.core.tests.internal.classpath.ClasspathResolutionTest; +import org.eclipse.pde.core.tests.internal.core.builders.BundleErrorReporterTest; +import org.eclipse.pde.core.tests.internal.util.PDESchemaHelperTest; import org.eclipse.pde.ui.tests.build.properties.AllValidatorTests; import org.eclipse.pde.ui.tests.classpathcontributor.ClasspathContributorTest; import org.eclipse.pde.ui.tests.classpathresolver.ClasspathResolverTest; @@ -38,27 +40,29 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses({ - AllTargetTests.class, - AllNewProjectTests.class, - AllPreferenceTests.class, - AllImportTests.class, - AllBundleModelTests.class, - AllXMLModelTests.class, - AllValidatorTests.class, - AllNLSTests.class, - AllPDERuntimeTests.class, - ExportBundleTests.class, - AllLauncherTests.class, - AllLogViewTests.class, - ProjectCreationTests.class, - BundleRootTests.class, - PluginRegistryTests.class, - ClasspathResolverTest.class, - ClasspathContributorTest.class, - DynamicPluginProjectReferencesTest.class, - ClasspathResolutionTest.class, - AllPDECoreTests.class +@SuiteClasses({ // + AllTargetTests.class, // + AllNewProjectTests.class, // + AllPreferenceTests.class, // + AllImportTests.class, // + AllBundleModelTests.class, // + AllXMLModelTests.class, // + AllValidatorTests.class, // + AllNLSTests.class, // + AllPDERuntimeTests.class, // + ExportBundleTests.class, // + AllLauncherTests.class, // + AllLogViewTests.class, // + ProjectCreationTests.class, // + BundleRootTests.class, // + PluginRegistryTests.class, // + ClasspathResolverTest.class, // + PDESchemaHelperTest.class, // + ClasspathContributorTest.class, // + DynamicPluginProjectReferencesTest.class, // + ClasspathResolutionTest.class, // + BundleErrorReporterTest.class, // + AllPDECoreTests.class // }) public class AllPDETests { diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/PDETestCase.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/PDETestCase.java index 64e1015a91..b0319f44b5 100644 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/PDETestCase.java +++ b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/PDETestCase.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2015 IBM Corporation and others. + * Copyright (c) 2005, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,6 +14,12 @@ package org.eclipse.pde.ui.tests; import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; + +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspaceRoot; @@ -22,6 +28,7 @@ import org.eclipse.core.runtime.ICoreRunnable; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.MessageDialog; @@ -131,4 +138,15 @@ private static void closeIntro(final IWorkbench wb) { } } } + + public static void assumeRunningInStandaloneEclipseSDK() { + try { + Path location = Path.of(Platform.getInstallLocation().getURL().toURI()); + for (String directory : List.of("plugins", "features")) { + assumeTrue("Not running in a standalone Eclipse SDK", Files.isDirectory(location.resolve(directory))); + } + } catch (URISyntaxException e) { + throw new IllegalStateException(e); + } + } } diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/ee/ExportBundleTests.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/ee/ExportBundleTests.java index c1c68aa78d..fbbbef5d99 100644 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/ee/ExportBundleTests.java +++ b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/ee/ExportBundleTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2017 IBM Corporation and others. + * Copyright (c) 2008, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -41,6 +41,7 @@ import org.eclipse.pde.ui.tests.runtime.TestUtils; import org.eclipse.pde.ui.tests.util.ProjectUtils; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -48,6 +49,11 @@ */ public class ExportBundleTests extends PDETestCase { + @BeforeClass + public static void requireStandaloneEclipseSDKEnvironment() { + PDETestCase.assumeRunningInStandaloneEclipseSDK(); + } + private static final IPath EXPORT_PATH = PDETestsPlugin.getDefault().getStateLocation().append(".export"); @Override diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/AllImportTests.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/AllImportTests.java index a993febdda..e799cca22b 100644 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/AllImportTests.java +++ b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/AllImportTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2017 IBM Corporation and others. + * Copyright (c) 2005, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -17,9 +17,9 @@ import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; - @RunWith(Suite.class) -@SuiteClasses({ ImportWithLinksTestCase.class, ImportAsBinaryTestCase.class, ImportAsSourceTestCase.class, +@SuiteClasses({ // + BaseImportTestCase.class, // // Temporarily disabled until git migration is complete and we have access to a // stable cvs repo (bug 355873) diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/BaseImportTestCase.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/BaseImportTestCase.java index ac774834fe..6927a270dd 100644 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/BaseImportTestCase.java +++ b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/BaseImportTestCase.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2015 IBM Corporation and others. + * Copyright (c) 2006, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,74 +10,122 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Hannes Wellmann - Combine BaseImportTestCase subclasses into a parameterized test and make it succeed in verifiation builds *******************************************************************************/ package org.eclipse.pde.ui.tests.imports; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; + +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.pde.core.plugin.IPluginModelBase; import org.eclipse.pde.core.plugin.ModelEntry; import org.eclipse.pde.core.plugin.PluginRegistry; +import org.eclipse.pde.internal.core.BinaryRepositoryProvider; import org.eclipse.pde.internal.core.PDECore; +import org.eclipse.pde.internal.core.natures.PDE; import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation; import org.eclipse.pde.ui.tests.PDETestCase; +import org.eclipse.team.core.RepositoryProvider; +import org.junit.Assume; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; +import org.osgi.framework.FrameworkUtil; import org.osgi.framework.Version; -public abstract class BaseImportTestCase extends PDETestCase { +@RunWith(Parameterized.class) +public class BaseImportTestCase extends PDETestCase { + + @Parameters(name = "{0}") + public static Object[][] importTypes() { + return new Object[][] { // + { "Import binary", PluginImportOperation.IMPORT_BINARY }, // + { "Import with source", PluginImportOperation.IMPORT_WITH_SOURCE }, // + { "Import with links", PluginImportOperation.IMPORT_BINARY_WITH_LINKS }, // + }; + } - protected abstract int getType(); - protected abstract void verifyProject(String projectName, boolean isJava); + @Parameter(0) + public String importTypeName; + @Parameter(1) + public int importType; @Test - public void testImportJAR() { + public void testImportJAR() throws Exception { doSingleImport("org.eclipse.jsch.core", true); } @Test - public void testImportFlat() { + public void testImportFlat() throws Exception { doSingleImport("org.eclipse.jdt.debug", true); } @Test - public void testImportNotJavaFlat() { + public void testImportNotJavaFlat() throws Exception { doSingleImport("org.junit.source", false); } @Test - public void testImportNotJavaJARd() { + public void testImportNotJavaJARd() throws Exception { doSingleImport("org.eclipse.jdt.doc.user", false); doSingleImport("org.eclipse.pde.ui.source", false); } @Test - public void testImportJUnit4() { + public void testImportAnt() throws Exception { + Assume.assumeFalse(importType == PluginImportOperation.IMPORT_WITH_SOURCE); + // Note: Ant is exempt from importing as source + doSingleImport("org.apache.ant", true); + } + + @Test + public void testImportJUnit4() throws Exception { doSingleImport("org.junit", 4, true); } @Test - public void testImportLinksMultiple() { - IPluginModelBase[] modelsToImport = getModels(new String[] {"org.eclipse.core.filebuffers", "org.eclipse.jdt.doc.user", "org.eclipse.pde.build"}); - runOperation(modelsToImport, getType()); - for (int i = 0; i < modelsToImport.length; i++) { - verifyProject(modelsToImport[i], i != 1); + public void testImportLinksMultiple() throws Exception { + List modelsToImport = Stream + .of("org.eclipse.core.filebuffers", "org.eclipse.jdt.doc.user", "org.eclipse.pde.build").map(name -> { + IPluginModelBase model = PluginRegistry.findModel(name); + assertNotNull("No model found with name'" + name + "'", model); + assertNull("Workspace resource already exists for: " + name, model.getUnderlyingResource()); + return model; + }).toList(); + runOperation(modelsToImport, importType); + for (int i = 0; i < modelsToImport.size(); i++) { + verifyProject(modelsToImport.get(i), i != 1); } } - protected void doSingleImport(String bundleSymbolicName, boolean isJava) { + protected void doSingleImport(String bundleSymbolicName, boolean isJava) throws Exception { IPluginModelBase modelToImport = PluginRegistry.findModel(bundleSymbolicName); + assertNotNull("No model found with name'" + name + "'", modelToImport); assertNull(modelToImport.getUnderlyingResource()); - runOperation(new IPluginModelBase[] {modelToImport}, getType()); + runOperation(List.of(modelToImport), importType); verifyProject(modelToImport, isJava); } @@ -90,73 +138,78 @@ protected void doSingleImport(String bundleSymbolicName, boolean isJava) { * @param majorVersion the major version that the imported plug-in must have * @param isJava whether the imported plug-in should have a java nature */ - protected void doSingleImport(String bundleSymbolicName, int majorVersion, boolean isJava) { + protected void doSingleImport(String bundleSymbolicName, int majorVersion, boolean isJava) throws Exception { ModelEntry entry = PluginRegistry.findEntry(bundleSymbolicName); IPluginModelBase models[] = entry.getExternalModels(); - assertTrue("No models for " + bundleSymbolicName + " could be found", models.length > 0); - IPluginModelBase modelToImport = null; - - for (IPluginModelBase model : models) { - Version version = new Version(model.getPluginBase().getVersion()); - if (version.getMajor() == majorVersion){ - modelToImport = model; - break; - } - } - - assertNull("Model with correct major version " + majorVersion + " could not be found", modelToImport.getUnderlyingResource()); - runOperation(new IPluginModelBase[] {modelToImport}, getType()); + assertTrue("No external models for with name '" + bundleSymbolicName + "'", models.length > 0); + IPluginModelBase modelToImport = Arrays.stream(models) + .filter(m -> new Version(m.getPluginBase().getVersion()).getMajor() == majorVersion).findFirst() + .orElse(null); + + assertNull("Model for " + bundleSymbolicName + " with major version " + majorVersion + " not be found", + modelToImport.getUnderlyingResource()); + runOperation(List.of(modelToImport), importType); verifyProject(modelToImport, isJava); } - protected void runOperation(IPluginModelBase[] models, int type) { - PluginImportOperation job = new PluginImportOperation(models, type, false); + protected void runOperation(List models, int type) throws InterruptedException { + PluginImportOperation job = new PluginImportOperation(models.toArray(IPluginModelBase[]::new), type, false); job.setRule(ResourcesPlugin.getWorkspace().getRoot()); job.setSystem(true); job.schedule(); - try{ - job.join(); - } catch (InterruptedException e){ - fail("Job interupted: " + e.getMessage()); - } + job.join(); IStatus status = job.getResult(); - if (!status.isOK()){ - fail("Import Operation failed: " + status.toString()); - } + assertTrue("Import Operation failed: " + status.toString(), status.isOK()); } - protected IPluginModelBase[] getModels(String[] symbolicNames) { - IPluginModelBase[] models = new IPluginModelBase[symbolicNames.length]; - for (int i = 0; i < symbolicNames.length; i++) { - IPluginModelBase model = PluginRegistry.findModel(symbolicNames[i]); - assertNull(model.getUnderlyingResource()); - models[i] = model; - } - return models; - } - - protected void verifyProject(IPluginModelBase modelImported, boolean isJava) { + private void verifyProject(IPluginModelBase modelImported, boolean isJava) throws CoreException { String id = modelImported.getPluginBase().getId(); - verifyProject(id, isJava); - } - - protected IProject verifyProject(String projectName) { - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IProject project = root.getProject(projectName); - assertTrue("Project " + projectName + " does not exist", project.exists()); - return project; + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(id); + assertTrue("Project " + id + " does not exist", project.exists()); + + // When self hosting the tests, import tests may fail if you have the + // imported project in the host + boolean isFromSelfHostedTestRuntime = Platform.inDevelopmentMode() + && Path.of(modelImported.getInstallLocation()).getParent().getParent() + .equals(FileLocator.getBundleFileLocation(FrameworkUtil.getBundle(BaseImportTestCase.class)) + .get().toPath().getParent().getParent()); + + if (!isFromSelfHostedTestRuntime) { + if (importType == PluginImportOperation.IMPORT_BINARY_WITH_LINKS) { + assertThat(RepositoryProvider.getProvider(project), is(instanceOf(BinaryRepositoryProvider.class))); + } else if (importType == PluginImportOperation.IMPORT_BINARY) { + assertEquals(PDECore.BINARY_PROJECT_VALUE, + project.getPersistentProperty(PDECore.EXTERNAL_PROJECT_PROPERTY)); + } + } + assertTrue(project.hasNature(PDE.PLUGIN_NATURE)); + assertEquals(isJava, project.hasNature(JavaCore.NATURE_ID)); + if (isJava) { + IJavaProject jProject = JavaCore.create(project); + assertSourceAttached(jProject); + if (importType == PluginImportOperation.IMPORT_WITH_SOURCE) { + assertAnyClasspathEntryOfKind(jProject, IClasspathEntry.CPE_SOURCE); + } else { + if (!isFromSelfHostedTestRuntime) { + assertAnyClasspathEntryOfKind(jProject, IClasspathEntry.CPE_LIBRARY); + } + } + } } - protected boolean checkSourceAttached(IJavaProject jProject) throws CoreException { - IPackageFragmentRoot[] roots = jProject.getPackageFragmentRoots(); - for (IPackageFragmentRoot root : roots) { + private void assertSourceAttached(IJavaProject jProject) throws CoreException { + for (IPackageFragmentRoot root : jProject.getPackageFragmentRoots()) { IClasspathEntry entry = root.getRawClasspathEntry(); - if (entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY || entry.getEntryKind() != IClasspathEntry.CPE_CONTAINER || !entry.getPath().equals(PDECore.REQUIRED_PLUGINS_CONTAINER_PATH)) - continue; - if (root.getSourceAttachmentPath() == null) - return false; + if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY + || (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) + && !entry.getPath().equals(PDECore.REQUIRED_PLUGINS_CONTAINER_PATH)) { + assertNotNull("Missing source attachement for entry " + entry, root.getSourceAttachmentPath()); + } } - return true; + } + + private static void assertAnyClasspathEntryOfKind(IJavaProject project, int entryKind) throws JavaModelException { + assertTrue(Arrays.stream(project.getRawClasspath()).anyMatch(e -> e.getEntryKind() == entryKind)); } } diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/ImportAsBinaryTestCase.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/ImportAsBinaryTestCase.java deleted file mode 100644 index 1042931215..0000000000 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/ImportAsBinaryTestCase.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2017 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.pde.ui.tests.imports; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.pde.internal.core.PDECore; -import org.eclipse.pde.internal.core.natures.PDE; -import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation; -import org.junit.Test; - -public class ImportAsBinaryTestCase extends BaseImportTestCase { - - private static int TYPE = PluginImportOperation.IMPORT_BINARY; - - @Override - protected int getType() { - return TYPE; - } - - @Test - public void testImportAnt() { - // Note: Ant is exempt from importing as source - doSingleImport("org.apache.ant", true); - } - - @Override - @Test - public void testImportJUnit4() { - // Note: JUnit 4 does not have source but it is a java project - doSingleImport("org.junit", 4, true); - } - - @Override - protected void verifyProject(String projectName, boolean isJava) { - try { - IProject project = verifyProject(projectName); - // When self hosting the tests, import tests may fail if you have the imported project in the host - if (!Platform.inDevelopmentMode()) { - assertEquals(PDECore.BINARY_PROJECT_VALUE, project.getPersistentProperty(PDECore.EXTERNAL_PROJECT_PROPERTY)); - } - assertTrue(project.hasNature(PDE.PLUGIN_NATURE)); - assertEquals(isJava, project.hasNature(JavaCore.NATURE_ID)); - if (isJava) { - IJavaProject jProject = JavaCore.create(project); - assertTrue(checkSourceAttached(jProject)); - assertTrue(checkLibraryEntry(jProject)); - } - } catch (CoreException e) { - fail(e.getMessage()); - } - } - - private boolean checkLibraryEntry(IJavaProject jProject) throws JavaModelException { - // When self hosting the tests, import tests may fail if you have the imported project in the host - if (Platform.inDevelopmentMode()) { - return true; - } - - IClasspathEntry[] entries = jProject.getRawClasspath(); - for (IClasspathEntry entry : entries) { - if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) - return true; - } - return false; - } - -} diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/ImportAsSourceTestCase.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/ImportAsSourceTestCase.java deleted file mode 100644 index 5bb7ee2a21..0000000000 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/ImportAsSourceTestCase.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2017 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.pde.ui.tests.imports; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.pde.internal.core.natures.PDE; -import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation; - -public class ImportAsSourceTestCase extends BaseImportTestCase { - - private static int TYPE = PluginImportOperation.IMPORT_WITH_SOURCE; - - @Override - protected int getType() { - return TYPE; - } - - @Override - protected void verifyProject(String projectName, boolean isJava) { - try { - IProject project = verifyProject(projectName); - assertTrue(project.hasNature(PDE.PLUGIN_NATURE)); - assertEquals(isJava, project.hasNature(JavaCore.NATURE_ID)); - if (isJava) { - IJavaProject jProject = JavaCore.create(project); - assertTrue(checkSourceAttached(jProject)); - assertTrue(checkSourceFolder(jProject)); - } - } catch (CoreException e) { - fail(e.getMessage()); - } - } - - private boolean checkSourceFolder(IJavaProject jProject) throws JavaModelException { - IClasspathEntry[] entries = jProject.getRawClasspath(); - for (IClasspathEntry entry : entries) { - if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) - return true; - } - return false; - } -} diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/ImportWithLinksTestCase.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/ImportWithLinksTestCase.java deleted file mode 100644 index 1b2050a768..0000000000 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/imports/ImportWithLinksTestCase.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2017 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.pde.ui.tests.imports; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.pde.internal.core.BinaryRepositoryProvider; -import org.eclipse.pde.internal.core.natures.PDE; -import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation; -import org.eclipse.team.core.RepositoryProvider; - -public class ImportWithLinksTestCase extends BaseImportTestCase { - - private static int TYPE = PluginImportOperation.IMPORT_BINARY_WITH_LINKS; - - @Override - protected int getType() { - return TYPE; - } - - public void testImportAnt() { - // Note: Ant is exempt from importing as source - doSingleImport("org.apache.ant", true); - } - - @Override - protected void verifyProject(String projectName, boolean isJava) { - try { - IProject project = verifyProject(projectName); - RepositoryProvider provider = RepositoryProvider.getProvider(project); - // When self hosting the tests, import tests may fail if you have the imported project in the host - if (!Platform.inDevelopmentMode()) { - assertTrue(provider instanceof BinaryRepositoryProvider); - } - assertTrue(project.hasNature(PDE.PLUGIN_NATURE)); - assertEquals(isJava, project.hasNature(JavaCore.NATURE_ID)); - if (isJava) { - IJavaProject jProject = JavaCore.create(project); - assertTrue(checkSourceAttached(jProject)); - assertTrue(checkLibraryEntry(jProject)); - } - } catch (CoreException e) { - fail(e.getMessage()); - } - } - - private boolean checkLibraryEntry(IJavaProject jProject) throws JavaModelException { - // When self hosting the tests, import tests may fail if you have the imported project in the host - if (Platform.inDevelopmentMode()) { - return true; - } - - IClasspathEntry[] entries = jProject.getRawClasspath(); - for (IClasspathEntry entry : entries) { - if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) - return true; - } - return false; - } - -} diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/project/PluginRegistryTests.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/project/PluginRegistryTests.java index e7575d05dd..32d32468b2 100644 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/project/PluginRegistryTests.java +++ b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/project/PluginRegistryTests.java @@ -15,10 +15,20 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.osgi.service.resolver.VersionRange; import org.eclipse.pde.core.plugin.IMatchRules; +import org.eclipse.pde.core.plugin.IPluginBase; import org.eclipse.pde.core.plugin.IPluginModelBase; import org.eclipse.pde.core.plugin.PluginRegistry; +import org.eclipse.pde.core.plugin.PluginRegistry.PluginFilter; +import org.eclipse.pde.core.project.IBundleProjectDescription; import org.junit.Test; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.Version; @@ -28,11 +38,160 @@ * * @since 3.6 */ -public class PluginRegistryTests extends PluginRegistryTestsMinimal { +public class PluginRegistryTests { + + @Test + public void testMatchNone() { + IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", null, IMatchRules.NONE, null); + assertNotNull(model); + assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId()); + } + + @Test + public void testMatchGreaterOrEqual() { + IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", "3.0.0", + IMatchRules.GREATER_OR_EQUAL, null); + assertNotNull(model); + assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId()); + } + + @Test + public void testMatchPerfect() { + IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", "3.0.0", IMatchRules.PERFECT, null); + assertNull(model); + } + + @Test + public void testMatchCompatible() { + IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", "3.6.0", IMatchRules.COMPATIBLE, + null); + assertNotNull(model); + assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId()); + } + + @Test + public void testMatchCompatibleNone() { + IPluginModelBase model = PluginRegistry.findModel("org.eclipse.pde.core", "2.6.0", IMatchRules.COMPATIBLE, + null); + assertNull(model); + } + + @Test + public void testMatchPrefix() { + IPluginModelBase model = PluginRegistry.findModel("org.eclipse", "3.6.0", IMatchRules.PREFIX, null); + // prefix rule is not supported by this API, should return null + assertNull(model); + } + + @Test + public void testRangeNone() { + IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", null, null); + assertNotNull(model); + assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId()); + } + + @Test + public void testOverlapRange() { + IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", new VersionRange("[2.0.0,4.0.0)"), + null); + assertNotNull(model); + assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId()); + } + + @Test + public void testMinRange() { + IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", new VersionRange("3.0.0"), null); + assertNotNull(model); + assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId()); + } + + @Test + public void testUnmatchedRange() { + IPluginModelBase model = PluginRegistry.findModel("org.eclipse.pde.core", new VersionRange("[1.0.0,2.0.0)"), + null); + assertNull(model); + } + + @Test + public void testRangeWithFilterMatch() { + PluginFilter filter = new PluginFilter() { + @Override + public boolean accept(IPluginModelBase model) { + IPluginBase base = model.getPluginBase(); + if (base != null) { + String id = base.getId(); + if (id != null) { + return id.startsWith("org.eclipse"); + } + } + return false; + } + }; + IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", new VersionRange("[2.0.0,4.0.0)"), + filter); + assertNotNull(model); + assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId()); + } + + @Test + public void testRangeWithFilterNoMatch() { + PluginFilter filter = new PluginFilter() { + @Override + public boolean accept(IPluginModelBase model) { + IPluginBase base = model.getPluginBase(); + if (base != null) { + String id = base.getId(); + if (id != null) { + return id.startsWith("xyz"); + } + } + return false; + } + }; + IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", new VersionRange("[2.0.0,4.0.0)"), + filter); + assertNull(model); + } + + @Test + public void testSingleRangeMatch() { + IPluginModelBase[] models = PluginRegistry.findModels("org.eclipse.jdt.debug", + new VersionRange("[1.0.0,4.0.0)"), null); + assertNotNull(models); + assertEquals(1, models.length); + assertEquals("org.eclipse.jdt.debug", models[0].getPluginBase().getId()); + } + + @Test + public void testWorkspaceOverTarget() throws CoreException { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("org.junit"); + try { + IBundleProjectDescription description = ProjectCreationTests.getBundleProjectService() + .getDescription(project); + description.setSymbolicName("org.junit"); + description.setBundleVersion(new Version("4.3.2")); + description.setBundleVendor("bogus"); + description.apply(null); + + waitForBuild(); + + IPluginModelBase[] models = PluginRegistry.findModels("org.junit", new VersionRange("[3.8.2,4.8.2]"), null); + assertNotNull(models); + assertEquals(1, models.length); + assertEquals("org.junit", models[0].getPluginBase().getId()); + assertEquals(project, models[0].getUnderlyingResource().getProject()); + + } finally { + if (project.exists()) { + project.delete(true, null); + waitForBuild(); + } + } + } @Test public void testMatchEquivalent() { - Version testsVersion = FrameworkUtil.getBundle(getClass()).getVersion(); + Version testsVersion = FrameworkUtil.getBundle(PluginRegistryTests.class).getVersion(); IPluginModelBase model = PluginRegistry.findModel("org.eclipse.pde.ui.tests", String.format("%s.%s.%s", testsVersion.getMajor(), testsVersion.getMinor(), testsVersion.getMicro()), IMatchRules.EQUIVALENT, @@ -40,4 +199,22 @@ public void testMatchEquivalent() { assertNotNull("NOTE: This test might also fail because the version of the bundle got changed.", model); assertEquals("org.eclipse.pde.ui.tests", model.getPluginBase().getId()); } + + /** + * Wait for builds to complete + */ + public static void waitForBuild() { + boolean wasInterrupted = false; + do { + try { + Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null); + Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_BUILD, null); + wasInterrupted = false; + } catch (OperationCanceledException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + wasInterrupted = true; + } + } while (wasInterrupted); + } } diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/project/PluginRegistryTestsMinimal.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/project/PluginRegistryTestsMinimal.java deleted file mode 100644 index c03f21cc3c..0000000000 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/project/PluginRegistryTestsMinimal.java +++ /dev/null @@ -1,204 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2017 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.pde.ui.tests.project; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.osgi.service.resolver.VersionRange; -import org.eclipse.pde.core.plugin.IMatchRules; -import org.eclipse.pde.core.plugin.IPluginBase; -import org.eclipse.pde.core.plugin.IPluginModelBase; -import org.eclipse.pde.core.plugin.PluginRegistry; -import org.eclipse.pde.core.plugin.PluginRegistry.PluginFilter; -import org.eclipse.pde.core.project.IBundleProjectDescription; -import org.junit.Test; -import org.osgi.framework.Version; - -/** - * Tests for plug-in searching /** Tests whether targets and bundle containers - * manage features correctly. Runs on minimal bundles and not the whole eclipse - * SDK. This class is refactored out of PluginRegistryTests - * - * @since 3.6 - */ - -public class PluginRegistryTestsMinimal { - - @Test - public void testMatchNone() { - IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", null, IMatchRules.NONE, null); - assertNotNull(model); - assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId()); - } - - @Test - public void testMatchGreaterOrEqual() { - IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", "3.0.0", IMatchRules.GREATER_OR_EQUAL, null); - assertNotNull(model); - assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId()); - } - - @Test - public void testMatchPerfect() { - IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", "3.0.0", IMatchRules.PERFECT, null); - assertNull(model); - } - - @Test - public void testMatchCompatible() { - IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", "3.6.0", IMatchRules.COMPATIBLE, - null); - assertNotNull(model); - assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId()); - } - - @Test - public void testMatchCompatibleNone() { - IPluginModelBase model = PluginRegistry.findModel("org.eclipse.pde.core", "2.6.0", IMatchRules.COMPATIBLE, null); - assertNull(model); - } - - @Test - public void testMatchPrefix() { - IPluginModelBase model = PluginRegistry.findModel("org.eclipse", "3.6.0", IMatchRules.PREFIX, null); - // prefix rule is not supported by this API, should return null - assertNull(model); - } - - @Test - public void testRangeNone() { - IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", null, null); - assertNotNull(model); - assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId()); - } - - @Test - public void testOverlapRange() { - IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", new VersionRange("[2.0.0,4.0.0)"), null); - assertNotNull(model); - assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId()); - } - - @Test - public void testMinRange() { - IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", new VersionRange("3.0.0"), null); - assertNotNull(model); - assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId()); - } - - @Test - public void testUnmatchedRange() { - IPluginModelBase model = PluginRegistry.findModel("org.eclipse.pde.core", new VersionRange("[1.0.0,2.0.0)"), null); - assertNull(model); - } - - @Test - public void testRangeWithFilterMatch() { - PluginFilter filter = new PluginFilter() { - @Override - public boolean accept(IPluginModelBase model) { - IPluginBase base = model.getPluginBase(); - if (base != null) { - String id = base.getId(); - if (id != null) { - return id.startsWith("org.eclipse"); - } - } - return false; - } - }; - IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", new VersionRange("[2.0.0,4.0.0)"), filter); - assertNotNull(model); - assertEquals("org.eclipse.jdt.debug", model.getPluginBase().getId()); - } - - @Test - public void testRangeWithFilterNoMatch() { - PluginFilter filter = new PluginFilter() { - @Override - public boolean accept(IPluginModelBase model) { - IPluginBase base = model.getPluginBase(); - if (base != null) { - String id = base.getId(); - if (id != null) { - return id.startsWith("xyz"); - } - } - return false; - } - }; - IPluginModelBase model = PluginRegistry.findModel("org.eclipse.jdt.debug", new VersionRange("[2.0.0,4.0.0)"), filter); - assertNull(model); - } - - @Test - public void testSingleRangeMatch() { - IPluginModelBase[] models = PluginRegistry.findModels("org.eclipse.jdt.debug", - new VersionRange("[1.0.0,4.0.0)"), null); - assertNotNull(models); - assertEquals(1, models.length); - assertEquals("org.eclipse.jdt.debug", models[0].getPluginBase().getId()); - } - - @Test - public void testWorkspaceOverTarget() throws CoreException { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("org.junit"); - try { - IBundleProjectDescription description = ProjectCreationTests.getBundleProjectService().getDescription(project); - description.setSymbolicName("org.junit"); - description.setBundleVersion(new Version("4.3.2")); - description.setBundleVendor("bogus"); - description.apply(null); - - waitForBuild(); - - IPluginModelBase[] models = PluginRegistry.findModels("org.junit", new VersionRange("[3.8.2,4.8.2]"), null); - assertNotNull(models); - assertEquals(1, models.length); - assertEquals("org.junit", models[0].getPluginBase().getId()); - assertEquals(project, models[0].getUnderlyingResource().getProject()); - - } finally { - if (project.exists()) { - project.delete(true, null); - waitForBuild(); - } - } - } - - /** - * Wait for builds to complete - */ - public static void waitForBuild() { - boolean wasInterrupted = false; - do { - try { - Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null); - Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_BUILD, null); - wasInterrupted = false; - } catch (OperationCanceledException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - wasInterrupted = true; - } - } while (wasInterrupted); - } -} diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/AllTargetMinimalTests.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/AllTargetMinimalTests.java deleted file mode 100644 index a6c94b2a57..0000000000 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/AllTargetMinimalTests.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2017 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.pde.ui.tests.target; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * They run on minimal plugin bundles and dont require the whole SDK ( for - * hudson gerrit). This class is refactored out of AllTargetTests - * - */ -@RunWith(Suite.class) -@SuiteClasses({ - TargetEnvironmentTestCase.class, // - TargetPlatformHelperTests.class, // - // LocalTargetDefinitionTests.class, - // WorkspaceTargetDefinitionTests.class - MinimalTargetDefinitionPersistenceTests.class, // - MinimalTargetDefinitionResolutionTests.class, // - MinimalTargetDefinitionFeatureResolutionTests.class, // - IUBundleContainerTests.class, // - ProfileContainerTests.class -}) -public class AllTargetMinimalTests { -} diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/LocalTargetDefinitionTests.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/LocalTargetDefinitionTests.java index e9e8966492..d5d6adf99c 100644 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/LocalTargetDefinitionTests.java +++ b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/LocalTargetDefinitionTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2018 IBM Corporation and others. + * Copyright (c) 2008, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -55,7 +55,9 @@ import org.eclipse.pde.internal.core.target.TargetDefinitionPersistenceHelper; import org.eclipse.pde.internal.core.target.TargetPlatformService; import org.eclipse.pde.internal.launching.launcher.LaunchArgumentsHelper; +import org.eclipse.pde.ui.tests.PDETestCase; import org.eclipse.pde.ui.tests.PDETestsPlugin; +import org.junit.BeforeClass; import org.junit.Test; import org.osgi.framework.ServiceReference; @@ -69,6 +71,11 @@ */ public class LocalTargetDefinitionTests extends AbstractTargetTest { + @BeforeClass + public static void requireStandaloneEclipseSDKEnvironment() { + PDETestCase.assumeRunningInStandaloneEclipseSDK(); + } + public static final NameVersionDescriptor MULTI_VERSION_LOW_DESCRIPTION = new NameVersionDescriptor( "a.typical.bundle", "1.0.0.200907071058"); public static final NameVersionDescriptor MULTI_VERSION_HIGH_DESCRIPTION = new NameVersionDescriptor( diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/MinimalTargetDefinitionFeatureResolutionTests.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/MinimalTargetDefinitionFeatureResolutionTests.java deleted file mode 100644 index 2e2750ab14..0000000000 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/MinimalTargetDefinitionFeatureResolutionTests.java +++ /dev/null @@ -1,378 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2018 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.pde.ui.tests.target; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.pde.core.plugin.TargetPlatform; -import org.eclipse.pde.core.target.ITargetDefinition; -import org.eclipse.pde.core.target.ITargetLocation; -import org.eclipse.pde.core.target.NameVersionDescriptor; -import org.eclipse.pde.core.target.TargetBundle; -import org.eclipse.pde.core.target.TargetFeature; -import org.eclipse.pde.internal.core.PDECore; -import org.eclipse.pde.internal.core.ifeature.IFeatureModel; -import org.junit.Test; - -/** - * Tests whether targets and bundle containers manage features correctly. Runs - * on minimal bundles and not the whole eclipse SDK. This class is refactored - * out of TargetDefinitionFeatureResolutionTests - */ -public class MinimalTargetDefinitionFeatureResolutionTests extends AbstractTargetTest { - - /** - * Tests that a directory bundle container provides the correct features to - * a target - */ - @Test - public void testDirectoryBundleContainer() throws Exception { - ITargetDefinition definition = getNewTarget(); - ITargetLocation directoryContainer = getTargetService() - .newDirectoryLocation(TargetPlatform.getDefaultLocation()); - - assertNull(directoryContainer.getFeatures()); - - IFeatureModel[] expectedFeatures = PDECore.getDefault().getFeatureModelManager().getModels(); - Set expectedIDs = new HashSet<>(); - for (IFeatureModel expectedFeature : expectedFeatures) { - expectedIDs.add(expectedFeature.getFeature().getId()); - } - - directoryContainer.resolve(definition, null); - TargetFeature[] features = directoryContainer.getFeatures(); - assertNotNull(features); - - for (TargetFeature feature : features) { - String currentID = feature.getId(); - assertTrue("Extra feature in result: " + currentID, expectedIDs.contains(currentID)); - expectedIDs.remove(currentID); - } - - assertTrue("Not all expected features returned by the container: " + expectedIDs.toString(), - expectedIDs.isEmpty()); - } - - /** - * Tests that a profile (installation) bundle container provides the correct - * features to a target - */ - @Test - public void testProfileBundleContainer() throws Exception { - ITargetDefinition definition = getNewTarget(); - ITargetLocation profileContainer = getTargetService().newProfileLocation(TargetPlatform.getDefaultLocation(), - null); - - assertNull(profileContainer.getFeatures()); - - IFeatureModel[] expectedFeatures = PDECore.getDefault().getFeatureModelManager().getModels(); - Set expectedIDs = new HashSet<>(); - for (IFeatureModel expectedFeature : expectedFeatures) { - expectedIDs.add(expectedFeature.getFeature().getId()); - } - - profileContainer.resolve(definition, null); - TargetFeature[] features = profileContainer.getFeatures(); - assertNotNull(features); - - for (TargetFeature feature : features) { - String currentID = feature.getId(); - assertTrue("Extra feature in result: " + currentID, expectedIDs.contains(currentID)); - expectedIDs.remove(currentID); - } - - assertTrue("Not all expected features returned by the container: " + expectedIDs.toString(), - expectedIDs.isEmpty()); - } - - @Test - public void testExplicitIncludes() throws Exception { - // Use the modified JDT features as we know their versions - ITargetDefinition definition = getNewTarget(); - IPath location = extractModifiedFeatures(); - - ITargetLocation container = getTargetService().newDirectoryLocation(location.toOSString()); - definition.setTargetLocations(new ITargetLocation[] { container }); - definition.resolve(null); - - List expected = new ArrayList<>(); - expected.add("org.eclipse.jdt"); - expected.add("org.eclipse.jdt.launching"); - expected.add("org.eclipse.jdt.launching.source"); - // 2 versions of JUnit - expected.add("org.junit"); - expected.add("org.junit.source"); - expected.add("org.junit"); - expected.add("org.junit.source"); - expected.add("org.junit4"); - if (Platform.getOS().equals(Platform.OS_MACOSX)) { - expected.add("org.eclipse.jdt.launching.macosx"); - expected.add("org.eclipse.jdt.launching.macosx.source"); - } - - NameVersionDescriptor[] allFeatures = new NameVersionDescriptor[] { - new NameVersionDescriptor("org.eclipse.jdt", "3.6.0.v20100105-0800-7z8VFR9FMTb52_pOyKHhoek1", - NameVersionDescriptor.TYPE_FEATURE), - new NameVersionDescriptor("org.eclipse.jdt.source", "3.6.0.v20100105-0800-7z8VFR9FMTb52_pOyKHhoek1", - NameVersionDescriptor.TYPE_FEATURE) }; - definition.setIncluded(allFeatures); - TargetBundle[] bundles = definition.getBundles(); - - for (TargetBundle bundle : bundles) { - String symbolicName = bundle.getBundleInfo().getSymbolicName(); - expected.remove(symbolicName); - if (symbolicName.equals("org.eclipse.jdt.launching.macosx")) { - // the bundle should be missing unless on Mac - IStatus status = bundle.getStatus(); - if (Platform.getOS().equals(Platform.OS_MACOSX)) { - assertTrue("Mac bundle should be present", status.isOK()); - } else { - assertFalse("Mac bundle should be missing", status.isOK()); - assertEquals("Mac bundle should be mssing", TargetBundle.STATUS_PLUGIN_DOES_NOT_EXIST, - status.getCode()); - } - } - } - for (String name : expected) { - System.err.println("Missing: " + name); - } - assertTrue("Wrong bundles in JDT feature", expected.isEmpty()); - - } - - @Test - public void testSingleInclude() throws Exception { - // Use the modified JDT features as we know their versions - ITargetDefinition definition = getNewTarget(); - IPath location = extractModifiedFeatures(); - - ITargetLocation container = getTargetService().newDirectoryLocation(location.toOSString()); - definition.setTargetLocations(new ITargetLocation[] { container }); - definition.resolve(null); - - List expected = new ArrayList<>(); - expected.add("org.eclipse.jdt"); - expected.add("org.eclipse.jdt.launching"); - // 2 versions of JUnit - expected.add("org.junit"); - expected.add("org.junit"); - expected.add("org.junit4"); - if (Platform.getOS().equals(Platform.OS_MACOSX)) { - expected.add("org.eclipse.jdt.launching.macosx"); - } - - NameVersionDescriptor[] allFeatures = new NameVersionDescriptor[] { - new NameVersionDescriptor("org.eclipse.jdt", null, NameVersionDescriptor.TYPE_FEATURE) }; - definition.setIncluded(allFeatures); - TargetBundle[] bundles = definition.getBundles(); - - for (TargetBundle bundle : bundles) { - String symbolicName = bundle.getBundleInfo().getSymbolicName(); - expected.remove(symbolicName); - if (symbolicName.equals("org.eclipse.jdt.launching.macosx")) { - // the bundle should be missing unless on Mac - IStatus status = bundle.getStatus(); - if (Platform.getOS().equals(Platform.OS_MACOSX)) { - assertTrue("Mac bundle should be present", status.isOK()); - } else { - assertFalse("Mac bundle should be missing", status.isOK()); - assertEquals("Mac bundle should be missing", TargetBundle.STATUS_PLUGIN_DOES_NOT_EXIST, - status.getCode()); - } - } - } - for (String name : expected) { - System.err.println("Missing: " + name); - } - assertTrue("Wrong bundles in JDT feature", expected.isEmpty()); - } - - @Test - public void testMixedIncludes() throws Exception { - // Use the modified JDT features as we know their versions - ITargetDefinition definition = getNewTarget(); - IPath location = extractModifiedFeatures(); - - ITargetLocation container = getTargetService().newDirectoryLocation(location.toOSString()); - definition.setTargetLocations(new ITargetLocation[] { container }); - definition.resolve(null); - - List expected = new ArrayList<>(); - expected.add("org.eclipse.jdt"); - expected.add("org.eclipse.jdt.launching"); - // 2 versions of JUnit - expected.add("org.junit"); - expected.add("org.junit"); - expected.add("org.junit4"); - if (Platform.getOS().equals(Platform.OS_MACOSX)) { - expected.add("org.eclipse.jdt.launching.macosx"); - } - - NameVersionDescriptor[] allFeatures = new NameVersionDescriptor[] { - new NameVersionDescriptor("org.eclipse.jdt", null, NameVersionDescriptor.TYPE_FEATURE), - new NameVersionDescriptor("org.eclipse.jdt", null, NameVersionDescriptor.TYPE_PLUGIN) }; - definition.setIncluded(allFeatures); - TargetBundle[] bundles = definition.getBundles(); - - for (TargetBundle bundle : bundles) { - String symbolicName = bundle.getBundleInfo().getSymbolicName(); - expected.remove(symbolicName); - if (symbolicName.equals("org.eclipse.jdt.launching.macosx")) { - // the bundle should be missing unless on Mac - IStatus status = bundle.getStatus(); - if (Platform.getOS().equals(Platform.OS_MACOSX)) { - assertTrue("Mac bundle should be present", status.isOK()); - } else { - assertFalse("Mac bundle should be missing", status.isOK()); - assertEquals("Mac bundle should be mssing", TargetBundle.STATUS_PLUGIN_DOES_NOT_EXIST, - status.getCode()); - } - } - } - for (String name : expected) { - System.err.println("Missing: " + name); - } - assertTrue("Wrong bundles in JDT feature", expected.isEmpty()); - } - - @Test - public void testMissingFeatures() throws Exception { - // Use the modified JDT features as we know their versions - ITargetDefinition definition = getNewTarget(); - IPath location = extractModifiedFeatures(); - - ITargetLocation container = getTargetService().newDirectoryLocation(location.toOSString()); - definition.setTargetLocations(new ITargetLocation[] { container }); - definition.resolve(null); - - NameVersionDescriptor[] allFeatures = new NameVersionDescriptor[] { - new NameVersionDescriptor("DOES_NOT_EXIST", null, NameVersionDescriptor.TYPE_FEATURE), }; - definition.setIncluded(allFeatures); - TargetBundle[] bundles = definition.getBundles(); - - assertNotNull("Target didn't resolve", bundles); - assertEquals("Wrong number of included bundles", 1, bundles.length); - - IStatus definitionStatus = definition.getStatus(); - assertEquals("Wrong severity", IStatus.ERROR, definitionStatus.getSeverity()); - - IStatus[] children = definitionStatus.getChildren(); - assertEquals("Wrong number of statuses", 1, children.length); - assertEquals("Wrong severity", IStatus.ERROR, children[0].getSeverity()); - assertEquals(TargetBundle.STATUS_FEATURE_DOES_NOT_EXIST, children[0].getCode()); - - // Check that removing the included bundles and resolving removes the - // errors. - definition.setIncluded(null); - assertTrue(definition.isResolved()); - assertTrue(definition.getStatus().isOK()); - assertTrue(definition.getBundles().length > 4); - } - - @Test - public void testMissingFeatureVersion() throws Exception { - // Use the modified JDT features as we know their versions - ITargetDefinition definition = getNewTarget(); - IPath location = extractModifiedFeatures(); - - ITargetLocation container = getTargetService().newDirectoryLocation(location.toOSString()); - definition.setTargetLocations(new ITargetLocation[] { container }); - definition.resolve(null); - - List expected = new ArrayList<>(); - expected.add("org.eclipse.jdt"); - expected.add("org.eclipse.jdt.launching"); - // 2 versions of JUnit - expected.add("org.junit"); - expected.add("org.junit"); - expected.add("org.junit4"); - if (Platform.getOS().equals(Platform.OS_MACOSX)) { - expected.add("org.eclipse.jdt.launching.macosx"); - } - - NameVersionDescriptor[] allFeatures = new NameVersionDescriptor[] { - new NameVersionDescriptor("org.eclipse.jdt", "DOES_NOT_EXIST", NameVersionDescriptor.TYPE_FEATURE) }; - definition.setIncluded(allFeatures); - TargetBundle[] bundles = definition.getBundles(); - - for (TargetBundle bundle : bundles) { - String symbolicName = bundle.getBundleInfo().getSymbolicName(); - expected.remove(symbolicName); - if (symbolicName.equals("org.eclipse.jdt.launching.macosx")) { - // the bundle should be missing unless on Mac - IStatus status = bundle.getStatus(); - if (Platform.getOS().equals(Platform.OS_MACOSX)) { - assertTrue("Mac bundle should be present", status.isOK()); - } else { - assertFalse("Mac bundle should be missing", status.isOK()); - assertEquals("Mac bundle should be mssing", TargetBundle.STATUS_PLUGIN_DOES_NOT_EXIST, - status.getCode()); - } - } - } - for (String name : expected) { - System.err.println("Missing: " + name); - } - assertTrue("Wrong bundles in JDT feature", expected.isEmpty()); - } - - @Test - public void testMissingMixed() throws Exception { - // Use the modified JDT features as we know their versions - ITargetDefinition definition = getNewTarget(); - IPath location = extractModifiedFeatures(); - - ITargetLocation container = getTargetService().newDirectoryLocation(location.toOSString()); - definition.setTargetLocations(new ITargetLocation[] { container }); - definition.resolve(null); - - NameVersionDescriptor[] allFeatures = new NameVersionDescriptor[] { - new NameVersionDescriptor("DOES_NOT_EXIST", null, NameVersionDescriptor.TYPE_FEATURE), - new NameVersionDescriptor("DOES_NOT_EXIST", null, NameVersionDescriptor.TYPE_PLUGIN), - new NameVersionDescriptor("org.eclipse.jdt", "DOES_NOT_EXIST", NameVersionDescriptor.TYPE_PLUGIN), }; - definition.setIncluded(allFeatures); - TargetBundle[] bundles = definition.getBundles(); - - assertNotNull("Target didn't resolve", bundles); - assertEquals("Wrong number of included bundles", 1, bundles.length); - - IStatus definitionStatus = definition.getStatus(); - assertEquals("Wrong severity", IStatus.ERROR, definitionStatus.getSeverity()); - - IStatus[] children = definitionStatus.getChildren(); - assertEquals("Wrong number of statuses", 1, children.length); - assertEquals("Wrong severity", IStatus.ERROR, children[0].getSeverity()); - assertEquals(TargetBundle.STATUS_FEATURE_DOES_NOT_EXIST, children[0].getCode()); - - // Check that removing the included bundles and resolving removes the - // errors. - definition.setIncluded(null); - assertTrue(definition.isResolved()); - assertTrue(definition.getStatus().isOK()); - assertTrue(definition.getBundles().length > 4); - } - -} \ No newline at end of file diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/MinimalTargetDefinitionPersistenceTests.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/MinimalTargetDefinitionPersistenceTests.java deleted file mode 100644 index 02e31aa816..0000000000 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/MinimalTargetDefinitionPersistenceTests.java +++ /dev/null @@ -1,653 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2018 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.pde.ui.tests.target; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.variables.VariablesPlugin; -import org.eclipse.jdt.launching.JavaRuntime; -import org.eclipse.pde.core.plugin.TargetPlatform; -import org.eclipse.pde.core.target.ITargetDefinition; -import org.eclipse.pde.core.target.ITargetHandle; -import org.eclipse.pde.core.target.ITargetLocation; -import org.eclipse.pde.core.target.ITargetPlatformService; -import org.eclipse.pde.core.target.NameVersionDescriptor; -import org.eclipse.pde.internal.core.target.DirectoryBundleContainer; -import org.eclipse.pde.internal.core.target.FeatureBundleContainer; -import org.eclipse.pde.internal.core.target.IUBundleContainer; -import org.eclipse.pde.internal.core.target.ProfileBundleContainer; -import org.eclipse.pde.internal.core.target.TargetDefinition; -import org.eclipse.pde.internal.core.target.TargetDefinitionPersistenceHelper; -import org.eclipse.pde.ui.tests.PDETestsPlugin; -import org.junit.Test; -import org.osgi.framework.ServiceReference; - -/** - * Tests the persistence of target definitions. Tests memento creation, reading - * of old target files, and writing of the model. Runs on the minimal bundles - * and don't require the whole eclipse SDK.This class is refactored out of - * TargetDefinitionPersistenceTests - * - */ -public class MinimalTargetDefinitionPersistenceTests { - - protected void assertTargetDefinitionsEqual(ITargetDefinition targetA, ITargetDefinition targetB) { - assertTrue("Target content not equal", ((TargetDefinition) targetA).isContentEqual(targetB)); - } - - /** - * Returns the target platform service or null if none - * - * @return target platform service - */ - protected ITargetPlatformService getTargetService() { - ServiceReference reference = PDETestsPlugin.getBundleContext() - .getServiceReference(ITargetPlatformService.class); - assertNotNull("Missing target platform service", reference); - return PDETestsPlugin.getBundleContext().getService(reference); - } - - /** - * Returns the resolved location of the specified bundle container. - * - * @param container - * bundle container - * @return resolved location - * @throws CoreException - */ - protected String getResolvedLocation(ITargetLocation container) throws CoreException { - return container.getLocation(true); - } - - /** - * Returns the location of the JDT feature in the running host as a path in - * the local file system. - * - * @return path to JDT feature - */ - protected IPath getJdtFeatureLocation() { - IPath path = IPath.fromOSString(TargetPlatform.getDefaultLocation()); - path = path.append("features"); - File dir = path.toFile(); - assertTrue("Missing features directory", dir.exists() && !dir.isFile()); - String[] files = dir.list(); - String location = null; - for (String file : files) { - if (file.startsWith("org.eclipse.jdt_")) { - location = path.append(file).toOSString(); - break; - } - } - assertNotNull("Missing JDT feature", location); - return IPath.fromOSString(location); - } - - /** - * Tests restoration of a handle to target definition in an IFile - * - * @throws CoreException - */ - @Test - public void testWorkspaceTargetHandleMemento() throws CoreException { - ITargetPlatformService service = getTargetService(); - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(IPath.fromOSString("does/not/exist")); - ITargetHandle handle = service.getTarget(file); - assertFalse("Target should not exist", handle.exists()); - String memento = handle.getMemento(); - assertNotNull("Missing memento", memento); - ITargetHandle handle2 = service.getTarget(memento); - assertEquals("Restore failed", handle, handle2); - IFile file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(IPath.fromOSString("does/not/exist/either")); - ITargetHandle handle3 = service.getTarget(file2); - assertFalse("Should be different targets", handle.equals(handle3)); - } - - /** - * Tests restoration of a handle to target definition in local metadata - * - * @throws CoreException - * @throws InterruptedException - */ - @Test - public void testLocalTargetHandleMemento() throws CoreException, InterruptedException { - ITargetPlatformService service = getTargetService(); - ITargetHandle handle = service.newTarget().getHandle(); - assertFalse("Target should not exist", handle.exists()); - String memento = handle.getMemento(); - assertNotNull("Missing memento", memento); - ITargetHandle handle2 = service.getTarget(memento); - assertEquals("Restore failed", handle, handle2); - ITargetHandle handle3 = service.newTarget().getHandle(); - assertFalse("Should be different targets", handle.equals(handle3)); - } - - /** - * Tests restoration of a handle to target definition in external URI - * - * @throws CoreException - * @throws InterruptedException - */ - @Test - public void testExternalFileTargetHandleMemento() throws CoreException, InterruptedException { - ITargetPlatformService service = getTargetService(); - URI uri = null; - try { - uri = new URI("file:///does/not/exist"); - } catch (URISyntaxException e) { - } - // IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new - // Path("does/not/exist")); - ITargetHandle handle = service.getTarget(uri); - assertFalse("Target should not exist", handle.exists()); - String memento = handle.getMemento(); - assertNotNull("Missing memento", memento); - ITargetHandle handle2 = service.getTarget(memento); - assertEquals("Restore failed", handle, handle2); - // IFile file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(new - // Path("does/not/exist/either")); - URI uri2 = null; - try { - uri2 = new URI("file://even/this/file/does/not/exist"); - } catch (URISyntaxException e) { - } - ITargetHandle handle3 = service.getTarget(uri2); - assertFalse("Should be different targets", handle.equals(handle3)); - } - - /** - * Tests that a complex metadata based target definition can be serialized - * to xml, then deserialized without any loss of data. - * - * @throws Exception - */ - - /** - * Tests that an empty target definition can be serialized to xml, then - * deserialized without any loss of data. - * - * @throws Exception - */ - @Test - public void testPersistEmptyDefinition() throws Exception { - ITargetDefinition definitionA = getTargetService().newTarget(); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - TargetDefinitionPersistenceHelper.persistXML(definitionA, outputStream); - ITargetDefinition definitionB = getTargetService().newTarget(); - ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); - TargetDefinitionPersistenceHelper.initFromXML(definitionB, inputStream); - assertTargetDefinitionsEqual(definitionA, definitionB); - } - - /** - * Reads a target definition file from the tests/targets/target-files - * location with the given name. Note that ".target" will be appended. - * - * @param name - * @return target definition - * @throws Exception - */ - protected ITargetDefinition readOldTarget(String name) throws Exception { - URL url = PDETestsPlugin.getBundleContext().getBundle() - .getEntry("/tests/targets/target-files/" + name + ".trgt"); - File file = new File(FileLocator.toFileURL(url).getFile()); - ITargetDefinition target = getTargetService().newTarget(); - try (FileInputStream stream = new FileInputStream(file)) { - TargetDefinitionPersistenceHelper.initFromXML(target, stream); - } - return target; - } - - /** - * Tests that we can de-serialize an old style target definition file - * (version 3.2) and retrieve the correct contents. - * - * @throws Exception - */ - @Test - public void testReadOldBasicTargetFile() throws Exception { - ITargetDefinition target = readOldTarget("basic"); - - assertEquals("Wrong name", "Basic", target.getName()); - assertNull(target.getArch()); - assertNull(target.getOS()); - assertNull(target.getNL()); - assertNull(target.getWS()); - assertNull(target.getProgramArguments()); - assertNull(target.getVMArguments()); - assertNull(target.getImplicitDependencies()); - assertNull(target.getJREContainer()); - - ITargetLocation[] containers = target.getTargetLocations(); - assertEquals("Wrong number of bundles", 1, containers.length); - assertTrue("Container should be a profile container", containers[0] instanceof ProfileBundleContainer); - assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()), - IPath.fromOSString(getResolvedLocation(containers[0]))); - } - - /** - * Tests that we can de-serialize an old style target definition file - * (version 3.2) and retrieve the correct contents. - * - * @throws Exception - */ - @Test - public void testReadOldBasicDirectoryTargetFile() throws Exception { - ITargetDefinition target = readOldTarget("directory"); - - assertEquals("Wrong name", "Directory", target.getName()); - assertNull(target.getArch()); - assertNull(target.getOS()); - assertNull(target.getNL()); - assertNull(target.getWS()); - assertNull(target.getProgramArguments()); - assertNull(target.getVMArguments()); - assertNull(target.getImplicitDependencies()); - assertNull(target.getJREContainer()); - - ITargetLocation[] containers = target.getTargetLocations(); - assertEquals("Wrong number of bundles", 1, containers.length); - assertTrue("Container should be a directory container", containers[0] instanceof DirectoryBundleContainer); - assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()).append("plugins"), - IPath.fromOSString(getResolvedLocation(containers[0]))); - } - - /** - * Tests that we can de-serialize an old style target definition file - * (version 3.2) and retrieve the correct contents. - * - * @throws Exception - */ - @Test - public void testReadOldSpecificTargetFile() throws Exception { - ITargetDefinition target = readOldTarget("specific"); - - assertEquals("Wrong name", "Specific Settings", target.getName()); - assertEquals("x86", target.getArch()); - assertEquals("linux", target.getOS()); - assertEquals("en_US", target.getNL()); - assertEquals("gtk", target.getWS()); - assertEquals("pgm1 pgm2", target.getProgramArguments()); - assertEquals("-Dfoo=\"bar\"", target.getVMArguments()); - assertEquals( - JavaRuntime - .newJREContainerPath(JavaRuntime.getExecutionEnvironmentsManager().getEnvironment( - "J2SE-1.4")), - target.getJREContainer()); - - NameVersionDescriptor[] infos = target.getImplicitDependencies(); - assertEquals("Wrong number of implicit dependencies", 2, infos.length); - Set set = new HashSet<>(); - for (NameVersionDescriptor info : infos) { - set.add(info.getId()); - } - assertTrue("Missing ", set.remove("org.eclipse.jdt.debug")); - assertTrue("Missing ", set.remove("org.eclipse.debug.core")); - assertTrue(set.isEmpty()); - - ITargetLocation[] containers = target.getTargetLocations(); - assertEquals("Wrong number of bundles", 1, containers.length); - assertTrue("Container should be a directory container", containers[0] instanceof DirectoryBundleContainer); - assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()).append("plugins"), - IPath.fromOSString(getResolvedLocation(containers[0]))); - } - - /** - * Tests that we can de-serialize an old style target definition file - * (version 3.2) and retrieve the correct contents. - * - * @throws Exception - */ - @Test - public void testReadOldAdditionLocationsTargetFile() throws Exception { - ITargetDefinition target = readOldTarget("additionalLocations"); - - assertEquals("Wrong name", "Additional Locations", target.getName()); - assertNull(target.getArch()); - assertNull(target.getOS()); - assertNull(target.getNL()); - assertNull(target.getWS()); - assertNull(target.getProgramArguments()); - assertNull(target.getVMArguments()); - assertNull(target.getJREContainer()); - assertNull(target.getImplicitDependencies()); - - ITargetLocation[] containers = target.getTargetLocations(); - assertEquals("Wrong number of bundles", 3, containers.length); - assertTrue(containers[0] instanceof ProfileBundleContainer); - assertTrue(containers[1] instanceof DirectoryBundleContainer); - assertTrue(containers[2] instanceof DirectoryBundleContainer); - - assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()), - IPath.fromOSString(getResolvedLocation(containers[0]))); - - String string = VariablesPlugin.getDefault().getStringVariableManager() - .performStringSubstitution("${workspace_loc}"); - assertEquals("Wrong 1st additional location", IPath.fromOSString(string).append("stuff"), - IPath.fromOSString(getResolvedLocation(containers[1]))); - - assertEquals("Wrong 2nd additional location", IPath.fromOSString(TargetPlatform.getDefaultLocation()).append("dropins"), - IPath.fromOSString(getResolvedLocation(containers[2]))); - } - - /** - * Tests that we can de-serialize an old style target definition file - * (version 3.2) and retrieve the correct contents. - * - * @throws Exception - */ - @Test - public void testReadOldFeaturesTargetFile() throws Exception { - ITargetDefinition target = readOldTarget("featureLocations"); - - assertEquals("Wrong name", "Features", target.getName()); - assertNull(target.getArch()); - assertNull(target.getOS()); - assertNull(target.getNL()); - assertNull(target.getWS()); - assertNull(target.getProgramArguments()); - assertNull(target.getVMArguments()); - assertNull(target.getJREContainer()); - assertNull(target.getImplicitDependencies()); - - ITargetLocation[] containers = target.getTargetLocations(); - assertEquals("Wrong number of bundles", 2, containers.length); - assertTrue(containers[0] instanceof FeatureBundleContainer); - assertTrue(containers[1] instanceof FeatureBundleContainer); - - assertEquals("Wrong feature location", "org.eclipse.jdt", - ((FeatureBundleContainer) containers[0]).getFeatureId()); - assertEquals("Wrong feature location", "org.eclipse.platform", - ((FeatureBundleContainer) containers[1]).getFeatureId()); - } - - /** - * Tests that we can de-serialize an old style target definition file - * (version 3.2) and retrieve the correct contents. - * - * @throws Exception - */ - @Test - public void testReadOldRestrictionsTargetFile() throws Exception { - ITargetDefinition target = readOldTarget("restrictions"); - - assertEquals("Wrong name", "Restrictions", target.getName()); - assertNull(target.getArch()); - assertNull(target.getOS()); - assertNull(target.getNL()); - assertNull(target.getWS()); - assertNull(target.getProgramArguments()); - assertNull(target.getVMArguments()); - assertNull(target.getJREContainer()); - assertNull(target.getImplicitDependencies()); - - ITargetLocation[] containers = target.getTargetLocations(); - assertEquals("Wrong number of containers", 3, containers.length); - assertTrue(containers[0] instanceof ProfileBundleContainer); - assertTrue(containers[1] instanceof FeatureBundleContainer); - assertTrue(containers[2] instanceof DirectoryBundleContainer); - - assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()), - IPath.fromOSString(getResolvedLocation(containers[0]))); - assertEquals("Wrong 1st additional location", "org.eclipse.jdt", - ((FeatureBundleContainer) containers[1]).getFeatureId()); - assertEquals("Wrong 2nd additional location", IPath.fromOSString(TargetPlatform.getDefaultLocation()).append("dropins"), - IPath.fromOSString(getResolvedLocation(containers[2]))); - - NameVersionDescriptor[] restrictions = new NameVersionDescriptor[] { - new NameVersionDescriptor("org.eclipse.debug.core", null), - new NameVersionDescriptor("org.eclipse.debug.ui", null), - new NameVersionDescriptor("org.eclipse.jdt.debug", null), - new NameVersionDescriptor("org.eclipse.jdt.debug.ui", null), - new NameVersionDescriptor("org.eclipse.jdt.launching", null) }; - - NameVersionDescriptor[] actual = target.getIncluded(); - assertNotNull(actual); - assertEquals("Wrong number of restrictions", restrictions.length, actual.length); - for (int j = 0; j < actual.length; j++) { - assertEquals("Wrong restriction", restrictions[j], actual[j]); - } - } - - /** - * Tests that we can de-serialize an old style target definition file - * (version 3.2) that has extra/unsupported tags and retrieve the correct - * contents. - * - * @throws Exception - */ - @Test - public void testReadOldTargetFileWithUnknownTags() throws Exception { - ITargetDefinition target = readOldTarget("extratags"); - - assertEquals("Wrong name", "Restrictions", target.getName()); - assertNull(target.getArch()); - assertNull(target.getOS()); - assertNull(target.getNL()); - assertNull(target.getWS()); - assertNull(target.getProgramArguments()); - assertNull(target.getVMArguments()); - assertNull(target.getJREContainer()); - assertNull(target.getImplicitDependencies()); - - ITargetLocation[] containers = target.getTargetLocations(); - assertEquals("Wrong number of bundles", 3, containers.length); - assertTrue(containers[0] instanceof ProfileBundleContainer); - assertTrue(containers[1] instanceof FeatureBundleContainer); - assertTrue(containers[2] instanceof DirectoryBundleContainer); - - assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()), - IPath.fromOSString(getResolvedLocation(containers[0]))); - assertEquals("Wrong 1st additional location", "org.eclipse.jdt", - ((FeatureBundleContainer) containers[1]).getFeatureId()); - assertEquals("Wrong 2nd additional location", IPath.fromOSString(TargetPlatform.getDefaultLocation()).append("dropins"), - IPath.fromOSString(getResolvedLocation(containers[2]))); - - NameVersionDescriptor[] restrictions = new NameVersionDescriptor[] { - new NameVersionDescriptor("org.eclipse.debug.core", null), - new NameVersionDescriptor("org.eclipse.debug.ui", null), - new NameVersionDescriptor("org.eclipse.jdt.debug", null), - new NameVersionDescriptor("org.eclipse.jdt.debug.ui", null), - new NameVersionDescriptor("org.eclipse.jdt.launching", null) }; - - NameVersionDescriptor[] actual = target.getIncluded(); - assertNotNull(actual); - assertEquals("Wrong number of restrictions", restrictions.length, actual.length); - for (int j = 0; j < actual.length; j++) { - assertEquals("Wrong restriction", restrictions[j], actual[j]); - } - } - - /** - * Tests that we can de-serialize an old style target definition file - * (version 3.2) and retrieve the correct contents with optional bundles. - * - * @throws Exception - */ - @Test - public void testReadOldOptionalTargetFile() throws Exception { - ITargetDefinition target = readOldTarget("optional"); - - assertEquals("Wrong name", "Optional", target.getName()); - assertNull(target.getArch()); - assertNull(target.getOS()); - assertNull(target.getNL()); - assertNull(target.getWS()); - assertNull(target.getProgramArguments()); - assertNull(target.getVMArguments()); - assertNull(target.getImplicitDependencies()); - assertNull(target.getJREContainer()); - - ITargetLocation[] containers = target.getTargetLocations(); - assertEquals("Wrong number of bundles", 2, containers.length); - assertTrue("Container should be a profile container", containers[0] instanceof ProfileBundleContainer); - assertTrue("Container should be a profile container", containers[1] instanceof FeatureBundleContainer); - assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()), - IPath.fromOSString(getResolvedLocation(containers[0]))); - assertEquals("Wrong feature location", "org.eclipse.jdt", - ((FeatureBundleContainer) containers[1]).getFeatureId()); - - // Old optional settings are added to includes - NameVersionDescriptor[] included = new NameVersionDescriptor[] { - new NameVersionDescriptor("org.eclipse.debug.core", null), - new NameVersionDescriptor("org.eclipse.debug.examples.core", null), - new NameVersionDescriptor("org.eclipse.debug.examples.ui", null), - new NameVersionDescriptor("org.eclipse.debug.ui", null), - new NameVersionDescriptor("org.eclipse.jdt.debug", null), - new NameVersionDescriptor("org.eclipse.jdt.debug.ui", null), - new NameVersionDescriptor("org.eclipse.jdt.launching", null) }; - - NameVersionDescriptor[] actual = target.getIncluded(); - assertNotNull(actual); - assertEquals("Wrong number of inclusions", included.length, actual.length); - for (int j = 0; j < actual.length; j++) { - assertEquals("Wrong restriction", included[j], actual[j]); - } - } - - /** - * Test for bug 268709, if the content section is included in the xml, but - * there are no specific plug-ins or features as well as no - * useAllPlugins=true setting, treat the file as though it did include all - * plug-ins from the directory. - */ - @Test - public void testEmptyContentSection() throws Exception { - ITargetDefinition target = readOldTarget("emptycontent"); - - ITargetLocation[] containers = target.getTargetLocations(); - assertEquals("Wrong number of bundles", 1, containers.length); - assertTrue("Container should be a directory container", containers[0] instanceof DirectoryBundleContainer); - assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()).append("plugins"), - IPath.fromOSString(getResolvedLocation(containers[0]))); - - target.resolve(null); - - assertTrue("Should have resolved bundles", target.getBundles().length > 0); - - } - - /** - * Test for bug 264139. Tests that when a target definition specifies - * "useAllPlugins=true" that we ignore specific plug-ins/features specified - * in the file during migration. - * - * @throws Exception - */ - @Test - public void testMigrationOfUseAllWithRestrictions() throws Exception { - ITargetDefinition target = readOldTarget("eclipse-serverside"); - ITargetLocation[] containers = target.getTargetLocations(); - assertEquals(6, containers.length); - validateTypeAndLocation(containers[0], ProfileBundleContainer.class, - "${resource_loc:/target-platforms/eclipse-equinox-SDK-3.5M5/eclipse}"); - validateTypeAndLocation(containers[1], DirectoryBundleContainer.class, - "${resource_loc:/target-platforms/eclipse-3.5M5-delta-pack/eclipse}"); - validateTypeAndLocation(containers[2], DirectoryBundleContainer.class, - "${resource_loc:/target-platforms/eclipse-pde-headless-3.5M5}"); - validateTypeAndLocation(containers[3], DirectoryBundleContainer.class, - "${resource_loc:/target-platforms/eclipse-test-framework-3.5M5/eclipse}"); - validateTypeAndLocation(containers[4], DirectoryBundleContainer.class, - "${resource_loc:/target-platforms/eclipse-core-plugins-3.5M5}"); - validateTypeAndLocation(containers[5], DirectoryBundleContainer.class, - "${resource_loc:/target-platforms/3rdparty-bundles}"); - } - - /** - * Validates the type and location of a bundle container. - * - * @param container - * container to validate - * @param clazz - * the type of container expected - * @param rawLocation - * its unresolved location - * @throws CoreException - * if something goes wrong - */ - protected void validateTypeAndLocation(ITargetLocation container, Class clazz, String rawLocation) - throws CoreException { - assertTrue(clazz.isInstance(container)); - assertEquals(rawLocation, container.getLocation(false)); - } - - /** - * Tests that we increment the sequence number correctly when target is - * modified contents. - * - * @throws Exception - */ - @Test - public void testSequenceNumberChange() throws Exception { - ITargetDefinition target = readOldTarget("featureLocations"); - - assertEquals("Wrong name", "Features", target.getName()); - TargetDefinition targetDef = (TargetDefinition) target; - int currentSeqNo = targetDef.getSequenceNumber(); - target.setArch("x86"); - asssrtSequenceNumber("Arch", currentSeqNo, targetDef); - - currentSeqNo = targetDef.getSequenceNumber(); - target.setOS("win32"); - asssrtSequenceNumber("OS", currentSeqNo, targetDef); - - currentSeqNo = targetDef.getSequenceNumber(); - target.setNL("hi_IN"); - asssrtSequenceNumber("NL", currentSeqNo, targetDef); - - currentSeqNo = targetDef.getSequenceNumber(); - target.setWS("carbon"); - asssrtSequenceNumber("WS", currentSeqNo, targetDef); - - ITargetLocation[] newContainers = new ITargetLocation[1]; - newContainers[0] = new DirectoryBundleContainer("Path"); - currentSeqNo = targetDef.getSequenceNumber(); - target.setTargetLocations(newContainers); - asssrtSequenceNumber("Bundle Containers", currentSeqNo, targetDef); - } - - private void asssrtSequenceNumber(String name, int currentSeqNo, TargetDefinition targetDef) { - assertEquals("Sequence number did not increment after updating '" + name + "'", currentSeqNo + 1, - targetDef.getSequenceNumber()); - } - - @Test - public void testIncludeSource() throws Exception { - ITargetDefinition target = readOldTarget("SoftwareSiteTarget"); - ITargetLocation[] containers = target.getTargetLocations(); - assertEquals(1, containers.length); - assertTrue(containers[0] instanceof IUBundleContainer); - IUBundleContainer iubc = (IUBundleContainer) containers[0]; - assertTrue(iubc.getIncludeSource()); - } - -} \ No newline at end of file diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/MinimalTargetDefinitionResolutionTests.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/MinimalTargetDefinitionResolutionTests.java deleted file mode 100644 index 5838e04249..0000000000 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/MinimalTargetDefinitionResolutionTests.java +++ /dev/null @@ -1,401 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2017 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.pde.ui.tests.target; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.File; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.equinox.p2.metadata.IInstallableUnit; -import org.eclipse.jdt.launching.JavaRuntime; -import org.eclipse.pde.core.plugin.TargetPlatform; -import org.eclipse.pde.core.target.ITargetDefinition; -import org.eclipse.pde.core.target.ITargetLocation; -import org.eclipse.pde.core.target.ITargetPlatformService; -import org.eclipse.pde.core.target.NameVersionDescriptor; -import org.eclipse.pde.core.target.TargetBundle; -import org.eclipse.pde.internal.core.target.IUBundleContainer; -import org.junit.Test; - -/** - * Runs on minimal bundles and don't require full eclipse SDK.This class is - * refactored out of TargetDefinitionResolutionTests - * - */ -public class MinimalTargetDefinitionResolutionTests extends AbstractTargetTest { - @Test - public void testInvalidBundleContainers() throws Exception { - ITargetDefinition definition = getNewTarget(); - - ITargetLocation directoryContainer = getTargetService().newDirectoryLocation("***SHOULD NOT EXIST***"); - IStatus status = directoryContainer.resolve(definition, null); - assertEquals("Incorrect severity", IStatus.ERROR, status.getSeverity()); - - ITargetLocation profileContainer = getTargetService().newProfileLocation("***SHOULD NOT EXIST***", null); - status = directoryContainer.resolve(definition, null); - assertEquals("Incorrect severity", IStatus.ERROR, status.getSeverity()); - - ITargetLocation featureContainer = getTargetService().newFeatureLocation("***SHOULD NOT EXIST***", - "org.eclipse.jdt", ""); - status = directoryContainer.resolve(definition, null); - assertEquals("Incorrect severity", IStatus.ERROR, status.getSeverity()); - - definition.setTargetLocations(new ITargetLocation[] { directoryContainer, profileContainer, featureContainer }); - status = definition.resolve(null); - IStatus[] children = status.getChildren(); - assertEquals("Wrong number of children", 3, children.length); - for (IStatus element : children) { - assertEquals("Incorrect severity", IStatus.ERROR, element.getSeverity()); - assertFalse("Failed resolution should be single status", element.isMultiStatus()); - } - } - - /** - * Tests that if we find a bundle with a bad or missing manifest when - * resolving we create the correct status. - * - * @see TargetBundle.STATUS_INVALID_MANIFEST - * @throws Exception - */ - @Test - public void testInvalidManifest() throws Exception { - // TODO Should we have tests for this? - } - - @Test - public void testResolutionCaching() throws Exception { - ITargetDefinition definition = getNewTarget(); - assertTrue(definition.isResolved()); - assertNotNull("Bundles not available when resolved", definition.getBundles()); - assertEquals("Wrong number of bundles", 0, definition.getBundles().length); - - // Resolving with errors should stay resolved, solving a definition - // should resolve all targets - ITargetLocation brokenContainer = getTargetService().newDirectoryLocation("***SHOULD NOT EXIST***"); - assertFalse(brokenContainer.isResolved()); - assertNull("Bundles available when unresolved", brokenContainer.getBundles()); - definition.setTargetLocations(new ITargetLocation[] { brokenContainer }); - assertFalse(definition.isResolved()); - assertNull("Bundles available when unresolved", definition.getBundles()); - IStatus status = definition.resolve(null); - assertEquals("Incorrect Severity", IStatus.ERROR, status.getSeverity()); - assertTrue(brokenContainer.isResolved()); - assertNotNull("Bundles not available when resolved", brokenContainer.getBundles()); - assertTrue(definition.isResolved()); - assertNotNull("Bundles not available when resolved", definition.getBundles()); - - // Adding an unresolved container should make the target unresolved, - // resolving the container should resolve the target - ITargetLocation profileContainer = getTargetService().newProfileLocation(TargetPlatform.getDefaultLocation(), - null); - assertFalse(profileContainer.isResolved()); - assertNull("Bundles available when unresolved", profileContainer.getBundles()); - definition.setTargetLocations(new ITargetLocation[] { brokenContainer, profileContainer }); - assertFalse(definition.isResolved()); - assertNull("Bundles available when unresolved", definition.getBundles()); - status = profileContainer.resolve(definition, null); - assertEquals("Incorrect Severity", IStatus.OK, status.getSeverity()); - assertEquals("Incorrect Severity", IStatus.ERROR, definition.getStatus().getSeverity()); - assertTrue(profileContainer.isResolved()); - assertNotNull("Bundles not available when resolved", profileContainer.getBundles()); - assertTrue(definition.isResolved()); - assertNotNull("Bundles not available when resolved", definition.getBundles()); - - // Having a bundle status does not prevent the resolution, adding a - // resolved container should leave the target resolved - ITargetLocation includesContainer = getTargetService().newProfileLocation(TargetPlatform.getDefaultLocation(), - null); - assertFalse(includesContainer.isResolved()); - assertNull("Bundles available when unresolved", includesContainer.getBundles()); - status = includesContainer.resolve(definition, null); - assertTrue(includesContainer.isResolved()); - assertNotNull("Bundles not available when resolved", includesContainer.getBundles()); - assertEquals("Incorrect Severity", IStatus.OK, status.getSeverity()); - assertEquals("Incorrect Severity", IStatus.OK, includesContainer.getStatus().getSeverity()); - definition.setTargetLocations(new ITargetLocation[] { brokenContainer, profileContainer }); - definition.setIncluded(new NameVersionDescriptor[] { new NameVersionDescriptor("bogus", null), - new NameVersionDescriptor("org.eclipse.platform", "666.666.666") }); - assertTrue(definition.isResolved()); - assertEquals("Incorrect Severity", IStatus.ERROR, definition.getStatus().getSeverity()); - assertNotNull("Bundles not available when resolved", definition.getBundles()); - - // Setting includes, etc. should not unresolve the target - definition.setIncluded(null); - assertTrue(definition.isResolved()); - definition.setIncluded(new NameVersionDescriptor[] { new NameVersionDescriptor("bogus", null), - new NameVersionDescriptor("org.eclipse.platform", "666.666.666") }); - assertTrue(definition.isResolved()); - definition.setName("name"); - definition.setOS("os"); - definition.setWS("ws"); - definition.setArch("arch"); - definition.setNL("nl"); - definition.setProgramArguments("program\nargs"); - definition.setVMArguments("vm\nargs"); - definition.setJREContainer(JavaRuntime.newDefaultJREContainerPath()); - NameVersionDescriptor[] implicit = new NameVersionDescriptor[] { - new NameVersionDescriptor("org.eclipse.jdt.launching", null), - new NameVersionDescriptor("org.eclipse.jdt.debug", null) }; - definition.setImplicitDependencies(implicit); - assertTrue(definition.isResolved()); - definition.setName(null); - definition.setOS(null); - definition.setWS(null); - definition.setArch(null); - definition.setNL(null); - definition.setProgramArguments(null); - definition.setVMArguments(null); - definition.setJREContainer(null); - definition.setImplicitDependencies(null); - assertTrue(definition.isResolved()); - - definition.setTargetLocations(null); - assertTrue(definition.isResolved()); - assertNotNull("Bundles not available when resolved", definition.getBundles()); - - } - - - - /** - * Tests that a target definition is in synch with the target platform. - * - * @throws Exception - */ - @Test - public void testTargetInSynch() throws Exception { - IPath location = extractAbcdePlugins(); - IPath dirPath = location.append("plugins"); - ITargetDefinition definition = getNewTarget(); - ITargetLocation container = getTargetService().newDirectoryLocation(dirPath.toOSString()); - definition.setTargetLocations(new ITargetLocation[] { container }); - definition.resolve(null); - TargetBundle[] allBundles = definition.getAllBundles(); - assertEquals(10, allBundles.length); - - try { - setTargetPlatform(definition); - IStatus status = getTargetService().compareWithTargetPlatform(definition); - assertTrue(status.isOK()); - } finally { - resetTargetPlatform(); - } - } - - /** - * Tests that a target definition is in synch with the target platform when - * there are duplicates in the target definition (duplicates should be - * ignored). - * - * @throws Exception - */ - @Test - public void testTargetInSynchWithDuplicates() throws Exception { - IPath location = extractAbcdePlugins(); - IPath dirPath = location.append("plugins"); - ITargetDefinition definition = getNewTarget(); - ITargetLocation container = getTargetService().newDirectoryLocation(dirPath.toOSString()); - ITargetLocation container2 = getTargetService().newDirectoryLocation(dirPath.toOSString()); - definition.setTargetLocations(new ITargetLocation[] { container, container2 }); - definition.resolve(null); - TargetBundle[] allBundles = definition.getAllBundles(); - assertEquals(20, allBundles.length); - - try { - setTargetPlatform(definition); - IStatus status = getTargetService().compareWithTargetPlatform(definition); - assertTrue(status.isOK()); - } finally { - resetTargetPlatform(); - } - } - - /** - * Tests that a target definition is not in synch with the target platform - * when a bundle is deleted from the underlying files system (target - * platform). - * - * @throws Exception - */ - @Test - public void testTargetMissingBundle() throws Exception { - IPath location = extractAbcdePlugins(); - IPath dirPath = location.append("plugins"); - ITargetDefinition definition = getNewTarget(); - ITargetLocation container = getTargetService().newDirectoryLocation(dirPath.toOSString()); - definition.setTargetLocations(new ITargetLocation[] { container }); - - try { - setTargetPlatform(definition); - // delete a bundle - IPath bundle = dirPath.append("bundle.a_1.0.0.jar"); - assertTrue(bundle.toFile().exists()); - bundle.toFile().delete(); - // force definition to re-resolve - ITargetDefinition copy = getTargetService().newTarget(); - getTargetService().copyTargetDefinition(definition, copy); - copy.resolve(null); - IStatus status = getTargetService().compareWithTargetPlatform(copy); - assertNotNull(status); - assertFalse(status.isOK()); - IStatus[] children = status.getChildren(); - assertEquals(1, children.length); - assertEquals(ITargetPlatformService.STATUS_MISSING_FROM_TARGET_DEFINITION, children[0].getCode()); - assertEquals("bundle.a", children[0].getMessage()); - } finally { - resetTargetPlatform(); - } - } - - /** - * Tests that a target definition will warn if an expected bundle does not - * exist on the file system. - * - * @throws Exception - */ - @Test - public void testTargetPlatformMissingBundle() throws Exception { - IPath location = extractAbcdePlugins(); - IPath dirPath = location.append("plugins"); - // delete a bundle - IPath bundle = dirPath.append("bundle.a_1.0.0.jar"); - File jar = bundle.toFile(); - assertTrue(jar.exists()); - jar.delete(); - - ITargetDefinition definition = getTargetService().newTarget(); - ITargetLocation container = getTargetService().newDirectoryLocation(dirPath.toOSString()); - definition.setTargetLocations(new ITargetLocation[] { container }); - definition.resolve(null); - TargetBundle[] allBundles = definition.getAllBundles(); - assertEquals(9, allBundles.length); - - try { - setTargetPlatform(definition); - // force definition to re-resolve - ITargetDefinition copy = getTargetService().newTarget(); - getTargetService().copyTargetDefinition(definition, copy); - // add the bundle back to the file system - extractAbcdePlugins(); - - copy.resolve(null); - IStatus status = getTargetService().compareWithTargetPlatform(copy); - assertNotNull(status); - assertFalse(status.isOK()); - IStatus[] children = status.getChildren(); - assertEquals(1, children.length); - assertEquals(ITargetPlatformService.STATUS_MISSING_FROM_TARGET_PLATFORM, children[0].getCode()); - assertEquals("bundle.a", children[0].getMessage()); - } finally { - resetTargetPlatform(); - } - } - - /** - * Tests the two options on IU bundle containers for controlling how the - * site will be resolved - * - * @throws Exception - */ - @Test - public void testSiteContainerIncludeSettings() throws Exception { - ITargetDefinition target = getNewTarget(); - IUBundleContainer containerA = (IUBundleContainer) getTargetService().newIULocation(new IInstallableUnit[0], - null, IUBundleContainer.INCLUDE_REQUIRED); - IUBundleContainer containerB = (IUBundleContainer) getTargetService().newIULocation( - new String[] { "unit1", "unit2" }, new String[] { "1.0", "2.0" }, null, - IUBundleContainer.INCLUDE_REQUIRED); - target.setTargetLocations(new ITargetLocation[] { containerA, containerB }); - - // Check default settings - assertTrue(containerA.getIncludeAllRequired()); - assertFalse(containerA.getIncludeAllEnvironments()); - assertFalse(containerA.getIncludeSource()); - assertTrue(containerB.getIncludeAllRequired()); - assertFalse(containerB.getIncludeAllEnvironments()); - assertFalse(containerB.getIncludeSource()); - - // Check basic changes - int flags = IUBundleContainer.INCLUDE_ALL_ENVIRONMENTS | IUBundleContainer.INCLUDE_SOURCE; - containerA = (IUBundleContainer) getTargetService().newIULocation(new IInstallableUnit[0], null, flags); - containerB = (IUBundleContainer) getTargetService().newIULocation(new String[] { "unit1", "unit2" }, - new String[] { "1.0", "2.0" }, null, flags); - target.setTargetLocations(new ITargetLocation[] { containerA, containerB }); - assertFalse(containerA.getIncludeAllRequired()); - assertTrue(containerA.getIncludeAllEnvironments()); - assertTrue(containerA.getIncludeSource()); - - // Check that all containers are updated in the target if target is - // passed as argument - flags = IUBundleContainer.INCLUDE_ALL_ENVIRONMENTS | IUBundleContainer.INCLUDE_SOURCE; - containerA = (IUBundleContainer) getTargetService().newIULocation(new IInstallableUnit[0], null, flags); - flags = IUBundleContainer.INCLUDE_REQUIRED; - containerB = (IUBundleContainer) getTargetService().newIULocation(new String[] { "unit1", "unit2" }, - new String[] { "1.0", "2.0" }, null, flags); - - target.setTargetLocations(new ITargetLocation[] { containerA, containerB }); - assertTrue(containerA.getIncludeAllRequired()); - assertFalse(containerA.getIncludeAllEnvironments()); - assertFalse(containerA.getIncludeSource()); - assertTrue(containerB.getIncludeAllRequired()); - assertFalse(containerB.getIncludeAllEnvironments()); - assertFalse(containerB.getIncludeSource()); - - // now switch the order of A and B - target.setTargetLocations(new ITargetLocation[] { containerB, containerA }); - assertFalse(containerA.getIncludeAllRequired()); - assertTrue(containerA.getIncludeAllEnvironments()); - assertTrue(containerA.getIncludeSource()); - assertFalse(containerB.getIncludeAllRequired()); - assertTrue(containerB.getIncludeAllEnvironments()); - assertTrue(containerB.getIncludeSource()); - } - - @Test - public void testNameVersionDescriptor() { - NameVersionDescriptor d1 = new NameVersionDescriptor("a.b.c", "1.0.0"); - NameVersionDescriptor d2 = new NameVersionDescriptor("a.b.c", "1.0.0"); - assertEquals(d1, d2); - - d1 = new NameVersionDescriptor("a.b.c", "1.0.0"); - d2 = new NameVersionDescriptor("a.b.c", "1.0.1"); - assertFalse(d1.equals(d2)); - - d1 = new NameVersionDescriptor("a.b.c", "1.0.0"); - d2 = new NameVersionDescriptor("a.b.e", "1.0.0"); - assertFalse(d1.equals(d2)); - - d1 = new NameVersionDescriptor("a.b.c", null); - d2 = new NameVersionDescriptor("a.b.c", null); - assertEquals(d1, d2); - - d1 = new NameVersionDescriptor("a.b.c", null); - d2 = new NameVersionDescriptor("a.b.e", null); - assertFalse(d1.equals(d2)); - - d1 = new NameVersionDescriptor("a.b.c", null); - d2 = new NameVersionDescriptor("a.b.c", "1.0.0"); - assertFalse(d1.equals(d2)); - - d1 = new NameVersionDescriptor("a.b.c", "1.0.0"); - d2 = new NameVersionDescriptor("a.b.c", null); - assertFalse(d1.equals(d2)); - } -} \ No newline at end of file diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/TargetDefinitionFeatureResolutionTests.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/TargetDefinitionFeatureResolutionTests.java index 1b49cfb58b..62428d7573 100644 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/TargetDefinitionFeatureResolutionTests.java +++ b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/TargetDefinitionFeatureResolutionTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2017 IBM Corporation and others. + * Copyright (c) 2009, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,16 +14,28 @@ package org.eclipse.pde.ui.tests.target; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; import org.eclipse.pde.core.plugin.TargetPlatform; import org.eclipse.pde.core.target.ITargetDefinition; import org.eclipse.pde.core.target.ITargetLocation; +import org.eclipse.pde.core.target.NameVersionDescriptor; +import org.eclipse.pde.core.target.TargetBundle; import org.eclipse.pde.core.target.TargetFeature; import org.eclipse.pde.internal.core.PDECore; import org.eclipse.pde.internal.core.ifeature.IFeatureModel; +import org.eclipse.pde.ui.tests.PDETestCase; import org.junit.Test; /** @@ -31,13 +43,346 @@ * * @since 3.6 */ -public class TargetDefinitionFeatureResolutionTests extends MinimalTargetDefinitionFeatureResolutionTests { +public class TargetDefinitionFeatureResolutionTests extends AbstractTargetTest { + + /** + * Tests that a directory bundle container provides the correct features to + * a target + */ + @Test + public void testDirectoryBundleContainer() throws Exception { + ITargetDefinition definition = getNewTarget(); + ITargetLocation directoryContainer = getTargetService() + .newDirectoryLocation(TargetPlatform.getDefaultLocation()); + + assertNull(directoryContainer.getFeatures()); + + IFeatureModel[] expectedFeatures = PDECore.getDefault().getFeatureModelManager().getModels(); + Set expectedIDs = new HashSet<>(); + for (IFeatureModel expectedFeature : expectedFeatures) { + expectedIDs.add(expectedFeature.getFeature().getId()); + } + + directoryContainer.resolve(definition, null); + TargetFeature[] features = directoryContainer.getFeatures(); + assertNotNull(features); + + for (TargetFeature feature : features) { + String currentID = feature.getId(); + assertTrue("Extra feature in result: " + currentID, expectedIDs.contains(currentID)); + expectedIDs.remove(currentID); + } + + assertTrue("Not all expected features returned by the container: " + expectedIDs.toString(), + expectedIDs.isEmpty()); + } + + /** + * Tests that a profile (installation) bundle container provides the correct + * features to a target + */ + @Test + public void testProfileBundleContainer() throws Exception { + ITargetDefinition definition = getNewTarget(); + ITargetLocation profileContainer = getTargetService().newProfileLocation(TargetPlatform.getDefaultLocation(), + null); + + assertNull(profileContainer.getFeatures()); + + IFeatureModel[] expectedFeatures = PDECore.getDefault().getFeatureModelManager().getModels(); + Set expectedIDs = new HashSet<>(); + for (IFeatureModel expectedFeature : expectedFeatures) { + expectedIDs.add(expectedFeature.getFeature().getId()); + } + + profileContainer.resolve(definition, null); + TargetFeature[] features = profileContainer.getFeatures(); + assertNotNull(features); + + for (TargetFeature feature : features) { + String currentID = feature.getId(); + assertTrue("Extra feature in result: " + currentID, expectedIDs.contains(currentID)); + expectedIDs.remove(currentID); + } + + assertTrue("Not all expected features returned by the container: " + expectedIDs.toString(), + expectedIDs.isEmpty()); + } + + @Test + public void testExplicitIncludes() throws Exception { + // Use the modified JDT features as we know their versions + ITargetDefinition definition = getNewTarget(); + IPath location = extractModifiedFeatures(); + + ITargetLocation container = getTargetService().newDirectoryLocation(location.toOSString()); + definition.setTargetLocations(new ITargetLocation[] { container }); + definition.resolve(null); + + List expected = new ArrayList<>(); + expected.add("org.eclipse.jdt"); + expected.add("org.eclipse.jdt.launching"); + expected.add("org.eclipse.jdt.launching.source"); + // 2 versions of JUnit + expected.add("org.junit"); + expected.add("org.junit.source"); + expected.add("org.junit"); + expected.add("org.junit.source"); + expected.add("org.junit4"); + if (Platform.getOS().equals(Platform.OS_MACOSX)) { + expected.add("org.eclipse.jdt.launching.macosx"); + expected.add("org.eclipse.jdt.launching.macosx.source"); + } + + NameVersionDescriptor[] allFeatures = new NameVersionDescriptor[] { + new NameVersionDescriptor("org.eclipse.jdt", "3.6.0.v20100105-0800-7z8VFR9FMTb52_pOyKHhoek1", + NameVersionDescriptor.TYPE_FEATURE), + new NameVersionDescriptor("org.eclipse.jdt.source", "3.6.0.v20100105-0800-7z8VFR9FMTb52_pOyKHhoek1", + NameVersionDescriptor.TYPE_FEATURE) }; + definition.setIncluded(allFeatures); + TargetBundle[] bundles = definition.getBundles(); + + for (TargetBundle bundle : bundles) { + String symbolicName = bundle.getBundleInfo().getSymbolicName(); + expected.remove(symbolicName); + if (symbolicName.equals("org.eclipse.jdt.launching.macosx")) { + // the bundle should be missing unless on Mac + IStatus status = bundle.getStatus(); + if (Platform.getOS().equals(Platform.OS_MACOSX)) { + assertTrue("Mac bundle should be present", status.isOK()); + } else { + assertFalse("Mac bundle should be missing", status.isOK()); + assertEquals("Mac bundle should be mssing", TargetBundle.STATUS_PLUGIN_DOES_NOT_EXIST, + status.getCode()); + } + } + } + for (String name : expected) { + System.err.println("Missing: " + name); + } + assertTrue("Wrong bundles in JDT feature", expected.isEmpty()); + + } + + @Test + public void testSingleInclude() throws Exception { + // Use the modified JDT features as we know their versions + ITargetDefinition definition = getNewTarget(); + IPath location = extractModifiedFeatures(); + + ITargetLocation container = getTargetService().newDirectoryLocation(location.toOSString()); + definition.setTargetLocations(new ITargetLocation[] { container }); + definition.resolve(null); + + List expected = new ArrayList<>(); + expected.add("org.eclipse.jdt"); + expected.add("org.eclipse.jdt.launching"); + // 2 versions of JUnit + expected.add("org.junit"); + expected.add("org.junit"); + expected.add("org.junit4"); + if (Platform.getOS().equals(Platform.OS_MACOSX)) { + expected.add("org.eclipse.jdt.launching.macosx"); + } + + NameVersionDescriptor[] allFeatures = new NameVersionDescriptor[] { + new NameVersionDescriptor("org.eclipse.jdt", null, NameVersionDescriptor.TYPE_FEATURE) }; + definition.setIncluded(allFeatures); + TargetBundle[] bundles = definition.getBundles(); + + for (TargetBundle bundle : bundles) { + String symbolicName = bundle.getBundleInfo().getSymbolicName(); + expected.remove(symbolicName); + if (symbolicName.equals("org.eclipse.jdt.launching.macosx")) { + // the bundle should be missing unless on Mac + IStatus status = bundle.getStatus(); + if (Platform.getOS().equals(Platform.OS_MACOSX)) { + assertTrue("Mac bundle should be present", status.isOK()); + } else { + assertFalse("Mac bundle should be missing", status.isOK()); + assertEquals("Mac bundle should be missing", TargetBundle.STATUS_PLUGIN_DOES_NOT_EXIST, + status.getCode()); + } + } + } + for (String name : expected) { + System.err.println("Missing: " + name); + } + assertTrue("Wrong bundles in JDT feature", expected.isEmpty()); + } + + @Test + public void testMixedIncludes() throws Exception { + // Use the modified JDT features as we know their versions + ITargetDefinition definition = getNewTarget(); + IPath location = extractModifiedFeatures(); + + ITargetLocation container = getTargetService().newDirectoryLocation(location.toOSString()); + definition.setTargetLocations(new ITargetLocation[] { container }); + definition.resolve(null); + + List expected = new ArrayList<>(); + expected.add("org.eclipse.jdt"); + expected.add("org.eclipse.jdt.launching"); + // 2 versions of JUnit + expected.add("org.junit"); + expected.add("org.junit"); + expected.add("org.junit4"); + if (Platform.getOS().equals(Platform.OS_MACOSX)) { + expected.add("org.eclipse.jdt.launching.macosx"); + } + + NameVersionDescriptor[] allFeatures = new NameVersionDescriptor[] { + new NameVersionDescriptor("org.eclipse.jdt", null, NameVersionDescriptor.TYPE_FEATURE), + new NameVersionDescriptor("org.eclipse.jdt", null, NameVersionDescriptor.TYPE_PLUGIN) }; + definition.setIncluded(allFeatures); + TargetBundle[] bundles = definition.getBundles(); + + for (TargetBundle bundle : bundles) { + String symbolicName = bundle.getBundleInfo().getSymbolicName(); + expected.remove(symbolicName); + if (symbolicName.equals("org.eclipse.jdt.launching.macosx")) { + // the bundle should be missing unless on Mac + IStatus status = bundle.getStatus(); + if (Platform.getOS().equals(Platform.OS_MACOSX)) { + assertTrue("Mac bundle should be present", status.isOK()); + } else { + assertFalse("Mac bundle should be missing", status.isOK()); + assertEquals("Mac bundle should be mssing", TargetBundle.STATUS_PLUGIN_DOES_NOT_EXIST, + status.getCode()); + } + } + } + for (String name : expected) { + System.err.println("Missing: " + name); + } + assertTrue("Wrong bundles in JDT feature", expected.isEmpty()); + } + + @Test + public void testMissingFeatures() throws Exception { + // Use the modified JDT features as we know their versions + ITargetDefinition definition = getNewTarget(); + IPath location = extractModifiedFeatures(); + + ITargetLocation container = getTargetService().newDirectoryLocation(location.toOSString()); + definition.setTargetLocations(new ITargetLocation[] { container }); + definition.resolve(null); + + NameVersionDescriptor[] allFeatures = new NameVersionDescriptor[] { + new NameVersionDescriptor("DOES_NOT_EXIST", null, NameVersionDescriptor.TYPE_FEATURE), }; + definition.setIncluded(allFeatures); + TargetBundle[] bundles = definition.getBundles(); + + assertNotNull("Target didn't resolve", bundles); + assertEquals("Wrong number of included bundles", 1, bundles.length); + + IStatus definitionStatus = definition.getStatus(); + assertEquals("Wrong severity", IStatus.ERROR, definitionStatus.getSeverity()); + + IStatus[] children = definitionStatus.getChildren(); + assertEquals("Wrong number of statuses", 1, children.length); + assertEquals("Wrong severity", IStatus.ERROR, children[0].getSeverity()); + assertEquals(TargetBundle.STATUS_FEATURE_DOES_NOT_EXIST, children[0].getCode()); + + // Check that removing the included bundles and resolving removes the + // errors. + definition.setIncluded(null); + assertTrue(definition.isResolved()); + assertTrue(definition.getStatus().isOK()); + assertTrue(definition.getBundles().length > 4); + } + + @Test + public void testMissingFeatureVersion() throws Exception { + // Use the modified JDT features as we know their versions + ITargetDefinition definition = getNewTarget(); + IPath location = extractModifiedFeatures(); + + ITargetLocation container = getTargetService().newDirectoryLocation(location.toOSString()); + definition.setTargetLocations(new ITargetLocation[] { container }); + definition.resolve(null); + + List expected = new ArrayList<>(); + expected.add("org.eclipse.jdt"); + expected.add("org.eclipse.jdt.launching"); + // 2 versions of JUnit + expected.add("org.junit"); + expected.add("org.junit"); + expected.add("org.junit4"); + if (Platform.getOS().equals(Platform.OS_MACOSX)) { + expected.add("org.eclipse.jdt.launching.macosx"); + } + + NameVersionDescriptor[] allFeatures = new NameVersionDescriptor[] { + new NameVersionDescriptor("org.eclipse.jdt", "DOES_NOT_EXIST", NameVersionDescriptor.TYPE_FEATURE) }; + definition.setIncluded(allFeatures); + TargetBundle[] bundles = definition.getBundles(); + + for (TargetBundle bundle : bundles) { + String symbolicName = bundle.getBundleInfo().getSymbolicName(); + expected.remove(symbolicName); + if (symbolicName.equals("org.eclipse.jdt.launching.macosx")) { + // the bundle should be missing unless on Mac + IStatus status = bundle.getStatus(); + if (Platform.getOS().equals(Platform.OS_MACOSX)) { + assertTrue("Mac bundle should be present", status.isOK()); + } else { + assertFalse("Mac bundle should be missing", status.isOK()); + assertEquals("Mac bundle should be mssing", TargetBundle.STATUS_PLUGIN_DOES_NOT_EXIST, + status.getCode()); + } + } + } + for (String name : expected) { + System.err.println("Missing: " + name); + } + assertTrue("Wrong bundles in JDT feature", expected.isEmpty()); + } + + @Test + public void testMissingMixed() throws Exception { + // Use the modified JDT features as we know their versions + ITargetDefinition definition = getNewTarget(); + IPath location = extractModifiedFeatures(); + + ITargetLocation container = getTargetService().newDirectoryLocation(location.toOSString()); + definition.setTargetLocations(new ITargetLocation[] { container }); + definition.resolve(null); + + NameVersionDescriptor[] allFeatures = new NameVersionDescriptor[] { + new NameVersionDescriptor("DOES_NOT_EXIST", null, NameVersionDescriptor.TYPE_FEATURE), + new NameVersionDescriptor("DOES_NOT_EXIST", null, NameVersionDescriptor.TYPE_PLUGIN), + new NameVersionDescriptor("org.eclipse.jdt", "DOES_NOT_EXIST", NameVersionDescriptor.TYPE_PLUGIN), }; + definition.setIncluded(allFeatures); + TargetBundle[] bundles = definition.getBundles(); + + assertNotNull("Target didn't resolve", bundles); + assertEquals("Wrong number of included bundles", 1, bundles.length); + + IStatus definitionStatus = definition.getStatus(); + assertEquals("Wrong severity", IStatus.ERROR, definitionStatus.getSeverity()); + + IStatus[] children = definitionStatus.getChildren(); + assertEquals("Wrong number of statuses", 1, children.length); + assertEquals("Wrong severity", IStatus.ERROR, children[0].getSeverity()); + assertEquals(TargetBundle.STATUS_FEATURE_DOES_NOT_EXIST, children[0].getCode()); + + // Check that removing the included bundles and resolving removes the + // errors. + definition.setIncluded(null); + assertTrue(definition.isResolved()); + assertTrue(definition.getStatus().isOK()); + assertTrue(definition.getBundles().length > 4); + } /** * Tests that a feature bundle container provides the correct features to a target */ @Test - public void testFeatureBundleContainer() throws Exception{ + public void testFeatureBundleContainer() throws Exception { + PDETestCase.assumeRunningInStandaloneEclipseSDK(); + ITargetDefinition definition = getNewTarget(); ITargetLocation featureContainer = getTargetService().newFeatureLocation(TargetPlatform.getDefaultLocation(), "org.eclipse.pde", null); diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/TargetDefinitionPersistenceTests.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/TargetDefinitionPersistenceTests.java index 531cda038a..2eec51c38d 100644 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/TargetDefinitionPersistenceTests.java +++ b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/TargetDefinitionPersistenceTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2017 IBM Corporation and others. + * Copyright (c) 2008, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,47 +13,527 @@ *******************************************************************************/ package org.eclipse.pde.ui.tests.target; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileInputStream; import java.net.URI; import java.net.URISyntaxException; +import java.net.URL; +import java.util.HashSet; +import java.util.Set; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.variables.VariablesPlugin; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.jdt.launching.JavaRuntime; import org.eclipse.pde.core.plugin.TargetPlatform; import org.eclipse.pde.core.target.ITargetDefinition; +import org.eclipse.pde.core.target.ITargetHandle; import org.eclipse.pde.core.target.ITargetLocation; +import org.eclipse.pde.core.target.ITargetPlatformService; import org.eclipse.pde.core.target.NameVersionDescriptor; +import org.eclipse.pde.internal.core.target.DirectoryBundleContainer; +import org.eclipse.pde.internal.core.target.FeatureBundleContainer; import org.eclipse.pde.internal.core.target.IUBundleContainer; +import org.eclipse.pde.internal.core.target.ProfileBundleContainer; +import org.eclipse.pde.internal.core.target.TargetDefinition; import org.eclipse.pde.internal.core.target.TargetDefinitionPersistenceHelper; +import org.eclipse.pde.ui.tests.PDETestCase; +import org.eclipse.pde.ui.tests.PDETestsPlugin; import org.junit.Test; +import org.osgi.framework.ServiceReference; /** - * Tests the persistence of target definitions. Tests memento creation, reading of old target files, and writing of the model. + * Tests the persistence of target definitions. Tests memento creation, reading + * of old target files, and writing of the model. * * @since 3.5 */ -public class TargetDefinitionPersistenceTests extends MinimalTargetDefinitionPersistenceTests { +public class TargetDefinitionPersistenceTests { + + /** Tests restoration of a handle to target definition in an IFile. */ + @Test + public void testWorkspaceTargetHandleMemento() throws CoreException { + ITargetPlatformService service = getTargetService(); + IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(IPath.fromOSString("does/not/exist")); + ITargetHandle handle = service.getTarget(file); + assertFalse("Target should not exist", handle.exists()); + String memento = handle.getMemento(); + assertNotNull("Missing memento", memento); + ITargetHandle handle2 = service.getTarget(memento); + assertEquals("Restore failed", handle, handle2); + IFile file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(IPath.fromOSString("does/not/exist/either")); + ITargetHandle handle3 = service.getTarget(file2); + assertFalse("Should be different targets", handle.equals(handle3)); + } + + /** Tests restoration of a handle to target definition in local metadata. */ + @Test + public void testLocalTargetHandleMemento() throws CoreException { + ITargetPlatformService service = getTargetService(); + ITargetHandle handle = service.newTarget().getHandle(); + assertFalse("Target should not exist", handle.exists()); + String memento = handle.getMemento(); + assertNotNull("Missing memento", memento); + ITargetHandle handle2 = service.getTarget(memento); + assertEquals("Restore failed", handle, handle2); + ITargetHandle handle3 = service.newTarget().getHandle(); + assertFalse("Should be different targets", handle.equals(handle3)); + } + + /** Tests restoration of a handle to target definition in external URI. */ + @Test + public void testExternalFileTargetHandleMemento() throws CoreException { + ITargetPlatformService service = getTargetService(); + URI uri = null; + try { + uri = new URI("file:///does/not/exist"); + } catch (URISyntaxException e) { + } + // IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new + // Path("does/not/exist")); + ITargetHandle handle = service.getTarget(uri); + assertFalse("Target should not exist", handle.exists()); + String memento = handle.getMemento(); + assertNotNull("Missing memento", memento); + ITargetHandle handle2 = service.getTarget(memento); + assertEquals("Restore failed", handle, handle2); + // IFile file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(new + // Path("does/not/exist/either")); + URI uri2 = null; + try { + uri2 = new URI("file://even/this/file/does/not/exist"); + } catch (URISyntaxException e) { + } + ITargetHandle handle3 = service.getTarget(uri2); + assertFalse("Should be different targets", handle.equals(handle3)); + } /** - * Tests that a complex metadata based target definition can be serialized to xml, - * then deserialized without any loss of data. - * - * @throws Exception + * Tests that an empty target definition can be serialized to xml, then + * deserialized without any loss of data. + */ + @Test + public void testPersistEmptyDefinition() throws Exception { + ITargetDefinition definitionA = getTargetService().newTarget(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + TargetDefinitionPersistenceHelper.persistXML(definitionA, outputStream); + ITargetDefinition definitionB = getTargetService().newTarget(); + ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); + TargetDefinitionPersistenceHelper.initFromXML(definitionB, inputStream); + assertTargetDefinitionsEqual(definitionA, definitionB); + } + + /** + * Tests that we can de-serialize an old style target definition file + * (version 3.2) and retrieve the correct contents. + */ + @Test + public void testReadOldBasicTargetFile() throws Exception { + ITargetDefinition target = readOldTarget("basic"); + + assertEquals("Wrong name", "Basic", target.getName()); + assertNull(target.getArch()); + assertNull(target.getOS()); + assertNull(target.getNL()); + assertNull(target.getWS()); + assertNull(target.getProgramArguments()); + assertNull(target.getVMArguments()); + assertNull(target.getImplicitDependencies()); + assertNull(target.getJREContainer()); + + ITargetLocation[] containers = target.getTargetLocations(); + assertEquals("Wrong number of bundles", 1, containers.length); + assertTrue("Container should be a profile container", containers[0] instanceof ProfileBundleContainer); + assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()), + IPath.fromOSString(getResolvedLocation(containers[0]))); + } + + /** + * Tests that we can de-serialize an old style target definition file + * (version 3.2) and retrieve the correct contents. + */ + @Test + public void testReadOldBasicDirectoryTargetFile() throws Exception { + ITargetDefinition target = readOldTarget("directory"); + + assertEquals("Wrong name", "Directory", target.getName()); + assertNull(target.getArch()); + assertNull(target.getOS()); + assertNull(target.getNL()); + assertNull(target.getWS()); + assertNull(target.getProgramArguments()); + assertNull(target.getVMArguments()); + assertNull(target.getImplicitDependencies()); + assertNull(target.getJREContainer()); + + ITargetLocation[] containers = target.getTargetLocations(); + assertEquals("Wrong number of bundles", 1, containers.length); + assertTrue("Container should be a directory container", containers[0] instanceof DirectoryBundleContainer); + assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()).append("plugins"), + IPath.fromOSString(getResolvedLocation(containers[0]))); + } + + /** + * Tests that we can de-serialize an old style target definition file + * (version 3.2) and retrieve the correct contents. + */ + @Test + public void testReadOldSpecificTargetFile() throws Exception { + ITargetDefinition target = readOldTarget("specific"); + + assertEquals("Wrong name", "Specific Settings", target.getName()); + assertEquals("x86", target.getArch()); + assertEquals("linux", target.getOS()); + assertEquals("en_US", target.getNL()); + assertEquals("gtk", target.getWS()); + assertEquals("pgm1 pgm2", target.getProgramArguments()); + assertEquals("-Dfoo=\"bar\"", target.getVMArguments()); + assertEquals( + JavaRuntime + .newJREContainerPath(JavaRuntime.getExecutionEnvironmentsManager().getEnvironment("J2SE-1.4")), + target.getJREContainer()); + + NameVersionDescriptor[] infos = target.getImplicitDependencies(); + assertEquals("Wrong number of implicit dependencies", 2, infos.length); + Set set = new HashSet<>(); + for (NameVersionDescriptor info : infos) { + set.add(info.getId()); + } + assertTrue("Missing ", set.remove("org.eclipse.jdt.debug")); + assertTrue("Missing ", set.remove("org.eclipse.debug.core")); + assertTrue(set.isEmpty()); + + ITargetLocation[] containers = target.getTargetLocations(); + assertEquals("Wrong number of bundles", 1, containers.length); + assertTrue("Container should be a directory container", containers[0] instanceof DirectoryBundleContainer); + assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()).append("plugins"), + IPath.fromOSString(getResolvedLocation(containers[0]))); + } + + /** + * Tests that we can de-serialize an old style target definition file + * (version 3.2) and retrieve the correct contents. + */ + @Test + public void testReadOldAdditionLocationsTargetFile() throws Exception { + ITargetDefinition target = readOldTarget("additionalLocations"); + + assertEquals("Wrong name", "Additional Locations", target.getName()); + assertNull(target.getArch()); + assertNull(target.getOS()); + assertNull(target.getNL()); + assertNull(target.getWS()); + assertNull(target.getProgramArguments()); + assertNull(target.getVMArguments()); + assertNull(target.getJREContainer()); + assertNull(target.getImplicitDependencies()); + + ITargetLocation[] containers = target.getTargetLocations(); + assertEquals("Wrong number of bundles", 3, containers.length); + assertTrue(containers[0] instanceof ProfileBundleContainer); + assertTrue(containers[1] instanceof DirectoryBundleContainer); + assertTrue(containers[2] instanceof DirectoryBundleContainer); + + assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()), + IPath.fromOSString(getResolvedLocation(containers[0]))); + + String string = VariablesPlugin.getDefault().getStringVariableManager() + .performStringSubstitution("${workspace_loc}"); + assertEquals("Wrong 1st additional location", IPath.fromOSString(string).append("stuff"), + IPath.fromOSString(getResolvedLocation(containers[1]))); + + assertEquals("Wrong 2nd additional location", + IPath.fromOSString(TargetPlatform.getDefaultLocation()).append("dropins"), + IPath.fromOSString(getResolvedLocation(containers[2]))); + } + + /** + * Tests that we can de-serialize an old style target definition file + * (version 3.2) and retrieve the correct contents. + */ + @Test + public void testReadOldFeaturesTargetFile() throws Exception { + ITargetDefinition target = readOldTarget("featureLocations"); + + assertEquals("Wrong name", "Features", target.getName()); + assertNull(target.getArch()); + assertNull(target.getOS()); + assertNull(target.getNL()); + assertNull(target.getWS()); + assertNull(target.getProgramArguments()); + assertNull(target.getVMArguments()); + assertNull(target.getJREContainer()); + assertNull(target.getImplicitDependencies()); + + ITargetLocation[] containers = target.getTargetLocations(); + assertEquals("Wrong number of bundles", 2, containers.length); + assertTrue(containers[0] instanceof FeatureBundleContainer); + assertTrue(containers[1] instanceof FeatureBundleContainer); + + assertEquals("Wrong feature location", "org.eclipse.jdt", + ((FeatureBundleContainer) containers[0]).getFeatureId()); + assertEquals("Wrong feature location", "org.eclipse.platform", + ((FeatureBundleContainer) containers[1]).getFeatureId()); + } + + /** + * Tests that we can de-serialize an old style target definition file + * (version 3.2) and retrieve the correct contents. + */ + @Test + public void testReadOldRestrictionsTargetFile() throws Exception { + ITargetDefinition target = readOldTarget("restrictions"); + + assertEquals("Wrong name", "Restrictions", target.getName()); + assertNull(target.getArch()); + assertNull(target.getOS()); + assertNull(target.getNL()); + assertNull(target.getWS()); + assertNull(target.getProgramArguments()); + assertNull(target.getVMArguments()); + assertNull(target.getJREContainer()); + assertNull(target.getImplicitDependencies()); + + ITargetLocation[] containers = target.getTargetLocations(); + assertEquals("Wrong number of containers", 3, containers.length); + assertTrue(containers[0] instanceof ProfileBundleContainer); + assertTrue(containers[1] instanceof FeatureBundleContainer); + assertTrue(containers[2] instanceof DirectoryBundleContainer); + + assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()), + IPath.fromOSString(getResolvedLocation(containers[0]))); + assertEquals("Wrong 1st additional location", "org.eclipse.jdt", + ((FeatureBundleContainer) containers[1]).getFeatureId()); + assertEquals("Wrong 2nd additional location", + IPath.fromOSString(TargetPlatform.getDefaultLocation()).append("dropins"), + IPath.fromOSString(getResolvedLocation(containers[2]))); + + NameVersionDescriptor[] restrictions = new NameVersionDescriptor[] { + new NameVersionDescriptor("org.eclipse.debug.core", null), + new NameVersionDescriptor("org.eclipse.debug.ui", null), + new NameVersionDescriptor("org.eclipse.jdt.debug", null), + new NameVersionDescriptor("org.eclipse.jdt.debug.ui", null), + new NameVersionDescriptor("org.eclipse.jdt.launching", null) }; + + NameVersionDescriptor[] actual = target.getIncluded(); + assertNotNull(actual); + assertEquals("Wrong number of restrictions", restrictions.length, actual.length); + for (int j = 0; j < actual.length; j++) { + assertEquals("Wrong restriction", restrictions[j], actual[j]); + } + } + + /** + * Tests that we can de-serialize an old style target definition file + * (version 3.2) that has extra/unsupported tags and retrieve the correct + * contents. + */ + @Test + public void testReadOldTargetFileWithUnknownTags() throws Exception { + ITargetDefinition target = readOldTarget("extratags"); + + assertEquals("Wrong name", "Restrictions", target.getName()); + assertNull(target.getArch()); + assertNull(target.getOS()); + assertNull(target.getNL()); + assertNull(target.getWS()); + assertNull(target.getProgramArguments()); + assertNull(target.getVMArguments()); + assertNull(target.getJREContainer()); + assertNull(target.getImplicitDependencies()); + + ITargetLocation[] containers = target.getTargetLocations(); + assertEquals("Wrong number of bundles", 3, containers.length); + assertTrue(containers[0] instanceof ProfileBundleContainer); + assertTrue(containers[1] instanceof FeatureBundleContainer); + assertTrue(containers[2] instanceof DirectoryBundleContainer); + + assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()), + IPath.fromOSString(getResolvedLocation(containers[0]))); + assertEquals("Wrong 1st additional location", "org.eclipse.jdt", + ((FeatureBundleContainer) containers[1]).getFeatureId()); + assertEquals("Wrong 2nd additional location", + IPath.fromOSString(TargetPlatform.getDefaultLocation()).append("dropins"), + IPath.fromOSString(getResolvedLocation(containers[2]))); + + NameVersionDescriptor[] restrictions = new NameVersionDescriptor[] { + new NameVersionDescriptor("org.eclipse.debug.core", null), + new NameVersionDescriptor("org.eclipse.debug.ui", null), + new NameVersionDescriptor("org.eclipse.jdt.debug", null), + new NameVersionDescriptor("org.eclipse.jdt.debug.ui", null), + new NameVersionDescriptor("org.eclipse.jdt.launching", null) }; + + NameVersionDescriptor[] actual = target.getIncluded(); + assertNotNull(actual); + assertEquals("Wrong number of restrictions", restrictions.length, actual.length); + for (int j = 0; j < actual.length; j++) { + assertEquals("Wrong restriction", restrictions[j], actual[j]); + } + } + + /** + * Tests that we can de-serialize an old style target definition file + * (version 3.2) and retrieve the correct contents with optional bundles. */ + @Test + public void testReadOldOptionalTargetFile() throws Exception { + ITargetDefinition target = readOldTarget("optional"); + assertEquals("Wrong name", "Optional", target.getName()); + assertNull(target.getArch()); + assertNull(target.getOS()); + assertNull(target.getNL()); + assertNull(target.getWS()); + assertNull(target.getProgramArguments()); + assertNull(target.getVMArguments()); + assertNull(target.getImplicitDependencies()); + assertNull(target.getJREContainer()); + + ITargetLocation[] containers = target.getTargetLocations(); + assertEquals("Wrong number of bundles", 2, containers.length); + assertTrue("Container should be a profile container", containers[0] instanceof ProfileBundleContainer); + assertTrue("Container should be a profile container", containers[1] instanceof FeatureBundleContainer); + assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()), + IPath.fromOSString(getResolvedLocation(containers[0]))); + assertEquals("Wrong feature location", "org.eclipse.jdt", + ((FeatureBundleContainer) containers[1]).getFeatureId()); + + // Old optional settings are added to includes + NameVersionDescriptor[] included = new NameVersionDescriptor[] { + new NameVersionDescriptor("org.eclipse.debug.core", null), + new NameVersionDescriptor("org.eclipse.debug.examples.core", null), + new NameVersionDescriptor("org.eclipse.debug.examples.ui", null), + new NameVersionDescriptor("org.eclipse.debug.ui", null), + new NameVersionDescriptor("org.eclipse.jdt.debug", null), + new NameVersionDescriptor("org.eclipse.jdt.debug.ui", null), + new NameVersionDescriptor("org.eclipse.jdt.launching", null) }; + + NameVersionDescriptor[] actual = target.getIncluded(); + assertNotNull(actual); + assertEquals("Wrong number of inclusions", included.length, actual.length); + for (int j = 0; j < actual.length; j++) { + assertEquals("Wrong restriction", included[j], actual[j]); + } + } + + /** + * Test for bug 268709, if the content section is included in the xml, but + * there are no specific plug-ins or features as well as no + * useAllPlugins=true setting, treat the file as though it did include all + * plug-ins from the directory. + */ + @Test + public void testEmptyContentSection() throws Exception { + ITargetDefinition target = readOldTarget("emptycontent"); + + ITargetLocation[] containers = target.getTargetLocations(); + assertEquals("Wrong number of bundles", 1, containers.length); + assertTrue("Container should be a directory container", containers[0] instanceof DirectoryBundleContainer); + assertEquals("Wrong home location", IPath.fromOSString(TargetPlatform.getDefaultLocation()).append("plugins"), + IPath.fromOSString(getResolvedLocation(containers[0]))); + + target.resolve(null); + + assertTrue("Should have resolved bundles", target.getBundles().length > 0); + + } + + /** + * Test for bug 264139. Tests that when a target definition specifies + * "useAllPlugins=true" that we ignore specific plug-ins/features specified + * in the file during migration. + */ + @Test + public void testMigrationOfUseAllWithRestrictions() throws Exception { + ITargetDefinition target = readOldTarget("eclipse-serverside"); + ITargetLocation[] containers = target.getTargetLocations(); + assertEquals(6, containers.length); + validateTypeAndLocation(containers[0], ProfileBundleContainer.class, + "${resource_loc:/target-platforms/eclipse-equinox-SDK-3.5M5/eclipse}"); + validateTypeAndLocation(containers[1], DirectoryBundleContainer.class, + "${resource_loc:/target-platforms/eclipse-3.5M5-delta-pack/eclipse}"); + validateTypeAndLocation(containers[2], DirectoryBundleContainer.class, + "${resource_loc:/target-platforms/eclipse-pde-headless-3.5M5}"); + validateTypeAndLocation(containers[3], DirectoryBundleContainer.class, + "${resource_loc:/target-platforms/eclipse-test-framework-3.5M5/eclipse}"); + validateTypeAndLocation(containers[4], DirectoryBundleContainer.class, + "${resource_loc:/target-platforms/eclipse-core-plugins-3.5M5}"); + validateTypeAndLocation(containers[5], DirectoryBundleContainer.class, + "${resource_loc:/target-platforms/3rdparty-bundles}"); + } + + /** Validates the type and location of a bundle container. */ + private static void validateTypeAndLocation(ITargetLocation container, Class clazz, String rawLocation) + throws CoreException { + assertTrue(clazz.isInstance(container)); + assertEquals(rawLocation, container.getLocation(false)); + } + + /** + * Tests that we increment the sequence number correctly when target is + * modified contents. + */ + @Test + public void testSequenceNumberChange() throws Exception { + ITargetDefinition target = readOldTarget("featureLocations"); + + assertEquals("Wrong name", "Features", target.getName()); + TargetDefinition targetDef = (TargetDefinition) target; + int currentSeqNo = targetDef.getSequenceNumber(); + target.setArch("x86"); + asssertSequenceNumber("Arch", currentSeqNo, targetDef); + + currentSeqNo = targetDef.getSequenceNumber(); + target.setOS("win32"); + asssertSequenceNumber("OS", currentSeqNo, targetDef); + + currentSeqNo = targetDef.getSequenceNumber(); + target.setNL("hi_IN"); + asssertSequenceNumber("NL", currentSeqNo, targetDef); + + currentSeqNo = targetDef.getSequenceNumber(); + target.setWS("carbon"); + asssertSequenceNumber("WS", currentSeqNo, targetDef); + + ITargetLocation[] newContainers = new ITargetLocation[1]; + newContainers[0] = new DirectoryBundleContainer("Path"); + currentSeqNo = targetDef.getSequenceNumber(); + target.setTargetLocations(newContainers); + asssertSequenceNumber("Bundle Containers", currentSeqNo, targetDef); + } + + @Test + public void testIncludeSource() throws Exception { + ITargetDefinition target = readOldTarget("SoftwareSiteTarget"); + ITargetLocation[] containers = target.getTargetLocations(); + assertEquals(1, containers.length); + assertTrue(containers[0] instanceof IUBundleContainer); + IUBundleContainer iubc = (IUBundleContainer) containers[0]; + assertTrue(iubc.getIncludeSource()); + } + + /** + * Tests that a complex metadata based target definition can be serialized + * to xml, then deserialized without any loss of data. + */ @Test public void testPersistComplexMetadataDefinition() throws Exception { - // org.junit.Assume.assumeTrue(false); + PDETestCase.assumeRunningInStandaloneEclipseSDK(); + ITargetDefinition definitionA = getTargetService().newTarget(); initComplexDefiniton(definitionA); @@ -69,12 +549,11 @@ public void testPersistComplexMetadataDefinition() throws Exception { /** * Tests that a complex workspace file based target definition can be * serialized to xml, then deserialized without any loss of data. - * - * @throws Exception */ @Test public void testPersistComplexWorkspaceDefinition() throws Exception { - // org.junit.Assume.assumeTrue(false); + PDETestCase.assumeRunningInStandaloneEclipseSDK(); + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("TargetDefinitionPersistenceTests"); try { if (!project.exists()) { @@ -99,7 +578,62 @@ public void testPersistComplexWorkspaceDefinition() throws Exception { } } - protected void initComplexDefiniton(ITargetDefinition definition) throws URISyntaxException { + /** + * Returns the target platform service or null if none + * + * @return target platform service + */ + private ITargetPlatformService getTargetService() { + ServiceReference reference = PDETestsPlugin.getBundleContext() + .getServiceReference(ITargetPlatformService.class); + assertNotNull("Missing target platform service", reference); + return PDETestsPlugin.getBundleContext().getService(reference); + } + + /** + * Reads a target definition file from the tests/targets/target-files + * location with the given name. Note that ".target" will be appended. + */ + private ITargetDefinition readOldTarget(String name) throws Exception { + URL url = PDETestsPlugin.getBundleContext().getBundle() + .getEntry("/tests/targets/target-files/" + name + ".trgt"); + File file = new File(FileLocator.toFileURL(url).getFile()); + ITargetDefinition target = getTargetService().newTarget(); + try (FileInputStream stream = new FileInputStream(file)) { + TargetDefinitionPersistenceHelper.initFromXML(target, stream); + } + return target; + } + + /** Returns the resolved location of the specified bundle container. */ + private String getResolvedLocation(ITargetLocation container) throws CoreException { + return container.getLocation(true); + } + + /** + * Returns the location of the JDT feature in the running host as a path in + * the local file system. + * + * @return path to JDT feature + */ + private IPath getJdtFeatureLocation() { + IPath path = IPath.fromOSString(TargetPlatform.getDefaultLocation()); + path = path.append("features"); + File dir = path.toFile(); + assertTrue("Missing features directory", dir.exists() && !dir.isFile()); + String[] files = dir.list(); + String location = null; + for (String file : files) { + if (file.startsWith("org.eclipse.jdt_")) { + location = path.append(file).toOSString(); + break; + } + } + assertNotNull("Missing JDT feature", location); + return IPath.fromOSString(location); + } + + private void initComplexDefiniton(ITargetDefinition definition) throws URISyntaxException { definition.setName("name"); definition.setOS("os"); definition.setWS("ws"); @@ -148,5 +682,13 @@ protected void initComplexDefiniton(ITargetDefinition definition) throws URISynt restrictedProfileContainer, siteContainer, siteContainer2 }); } + private void assertTargetDefinitionsEqual(ITargetDefinition targetA, ITargetDefinition targetB) { + assertTrue("Target content not equal", ((TargetDefinition) targetA).isContentEqual(targetB)); + } + + private void asssertSequenceNumber(String name, int currentSeqNo, TargetDefinition targetDef) { + assertEquals("Sequence number did not increment after updating '" + name + "'", currentSeqNo + 1, + targetDef.getSequenceNumber()); + } } \ No newline at end of file diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/TargetDefinitionResolutionTests.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/TargetDefinitionResolutionTests.java index 76910c89f8..ead5668e67 100644 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/TargetDefinitionResolutionTests.java +++ b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/target/TargetDefinitionResolutionTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2017 IBM Corporation and others. + * Copyright (c) 2009, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,22 +14,391 @@ package org.eclipse.pde.ui.tests.target; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.io.File; + +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.equinox.frameworkadmin.BundleInfo; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.jdt.launching.JavaRuntime; import org.eclipse.pde.core.plugin.TargetPlatform; import org.eclipse.pde.core.target.ITargetDefinition; import org.eclipse.pde.core.target.ITargetLocation; +import org.eclipse.pde.core.target.ITargetPlatformService; import org.eclipse.pde.core.target.NameVersionDescriptor; import org.eclipse.pde.core.target.TargetBundle; +import org.eclipse.pde.internal.core.target.IUBundleContainer; +import org.eclipse.pde.ui.tests.PDETestCase; import org.junit.Test; -public class TargetDefinitionResolutionTests extends MinimalTargetDefinitionResolutionTests { +public class TargetDefinitionResolutionTests extends AbstractTargetTest { + + @Test + public void testInvalidBundleContainers() throws Exception { + ITargetDefinition definition = getNewTarget(); + + ITargetLocation directoryContainer = getTargetService().newDirectoryLocation("***SHOULD NOT EXIST***"); + IStatus status = directoryContainer.resolve(definition, null); + assertEquals("Incorrect severity", IStatus.ERROR, status.getSeverity()); + + ITargetLocation profileContainer = getTargetService().newProfileLocation("***SHOULD NOT EXIST***", null); + status = directoryContainer.resolve(definition, null); + assertEquals("Incorrect severity", IStatus.ERROR, status.getSeverity()); + + ITargetLocation featureContainer = getTargetService().newFeatureLocation("***SHOULD NOT EXIST***", + "org.eclipse.jdt", ""); + status = directoryContainer.resolve(definition, null); + assertEquals("Incorrect severity", IStatus.ERROR, status.getSeverity()); + + definition.setTargetLocations(new ITargetLocation[] { directoryContainer, profileContainer, featureContainer }); + status = definition.resolve(null); + IStatus[] children = status.getChildren(); + assertEquals("Wrong number of children", 3, children.length); + for (IStatus element : children) { + assertEquals("Incorrect severity", IStatus.ERROR, element.getSeverity()); + assertFalse("Failed resolution should be single status", element.isMultiStatus()); + } + } + + /** + * Tests that if we find a bundle with a bad or missing manifest when + * resolving we create the correct status. + * + * @see TargetBundle.STATUS_INVALID_MANIFEST + * @throws Exception + */ + @Test + public void testInvalidManifest() throws Exception { + // TODO Should we have tests for this? + } + + @Test + public void testResolutionCaching() throws Exception { + ITargetDefinition definition = getNewTarget(); + assertTrue(definition.isResolved()); + assertNotNull("Bundles not available when resolved", definition.getBundles()); + assertEquals("Wrong number of bundles", 0, definition.getBundles().length); + + // Resolving with errors should stay resolved, solving a definition + // should resolve all targets + ITargetLocation brokenContainer = getTargetService().newDirectoryLocation("***SHOULD NOT EXIST***"); + assertFalse(brokenContainer.isResolved()); + assertNull("Bundles available when unresolved", brokenContainer.getBundles()); + definition.setTargetLocations(new ITargetLocation[] { brokenContainer }); + assertFalse(definition.isResolved()); + assertNull("Bundles available when unresolved", definition.getBundles()); + IStatus status = definition.resolve(null); + assertEquals("Incorrect Severity", IStatus.ERROR, status.getSeverity()); + assertTrue(brokenContainer.isResolved()); + assertNotNull("Bundles not available when resolved", brokenContainer.getBundles()); + assertTrue(definition.isResolved()); + assertNotNull("Bundles not available when resolved", definition.getBundles()); + + // Adding an unresolved container should make the target unresolved, + // resolving the container should resolve the target + ITargetLocation profileContainer = getTargetService().newProfileLocation(TargetPlatform.getDefaultLocation(), + null); + assertFalse(profileContainer.isResolved()); + assertNull("Bundles available when unresolved", profileContainer.getBundles()); + definition.setTargetLocations(new ITargetLocation[] { brokenContainer, profileContainer }); + assertFalse(definition.isResolved()); + assertNull("Bundles available when unresolved", definition.getBundles()); + status = profileContainer.resolve(definition, null); + assertEquals("Incorrect Severity", IStatus.OK, status.getSeverity()); + assertEquals("Incorrect Severity", IStatus.ERROR, definition.getStatus().getSeverity()); + assertTrue(profileContainer.isResolved()); + assertNotNull("Bundles not available when resolved", profileContainer.getBundles()); + assertTrue(definition.isResolved()); + assertNotNull("Bundles not available when resolved", definition.getBundles()); + + // Having a bundle status does not prevent the resolution, adding a + // resolved container should leave the target resolved + ITargetLocation includesContainer = getTargetService().newProfileLocation(TargetPlatform.getDefaultLocation(), + null); + assertFalse(includesContainer.isResolved()); + assertNull("Bundles available when unresolved", includesContainer.getBundles()); + status = includesContainer.resolve(definition, null); + assertTrue(includesContainer.isResolved()); + assertNotNull("Bundles not available when resolved", includesContainer.getBundles()); + assertEquals("Incorrect Severity", IStatus.OK, status.getSeverity()); + assertEquals("Incorrect Severity", IStatus.OK, includesContainer.getStatus().getSeverity()); + definition.setTargetLocations(new ITargetLocation[] { brokenContainer, profileContainer }); + definition.setIncluded(new NameVersionDescriptor[] { new NameVersionDescriptor("bogus", null), + new NameVersionDescriptor("org.eclipse.platform", "666.666.666") }); + assertTrue(definition.isResolved()); + assertEquals("Incorrect Severity", IStatus.ERROR, definition.getStatus().getSeverity()); + assertNotNull("Bundles not available when resolved", definition.getBundles()); + + // Setting includes, etc. should not unresolve the target + definition.setIncluded(null); + assertTrue(definition.isResolved()); + definition.setIncluded(new NameVersionDescriptor[] { new NameVersionDescriptor("bogus", null), + new NameVersionDescriptor("org.eclipse.platform", "666.666.666") }); + assertTrue(definition.isResolved()); + definition.setName("name"); + definition.setOS("os"); + definition.setWS("ws"); + definition.setArch("arch"); + definition.setNL("nl"); + definition.setProgramArguments("program\nargs"); + definition.setVMArguments("vm\nargs"); + definition.setJREContainer(JavaRuntime.newDefaultJREContainerPath()); + NameVersionDescriptor[] implicit = new NameVersionDescriptor[] { + new NameVersionDescriptor("org.eclipse.jdt.launching", null), + new NameVersionDescriptor("org.eclipse.jdt.debug", null) }; + definition.setImplicitDependencies(implicit); + assertTrue(definition.isResolved()); + definition.setName(null); + definition.setOS(null); + definition.setWS(null); + definition.setArch(null); + definition.setNL(null); + definition.setProgramArguments(null); + definition.setVMArguments(null); + definition.setJREContainer(null); + definition.setImplicitDependencies(null); + assertTrue(definition.isResolved()); + + definition.setTargetLocations(null); + assertTrue(definition.isResolved()); + assertNotNull("Bundles not available when resolved", definition.getBundles()); + + } + + /** + * Tests that a target definition is in synch with the target platform. + * + * @throws Exception + */ + @Test + public void testTargetInSynch() throws Exception { + IPath location = extractAbcdePlugins(); + IPath dirPath = location.append("plugins"); + ITargetDefinition definition = getNewTarget(); + ITargetLocation container = getTargetService().newDirectoryLocation(dirPath.toOSString()); + definition.setTargetLocations(new ITargetLocation[] { container }); + definition.resolve(null); + TargetBundle[] allBundles = definition.getAllBundles(); + assertEquals(10, allBundles.length); + + try { + setTargetPlatform(definition); + IStatus status = getTargetService().compareWithTargetPlatform(definition); + assertTrue(status.isOK()); + } finally { + resetTargetPlatform(); + } + } + + /** + * Tests that a target definition is in synch with the target platform when + * there are duplicates in the target definition (duplicates should be + * ignored). + * + * @throws Exception + */ + @Test + public void testTargetInSynchWithDuplicates() throws Exception { + IPath location = extractAbcdePlugins(); + IPath dirPath = location.append("plugins"); + ITargetDefinition definition = getNewTarget(); + ITargetLocation container = getTargetService().newDirectoryLocation(dirPath.toOSString()); + ITargetLocation container2 = getTargetService().newDirectoryLocation(dirPath.toOSString()); + definition.setTargetLocations(new ITargetLocation[] { container, container2 }); + definition.resolve(null); + TargetBundle[] allBundles = definition.getAllBundles(); + assertEquals(20, allBundles.length); + + try { + setTargetPlatform(definition); + IStatus status = getTargetService().compareWithTargetPlatform(definition); + assertTrue(status.isOK()); + } finally { + resetTargetPlatform(); + } + } + + /** + * Tests that a target definition is not in synch with the target platform + * when a bundle is deleted from the underlying files system (target + * platform). + * + * @throws Exception + */ + @Test + public void testTargetMissingBundle() throws Exception { + IPath location = extractAbcdePlugins(); + IPath dirPath = location.append("plugins"); + ITargetDefinition definition = getNewTarget(); + ITargetLocation container = getTargetService().newDirectoryLocation(dirPath.toOSString()); + definition.setTargetLocations(new ITargetLocation[] { container }); + + try { + setTargetPlatform(definition); + // delete a bundle + IPath bundle = dirPath.append("bundle.a_1.0.0.jar"); + assertTrue(bundle.toFile().exists()); + bundle.toFile().delete(); + // force definition to re-resolve + ITargetDefinition copy = getTargetService().newTarget(); + getTargetService().copyTargetDefinition(definition, copy); + copy.resolve(null); + IStatus status = getTargetService().compareWithTargetPlatform(copy); + assertNotNull(status); + assertFalse(status.isOK()); + IStatus[] children = status.getChildren(); + assertEquals(1, children.length); + assertEquals(ITargetPlatformService.STATUS_MISSING_FROM_TARGET_DEFINITION, children[0].getCode()); + assertEquals("bundle.a", children[0].getMessage()); + } finally { + resetTargetPlatform(); + } + } + + /** + * Tests that a target definition will warn if an expected bundle does not + * exist on the file system. + * + * @throws Exception + */ + @Test + public void testTargetPlatformMissingBundle() throws Exception { + IPath location = extractAbcdePlugins(); + IPath dirPath = location.append("plugins"); + // delete a bundle + IPath bundle = dirPath.append("bundle.a_1.0.0.jar"); + File jar = bundle.toFile(); + assertTrue(jar.exists()); + jar.delete(); + + ITargetDefinition definition = getTargetService().newTarget(); + ITargetLocation container = getTargetService().newDirectoryLocation(dirPath.toOSString()); + definition.setTargetLocations(new ITargetLocation[] { container }); + definition.resolve(null); + TargetBundle[] allBundles = definition.getAllBundles(); + assertEquals(9, allBundles.length); + + try { + setTargetPlatform(definition); + // force definition to re-resolve + ITargetDefinition copy = getTargetService().newTarget(); + getTargetService().copyTargetDefinition(definition, copy); + // add the bundle back to the file system + extractAbcdePlugins(); + + copy.resolve(null); + IStatus status = getTargetService().compareWithTargetPlatform(copy); + assertNotNull(status); + assertFalse(status.isOK()); + IStatus[] children = status.getChildren(); + assertEquals(1, children.length); + assertEquals(ITargetPlatformService.STATUS_MISSING_FROM_TARGET_PLATFORM, children[0].getCode()); + assertEquals("bundle.a", children[0].getMessage()); + } finally { + resetTargetPlatform(); + } + } + + /** + * Tests the two options on IU bundle containers for controlling how the + * site will be resolved + * + * @throws Exception + */ + @Test + public void testSiteContainerIncludeSettings() throws Exception { + ITargetDefinition target = getNewTarget(); + IUBundleContainer containerA = (IUBundleContainer) getTargetService().newIULocation(new IInstallableUnit[0], + null, IUBundleContainer.INCLUDE_REQUIRED); + IUBundleContainer containerB = (IUBundleContainer) getTargetService().newIULocation( + new String[] { "unit1", "unit2" }, new String[] { "1.0", "2.0" }, null, + IUBundleContainer.INCLUDE_REQUIRED); + target.setTargetLocations(new ITargetLocation[] { containerA, containerB }); + + // Check default settings + assertTrue(containerA.getIncludeAllRequired()); + assertFalse(containerA.getIncludeAllEnvironments()); + assertFalse(containerA.getIncludeSource()); + assertTrue(containerB.getIncludeAllRequired()); + assertFalse(containerB.getIncludeAllEnvironments()); + assertFalse(containerB.getIncludeSource()); + + // Check basic changes + int flags = IUBundleContainer.INCLUDE_ALL_ENVIRONMENTS | IUBundleContainer.INCLUDE_SOURCE; + containerA = (IUBundleContainer) getTargetService().newIULocation(new IInstallableUnit[0], null, flags); + containerB = (IUBundleContainer) getTargetService().newIULocation(new String[] { "unit1", "unit2" }, + new String[] { "1.0", "2.0" }, null, flags); + target.setTargetLocations(new ITargetLocation[] { containerA, containerB }); + assertFalse(containerA.getIncludeAllRequired()); + assertTrue(containerA.getIncludeAllEnvironments()); + assertTrue(containerA.getIncludeSource()); + + // Check that all containers are updated in the target if target is + // passed as argument + flags = IUBundleContainer.INCLUDE_ALL_ENVIRONMENTS | IUBundleContainer.INCLUDE_SOURCE; + containerA = (IUBundleContainer) getTargetService().newIULocation(new IInstallableUnit[0], null, flags); + flags = IUBundleContainer.INCLUDE_REQUIRED; + containerB = (IUBundleContainer) getTargetService().newIULocation(new String[] { "unit1", "unit2" }, + new String[] { "1.0", "2.0" }, null, flags); + + target.setTargetLocations(new ITargetLocation[] { containerA, containerB }); + assertTrue(containerA.getIncludeAllRequired()); + assertFalse(containerA.getIncludeAllEnvironments()); + assertFalse(containerA.getIncludeSource()); + assertTrue(containerB.getIncludeAllRequired()); + assertFalse(containerB.getIncludeAllEnvironments()); + assertFalse(containerB.getIncludeSource()); + + // now switch the order of A and B + target.setTargetLocations(new ITargetLocation[] { containerB, containerA }); + assertFalse(containerA.getIncludeAllRequired()); + assertTrue(containerA.getIncludeAllEnvironments()); + assertTrue(containerA.getIncludeSource()); + assertFalse(containerB.getIncludeAllRequired()); + assertTrue(containerB.getIncludeAllEnvironments()); + assertTrue(containerB.getIncludeSource()); + } + + @Test + public void testNameVersionDescriptor() { + NameVersionDescriptor d1 = new NameVersionDescriptor("a.b.c", "1.0.0"); + NameVersionDescriptor d2 = new NameVersionDescriptor("a.b.c", "1.0.0"); + assertEquals(d1, d2); + + d1 = new NameVersionDescriptor("a.b.c", "1.0.0"); + d2 = new NameVersionDescriptor("a.b.c", "1.0.1"); + assertFalse(d1.equals(d2)); + + d1 = new NameVersionDescriptor("a.b.c", "1.0.0"); + d2 = new NameVersionDescriptor("a.b.e", "1.0.0"); + assertFalse(d1.equals(d2)); + + d1 = new NameVersionDescriptor("a.b.c", null); + d2 = new NameVersionDescriptor("a.b.c", null); + assertEquals(d1, d2); + + d1 = new NameVersionDescriptor("a.b.c", null); + d2 = new NameVersionDescriptor("a.b.e", null); + assertFalse(d1.equals(d2)); + + d1 = new NameVersionDescriptor("a.b.c", null); + d2 = new NameVersionDescriptor("a.b.c", "1.0.0"); + assertFalse(d1.equals(d2)); + + d1 = new NameVersionDescriptor("a.b.c", "1.0.0"); + d2 = new NameVersionDescriptor("a.b.c", null); + assertFalse(d1.equals(d2)); + } + @Test public void testMissingBundles() throws Exception { + PDETestCase.assumeRunningInStandaloneEclipseSDK(); + ITargetDefinition definition = getNewTarget(); ITargetLocation directoryContainer = getTargetService().newDirectoryLocation(TargetPlatform.getDefaultLocation() + "/plugins"); @@ -68,6 +437,8 @@ public void testMissingBundles() throws Exception { */ @Test public void testSourceBundleRecognition() throws Exception { + PDETestCase.assumeRunningInStandaloneEclipseSDK(); + ITargetDefinition definition = getNewTarget(); ITargetLocation directoryContainer = getTargetService().newDirectoryLocation(TargetPlatform.getDefaultLocation() + "/plugins"); @@ -108,6 +479,4 @@ public void testSourceBundleRecognition() throws Exception { } } - - } \ No newline at end of file diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/wizards/AllNewProjectMinimalTests.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/wizards/AllNewProjectMinimalTests.java deleted file mode 100644 index a1937e8e5b..0000000000 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/wizards/AllNewProjectMinimalTests.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016, 2017 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.pde.ui.tests.wizards; - -import org.eclipse.pde.ui.tests.ee.ExecutionEnvironmentTests; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * They run on minimal plugin bundles and dont require the whole SDK ( for - * hudson gerrit). This class is refactored out of AllNewProjectTests - * - */ -@RunWith(Suite.class) -@SuiteClasses({ NewFeatureProjectTestCase.class, NewSiteProjectTestCase.class, - // ConvertProjectToPluginTestCase.class, - ExecutionEnvironmentTests.class }) -public class AllNewProjectMinimalTests { - -} diff --git a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/wizards/ConvertProjectToPluginTestCase.java b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/wizards/ConvertProjectToPluginTestCase.java index 36417607ca..af94f5e56d 100644 --- a/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/wizards/ConvertProjectToPluginTestCase.java +++ b/ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/wizards/ConvertProjectToPluginTestCase.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2017 IBM Corporation and others. + * Copyright (c) 2007, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -27,6 +27,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin; import org.eclipse.pde.internal.core.natures.PDE; import org.eclipse.pde.internal.core.project.PDEProject; import org.eclipse.pde.internal.ui.wizards.tools.ConvertProjectToPluginOperation; @@ -43,7 +44,7 @@ public class ConvertProjectToPluginTestCase extends PDETestCase { private static String PROJECT_NAME_1 = "Foo"; private static String PROJECT_NAME_2 = "Bar"; - private final static String API_TOOLS_NATURE = "org.eclipse.pde.api.tools.apiAnalysisNature"; + private final static String API_TOOLS_NATURE = ApiPlugin.NATURE_ID; /** * Test the conversion of a single simple project.