Skip to content

Commit

Permalink
Enable java11
Browse files Browse the repository at this point in the history
* updated turbine
* added ability to exclude packages from compilation
  • Loading branch information
treblereel committed Jun 25, 2024
1 parent a820c53 commit ed8853a
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import java.util.Optional;
import java.util.Set;

@SupportedSourceVersion(SourceVersion.RELEASE_8)
@SupportedSourceVersion(SourceVersion.RELEASE_11)
public class MyProcessor extends AbstractProcessor {
@Override
public Set<String> getSupportedAnnotationTypes() {
Expand Down
62 changes: 62 additions & 0 deletions j2cl-maven-plugin/src/it/hello-world-super-source/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>hello-world-single</groupId>
<artifactId>hello-world-super-source</artifactId>
<version>1.0</version>
<packaging>war</packaging>

<dependencies>
<dependency>
<groupId>com.google.jsinterop</groupId>
<artifactId>jsinterop-annotations</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
<configuration>
<compilationLevel>ADVANCED</compilationLevel>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright © 2024 j2cl-maven-plugin authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package example.helloworld;

public class Test {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.lang;

public class NoSuchMethodException {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<module>
<super-source path="java"/>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<web-app></web-app>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script type="application/javascript" src="hello-world-single/hello-world-single.js"></script>
</head>
<body></body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.auto.service.AutoService;
import com.google.j2cl.common.SourceUtils;
import com.vertispan.j2cl.build.task.*;
import com.vertispan.j2cl.tools.J2CLModuleParser;
import com.vertispan.j2cl.tools.Javac;

import javax.annotation.Nullable;
Expand All @@ -36,6 +37,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -148,10 +150,19 @@ public Task resolve(Project project, Config config) {
File classOutputDir = context.outputPath().toFile();
Javac javac = new Javac(context, generatedClassesDir, sourcePaths, classpathDirs, classOutputDir, bootstrapClasspath, aptProcessors, annotationProcessorsArgs);

// Find the super-source path, if it exists
Optional<Path> superSource = J2CLModuleParser.getSuperSourcePath(sourcePaths);
Stream<? extends CachedPath> inputSourcesStream = inputSources.getFilesAndHashes()
.stream();

// Exclude super-source files from compilation
if(project.hasSourcesMapped() && superSource.isPresent()) {
inputSourcesStream = inputSourcesStream.filter(p -> !p.getSourcePath().startsWith(superSource.get()));
}

// TODO convention for mapping to original file paths, provide FileInfo out of Inputs instead of Paths,
// automatically relativized?
List<SourceUtils.FileInfo> sources = inputSources.getFilesAndHashes()
.stream()
List<SourceUtils.FileInfo> sources = inputSourcesStream
.map(p -> SourceUtils.FileInfo.create(p.getAbsolutePath().toString(), p.getSourcePath().toString()))
.collect(Collectors.toUnmodifiableList());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright © 2024 j2cl-maven-plugin authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.vertispan.j2cl.tools;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Optional;

public class J2CLModuleParser {

private static final DocumentBuilder db;

static {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(false);
dbf.setValidating(false);
dbf.setFeature("http://xml.org/sax/features/namespaces", false);
dbf.setFeature("http://xml.org/sax/features/validation", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
}
}

public static Optional<Path> getSuperSourcePath(Collection<File> files) {
for(File file : files) {
Optional<Path> superSourcePath = getSuperSourcePath(file.toPath());
if(superSourcePath.isPresent()) {
return superSourcePath;
}
}
return Optional.empty();
}


private static Optional<Path> getSuperSourcePath(Path p) {
Path modulePath = p.resolve("META-INF").resolve("module.j2cl.xml");
Document doc;
try {
doc = db.parse(modulePath.toFile());
} catch (SAXException | IOException e) {
return Optional.empty();
}
doc.getDocumentElement().normalize();
NodeList modules = doc.getElementsByTagName("module");
for (int i = 0; i < modules.getLength(); i++) {
Node module = modules.item(i);
for (int j = 0; j < module.getChildNodes().getLength(); j++) {
Node node = module.getChildNodes().item(j);
if(node.getNodeName().equals("super-source")) {
String path = node.getAttributes().getNamedItem("path").getNodeValue();
return Optional.of(Paths.get(path));
}
}
}
return Optional.empty();
}
}
2 changes: 2 additions & 0 deletions j2cl-tasks/src/main/java/com/vertispan/j2cl/tools/J2cl.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.vertispan.j2cl.tools;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.j2cl.common.OutputUtils;
import com.google.j2cl.common.SourceUtils;
import com.google.j2cl.common.Problems;
Expand Down Expand Up @@ -63,6 +64,7 @@ public boolean transpile(List<SourceUtils.FileInfo> sourcesToCompile, List<Sourc
.setOutput(output)
.setSources(sourcesToCompile)
.setNativeSources(nativeSources)
//.setKotlinCommonSources(Collections.emptyList())
.setKotlincOptions(ImmutableList.of())
.setWasmEntryPointStrings(ImmutableList.of())
.build(problems);
Expand Down
6 changes: 3 additions & 3 deletions j2cl-tasks/src/main/java/com/vertispan/j2cl/tools/Javac.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public Javac(BuildLog log, File generatedClassesPath, List<File> sourcePaths, Li
if (generatedClassesPath == null) {
javacOptions.add("-proc:none");
}
if (SourceVersion.latestSupported().compareTo(SourceVersion.RELEASE_8) > 0) {
//java 9+
javacOptions.add("--release=8");
if (SourceVersion.latestSupported().compareTo(SourceVersion.RELEASE_11) > 0) {
//java 11+
javacOptions.add("--release=11");
}
if (!processors.isEmpty()) {
javacOptions.add("-processor");
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<error.prone.annotations.version>2.1.3</error.prone.annotations.version>
<jsr305.version>3.0.2</jsr305.version>
<commons.lang3.version>3.8.1</commons.lang3.version>
<google.turbine.version>0.2.1</google.turbine.version>
<google.turbine.version>0.6.0</google.turbine.version>
<slf4j.api.version>1.7.5</slf4j.api.version>

<!-- Test goal -->
Expand Down

0 comments on commit ed8853a

Please sign in to comment.