Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #28

Merged
merged 10 commits into from
Jul 8, 2024
Merged
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Setup Chrome
uses: browser-actions/setup-chrome@v1.2.3
uses: browser-actions/setup-chrome@v1.7.1
- name: Checkout
uses: actions/checkout@v2
- name: Set up Java 11
Expand Down
2 changes: 1 addition & 1 deletion annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.treblereel.j2cl.processors</groupId>
<artifactId>parent</artifactId>
<version>0.6.3</version>
<version>0.7</version>
</parent>

<artifactId>annotations</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.treblereel.j2cl.processors</groupId>
<artifactId>parent</artifactId>
<version>0.6.3</version>
<version>0.7</version>
</parent>

<artifactId>common</artifactId>
Expand Down
43 changes: 14 additions & 29 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.treblereel.j2cl.processors</groupId>
<artifactId>parent</artifactId>
<version>0.6.3</version>
<version>0.7</version>
<packaging>pom</packaging>

<name>GWT3 processors parent</name>
Expand Down Expand Up @@ -42,8 +42,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.version>3.8.0</maven.compiler.version>
<maven.checkstyle.plugin.version>2.17</maven.checkstyle.plugin.version>
<maven.deploy.plugin.version>2.8.2</maven.deploy.plugin.version>
Expand All @@ -57,17 +57,17 @@
<maven.shade.plugin>3.2.4</maven.shade.plugin>
<maven.license.plugin>3.0</maven.license.plugin>

<com.google.elemental2.version>1.1.0</com.google.elemental2.version>
<com.google.elemental2.version>1.2.1</com.google.elemental2.version>
<com.google.jsinterop.annotations.version>2.0.0</com.google.jsinterop.annotations.version>
<j2cl.version>0.11.0-9336533b6</j2cl.version>
<j2cl.version>v20240622-2</j2cl.version>
<auto.common.version>0.11</auto.common.version>
<auto.service.version>1.0-rc7</auto.service.version>
<classgraph.version>4.8.141</classgraph.version>
<freemarker.version>2.3.30</freemarker.version>
<commons.io.version>2.8.0</commons.io.version>
<commons.text.version>1.2</commons.text.version>
<maven.aether.provider.version>3.3.9</maven.aether.provider.version>
<org.eclipse.aether.version>1.1.0</org.eclipse.aether.version>
<maven.resolver.version>1.9.20</maven.resolver.version>
<junit.version>4.11</junit.version>
</properties>

Expand All @@ -87,41 +87,26 @@
<version>${com.google.elemental2.version}</version>
</dependency>
<dependency>
<groupId>com.vertispan.j2cl</groupId>
<groupId>org.kie.j2cl.tools</groupId>
<artifactId>frontend-common</artifactId>
<version>${j2cl.version}</version>
</dependency>

