140866 - import configuration should only save the changed files
added method to com[pare two method elements
diff --git a/plugins/org.eclipse.epf.import/src/org/eclipse/epf/importing/services/LibraryImportManager.java b/plugins/org.eclipse.epf.import/src/org/eclipse/epf/importing/services/LibraryImportManager.java
index 7ca5e5e..33cd35f 100755
--- a/plugins/org.eclipse.epf.import/src/org/eclipse/epf/importing/services/LibraryImportManager.java
+++ b/plugins/org.eclipse.epf.import/src/org/eclipse/epf/importing/services/LibraryImportManager.java
@@ -468,6 +468,19 @@
return;
}
+ // if content description, check if it's changed or not
+ if ( (oldObj instanceof ContentDescription) && (newObj instanceof ContentDescription) ) {
+ if ( LibraryUtil.isIdentical((ContentDescription)oldObj, (ContentDescription)newObj) ) {
+ if (debug ) {
+ Resource res = oldObj.eResource();
+ if ( res != null ) {
+ System.out.println("Identical element not replaced: " + res.getURI().toFileString() );
+ }
+ }
+ return;
+ }
+ }
+
// set repalced first to avoid calling into the same object recursively
setReplaced(oldObj);
@@ -483,7 +496,8 @@
//package structure is handled by the diff tree
// so we don't process the related feature
if ( feature == UmaPackage.eINSTANCE.getMethodPlugin_MethodPackages()
- || feature == UmaPackage.eINSTANCE.getMethodPackage_ChildPackages() )
+ || feature == UmaPackage.eINSTANCE.getMethodPackage_ChildPackages()
+ || feature.isDerived() )
{
continue;
}
@@ -969,7 +983,7 @@
// System.out.println("No resource for " + obj);
if (debug && res.isModified() ) {
- System.out.println("Modified: " + obj);
+ System.out.println("Modified: " + res.getURI().toFileString());
}
}
diff --git a/plugins/org.eclipse.epf.library/src/org/eclipse/epf/library/util/LibraryUtil.java b/plugins/org.eclipse.epf.library/src/org/eclipse/epf/library/util/LibraryUtil.java
index 83f04f4..c7b5b57 100755
--- a/plugins/org.eclipse.epf.library/src/org/eclipse/epf/library/util/LibraryUtil.java
+++ b/plugins/org.eclipse.epf.library/src/org/eclipse/epf/library/util/LibraryUtil.java
@@ -21,6 +21,7 @@
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.epf.library.LibraryResources;
@@ -408,4 +409,89 @@
}
return contained;
}
+
+ /**
+ * check if two method element are identical or not. Two elements are identical if and only if:
+ * all the attribute values are equal
+ * all the referenced elements are equal
+ * all the contained elements are identical
+ *
+ * @param oldObj MethodElement
+ * @param newObj MethodElement
+ * @return boolean
+ */
+ public static boolean isIdentical(MethodElement oldObj, MethodElement newObj) {
+
+ if ( (oldObj == null) && (newObj == null) ) {
+ return true;
+ }
+
+ if ( (oldObj == null) || (newObj == null) ) {
+ return false;
+ }
+
+ // this does not work, the toString contains the object instance info
+// return oldObj.toString().equals(newObj.toString());
+
+ List properties = oldObj.getInstanceProperties();
+ if (properties != null) {
+ for (int i = 0; i < properties.size(); i++) {
+ EStructuralFeature feature = (EStructuralFeature) properties.get(i);
+ Object oldValue = oldObj.eGet(feature);
+ Object newValue = newObj.eGet(feature);
+ if ( oldValue == null && newValue == null ) {
+ continue;
+ }
+
+ if ( oldValue == null || newValue == null ) {
+ return false;
+ }
+
+ if ( oldValue instanceof MethodElement ) {
+
+ // if it'c containment feature value, iterate it
+ MethodElement olde = (MethodElement)oldValue;
+ if ( olde.eContainer() == oldObj ) {
+ if ( !isIdentical(olde, (MethodElement)newValue) ) {
+ return false;
+ }
+ } else if ( oldValue != newValue ) {
+ return false;
+ }
+ } else if ( oldValue instanceof List ) {
+ List oldl = (List)oldValue;
+ List newl = (List)newValue;
+ if ( oldl.size() != newl.size() ) {
+ return false;
+ }
+
+ for ( int x = 0; x < oldl.size(); x++ ) {
+ Object o = oldl.get(x);
+ Object n = newl.get(x);
+ if ( o instanceof MethodElement) {
+ // if it'c containment feature value, iterate it
+ MethodElement olde = (MethodElement)o;
+ if ( olde.eContainer() == oldObj ) {
+ if ( !isIdentical(olde, (MethodElement)n) ) {
+ return false;
+ }
+ } else if ( oldValue != newValue ) {
+ return false;
+ }
+ } else {
+ if ( !o.equals(n) ) {
+ return false;
+ }
+ }
+ }
+ } else {
+ if ( !oldValue.equals(newValue) ) {
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+ }
}