Skip to content

Commit

Permalink
Merge branch 'release/0.16.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
pmlopes committed Dec 14, 2021
2 parents 1026e5b + 3e38cf2 commit e9e48d2
Show file tree
Hide file tree
Showing 85 changed files with 375 additions and 179 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.16.2] - 2021-12-14
* Bump vert.x to 4.2.2
* Pretty print polyglot exceptions so IDEs can track back
* Allow multiple maven repositories (comma separated)

## [0.16.1] - 2021-11-10
* Bump vert.x to 4.2.1
* Fixed codegen for data objects to properly handle collection types
Expand Down
4 changes: 2 additions & 2 deletions codegen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<parent>
<groupId>io.reactiverse</groupId>
<artifactId>es4x-parent</artifactId>
<version>0.16.1</version>
<version>0.16.2</version>
<relativePath>..</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>es4x-codegen</artifactId>
<version>0.16.1</version>
<version>0.16.2</version>

<properties>
<tools.jar>${java.home}/../lib/tools.jar</tools.jar>
Expand Down
4 changes: 2 additions & 2 deletions es4x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<parent>
<groupId>io.reactiverse</groupId>
<artifactId>es4x-parent</artifactId>
<version>0.16.1</version>
<version>0.16.2</version>
<relativePath>..</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>es4x</artifactId>
<version>0.16.1</version>
<version>0.16.2</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
122 changes: 122 additions & 0 deletions es4x/src/main/java/io/reactiverse/es4x/jul/ANSIFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,22 @@
*/
package io.reactiverse.es4x.jul;

import io.reactiverse.es4x.sourcemap.SourceMap;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.Json;
import io.vertx.core.json.JsonObject;
import org.graalvm.polyglot.PolyglotException;
import org.graalvm.polyglot.SourceSection;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Set;
import java.util.logging.*;

