Skip to content

Commit

Permalink
Cache and delete metafile. Closes #1 and #2
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jan 23, 2014
1 parent 7f94f51 commit 37d133a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= Gipsy
:author: Andres Almiray
:version: 0.2.0
:version: 0.3.0

image::https://travis-ci.org/aalmiray/gipsy.png?branch=master["Build Status", link="https://travis-ci.org/aalmiray/gipsy"]

Expand Down
5 changes: 1 addition & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ apply from: 'gradle/publish.gradle'

repositories {
jcenter()
maven {
name 'Kordamp'
url 'http://dl.bintray.com/content/aalmiray/kordamp'
}
maven { url 'http://dl.bintray.com/content/aalmiray/kordamp' }
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=0.2.0
version=0.3.0
group=org.kordamp.gipsy
groovyVersion=2.2.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ protected File getResourceFile(String name) throws IOException {
return new File(outputDir.getAbsolutePath() + File.separator + path + name);
}

@Override
public void delete() throws IOException {
new File(outputDir.getAbsolutePath() + File.separator + path + name).delete();
}

@Override
protected Writer createWriter(String name) throws IOException {
System.out.print(name);
return new BufferedWriter(new FileWriter(getResourceFile(name)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.kordamp.gipsy.transform;

import org.codehaus.groovy.ast.*;
import org.codehaus.groovy.ast.expr.ClassExpression;
import org.codehaus.groovy.ast.expr.Expression;
import org.codehaus.groovy.ast.expr.ListExpression;
import org.codehaus.groovy.control.SourceUnit;
Expand All @@ -27,7 +26,6 @@
import org.kordamp.jipsy.processor.ProcessorLogger;
import org.kordamp.jipsy.processor.service.ServiceProviderProcessor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -106,25 +104,6 @@ protected CheckResult isImplementation(ClassNode classNode, ClassNode type) {
return CheckResult.valueOf(message + " " + type.getName());
}

protected List<ClassExpression> findClassListValue(AnnotationNode annotation) {
Expression value = annotation.getMember("value");
if (value instanceof ClassExpression) {
return Collections.singletonList((ClassExpression) value);
} else if (value instanceof ListExpression) {
List<ClassExpression> classes = new ArrayList<ClassExpression>();
ListExpression list = (ListExpression) value;
for (Expression expression : list.getExpressions()) {
if (expression instanceof ClassExpression) {
classes.add((ClassExpression) expression);
}
}
if (!classes.isEmpty()) {
return classes;
}
}
throw new IllegalStateException("No value found in element");
}

protected List<Expression> findCollectionValueMember(AnnotationNode annotation, String memberName) {
Expression value = annotation.getMember(memberName);
if (value instanceof ListExpression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.kordamp.gipsy.transform.GipsyASTTransformation;
import org.kordamp.jipsy.ServiceProviderFor;
import org.kordamp.jipsy.processor.CheckResult;
import org.kordamp.jipsy.processor.LogLocation;
import org.kordamp.jipsy.processor.Persistence;
import org.kordamp.jipsy.processor.service.Service;
import org.kordamp.jipsy.processor.service.ServiceCollector;
Expand Down Expand Up @@ -70,6 +71,7 @@ protected void initialize(ModuleNode moduleNode) {
for (String serviceName : persistence.tryFind()) {
data.getService(serviceName);
}
data.cache();
}

@Override
Expand All @@ -96,14 +98,26 @@ protected void handleAnnotations(ClassNode classNode, List<AnnotationNode> annot

@Override
protected void writeData() {
for (Service service : data.services()) {
try {
persistence.write(service.getName(), service.toProviderNamesList());
} catch (IOException e) {
// TODO print out error
if (data.isModified()) {
if (data.services().isEmpty()) {
logger.note(LogLocation.LOG_FILE, "Writing output");
try {
persistence.delete();
} catch (IOException e) {
logger.warning(LogLocation.LOG_FILE, "An error occurred while deleting data file");
}
} else {
logger.note(LogLocation.LOG_FILE, "Writing output");
for (Service service : data.services()) {
try {
persistence.write(service.getName(), service.toProviderNamesList());
} catch (IOException e) {
// TODO print out error
}
}
persistence.writeLog();
}
}
persistence.writeLog();
}

private CheckResult checkCurrentClass(ClassNode currentClass) {
Expand Down

0 comments on commit 37d133a

Please sign in to comment.