Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ResourceAdapter.java11
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/org.eclipse.papyrus.infra.core.tests.launch85
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/resource/ResourceAdapterTest.java54
3 files changed, 83 insertions, 67 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ResourceAdapter.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ResourceAdapter.java
index de8f48b5dbd..454dc5ea26f 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ResourceAdapter.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ResourceAdapter.java
@@ -53,6 +53,7 @@ public abstract class ResourceAdapter extends AdapterImpl {
// Discover existing resources. Iterate the current set; any new additions
// will be discovered automatically
for (Resource next : ImmutableList.copyOf(((ResourceSet) newTarget).getResources())) {
+ addAdapter(next);
handleResourceAdded(next);
if (next.isLoaded()) {
handleResourceLoaded(next);
@@ -183,8 +184,8 @@ public abstract class ResourceAdapter extends AdapterImpl {
Object newValue = msg.getNewValue();
if (newValue instanceof Iterable<?>) {
for (Object next : (Iterable<?>) newValue) {
- handleRootAdded(resource, (EObject) next);
- }
+ handleRootAdded(resource, (EObject) next);
+ }
}
break;
}
@@ -199,8 +200,8 @@ public abstract class ResourceAdapter extends AdapterImpl {
Object oldValue = msg.getOldValue();
if (oldValue instanceof Iterable<?>) {
for (Object next : (Iterable<?>) oldValue) {
- handleRootRemoved(resource, (EObject) next);
- }
+ handleRootRemoved(resource, (EObject) next);
+ }
}
break;
}
@@ -213,9 +214,9 @@ public abstract class ResourceAdapter extends AdapterImpl {
}
break;
}
+ }
}
}
- }
protected void handleResourceAdded(Resource resource) {
// Pass
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/org.eclipse.papyrus.infra.core.tests.launch b/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/org.eclipse.papyrus.infra.core.tests.launch
index 570dd9717f8..4eb7c497ae3 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/org.eclipse.papyrus.infra.core.tests.launch
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/org.eclipse.papyrus.infra.core.tests.launch
@@ -1,42 +1,43 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<launchConfiguration type="org.eclipse.pde.ui.JunitLaunchConfig">
-<booleanAttribute key="append.args" value="true"/>
-<booleanAttribute key="askclear" value="false"/>
-<booleanAttribute key="automaticAdd" value="true"/>
-<booleanAttribute key="automaticValidate" value="false"/>
-<stringAttribute key="bootstrap" value=""/>
-<stringAttribute key="checked" value="[NONE]"/>
-<booleanAttribute key="clearConfig" value="true"/>
-<booleanAttribute key="clearws" value="true"/>
-<booleanAttribute key="clearwslog" value="false"/>
-<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/>
-<booleanAttribute key="default" value="true"/>
-<booleanAttribute key="includeOptional" value="true"/>
-<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/>
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
-<listEntry value="/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/tests/AllTests.java"/>
-</listAttribute>
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
-<listEntry value="1"/>
-</listAttribute>
-<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
-<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
-<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
-<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
-<stringAttribute key="org.eclipse.jdt.launching.JAVA_COMMAND" value="java"/>
-<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
-<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.papyrus.infra.core.tests.AllTests"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.papyrus.infra.core.tests"/>
-<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
-<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dosgi.requiredJavaVersion=1.5 -Xms768m -Xmx1024m -XX:PermSize=256M -XX:MaxPermSize=512M"/>
-<stringAttribute key="pde.version" value="3.3"/>
-<stringAttribute key="product" value="org.eclipse.platform.ide"/>
-<booleanAttribute key="run_in_ui_thread" value="true"/>
-<booleanAttribute key="show_selected_only" value="false"/>
-<booleanAttribute key="tracing" value="false"/>
-<booleanAttribute key="useCustomFeatures" value="false"/>
-<booleanAttribute key="useDefaultConfig" value="true"/>
-<booleanAttribute key="useDefaultConfigArea" value="false"/>
-<booleanAttribute key="useProduct" value="true"/>
-</launchConfiguration>
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.pde.ui.JunitLaunchConfig">
+<booleanAttribute key="append.args" value="true"/>
+<booleanAttribute key="askclear" value="false"/>
+<booleanAttribute key="automaticAdd" value="true"/>
+<booleanAttribute key="automaticValidate" value="false"/>
+<stringAttribute key="bootstrap" value=""/>
+<stringAttribute key="checked" value="[NONE]"/>
+<booleanAttribute key="clearConfig" value="true"/>
+<booleanAttribute key="clearws" value="true"/>
+<booleanAttribute key="clearwslog" value="false"/>
+<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/>
+<booleanAttribute key="default" value="true"/>
+<booleanAttribute key="includeOptional" value="true"/>
+<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/tests/AllTests.java"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
+<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
+<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
+<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
+<stringAttribute key="org.eclipse.jdt.launching.JAVA_COMMAND" value="java"/>
+<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.papyrus.infra.core.tests.AllTests"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.papyrus.infra.core.tests"/>
+<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dosgi.requiredJavaVersion=1.5 -Xms768m -Xmx1024m -XX:PermSize=256M -XX:MaxPermSize=512M"/>
+<stringAttribute key="pde.version" value="3.3"/>
+<stringAttribute key="product" value="org.eclipse.platform.ide"/>
+<booleanAttribute key="run_in_ui_thread" value="true"/>
+<booleanAttribute key="show_selected_only" value="false"/>
+<booleanAttribute key="tracing" value="false"/>
+<booleanAttribute key="useCustomFeatures" value="false"/>
+<booleanAttribute key="useDefaultConfig" value="true"/>
+<booleanAttribute key="useDefaultConfigArea" value="false"/>
+<booleanAttribute key="useProduct" value="true"/>
+</launchConfiguration>
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/resource/ResourceAdapterTest.java b/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/resource/ResourceAdapterTest.java
index b3d9ab3f8f0..9a78e1a355c 100644
--- a/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/resource/ResourceAdapterTest.java
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.infra.core.tests/test/org/eclipse/papyrus/infra/core/resource/ResourceAdapterTest.java
@@ -23,10 +23,11 @@ import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest;
-import org.junit.After;
+import org.eclipse.papyrus.junit.utils.rules.AbstractHouseKeeperRule.CleanUp;
+import org.eclipse.papyrus.junit.utils.rules.HouseKeeper;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import com.google.common.collect.ImmutableSet;
@@ -52,8 +53,12 @@ public class ResourceAdapterTest extends AbstractPapyrusTest {
private static final String RESOURCE_ROOT_REMOVED = "handleRootRemoved";
+ @Rule
+ public final HouseKeeper houseKeeper = new HouseKeeper();
+
private ResourceSet rset;
+ @CleanUp
private Fixture fixture;
public ResourceAdapterTest() {
@@ -143,32 +148,41 @@ public class ResourceAdapterTest extends AbstractPapyrusTest {
fixture.assertRoots(root);
}
+
+ @Test
+ public void testChangesInPreexistingResources_bug481151() {
+ // Need a different one than the usual, which already has the fixture attached
+ ResourceSet rset = houseKeeper.createResourceSet();
+
+ // A pre-existing resource
+ Resource resource = new ResourceImpl(URI.createURI("bogus://test"));
+ rset.getResources().add(resource);
+
+ rset.eAdapters().add(fixture);
+
+ // Consequence of initial discovery
+ fixture.assertHooks(RESOURCE_ADDED);
+ fixture.reset();
+
+ EObject newRoot = EcoreFactory.eINSTANCE.createEObject();
+ resource.getContents().add(newRoot);
+
+ // An unloaded resource becomes implicitly loaded when its contents are changed
+ fixture.assertHooks(RESOURCE_LOADED, RESOURCE_ROOT_ADDED);
+ }
+
//
// Test framework
//
@Before
public void createFixture() {
- rset = new ResourceSetImpl();
+ rset = houseKeeper.createResourceSet();
fixture = new Fixture();
rset.eAdapters().add(fixture);
}
- @After
- public void disposeFixture() {
- fixture = null;
-
- for(Resource next : rset.getResources()) {
- next.unload();
- next.eAdapters().clear();
- }
-
- rset.getResources().clear();
- rset.eAdapters().clear();
- rset = null;
- }
-
URI getTestResourceURI() {
// Doesn't matter the resource; this one's conveniently available
return URI.createURI(getClass().getResource("Bug402525.ecore").toExternalForm(), true);
@@ -195,15 +209,15 @@ public class ResourceAdapterTest extends AbstractPapyrusTest {
}
void assertResources(Resource... resources) {
- assertThat(this.resources, is((Set<Resource>)ImmutableSet.copyOf(resources)));
+ assertThat(this.resources, is((Set<Resource>) ImmutableSet.copyOf(resources)));
}
void assertHooks(String... hooks) {
- assertThat(this.hooksCalled, is((Set<String>)ImmutableSet.copyOf(hooks)));
+ assertThat(this.hooksCalled, is((Set<String>) ImmutableSet.copyOf(hooks)));
}
void assertRoots(EObject... objects) {
- assertThat(this.roots, is((Set<EObject>)ImmutableSet.copyOf(objects)));
+ assertThat(this.roots, is((Set<EObject>) ImmutableSet.copyOf(objects)));
}
void assertURIs(URI oldURI, URI newURI) {

Back to the top