<dependency>
<groupId>com.vertispan.j2cl</groupId>
<groupId>org.kie.j2cl.tools</groupId>
<artifactId>frontend-javac</artifactId>
<version>${j2cl.version}</version>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
<version>${maven.aether.provider.version}</version>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
<version>${maven.resolver.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-impl</artifactId>
<version>${org.eclipse.aether.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-file</artifactId>
<version>${org.eclipse.aether.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-http</artifactId>
<version>${org.eclipse.aether.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<version>${org.eclipse.aether.version}</version>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-supplier</artifactId>
<version>${maven.resolver.version}</version>
</dependency>

<dependency>
Expand Down
22 changes: 5 additions & 17 deletions processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.treblereel.j2cl.processors</groupId>
<artifactId>parent</artifactId>
<version>0.6.3</version>
<version>0.7</version>
</parent>

<artifactId>processors</artifactId>
Expand Down Expand Up @@ -87,24 +87,12 @@
<version>v20221004</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-impl</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-file</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-http</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-supplier</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.treblereel.j2cl.processors.generator.resources.GWT3ResourceGenerator;

@AutoService(Processor.class)
@SupportedSourceVersion(SourceVersion.RELEASE_8)
@SupportedSourceVersion(SourceVersion.RELEASE_11)
@SupportedAnnotationTypes({
"org.treblereel.j2cl.processors.annotations.GWT3EntryPoint",
"org.treblereel.j2cl.processors.annotations.ES6Module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.stream.Collectors;
import javax.lang.model.element.Element;
Expand Down Expand Up @@ -112,13 +114,13 @@ public void generate(Set<Element> elements) {
exports.put(checkClazz(parent), new HashSet<>());
exports.get(parent).addAll(methods);

ElementFilter.methodsIn(parent.getEnclosedElements()).stream()
getAllMethodsIn(parent).stream()
.filter(elm -> !elm.getModifiers().contains(Modifier.PRIVATE))
.filter(elm -> !elm.getModifiers().contains(Modifier.NATIVE))
.filter(elm -> !elm.getModifiers().contains(Modifier.ABSTRACT))
.forEach(elm -> exportDTOs.get(parent).addMethod(getMethodDTO(parent, elm)));

ElementFilter.fieldsIn(parent.getEnclosedElements()).stream()
getAllFieldsIn(parent).stream()
.filter(elm -> !elm.getModifiers().contains(Modifier.PRIVATE))
.filter(elm -> !elm.getModifiers().contains(Modifier.NATIVE))
.filter(elm -> !elm.getModifiers().contains(Modifier.ABSTRACT))
Expand Down Expand Up @@ -287,9 +289,8 @@ private TypeElement checkClazz(TypeElement parent) {
+ ", mustn't be annotated with @ES6Module");
}
Set<ExecutableElement> constructors =
ElementFilter.constructorsIn(parent.getEnclosedElements()).stream()
.collect(Collectors.toSet());
if (!constructors.isEmpty()) {
new HashSet<>(ElementFilter.constructorsIn(parent.getEnclosedElements()));
if (parent.getAnnotation(JsType.class) == null && !constructors.isEmpty()) {
constructors.stream()
.filter(elm -> elm.getModifiers().contains(Modifier.PUBLIC))
.filter(elm -> elm.getParameters().isEmpty())
Expand All @@ -305,4 +306,34 @@ private TypeElement checkClazz(TypeElement parent) {

return parent;
}

private Set<ExecutableElement> getAllMethodsIn(TypeElement parent) {
Set<ExecutableElement> elements = new HashSet<>();
Queue<TypeElement> queue = new LinkedList<>();
queue.add(parent);
while (!queue.isEmpty()) {
TypeElement current = queue.poll();
elements.addAll(ElementFilter.methodsIn(current.getEnclosedElements()));
if (!current.getSuperclass().toString().equals("java.lang.Object")
&& MoreTypes.asElement(current.getSuperclass()).getKind().isClass()) {
queue.offer((TypeElement) MoreTypes.asElement(current.getSuperclass()));
}
}
return elements;
}

private Set<VariableElement> getAllFieldsIn(TypeElement parent) {
Set<VariableElement> elements = new HashSet<>();
Queue<TypeElement> queue = new LinkedList<>();
queue.add(parent);
while (!queue.isEmpty()) {
TypeElement current = queue.poll();
elements.addAll(ElementFilter.fieldsIn(current.getEnclosedElements()));
if (!current.getSuperclass().toString().equals("java.lang.Object")
&& MoreTypes.asElement(current.getSuperclass()).getKind().isClass()) {
queue.offer((TypeElement) MoreTypes.asElement(current.getSuperclass()));
}
}
return elements;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,19 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.tools.FileObject;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.eclipse.aether.AbstractRepositoryListener;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
import org.eclipse.aether.impl.DefaultServiceLocator;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.ArtifactResult;
import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
import org.eclipse.aether.spi.connector.transport.TransporterFactory;
import org.eclipse.aether.supplier.RepositorySystemSupplier;
import org.eclipse.aether.transfer.AbstractTransferListener;
import org.eclipse.aether.transport.file.FileTransporterFactory;
import org.eclipse.aether.transport.http.HttpTransporterFactory;
import org.treblereel.j2cl.processors.exception.GenerationException;

class MavenArtifactDownloader {
Expand Down Expand Up @@ -137,19 +131,18 @@ private void download() {
this.artifact = artifactResult.getArtifact();
} catch (ArtifactResolutionException e) {
throw new GenerationException(e);
} finally {
system.shutdown();
}
}

private RepositorySystem newRepositorySystem() {
DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
locator.addService(TransporterFactory.class, FileTransporterFactory.class);
locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
return locator.getService(RepositorySystem.class);
RepositorySystemSupplier supplier = new RepositorySystemSupplier();
return supplier.get();
}

private RepositorySystemSession newSession(RepositorySystem system) {
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
LocalRepository localRepo = new LocalRepository(tempDir);
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
session.setTransferListener(new ConsoleTransferListener());
Expand Down
36 changes: 22 additions & 14 deletions processor/src/main/resources/templates/resources/export.ftlh
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
<#if !isNative>
/**
* @fileoverview
* @suppress {missingProperties}
*/
</#if>
goog.module('${module}$GWT3Export');

const EXPORT = goog.require('${target}');

<#if isNative>
goog.exportSymbol('${type}', EXPORT);
<#else>
const j_l_Object = goog.require('java.lang.Object$impl');
const $Util = goog.require('nativebootstrap.Util$impl');

class _EXPORT extends EXPORT {
constructor() {
EXPORT.$clinit();
super();
this.${ctor}();
<#list methods as method>
goog.exportSymbol('${type}.<#if !method.isStatic>prototype.</#if>${method.name}', EXPORT.<#if !method.isStatic>prototype.</#if>${method.mangleName});
</#list>
<#else>
const classProxy = new Proxy(EXPORT, {
construct(target, args) {
return EXPORT.$create__();
}
}

$Util.$setClassMetadata(_EXPORT, '${module}');
goog.exportSymbol('${type}', _EXPORT);
</#if>
});

EXPORT.$clinit();
goog.exportSymbol('${type}', classProxy);
<#list methods as method>
goog.exportSymbol('${type}.<#if !method.isStatic>prototype.</#if>${method.name}', EXPORT.<#if !method.isStatic>prototype.</#if>${method.mangleName});
<#if method.isStatic>
goog.exportProperty(EXPORT, '${method.name}', EXPORT.${method.mangleName});
<#else>
goog.exportSymbol('${type}.prototype.${method.name}', classProxy.prototype.${method.mangleName});
</#if>
</#list>
</#if>
Loading
Loading