Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed errors in the Eclipse connectors #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/jess.jar"/>
<classpathentry kind="lib" path="lib/cglib-nodep-2.2.2.jar"/>
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="lib/mockito-core-1.10.19.jar"/>
<classpathentry kind="lib" path="lib/powermock-mockito-1.6.6-full.jar"/>
<classpathentry kind="lib" path="lib/javassist-3.21.0-GA.jar"/>
<classpathentry kind="lib" path="lib/objenesis-2.4.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="lib/mockito-all-1.8.5.jar"/>
<classpathentry kind="lib" path="lib/org.eclipse.jgit-0.9.3.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
12 changes: 8 additions & 4 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#Thu Aug 19 14:41:32 BRT 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.compiler.source=1.8
Binary file added lib/cglib-nodep-2.2.2.jar
Binary file not shown.
Binary file added lib/hamcrest-core-1.3.jar
Binary file not shown.
Binary file added lib/javassist-3.21.0-GA.jar
Binary file not shown.
Binary file added lib/mockito-core-1.10.19.jar
Binary file not shown.
Binary file added lib/objenesis-2.4.jar
Binary file not shown.
Binary file added lib/powermock-mockito-1.6.6-full.jar
Binary file not shown.
10 changes: 6 additions & 4 deletions src/besouro/classification/zorro/ZorroEpisodeClassification.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected QueryResult queryjessRules(Episode episode) {

engine.run();

//debugFacts();
debugFacts();

QueryResult result = engine.runQueryStar("episode-classification-query", new ValueVector());
return result;
Expand All @@ -81,9 +81,11 @@ protected QueryResult queryjessRules(Episode episode) {

private void debugFacts() {
Iterator it = engine.listFacts();
while (it.hasNext()) {
System.out.println(it.next());
}
try {
while (it.hasNext()) {
System.out.println(it.next());
}
} catch(Exception e) {}
}

public void assertJessFact(int index, Action action){
Expand Down
18 changes: 18 additions & 0 deletions src/besouro/listeners/BesouroListenerSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
import besouro.plugin.Activator;
import besouro.model.Action;
import besouro.stream.ActionOutputStream;
import java.util.Date;

public class BesouroListenerSet implements ActionOutputStream {

private static BesouroListenerSet singleton;
private String actualEditedFile = "";
private Date actualEditedDate;

public static BesouroListenerSet getSingleton() {
if (singleton==null) {
Expand Down Expand Up @@ -67,4 +70,19 @@ public void addAction(Action action) {

}

public String getActualEditedFile() {
return this.actualEditedFile;
}

public void setActualEditedFile(String actualEditedFile) {
this.actualEditedFile = actualEditedFile;
}

public Date getActualEditedDate() {
return this.actualEditedDate;
}

public void setActualEditedDate(Date actualEditedDate) {
this.actualEditedDate = actualEditedDate;
}
}
41 changes: 41 additions & 0 deletions src/besouro/listeners/JUnitListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.util.Date;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IJavaElement;
Expand All @@ -19,6 +21,8 @@
import org.eclipse.jdt.junit.model.ITestRunSession;
import org.eclipse.jdt.junit.model.ITestSuiteElement;

import besouro.measure.JavaStatementMeter;
import besouro.model.EditAction;
import besouro.model.UnitTestAction;
import besouro.model.UnitTestCaseAction;
import besouro.model.UnitTestSessionAction;
Expand All @@ -28,6 +32,7 @@
public class JUnitListener extends TestRunListener {

private ActionOutputStream stream;
private JavaStatementMeter measurer = new JavaStatementMeter();

public JUnitListener(ActionOutputStream stream) {
this.stream = stream;
Expand All @@ -36,6 +41,35 @@ public JUnitListener(ActionOutputStream stream) {
@Override
public void sessionFinished(ITestRunSession session) {

// Get Last edited file
BesouroListenerSet listeners = BesouroListenerSet.getSingleton();
String actualEditedFile = listeners.getActualEditedFile();

// Add last edited file
if (!actualEditedFile.isEmpty()) {
Date actualEditedDate = listeners.getActualEditedDate();

Path path = new Path(actualEditedFile);
IFile changedFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);

EditAction action = new EditAction(actualEditedDate, changedFile.getName());

JavaStatementMeter meter = this.measurer.measureJavaFile(changedFile);

action.setFileSize((int) changedFile.getLocation().toFile().length());
action.setIsTestEdit(meter.isTest());
action.setMethodsCount(meter.getNumOfMethods());
action.setStatementsCount(meter.getNumOfStatements());
action.setTestMethodsCount(meter.getNumOfTestMethods());
action.setTestAssertionsCount(meter.getNumOfTestAssertions());

stream.addAction(action);
}

listeners.setActualEditedFile("");
// END - Get Last edited file


boolean isSuccessfull = true;
for (UnitTestAction action: getTestFileActions(session, session.getLaunchedProject())) {
stream.addAction(action);
Expand Down Expand Up @@ -105,6 +139,13 @@ private IResource findTestResource(IJavaProject project, String className) {
throw new RuntimeException(e);
}
}

/**
* for testing purposes
*/
public void setMeasurer(JavaStatementMeter meter) {
this.measurer = meter;
}


// private void print(ITestElement session) {
Expand Down
71 changes: 71 additions & 0 deletions src/besouro/listeners/JavaStructureChangeListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@
import java.util.Iterator;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.IElementChangedListener;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaElementDelta;

import besouro.measure.JavaStatementMeter;
import besouro.model.EditAction;
import besouro.model.RefactoringAction;
import besouro.stream.ActionOutputStream;

Expand All @@ -37,12 +45,16 @@ public class JavaStructureChangeListener implements IElementChangedListener {
protected static final String PROP_CURRENT_TEST_ASSERTIONS = "Current-Test-Assertions";

private ActionOutputStream stream;
private JavaStatementMeter measurer = new JavaStatementMeter();

public JavaStructureChangeListener(ActionOutputStream stream) {
this.stream = stream;
}

public void elementChanged(ElementChangedEvent event) {

addToEditedFiles(event.getDelta());

// IJavaElementDelta jed = event.getDelta().getAffectedChildren()[0];
IJavaElementDelta[] childrenChanges = event.getDelta().getAffectedChildren();

Expand Down Expand Up @@ -261,4 +273,63 @@ private void traverse(IJavaElementDelta delta, List<IJavaElementDelta> additions
traverse(children[i], additions, deletions);
}
}

private void addToEditedFiles(IJavaElementDelta delta) {
IResource resource = delta.getElement().getResource();
int flag = delta.getFlags();
int kind = delta.getKind();

// :RESOLVED: 28 Mar 2017
// Author: Adonis Figueroa
// Note that the 540673 and 540680 enumeration types are not listed in the IJavaElementDelta static filed.
// However, these numbers are generated when a File is edited so that it is checked in the logical condition.
int EDITED_FLAG = 540673;
int METHOD_UPDATED_FLAG = 540680; //Method Name Updated | Added | Deleted

if ((kind == IJavaElementDelta.CHANGED) && resource instanceof IFile &&
(flag == EDITED_FLAG || flag == METHOD_UPDATED_FLAG)) {
if (JAVA.equals(resource.getFileExtension())) {
String fullPath = resource.getFullPath().toString();

BesouroListenerSet listeners = BesouroListenerSet.getSingleton();
String previousEditedFile = listeners.getActualEditedFile();

// If edited file is different --> add Action
if (!previousEditedFile.isEmpty() && !previousEditedFile.equals(fullPath)) {
Date previousEditedDate = listeners.getActualEditedDate();
Path path = new Path(previousEditedFile);

IFile changedFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
EditAction action = new EditAction(previousEditedDate, changedFile.getName());

JavaStatementMeter meter = this.measurer.measureJavaFile(changedFile);

action.setFileSize((int) changedFile.getLocation().toFile().length());
action.setIsTestEdit(meter.isTest());
action.setMethodsCount(meter.getNumOfMethods());
action.setStatementsCount(meter.getNumOfStatements());
action.setTestMethodsCount(meter.getNumOfTestMethods());
action.setTestAssertionsCount(meter.getNumOfTestAssertions());

stream.addAction(action);
}

listeners.setActualEditedFile(fullPath);
listeners.setActualEditedDate(new Date());
}
}

// Recursively look for changes on children elements.
IJavaElementDelta[] children = delta.getAffectedChildren();
for (int i = 0; i < children.length; i++) {
addToEditedFiles(children[i]);
}
}

/**
* for testing purposes
*/
public void setMeasurer(JavaStatementMeter meter) {
this.measurer = meter;
}
}
22 changes: 1 addition & 21 deletions src/besouro/listeners/ResourceChangeListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean visit(IResourceDelta delta) throws CoreException {

IResource resource = delta.getResource();
int flag = delta.getFlags();
int kind = delta.getKind();
//int kind = delta.getKind();

// If there is compilation problem with the current java file then send out the activity data.
// do not catch errors in other files
Expand All @@ -76,26 +76,6 @@ public boolean visit(IResourceDelta delta) throws CoreException {
// do not visit the children
return false;

} else if ((kind == IResourceDelta.CHANGED) && resource instanceof IFile && flag == IResourceDelta.CONTENT) {

if (resource.getLocation().toString().endsWith(".java")) {

IFile changedFile = (IFile) resource;
EditAction action = new EditAction(new Date(), changedFile.getName());

JavaStatementMeter meter = this.measurer.measureJavaFile(changedFile);

action.setFileSize((int) changedFile.getLocation().toFile().length());
action.setIsTestEdit(meter.isTest());
action.setMethodsCount(meter.getNumOfMethods());
action.setStatementsCount(meter.getNumOfStatements());
action.setTestMethodsCount(meter.getNumOfTestMethods());
action.setTestAssertionsCount(meter.getNumOfTestAssertions());

sensor.addAction(action);

}

}

// visit the children
Expand Down
3 changes: 1 addition & 2 deletions test/besouro/classification/TDDMeasureTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package besouro.classification;

import junit.framework.Assert;

import org.junit.Assert;
import org.junit.Test;

import besouro.model.Episode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package besouro.classification.besouro;

import static org.mockito.Mockito.when;

import java.util.Iterator;

import jess.QueryResult;
import jess.ValueVector;
import junit.framework.Assert;

import org.eclipse.jdt.junit.model.ITestElement.Result;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import besouro.classification.zorro.TestEpisodesFactory;
import besouro.classification.zorro.ZorroEpisodeClassifierTest;
import besouro.listeners.mock.JUnitEventFactory;
import besouro.listeners.mock.ResourceChangeEventFactory;
import besouro.model.EditAction;
import besouro.model.RefactoringAction;
import besouro.model.UnitTestCaseAction;

/**
Expand Down Expand Up @@ -54,10 +48,8 @@ public void productionCategory2WithTestBreak() throws Exception {

zorro.assertJessFact(1, editAction);

// Unit test failue
// Unit test failure
UnitTestCaseAction unitTestAction = new UnitTestCaseAction(clock, TestEpisodesFactory.testFile);
unitTestAction.setFailureMessage("Failed to import");
zorro.assertJessFact(2, unitTestAction);

// Edit on production code (corrects the error)
editAction = new EditAction(clock, TestEpisodesFactory.productionFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package besouro.classification.besouro;

import junit.framework.Assert;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package besouro.classification.randomHeuristic;

import junit.framework.Assert;

import org.junit.Assert;
import org.junit.Test;

import besouro.model.Episode;
Expand Down
3 changes: 0 additions & 3 deletions test/besouro/classification/zorro/JessTemplatesTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package besouro.classification.zorro;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.Date;

Expand All @@ -12,7 +10,6 @@
import jess.Value;
import jess.ValueVector;

import org.eclipse.core.resources.IResource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down
Loading