Skip to content

Commit

Permalink
Merge pull request #278 from powerunit/evol-version-dump
Browse files Browse the repository at this point in the history
Add version to generated file and dump error
  • Loading branch information
boretti committed May 18, 2020
2 parents 7f8a466 + da853f3 commit a97bb9f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Expand Up @@ -273,6 +273,18 @@
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
Expand Up @@ -19,8 +19,15 @@
*/
package ch.powerunit.extensions.matchers.common;

import java.io.PrintStream;
import java.time.Instant;

import javax.annotation.processing.Filer;
import javax.annotation.processing.Messager;
import javax.lang.model.element.Element;
import javax.tools.Diagnostic.Kind;
import javax.tools.StandardLocation;

/**
* These are some method to manipulate java.
*
Expand Down Expand Up @@ -66,4 +73,16 @@ public static String generateGeneratedAnnotation(Class<?> generatedBy, String co
+ "\"" + (comments == null ? "" : (",comments=" + toJavaSyntax(comments))) + ")";
}

public static void traceErrorAndDump(Messager messager, Filer filer, Exception e, Element te) {
FileObjectHelper.processFileWithIOException(
() -> filer.createResource(StandardLocation.SOURCE_OUTPUT, "",
"dump" + System.currentTimeMillis() + "txt", te),
s -> new PrintStream(s.openOutputStream()), s -> e.printStackTrace(s),
e2 -> messager.printMessage(Kind.ERROR,
"Unable to create the file containing the dump of the error because of " + e2
+ " during handling of " + e,
te));
messager.printMessage(Kind.ERROR, "Unable to create the file containing the target class because of " + e, te);
}

}
Expand Up @@ -21,6 +21,7 @@

import static ch.powerunit.extensions.matchers.common.CommonUtils.addPrefix;
import static ch.powerunit.extensions.matchers.common.CommonUtils.generateGeneratedAnnotation;
import static ch.powerunit.extensions.matchers.common.CommonUtils.traceErrorAndDump;
import static ch.powerunit.extensions.matchers.common.FileObjectHelper.processFileWithIOExceptionAndResult;
import static ch.powerunit.extensions.matchers.provideprocessor.dsl.DSLMethod.of;
import static java.util.Collections.unmodifiableList;
Expand All @@ -38,7 +39,6 @@

import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic.Kind;

import ch.powerunit.extensions.matchers.provideprocessor.dsl.DSLMethod;

Expand Down Expand Up @@ -77,6 +77,7 @@ public Collection<DSLMethod> process() {
jfo -> new PrintWriter(jfo.openWriter()), wjfo -> {
wjfo.println("package " + getPackageNameOfGeneratedClass() + ";");
wjfo.println();
wjfo.println("// Generated by version "+getClass().getPackage().getImplementationVersion());
wjfo.println(generateMainJavaDoc());
wjfo.println(generateGeneratedAnnotation(ProvidesMatchersAnnotationsProcessor.class,
annotation.get().comments()));
Expand All @@ -94,10 +95,9 @@ public Collection<DSLMethod> process() {
tmp.stream().map(m -> addPrefix(" ", m.asStaticImplementation())).forEach(wjfo::println);
wjfo.println("}");
return tmp;
}, e -> getMessager().printMessage(Kind.ERROR,
"Unable to create the file containing the target class because of " + e, te));
}, e -> traceErrorAndDump(getMessager(),getFiler(),e,te));
}

public Collection<DSLMethod> generateDSLStarter() {
return dslProvider.stream().map(Supplier::get).filter(Objects::nonNull).collect(toList());
}
Expand Down

0 comments on commit a97bb9f

Please sign in to comment.