Commit 37e7e8bf authored by Marc Jeanmougin's avatar Marc Jeanmougin

write result to csv file

parent bf02e380
......@@ -8,8 +8,15 @@ import java.lang.Object;
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.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
......@@ -59,10 +66,10 @@ public class AadlToTrajectoryActionHandler extends AbstractHandler {
return newObject;
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
......@@ -71,9 +78,9 @@ public class AadlToTrajectoryActionHandler extends AbstractHandler {
LatencyAnalyzer la = new LatencyAnalyzer();
//TODO use performAnalysis
TrajectoryAnalysisResult ar;
try {
ar = la.trajectoryAnalysis(instance);
......@@ -86,6 +93,7 @@ public class AadlToTrajectoryActionHandler extends AbstractHandler {
AnalysisArtifact result = f.createAnalysisArtifact() ;
ar.normalize(result);
Resource resource = instance.eResource();
URI resUri = resource.getURI().trimFileExtension().appendFileExtension("analysisresult");
ResourceSet rset = resource.getResourceSet();
......@@ -96,16 +104,27 @@ public class AadlToTrajectoryActionHandler extends AbstractHandler {
} catch (IOException e) {
throw new ExecutionException(e.getMessage(),e);
}
URI csvUri = resource.getURI().trimFileExtension().appendFileExtension("csv");
Resource r = rset.createResource(csvUri);
System.out.println(csvUri.toString());
File f1 = new File(csvUri.toString());
try {
String path="";
URI dirURI = resource.getURI();
String projectName = dirURI.toPlatformString(true).substring(1);
projectName = projectName.substring(0,projectName.indexOf("/"));
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
path = project.getLocation().toOSString();
String filePathWithProject = dirURI.toPlatformString(true);
filePathWithProject = filePathWithProject.substring(filePathWithProject.indexOf("/")+projectName.length()+1);
path = path + filePathWithProject ;
int index = path.lastIndexOf(File.separator);
path = path.substring(0, index+1);
File f1 = new File(path.concat("analysis.csv"));
try {
PrintWriter writer =
new PrintWriter(f1);
new PrintWriter(f1);
writer.println("");
for(ComponentInstance ci: ar._virtualLink2WCTT.keySet())
......@@ -125,13 +144,15 @@ public class AadlToTrajectoryActionHandler extends AbstractHandler {
writer.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
throw new ExecutionException(e1.getMessage(),e1);
}
try {
r.save(null);
} catch (IOException e) {
throw new ExecutionException(e.getMessage(),e);
project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (CoreException e) {
e.printStackTrace();
}
return null;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment