Skip to content
This repository has been archived by the owner on Nov 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2 from bkarak/master
Browse files Browse the repository at this point in the history
JDK 1.7 Supported; Removed Obsolete HSQLDB dependency
  • Loading branch information
gousiosg committed Nov 4, 2012
2 parents 9c1c728 + d814eca commit c4087ab
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,172 +32,28 @@
*/
package eu.sqooss.service.abstractmetric;

import com.sun.source.tree.MethodTree;
import com.sun.source.tree.VariableTree;
import com.sun.source.util.TreePath;
import com.sun.source.util.TreePathScanner;
import com.sun.source.util.Trees;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.tools.Diagnostic.Kind;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;

@SupportedSourceVersion(SourceVersion.RELEASE_6)
//@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("eu.sqooss.service.abstractmetric.*")
public class PluginAnnotationProcessor extends AbstractProcessor {

Set<String> declActivators = new HashSet<String>();

private Trees trees;

@Override
public void init(ProcessingEnvironment pe) {
super.init(pe);
trees = Trees.instance(pe);
}

@Override
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnvironment) {

MethodVisitor mv = new MethodVisitor();

for (Element e : roundEnvironment.getRootElements()) {
for (AnnotationMirror mirror : e.getAnnotationMirrors()) {
String annotationType = mirror.getAnnotationType().toString();

if (annotationType.equals(MetricDeclarations.class.getName())) {
processMetricDeclarations(mirror);
} else if (annotationType.equals(MetricDecl.class.getName())) {
processingEnv.getMessager().printMessage(Kind.ERROR,
"The @MetricDecl annotation is only allowed " +
"as a child of @MetricDeclarations");
}
}

TreePath tp = trees.getPath(e);
mv.scan(tp, trees);
}



public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment) {
return true;
}

private void processMetricDeclarations(AnnotationMirror aMirror) {
try {
Map<? extends ExecutableElement, ? extends AnnotationValue> mirrorMap = aMirror.getElementValues();

for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> mirrorEntry : mirrorMap.entrySet()) {
final String mirrorKey = mirrorEntry.getKey().toString();

if (mirrorKey.equals("metrics()")) {
List<? extends AnnotationValue> anns = extractMetricDecl(mirrorEntry.getValue());
for (AnnotationValue annVal : anns) {
extractMetricDeclParams(annVal);
}
}
}
} catch (Exception ex) {
processingEnv.getMessager().printMessage(Kind.ERROR,
"processMetricDeclarations: " + ex.getMessage());
}
}

private List<? extends AnnotationValue> extractMetricDecl(
AnnotationValue aAnnotationValue) {
return (List<? extends AnnotationValue>) aAnnotationValue.getValue();
}

private void extractMetricDeclParams(AnnotationValue aAnnotationValue) {

AnnotationMirror am = (AnnotationMirror) aAnnotationValue;
Map<? extends ExecutableElement, ? extends AnnotationValue> amMap = am
.getElementValues();
String mnemonic = "", descr = "", act = "";
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> amMirrorEntry : amMap.entrySet()) {
String amMirrorKey = amMirrorEntry.getKey().toString();


if (amMirrorKey.equals("mnemonic()")) {
mnemonic = amMirrorEntry.getValue().toString();
mnemonic = mnemonic.substring(1, mnemonic.length() - 1);
} else if (amMirrorKey.equals("descr()")) {
descr = amMirrorEntry.getValue().toString();
} else if (amMirrorKey.equals("activator()")) {
act = amMirrorEntry.getValue().toString();
}
}

if (mnemonic.length() > 10)
processingEnv.getMessager().printMessage(Kind.ERROR,
"Mnemonic " + mnemonic + " is too long. " +
"A metric mnemonic can only be < 10 chars long");

if (mnemonic.equals(""))
processingEnv.getMessager().printMessage(Kind.ERROR,
"Metric mnemonic is an empty String");

if (descr == null || descr.length() <= 0)
processingEnv.getMessager().printMessage(Kind.WARNING,
"A valid description should be specified with metric "
+ mnemonic);

declActivators.add(act);
}

/*
* A simple visitor that records method objects for methods that comply with
* the Alitheia Core plug-in interface requirements.
*/
private class MethodVisitor extends TreePathScanner<Object, Trees> {

List<MethodTree> methods = new ArrayList<MethodTree>();

@Override
public Object visitMethod(MethodTree methodTree, Trees trees) {
String name = methodTree.getName().toString();

if (name.equals("run")) {
if (!methodTree.getReturnType().toString().equals("void"))
return super.visitMethod(methodTree, trees);

List<? extends VariableTree> params = methodTree.getParameters();

// The run method has exactly 1 argument
if (params.size() != 1)
return super.visitMethod(methodTree, trees);

String paramType = params.get(0).getType().toString();

if (paramType.startsWith("eu.sqooss.service.db"))
methods.add(methodTree);
}

if (name.equals("getResult")) {
methods.add(methodTree);
}

return super.visitMethod(methodTree, trees);
}

public List<MethodTree> getMethodList() {
return methods;
}
}
}
Binary file not shown.
1 change: 1 addition & 0 deletions external/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO: Describe the usage of external directory
10 changes: 0 additions & 10 deletions external/hsqldb/osgi.bnd

This file was deleted.

35 changes: 0 additions & 35 deletions external/hsqldb/pom.xml

This file was deleted.

1 change: 0 additions & 1 deletion external/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<module>mysql-connector-java</module>
<module>org.hibernate.core</module>
<module>log4j</module>
<module>hsqldb</module>
<module>dom4j</module>
<module>com.jcraft.jsch</module>
<module>h2</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,11 @@ public void update() throws Exception {
if (db.isDBSessionActive())db.commitDBSession();
}

@Override
public void jobStateChanged(Job j, State newState) {
if (newState == State.Error || newState == State.Finished)
progress = 100 - (float) (((double)jobCounter.decrementAndGet() / (double)numVersions) * 100);
}

@Override
public int progress() {
return (int) progress;
}
Expand Down
32 changes: 31 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@
<email>[email protected]</email>
<url>http://istlab.dmst.aueb.gr/~george</url>
</developer>
<developer>
<id>bkarak</id>
<name>Vassilios Karakoidas</name>
<email>[email protected]</email>
<url>http://bkarak.wizhut.com/</url>
</developer>
</developers>

<scm>
Expand All @@ -116,8 +122,28 @@
<developerConnection>scm:git:ssh://[email protected]:sqo-oss.git</developerConnection>
</scm>

<!-- build -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<!-- FUTURE: executable jar
<archive>
<manifest>
<mainClass>org.sample.App</mainClass>
</manifest>
</archive>
-->
<!-- create a jar -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- configure execution -->
</configuration>
</plugin>
<plugin>
<groupId>org.ops4j</groupId>
<artifactId>maven-pax-plugin</artifactId>
Expand Down Expand Up @@ -164,6 +190,8 @@
</extension>
</extensions>
</build>

<!-- reporting -->
<reporting>
<plugins>
<plugin>
Expand All @@ -178,6 +206,8 @@
</plugin>
</plugins>
</reporting>

<!-- profiles -->
<profiles>
<profile>
<id>skiptests</id>
Expand Down Expand Up @@ -218,7 +248,7 @@
<configuration>
<skipTests>false</skipTests>
</configuration>
</plugin>
</plugin>
</plugins>
</build>
</profile>
Expand Down

0 comments on commit c4087ab

Please sign in to comment.