Search in sources :

Example 6 with EMFCompare

use of org.eclipse.emf.compare.EMFCompare in project tdq-studio-se by Talend.

the class ExampleLauncher method compare.

public static void compare() {
    // Load the two input models
    ResourceSet resourceSet1 = new ResourceSetImpl();
    ResourceSet resourceSet2 = new ResourceSetImpl();
    // String xmi1 = "path/to/first/model.xmi";
    // String xmi2 = "path/to/second/model.xmi";
    load(fileName1, resourceSet1);
    load(fileName2, resourceSet2);
    // Configure EMF Compare
    IEObjectMatcher matcher = DefaultMatchEngine.createDefaultEObjectMatcher(UseIdentifiers.NEVER);
    IComparisonFactory comparisonFactory = new DefaultComparisonFactory(new DefaultEqualityHelperFactory());
    IMatchEngine.Factory matchEngineFactory = new MatchEngineFactoryImpl(matcher, comparisonFactory);
    matchEngineFactory.setRanking(20);
    IMatchEngine.Factory.Registry matchEngineRegistry = new MatchEngineFactoryRegistryImpl();
    matchEngineRegistry.add(matchEngineFactory);
    EMFCompare comparator = EMFCompare.builder().setMatchEngineFactoryRegistry(matchEngineRegistry).build();
    // Compare the two models
    IComparisonScope scope = new DefaultComparisonScope(resourceSet1, resourceSet2, null);
    Comparison compare = comparator.compare(scope);
    comparator.compare(scope);
    EList<Diff> differences = compare.getDifferences();
    ICompareEditingDomain editingDomain = EMFCompareEditingDomain.create(scope.getLeft(), scope.getRight(), null);
    AdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
    EMFCompareConfiguration configuration = new EMFCompareConfiguration(new CompareConfiguration());
    CompareEditorInput input = new ComparisonScopeEditorInput(configuration, editingDomain, adapterFactory, comparator, scope);
    // CompareUI.openCompareDialog(input); // or CompareUI.openCompareEditor(input);
    CompareUI.openCompareEditor(input);
}
Also used : MatchEngineFactoryImpl(org.eclipse.emf.compare.match.impl.MatchEngineFactoryImpl) Diff(org.eclipse.emf.compare.Diff) CompareConfiguration(org.eclipse.compare.CompareConfiguration) EMFCompareConfiguration(org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration) DefaultEqualityHelperFactory(org.eclipse.emf.compare.match.DefaultEqualityHelperFactory) AdapterFactory(org.eclipse.emf.common.notify.AdapterFactory) IComparisonFactory(org.eclipse.emf.compare.match.IComparisonFactory) DefaultComparisonFactory(org.eclipse.emf.compare.match.DefaultComparisonFactory) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) MatchEngineFactoryRegistryImpl(org.eclipse.emf.compare.match.impl.MatchEngineFactoryRegistryImpl) IComparisonScope(org.eclipse.emf.compare.scope.IComparisonScope) DefaultComparisonFactory(org.eclipse.emf.compare.match.DefaultComparisonFactory) Comparison(org.eclipse.emf.compare.Comparison) AdapterFactory(org.eclipse.emf.common.notify.AdapterFactory) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) ICompareEditingDomain(org.eclipse.emf.compare.domain.ICompareEditingDomain) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) DefaultEqualityHelperFactory(org.eclipse.emf.compare.match.DefaultEqualityHelperFactory) DefaultComparisonScope(org.eclipse.emf.compare.scope.DefaultComparisonScope) IComparisonFactory(org.eclipse.emf.compare.match.IComparisonFactory) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) EMFCompareConfiguration(org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration) ComparisonScopeEditorInput(org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonScopeEditorInput) CompareEditorInput(org.eclipse.compare.CompareEditorInput) EMFCompare(org.eclipse.emf.compare.EMFCompare) IEObjectMatcher(org.eclipse.emf.compare.match.eobject.IEObjectMatcher) IMatchEngine(org.eclipse.emf.compare.match.IMatchEngine)

Example 7 with EMFCompare

use of org.eclipse.emf.compare.EMFCompare in project tdq-studio-se by Talend.

the class FileMetadataTableComparisonLevel method compareWithReloadObject.

