diff options
| author | Reto Weiss | 2019-01-24 10:28:14 +0000 |
|---|---|---|
| committer | Reto Weiss | 2019-01-25 16:44:17 +0000 |
| commit | daf7fb70f33aa29ef831772534496a18291165d6 (patch) | |
| tree | 55972fa2e4e6b47042999c821df9479d08698dd6 | |
| parent | 5547c6a5177063b5f47e5e7215230298228c7723 (diff) | |
| download | eclipse.platform.resources-daf7fb70f33aa29ef831772534496a18291165d6.tar.gz eclipse.platform.resources-daf7fb70f33aa29ef831772534496a18291165d6.tar.xz eclipse.platform.resources-daf7fb70f33aa29ef831772534496a18291165d6.zip | |
Bug 543776 - provide the project as parameter instead of resolving it.I20190125-1800
Instead of getting the project with the name from the .project file from
the workspace root, provide the project as parameter directly to the
method getAllBuildConfigReferences of class ProjectDescription.
Add test ProjectDynamicReferencesTest for dynamicReference feature of
builder extension point.
Add regression test ProjectDynamicReferencesTest#testBug543776 for bug.
Signed-off-by: Reto Weiss <reto.weiss@axonivy.com>
Change-Id: Ia270fdae5269d1837381045f3346f6e6309867e1
10 files changed, 205 insertions, 19 deletions
diff --git a/bundles/org.eclipse.core.resources/META-INF/MANIFEST.MF b/bundles/org.eclipse.core.resources/META-INF/MANIFEST.MF index 79895a2b2..1ffe1db0c 100644 --- a/bundles/org.eclipse.core.resources/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.core.resources/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.core.resources; singleton:=true -Bundle-Version: 3.13.200.qualifier +Bundle-Version: 3.13.300.qualifier Bundle-Activator: org.eclipse.core.resources.ResourcesPlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.core.resources/pom.xml b/bundles/org.eclipse.core.resources/pom.xml index d166c278c..07b416528 100644 --- a/bundles/org.eclipse.core.resources/pom.xml +++ b/bundles/org.eclipse.core.resources/pom.xml @@ -19,6 +19,6 @@ </parent> <groupId>org.eclipse.core</groupId> <artifactId>org.eclipse.core.resources</artifactId> - <version>3.13.200-SNAPSHOT</version> + <version>3.13.300-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Project.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Project.java index c4e20cc51..0fbf98d19 100644 --- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Project.java +++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Project.java @@ -470,7 +470,7 @@ public class Project extends Container implements IProject { //if the project is currently in the middle of being created, the description might not be available yet if (description == null) checkAccessible(NULL_FLAG); - return description.getAllReferences(true); + return description.getAllReferences(this, true); } @Override @@ -499,7 +499,7 @@ public class Project extends Container implements IProject { ProjectDescription description = project.internalGetDescription(); if (description == null) continue; - IProject[] references = description.getAllReferences(false); + IProject[] references = description.getAllReferences(this, false); for (IProject reference : references) if (reference.equals(this)) { result.add(project); @@ -792,7 +792,7 @@ public class Project extends Container implements IProject { */ public IBuildConfiguration[] internalGetReferencedBuildConfigs(String configName, boolean includeMissing) { ProjectDescription description = internalGetDescription(); - IBuildConfiguration[] refs = description.getAllBuildConfigReferences(configName, false); + IBuildConfiguration[] refs = description.getAllBuildConfigReferences(this, configName, false); Collection<IBuildConfiguration> configs = new LinkedHashSet<>(refs.length); for (IBuildConfiguration ref : refs) { try { @@ -890,8 +890,8 @@ public class Project extends Container implements IProject { // get the children via the workspace since we know that this // resource exists (it is local). IResource[] children = getChildren(IResource.NONE); - for (int i = 0; i < children.length; i++) - if (!children[i].isLocal(depth)) + for (IResource element : children) + if (!element.isLocal(depth)) return false; return true; } diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectDescription.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectDescription.java index cea29da02..bd81623bd 100644 --- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectDescription.java +++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectDescription.java @@ -205,9 +205,9 @@ public class ProjectDescription extends ModelObject implements IProjectDescripti * Returns the union of the description's static and dynamic project references, * with duplicates omitted. The calculation is optimized by caching the result * Call the configuration based implementation. - * @see #getAllBuildConfigReferences(String, boolean) + * @see #getAllBuildConfigReferences(IProject, String, boolean) */ - public IProject[] getAllReferences(boolean makeCopy) { + public IProject[] getAllReferences(IProject project, boolean makeCopy) { int dirtyCount; IProject[] projRefs; @@ -221,12 +221,12 @@ public class ProjectDescription extends ModelObject implements IProjectDescripti while (projRefs == null) { IBuildConfiguration[] refs; if (hasBuildConfig(activeConfiguration)) - refs = getAllBuildConfigReferences(activeConfiguration, false); + refs = getAllBuildConfigReferences(project, activeConfiguration, false); else if (configNames.length > 0) - refs = getAllBuildConfigReferences(configNames[0], false); + refs = getAllBuildConfigReferences(project, configNames[0], false); else // No build configuration => fall-back to default - refs = getAllBuildConfigReferences(IBuildConfiguration.DEFAULT_CONFIG_NAME, false); + refs = getAllBuildConfigReferences(project, IBuildConfiguration.DEFAULT_CONFIG_NAME, false); Collection<IProject> l = getProjectsFromBuildConfigRefs(refs); synchronized (cachedRefsMutex) { @@ -254,14 +254,13 @@ public class ProjectDescription extends ModelObject implements IProjectDescripti * be resolved using {@link BuildConfiguration#getBuildConfig()} before use. * Returns an empty array if the given configName does not exist in the description. */ - public IBuildConfiguration[] getAllBuildConfigReferences(String configName, boolean makeCopy) { + public IBuildConfiguration[] getAllBuildConfigReferences(IProject project, String configName, boolean makeCopy) { if (!hasBuildConfig(configName)) return EMPTY_BUILD_CONFIG_REFERENCE_ARRAY; IBuildConfiguration[] refs = cachedConfigRefs.get(configName); if (refs == null) { Set<IBuildConfiguration> references = new LinkedHashSet<>(); IBuildConfiguration[] dynamicBuildConfigs = dynamicConfigRefs.containsKey(configName) ? dynamicConfigRefs.get(configName) : EMPTY_BUILD_CONFIG_REFERENCE_ARRAY; - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(getName()); Collection<BuildConfiguration> dynamic; try { IBuildConfiguration buildConfig = project.getBuildConfig(configName); diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java index c76cb3af3..f4c88453b 100644 --- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java +++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java @@ -676,7 +676,7 @@ public class Workspace extends PlatformObject implements IWorkspace, ICoreConsta if (desc == null) continue; //obtain both static and dynamic project references - IProject[] refs = desc.getAllReferences(false); + IProject[] refs = desc.getAllReferences(project, false); allAccessibleProjects.add(project); for (IProject ref : refs) { // ignore self references and references to projects that are not accessible @@ -1636,8 +1636,8 @@ public class Workspace extends PlatformObject implements IWorkspace, ICoreConsta for (IProject project : projects) { if (!project.isAccessible()) { continue; - } - IProject[] refs = ((Project)project).internalGetDescription().getReferencedProjects(false); + } + IProject[] refs = ((Project) project).internalGetDescription().getReferencedProjects(false); List<IProject> dangling = new ArrayList<>(refs.length); for (IProject ref : refs) { if (!ref.exists()) { diff --git a/tests/org.eclipse.core.tests.resources/META-INF/MANIFEST.MF b/tests/org.eclipse.core.tests.resources/META-INF/MANIFEST.MF index f6f6041ed..1a944cfaa 100644 --- a/tests/org.eclipse.core.tests.resources/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.core.tests.resources/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Eclipse Core Tests Resources Bundle-SymbolicName: org.eclipse.core.tests.resources; singleton:=true -Bundle-Version: 3.10.400.qualifier +Bundle-Version: 3.10.500.qualifier Bundle-Vendor: Eclipse.org Export-Package: org.eclipse.core.tests.filesystem, org.eclipse.core.tests.internal.alias, diff --git a/tests/org.eclipse.core.tests.resources/plugin.xml b/tests/org.eclipse.core.tests.resources/plugin.xml index 3944f3cac..386e23f56 100644 --- a/tests/org.eclipse.core.tests.resources/plugin.xml +++ b/tests/org.eclipse.core.tests.resources/plugin.xml @@ -629,4 +629,14 @@ </run> </builder> </extension> + <extension + id="dynamicProjectReferenceBuilder" + name="Dynamic Project Reference Builder" + point="org.eclipse.core.resources.builders"> + <builder> + <dynamicReference + class="org.eclipse.core.tests.internal.resources.ProjectDynamicReferencesTest$DynamicReferenceProvider"> + </dynamicReference> + </builder> + </extension> </plugin> diff --git a/tests/org.eclipse.core.tests.resources/pom.xml b/tests/org.eclipse.core.tests.resources/pom.xml index 3642e464d..f1c014fec 100644 --- a/tests/org.eclipse.core.tests.resources/pom.xml +++ b/tests/org.eclipse.core.tests.resources/pom.xml @@ -19,7 +19,7 @@ </parent> <groupId>org.eclipse.core</groupId> <artifactId>org.eclipse.core.tests.resources</artifactId> - <version>3.10.400-SNAPSHOT</version> + <version>3.10.500-SNAPSHOT</version> <packaging>eclipse-test-plugin</packaging> <properties> diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/AllTests.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/AllTests.java index cbd9df617..9a6bfb15c 100644 --- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/AllTests.java +++ b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/AllTests.java @@ -32,6 +32,7 @@ public class AllTests extends TestCase { suite.addTest(WorkspaceConcurrencyTest.suite()); suite.addTest(WorkspacePreferencesTest.suite()); suite.addTest(ProjectReferencesTest.suite()); + suite.addTest(ProjectDynamicReferencesTest.suite()); suite.addTest(ProjectBuildConfigsTest.suite()); return suite; } diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectDynamicReferencesTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectDynamicReferencesTest.java new file mode 100644 index 000000000..d9da71401 --- /dev/null +++ b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ProjectDynamicReferencesTest.java @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (c) 2010, 2015 Broadcom 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: + * Broadcom Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.core.tests.internal.resources; + +import java.util.*; +import junit.framework.Test; +import junit.framework.TestSuite; +import org.eclipse.core.resources.*; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.tests.resources.ResourceTest; + +/** + * Test project dynamic references provided by extension point + * <code>org.eclipse.core.resources.builders<code> and dynamicReference + * {@link IDynamicReferenceProvider} + */ +public class ProjectDynamicReferencesTest extends ResourceTest { + private static final String PROJECT_0_NAME = "ProjectDynamicReferencesTest_p0"; + + private static final IProject[] EMPTY_PROJECTS = new IProject[0]; + + private IProject project0; + private IProject project1; + private IProject project2; + + public static Test suite() { + return new TestSuite(ProjectDynamicReferencesTest.class); + } + + public ProjectDynamicReferencesTest(String name) { + super(name); + } + + @Override + public void setUp() throws Exception { + project0 = getWorkspace().getRoot().getProject(PROJECT_0_NAME); + project1 = getWorkspace().getRoot().getProject("ProjectDynamicReferencesTest_p1"); + project2 = getWorkspace().getRoot().getProject("ProjectDynamicReferencesTest_p2"); + ensureExistsInWorkspace(new IProject[] { project0, project1, project2 }, true); + addBuilder(project0); + addBuilder(project1); + addBuilder(project2); + } + + private static void addBuilder(IProject project) throws CoreException { + IProjectDescription description = project.getDescription(); + ICommand command = description.newCommand(); + command.setBuilderName(Builder.NAME); + description.setBuildSpec(new ICommand[] {command}); + project.setDescription(description, null); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + DynamicReferenceProvider.clear(); + project0.delete(true, null); + project1.delete(true, null); + project2.delete(true, null); + } + + public void testReferences() throws CoreException { + assertEquals("Project0 must not have referenced projects", EMPTY_PROJECTS, project0.getReferencedProjects()); + assertEquals("Project1 must not have referenced projects", EMPTY_PROJECTS, project1.getReferencedProjects()); + assertEquals("Project2 must not have referenced projects", EMPTY_PROJECTS, project2.getReferencedProjects()); + + DynamicReferenceProvider.addReference(project0, project1); + + assertEquals("Project0 must not have referenced projects", EMPTY_PROJECTS, project0.getReferencedProjects()); + assertEquals("Project1 must not have referenced projects", EMPTY_PROJECTS, project1.getReferencedProjects()); + assertEquals("Project2 must not have referenced projects", EMPTY_PROJECTS, project2.getReferencedProjects()); + + clearCache(); + + assertEquals("Project0 must reference Project1", new IProject[] { project1 }, project0.getReferencedProjects()); + assertEquals("Project1 must not have referenced projects", EMPTY_PROJECTS, project1.getReferencedProjects()); + assertEquals("Project2 must not have referenced projects", EMPTY_PROJECTS, project2.getReferencedProjects()); + + DynamicReferenceProvider.addReference(project1, project2); + + assertEquals("Project0 must reference Project1", new IProject[] { project1 }, project0.getReferencedProjects()); + assertEquals("Project1 must not have referenced projects", EMPTY_PROJECTS, project1.getReferencedProjects()); + assertEquals("Project2 must not have referenced projects", EMPTY_PROJECTS, project2.getReferencedProjects()); + + clearCache(); + + assertEquals("Project0 must reference Project1", new IProject[] { project1 }, project0.getReferencedProjects()); + assertEquals("Project1 must reference Project2", new IProject[] { project2 }, project1.getReferencedProjects()); + assertEquals("Project2 must not have referenced projects", EMPTY_PROJECTS, project2.getReferencedProjects()); + + DynamicReferenceProvider.addReference(project0, project2); + + assertEquals("Project0 must reference Project1", new IProject[] { project1 }, project0.getReferencedProjects()); + assertEquals("Project1 must reference Project2", new IProject[] { project2 }, project1.getReferencedProjects()); + assertEquals("Project2 must not have referenced projects", EMPTY_PROJECTS, project2.getReferencedProjects()); + + clearCache(); + + assertEquals("Project0 must reference Project1 and Project2", new IProject[] { project1, project2 }, + project0.getReferencedProjects()); + assertEquals("Project1 must reference Project2", new IProject[] { project2 }, + project1.getReferencedProjects()); + assertEquals("Project2 must not have referenced projects", EMPTY_PROJECTS, project2.getReferencedProjects()); + } + + public void testBug543776() throws CoreException { + IFile projectFile = project0.getFile(IProjectDescription.DESCRIPTION_FILE_NAME); + String projectDescription = readStringInFileSystem(projectFile); + projectDescription = projectDescription.replace(PROJECT_0_NAME, "anotherName"); + ensureExistsInWorkspace(projectFile, projectDescription); + project0.delete(false, true, null); + project0.create(null); + project0.open(null); + + assertEquals(PROJECT_0_NAME, project0.getName()); + assertEquals("anotherName", project0.getDescription().getName()); + + DynamicReferenceProvider.addReference(project0, project1); + clearCache(); + + assertEquals("Project0 must reference Project1", new IProject[] { project1 }, project0.getReferencedProjects()); + } + + private void clearCache() { + project0.clearCachedDynamicReferences(); + project1.clearCachedDynamicReferences(); + project2.clearCachedDynamicReferences(); + } + + public static final class Builder extends IncrementalProjectBuilder { + + public static final String NAME = "org.eclipse.core.tests.resources.dynamicProjectReferenceBuilder"; + + @Override + protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException { + return null; + } + + } + + public static final class DynamicReferenceProvider implements IDynamicReferenceProvider + { + private static final Map<IProject, List<IProject>> dependentProjects = new HashMap<>(); + + @Override + public List<IProject> getDependentProjects(IBuildConfiguration buildConfiguration) throws CoreException { + IProject project = buildConfiguration.getProject(); + List<IProject> depProjects = dependentProjects.get(project); + if (depProjects != null) { + return depProjects; + } + return Collections.emptyList(); + } + + public static void addReference(IProject project, IProject dependentProject) { + List<IProject> depProjects = dependentProjects.computeIfAbsent(project, proj -> new ArrayList<>()); + depProjects.add(dependentProject); + } + + public static void clear() { + dependentProjects.clear(); + } + } +} |
