Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2021-02-25 20:21:56 +0000
committerPatrick Tessier2021-04-12 09:24:53 +0000
commit37d4082befff96b267d44a145687fd43e238e80d (patch)
tree95af399489a923567307ac436bcf1005611e1a62
parent5f60acc76eb5f16c35933809251f32349a5d5e62 (diff)
downloadorg.eclipse.papyrus-37d4082befff96b267d44a145687fd43e238e80d.tar.gz
org.eclipse.papyrus-37d4082befff96b267d44a145687fd43e238e80d.tar.xz
org.eclipse.papyrus-37d4082befff96b267d44a145687fd43e238e80d.zip
Bug 539694: The Architecture models raises bad errors
- fix case of workspace-wide JDT search without context URI broken by earlier fix - ensure that JDT and Java projects are ready when running tests with Maven Change-Id: If65d2334ee653286d8ddbed01765093135893ba5 Signed-off-by: Christian W. Damus <give.a.damus@gmail.com>
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/ClasspathHelper.java13
-rw-r--r--tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/AbstractHouseKeeperRule.java18
-rw-r--r--tests/junit/plugins/infra/org.eclipse.papyrus.infra.tools.tests/META-INF/MANIFEST.MF3
-rw-r--r--tests/junit/plugins/infra/org.eclipse.papyrus.infra.tools.tests/src/org/eclipse/papyrus/infra/tools/util/ClasspathHelperTest.java78
4 files changed, 86 insertions, 26 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/ClasspathHelper.java b/plugins/infra/core/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/ClasspathHelper.java
index da56edf377a..9eee290a6c9 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/ClasspathHelper.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/ClasspathHelper.java
@@ -92,9 +92,16 @@ public class ClasspathHelper {
IJavaProject project = getJavaProject(context);
if (project == null) {
- // This search is not in a Java project context. So, it's a run-time environment
- // and we need to search the classpath.
- result = super.findClass(name, context, constraint);
+ if (context == null) {
+ // No specific source context? Try to search the entire workspace, then
+ result = searchType(name, constraint);
+ }
+
+ if (result == null) {
+ // Assume that this search is not in a Java project context. So, it's a
+ // run-time environment and we need to search the classpath.
+ result = super.findClass(name, context, constraint);
+ }
} else {
result = findType(project, name, constraint);
}
diff --git a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/AbstractHouseKeeperRule.java b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/AbstractHouseKeeperRule.java
index 898287793e0..a12a2c3b54e 100644
--- a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/AbstractHouseKeeperRule.java
+++ b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/AbstractHouseKeeperRule.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2015 CEA, Christian W. Damus, and others.
+ * Copyright (c) 2014, 2021 CEA, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,7 +10,7 @@
*
* Contributors:
* Christian W. Damus (CEA) - Initial API and implementation
- * Christian W. Damus - bug 476683
+ * Christian W. Damus - bugs 476683, 539694
*
*/
package org.eclipse.papyrus.junit.utils.rules;
@@ -95,7 +95,7 @@ public abstract class AbstractHouseKeeperRule {
// This one must be last because it matches any object
ReflectiveDisposer.register(disposers);
- DISPOSER_FUNCTION = new Function<Object, Disposer<Object>>() {
+ DISPOSER_FUNCTION = new Function<>() {
private final Function<Object, Disposer<?>> nullFunction = Functions.constant(null);
@@ -295,7 +295,7 @@ public abstract class AbstractHouseKeeperRule {
*/
public IMultiDiagramEditor openPapyrusEditor(final IFile file) throws Exception {
final IMultiDiagramEditor[] result = { null };
- final AtomicReference<Exception> syncExecException = new AtomicReference<Exception>();
+ final AtomicReference<Exception> syncExecException = new AtomicReference<>();
Display.getDefault().syncExec(new Runnable() {
@@ -323,7 +323,7 @@ public abstract class AbstractHouseKeeperRule {
* the field to access now and clear later
*
* @return the value of the field
- *
+ *
* @deprecated Use the {@link CleanUp @CleanUp} annotation on the field and access it directly.
*/
@Deprecated
@@ -373,7 +373,7 @@ public abstract class AbstractHouseKeeperRule {
* the value to set
*
* @return the new value of the field
- *
+ *
* @deprecated Use the {@link CleanUp @CleanUp} annotation on the field and access it directly.
*/
@Deprecated
@@ -490,7 +490,7 @@ public abstract class AbstractHouseKeeperRule {
}
private static CacheLoader<Class<?>, Field[]> fieldCacheLoader(final boolean staticFields) {
- return new CacheLoader<Class<?>, Field[]>() {
+ return new CacheLoader<>() {
@Override
public Field[] load(Class<?> key) {
@@ -539,7 +539,7 @@ public abstract class AbstractHouseKeeperRule {
* up the annotated field. By default, the field is simply
* cleared to {@code null}.
*/
- Class<? extends Disposer<?>>value() default FieldDisposer.class;
+ Class<? extends Disposer<?>> value() default FieldDisposer.class;
}
private static final class CleanUpAction implements Runnable {
@@ -627,7 +627,7 @@ public abstract class AbstractHouseKeeperRule {
case IResource.PROJECT:
case IResource.FOLDER:
case IResource.FILE:
- object.delete(true, null);
+ object.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, null);
break;
default:
// Delete the workspace? No, I don't think so
diff --git a/tests/junit/plugins/infra/org.eclipse.papyrus.infra.tools.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/infra/org.eclipse.papyrus.infra.tools.tests/META-INF/MANIFEST.MF
index eca328c54c0..0549e4697ee 100644
--- a/tests/junit/plugins/infra/org.eclipse.papyrus.infra.tools.tests/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/infra/org.eclipse.papyrus.infra.tools.tests/META-INF/MANIFEST.MF
@@ -6,7 +6,8 @@ Require-Bundle: org.eclipse.core.databinding.beans;bundle-version="[1.6.0,2.0.0)
org.eclipse.papyrus.junit.utils;bundle-version="[3.0.0,4.0.0)",
org.junit;bundle-version="[4.13.0,5.0.0)",
org.eclipse.core.resources;bundle-version="[3.13.900,4.0.0)",
- org.eclipse.core.runtime;bundle-version="[3.20.0,4.0.0)"
+ org.eclipse.core.runtime;bundle-version="[3.20.0,4.0.0)",
+ org.eclipse.jdt.core;bundle-version="[3.24.0,4.0.0)"
Export-Package: org.eclipse.papyrus.infra.tools.databinding,
org.eclipse.papyrus.infra.tools.tests,
org.eclipse.papyrus.infra.tools.util
diff --git a/tests/junit/plugins/infra/org.eclipse.papyrus.infra.tools.tests/src/org/eclipse/papyrus/infra/tools/util/ClasspathHelperTest.java b/tests/junit/plugins/infra/org.eclipse.papyrus.infra.tools.tests/src/org/eclipse/papyrus/infra/tools/util/ClasspathHelperTest.java
index ed321862547..4a03cab68cb 100644
--- a/tests/junit/plugins/infra/org.eclipse.papyrus.infra.tools.tests/src/org/eclipse/papyrus/infra/tools/util/ClasspathHelperTest.java
+++ b/tests/junit/plugins/infra/org.eclipse.papyrus.infra.tools.tests/src/org/eclipse/papyrus/infra/tools/util/ClasspathHelperTest.java
@@ -24,17 +24,32 @@ import java.io.IOException;
import java.io.Serializable;
import java.net.URISyntaxException;
import java.net.URL;
+import java.nio.file.FileAlreadyExistsException;
+import java.nio.file.FileVisitOption;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.StandardCopyOption;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.EnumSet;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
-import org.junit.AfterClass;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.papyrus.junit.utils.rules.AbstractHouseKeeperRule.CleanUp;
+import org.eclipse.papyrus.junit.utils.rules.HouseKeeper;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
import org.osgi.framework.FrameworkUtil;
@@ -53,7 +68,12 @@ public class ClasspathHelperTest {
private static final URI PROJECT2_CONTEXT = URI.createPlatformResourceURI(PROJECT2 + "/other/resource.xmi", true);
+ @ClassRule
+ public static final HouseKeeper.Static housekeeper = new HouseKeeper.Static();
+
+ @CleanUp
private static IProject project1;
+ @CleanUp
private static IProject project2;
@Test
@@ -110,26 +130,58 @@ public class ClasspathHelperTest {
@BeforeClass
public static void importProjects() throws URISyntaxException, CoreException, IOException {
- project1 = importProject(PROJECT1);
- project2 = importProject(PROJECT2);
- }
+ project1 = housekeeper.cleanUpLater(importProject(PROJECT1));
+ project2 = housekeeper.cleanUpLater(importProject(PROJECT2));
- @AfterClass
- public static void destroyProjects() throws CoreException {
- project2.delete(false, true, null);
- project1.delete(false, true, null);
+ JavaCore.rebuildIndex(null);
}
private static IProject importProject(String name) throws URISyntaxException, CoreException, IOException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject result = workspace.getRoot().getProject(name);
- IProjectDescription desc = workspace.newProjectDescription(name);
+ // Copy the contents of the template into the project
+ java.nio.file.Path location = result.getParent().getLocation().append(name).toFile().toPath();
URL url = FileLocator.find(FrameworkUtil.getBundle(ClasspathHelperTest.class), new Path("resources/projects/" + name));
- url = FileLocator.toFileURL(url);
- desc.setLocationURI(url.toURI());
- result.create(desc, null);
+ java.nio.file.Path path = Paths.get(FileLocator.toFileURL(url).toURI());
+ Files.walkFileTree(path, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
+ new SimpleFileVisitor<java.nio.file.Path>() {
+ @Override
+ public FileVisitResult preVisitDirectory(java.nio.file.Path dir, BasicFileAttributes attrs)
+ throws IOException {
+
+ java.nio.file.Path targetDir = location.resolve(path.relativize(dir));
+ try {
+ Files.copy(dir, targetDir);
+ } catch (FileAlreadyExistsException e) {
+ if (!Files.isDirectory(targetDir)) {
+ throw e;
+ }
+ }
+
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult visitFile(java.nio.file.Path file, BasicFileAttributes attrs)
+ throws IOException {
+
+ java.nio.file.Path targetFile = location.resolve(path.relativize(file));
+ Files.copy(file, targetFile, StandardCopyOption.REPLACE_EXISTING); // e.g., .project
+
+ return FileVisitResult.CONTINUE;
+ }
+ });
+
+ result.create(null);
result.open(null);
+ result.refreshLocal(IResource.DEPTH_INFINITE, null);
+
+ IJavaProject javaProject = JavaCore.create(result);
+ if (javaProject.exists()) {
+ javaProject.makeConsistent(new NullProgressMonitor());
+ }
+ result.build(IncrementalProjectBuilder.FULL_BUILD, null);
return result;
}

Back to the top