@Override
protected boolean compareWithReloadObject() throws ReloadCompareException {
    Map<ResourceSet, List<Resource>> rsJrxmlMap = removeJrxmlsFromResourceSet();
    EMFCompare comparator = createDefaultEMFCompare();
    MetadataTable tempOldTable = (MetadataTable) getTempTableFromOldFile();
    if (tempOldTable == null) {
        return false;
    }
    IComparisonScope scope = new DefaultComparisonScope(tempOldTable, (MetadataTable) selectedObj, null);
    Comparison compare = comparator.compare(scope);
    addJrxmlsIntoResourceSet(rsJrxmlMap);
    EList<Diff> differences = compare.getDifferences();
    for (Diff diff : differences) {
        // ignore the move Kind
        if (diff.getKind() == DifferenceKind.MOVE) {
            continue;
        }
        if (diff instanceof ReferenceChange) {
            ReferenceChange refChange = (ReferenceChange) diff;
            if (diff.getKind() == DifferenceKind.ADD) {
                handleRemoveElement(refChange);
            } else if (diff.getKind() == DifferenceKind.DELETE) {
                handleAddElement(refChange);
            }
        }
    }
    tempMetadataTable.getFeature().clear();
    return true;
}
Also used : DefaultComparisonScope(org.eclipse.emf.compare.scope.DefaultComparisonScope) EMFCompare(org.eclipse.emf.compare.EMFCompare) Comparison(org.eclipse.emf.compare.Comparison) Diff(org.eclipse.emf.compare.Diff) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ReferenceChange(org.eclipse.emf.compare.ReferenceChange) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IComparisonScope(org.eclipse.emf.compare.scope.IComparisonScope)

Example 8 with EMFCompare

use of org.eclipse.emf.compare.EMFCompare in project InformationSystem by ObeoNetwork.

the class DatabaseCompareService method compare.

public static Comparison compare(TableContainer source, TableContainer target) throws Exception {
    // Prepare using specific match engine
    IMatchEngine.Factory matchEngineFactory = new DatabaseMatchEngineFactory();
    matchEngineFactory.setRanking(20);
    IMatchEngine.Factory.Registry matchEngineRegistry = new MatchEngineFactoryRegistryImpl();
    matchEngineRegistry.add(matchEngineFactory);
    // Prepare using post processor
    IPostProcessor customPostProcessor = new DatabasePostProcessor();
    IPostProcessor.Descriptor descriptor = new BasicPostProcessorDescriptorImpl(customPostProcessor, NS_URI_PATTERN_FOR_POST_PROCESSOR, null);
    IPostProcessor.Descriptor.Registry<Object> postProcessorRegistry = new PostProcessorDescriptorRegistryImpl<Object>();
    postProcessorRegistry.put(DatabasePostProcessor.class.getName(), descriptor);
    EMFCompare comparator = EMFCompare.builder().setPostProcessorRegistry(postProcessorRegistry).setMatchEngineFactoryRegistry(matchEngineRegistry).build();
    // Set the "load on demand policy" registry to resolve dependencies to external libraries.
    EMFCompareRCPPlugin.getDefault().getLoadOnDemandPolicyRegistry().addPolicy(new DependenciesLoadOnDemandPolicy());
    // Compare the two models
    IComparisonScope scope = new DefaultComparisonScope(source, target, null);
    return comparator.compare(scope);
}
Also used : PostProcessorDescriptorRegistryImpl(org.eclipse.emf.compare.postprocessor.PostProcessorDescriptorRegistryImpl) DefaultComparisonScope(org.eclipse.emf.compare.scope.DefaultComparisonScope) IPostProcessor(org.eclipse.emf.compare.postprocessor.IPostProcessor) DatabaseMatchEngineFactory(org.obeonetwork.dsl.database.compare.extensions.match.DatabaseMatchEngineFactory) MatchEngineFactoryRegistryImpl(org.eclipse.emf.compare.match.impl.MatchEngineFactoryRegistryImpl) IComparisonScope(org.eclipse.emf.compare.scope.IComparisonScope) DatabasePostProcessor(org.obeonetwork.dsl.database.compare.extensions.processor.DatabasePostProcessor) DependenciesLoadOnDemandPolicy(org.obeonetwork.dsl.database.compare.extensions.policy.DependenciesLoadOnDemandPolicy) DatabaseMatchEngineFactory(org.obeonetwork.dsl.database.compare.extensions.match.DatabaseMatchEngineFactory) EMFCompare(org.eclipse.emf.compare.EMFCompare) BasicPostProcessorDescriptorImpl(org.eclipse.emf.compare.postprocessor.BasicPostProcessorDescriptorImpl) IMatchEngine(org.eclipse.emf.compare.match.IMatchEngine)

Example 9 with EMFCompare

use of org.eclipse.emf.compare.EMFCompare in project InformationSystem by ObeoNetwork.

the class EMFCompareUtils method initializeComparator.