import static java.util.logging.Level.*;
Expand All @@ -26,6 +39,7 @@ public class ANSIFormatter extends Formatter {

// are ANSI colors allowed?
private static final boolean colors;
// private static final SourceMap sourceMap;

static {
if (Boolean.getBoolean("noTTY")) {
Expand All @@ -48,6 +62,14 @@ public class ANSIFormatter extends Formatter {
colors = System.console() != null;
}
}
//
// // handle source maps
// String sourceMapFile = System.getProperty("sourceMap");
// if (sourceMapFile != null) {
// sourceMap = new SourceMap(Buffer.buffer(Files.readAllBytes(Paths.get(sourceMapFile))));
// } else {
// sourceMap = null;
// }
}

@Override
Expand Down Expand Up @@ -151,4 +173,104 @@ private static String suffix(Level l) {

return "";
}


private static final String CAUSE_CAPTION = "Caused by: ";
private static final String SUPPRESSED_CAPTION = "Suppressed: ";

public static void printStackTrace(Throwable self, PrintWriter s) {
// Guard against malicious overrides of Throwable.equals by
// using a Set with identity equality semantics.
Set<Throwable> dejaVu = Collections.newSetFromMap(new IdentityHashMap<>());
dejaVu.add(self);

// Print our stack trace
s.println(self);
StackTraceElement[] trace = self.getStackTrace();
printTrace(self, trace, trace.length, s);

// Print suppressed exceptions, if any
for (Throwable se : self.getSuppressed())
printEnclosedStackTrace(se, s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);

// Print cause, if any
Throwable ourCause = self.getCause();
if (ourCause != null)
printEnclosedStackTrace(ourCause, s, trace, CAUSE_CAPTION, "", dejaVu);
}

private static void printEnclosedStackTrace(
Throwable self,
PrintWriter s,
StackTraceElement[] enclosingTrace,
String caption,
String prefix,
Set<Throwable> dejaVu) {

if (dejaVu.contains(self)) {
s.println(prefix + caption + "[CIRCULAR REFERENCE: " + self + "]");
} else {
dejaVu.add(self);
// Compute number of frames in common between this and enclosing trace
StackTraceElement[] trace = self.getStackTrace();
int m = trace.length - 1;
int n = enclosingTrace.length - 1;
while (m >= 0 && n >= 0 && trace[m].equals(enclosingTrace[n])) {
m--;
n--;
}
int framesInCommon = trace.length - 1 - m;

// Print our stack trace
s.println(prefix + caption + self);
printTrace(self, trace, m, s);

if (framesInCommon != 0)
s.println(prefix + "\t... " + framesInCommon + " more");

// Print suppressed exceptions, if any
for (Throwable se : self.getSuppressed())
printEnclosedStackTrace(se, s, trace, SUPPRESSED_CAPTION,
prefix + "\t", dejaVu);

// Print cause, if any
Throwable ourCause = self.getCause();
if (ourCause != null)
printEnclosedStackTrace(ourCause, s, trace, CAUSE_CAPTION, prefix, dejaVu);
}
}

private static void printTrace(Throwable self, StackTraceElement[] trace, int limit, PrintWriter s) {
if (self instanceof PolyglotException) {
int i = 0;
for (PolyglotException.StackFrame stackFrame : ((PolyglotException) self).getPolyglotStackTrace()) {
if (i++ == limit) {
break;
}
if (stackFrame.isHostFrame()) {
s.println("\tat " + stackFrame);
} else {
SourceSection sourceSection = stackFrame.getSourceLocation();
if (sourceSection != null) {
URI uri = sourceSection.getSource().getURI();

// TODO: rewrite with sourcemap is available

s.println("\tat <js> " + stackFrame.getRootName()
+ "(" +
("file".equals(uri.getScheme()) ? uri.getPath() : uri) +
(sourceSection.hasLines() ? ":" + sourceSection.getStartLine() : "") +
(sourceSection.hasColumns() ? ":" + sourceSection.getStartColumn() : "") +
")");
} else {
s.println("\tat " + stackFrame);
}
}
}
} else {
for (int i = 0; i <= limit; i++) {
s.println("\tat " + trace[i]);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.reactiverse.es4x.sourcemap;

import io.vertx.core.json.Json;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

Expand All @@ -21,15 +20,15 @@ public class SourceMap {
private ArrayList<ArrayList<Mapping>> lines = null;
private String sourceRoot;

public SourceMap(String sourceMapData) {
public SourceMap(byte[] sourceMapData) {
parse(sourceMapData);
}

/**
* Parses the given contents containing a source map.
*/
private void parse(String sourceMapData) {
JsonObject sourceMapRoot = new JsonObject(sourceMapData);
private void parse(byte[] sourceMapData) {
JsonObject sourceMapRoot = new JsonObject(Buffer.buffer(sourceMapData));

// Check basic assertions about the format.
int version = sourceMapRoot.getInteger("version");
Expand Down
8 changes: 2 additions & 6 deletions es4x/src/test/java/io/reactiverse/es4x/MappingTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package io.reactiverse.es4x;

import io.reactiverse.es4x.impl.VertxFileSystem;
import io.reactiverse.es4x.sourcemap.SourceMap;
import io.vertx.core.Vertx;
import org.graalvm.polyglot.io.FileSystem;
import org.junit.Test;

import java.io.File;
Expand Down Expand Up @@ -37,9 +34,8 @@ public void testMapping() throws IOException {



SourceMap source = new SourceMap(new String(
Files.readAllBytes(new File("src/test/resources/bundle.js.map").toPath())
));
SourceMap source = new SourceMap(
Files.readAllBytes(new File("src/test/resources/bundle.js.map").toPath()));

source.eachMapping(System.out::println);

Expand Down
58 changes: 58 additions & 0 deletions es4x/src/test/java/io/reactiverse/es4x/test/JULFormatterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.reactiverse.es4x.test;

import io.reactiverse.es4x.jul.ANSIFormatter;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.RunTestOnContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Level;
import java.util.logging.LogRecord;

@RunWith(VertxUnitRunner.class)
public class JULFormatterTest {

@BeforeClass
public static void before() {
//System.setProperty("es4x.host.class.filter", "io.vertx.**,java.util.**,java.time.**,java.lang.**,java.net.**,io.reactiverse.es4x.**,!java.nio.file.FileAlreadyExistsException");
System.setProperty("es4x.host.class.filter", "!java.nio.file.FileAlreadyExistsException");
}

@AfterClass
public static void after() {
System.getProperties().remove("es4x.host.class.filter");
}

@Rule
public RunTestOnContext rule = new RunTestOnContext();

@Test(timeout = 10000)
public void shouldDeployVerticle(TestContext ctx) {
final Async async = ctx.async();
rule.vertx().deployVerticle("js:./verticle3.js", deploy -> {
ctx.assertFalse(deploy.succeeded());
ANSIFormatter formatter = new ANSIFormatter();
LogRecord item = new LogRecord(Level.ALL, "message");
item.setThrown(deploy.cause());
String out = formatter.format(item);
System.out.println(out);

try (StringWriter sw = new StringWriter()) {
PrintWriter pw = new PrintWriter(sw);
ANSIFormatter.printStackTrace(deploy.cause(), pw);
System.out.println(sw);
} catch (IOException e) {
// ignore
}
async.complete();
});
}
}
4 changes: 2 additions & 2 deletions generator/io.reactiverse/elasticsearch-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<parent>
<groupId>io.reactiverse.es4x</groupId>
<artifactId>es4x-generator</artifactId>
<version>0.16.1</version>
<version>0.16.2</version>
<relativePath>../..</relativePath>
</parent>

<artifactId>elasticsearch-client</artifactId>
<version>0.16.1</version>
<version>0.16.2</version>

<packaging>jar</packaging>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<parent>
<groupId>io.reactiverse.es4x</groupId>
<artifactId>es4x-generator</artifactId>
<version>0.16.1</version>
<version>0.16.2</version>
<relativePath>../..</relativePath>
</parent>

<artifactId>reactiverse-contextual-logging</artifactId>
<version>0.16.1</version>
<version>0.16.2</version>

<packaging>jar</packaging>

Expand All @@ -29,7 +29,7 @@
}
</npm-dependencies>
<logback.version>1.2.3</logback.version>
<log4j2.version>2.14.0</log4j2.version>
<log4j2.version>2.15.0</log4j2.version>
</properties>

<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions generator/io.vertx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<parent>
<groupId>io.reactiverse</groupId>
<artifactId>es4x-parent</artifactId>
<version>0.16.1</version>
<version>0.16.2</version>
<relativePath>../..</relativePath>
</parent>

<artifactId>es4x-vertx-stack</artifactId>
<version>0.16.1</version>
<version>0.16.2</version>

<dependencies>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions generator/io.vertx/vertx-amqp-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<parent>
<groupId>io.reactiverse.es4x</groupId>
<artifactId>es4x-generator</artifactId>
<version>0.16.1</version>
<version>0.16.2</version>
<relativePath>../..</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>vertx-amqp-client</artifactId>
<version>0.16.1</version>
<version>0.16.2</version>

<properties>
<maven.groupId>io.vertx</maven.groupId>
Expand Down
4 changes: 2 additions & 2 deletions generator/io.vertx/vertx-auth-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<parent>
<groupId>io.reactiverse.es4x</groupId>
<artifactId>es4x-generator</artifactId>
<version>0.16.1</version>
<version>0.16.2</version>
<relativePath>../..</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>vertx-auth-common</artifactId>
<version>0.16.1</version>
<version>0.16.2</version>

<properties>
<maven.groupId>io.vertx</maven.groupId>
Expand Down

0 comments on commit e9e48d2

Please sign in to comment.