From 37d133ab93893262c1e0af58922ad083527f8bfa Mon Sep 17 00:00:00 2001 From: aalmiray Date: Thu, 23 Jan 2014 08:02:50 +0100 Subject: [PATCH] Cache and delete metafile. Closes #1 and #2 --- README.adoc | 2 +- build.gradle | 5 +--- gradle.properties | 2 +- .../transform/AbstractFilePersistence.java | 6 ++++- .../transform/GipsyASTTransformation.java | 21 --------------- .../ServiceProviderASTTransformation.java | 26 ++++++++++++++----- 6 files changed, 28 insertions(+), 34 deletions(-) diff --git a/README.adoc b/README.adoc index 26ddc2e..1f0f1f7 100644 --- a/README.adoc +++ b/README.adoc @@ -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"] diff --git a/build.gradle b/build.gradle index fcbe3d4..b118c74 100644 --- a/build.gradle +++ b/build.gradle @@ -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 { diff --git a/gradle.properties b/gradle.properties index c9862a5..435b378 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=0.2.0 +version=0.3.0 group=org.kordamp.gipsy groovyVersion=2.2.1 diff --git a/src/main/java/org/kordamp/gipsy/transform/AbstractFilePersistence.java b/src/main/java/org/kordamp/gipsy/transform/AbstractFilePersistence.java index 3f92031..1fefb18 100644 --- a/src/main/java/org/kordamp/gipsy/transform/AbstractFilePersistence.java +++ b/src/main/java/org/kordamp/gipsy/transform/AbstractFilePersistence.java @@ -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))); } } diff --git a/src/main/java/org/kordamp/gipsy/transform/GipsyASTTransformation.java b/src/main/java/org/kordamp/gipsy/transform/GipsyASTTransformation.java index 389e1b7..6205d84 100644 --- a/src/main/java/org/kordamp/gipsy/transform/GipsyASTTransformation.java +++ b/src/main/java/org/kordamp/gipsy/transform/GipsyASTTransformation.java @@ -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; @@ -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; @@ -106,25 +104,6 @@ protected CheckResult isImplementation(ClassNode classNode, ClassNode type) { return CheckResult.valueOf(message + " " + type.getName()); } - protected List findClassListValue(AnnotationNode annotation) { - Expression value = annotation.getMember("value"); - if (value instanceof ClassExpression) { - return Collections.singletonList((ClassExpression) value); - } else if (value instanceof ListExpression) { - List classes = new ArrayList(); - 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 findCollectionValueMember(AnnotationNode annotation, String memberName) { Expression value = annotation.getMember(memberName); if (value instanceof ListExpression) { diff --git a/src/main/java/org/kordamp/gipsy/transform/service/ServiceProviderASTTransformation.java b/src/main/java/org/kordamp/gipsy/transform/service/ServiceProviderASTTransformation.java index efdcaec..ebdb92b 100644 --- a/src/main/java/org/kordamp/gipsy/transform/service/ServiceProviderASTTransformation.java +++ b/src/main/java/org/kordamp/gipsy/transform/service/ServiceProviderASTTransformation.java @@ -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; @@ -70,6 +71,7 @@ protected void initialize(ModuleNode moduleNode) { for (String serviceName : persistence.tryFind()) { data.getService(serviceName); } + data.cache(); } @Override @@ -96,14 +98,26 @@ protected void handleAnnotations(ClassNode classNode, List 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) {