### Eclipse Workspace Patch 1.0 #P org.eclipse.gmf.common Index: src/org/eclipse/gmf/internal/common/migrate/MigrationConfig.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/internal/common/migrate/MigrationConfig.java,v retrieving revision 1.7 diff -u -r1.7 MigrationConfig.java --- src/org/eclipse/gmf/internal/common/migrate/MigrationConfig.java 20 Oct 2006 16:22:22 -0000 1.7 +++ src/org/eclipse/gmf/internal/common/migrate/MigrationConfig.java 3 May 2007 15:59:57 -0000 @@ -221,6 +221,11 @@ return false; } + protected boolean setAttribValue(MigrationHandler handler, EObject peekObject, String name, String value) { + // override + return false; + } + /** * Migration config registry implementaion. */ @@ -249,5 +254,6 @@ } put(descriptor.getExtension(), descriptor); } - } + } + } Index: src/org/eclipse/gmf/internal/common/migrate/MigrationResource.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.common/src/org/eclipse/gmf/internal/common/migrate/MigrationResource.java,v retrieving revision 1.9 diff -u -r1.9 MigrationResource.java --- src/org/eclipse/gmf/internal/common/migrate/MigrationResource.java 19 Mar 2007 16:49:09 -0000 1.9 +++ src/org/eclipse/gmf/internal/common/migrate/MigrationResource.java 3 May 2007 15:59:58 -0000 @@ -241,18 +241,24 @@ @Override protected void setAttribValue(EObject object, String name, String value) { - if ((isMigrationEnabled() || fixmePotentiallyCompatibilityIssues) && config.shouldIgnoreAttribute(object, name)) { - Map> ignoredAttributes = resource().ignoredAttributes; - if (ignoredAttributes != null) { - Map attrs = ignoredAttributes.get(object); - if (attrs == null) { - attrs = new HashMap(); - ignoredAttributes.put(object, attrs); + if ((isMigrationEnabled() || fixmePotentiallyCompatibilityIssues)) { + if (config.setAttribValue(this, object, name, value)) { + notifyMigrationApplied(); + return; + } + if (config.shouldIgnoreAttribute(object, name)) { + Map> ignoredAttributes = resource().ignoredAttributes; + if (ignoredAttributes != null) { + Map attrs = ignoredAttributes.get(object); + if (attrs == null) { + attrs = new HashMap(); + ignoredAttributes.put(object, attrs); + } + attrs.put(name, value); } - attrs.put(name, value); + notifyMigrationApplied(); // notify we had to migrate + return; // do not try to set value } - notifyMigrationApplied(); // notify we had to migrate - return; // do not try to set value } super.setAttribValue(object, name, value); } @@ -292,7 +298,7 @@ } super.handleFeature(prefix, name); } - + /** * Make public for access from config. */ @@ -336,4 +342,5 @@ resource().handleMigrationPatchApplied(); } } + } #P org.eclipse.gmf.tests Index: src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java,v retrieving revision 1.9 diff -u -r1.9 MigrationPatchesTest.java --- src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java 19 Mar 2007 16:49:14 -0000 1.9 +++ src/org/eclipse/gmf/tests/migration/MigrationPatchesTest.java 3 May 2007 15:59:59 -0000 @@ -11,15 +11,19 @@ package org.eclipse.gmf.tests.migration; import java.io.IOException; +import java.util.Iterator; import junit.framework.TestCase; import org.eclipse.core.runtime.IStatus; import org.eclipse.emf.common.util.EList; 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.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.gmf.codegen.gmfgen.GenAuditContainer; +import org.eclipse.gmf.codegen.gmfgen.GenAuditRule; import org.eclipse.gmf.internal.common.ToolingResourceFactory; import org.eclipse.gmf.internal.common.migrate.MigrationUtil; import org.eclipse.gmf.internal.common.migrate.ModelLoadHelper; @@ -103,4 +107,82 @@ caughtException != null || !resource.getErrors().isEmpty() || !resource.getWarnings().isEmpty()); return caughtException; } + +/* +GenDiagram +Removed attrs: +attr String paletteProviderClassName; +attr ProviderPriority paletteProviderPriority; +attr String propertyProviderClassName; +attr ProviderPriority propertyProviderPriority; +attr String referenceConnectionEditPolicyClassName; +attr String externalNodeLabelHostLayoutEditPolicyClassName; +attr String diagramFileCreatorClassName; +attr String preferenceInitializerClassName; + */ + public void testGenDiagram() throws Exception { + String genmodelFileName = "testGenDiagram.gmfgen"; //$NON-NLS-1$ + + Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName); + assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$ + + assertOnLoadModelMigrationSuccess(genmodelFileName); + } + + public void testGenAuditRootDefaultAndNested() throws Exception { + String genmodelFileName = "testGenAuditRootDefaultAndNested.gmfgen"; //$NON-NLS-1$ + + Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName); + assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$ + + assertOnLoadModelMigrationSuccess(genmodelFileName); + } + + public void testGenAuditRootNoDefaultButNested() throws Exception { + String genmodelFileName = "testGenAuditRootNoDefaultButNested.gmfgen"; //$NON-NLS-1$ + + Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName); + assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$ + + assertOnLoadModelMigrationSuccess(genmodelFileName); + } + + public void testGenAudits() throws Exception { + String genmodelFileName = "testGenAudits.gmfgen"; //$NON-NLS-1$ + + Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName); + assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$ + + assertOnLoadModelMigrationSuccess(genmodelFileName); + } + + public void testGenEditorAuditRootNoDefaultButNested() throws Exception { + String genmodelFileName = "testGenEditorAuditRootNoDefaultButNested.gmfgen"; //$NON-NLS-1$ + + Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName); + assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$ + + assertOnLoadModelMigrationSuccess(genmodelFileName); + } + + public void testGenAuditsCorrectCategories() throws Exception { + String genmodelFileName = "testGenAuditsCorrectCategories.gmfgen"; //$NON-NLS-1$ + + Exception caughtGenException = assertOrdinaryLoadModelProblems(genmodelFileName); + assertTrue("expected diagnostic exception", caughtGenException != null); //$NON-NLS-1$ + + assertOnLoadModelMigrationSuccess(genmodelFileName); + + URI uri = createURI(genmodelFileName); + ModelLoadHelper loadHelper = new ModelLoadHelper(new ResourceSetImpl(), uri); + Resource resource = loadHelper.getLoadedResource(); + for (Iterator it = resource.getAllContents(); it.hasNext();) { + EObject next = it.next(); + if (next instanceof GenAuditRule) { + GenAuditRule nextRule = (GenAuditRule) next; + GenAuditContainer nextCategory = nextRule.getCategory(); + assertEquals("Audit rule expected to be placed to correct audit category after migration", "rule:"+nextCategory.getId(), nextRule.getId()); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + } } Index: models/migration/testGenAuditRootDefaultAndNested.gmfgen =================================================================== RCS file: models/migration/testGenAuditRootDefaultAndNested.gmfgen diff -N models/migration/testGenAuditRootDefaultAndNested.gmfgen --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ models/migration/testGenAuditRootDefaultAndNested.gmfgen 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,24 @@ + + + + + + + + + + + + Index: models/migration/testGenAuditsCorrectCategories.gmfgen =================================================================== RCS file: models/migration/testGenAuditsCorrectCategories.gmfgen diff -N models/migration/testGenAuditsCorrectCategories.gmfgen --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ models/migration/testGenAuditsCorrectCategories.gmfgen 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,26 @@ + + + + + + + + + + + + Index: models/migration/testGenEditorAuditRootNoDefaultButNested.gmfgen =================================================================== RCS file: models/migration/testGenEditorAuditRootNoDefaultButNested.gmfgen diff -N models/migration/testGenEditorAuditRootNoDefaultButNested.gmfgen --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ models/migration/testGenEditorAuditRootNoDefaultButNested.gmfgen 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,22 @@ + + + + + + + + + + + + Index: models/migration/testGenDiagram.gmfgen =================================================================== RCS file: models/migration/testGenDiagram.gmfgen diff -N models/migration/testGenDiagram.gmfgen --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ models/migration/testGenDiagram.gmfgen 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,11 @@ + + Index: models/migration/testGenAudits.gmfgen =================================================================== RCS file: models/migration/testGenAudits.gmfgen diff -N models/migration/testGenAudits.gmfgen --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ models/migration/testGenAudits.gmfgen 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + Index: models/migration/testGenAuditRootNoDefaultButNested.gmfgen =================================================================== RCS file: models/migration/testGenAuditRootNoDefaultButNested.gmfgen diff -N models/migration/testGenAuditRootNoDefaultButNested.gmfgen --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ models/migration/testGenAuditRootNoDefaultButNested.gmfgen 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,20 @@ + + + + + + + + + + #P org.eclipse.gmf.codegen Index: src/org/eclipse/gmf/codegen/gmfgen/util/GMFGenMigration.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/gmfgen/util/GMFGenMigration.java,v retrieving revision 1.10 diff -u -r1.10 GMFGenMigration.java --- src/org/eclipse/gmf/codegen/gmfgen/util/GMFGenMigration.java 11 Apr 2007 08:10:24 -0000 1.10 +++ src/org/eclipse/gmf/codegen/gmfgen/util/GMFGenMigration.java 3 May 2007 16:00:01 -0000 @@ -10,10 +10,21 @@ */ package org.eclipse.gmf.codegen.gmfgen.util; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.gmf.codegen.gmfgen.FeatureLabelModelFacet; +import org.eclipse.gmf.codegen.gmfgen.GMFGenFactory; import org.eclipse.gmf.codegen.gmfgen.GMFGenPackage; +import org.eclipse.gmf.codegen.gmfgen.GenAuditContainer; +import org.eclipse.gmf.codegen.gmfgen.GenAuditRoot; +import org.eclipse.gmf.codegen.gmfgen.GenAuditRule; +import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator; import org.eclipse.gmf.internal.common.migrate.MigrationConfig; import org.eclipse.gmf.internal.common.migrate.MigrationResource.MigrationHandler; @@ -29,14 +40,142 @@ public MigrationConfig getConfig() { MigrationConfig config = new MigrationConfig(GMFGenPackage.eNS_URI, new String[] { eNS_URI_1_0 }) { + private boolean isDefaultAuditCategoryAdded = false; + private boolean isAuditMigrationApplied = false; + + @Override + protected void handleResourceLoaded(Resource resource, Map> ignoredAttributes) { + if (!isAuditMigrationApplied) { + return; + } + List initialResourceContents = new ArrayList(resource.getContents().size()); + initialResourceContents.addAll(resource.getContents()); + for (Iterator it = initialResourceContents.iterator(); it.hasNext();) { + EObject object = it.next(); + if (object instanceof GenAuditContainer) { + GenAuditRoot root = GMFGenFactory.eINSTANCE.createGenAuditRoot(); + resource.getContents().add(root); + GenAuditContainer nextContainer = (GenAuditContainer) object; + root.getCategories().add(nextContainer); + moveNestedCategoriesToTheRoot(nextContainer, root); + nextContainer.getPath().clear(); + } + if (object instanceof GenEditorGenerator) { + GenEditorGenerator generator = (GenEditorGenerator) object; + GenAuditRoot root = generator.getAudits(); + if (root != null && !root.getCategories().isEmpty()) { + if (isDefaultAuditCategoryAdded) { + GenAuditContainer defaultCategory = getDefaultAuditContainer(root); + for (Iterator toplevelRules = root.getRules().iterator(); toplevelRules.hasNext();) { + GenAuditRule nextFirst = toplevelRules.next(); + nextFirst.setCategory(defaultCategory); + } + if (root.getCategories().size() > 1) { + List containersList = new ArrayList(root.getCategories().size()); + containersList.addAll(root.getCategories()); + containersList.remove(defaultCategory); + for (Iterator containers = containersList.iterator(); containers.hasNext();) { + GenAuditContainer nextContainer = containers.next(); + moveNestedCategoriesToTheRoot(nextContainer, root); + nextContainer.getPath().clear(); + nextContainer.getPath().add(defaultCategory); + } + } + } else { + List containersList = new ArrayList(root.getCategories().size()); + containersList.addAll(root.getCategories()); + for (Iterator containers = containersList.iterator(); containers.hasNext();) { + GenAuditContainer nextContainer = containers.next(); + moveNestedCategoriesToTheRoot(nextContainer, root); + nextContainer.getPath().clear(); + } + } + } + } + } + isDefaultAuditCategoryAdded = false; + isAuditMigrationApplied = false; + } + + private void moveNestedCategoriesToTheRoot(GenAuditContainer nextContainer, GenAuditRoot root) { + moveNestedAuditsToTheRoot(nextContainer, root); + for (Iterator nestedContainers=nextContainer.getPath().iterator(); nestedContainers.hasNext();) { + GenAuditContainer nextNestedContainer = nestedContainers.next(); + moveNestedCategoriesToTheRoot(nextNestedContainer, root); + nestedContainers.remove(); + root.getCategories().add(nextNestedContainer); + nextNestedContainer.getPath().clear(); + nextNestedContainer.getPath().add(nextContainer); + } + } + + private void moveNestedAuditsToTheRoot(GenAuditContainer nextContainer, GenAuditRoot root) { + for (Iterator nestedAudits = nextContainer.getAudits().iterator(); nestedAudits.hasNext();) { + GenAuditRule nextNestedRule = nestedAudits.next(); + nextNestedRule.setCategory(nextContainer); + root.getRules().add(nextNestedRule); + } + } + + @Override + public boolean setAttribValue(MigrationHandler handler, EObject peekObject, String name, String value) { + if (peekObject instanceof GenAuditRoot) { + if ("id".equals(name)) { //$NON-NLS-1$ + getDefaultAuditContainer((GenAuditRoot) peekObject).setId(value); + isAuditMigrationApplied = true; + return true; + } else if ("name".equals(name)) { //$NON-NLS-1$ + getDefaultAuditContainer((GenAuditRoot) peekObject).setName(value); + isAuditMigrationApplied = true; + return true; + } else if ("description".equals(name)) { //$NON-NLS-1$ + getDefaultAuditContainer((GenAuditRoot) peekObject).setDescription(value); + isAuditMigrationApplied = true; + return true; + } + } + return super.setAttribValue(handler, peekObject, name, value); + } + + private GenAuditContainer getDefaultAuditContainer(GenAuditRoot root) { + /* + * As we are mapping first audit category right into audit root, + * we should create some instance for that default category parameters + * also + */ + if (root.getCategories().isEmpty()) { + root.getCategories().add(0, GMFGenFactory.eINSTANCE.createGenAuditContainer()); + isDefaultAuditCategoryAdded = true; + } + return root.getCategories().get(0); + } @Override protected boolean handleFeature(MigrationHandler handler, String prefix, String name) { - if ("metaFeature".equals(name) && handler.peekEObject() instanceof FeatureLabelModelFacet) { //$NON-NLS-1$ + EObject object = handler.peekEObject(); + if ("metaFeature".equals(name) && object instanceof FeatureLabelModelFacet) { //$NON-NLS-1$ name = "metaFeatures"; //$NON-NLS-1$ handler.handleFeatureHook(prefix, name); return true; } + if ("audits".equals(name) && object instanceof GenAuditRoot) { //$NON-NLS-1$ + name = "rules"; //$NON-NLS-1$ + handler.handleFeatureHook(prefix, name); + isAuditMigrationApplied = true; + return true; + } + if ("childContainers".equals(name) && object instanceof GenAuditRoot) { //$NON-NLS-1$ + name = "categories"; //$NON-NLS-1$ + handler.handleFeatureHook(prefix, name); + isAuditMigrationApplied = true; + return true; + } + if ("childContainers".equals(name) && object instanceof GenAuditContainer) { //$NON-NLS-1$ + name = "path"; //$NON-NLS-1$ + handler.handleFeatureHook(prefix, name); + isAuditMigrationApplied = true; + return true; + } return false; } @@ -48,6 +187,7 @@ } return false; } + }; initialize(config); return config;