Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Compare » EMF Merge Issue(Got InvocationTargetException when click on commit button in compare dialog)
EMF Merge Issue [message #1798549] Tue, 20 November 2018 10:47
Ramesh Javalagatti is currently offline Ramesh JavalagattiFriend
Messages: 16
Registered: November 2018
Junior Member
In EMF compare and Merge i got InvocationTargetException when click on the commit button, PFA regarding error.Code is

package com.avin.importArxml;

import java.awt.Window;
//import java.awt.Composite;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notifier;
//import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;

import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.domain.ICompareEditingDomain;
import org.eclipse.emf.compare.domain.impl.EMFCompareEditingDomain;
import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration;
import org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonEditorInput;
//import org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonEditorInput;
//import org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonScopeEditorInput;
//import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.EMFCompareStructureMergeViewer;
import org.eclipse.emf.compare.merge.BatchMerger;
import org.eclipse.emf.compare.merge.IBatchMerger;
import org.eclipse.emf.compare.merge.IMerger;
import org.eclipse.emf.compare.scope.DefaultComparisonScope;
import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.transaction.impl.InternalTransaction;
import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.sirius.diagram.ui.internal.edit.commands.DistributeCommand.GetNewBoundsFunction;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;

import com.avin.arxml.generation.handlers.GenerateDesign;

import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareEditorInput;
import org.eclipse.compare.CompareUI;



public class SwcEditorDiffMergeImpl extends AbstractHandler {
private boolean global_arxmlFlag = false;
IWorkbenchWindow global_window=null;
IFile global_swcFile = null;
/* creating the instance of GenerateDesign */
GenerateDesign local_design = new GenerateDesign();

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;

}

}


code which throw the exception is as follows from CompareEditInput.java class

try {
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);
}
}

});
return true;
} catch (InterruptedException x) {
// Ignore
} catch (OperationCanceledException x) {
// Ignore
} catch (InvocationTargetException x) {
ErrorDialog.openError(fComposite.getShell(), CompareMessages.CompareDialog_error_title, null,
new Status(IStatus.ERROR, CompareUIPlugin.PLUGIN_ID, 0,
NLS.bind(CompareMessages.CompareDialog_error_message, x.getTargetException().getMessage()), x.getTargetException()));
}
  • Attachment: error.PNG
    (Size: 46.70KB, Downloaded 47 times)
Previous Topic:Behavior of matcher
Next Topic:[EMF Compare] handeling inheritance
Goto Forum:
  


Current Time: Sun Sep 15 06:15:58 GMT 2019

Powered by FUDForum. Page generated in 0.01948 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top