Skip to content

Commit

Permalink
move ui in this repo
Browse files Browse the repository at this point in the history
  • Loading branch information
monperrus committed Apr 8, 2019
1 parent d1d212f commit 5fa074f
Show file tree
Hide file tree
Showing 16 changed files with 1,147 additions and 13 deletions.
15 changes: 15 additions & 0 deletions CoCoSpoon-ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Created by .ignore support plugin (hsz.mobi)
### Java template
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

59 changes: 59 additions & 0 deletions CoCoSpoon-ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<p align="center">
<img width="10%" src="https://github.com/maxcleme/OPL-Rendu2/blob/master/report/images/logoCoCoSpoon.png" />
</p>

# CoCoSpoon-ui

This project is the graphical part of [CoCoSpoon](https://github.com/SpoonLabs/CoCoSpoon.git)

## Install

Prerequisite: use a JVM with JavaFX installed.

cat $JAVA_HOME/jre/lib/javafx.properties

To Install CoCoSpoon-Ui :

```
git clone http://github.com/SpoonLabs/CoCoSpoon.git
cd CoCoSpoon/CoCoSpoon-ui
sh install.sh
```


## Run

### Example

You can run as example commons-lang by running the following script:
```sh
./example_commons-lang.sh
```

### Your own project

You can run CoCoSpoon-Ui on your project with:
```sh
mvn exec:java -Dexec.mainClass="Main" -Dexec.args="-i <pathToMyProject> -o <pathToMyOutput> -v OVERALL"
```
and by replacing `<pathToMyProject>` by the path to the root directory of your project, and
`<pathToMyOutput>` by the desired location of the output. The output can be the same as your input, but CoCoSpoon will erase old version by the instrumented one.

To the real time coverage, just run your test suite in your favorite IDE.

### Options

CocoSpoon
-i, --input-path input project folder
-o, --output-path instrumented project destination
[-c, --classpath classpath]
[-v, --view-type TEXT | OVERALL | INTERACTIVE]

### Screencast

[![alt tag](https://github.com/maxcleme/OPL-Rendu2/blob/master/report/images/youtubeVideo.png)](https://youtu.be/QUZK3erdiEM)


![alt tag](https://github.com/maxcleme/OPL-Rendu2/blob/master/report/images/overall_view.png)
![alt tag](https://github.com/maxcleme/OPL-Rendu2/blob/master/report/images/package_view.png)
![alt tag](https://github.com/maxcleme/OPL-Rendu2/blob/master/report/images/couverture_classe.png)
8 changes: 8 additions & 0 deletions CoCoSpoon-ui/example_commons-lang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

git clone https://github.com/apache/commons-lang.git
cd commons-lang
mvn clean install -DskipTests

cd ..
mvn exec:java -Dexec.mainClass="Main" -Dexec.args="-i commons-lang/ -o target/commong-lang -v OVERALL"
8 changes: 8 additions & 0 deletions CoCoSpoon-ui/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

git clone https://github.com/SpoonLabs/CoCoSpoon.git
cd CoCoSpoon
mvn clean install
cd ..

mvn clean install
90 changes: 90 additions & 0 deletions CoCoSpoon-ui/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>fil.iagl.cocospoon</groupId>
<artifactId>CocoSpoon-ui</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>
<version>1.4</version>
</dependency>

<dependency>
<groupId>com.sanityinc</groupId>
<artifactId>jargs</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>fil.iagl.cocospoon</groupId>
<artifactId>CocoSpoon</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>

</dependencies>
<repositories>
<repository>
<id>sonatype-oss-public</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fil.iagl.opl.cocospoon.CocoSpoon</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>


</project>
65 changes: 65 additions & 0 deletions CoCoSpoon-ui/src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import fil.iagl.opl.cocospoon.CocoSpoon;
import fil.iagl.opl.cocospoon.tools.Params;
import instrumenting._Instrumenting;
import instrumenting._View;
import org.apache.commons.lang3.StringEscapeUtils;
import spoon.Launcher;
import spoon.reflect.declaration.CtClass;

import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

/**
* Created by Benjamin DANGLOT
* benjamin.danglot@inria.fr
*/
public class Main {

public static void main(String[] args) {
try {
args = getView(args);
Launcher launcher = CocoSpoon.run(args);
Params params = new Params();
params.handleArgs(args);
CtClass<Object> instrumentClass = launcher.getFactory().Class().get(_Instrumenting.class);

File tmpFile = File.createTempFile("opl_instrumented", "");
FileOutputStream fout = new FileOutputStream(tmpFile);
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(_Instrumenting.lines);
oos.close();

instrumentClass.getField("TMP_FILE_NAME")
.setDefaultExpression(launcher.getFactory().Code().createCodeSnippetExpression("\"" + StringEscapeUtils.escapeJava(tmpFile.getAbsolutePath()) + "\""));
instrumentClass.getField("CURRENT_DIR")
.setDefaultExpression(launcher.getFactory().Code().createCodeSnippetExpression("\"" + StringEscapeUtils.escapeJava(params.getInputSource()) + "\""));
instrumentClass.getField("VIEW")
.setDefaultExpression(launcher.getFactory().Code().createCodeSnippetExpression("instrumenting._View.View." + view));

System.out.println("Rewriting...");
launcher.prettyprint();
System.out.println("Done!");

} catch (Exception ignored) {

}
}

private static _View.View view = _View.View.OVERALL;;

private static String[] getView(String [] args) {
List<String> argsWithoutView = new ArrayList<>();
for (int i = 0; i < args.length; i++) {
if ("-v".equals(args[i]) && i + 1 < args.length) {
view = _View.View.valueOf(args[i+1]);
i++;
} else {
argsWithoutView.add(args[i]);
}
}
return argsWithoutView.toArray(new String[argsWithoutView.size()]);
}
}
72 changes: 72 additions & 0 deletions CoCoSpoon-ui/src/main/java/fil/iagl/opl/cocospoon/CocoSpoon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package fil.iagl.opl.cocospoon;

import java.io.File;

import fil.iagl.opl.cocospoon.processors.WatcherProcessor;
import org.apache.commons.io.FileUtils;

import fil.iagl.opl.cocospoon.tools.Params;
import spoon.Launcher;
import spoon.support.compiler.ZipFolder;

/**
* Hello world!
*/
public class CocoSpoon {
private static final String INSTRUMENT_SOURCE_FOLDER = "src/main/java/instrumenting";

public static void main(String[] args) throws Exception {
Launcher l = run(args);
System.out.println("Rewriting...");
l.prettyprint();
System.out.println("Done!");
}

public static Launcher run(String[] args) throws Exception {
Params params = new Params();
params.handleArgs(args);

File inputFile = new File(params.getInputSource());
File outputFile = new File(params.getOutputSource());

if (outputFile.exists()) {
System.out.println("Deleting older instrumentation...");
FileUtils.forceDelete(outputFile);
}

System.out.println("Creating output folder...");
FileUtils.copyDirectory(inputFile, outputFile);

Launcher l = new Launcher();
l.addInputResource(params.getInputSource() + "/src/main/java");

if (new File(INSTRUMENT_SOURCE_FOLDER).exists()) {
l.addInputResource(INSTRUMENT_SOURCE_FOLDER);
} else {
l.getModelBuilder().addInputSource(new ZipFolder(new File(getNameRunningJar())));
}

if (params.getClasspath() != null && !params.getClasspath().isEmpty()) {
l.getModelBuilder().setSourceClasspath(params.getClasspath());
}
l.setSourceOutputDirectory(params.getOutputSource() + "/src/main/java");
l.addProcessor(new WatcherProcessor());

System.out.println("Building model...");
l.buildModel();

System.out.println("Start instrumentation...");
l.process();

return l;
}

private static String getNameRunningJar() {
return new File(CocoSpoon.class.getProtectionDomain()
.getCodeSource()
.getLocation()
.getPath())
.getName();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package fil.iagl.opl.cocospoon.tools;


import com.sanityinc.jargs.CmdLineParser;
import com.sanityinc.jargs.CmdLineParser.Option;


public class Params {

private String inputSource;
private String outputSource;
private String classpath;

public void handleArgs(String[] args) {
CmdLineParser parse = new CmdLineParser();

Option<String> inputSourceOption = parse.addStringOption('i', "input-path");
Option<String> outputSourceOption = parse.addStringOption('o', "output-path");
Option<String> classPathOption = parse.addStringOption('c', "classpath");

try {
parse.parse(args);
} catch (CmdLineParser.OptionException e) {
System.err.println(e.getMessage());
printUsage();
System.exit(2);
}

inputSource = parse.getOptionValue(inputSourceOption);
outputSource = parse.getOptionValue(outputSourceOption);
classpath = parse.getOptionValue(classPathOption);

if (inputSource == null || outputSource == null) {
printUsage();
System.exit(2);
}
}

private void printUsage() {
System.err.println("Usage: CoCoSpoon\n"
+ " -i, --input-path\t\tpath_program\n"
+ " -o, --output-path\t\tinstrumented sources destination\n"
+ "[-c, --classpath]\t\tclasspath\n"
+ "[-v, --view-type]\t\tview type : | OVERALL | INTERACTIVE | TEXT \n");
}

public String getClasspath() {
return classpath;
}

public void setClasspath(String classpath) {
this.classpath = classpath;
}

public String getInputSource() {
return inputSource;
}

public String getOutputSource() {
return outputSource;
}

}
Loading

0 comments on commit 5fa074f

Please sign in to comment.