summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-28 03:39:17 (EDT)
committerEike Stepper2007-09-28 03:39:17 (EDT)
commit9b2828b6b8b23cd6e6630fa220c288de1ab598b3 (patch)
tree97ab88b5e90d34342d6d5015fb7d2b59154d5fde
parentc72136e8f9956643bf88c941b1710dca4c50187d (diff)
downloadcdo-9b2828b6b8b23cd6e6630fa220c288de1ab598b3.zip
cdo-9b2828b6b8b23cd6e6630fa220c288de1ab598b3.tar.gz
cdo-9b2828b6b8b23cd6e6630fa220c288de1ab598b3.tar.bz2
[204886] Don't commit unused packages
https://bugs.eclipse.org/bugs/show_bug.cgi?id=204886
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java35
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CompletePackageClosure.java166
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CrossReferencesPackageClosure.java (renamed from plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/EMFPackageClosure.java)8
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/InstancePackageClosure.java166
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/PackageClosure.java3
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/TraversingPackageClosure.java136
6 files changed, 363 insertions, 151 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
index 03fb795..4728355 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
@@ -23,11 +23,11 @@ import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.cdo.protocol.util.TransportException;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.internal.cdo.bundle.OM;
import org.eclipse.emf.internal.cdo.protocol.CommitTransactionRequest;
import org.eclipse.emf.internal.cdo.protocol.CommitTransactionResult;
-import org.eclipse.emf.internal.cdo.util.EMFPackageClosure;
import org.eclipse.emf.internal.cdo.util.ModelUtil;
import org.eclipse.net4j.IChannel;
@@ -283,32 +283,45 @@ public class CDOTransactionImpl extends CDOViewImpl implements CDOTransaction
private List<CDOPackage> analyzeNewPackages(CDOSessionImpl session)
{
- Set<EPackage> ePackages = new HashSet<EPackage>();
+ // Find all used classes and their super classes
+ Set<EClass> usedClasses = new HashSet<EClass>();
for (CDOObject object : newObjects.values())
{
- ePackages.add(object.eClass().getEPackage());
+ EClass usedClass = object.eClass();
+ if (usedClasses.add(usedClass))
+ {
+ for (EClass superType : usedClass.getEAllSuperTypes())
+ {
+ usedClasses.add(superType);
+ }
+ }
}
- // Find all indirectly referenced EPackages as well
- ePackages = new EMFPackageClosure().calculate(ePackages);
+ // Calculate the packages of the used classes
+ Set<EPackage> usedPackages = new HashSet<EPackage>();
+ for (EClass usedClass : usedClasses)
+ {
+ usedPackages.add(usedClass.getEPackage());
+ }
+ // Determine which of the used packages are new
CDOSessionPackageManager packageManager = session.getPackageManager();
- List<CDOPackage> cdoPackages = new ArrayList<CDOPackage>();
- for (EPackage ePackage : ePackages)
+ List<CDOPackage> newPackages = new ArrayList<CDOPackage>();
+ for (EPackage usedPackage : usedPackages)
{
- CDOPackageImpl cdoPackage = ModelUtil.getCDOPackage(ePackage, packageManager);
+ CDOPackageImpl cdoPackage = ModelUtil.getCDOPackage(usedPackage, packageManager);
if (cdoPackage == null)
{
- throw new IllegalStateException("Missing CDO package: " + ePackage.getNsURI());
+ throw new IllegalStateException("Missing CDO package: " + usedPackage.getNsURI());
}
if (!cdoPackage.isPersistent() && !cdoPackage.isSystem())
{
- cdoPackages.add(cdoPackage);
+ newPackages.add(cdoPackage);
}
}
- return cdoPackages;
+ return newPackages;
}
@SuppressWarnings("unchecked")
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CompletePackageClosure.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CompletePackageClosure.java
new file mode 100644
index 0000000..419863e
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CompletePackageClosure.java
@@ -0,0 +1,166 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.util;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EGenericType;
+import org.eclipse.emf.ecore.EOperation;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EParameter;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.ETypeParameter;
+import org.eclipse.emf.internal.cdo.bundle.OM;
+
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public class CompletePackageClosure extends PackageClosure
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_MODEL, CompletePackageClosure.class);
+
+ public CompletePackageClosure()
+ {
+ }
+
+ @Override
+ protected void collectContents(EPackage ePackage, Set<EPackage> visited)
+ {
+ Set<EClass> classes = new HashSet<EClass>();
+ List<EClassifier> classifiers = ePackage.getEClassifiers();
+ for (EClassifier classifier : classifiers)
+ {
+ handleEClassifier(classifier, classes);
+ }
+
+ for (EClass eClass : classes)
+ {
+ final EPackage p = eClass.getEPackage();
+ if (p != null)
+ {
+ if (visited.add(p))
+ {
+ if (TRACER.isEnabled()) TRACER.trace("Found package " + p.getNsURI());
+ }
+ }
+ else
+ {
+ OM.LOG.warn("Package == null for " + eClass.getName());
+ }
+ }
+ }
+
+ protected void handleEClassifiers(List<EClassifier> classifiers, Set<EClass> visited)
+ {
+ for (EClassifier classifier : classifiers)
+ {
+ handleEClassifier(classifier, visited);
+ }
+ }
+
+ protected void handleEClassifier(EClassifier classifier, Set<EClass> visited)
+ {
+ if (classifier instanceof EClass)
+ {
+ handleEClass((EClass)classifier, visited);
+ }
+ }
+
+ protected void handleEClasses(List<EClass> classes, Set<EClass> visited)
+ {
+ for (EClass eClass : classes)
+ {
+ handleEClass(eClass, visited);
+ }
+ }
+
+ protected void handleEClass(EClass eClass, Set<EClass> visited)
+ {
+ if (visited.add(eClass))
+ {
+ if (TRACER.isEnabled()) TRACER.trace("Found class " + eClass.getName());
+ handleEStructuralFeatures(eClass.getEStructuralFeatures(), visited);
+ handleEOperations(eClass.getEOperations(), visited);
+ handleEClasses(eClass.getESuperTypes(), visited);
+ handleEGenericTypes(eClass.getEGenericSuperTypes(), visited);
+ handleETypeParameters(eClass.getETypeParameters(), visited);
+ }
+ }
+
+ protected void handleEStructuralFeatures(List<EStructuralFeature> structuralFeatures, Set<EClass> visited)
+ {
+ for (EStructuralFeature structuralFeature : structuralFeatures)
+ {
+ handleEClassifier(structuralFeature.getEType(), visited);
+ handleEGenericType(structuralFeature.getEGenericType(), visited);
+ }
+ }
+
+ protected void handleEOperations(List<EOperation> operations, Set<EClass> visited)
+ {
+ for (EOperation operation : operations)
+ {
+ handleEClassifier(operation.getEType(), visited);
+ handleEGenericType(operation.getEGenericType(), visited);
+ handleETypeParameters(operation.getETypeParameters(), visited);
+ handleEParameters(operation.getEParameters(), visited);
+ handleEClassifiers(operation.getEExceptions(), visited);
+ handleEGenericTypes(operation.getEGenericExceptions(), visited);
+ }
+ }
+
+ protected void handleEParameters(List<EParameter> parameters, Set<EClass> visited)
+ {
+ for (EParameter parameter : parameters)
+ {
+ handleEClassifier(parameter.getEType(), visited);
+ handleEGenericType(parameter.getEGenericType(), visited);
+ }
+ }
+
+ protected void handleEGenericTypes(EList<EGenericType> genericTypes, Set<EClass> visited)
+ {
+ for (EGenericType genericType : genericTypes)
+ {
+ handleEGenericType(genericType, visited);
+ }
+ }
+
+ protected void handleEGenericType(EGenericType genericType, Set<EClass> visited)
+ {
+ handleEClassifier(genericType.getEClassifier(), visited);
+ handleEClassifier(genericType.getERawType(), visited);
+ handleEGenericType(genericType.getELowerBound(), visited);
+ handleEGenericType(genericType.getEUpperBound(), visited);
+ handleEGenericTypes(genericType.getETypeArguments(), visited);
+ handleETypeParameter(genericType.getETypeParameter(), visited);
+ }
+
+ protected void handleETypeParameters(EList<ETypeParameter> typeParameters, Set<EClass> visited)
+ {
+ for (ETypeParameter typeParameter : typeParameters)
+ {
+ handleETypeParameter(typeParameter, visited);
+ }
+ }
+
+ protected void handleETypeParameter(ETypeParameter typeParameter, Set<EClass> visited)
+ {
+ handleEGenericTypes(typeParameter.getEBounds(), visited);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/EMFPackageClosure.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CrossReferencesPackageClosure.java
index b823c2a..b56dbea 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/EMFPackageClosure.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CrossReferencesPackageClosure.java
@@ -10,6 +10,7 @@
**************************************************************************/
package org.eclipse.emf.internal.cdo.util;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
@@ -20,9 +21,9 @@ import java.util.Set;
/**
* @author Eike Stepper
*/
-public class EMFPackageClosure extends PackageClosure
+public class CrossReferencesPackageClosure extends PackageClosure
{
- public EMFPackageClosure()
+ public CrossReferencesPackageClosure()
{
}
@@ -45,7 +46,8 @@ public class EMFPackageClosure extends PackageClosure
protected void collectCrossReferences(EObject content, Set<EPackage> visited)
{
- for (EObject crossReference : content.eCrossReferences())
+ EList<EObject> crossReferences = content.eCrossReferences();
+ for (EObject crossReference : crossReferences)
{
EPackage crossReferencePackage = crossReference.eClass().getEPackage();
if (!visited.contains(crossReferencePackage))
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/InstancePackageClosure.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/InstancePackageClosure.java
new file mode 100644
index 0000000..b4297ed
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/InstancePackageClosure.java
@@ -0,0 +1,166 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.util;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EGenericType;
+import org.eclipse.emf.ecore.EOperation;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EParameter;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.ETypeParameter;
+import org.eclipse.emf.internal.cdo.bundle.OM;
+
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public class InstancePackageClosure extends PackageClosure
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_MODEL, InstancePackageClosure.class);
+
+ public InstancePackageClosure()
+ {
+ }
+
+ @Override
+ protected void collectContents(EPackage ePackage, Set<EPackage> visited)
+ {
+ Set<EClass> classes = new HashSet<EClass>();
+ List<EClassifier> classifiers = ePackage.getEClassifiers();
+ for (EClassifier classifier : classifiers)
+ {
+ handleEClassifier(classifier, classes);
+ }
+
+ for (EClass eClass : classes)
+ {
+ final EPackage p = eClass.getEPackage();
+ if (p != null)
+ {
+ if (visited.add(p))
+ {
+ if (TRACER.isEnabled()) TRACER.trace("Found package " + p.getNsURI());
+ }
+ }
+ else
+ {
+ OM.LOG.warn("Package == null for " + eClass.getName());
+ }
+ }
+ }
+
+ protected void handleEClassifiers(List<EClassifier> classifiers, Set<EClass> visited)
+ {
+ for (EClassifier classifier : classifiers)
+ {
+ handleEClassifier(classifier, visited);
+ }
+ }
+
+ protected void handleEClassifier(EClassifier classifier, Set<EClass> visited)
+ {
+ if (classifier instanceof EClass)
+ {
+ handleEClass((EClass)classifier, visited);
+ }
+ }
+
+ protected void handleEClasses(List<EClass> classes, Set<EClass> visited)
+ {
+ for (EClass eClass : classes)
+ {
+ handleEClass(eClass, visited);
+ }
+ }
+
+ protected void handleEClass(EClass eClass, Set<EClass> visited)
+ {
+ if (visited.add(eClass))
+ {
+ if (TRACER.isEnabled()) TRACER.trace("Found class " + eClass.getName());
+ handleEStructuralFeatures(eClass.getEStructuralFeatures(), visited);
+ handleEOperations(eClass.getEOperations(), visited);
+ handleEClasses(eClass.getESuperTypes(), visited);
+ handleEGenericTypes(eClass.getEGenericSuperTypes(), visited);
+ handleETypeParameters(eClass.getETypeParameters(), visited);
+ }
+ }
+
+ protected void handleEStructuralFeatures(List<EStructuralFeature> structuralFeatures, Set<EClass> visited)
+ {
+ for (EStructuralFeature structuralFeature : structuralFeatures)
+ {
+ handleEClassifier(structuralFeature.getEType(), visited);
+ handleEGenericType(structuralFeature.getEGenericType(), visited);
+ }
+ }
+
+ protected void handleEOperations(List<EOperation> operations, Set<EClass> visited)
+ {
+ for (EOperation operation : operations)
+ {
+ handleEClassifier(operation.getEType(), visited);
+ handleEGenericType(operation.getEGenericType(), visited);
+ handleETypeParameters(operation.getETypeParameters(), visited);
+ handleEParameters(operation.getEParameters(), visited);
+ handleEClassifiers(operation.getEExceptions(), visited);
+ handleEGenericTypes(operation.getEGenericExceptions(), visited);
+ }
+ }
+
+ protected void handleEParameters(List<EParameter> parameters, Set<EClass> visited)
+ {
+ for (EParameter parameter : parameters)
+ {
+ handleEClassifier(parameter.getEType(), visited);
+ handleEGenericType(parameter.getEGenericType(), visited);
+ }
+ }
+
+ protected void handleEGenericTypes(EList<EGenericType> genericTypes, Set<EClass> visited)
+ {
+ for (EGenericType genericType : genericTypes)
+ {
+ handleEGenericType(genericType, visited);
+ }
+ }
+
+ protected void handleEGenericType(EGenericType genericType, Set<EClass> visited)
+ {
+ handleEClassifier(genericType.getEClassifier(), visited);
+ handleEClassifier(genericType.getERawType(), visited);
+ handleEGenericType(genericType.getELowerBound(), visited);
+ handleEGenericType(genericType.getEUpperBound(), visited);
+ handleEGenericTypes(genericType.getETypeArguments(), visited);
+ handleETypeParameter(genericType.getETypeParameter(), visited);
+ }
+
+ protected void handleETypeParameters(EList<ETypeParameter> typeParameters, Set<EClass> visited)
+ {
+ for (ETypeParameter typeParameter : typeParameters)
+ {
+ handleETypeParameter(typeParameter, visited);
+ }
+ }
+
+ protected void handleETypeParameter(ETypeParameter typeParameter, Set<EClass> visited)
+ {
+ handleEGenericTypes(typeParameter.getEBounds(), visited);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/PackageClosure.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/PackageClosure.java
index 6d62b1b..cc23ddf 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/PackageClosure.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/PackageClosure.java
@@ -41,7 +41,8 @@ public abstract class PackageClosure implements IPackageClosure
// Optimize 1 package
if (ePackages.size() == 1)
{
- return calculate(ePackages.iterator().next());
+ EPackage ePackage = ePackages.iterator().next();
+ return calculate(ePackage);
}
// Handle >1 packages
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/TraversingPackageClosure.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/TraversingPackageClosure.java
deleted file mode 100644
index 5550ca8..0000000
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/TraversingPackageClosure.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
- * 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:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.emf.internal.cdo.util;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EOperation;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EParameter;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.internal.cdo.bundle.OM;
-
-import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * TODO Handle generic types and type parameters
- *
- * @author Eike Stepper
- */
-@Deprecated
-public class TraversingPackageClosure extends PackageClosure
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_MODEL, TraversingPackageClosure.class);
-
- public TraversingPackageClosure()
- {
- }
-
- @Override
- protected void collectContents(EPackage ePackage, Set<EPackage> visited)
- {
- Set<EClass> classes = new HashSet<EClass>();
- List<EClassifier> classifiers = ePackage.getEClassifiers();
- for (EClassifier classifier : classifiers)
- {
- handleEClassifier(classifier, classes);
- }
-
- for (EClass eClass : classes)
- {
- final EPackage p = eClass.getEPackage();
- if (p != null)
- {
- if (visited.add(p))
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Found package " + p.getNsURI());
- }
- }
- }
- else
- {
- String msg = "Package == null for " + eClass.getName();
- OM.LOG.warn(msg);
- if (TRACER.isEnabled())
- {
- TRACER.trace(msg);
- }
- }
- }
- }
-
- private void handleEClassifier(EClassifier classifier, Set<EClass> visited)
- {
- if (classifier instanceof EClass)
- {
- EClass eClass = (EClass)classifier;
- if (visited.add(eClass))
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Found class " + eClass.getName());
- }
-
- handleEStructuralFeatures(eClass.getEStructuralFeatures(), visited);
- handleEOperations(eClass.getEOperations(), visited);
- handleESuperTypes(eClass.getESuperTypes(), visited);
- }
- }
- }
-
- private void handleEStructuralFeatures(List<EStructuralFeature> structuralFeatures, Set<EClass> visited)
- {
- for (EStructuralFeature structuralFeature : structuralFeatures)
- {
- handleEClassifier(structuralFeature.getEType(), visited);
- }
- }
-
- private void handleEOperations(List<EOperation> operations, Set<EClass> visited)
- {
- for (EOperation operation : operations)
- {
- handleEClassifier(operation.getEType(), visited);
- handleEParameters(operation.getEParameters(), visited);
- handleEExceptions(operation.getEExceptions(), visited);
- }
- }
-
- private void handleEParameters(List<EParameter> parameters, Set<EClass> visited)
- {
- for (EParameter parameter : parameters)
- {
- handleEClassifier(parameter.getEType(), visited);
- }
- }
-
- private void handleEExceptions(List<EClassifier> exceptions, Set<EClass> visited)
- {
- for (EClassifier exception : exceptions)
- {
- handleEClassifier(exception, visited);
- }
- }
-
- private void handleESuperTypes(List<EClass> superTypes, Set<EClass> visited)
- {
- for (EClass superType : superTypes)
- {
- handleEClassifier(superType, visited);
- }
- }
-}