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