Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Pascual2014-09-18 16:07:23 +0000
committerRemi Schnekenburger2014-12-08 07:56:24 +0000
commit43c6ffbae7d1c4e586f15d2e1a489a6649cb048b (patch)
tree83491b7b4610c94f55d628d600e6deefa5405eb9 /plugins/infra/core
parenta86fc5f729ea042f3986ba291d13f2289b060305 (diff)
downloadorg.eclipse.papyrus-43c6ffbae7d1c4e586f15d2e1a489a6649cb048b.tar.gz
org.eclipse.papyrus-43c6ffbae7d1c4e586f15d2e1a489a6649cb048b.tar.xz
org.eclipse.papyrus-43c6ffbae7d1c4e586f15d2e1a489a6649cb048b.zip
436952: [Submodel] Deletion of a model fragment does not delete the
model fragment resources https://bugs.eclipse.org/bugs/show_bug.cgi?id=436952 - Control model Request : Check if the new resource have to replace a previous resource (i.e. its state is "deleted on save") - Add management of the next deleted resource's referencings during save action Change-Id: I1a240c6492d1834994a43a1a1237f4fadfc05807 Signed-off-by: Gabriel Pascual <gabriel.pascual@all4tec.net>
Diffstat (limited to 'plugins/infra/core')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModel.java15
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/EMFLogicalModel.java297
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/IModel.java10
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java11
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/additional/AdditionalResourcesModel.java39
5 files changed, 243 insertions, 129 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModel.java
index cd984f9b525..4d9940c47a5 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModel.java
@@ -8,12 +8,15 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 436952
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.resource;
import java.util.List;
+import java.util.Set;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.ResourceSet;
/**
@@ -118,4 +121,16 @@ public abstract class AbstractModel implements IModel {
public boolean isModelFor(Object element) {
return false;
}
+
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.resource.IModel#cleanModel(java.util.Set)
+ *
+ * @param toDeleteOnSave
+ */
+ @Override
+ public void cleanModel(Set<URI> resourcesToDelete) {
+ // Nothing to do
+
+ }
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/EMFLogicalModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/EMFLogicalModel.java
index 9ee222ffaca..123cc50a34b 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/EMFLogicalModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/EMFLogicalModel.java
@@ -1,128 +1,169 @@
-/*****************************************************************************
- * Copyright (c) 2013, 2014 CEA LIST, 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 v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- * Christian W. Damus (CEA) - bug 437052
- * Christian W. Damus - bug 399859
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.core.resource;
-
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.papyrus.infra.core.Activator;
-
-/**
- * An IModel which is an abstraction for a set of consistent EMF Resources
- *
- * @author Camille Letavernier
- *
- */
-public abstract class EMFLogicalModel extends AbstractBaseModel implements IEMFModel {
-
- protected final Set<Resource> resources = new HashSet<Resource>();
-
- public Set<Resource> getResources() {
- pruneDeletedResources();
- return resources;
- }
-
- protected void pruneDeletedResources() {
- ResourceSet rset = getModelManager();
- for (Iterator<Resource> iter = resources.iterator(); iter.hasNext();) {
- if (iter.next().getResourceSet() != rset) {
- // This resource was deleted
- iter.remove();
- }
- }
- }
-
- @Override
- protected void configureResource(Resource resourceToConfigure) {
- super.configureResource(resourceToConfigure);
- if (resourceToConfigure != null) {
- resources.add(resourceToConfigure);
- }
- }
-
- protected boolean isRelatedResource(Resource resource) {
- if (resource == null) {
- return false;
- }
-
- return resource.getURI().fileExtension().equals(getModelFileExtension());
- }
-
- @Override
- public void saveModel() throws IOException {
- final ModelSet set = getModelManager();
-
- for (Resource resource : getResources()) {
- if (set.shouldSave(resource)) {
- try {
- resource.save(null);
- } catch (IOException ex) {
- // If an exception occurs, we should not prevent other resources from being saved.
- // This would probably make things even worse. Catch and log.
- Activator.log.error(ex);
- }
- }
- }
- }
-
- @Override
- public void handle(Resource resource) {
- if (isRelatedResource(resource)) {
- configureResource(resource);
- }
- }
-
- @Override
- public void unload() {
- super.unload();
- getResources().clear();
- }
-
- @Override
- public void setModelURI(URI uriWithoutExtension) {
- for (Resource resource : getResources()) {
- if (isControlled(resource)) {
- updateURI(resource, uriWithoutExtension);
- }
- }
- super.setModelURI(uriWithoutExtension);
- }
-
- protected void updateURI(Resource resource, URI uriWithoutExtension) {
- URI oldBaseURI = this.resource.getURI();
- URI newBaseURI = uriWithoutExtension.appendFileExtension(getModelFileExtension());
-
- URI currentFullURI = resource.getURI();
- URI currentRelativeURI = currentFullURI.deresolve(oldBaseURI);
- URI newFullURI = currentRelativeURI.resolve(newBaseURI);
-
- resource.setURI(newFullURI);
- }
-
- @Override
- public boolean isModelFor(Object element) {
- if (element instanceof EObject) {
- return resources.contains(((EObject) element).eResource());
- }
- return resources.contains(element);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013, 2014 CEA LIST, 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 437052
+ * Christian W. Damus - bug 399859
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 436952
+ *
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.resource;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.papyrus.infra.core.Activator;
+
+/**
+ * An IModel which is an abstraction for a set of consistent EMF Resources
+ *
+ * @author Camille Letavernier
+ *
+ */
+public abstract class EMFLogicalModel extends AbstractBaseModel implements IEMFModel {
+
+ protected final Set<Resource> resources = new HashSet<Resource>();
+
+ public Set<Resource> getResources() {
+ pruneDeletedResources();
+ return resources;
+ }
+
+ protected void pruneDeletedResources() {
+ ResourceSet rset = getModelManager();
+ for (Iterator<Resource> iter = resources.iterator(); iter.hasNext();) {
+ if (iter.next().getResourceSet() != rset) {
+ // This resource was deleted
+ iter.remove();
+ }
+ }
+ }
+
+ @Override
+ protected void configureResource(Resource resourceToConfigure) {
+ super.configureResource(resourceToConfigure);
+ if (resourceToConfigure != null) {
+ resources.add(resourceToConfigure);
+ }
+ }
+
+ protected boolean isRelatedResource(Resource resource) {
+ if (resource == null) {
+ return false;
+ }
+
+ return resource.getURI().fileExtension().equals(getModelFileExtension());
+ }
+
+ @Override
+ public void saveModel() throws IOException {
+ final ModelSet set = getModelManager();
+
+ for (Resource resource : getResources()) {
+ if (set.shouldSave(resource)) {
+ try {
+ resource.save(null);
+ } catch (IOException ex) {
+ // If an exception occurs, we should not prevent other resources from being saved.
+ // This would probably make things even worse. Catch and log.
+ Activator.log.error(ex);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void handle(Resource resource) {
+ if (isRelatedResource(resource)) {
+ configureResource(resource);
+ }
+ }
+
+ @Override
+ public void unload() {
+ super.unload();
+ getResources().clear();
+ }
+
+ @Override
+ public void setModelURI(URI uriWithoutExtension) {
+ for (Resource resource : getResources()) {
+ if (isControlled(resource)) {
+ updateURI(resource, uriWithoutExtension);
+ }
+ }
+ super.setModelURI(uriWithoutExtension);
+ }
+
+ protected void updateURI(Resource resource, URI uriWithoutExtension) {
+ URI oldBaseURI = this.resource.getURI();
+ URI newBaseURI = uriWithoutExtension.appendFileExtension(getModelFileExtension());
+
+ URI currentFullURI = resource.getURI();
+ URI currentRelativeURI = currentFullURI.deresolve(oldBaseURI);
+ URI newFullURI = currentRelativeURI.resolve(newBaseURI);
+
+ resource.setURI(newFullURI);
+ }
+
+ @Override
+ public boolean isModelFor(Object element) {
+ if (element instanceof EObject) {
+ return resources.contains(((EObject) element).eResource());
+ }
+ return resources.contains(element);
+ }
+
+ /**
+ * Clean model.
+ *
+ * @param resourcesToDelete
+ * the resource to delete
+ * @see org.eclipse.papyrus.infra.core.resource.IModel#cleanModel(java.util.Set)
+ */
+ @Override
+ public void cleanModel(Set<URI> resourcesToDelete) {
+
+ if (!resourcesToDelete.isEmpty()) {
+
+ // Initialise exploration
+ Iterator<Resource> modelResourcesIterator = getResources().iterator();
+ List<Resource> referencedDeletedResources = new ArrayList<Resource>();
+
+ while (modelResourcesIterator.hasNext()) {
+
+ // Verify if current resource will be deleted
+ Resource currentResource = modelResourcesIterator.next();
+ if (resourcesToDelete.contains(currentResource.getURI())) {
+
+ referencedDeletedResources.add(currentResource);
+ }
+
+ }
+
+ // Remove all bad references
+ if (!referencedDeletedResources.isEmpty()) {
+ getResources().removeAll(referencedDeletedResources);
+ }
+
+
+ }
+
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/IModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/IModel.java
index 09e5825e8fb..2e4d9ed0ca3 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/IModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/IModel.java
@@ -10,6 +10,8 @@
* Contributors:
* CEA LIST - Initial API and implementation
* Christian W. Damus (CEA) - manage models by URI, not IFile (CDO)
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 436952
+ *
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.resource;
@@ -194,4 +196,12 @@ public interface IModel {
* @return
*/
public boolean isModelFor(Object element);
+
+ /**
+ * Clean model of deleted or uncontrolled references.
+ *
+ * @param resourcesToDelete
+ * the to delete on save
+ */
+ public void cleanModel(Set<URI> resourcesToDelete);
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java
index 3ef7414db4c..152d35d96c7 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java
@@ -17,6 +17,7 @@
* Christian W. Damus (CEA) - bug 429826
* Christian W. Damus (CEA) - bug 432813
* Christian W. Damus (CEA) - bug 437052
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 436952
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.resource;
@@ -752,6 +753,10 @@ public class ModelSet extends ResourceSetImpl {
for (IModel model : modelList) {
try {
if (!(model instanceof AdditionalResourcesModel)) {
+
+ // Bug 436952 : Clean referenced resources by models
+ model.cleanModel(getResourcesToDeleteOnSave());
+
model.saveModel();
monitor.worked(1);
}
@@ -762,6 +767,7 @@ public class ModelSet extends ResourceSetImpl {
}
}
try {
+ additional.cleanModel(getResourcesToDeleteOnSave());
additional.saveModel();
} catch (Exception ex) {
Activator.log.error(ex);
@@ -774,6 +780,8 @@ public class ModelSet extends ResourceSetImpl {
}
}
+
+
/**
* @return {@link ModelSet#toDeleteOnSave}
*/
@@ -790,6 +798,7 @@ public class ModelSet extends ResourceSetImpl {
URI uri = uriIterator.next();
if (validateDeleteResource(uri)) {
+
if (deleteResource(uri)) {
uriIterator.remove();
}
@@ -1162,7 +1171,7 @@ public class ModelSet extends ResourceSetImpl {
}
break;
case Notification.REMOVE:
- object = notification.getNewValue();
+ object = notification.getOldValue();
if (object instanceof Resource) {
resourcesToLoadState.remove((object));
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/additional/AdditionalResourcesModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/additional/AdditionalResourcesModel.java
index 2b0415ad04d..825ea8c04fb 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/additional/AdditionalResourcesModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/additional/AdditionalResourcesModel.java
@@ -12,13 +12,18 @@
* Christian W. Damus (CEA) - manage models by URI, not IFile (CDO)
* Christian W. Damus (CEA LIST) - support control mode in CDO resources
* Christian W. Damus (CEA) - bug 437052
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 436952
+ *
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.resource.additional;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.IPath;
@@ -156,4 +161,38 @@ public class AdditionalResourcesModel extends AbstractModel implements IModel {
return res;
}
+ /**
+ * @see org.eclipse.papyrus.infra.core.resource.AbstractModel#cleanModel(java.util.Set)
+ *
+ * @param resourcesToDelete
+ */
+ @Override
+ public void cleanModel(Set<URI> resourcesToDelete) {
+ if (!resourcesToDelete.isEmpty()) {
+
+ // Initialise exploration
+ Iterator<Resource> modelResourcesIterator = modelSet.getResources().iterator();
+ List<Resource> referencedDeletedResources = new ArrayList<Resource>();
+
+ while (modelResourcesIterator.hasNext()) {
+
+ // Verify if current resource will be deleted
+ Resource currentResource = modelResourcesIterator.next();
+ if (resourcesToDelete.contains(currentResource.getURI())) {
+
+ referencedDeletedResources.add(currentResource);
+ }
+
+ }
+
+ // Remove all bad references
+ if (!referencedDeletedResources.isEmpty()) {
+ modelSet.getResources().removeAll(referencedDeletedResources);
+ }
+
+
+ }
+
+ }
+
}

Back to the top