Skip to content

Commit

Permalink
Merge f5bada4 into 94a1809
Browse files Browse the repository at this point in the history
  • Loading branch information
boretti committed May 18, 2020
2 parents 94a1809 + f5bada4 commit 1d14538
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Expand Up @@ -269,6 +269,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 @@ -21,8 +21,15 @@

import static java.util.stream.Collectors.joining;

import java.io.PrintStream;
import java.util.Arrays;

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;

public class CommonUtils {
private CommonUtils() {
}
Expand Down Expand Up @@ -56,4 +63,16 @@ public static String addPrefix(String prefix, String input) {
return "\n" + Arrays.stream(input.split("\\R")).map(l -> prefix + l).collect(joining("\n")) + "\n";
}

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 @@ -20,6 +20,7 @@
package ch.powerunit.extensions.matchers.provideprocessor;

import static ch.powerunit.extensions.matchers.common.CommonUtils.addPrefix;
import static ch.powerunit.extensions.matchers.common.CommonUtils.traceErrorAndDump;
import static java.util.Collections.unmodifiableList;
import static java.util.stream.Collectors.toList;

Expand All @@ -36,7 +37,6 @@

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

import ch.powerunit.extensions.matchers.common.CommonUtils;
import ch.powerunit.extensions.matchers.common.FileObjectHelper;
Expand Down Expand Up @@ -80,6 +80,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("@javax.annotation.Generated(value=\""
+ ProvidesMatchersAnnotationsProcessor.class.getName() + "\",date=\""
Expand All @@ -99,8 +100,7 @@ public Collection<DSLMethod> process() {
tmp.stream().map(m -> addPrefix(" ", m.asStaticImplementation())).forEach(wjfo::println);
wjfo.println("}");
results.addAll(tmp);
} , e -> rm.getProcessingEnv().getMessager().printMessage(Kind.ERROR,
"Unable to create the file containing the target class because of " + e, te));
} , e -> traceErrorAndDump(getProcessingEnv().getMessager(),getProcessingEnv().getFiler(),e,te));
return results;
}

Expand Down

0 comments on commit 1d14538

Please sign in to comment.