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);
}
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;
}
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);
}
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;
}
Aggregations