Commit 8b0e385f authored by Erwan Bousse's avatar Erwan Bousse
Browse files

Merging changes made after windows testing/building

parent 95159bad
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2014 Université de Rennes 1. * Copyright (c) 2014 Université de Rennes 1.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Erwan Bousse - initial API and implementation * Erwan Bousse - initial API and implementation
******************************************************************************/ ******************************************************************************/
package fr.inria.diverse.cloning.benchmark.materialgenerator.main; package fr.inria.diverse.cloning.benchmark.materialgenerator.main;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import joptsimple.OptionException; import joptsimple.OptionException;
import joptsimple.OptionParser; import joptsimple.OptionParser;
import joptsimple.OptionSet; import joptsimple.OptionSet;
import joptsimple.OptionSpec; import joptsimple.OptionSpec;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.jdt.core.IClasspathAttribute; import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.internal.core.ClasspathEntry; import org.eclipse.jdt.internal.core.ClasspathEntry;
import fr.inria.diverse.cloning.benchmark.materialgenerator.generator.BenchmarkMaterialGenerator; import fr.inria.diverse.cloning.benchmark.materialgenerator.generator.BenchmarkMaterialGenerator;
import fr.inria.diverse.cloning.benchmark.materialgenerator.generator.ModelCreatorGenerator; import fr.inria.diverse.cloning.benchmark.materialgenerator.generator.ModelCreatorGenerator;
import fr.inria.diverse.cloning.benchmark.materialgenerator.generator.OsgiBundleGenerator; import fr.inria.diverse.cloning.benchmark.materialgenerator.generator.OsgiBundleGenerator;
import fr.inria.diverse.cloning.materialgenerator.generators.EMFCodeGenerator; import fr.inria.diverse.cloning.materialgenerator.generators.EMFCodeGenerator;
import fr.inria.diverse.cloning.materialgenerator.generators.EMFCodeGenerator.EMFGenerationException; import fr.inria.diverse.cloning.materialgenerator.generators.EMFCodeGenerator.EMFGenerationException;
import fr.inria.diverse.cloning.materialgenerator.generators.PImplGenerator; import fr.inria.diverse.cloning.materialgenerator.generators.PImplGenerator;
import fr.inria.diverse.cloning.materialgenerator.tagger.Tagger; import fr.inria.diverse.cloning.materialgenerator.tagger.Tagger;
import fr.inria.diverse.cloning.materialgenerator.tagger.impl.DeepCloningTagger; import fr.inria.diverse.cloning.materialgenerator.tagger.impl.DeepCloningTagger;
import fr.inria.diverse.cloning.materialgenerator.tagger.impl.ShareFieldsOnlyTagger; import fr.inria.diverse.cloning.materialgenerator.tagger.impl.ShareFieldsOnlyTagger;
import fr.inria.diverse.cloning.materialgenerator.tagger.impl.ShareAllTagger; import fr.inria.diverse.cloning.materialgenerator.tagger.impl.ShareAllTagger;
import fr.inria.diverse.cloning.materialgenerator.tagger.impl.ShareObjOnlyTagger; import fr.inria.diverse.cloning.materialgenerator.tagger.impl.ShareObjOnlyTagger;
import fr.inria.diverse.cloning.runtime.util.Log; import fr.inria.diverse.cloning.runtime.util.Log;
/** /**
* This class controls all aspects of the application's execution * This class controls all aspects of the application's execution
*/ */
@SuppressWarnings("restriction") @SuppressWarnings("restriction")
public class Application implements IApplication { public class Application implements IApplication {
public static void realMain(String[] args) throws IOException, CoreException { public static void realMain(String[] args) throws IOException, CoreException {
Log.info("Starting cloning benchmark material generator."); Log.info("Starting cloning benchmark material generator.");
// Specifying arguments // Specifying arguments
OptionParser parser = new OptionParser(); OptionParser parser = new OptionParser();
OptionSpec<File> metamodelsFolderOption = parser OptionSpec<File> metamodelsFolderOption = parser
.accepts("metamodelsFolder", "A folder containing ecore files to process.").withRequiredArg() .accepts("metamodelsFolder", "A folder containing ecore files to process.").withRequiredArg()
.required().describedAs("path").ofType(File.class).required(); .required().describedAs("path").ofType(File.class).required();
OptionSpec<File> outputFileOption = parser.accepts("outputFile", "The OSGI jar bundle to create.") OptionSpec<File> outputFileOption = parser.accepts("outputFile", "The OSGI jar bundle to create.")
.withRequiredArg().required().describedAs("path").ofType(File.class).required(); .withRequiredArg().required().describedAs("path").ofType(File.class).required();
OptionSpec<File> outputProjectFolderOption = parser OptionSpec<File> outputProjectFolderOption = parser
.accepts("outputProjectFolder", .accepts("outputProjectFolder",
"The folder in which all the code is generated, as a complete eclipse project. NO SPACE CHARACTERS /!\\.") "The folder in which all the code is generated, as a complete eclipse project. NO SPACE CHARACTERS /!\\.")
.withRequiredArg().describedAs("path").ofType(File.class); .withRequiredArg().describedAs("path").ofType(File.class);
try { try {
// Parsing arguments (throws an error if problem) // Parsing arguments (throws an error if problem)
OptionSet options = parser.parse(args); OptionSet options = parser.parse(args);
File metamodelsFolder = options.valueOf(metamodelsFolderOption); File metamodelsFolder = options.valueOf(metamodelsFolderOption);
File outputFile = options.valueOf(outputFileOption); File outputFile = options.valueOf(outputFileOption);
File outputProjectFolder; File outputProjectFolder;
// Creating the java project in which we put everything // Creating the java project in which we put everything
if (options.has(outputProjectFolderOption)) { if (options.has(outputProjectFolderOption)) {
outputProjectFolder = options.valueOf(outputProjectFolderOption); outputProjectFolder = options.valueOf(outputProjectFolderOption);
} else { } else {
outputProjectFolder = File.createTempFile("cloningBenchmarkMaterial", ""); outputProjectFolder = File.createTempFile("cloningBenchmarkMaterial", "");
} }
File tmpDir = outputProjectFolder; File tmpDir = outputProjectFolder;
// Getting ecore files // Getting ecore files
List<Set<File>> metamodelsFiles = new ArrayList<>(); List<Set<File>> metamodelsFiles = new ArrayList<>();
List<String> names = new ArrayList<String>(); List<String> names = new ArrayList<String>();
for (File file : metamodelsFolder.listFiles()) { for (File file : metamodelsFolder.listFiles()) {
if (file.getName().endsWith(".ecore")) { if (file.getName().endsWith(".ecore")) {
Log.info("Found " + file.getAbsolutePath()); Log.info("Found " + file.getAbsolutePath());
Set<File> files = new HashSet<File>(); Set<File> files = new HashSet<File>();
files.add(file); files.add(file);
metamodelsFiles.add(files); metamodelsFiles.add(files);
names.add(file.getName().replace(".ecore", "")); names.add(file.getName().replace(".ecore", ""));
} }
} }
Log.info("Creating temporary project folder: " + tmpDir.getAbsolutePath()); Log.info("Creating temporary project folder: " + tmpDir.getAbsolutePath());
tmpDir.delete(); tmpDir.delete();
tmpDir.mkdir(); tmpDir.mkdir();
IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription("yayProject"); IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription("yayProject");
// Problem with spaces? // Problem with spaces?
description.setLocationURI(java.net.URI.create(tmpDir.getAbsolutePath())); //description.setLocationURI(java.net.URI.create(tmpDir.getAbsolutePath()));
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName()); description.setLocationURI(tmpDir.toURI());
project.delete(true, true, null); // to make sure that there is nothing there already IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
project.create(description, null); project.delete(true, true, null); // to make sure that there is nothing there already
project.open(null); project.create(description, null);
project.open(null);
List<ResourceSet> metamodels = new ArrayList<ResourceSet>();
List<ResourceSet> metamodels = new ArrayList<ResourceSet>();
File srcFolder = new File(tmpDir, "src");
File binFolder = new File(tmpDir, "bin"); File srcFolder = new File(tmpDir, "src");
File binFolder = new File(tmpDir, "bin");
Log.enableProgress(metamodelsFiles.size());
Log.enableProgress(metamodelsFiles.size());
// Iterating through metamodels an generating everything
Iterator<String> namesIt = names.iterator(); // Iterating through metamodels an generating everything
for (Set<File> metamodel : metamodelsFiles) { Iterator<String> namesIt = names.iterator();
for (Set<File> metamodel : metamodelsFiles) {
String name = namesIt.next();
String name = namesIt.next();
Log.info("Generating material for metamodel \"" + name + "\"");
Log.plusLevel(); Log.info("Generating material for metamodel \"" + name + "\"");
Log.plusLevel(); Log.plusLevel();
Log.plusLevel();
Log.info("Calling EMF code generator...");
ResourceSet rs = EMFCodeGenerator.generate(metamodel, name, project); Log.info("Calling EMF code generator...");
ResourceSet rs = EMFCodeGenerator.generate(metamodel, name, project);
// Tagging
Set<Tagger> taggers = new HashSet<Tagger>(); // Tagging
taggers.add(new DeepCloningTagger(rs, name)); Set<Tagger> taggers = new HashSet<Tagger>();
taggers.add(new ShareAllTagger(rs, name)); taggers.add(new DeepCloningTagger(rs, name));
taggers.add(new ShareFieldsOnlyTagger(rs, name)); taggers.add(new ShareAllTagger(rs, name));
taggers.add(new ShareObjOnlyTagger(rs, name)); taggers.add(new ShareFieldsOnlyTagger(rs, name));
taggers.add(new ShareObjOnlyTagger(rs, name));
metamodels.add(rs);
metamodels.add(rs);
PImplGenerator.generate(name, project, taggers, false);
ModelCreatorGenerator.generateModelCreator(rs, name, srcFolder.getAbsolutePath()); PImplGenerator.generate(name, project, taggers, false);
Log.minusLevel(); ModelCreatorGenerator.generateModelCreator(rs, name, srcFolder.getAbsolutePath());
Log.minusLevel(); Log.minusLevel();
Log.minusLevel();
Log.incProgress();
Log.incProgress();
}
Log.info("All metamodels have been processed."); }
Log.info("All metamodels have been processed.");
Log.disableProgress();
Log.disableProgress();
Log.info("Generating benchmark material class.");
BenchmarkMaterialGenerator.generate(names, metamodels, srcFolder); Log.info("Generating benchmark material class.");
BenchmarkMaterialGenerator.generate(names, metamodels, srcFolder);
// Generating required elements for the osgi bundle
Log.info("Generating OSGI bundle elements."); // Generating required elements for the osgi bundle
OsgiBundleGenerator.generateActivator(srcFolder); Log.info("Generating OSGI bundle elements.");
OsgiBundleGenerator.generateComponentConf(tmpDir); OsgiBundleGenerator.generateActivator(srcFolder);
OsgiBundleGenerator.generateManifest(tmpDir); OsgiBundleGenerator.generateComponentConf(tmpDir);
OsgiBundleGenerator.generateManifest(tmpDir);
// Adding to the java project classpath the plugin dependencies
IJavaProject jdtProject = JavaCore.create(project); // Adding to the java project classpath the plugin dependencies
IClasspathEntry[] classPath = jdtProject.getRawClasspath(); IJavaProject jdtProject = JavaCore.create(project);
IClasspathEntry[] newClassPath = Arrays.copyOf(classPath, classPath.length + 1); IClasspathEntry[] classPath = jdtProject.getRawClasspath();
IClasspathEntry other = new ClasspathEntry(1, 5, new org.eclipse.core.runtime.Path( IClasspathEntry[] newClassPath = Arrays.copyOf(classPath, classPath.length + 1);
"org.eclipse.pde.core.requiredPlugins"), new IPath[0], new IPath[0], null, null, null, false, null, IClasspathEntry other = new ClasspathEntry(1, 5, new org.eclipse.core.runtime.Path(
true, new IClasspathAttribute[0]); "org.eclipse.pde.core.requiredPlugins"), new IPath[0], new IPath[0], null, null, null, false, null,
newClassPath[newClassPath.length - 1] = other; true, new IClasspathAttribute[0]);
jdtProject.setRawClasspath(newClassPath, null); newClassPath[newClassPath.length - 1] = other;
jdtProject.setRawClasspath(newClassPath, null);
// Compiling the java project
Log.info("Compiling created java project."); // Compiling the java project
project.refreshLocal(IResource.DEPTH_INFINITE, null); Log.info("Compiling created java project.");
project.build(IncrementalProjectBuilder.FULL_BUILD, null); project.refreshLocal(IResource.DEPTH_INFINITE, null);
project.build(IncrementalProjectBuilder.FULL_BUILD, null);
// Generating files a second time, in order to use the bin folder as a basis for the jar
OsgiBundleGenerator.generateComponentConf(binFolder); // Generating files a second time, in order to use the bin folder as a basis for the jar
OsgiBundleGenerator.generateManifest(binFolder); OsgiBundleGenerator.generateComponentConf(binFolder);
OsgiBundleGenerator.generateManifest(binFolder);
// Creating the jar using the content of the bin folder
Log.info("Creating OSGI jar bundle: " + outputFile.getAbsolutePath()); // Creating the jar using the content of the bin folder
OsgiBundleGenerator.createJar(binFolder, outputFile); Log.info("Creating OSGI jar bundle: " + outputFile.getAbsolutePath());
OsgiBundleGenerator.createJar(binFolder, outputFile);
Log.info("Done!");
} catch (OptionException e) { Log.info("Done!");
Log.error("Invalid options: " + e.getMessage()); } catch (OptionException e) {
parser.printHelpOn(System.out); Log.error("Invalid options: " + e.getMessage());
} catch (EMFGenerationException e) { parser.printHelpOn(System.out);
System.err.println("There was a problem during EMF model code generation."); } catch (EMFGenerationException e) {
e.printStackTrace(); System.err.println("There was a problem during EMF model code generation.");
} e.printStackTrace();
} }
}
/*
* (non-Javadoc) /*
* * (non-Javadoc)
* @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext) *
*/ * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
public Object start(IApplicationContext context) throws Exception { */
String[] args = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS); public Object start(IApplicationContext context) throws Exception {
realMain(args); String[] args = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
return IApplication.EXIT_OK; realMain(args);
} return IApplication.EXIT_OK;
}
/*
* (non-Javadoc) /*
* * (non-Javadoc)
* @see org.eclipse.equinox.app.IApplication#stop() *
*/ * @see org.eclipse.equinox.app.IApplication#stop()
public void stop() { */
// nothing to do public void stop() {
} // nothing to do
} }
}
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?> <?pde version="3.5"?>
<product name="Benchmark tool" uid="fr.inria.diverse.cloning.benchmark.tool.product" id="fr.inria.diverse.cloning.benchmark.tool.BenchmarkToolSuite" application="fr.inria.diverse.cloning.benchmark.tool.application" version="0.1.0.qualifier" useFeatures="false" includeLaunchers="true"> <product name="Benchmark tool" uid="fr.inria.diverse.cloning.benchmark.tool.product" id="fr.inria.diverse.cloning.benchmark.tool.BenchmarkToolSuite" application="fr.inria.diverse.cloning.benchmark.tool.application" version="0.1.0.qualifier" useFeatures="false" includeLaunchers="true">
<configIni use="default"> <configIni use="default">
</configIni> </configIni>
<launcherArgs> <launcherArgs>
<vmArgs>-Xms128m -Xmx2048m <vmArgs>-Xms128m -Xmx2048m
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n</vmArgs> -agentlib:jdwp=transport=dt_socket,server=y,suspend=n</vmArgs>
<vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts</vmArgsMac> <vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts</vmArgsMac>
</launcherArgs> </launcherArgs>
<windowImages/> <windowImages/>
<launcher name="cloning-benchmark"> <launcher name="cloning-benchmark">
<solaris/> <solaris/>
<win useIco="false"> <win useIco="false">
<bmp/> <bmp/>
</win> </win>
</launcher> </launcher>
<vm> <vm>
</vm> </vm>
<plugins> <plugins>
<plugin id="fr.inria.diverse.cloning.benchmark.tool" version="0.1.0.qualifier"/> <plugin id="fr.inria.diverse.cloning.benchmark.tool" version="0.1.0.qualifier"/>
<plugin id="org.eclipse.core.runtime"/> <plugin id="org.eclipse.core.runtime"/>
<plugin id="org.eclipse.swt"/> <!--<plugin id="org.eclipse.swt"/>
<plugin id="org.eclipse.swt.gtk.linux.x86_64" fragment="true"/> <plugin id="org.eclipse.swt.win32.win32.x86_64" fragment="true"/>
</plugins> <plugin id="org.eclipse.swt.gtk.linux.x86_64" fragment="true"/>-->
<configurations> <plugin id="org.eclipse.swt"/>
<plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="0" /> <plugin id="org.eclipse.swt.gtk.linux.x86_64" fragment="true"/>
<property name="osgi.instance.area.default" value="benchmarktool-workingdir" /> <plugin id="org.eclipse.swt.gtk.linux.x86" fragment="true"/>
</configurations> <plugin id="org.eclipse.swt.win32.win32.x86" fragment="true"/>
<plugin id="org.eclipse.swt.win32.win32.x86_64" fragment="true"/>
</product> <plugin id="org.eclipse.swt.cocoa.macosx.x86_64" fragment="true"/>
</plugins>
<configurations>
<plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="0" />
<property name="osgi.instance.area.default" value="benchmarktool-workingdir" />
<plugin id="org.eclipse.swt" autoStart="true" startLevel="0" />
</configurations>
</product>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
Copyright (c) 2014 Université de Rennes 1. Copyright (c) 2014 Université de Rennes 1.
All rights reserved. This program and the accompanying materials All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0 are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html http://www.eclipse.org/legal/epl-v10.html
Contributors: Contributors:
Erwan Bousse - initial API and implementation Erwan Bousse - initial API and implementation
--> -->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>fr.inria.diverse.cloning.benchmark</groupId> <groupId>fr.inria.diverse.cloning.benchmark</groupId>
<artifactId>fr.inria.diverse.cloning.benchmark.tool.product</artifactId> <artifactId>fr.inria.diverse.cloning.benchmark.tool.product</artifactId>
<version>0.1.0-SNAPSHOT</version> <version>0.1.0-SNAPSHOT</version>
<packaging>eclipse-repository</packaging> <packaging>eclipse-repository</packaging>