/**
 * Initializes the EMF Compare comparator.
 *
 * @return the EMFCompare comparator.
 */
private static EMFCompare initializeComparator() {
    final IEObjectMatcher matcher = DefaultMatchEngine.createDefaultEObjectMatcher(UseIdentifiers.NEVER);
    final IComparisonFactory comparisonFactory = new DefaultComparisonFactory(new DefaultEqualityHelperFactory());
    final IMatchEngine.Factory matchEngineFactory = new MatchEngineFactoryImpl(matcher, comparisonFactory);
    matchEngineFactory.setRanking(20);
    final IMatchEngine.Factory.Registry matchEngineRegistry = new MatchEngineFactoryRegistryImpl();
    matchEngineRegistry.add(matchEngineFactory);
    final IDiffProcessor diffProcessor = new DiffBuilder();
    final IDiffEngine diffEngine = new DefaultDiffEngine(diffProcessor) {

        @Override
        protected FeatureFilter createFeatureFilter() {
            return new FeatureFilter() {

                @Override
                protected boolean isIgnoredAttribute(EAttribute attribute) {
                    if (attribute == null) {
                        // comparison, do it here.
                        return true;
                    } else {
                        return super.isIgnoredAttribute(attribute);
                    }
                }
            };
        }
    };
    final EMFCompare comparator = EMFCompare.builder().setDiffEngine(diffEngine).setMatchEngineFactoryRegistry(matchEngineRegistry).build();
    return comparator;
}
Also used : DiffBuilder(org.eclipse.emf.compare.diff.DiffBuilder) DefaultEqualityHelperFactory(org.eclipse.emf.compare.match.DefaultEqualityHelperFactory) MatchEngineFactoryImpl(org.eclipse.emf.compare.match.impl.MatchEngineFactoryImpl) FeatureFilter(org.eclipse.emf.compare.diff.FeatureFilter) IComparisonFactory(org.eclipse.emf.compare.match.IComparisonFactory) DefaultEqualityHelperFactory(org.eclipse.emf.compare.match.DefaultEqualityHelperFactory) IComparisonFactory(org.eclipse.emf.compare.match.IComparisonFactory) DefaultComparisonFactory(org.eclipse.emf.compare.match.DefaultComparisonFactory) MatchEngineFactoryRegistryImpl(org.eclipse.emf.compare.match.impl.MatchEngineFactoryRegistryImpl) IDiffEngine(org.eclipse.emf.compare.diff.IDiffEngine) DefaultComparisonFactory(org.eclipse.emf.compare.match.DefaultComparisonFactory) DefaultDiffEngine(org.eclipse.emf.compare.diff.DefaultDiffEngine) EAttribute(org.eclipse.emf.ecore.EAttribute) EMFCompare(org.eclipse.emf.compare.EMFCompare) IDiffProcessor(org.eclipse.emf.compare.diff.IDiffProcessor) IEObjectMatcher(org.eclipse.emf.compare.match.eobject.IEObjectMatcher) IMatchEngine(org.eclipse.emf.compare.match.IMatchEngine)

Aggregations

EMFCompare (org.eclipse.emf.compare.EMFCompare)9 DefaultComparisonScope (org.eclipse.emf.compare.scope.DefaultComparisonScope)7 IComparisonScope (org.eclipse.emf.compare.scope.IComparisonScope)7 Comparison (org.eclipse.emf.compare.Comparison)6 Diff (org.eclipse.emf.compare.Diff)6 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)6 List (java.util.List)5 EList (org.eclipse.emf.common.util.EList)5 ArrayList (java.util.ArrayList)4 MatchEngineFactoryRegistryImpl (org.eclipse.emf.compare.match.impl.MatchEngineFactoryRegistryImpl)4 ReferenceChange (org.eclipse.emf.compare.ReferenceChange)3 DefaultComparisonFactory (org.eclipse.emf.compare.match.DefaultComparisonFactory)3 DefaultEqualityHelperFactory (org.eclipse.emf.compare.match.DefaultEqualityHelperFactory)3 IComparisonFactory (org.eclipse.emf.compare.match.IComparisonFactory)3 IMatchEngine (org.eclipse.emf.compare.match.IMatchEngine)3 IEObjectMatcher (org.eclipse.emf.compare.match.eobject.IEObjectMatcher)3 DiffBuilder (org.eclipse.emf.compare.diff.DiffBuilder)2 MatchEngineFactoryImpl (org.eclipse.emf.compare.match.impl.MatchEngineFactoryImpl)2 EObject (org.eclipse.emf.ecore.EObject)2 CompareConfiguration (org.eclipse.compare.CompareConfiguration)1