EMF Compare and Merge [message #1798544] |
Tue, 20 November 2018 10:16 |
Ramesh Javalagatti Messages: 17 Registered: November 2018 |
Junior Member |
|
|
Hi,
I am trying to compare and merge two resources using EMF compare and Merge.I am getting InvocationTargetException when commiting the merge transaction so please give me solution. please find code and error screen shot.
public boolean compareAndMergeEObjects(IFile local_oldSWCFile,IProject local_selectedProject,IStructuredSelection selectedSTructure) {
HashMap<String, Resource> local_arPackages=new HashMap<String, Resource>();
local_arPackages=this.getARPackages(local_oldSWCFile,local_selectedProject,selectedSTructure);
boolean local_flag=false;
Notifier left =local_arPackages.get("local_SWCresource");
Notifier right=local_arPackages.get("local_ARXMLresource");
if(local_arPackages !=null){
IComparisonScope scope = new DefaultComparisonScope(left,
right,null);
EMFCompare comparator = EMFCompare.builder().build();
Comparison comparison = comparator.compare(scope);
EList<Diff> differences = comparison.getDifferences();
if(differences.isEmpty()){
local_flag=true;
return local_flag;
}
ICompareEditingDomain editingDomain = EMFCompareEditingDomain.create(left,
right,null);
AdapterFactory adapterFactory = new ComposedAdapterFactory
(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
@SuppressWarnings("restriction")
EMFCompareConfiguration configuration=new EMFCompareConfiguration(new CompareConfiguration());
@SuppressWarnings("restriction")
CompareEditorInput input = new ComparisonEditorInput(configuration, comparison, editingDomain, adapterFactory);
//To Open Compare dialog to show differences
CompareUI.openCompareDialog(input);
}
return local_flag;
}
/**
*
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
global_window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
return null;
}
/**
*
* @param local_oldSWCFile
* @param local_selectedProject
* @return
*/
public HashMap<String,Resource> getARPackages(IFile local_oldSWCFile,
IProject local_selectedProject,IStructuredSelection selectedStructure){
IFile local_arxmlFile=null;
IResource[] local_resource=null;
//List<ARPackage> local_SWCarPackages = null;
//List<ARPackage> local_ARXMLarPackages = null;
HashMap<String,Resource> local_arPackageMap=new HashMap<String, Resource>();
if(local_oldSWCFile !=null){
URI local_createPlatformResourceURISWC = URI.createPlatformResourceURI
(local_oldSWCFile.getFullPath().toString(), true);
Resource local_SWCresource = new ResourceSetImpl()
.getResource(local_createPlatformResourceURISWC, true);
local_arPackageMap.put("local_SWCresource", local_SWCresource);
}
else{
ModelARXMLFileCreation local_modelARXMLFileCreation=new ModelARXMLFileCreation(local_selectedProject, "ModelFile.arxml",selectedStructure);
local_modelARXMLFileCreation.createModelFile();
try {
local_resource = local_selectedProject.members();
} catch (CoreException e) {
e.printStackTrace();
}
for (IResource iResource : local_resource) {
if (iResource instanceof IFile) {
if (((IFile)iResource).getName().equals("ModelFile.arxml")) {
global_swcFile = (IFile) iResource;
break;
} // End of if(matcher.matches())
} // End of If (iResource instanceof IFile)
}
/*
variable used to store regular expression of a file (autosartoplevelstructure)
final String local_AUTOSAR_PATTERN = "([^\\s]+(\\.(?i)(autosartoplevelstructure))$)";
*//**
* method used to complie of regular expression pattern
*
* @param ARPACKAGE_PATTERN
* compiles the regular expression into a pattern
* @return pattern return the given regular expression compiled into a
* pattern and assigned to a variable pattern
*//*
Pattern local_pattern = Pattern.compile(local_AUTOSAR_PATTERN);
for (IResource iResource : local_resource) {
if (iResource instanceof IFile) {
Matcher local_matcher = local_pattern.matcher(((IFile) iResource).getName());
if (local_matcher.matches()) {
local_swcFile = (IFile) iResource;
} // End of if(matcher.matches())
}
}*/
URI local_createPlatformResourceURISWC = URI.createPlatformResourceURI
(global_swcFile.getFullPath().toString(), true);
Resource local_SWCresource = new ResourceSetImpl()
.getResource(local_createPlatformResourceURISWC, true);
local_arPackageMap.put("local_SWCresource", local_SWCresource);
//EList<EObject> local_SWCresources = local_SWCresource.getContents();
}
/* variable used to store regular expression of a file */
final String local_DESCRIPTIONFILE_PATTERN = "([^\\s]+(\\.(?i)(arxml))$)";
/**
* method used to compiles the regular expression into a pattern
*
* @param local_DESCRIPTIONFILE_PATTERN
* hold the .arxml file extension
* @return pattern returns the given regular expression compiled
* into a pattern and assigned to a variable arxmlPattern
*/
Pattern local_arxmlPattern = Pattern.compile(local_DESCRIPTIONFILE_PATTERN);
try {
local_resource = local_selectedProject.members();
} catch (CoreException e) {
e.printStackTrace();
}
for (IResource iResource : local_resource) {
if (iResource instanceof IFile) {
Matcher local_arxmlMatcher = local_arxmlPattern.matcher(((IFile) iResource).getName());
if (local_oldSWCFile != null) {
if (local_arxmlMatcher.matches()
&& !(((IFile) iResource).getName()).equals(local_oldSWCFile.getName())) {
local_arxmlFile = (IFile) iResource;
break;
}
} else {
if(local_arxmlMatcher.matches()
&& !(((IFile)iResource).getName()).equals("ModelFile.arxml")){
local_arxmlFile = (IFile) iResource;
break;
}
}
} // End of If (iResource instanceof IFile)
}
//create resources from the arxmFile
URI local_createPlatformResourceURIARXML = URI.createPlatformResourceURI
(local_arxmlFile.getFullPath().toString(), true);
Resource local_ARXMLresource = new ResourceSetImpl()
.getResource(local_createPlatformResourceURIARXML, true);
local_arPackageMap.put("local_ARXMLresource", local_ARXMLresource);
// Get all contents from the resource
//EList<EObject> local_ARXMLResources = local_ARXMLresource.getContents();
return local_arPackageMap;
}
Below line of code throwing the exception
PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
saveChanges(monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
-
Attachment: error.PNG
(Size: 46.70KB, Downloaded 93 times)
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03378 seconds