Migrate to gradle

This commit is contained in:
Alexey Andreev 2023-01-03 15:29:13 +01:00
parent 2a0f6f206e
commit 8014c038c0
196 changed files with 4804 additions and 5006 deletions

6
.gitignore vendored
View File

@ -1,8 +1,14 @@
# output dir # output dir
target target
build
/build-dir /build-dir
/build-cache /build-cache
/deploy-with-env.sh /deploy-with-env.sh
/.gradle
/build-logic/.gradle
/relocated
/samples/.gradle
local.properties
# KDE # KDE
.directory .directory

View File

@ -13,6 +13,9 @@
</value> </value>
</option> </option>
</JavaCodeStyleSettings> </JavaCodeStyleSettings>
<ScalaCodeStyleSettings>
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
</ScalaCodeStyleSettings>
<codeStyleSettings language="HTML"> <codeStyleSettings language="HTML">
<indentOptions> <indentOptions>
<option name="INDENT_SIZE" value="2" /> <option name="INDENT_SIZE" value="2" />

View File

@ -0,0 +1,23 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="build" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="-x test --stacktrace" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="build" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,23 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="build samples" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$/samples" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="--stacktrace" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="build" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,23 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="publish locally" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="-x test --stacktrace" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="publishToMavenLocal" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>

View File

@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="run-tests (wasi)" type="JUnit" factoryName="JUnit"> <configuration default="false" name="run-tests (wasi)" type="JUnit" factoryName="JUnit">
<module name="teavm-tests" /> <module name="teavm.tests.test" />
<extension name="coverage"> <extension name="coverage">
<pattern> <pattern>
<option name="PATTERN" value="org.teavm.*" /> <option name="PATTERN" value="org.teavm.*" />

View File

@ -21,13 +21,16 @@ Useful links:
Building TeaVM Building TeaVM
-------------- --------------
Simply clone source code (`git clone https://github.com/konsoletyper/teavm.git`) and run maven build (`mvn clean install`). You can do things a little faster (`mvn clean -DskipTests`) or even a little more faster (`mvn clean -DskipTests -Dteavm.build.all=false`). Simply clone source code (`git clone https://github.com/konsoletyper/teavm.git`)
and run Gradle build (`gradle publishToMavenLocal`).
Preview builds Preview builds
-------------- --------------
You may want to access new features and don't want to wait until stable release is published on Maven Central. In this case you can get latest development build from [bintray](https://bintray.com/konsoletyper/teavm/teavm-dev). All you need is to put the following in your `pom.xml`: You may want to access new features and don't want to wait until stable release is published on Maven Central.
In this case you can get latest development build from [bintray](https://bintray.com/konsoletyper/teavm/teavm-dev).
All you need is to put the following in your `pom.xml`:
```xml ```xml
<repositories> <repositories>
@ -44,13 +47,21 @@ You may want to access new features and don't want to wait until stable release
</pluginRepositories> </pluginRepositories>
``` ```
IDEA plugin is also available in preview builds. You need to add corresponding repository manually to IDEA. Open *Settings* -> *Plugins* -> *Browse repositories...* -> *Manage repositories...*, click *Add* button and enter `https://teavm.org/idea/dev/teavmRepository.xml`. Then get back to *Browse repositories* and pick TeaVM plugin from list. IDEA plugin is also available in preview builds. You need to add corresponding repository manually to IDEA.
Open *Settings* -> *Plugins* -> *Browse repositories...* -> *Manage repositories...*, click *Add* button
and enter `https://teavm.org/idea/dev/teavmRepository.xml`.
Then get back to *Browse repositories* and pick TeaVM plugin from list.
Embedding TeaVM Embedding TeaVM
--------------- ---------------
If you are not satisfied with Maven, you can embed TeaVM in your program or even create your own plugin for any build tool, like Ant or Gradle. The starting point for you may be `org.teavm.tooling.TeaVMTool` class from `teavm-tooling` artifact. You may want to go deeper and use `org.teavm.vm.TeaVM` from `teavm-core` artifact, learn how `TeaVMTool` initializes it. To learn how to use `TeaVMTool` class itself, find its usages across project source code. You most likely encounter Maven and IDEA plugins. If you are not satisfied with Maven, you can embed TeaVM in your program
or even create your own plugin for any build tool, like Ant or Gradle.
The starting point for you may be `org.teavm.tooling.TeaVMTool` class from `teavm-tooling` artifact.
You may want to go deeper and use `org.teavm.vm.TeaVM` from `teavm-core` artifact, learn how `TeaVMTool` initializes it.
To learn how to use `TeaVMTool` class itself, find its usages across project source code.
You most likely encounter Maven and IDEA plugins.
Please, notice that these APIs for embedding are still unstable and may change between versions. Please, notice that these APIs for embedding are still unstable and may change between versions.
@ -58,7 +69,13 @@ Please, notice that these APIs for embedding are still unstable and may change b
WebAssembly WebAssembly
----------- -----------
WebAssembly support is in experimental status. It may lack major features available in JavaScript backend. There's no documentation yet and you should do many things by hands (like embedding generated `wasm` file into your page, importing JavaScript objects, etc). Look at [samples/benchmark](https://github.com/konsoletyper/teavm/blob/master/samples/benchmark/) module. You should first examine `pom.xml` file to learn how to build `wasm` file from Java. Then you may want to examine `index-teavm.html` and `index-teavm.js` to learn how to embed WebAssembly into your web page. WebAssembly support is in experimental status. It may lack major features available in JavaScript backend.
There's no documentation yet and you should do many things by hands
(like embedding generated `wasm` file into your page, importing JavaScript objects, etc).
Look at [samples/benchmark](https://github.com/konsoletyper/teavm/blob/master/samples/benchmark/) module.
You should first examine `pom.xml` file to learn how to build `wasm` file from Java.
Then you may want to examine `index-teavm.html` and `index-teavm.js`
to learn how to embed WebAssembly into your web page.
License License
@ -66,13 +83,15 @@ License
TeaVM is distributed under [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). TeaVM is distributed under [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).
TeaVM does not rely on OpenJDK or code or other (L)GPL code. TeaVM does not rely on OpenJDK or code or other (L)GPL code.
TeaVM has its own reimplementation of Java class library, which is either implemented from scratch or based on non-(L)GPL projects: TeaVM has its own reimplementation of Java class library, which is either implemented from scratch or
based on non-(L)GPL projects:
* [Apache Harmony](https://harmony.apache.org/) (Apache 2.0) * [Apache Harmony](https://harmony.apache.org/) (Apache 2.0)
* [Joda-Time](https://github.com/JodaOrg/joda-time) (Apache 2.0) * [Joda-Time](https://github.com/JodaOrg/joda-time) (Apache 2.0)
* [jzlib](https://github.com/ymnk/jzlib) (BSD style license) * [jzlib](https://github.com/ymnk/jzlib) (BSD style license)
If you want to contribute code to implementation of Java class library, please make sure it's no based on OpenJDK or other code licensed under (L)GPL. If you want to contribute code to implementation of Java class library,
please make sure it's no based on OpenJDK or other code licensed under (L)GPL.
Feedback Feedback
@ -80,4 +99,5 @@ Feedback
More information is available at the official site: https://teavm.org. More information is available at the official site: https://teavm.org.
Ask your questions by email: info@teavm.org. Also you can report issues on a project's [issue tracker](https://github.com/konsoletyper/teavm/issues). Ask your questions by email: info@teavm.org. Also you can report issues on a project's
[issue tracker](https://github.com/konsoletyper/teavm/issues).

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="teavm-classlib" exported="" />
<orderEntry type="module" module-name="teavm-cli" exported="" />
<orderEntry type="module" module-name="teavm-core" exported="" />
<orderEntry type="module" module-name="teavm-jso-apis" exported="" />
<orderEntry type="module" module-name="teavm-jso-impl" exported="" />
<orderEntry type="module" module-name="teavm-metaprogramming-api" exported="" />
<orderEntry type="module" module-name="teavm-platform" exported="" />
<orderEntry type="module" module-name="teavm-tests" exported="" />
<orderEntry type="module" module-name="teavm-tooling" exported="" />
<orderEntry type="module" module-name="teavm-samples-async" exported="" />
<orderEntry type="module" module-name="teavm-samples-benchmark" exported="" />
<orderEntry type="module" module-name="teavm-samples-hello" exported="" />
<orderEntry type="module" module-name="teavm-samples-kotlin" exported="" />
<orderEntry type="module" module-name="teavm-samples-scala" exported="" />
<orderEntry type="module" module-name="teavm-samples-storage" exported="" />
<orderEntry type="module" module-name="teavm-samples-video" exported="" />
</component>
<component name="teavm">
<option name="mainClass" value="" />
<option name="targetDirectory" value="" />
</component>
</module>

View File

@ -0,0 +1,90 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
`java-gradle-plugin`
checkstyle
}
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
dependencies {
implementation(libs.shadowPlugin)
implementation(libs.maven.plugin.tools.api)
implementation(libs.maven.plugin.tools.generators)
implementation(libs.maven.plugin.tools.annotations)
implementation(libs.maven.embedder)
implementation(libs.maven.compat)
}
gradlePlugin {
plugins {
create("teavm-publish") {
id = "teavm-publish"
implementationClass = "org.teavm.buildutil.PublishTeaVMPlugin"
}
create("dependency-relocation") {
id = "dependency-relocation"
implementationClass = "org.teavm.buildutil.DependencyRelocationPlugin"
}
create("shadowApply") {
id = "shadowApply"
implementationClass = "org.teavm.buildutil.ShadowApplyPlugin"
}
create("mavenPlugin") {
id = "mavenPlugin"
implementationClass = "org.teavm.buildutil.MavenPluginPlugin"
}
}
}
checkstyle {
toolVersion = libs.versions.checkstyle.get()
configDirectory.set(project.layout.projectDirectory.dir("../config/checkstyle"))
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
val generatedConfigDir = project.layout.buildDirectory.dir("generated/config").get()
val generateConfig by tasks.registering {
val file = generatedConfigDir.file("org/teavm/buildutil/Config.java").asFile
outputs.file(file)
doLast {
file.parentFile.mkdirs()
file.writeText("""
package org.teavm.buildutil;
class Config {
static final String MAVEN_PLUGIN_API = "${libs.maven.plugin.api.get()}";
static final String MAVEN_PLUGIN_ANNOTATIONS = "${libs.maven.plugin.annotations.get()}";
static final String MAVEN_ARTIFACT = "${libs.maven.artifact.get()}";
static final String MAVEN_CORE = "${libs.maven.core.get()}";
}
""".trimIndent())
}
}
tasks.compileJava.configure { dependsOn(generateConfig) }
sourceSets.main.configure { java.srcDir(generatedConfigDir) }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2015 Jaroslav Tulach. * Copyright 2023 Alexey Andreev.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,20 +13,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.teavm.samples.benchmark.htmljava;
import net.java.html.boot.BrowserBuilder; dependencyResolutionManagement {
versionCatalogs {
public final class BenchmarkFX { create("libs") {
private BenchmarkFX() { from(files("../gradle/libs.versions.toml"))
}
} }
public static void main(String... args) {
BrowserBuilder.newBrowser().loadPage("fx.html")
.loadClass(BenchmarkStarter.class)
.invoke("main")
.showAndWait();
System.exit(0);
}
} }

View File

@ -0,0 +1,28 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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 org.teavm.buildutil;
import org.gradle.api.Action;
public interface DependencyRelocationExtension {
void library(String libs, String alias, Action<DependencyRelocationLibrary> action);
String getArtifactIdPrefix();
void setArtifactIdPrefix(String prefix);
void skip(String project);
}

View File

@ -0,0 +1,274 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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 org.teavm.buildutil;
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.ModuleIdentifier;
import org.gradle.api.artifacts.VersionCatalogsExtension;
import org.gradle.api.artifacts.component.ModuleComponentSelector;
import org.gradle.api.artifacts.component.ProjectComponentSelector;
import org.gradle.api.artifacts.result.ResolvedDependencyResult;
import org.gradle.api.attributes.Usage;
import org.gradle.api.initialization.Settings;
import org.gradle.api.plugins.JavaLibraryPlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.plugins.catalog.VersionCatalogPlugin;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import org.gradle.jvm.tasks.Jar;
class DependencyRelocationExtensionImpl implements DependencyRelocationExtension {
private static final String RELOCATE_JAR = "relocateJar";
private Settings target;
private Map<String, RelocatedDependency> depsByProjectPath = new LinkedHashMap<>();
private String artifactIdPrefix;
private Set<String> skippedProjects = new HashSet<>();
DependencyRelocationExtensionImpl(Settings target) {
this.target = target;
target.getGradle().afterProject(project -> {
var dependency = depsByProjectPath.get(project.getPath());
if (dependency != null) {
setupSynthesizedProject(project, dependency);
} else {
setupConsumingProject(project);
}
});
}
private void setupSynthesizedProject(Project project, RelocatedDependency dependency) {
project.getPlugins().apply(VersionCatalogPlugin.class);
project.getPlugins().apply(JavaLibraryPlugin.class);
project.getPlugins().apply(PublishTeaVMPlugin.class);
var synthesizedProjects = new HashMap<ModuleIdentifier, String>();
for (var dep : depsByProjectPath.values()) {
var lib = project.getExtensions().getByType(VersionCatalogsExtension.class).named(dep.libs)
.findLibrary(dep.alias).get().get();
synthesizedProjects.put(lib.getModule(), dep.projectPath);
}
var library = project.getExtensions().getByType(VersionCatalogsExtension.class).named(dependency.libs)
.findLibrary(dependency.alias).get().get();
var libraryDep = project.getDependencies().create(library);
project.getDependencies().add(JavaPlugin.COMPILE_ONLY_API_CONFIGURATION_NAME, library);
copyLibraryDeps(project, libraryDep, Usage.JAVA_RUNTIME, JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME,
synthesizedProjects);
project.setGroup(project.getRootProject().getGroup());
var prefix = artifactIdPrefix != null ? artifactIdPrefix : project.getRootProject().getName() + "-relocated";
var fullArtifactId = prefix + "-" + dependency.libs + "-" + dependency.alias;
project.getExtensions().configure(PublishTeaVMExtension.class, extension -> {
extension.setArtifactId(fullArtifactId);
});
var config = project.getConfigurations().detachedConfiguration(project.getDependencies().create(library));
config.setTransitive(false);
setupRelocation(project, config, dependency.relocations);
}
private void replaceArtifacts(Project project, String configurationName, Task task) {
var configuration = project.getConfigurations().getByName(configurationName);
configuration.getArtifacts().clear();
project.getArtifacts().add(configurationName, task);
}
private void copyLibraryDeps(Project project, Dependency dependency, String usage, String targetConfig,
Map<ModuleIdentifier, String> synthesizedProjects) {
var detachedConfig = project.getConfigurations().detachedConfiguration(
project.getDependencies().create(dependency));
detachedConfig.setTransitive(true);
detachedConfig.getAttributes().attribute(Usage.USAGE_ATTRIBUTE,
project.getObjects().named(Usage.class, usage));
var root = detachedConfig.getIncoming().getResolutionResult().getRoot().getDependencies().iterator().next();
if (root instanceof ResolvedDependencyResult) {
var rootComponent = ((ResolvedDependencyResult) root).getSelected();
for (var dep : rootComponent.getDependencies()) {
var requested = dep.getRequested();
if (requested instanceof ModuleComponentSelector) {
var moduleDep = (ModuleComponentSelector) requested;
var replacement = synthesizedProjects.get(moduleDep.getModuleIdentifier());
if (replacement != null) {
var notation = new HashMap<String, String>();
notation.put("path", replacement);
project.getDependencies().add(targetConfig,
project.getDependencies().project(notation));
} else {
project.getDependencies().add(targetConfig,
moduleDep.getGroup() + ":" + moduleDep.getModule() + ":" + moduleDep.getVersion());
}
} else if (requested instanceof ProjectComponentSelector) {
var projectDep = (ProjectComponentSelector) requested;
var notation = new HashMap<String, String>();
notation.put("path", projectDep.getProjectPath());
project.getDependencies().add(targetConfig, project.getDependencies().project(notation));
}
}
}
}
private void setupConsumingProject(Project project) {
if (skippedProjects.contains(project.getPath())
|| project.getExtensions().findByType(JavaPluginExtension.class) == null) {
return;
}
var relocations = new ArrayList<Relocation>();
var depsByLibrary = new LinkedHashMap<Dependency, RelocatedDependency>();
for (var dependency : depsByProjectPath.values()) {
var library = project.getExtensions().getByType(VersionCatalogsExtension.class).named(dependency.libs)
.findLibrary(dependency.alias).get().get();
if (library != null) {
depsByLibrary.put(project.getDependencies().create(library), dependency);
}
relocations.addAll(dependency.relocations);
}
replaceDependencies(
project,
JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME,
Arrays.asList(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME,
JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME),
Arrays.asList(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME,
JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME,
JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME),
depsByLibrary
);
var sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
var main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
var sourceDirs = main.getOutput();
setupRelocation(project, sourceDirs, relocations);
}
private void replaceDependencies(Project project, String configurationName,
List<String> runtimeConfigurations, List<String> compileConfigurations,
Map<Dependency, RelocatedDependency> depsByLibrary) {
var config = project.getConfigurations().findByName(configurationName);
if (config == null) {
return;
}
for (var iterator = config.getDependencies().iterator(); iterator.hasNext(); ) {
var dependency = iterator.next();
var relocatedDep = depsByLibrary.get(dependency);
if (relocatedDep != null) {
var projectNotation = new HashMap<String, String>();
projectNotation.put("path", relocatedDep.projectPath);
for (var runtimeConfiguration : runtimeConfigurations) {
if (project.getConfigurations().findByName(runtimeConfiguration) != null) {
project.getDependencies().add(runtimeConfiguration,
project.getDependencies().project(projectNotation));
}
}
for (var compileConfiguration : compileConfigurations) {
project.getDependencies().add(compileConfiguration, dependency);
}
iterator.remove();
}
}
}
private void setupRelocation(Project project, Object input, List<Relocation> relocations) {
if (project.getTasks().findByPath(JavaPlugin.JAR_TASK_NAME) == null) {
return;
}
project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class, jar -> {
jar.getArchiveClassifier().set("original");
});
var relocateTask = project.getTasks().create(RELOCATE_JAR, ShadowJar.class, task -> {
task.getArchiveClassifier().set("");
task.from(input);
for (var relocation : relocations) {
task.relocate(relocation.src, relocation.dest);
}
project.getTasks().getByName("assemble").dependsOn(task);
});
project.getTasks().withType(AbstractArchiveTask.class, archive -> {
archive.setPreserveFileTimestamps(false);
archive.setReproducibleFileOrder(true);
});
replaceArtifacts(project, JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, relocateTask);
replaceArtifacts(project, JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, relocateTask);
}
@Override
public void library(String libs, String alias, Action<DependencyRelocationLibrary> action) {
var projectName = "relocated:" + libs + ":" + alias;
var projectPath = ":" + projectName;
target.include(projectName);
target.project(projectPath).setProjectDir(new File(target.getRootDir(), "relocated/" + libs + "/" + alias));
var dependency = new RelocatedDependency(projectPath, libs, alias);
depsByProjectPath.put(projectPath, dependency);
action.execute((src, dest) -> {
dependency.relocations.add(new Relocation(src, dest));
});
}
@Override
public String getArtifactIdPrefix() {
return artifactIdPrefix;
}
@Override
public void setArtifactIdPrefix(String prefix) {
artifactIdPrefix = prefix;
}
@Override
public void skip(String project) {
skippedProjects.add(project);
}
static class RelocatedDependency {
String projectPath;
String libs;
String alias;
List<Relocation> relocations = new ArrayList<>();
RelocatedDependency(String projectPath, String libs, String alias) {
this.projectPath = projectPath;
this.libs = libs;
this.alias = alias;
}
}
static class Relocation {
String src;
String dest;
Relocation(String src, String dest) {
this.src = src;
this.dest = dest;
}
}
}

View File

@ -0,0 +1,20 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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 org.teavm.buildutil;
public interface DependencyRelocationLibrary {
void relocate(String from, String to);
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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 org.teavm.buildutil;
import org.gradle.api.Plugin;
import org.gradle.api.initialization.Settings;
public class DependencyRelocationPlugin implements Plugin<Settings> {
@Override
public void apply(Settings target) {
var extensions = new DependencyRelocationExtensionImpl(target);
target.getExtensions().add("dependencyRelocation", extensions);
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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 org.teavm.buildutil;
import java.io.Serializable;
public class MavenArtifact implements Serializable {
public final String groupId;
public final String artifactId;
public final String version;
public MavenArtifact(String groupId, String artifactId, String version) {
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
}
}

View File

@ -0,0 +1,115 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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 org.teavm.buildutil;
import java.io.File;
import javax.inject.Inject;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
import org.apache.maven.tools.plugin.extractor.ExtractionException;
import org.apache.maven.tools.plugin.generator.GeneratorException;
import org.apache.maven.tools.plugin.generator.PluginDescriptorFilesGenerator;
import org.apache.maven.tools.plugin.scanner.MojoScanner;
import org.codehaus.plexus.DefaultContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.gradle.api.DefaultTask;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.TaskAction;
public abstract class MavenPluginDescriptorTask extends DefaultTask {
@Input
public abstract Property<String> getGroupId();
@Input
public abstract Property<String> getArtifactId();
@Input
public abstract Property<String> getVersion();
@Input
public abstract Property<String> getPluginName();
@Input
@Optional
public abstract Property<String> getPluginDescription();
@InputDirectory
public abstract Property<File> getClassesDirectory();
@OutputDirectory
public abstract Property<File> getOutputDirectory();
@Inject
public MavenPluginDescriptorTask() {
var project = getProject();
getPluginName().convention(project.provider(project::getName));
getPluginDescription().convention(project.provider(() -> project.getDescription() != null
? project.getDescription() : ""));
getVersion().convention(project.provider(() -> project.getVersion().toString()));
getGroupId().convention(project.provider(() -> project.getGroup().toString()));
getArtifactId().convention(project.provider(project::getName));
}
@TaskAction
public void generate() throws ExtractionException, InvalidPluginDescriptorException, GeneratorException,
PlexusContainerException, ComponentLookupException {
var cc = new DefaultContainerConfiguration()
.setClassPathScanning(PlexusConstants.SCANNING_INDEX)
.setAutoWiring(true)
.setJSR250Lifecycle(true)
.setName("maven");
var container = new DefaultPlexusContainer(cc);
var scanner = container.lookup(MojoScanner.class);
var descriptor = new PluginDescriptor();
descriptor.setGroupId(getGroupId().get());
descriptor.setArtifactId(getArtifactId().get());
descriptor.setVersion(getVersion().get());
descriptor.setName(getPluginName().get());
descriptor.setDescription(getPluginDescription().get());
var project = new MavenProject();
project.getBuild().setOutputDirectory(getClassesDirectory().get().getAbsolutePath());
project.getBuild().setDirectory(getOutputDirectory().get().getAbsolutePath());
project.setGroupId(getGroupId().get());
project.setArtifactId(getArtifactId().get());
project.setVersion(getVersion().get());
project.setArtifact(new DefaultArtifact(getGroupId().get(), getArtifactId().get(),
getVersion().get(), "compile", "jar", "", new DefaultArtifactHandler()));
var request = new DefaultPluginToolsRequest(project, descriptor);
request.setEncoding("UTF-8");
request.setSkipErrorNoDescriptorsFound(false);
scanner.populatePluginDescriptor(request);
var out = getOutputDirectory().get();
out.getParentFile().mkdirs();
var pluginDescriptorGenerator = new PluginDescriptorFilesGenerator();
pluginDescriptorGenerator.execute(out, request);
}
}

View File

@ -0,0 +1,73 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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 org.teavm.buildutil;
import java.io.File;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaLibraryPlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.tasks.SourceSetContainer;
public class MavenPluginPlugin implements Plugin<Project> {
private static final String GENERATED_DIR = "generated/resources/maven-plugin";
private static final String PLUGIN_DIR = "META-INF/maven";
@Override
public void apply(Project project) {
project.getPlugins().apply(JavaLibraryPlugin.class);
installDependencies(project);
var generatedDir = new File(project.getBuildDir(), GENERATED_DIR);
var pluginDir = new File(generatedDir, PLUGIN_DIR);
var task = project.getTasks().create("generateMavenPluginDescriptor", MavenPluginDescriptorTask.class);
task.getOutputDirectory().convention(pluginDir);
var thisArtifact = project.provider(() -> getProjectArtifact(project));
task.getGroupId().convention(thisArtifact.map(a -> a.groupId));
task.getArtifactId().convention(thisArtifact.map(a -> a.artifactId));
task.getVersion().convention(thisArtifact.map(a -> a.version));
var sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
var main = sourceSets.getByName("main");
task.getClassesDirectory().convention(main.getOutput().getClassesDirs().getSingleFile());
task.dependsOn(project.getTasks().getByName(JavaPlugin.CLASSES_TASK_NAME));
main.getOutput().dir(generatedDir);
}
private void installDependencies(Project project) {
var config = JavaPlugin.COMPILE_ONLY_API_CONFIGURATION_NAME;
project.getDependencies().add(config, Config.MAVEN_PLUGIN_API);
project.getDependencies().add(config, Config.MAVEN_PLUGIN_ANNOTATIONS);
project.getDependencies().add(config, Config.MAVEN_ARTIFACT);
project.getDependencies().add(config, Config.MAVEN_CORE);
}
private MavenArtifact getProjectArtifact(Project project) {
var ext = project.getExtensions().getByType(PublishingExtension.class);
for (var publication : ext.getPublications()) {
if (publication instanceof MavenPublication) {
var mavenPublication = (MavenPublication) publication;
return new MavenArtifact(mavenPublication.getGroupId(), mavenPublication.getArtifactId(),
mavenPublication.getVersion());
}
}
return new MavenArtifact(project.getGroup().toString(), project.getName(), project.getVersion().toString());
}
}

View File

@ -0,0 +1,22 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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 org.teavm.buildutil;
public interface PublishTeaVMExtension {
String getArtifactId();
void setArtifactId(String artifactId);
}

View File

@ -0,0 +1,93 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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 org.teavm.buildutil;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
import org.gradle.api.publish.plugins.PublishingPlugin;
import org.gradle.api.tasks.javadoc.Javadoc;
import org.gradle.external.javadoc.CoreJavadocOptions;
public abstract class PublishTeaVMPlugin implements Plugin<Project> {
private static final String EXTENSION_NAME = "teavmPublish";
@Override
public void apply(Project target) {
target.getPlugins().apply(PublishingPlugin.class);
target.getPlugins().apply(MavenPublishPlugin.class);
var extension = new ExtensionImpl();
target.getExtensions().add(PublishTeaVMExtension.class, EXTENSION_NAME, extension);
target.afterEvaluate(p -> target.getExtensions().configure(PublishingExtension.class, publishing -> {
publishing.publications(publications -> {
publications.create("java", MavenPublication.class, publication -> {
customizePublication(target, publication, extension);
});
});
publishing.repositories(repositories -> {
var url = target.getProviders().gradleProperty("teavm.publish.url");
if (url.isPresent()) {
repositories.maven(repository -> {
repository.setName("teavm");
repository.setUrl(url.get());
repository.getCredentials().setUsername(target.getProviders().gradleProperty(
"teavm.publish.username").get());
repository.getCredentials().setPassword(target.getProviders().gradleProperty(
"teavm.publish.password").get());
});
}
repositories.mavenCentral();
});
}));
target.getExtensions().configure(JavaPluginExtension.class, ext -> {
ext.withSourcesJar();
ext.withJavadocJar();
});
target.getTasks().withType(Javadoc.class, task -> {
var options = (CoreJavadocOptions) task.getOptions();
options.addStringOption("Xdoclint:none", "-quiet");
});
}
private void customizePublication(Project project, MavenPublication publication, ExtensionImpl extension) {
publication.setGroupId("org.teavm");
if (extension.getArtifactId() != null) {
publication.setArtifactId(extension.getArtifactId());
}
publication.from(project.getComponents().getByName("java"));
}
private static class ExtensionImpl implements PublishTeaVMExtension {
private String artifactId;
@Override
public String getArtifactId() {
return artifactId;
}
@Override
public void setArtifactId(String artifactId) {
this.artifactId = artifactId;
}
}
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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 org.teavm.buildutil;
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
public class ShadowApplyPlugin implements Plugin<Project> {
@Override
public void apply(Project target) {
target.getPlugins().apply(ShadowPlugin.class);
}
}

17
build.gradle.kts Normal file
View File

@ -0,0 +1,17 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
group = "org.teavm"

61
classlib/build.gradle.kts Normal file
View File

@ -0,0 +1,61 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
`java-library`
`teavm-publish`
}
description = "Java class library emulation"
dependencies {
compileOnly(project(":core"))
implementation(project(":platform"))
implementation(project(":jso:apis"))
implementation(project(":jso:impl"))
implementation(project(":metaprogramming:impl"))
implementation(libs.commons.io)
implementation(libs.gson)
implementation(libs.jzlib)
implementation(libs.jodaTime)
testImplementation(libs.junit)
testImplementation(project(":core"))
}
tasks {
val generatedClassesDir = File(buildDir, "generated/classes/java/main")
val generateTzCache by registering(JavaExec::class) {
val outputFile = File(generatedClassesDir, "org/teavm/classlib/impl/tz/cache")
classpath(sourceSets.main.get().runtimeClasspath, sourceSets.main.get().compileClasspath)
outputs.file(outputFile)
inputs.files(sourceSets.main.get().runtimeClasspath)
dependsOn(compileJava)
mainClass.set("org.teavm.classlib.impl.tz.TimeZoneCache")
args(outputFile.absolutePath)
}
jar {
dependsOn(generateTzCache)
from(generatedClassesDir)
exclude("html/**")
exclude("org/teavm/classlib/impl/tz/tzdata*.zip")
}
}
teavmPublish {
artifactId = "teavm-classlib"
}

View File

@ -1,175 +0,0 @@
<!--
Copyright 2013 Alexey Andreev.
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.
-->
<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>
<parent>
<groupId>org.teavm</groupId>
<artifactId>teavm</artifactId>
<version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>teavm-classlib</artifactId>
<name>TeaVM Java class library</name>
<description>TeaVM Java class library emulation</description>
<properties>
<teavm.classlib.test.incremental>false</teavm.classlib.test.incremental>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-platform</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso-apis</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso-impl</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-metaprogramming-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-metaprogramming-impl</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jzlib</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-tz-cache</id>
<goals>
<goal>java</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<mainClass>org.teavm.classlib.impl.tz.TimeZoneCache</mainClass>
<arguments>
<argument>${project.build.directory}/classes/org/teavm/classlib/impl/tz/cache</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>html/**</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>org.teavm:teavm-classlib</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.objectweb.asm</pattern>
<shadedPattern>org.teavm.asm</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -35,33 +35,6 @@ package org.teavm.classlib.java.util.regex;
import java.util.ArrayList; import java.util.ArrayList;
/**
* Provides a means of matching regular expressions against a given input,
* finding occurrences of regular expressions in a given input, or replacing
* parts of a given input. A {@code Matcher} instance has an associated
* {@link TPattern} instance and an input text. A typical use case is to
* iteratively find all occurrences of the {@code Pattern}, until the end of the
* input is reached, as the following example illustrates:
*
* <p/>
*
* <pre>
* Pattern p = Pattern.compile(&quot;[A-Za-z]+&quot;);
*
* Matcher m = p.matcher(&quot;Hello, Android!&quot;);
* while (m.find()) {
* System.out.println(m.group()); // prints &quot;Hello&quot; and &quot;Android&quot;
* }
* </pre>
*
* <p/>
*
* The {@code Matcher} has a state that results from the previous operations.
* For example, it knows whether the most recent attempt to find the
* {@code Pattern} was successful and at which position the next attempt would
* resume the search. Depending on the application's needs, it may become
* necessary to explicitly {@link #reset()} this state from time to time.
*/
public final class TMatcher implements TMatchResult { public final class TMatcher implements TMatchResult {
static final int MODE_FIND = 1; static final int MODE_FIND = 1;

View File

@ -39,36 +39,6 @@ package org.teavm.classlib.java.util.regex;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
/**
* Represents a pattern used for matching, searching, or replacing strings.
* {@code Pattern}s are specified in terms of regular expressions and compiled
* using an instance of this class. They are then used in conjunction with a
* {@link TMatcher} to perform the actual search.
* <p/>
* A typical use case looks like this:
* <p/>
*
* <pre>
* Pattern p = Pattern.compile(&quot;Hello, A[a-z]*!&quot;);
*
* Matcher m = p.matcher(&quot;Hello, Android!&quot;);
* boolean b1 = m.matches(); // true
*
* m.setInput(&quot;Hello, Robot!&quot;);
* boolean b2 = m.matches(); // false
* </pre>
* <p/>
* The above code could also be written in a more compact fashion, though this
* variant is less efficient, since {@code Pattern} and {@code Matcher} objects
* are created on the fly instead of being reused. fashion:
*
* <pre>
* boolean b1 = Pattern.matches(&quot;Hello, A[a-z]*!&quot;, &quot;Hello, Android!&quot;); // true
* boolean b2 = Pattern.matches(&quot;Hello, A[a-z]*!&quot;, &quot;Hello, Robot!&quot;); // false
* </pre>
*
* @see TMatcher
*/
public final class TPattern implements Serializable { public final class TPattern implements Serializable {
private static final long serialVersionUID = 5073258162644648461L; private static final long serialVersionUID = 5073258162644648461L;

View File

@ -1261,7 +1261,7 @@ public final class OffsetTime
* Outputs this time as a {@code String}, such as {@code 10:15:30+01:00}. * Outputs this time as a {@code String}, such as {@code 10:15:30+01:00}.
* <p> * <p>
* The output will be one of the following ISO-8601 formats: * The output will be one of the following ISO-8601 formats:
* <p><ul> * <ul>
* <li>{@code HH:mmXXXXX}</li> * <li>{@code HH:mmXXXXX}</li>
* <li>{@code HH:mm:ssXXXXX}</li> * <li>{@code HH:mm:ssXXXXX}</li>
* <li>{@code HH:mm:ss.SSSXXXXX}</li> * <li>{@code HH:mm:ss.SSSXXXXX}</li>

View File

@ -149,7 +149,7 @@ public final class ZoneOffset
* This method parses the string ID of a {@code ZoneOffset} to * This method parses the string ID of a {@code ZoneOffset} to
* return an instance. The parsing accepts all the formats generated by * return an instance. The parsing accepts all the formats generated by
* {@link #getId()}, plus some additional formats: * {@link #getId()}, plus some additional formats:
* <p><ul> * <ul>
* <li>{@code Z} - for UTC * <li>{@code Z} - for UTC
* <li>{@code +h} * <li>{@code +h}
* <li>{@code +hh} * <li>{@code +hh}
@ -452,7 +452,7 @@ public final class ZoneOffset
* <p> * <p>
* The ID is minor variation to the standard ISO-8601 formatted string * The ID is minor variation to the standard ISO-8601 formatted string
* for the offset. There are three formats: * for the offset. There are three formats:
* <p><ul> * <ul>
* <li>{@code Z} - for UTC (ISO-8601) * <li>{@code Z} - for UTC (ISO-8601)
* <li>{@code +hh:mm} or {@code -hh:mm} - if the seconds are zero (ISO-8601) * <li>{@code +hh:mm} or {@code -hh:mm} - if the seconds are zero (ISO-8601)
* <li>{@code +hh:mm:ss} or {@code -hh:mm:ss} - if the seconds are non-zero (not ISO-8601) * <li>{@code +hh:mm:ss} or {@code -hh:mm:ss} - if the seconds are non-zero (not ISO-8601)

View File

@ -105,7 +105,7 @@ import org.threeten.bp.jdk8.Jdk8Methods;
* The earliest period is referred to as week 0 if it has less than the minimal number of days * The earliest period is referred to as week 0 if it has less than the minimal number of days
* and week 1 if it has at least the minimal number of days. * and week 1 if it has at least the minimal number of days.
* <p> * <p>
* <table cellpadding="0" cellspacing="3" border="0" style="text-align: left; width: 50%;"> * <table style="text-align: left; width: 50%;">
* <caption>Examples of WeekFields</caption> * <caption>Examples of WeekFields</caption>
* <tr><th>Date</th><td>Day-of-week</td> * <tr><th>Date</th><td>Day-of-week</td>
* <td>First day: Monday<br>Minimal days: 4</td><td>First day: Monday<br>Minimal days: 5</td></tr> * <td>First day: Monday<br>Minimal days: 4</td><td>First day: Monday<br>Minimal days: 5</td></tr>

View File

@ -198,16 +198,16 @@ public abstract class ZoneRules {
* <p> * <p>
* There are various ways to handle the conversion from a {@code LocalDateTime}. * There are various ways to handle the conversion from a {@code LocalDateTime}.
* One technique, using this method, would be: * One technique, using this method, would be:
* <pre> * <pre>{@code
* List<ZoneOffset> validOffsets = rules.getOffset(localDT); * var validOffsets = rules.getOffset(localDT);
* if (validOffsets.size() == 1) { * if (validOffsets.size() == 1) {
* // Normal case: only one valid offset * // Normal case: only one valid offset
* zoneOffset = validOffsets.get(0); * zoneOffset = validOffsets.get(0);
* } else { * } else {
* // Gap or Overlap: determine what to do from transition (which will be non-null) * // Gap or Overlap: determine what to do from transition (which will be non-null)
* ZoneOffsetTransition trans = rules.getTransition(localDT); * var trans = rules.getTransition(localDT);
* } * }
* </pre> * }</pre>
* <p> * <p>
* In theory, it is possible for there to be more than two valid offsets. * In theory, it is possible for there to be more than two valid offsets.
* This would happen if clocks to be put back more than once in quick succession. * This would happen if clocks to be put back more than once in quick succession.

40
core/build.gradle.kts Normal file
View File

@ -0,0 +1,40 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
`java-library`
`teavm-publish`
}
description = "Compiler, backends and runtime"
dependencies {
api(project(":interop:core"))
api(project(":metaprogramming:api"))
implementation(libs.asm.commons)
implementation(libs.asm.util)
implementation(libs.hppc)
implementation(libs.rhino)
compileOnly(libs.jackson.annotations)
testImplementation(libs.junit)
}
teavmPublish {
artifactId = "teavm-core"
}

View File

@ -1,159 +0,0 @@
<!--
Copyright 2013 Alexey Andreev.
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.
-->
<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>
<parent>
<groupId>org.teavm</groupId>
<artifactId>teavm</artifactId>
<version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>teavm-core</artifactId>
<name>TeaVM core</name>
<description>TeaVM compiler and SPI</description>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-interop</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-metaprogramming-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.carrotsearch</groupId>
<artifactId>hppc</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>junit:junit</exclude>
<exclude>org.teavm:teavm-interop</exclude>
<exclude>org.teavm:teavm-metaprogramming-api</exclude>
<exclude>com.fasterxml.jackson.core:jackson-annotations</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>**/module-info.class</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>org.objectweb.asm</pattern>
<shadedPattern>org.teavm.asm</shadedPattern>
</relocation>
<relocation>
<pattern>org.mozilla</pattern>
<shadedPattern>org.teavm.rhino</shadedPattern>
</relocation>
<relocation>
<pattern>com.carrotsearch.hppc</pattern>
<shadedPattern>org.teavm.hppc</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons</pattern>
<shadedPattern>org.teavm.apachecommons</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
<show>protected</show>
</configuration>
</plugin>
</plugins>
</reporting>
</project>

View File

@ -21,10 +21,10 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -55,11 +55,11 @@ final class TeaVMPluginReader {
static void load(ClassLoader classLoader, Consumer<String> consumer) { static void load(ClassLoader classLoader, Consumer<String> consumer) {
Set<String> unorderedPlugins = new HashSet<>(); Set<String> unorderedPlugins = new HashSet<>();
try { try {
Enumeration<URL> resourceFiles = classLoader.getResources(DESCRIPTOR_LOCATION); var resourceFiles = classLoader.getResources(DESCRIPTOR_LOCATION);
while (resourceFiles.hasMoreElements()) { while (resourceFiles.hasMoreElements()) {
URL resourceFile = resourceFiles.nextElement(); URL resourceFile = resourceFiles.nextElement();
try (BufferedReader input = new BufferedReader( try (var input = new BufferedReader(
new InputStreamReader(resourceFile.openStream(), "UTF-8"))) { new InputStreamReader(resourceFile.openStream(), StandardCharsets.UTF_8))) {
readPlugins(input, unorderedPlugins); readPlugins(input, unorderedPlugins);
} }
} }

View File

@ -166,7 +166,7 @@ TeaVM.wasm = function() {
const importObj = {}; const importObj = {};
const controller = defaults(importObj); const controller = defaults(importObj);
if (typeof options.installImports !== "undefined") { if (typeof options.installImports !== "undefined") {
options.installImports(importObj); options.installImports(importObj, controller);
} }
return WebAssembly.instantiateStreaming(fetch(path), importObj).then((obj => { return WebAssembly.instantiateStreaming(fetch(path), importObj).then((obj => {

View File

@ -1,28 +0,0 @@
<!--
~ Copyright 2021 Alexey Andreev.
~
~ 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.
-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>teavm-repo</id>
<username>${env.TEAVM_DEPLOY_LOGIN}</username>
<password>${env.TEAVM_DEPLOY_PASSWORD}</password>
</server>
</servers>
</settings>

View File

@ -21,8 +21,7 @@ git fetch
git archive master | tar -x -C build-dir || { echo 'Git archive failed' ; exit 1; } git archive master | tar -x -C build-dir || { echo 'Git archive failed' ; exit 1; }
function deploy_teavm { function deploy_teavm {
TEAVM_OLD_VERSION=`mvn help:evaluate -Dexpression=project.version 2>/dev/null | grep -Ev "(^\[|Download)"` TEAVM_DEPLOY_VERSION=`sed -En 's/teavm\.project\.version\s*=\s*([0-9]+\.[0-9]+)\..*/\1/p' gradle.properties`
TEAVM_DEPLOY_VERSION=${TEAVM_OLD_VERSION%.0-SNAPSHOT}
git rev-parse master >commit-id.txt git rev-parse master >commit-id.txt
TEAVM_DEPLOY_COMMIT_ID=`cat commit-id.txt` TEAVM_DEPLOY_COMMIT_ID=`cat commit-id.txt`
@ -45,31 +44,8 @@ function deploy_teavm {
echo "Building version $TEAVM_DEPLOY_VERSION_FULL" echo "Building version $TEAVM_DEPLOY_VERSION_FULL"
sed -i -e "s/{{TEAVM_DEPLOY_URL}}/ftp:\/\/${TEAVM_DEPLOY_SERVER//\//\\/}\/maven\/repository/g" pom.xml ./gradlew build || { echo 'Build failed' ; return 1; }
./gradlew publishAllPublicationsToMavenRepository || { echo 'Deploy failed' ; return 1; }
mvn -e versions:set \
-DnewVersion="$TEAVM_DEPLOY_VERSION_FULL" \
-DgenerateBackupPoms=false \
|| { echo 'Setting version' ; return 1; }
mvn -T $TEAVM_DEPLOY_THREADS -e -V install \
--settings ../deploy-settings.xml \
-P with-idea -P with-cli -P deploy-to-teavm -P with-tests \
-Dmaven.repo.local=`pwd`/../build-cache/maven-repository \
-Dteavm.build.all=false \
-Dteavm.junit.optimized=true \
-Dteavm.junit.js.decodeStack=false \
-Dteavm.junit.threads=$TEAVM_DEPLOY_TEST_THREADS \
-Dteavm.junit.js.runner=browser-chrome \
|| { echo 'Build failed' ; return 1; }
mvn -T $TEAVM_DEPLOY_THREADS -e -V deploy \
--settings ../deploy-settings.xml \
-P with-idea -P with-cli -P deploy-to-teavm \
-Dmaven.repo.local=`pwd`/../build-cache/maven-repository \
-Dteavm.build.all=false \
-DskipTests \
|| { echo 'Deploy failed' ; return 1; }
cat <<EOF >idea-repository.xml cat <<EOF >idea-repository.xml
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>

View File

@ -0,0 +1,33 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
`java-library`
`teavm-publish`
}
description = "TeaVM backend for slf4j"
dependencies {
implementation(project(":jso:core"))
compileOnly(project(":core"))
compileOnly(libs.slf4j)
}
teavmPublish {
artifactId = "teavm-extras-slf4j"
}

View File

@ -1,68 +0,0 @@
<!--
Copyright 2015 Alexey Andreev.
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.
-->
<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>
<parent>
<groupId>org.teavm</groupId>
<artifactId>teavm</artifactId>
<version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>teavm-extras-slf4j</artifactId>
<name>TeaVM slf4j</name>
<description>TeaVM backend for slf4j</description>
<dependencies>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

25
gradle.properties Normal file
View File

@ -0,0 +1,25 @@
#
# Copyright 2023 Alexey Andreev.
#
# 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.
#
org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.caching=true
org.gradle.unsafe.configuration-cache=true
teavm.project.version=0.7.0-SNAPSHOT
teavm.tests.decodeStack=false
teavm.tests.optimized=true
teavm.tests.minified=false

74
gradle/libs.versions.toml Normal file
View File

@ -0,0 +1,74 @@
[versions]
asm = "9.4"
jackson = "2.12.2"
jetty = "9.4.38.v20210224"
shadow = "7.1.2"
checkstyle = "8.41"
idea = "2020.1.4"
idea-scala = "2020.1.43"
maven = "3.5.4"
maven-tools = "3.7.1"
[libraries]
hppc = "com.carrotsearch:hppc:0.8.2"
commons-io = "commons-io:commons-io:2.8.0"
commons-cli = "commons-cli:commons-cli:1.4"
rhino = "org.mozilla:rhino:1.7.11"
slf4j = "org.slf4j:slf4j-api:1.7.30"
javax-servlet = "javax.servlet:javax.servlet-api:3.1.0"
javax-websocket = "javax.websocket:javax.websocket-api:1.0"
asm = { module = "org.ow2.asm:asm", version.ref = "asm" }
asm-commons = { module = "org.ow2.asm:asm-commons", version.ref = "asm" }
asm-util = { module = "org.ow2.asm:asm-util", version.ref = "asm" }
asm-tree = { module = "org.ow2.asm:asm-tree", version.ref = "asm" }
asm-analysis = { module = "org.ow2.asm:asm-analysis", version.ref = "asm" }
jackson-annotations = { module = "com.fasterxml.jackson.core:jackson-annotations", version.ref = "jackson" }
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
gson = "com.google.code.gson:gson:2.8.6"
jzlib = "com.jcraft:jzlib:1.1.3"
jodaTime = "joda-time:joda-time:2.7"
htmlunit = "net.sourceforge.htmlunit:htmlunit:2.37.0"
httpclient = "org.apache.httpcomponents:httpclient:4.5.13"
jetty-server = { module = "org.eclipse.jetty:jetty-server", version.ref = "jetty" }
jetty-websocket-server = { module = "org.eclipse.jetty.websocket:javax-websocket-server-impl", version.ref = "jetty" }
jetty-websocket-client = { module = "org.eclipse.jetty.websocket:websocket-client", version.ref = "jetty" }
junit = "junit:junit:4.13.2"
testng = "org.testng:testng:7.7.0"
maven-plugin-api = { module = "org.apache.maven:maven-plugin-api", version.ref = "maven" }
maven-artifact = { module = "org.apache.maven:maven-artifact", version.ref = "maven" }
maven-core = { module = "org.apache.maven:maven-core", version.ref = "maven" }
maven-embedder = { module = "org.apache.maven:maven-embedder", version.ref = "maven" }
maven-compat = { module = "org.apache.maven:maven-compat", version.ref = "maven" }
[libraries.maven-plugin-tools-api]
module = "org.apache.maven.plugin-tools:maven-plugin-tools-api"
version.ref = "maven-tools"
[libraries.maven-plugin-tools-generators]
module = "org.apache.maven.plugin-tools:maven-plugin-tools-generators"
version.ref = "maven-tools"
[libraries.maven-plugin-tools-annotations]
module = "org.apache.maven.plugin-tools:maven-plugin-tools-annotations"
version.ref = "maven-tools"
[libraries.maven-plugin-annotations]
module = "org.apache.maven.plugin-tools:maven-plugin-annotations"
version.ref = "maven-tools"
[libraries.shadowPlugin]
module = "com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin"
version.ref = "shadow"
[plugins]
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
intellij = { id = "org.jetbrains.intellij", version = "1.10.0" }

View File

View File

@ -1,133 +0,0 @@
<!--
Copyright 2014 Alexey Andreev.
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.
-->
<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>
<parent>
<groupId>org.teavm</groupId>
<artifactId>teavm</artifactId>
<version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>teavm-html4j</artifactId>
<name>TeaVM html4j support</name>
<description>A set of interceptors and hacks for TeaVM to support html4j</description>
<dependencies>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.html</groupId>
<artifactId>net.java.html.boot</artifactId>
</dependency>
<dependency>
<groupId>org.netbeans.html</groupId>
<artifactId>net.java.html.json.tck</artifactId>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.netbeans.html</groupId>
<artifactId>ko4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>teavm-junit</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.carrotsearch</groupId>
<artifactId>hppc</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${maven-surefire-plugin.version}</version>
</dependency>
</dependencies>
<configuration>
<systemProperties>
<teavm.junit.target>${project.build.directory}/js-tests</teavm.junit.target>
<teavm.junit.minified>true</teavm.junit.minified>
<teavm.junit.optimized>false</teavm.junit.optimized>
</systemProperties>
<argLine>-Xmx1024m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,26 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
`java-library`
`teavm-publish`
}
description = "Runtime interoperability API"
teavmPublish {
artifactId = "teavm-interop"
}

View File

@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016 Alexey Andreev.
~
~ 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.
-->
<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>
<parent>
<groupId>org.teavm</groupId>
<artifactId>teavm</artifactId>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>teavm-interop</artifactId>
<name>TeaVM interop API</name>
<description>API that allows Java programs to interoperate with low-level languages like C in some low-level
environments like WebAssembly and LLVM</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../../checkstyle.xml</configLocation>
<propertyExpansion>config_loc=${basedir}/../..</propertyExpansion>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

36
jso/apis/build.gradle.kts Normal file
View File

@ -0,0 +1,36 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
`java-library`
`teavm-publish`
}
description = "Set of JavaScript API wrappers for JSO"
configurations {
val teavm = create("teavm")
teavm.extendsFrom(compileClasspath.get())
}
dependencies {
api(project(":jso:core"))
api(project(":interop:core"))
}
teavmPublish {
artifactId = "teavm-jso-apis"
}

View File

@ -1,81 +0,0 @@
<!--
Copyright 2014 Alexey Andreev.
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.
-->
<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>
<parent>
<groupId>org.teavm</groupId>
<artifactId>teavm</artifactId>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>teavm-jso-apis</artifactId>
<name>TeaVM JavaScript APIs</name>
<description>Set of JavaScript API wrappers for JSO</description>
<dependencies>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-interop</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../../checkstyle.xml</configLocation>
<propertyExpansion>config_loc=${basedir}/../..</propertyExpansion>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>org.teavm.jso.apis</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

35
jso/core/build.gradle.kts Normal file
View File

@ -0,0 +1,35 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
`java-library`
`teavm-publish`
}
description = "Library that adds convenient interface for interaction between TeaVM and JavaScript code"
configurations {
val teavm = create("teavm")
teavm.extendsFrom(compileClasspath.get())
}
dependencies {
"teavm"(project(":jso:impl"))
}
teavmPublish {
artifactId = "teavm-jso"
}

View File

@ -1,78 +0,0 @@
<!--
Copyright 2014 Alexey Andreev.
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.
-->
<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>
<parent>
<groupId>org.teavm</groupId>
<artifactId>teavm</artifactId>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>teavm-jso</artifactId>
<name>TeaVM JavaScript objects</name>
<description>A library that adds convenient interface for interaction between TeaVM and JavaScript code</description>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../../checkstyle.xml</configLocation>
<propertyExpansion>config_loc=${basedir}/../..</propertyExpansion>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>org.teavm.jso</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>

34
jso/impl/build.gradle.kts Normal file
View File

@ -0,0 +1,34 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
`java-library`
`teavm-publish`
}
description = "implementation of JSO"
dependencies {
compileOnly(project(":core"))
implementation(libs.rhino)
implementation(project(":jso:core"))
implementation(project(":jso:apis"))
}
teavmPublish {
artifactId = "teavm-jso-impl"
}

View File

@ -1,100 +0,0 @@
<!--
Copyright 2015 Alexey Andreev.
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.
-->
<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>
<parent>
<groupId>org.teavm</groupId>
<artifactId>teavm</artifactId>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>teavm-jso-impl</artifactId>
<name>TeaVM JavaScript objects - implementation</name>
<description>An implementation of JSO</description>
<dependencies>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso-apis</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../../checkstyle.xml</configLocation>
<propertyExpansion>config_loc=${basedir}/../..</propertyExpansion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>org.teavm:teavm-jso-impl</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.mozilla</pattern>
<shadedPattern>org.teavm.rhino</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,35 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
`java-library`
`teavm-publish`
}
description = "Declaration of interfaces and annotations for TeaVM metaprogramming"
configurations {
val teavm = create("teavm")
teavm.extendsFrom(compileClasspath.get())
}
dependencies {
"teavm"(project(":metaprogramming:impl"))
}
teavmPublish {
artifactId = "teavm-metaprogramming-api"
}

View File

@ -1,73 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016 Alexey Andreev.
~
~ 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.
-->
<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>
<parent>
<groupId>org.teavm</groupId>
<artifactId>teavm</artifactId>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>teavm-metaprogramming-api</artifactId>
<name>TeaVM metaprogramming API</name>
<description>Declaration of interfaces and annotations for TeaVM metaprogramming</description>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../../checkstyle.xml</configLocation>
<propertyExpansion>config_loc=${basedir}/../..</propertyExpansion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>org.teavm.metaprogramming.api</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,34 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
`java-library`
`teavm-publish`
}
description = "Implementation of metaprogramming API"
dependencies {
compileOnly(project(":core"))
implementation(libs.commons.io)
implementation(libs.asm)
implementation(project(":metaprogramming:api"))
}
teavmPublish {
artifactId = "teavm-metaprogramming-impl"
}

View File

@ -1,117 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016 Alexey Andreev.
~
~ 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.
-->
<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">
<parent>
<artifactId>teavm</artifactId>
<groupId>org.teavm</groupId>
<version>0.7.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>teavm-metaprogramming-impl</artifactId>
<name>TeaVM metaprogramming API implementation</name>
<description>Implementation of metaprogramming API</description>
<dependencies>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-metaprogramming-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../../checkstyle.xml</configLocation>
<propertyExpansion>config_loc=${basedir}/../..</propertyExpansion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>org.teavm:teavm-metaprogramming-impl</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.objectweb.asm</pattern>
<shadedPattern>org.teavm.asm</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons</pattern>
<shadedPattern>org.teavm.apachecommons</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

34
platform/build.gradle.kts Normal file
View File

@ -0,0 +1,34 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
`java-library`
`teavm-publish`
}
description = "Low-level classes that help to implement Java class library"
dependencies {
compileOnly(project(":core"))
compileOnly(libs.commons.io)
compileOnly(libs.asm)
implementation(project(":jso:apis"))
}
teavmPublish {
artifactId = "teavm-platform"
}

View File

@ -1,68 +0,0 @@
<!--
Copyright 2014 Alexey Andreev.
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.
-->
<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>
<parent>
<groupId>org.teavm</groupId>
<artifactId>teavm</artifactId>
<version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>teavm-platform</artifactId>
<name>TeaVM platform</name>
<description>A low-level classes that help to implement Java class library</description>
<dependencies>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso-apis</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -17,43 +17,6 @@ package org.teavm.platform.metadata;
import org.teavm.model.MethodReference; import org.teavm.model.MethodReference;
/**
* <p>Represents a generator, that produces resources during compilation phase. User must implement this
* interface and bind this implementation to a method that would read resources at runtime.</p>
*
* <p>Here is the full workflow:</p>
*
* <ul>
* <li>Compiler finds a method that is marked with the {@link MetadataProvider} annotation.
* This method must be declared as <code>native</code>, otherwise compiler should throw an exception.</li>
* <li>Compiler instantiates the {@link MetadataGenerator} instance with the no-arg constructor
* If no such constructor exists, compiler throws exception.</li>
* <li>Compiler runs the {@link #generateMetadata(MetadataGeneratorContext, MethodReference)} method
* ands gets the produced resource.</li>
* <li>Compiler generates implementation of the method marked with {@link MetadataProvider}, that
* will return the generated resource in run time.</li>
* </ul>
*
* <p>Therefore, the type of the value, returned by the
* {@link #generateMetadata(MetadataGeneratorContext, MethodReference)}
* method must match the returning type of the appropriate method, marked with {@link MetadataProvider}.</p>
*
* <p>The valid resource types are the following:</p>
*
* <ul>
* <li>Valid interfaces, extending the {@link Resource} annotation. Read the description of this interface
* for detailed description about valid resources interfaces.</li>
* <li>{@link ResourceArray} of valid resources.</li>
* <li>{@link ResourceMap} of valid resources.</li>
* <li>The <code>null</code> value.</li>
* </ul>
*
* <p>All other types are not considered to be resources and therefore are not accepted.</p>
*
* @see ClassScopedMetadataGenerator
*
* @author Alexey Andreev
*/
public interface MetadataGenerator { public interface MetadataGenerator {
/** /**
* <p>Generates resources, that will be available at runtime.</p> * <p>Generates resources, that will be available at runtime.</p>

View File

@ -50,13 +50,6 @@ public interface MetadataGeneratorContext extends ServiceRepository {
*/ */
Properties getProperties(); Properties getProperties();
/**
* Creates a new resource of the given type. The description of valid resources
* is available in documentation for {@link Resource}.
*
* @param resourceType type of resource to create.
* @return a new resource
*/
<T extends Resource> T createResource(Class<T> resourceType); <T extends Resource> T createResource(Class<T> resourceType);
/** /**
@ -68,18 +61,8 @@ public interface MetadataGeneratorContext extends ServiceRepository {
*/ */
StaticFieldResource createFieldResource(FieldReference field); StaticFieldResource createFieldResource(FieldReference field);
/**
* Creates a new resource array.
*
* @return a new resource.
*/
<T extends Resource> ResourceArray<T> createResourceArray(); <T extends Resource> ResourceArray<T> createResourceArray();
/**
* Creates a new resource map.
*
* @return a new resource.
*/
<T extends Resource> ResourceMap<T> createResourceMap(); <T extends Resource> ResourceMap<T> createResourceMap();
ResourceTypeDescriptor getTypeDescriptor(Class<? extends Resource> type); ResourceTypeDescriptor getTypeDescriptor(Class<? extends Resource> type);

480
pom.xml
View File

@ -1,480 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2014 Alexey Andreev.
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.
-->
<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>org.teavm</groupId>
<artifactId>teavm</artifactId>
<version>0.7.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>TeaVM</name>
<description>TeaVM aggregate project</description>
<url>http://teavm.org</url>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
<comments>A business-friendly OSS license</comments>
</license>
</licenses>
<developers>
<developer>
<id>konsoletyper</id>
<name>Alexey Andreev</name>
<email>konsoletyper@gmail.com</email>
<timezone>+4</timezone>
</developer>
</developers>
<scm>
<url>https://github.com/konsoletyper/teavm</url>
<connection>scm:git:git@github.com:konsoletyper/teavm.git</connection>
</scm>
<distributionManagement>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>${sonatypeOssDistMgmtSnapshotsUrl}</url>
</snapshotRepository>
<repository>
<id>sonatype-nexus-staging</id>
<name>Nexus Release Repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonatypeOssDistMgmtSnapshotsUrl>https://oss.sonatype.org/content/repositories/snapshots/</sonatypeOssDistMgmtSnapshotsUrl>
<html4j.version>1.5</html4j.version>
<slf4j.version>1.7.30</slf4j.version>
<asm.version>9.4</asm.version>
<java.version>11</java.version>
<java-tests.version>17</java-tests.version>
<rhino.version>1.7.11</rhino.version>
<testng.version>7.1.0</testng.version>
<junit.version>4.13.2</junit.version>
<commons-cli.version>1.4</commons-cli.version>
<commons-io.version>2.8.0</commons-io.version>
<jzlib.version>1.1.3</jzlib.version>
<joda-time.version>2.7</joda-time.version>
<hppc.version>0.8.2</hppc.version>
<jetty.version>9.4.38.v20210224</jetty.version>
<javax-websocket.version>1.0</javax-websocket.version>
<jackson.version>2.12.2</jackson.version>
<gson.version>2.8.6</gson.version>
<maven-plugin-api.version>3.3.3</maven-plugin-api.version>
<maven-plugin-annotations.version>3.3</maven-plugin-annotations.version>
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
<maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version>
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
<maven-shade-plugin.version>3.4.0</maven-shade-plugin.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
<exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>
<wagon-ftp.version>3.4.3</wagon-ftp.version>
<checkstyle.version>8.41</checkstyle.version>
<teavm.test.incremental>false</teavm.test.incremental>
<teavm.test.threads>1</teavm.test.threads>
<teavm.test.skip>true</teavm.test.skip>
</properties>
<modules>
<module>metaprogramming/api</module>
<module>interop/core</module>
<module>core</module>
<module>classlib</module>
<module>jso/core</module>
<module>jso/apis</module>
<module>jso/impl</module>
<module>html4j</module>
<module>platform</module>
<module>tools/c-incremental</module>
<module>tools/core</module>
<module>tools/maven</module>
<module>tools/chrome-rdp</module>
<module>tools/junit</module>
<module>tools/devserver</module>
<module>extras-slf4j</module>
<module>metaprogramming/impl</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.html</groupId>
<artifactId>net.java.html.boot</artifactId>
<version>${html4j.version}</version>
<exclusions>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.netbeans.html</groupId>
<artifactId>net.java.html.json.tck</artifactId>
<version>${html4j.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.html</groupId>
<artifactId>ko4j</artifactId>
<version>${html4j.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<version>${asm.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
<version>${asm.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven-plugin-api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>${maven-plugin-annotations.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven-plugin-api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${maven-plugin-api.version}</version>
</dependency>
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>${javax-websocket.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<version>${rhino.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>${commons-cli.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jzlib</artifactId>
<version>${jzlib.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<dependency>
<groupId>com.carrotsearch</groupId>
<artifactId>hppc</artifactId>
<version>${hppc.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>${wagon-ftp.version}</version>
</extension>
</extensions>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<executions>
<execution>
<id>build-javadoc</id>
<goals>
<goal>jar</goal>
</goals>
<phase>post-integration-test</phase>
<configuration>
<quiet>true</quiet>
</configuration>
</execution>
</executions>
<configuration>
<source>${java.version}</source>
<show>protected</show>
<failOnError>false</failOnError>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>post-integration-test</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<propertyExpansion>config_loc=${basedir}/..</propertyExpansion>
<configLocation>../checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>with-samples</id>
<activation>
<property>
<name>teavm.build.all</name>
<value>!false</value>
</property>
</activation>
<modules>
<module>samples</module>
</modules>
</profile>
<profile>
<id>with-tests</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>tests</module>
</modules>
</profile>
<profile>
<id>with-cli</id>
<modules>
<module>tools/cli</module>
</modules>
</profile>
<profile>
<id>with-ide-deps</id>
<modules>
<module>tools/ide-deps</module>
</modules>
</profile>
<profile>
<id>with-eclipse</id>
<modules>
<module>tools/eclipse</module>
</modules>
</profile>
<profile>
<id>with-classlib-comparison</id>
<modules>
<module>tools/classlib-comparison-gen</module>
</modules>
</profile>
<profile>
<id>sign-artifacts</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>deploy-to-bintray</id>
<distributionManagement>
<repository>
<id>bintray-teavm</id>
<name>Bintray Preview Repository</name>
<url>https://api.bintray.com/maven/konsoletyper/teavm/teavm-dev/;publish=1</url>
</repository>
</distributionManagement>
</profile>
<profile>
<id>deploy-to-teavm</id>
<distributionManagement>
<repository>
<id>teavm-repo</id>
<name>Development Preview Repository</name>
<url>{{TEAVM_DEPLOY_URL}}</url>
</repository>
</distributionManagement>
</profile>
</profiles>
</project>

View File

@ -0,0 +1,40 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
java
war
id("org.teavm")
}
configurations {
create("war")
}
dependencies {
teavm(teavm.libs.jsoApis)
"war"(project(":stdout-helper", "war"))
}
teavm.js {
addedToWebApp.set(true)
mainClass.set("org.teavm.samples.async.AsyncProgram")
}
tasks.war {
dependsOn(configurations["war"])
from(provider { configurations["war"].map { zipTree(it) } })
}

View File

@ -1,92 +0,0 @@
<!--
Copyright 2014 Alexey Andreev.
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.
-->
<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>
<parent>
<groupId>org.teavm</groupId>
<artifactId>teavm-samples</artifactId>
<version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>teavm-samples-async</artifactId>
<packaging>war</packaging>
<name>TeaVM CPS demo</name>
<description>TeaVM application that demonstrates continuation-passing style generator</description>
<dependencies>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/generated/js</directory>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>web-client</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
<mainClass>org.teavm.samples.async.AsyncProgram</mainClass>
<minifying>false</minifying>
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>
<sourceFilesCopied>true</sourceFilesCopied>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../../checkstyle.xml</configLocation>
<propertyExpansion>config_loc=${basedir}/../..</propertyExpansion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -31,7 +31,7 @@ public final class AsyncProgram {
withAsync(); withAsync();
report(""); report("");
final Object lock = new Object(); final var lock = new Object();
new Thread(() -> { new Thread(() -> {
try { try {
doRun(lock); doRun(lock);
@ -60,12 +60,12 @@ public final class AsyncProgram {
private static void findPrimes() { private static void findPrimes() {
report("Finding primes"); report("Finding primes");
boolean[] prime = new boolean[1000]; var prime = new boolean[1000];
prime[2] = true; prime[2] = true;
prime[3] = true; prime[3] = true;
nextPrime: for (int i = 5; i < prime.length; i += 2) { nextPrime: for (var i = 5; i < prime.length; i += 2) {
int maxPrime = (int) Math.sqrt(i); var maxPrime = (int) Math.sqrt(i);
for (int j = 3; j <= maxPrime; j += 2) { for (var j = 3; j <= maxPrime; j += 2) {
Thread.yield(); Thread.yield();
if (prime[j] && i % j == 0) { if (prime[j] && i % j == 0) {
continue nextPrime; continue nextPrime;
@ -73,8 +73,8 @@ public final class AsyncProgram {
} }
prime[i] = true; prime[i] = true;
} }
StringBuilder sb = new StringBuilder(); var sb = new StringBuilder();
for (int i = 0; i < 1000; ++i) { for (var i = 0; i < 1000; ++i) {
if (prime[i]) { if (prime[i]) {
sb.append(i).append(' '); sb.append(i).append(' ');
} }
@ -83,7 +83,7 @@ public final class AsyncProgram {
} }
private static void report(String message) { private static void report(String message) {
long current = System.currentTimeMillis() - start; var current = System.currentTimeMillis() - start;
System.out.println("[" + Thread.currentThread().getName() + "]/" + current + ": " + message); System.out.println("[" + Thread.currentThread().getName() + "]/" + current + ": " + message);
} }
@ -108,9 +108,9 @@ public final class AsyncProgram {
private static void withoutAsync() { private static void withoutAsync() {
report("Start sync"); report("Start sync");
for (int i = 0; i < 20; ++i) { for (var i = 0; i < 20; ++i) {
StringBuilder sb = new StringBuilder(); var sb = new StringBuilder();
for (int j = 0; j <= i; ++j) { for (var j = 0; j <= i; ++j) {
sb.append(j); sb.append(j);
sb.append(' '); sb.append(' ');
} }
@ -121,8 +121,8 @@ public final class AsyncProgram {
private static void withAsync() throws InterruptedException { private static void withAsync() throws InterruptedException {
report("Start async"); report("Start async");
for (int i = 0; i < 20; ++i) { for (var i = 0; i < 20; ++i) {
StringBuilder sb = new StringBuilder(); var sb = new StringBuilder();
for (int j = 0; j <= i; ++j) { for (int j = 0; j <= i; ++j) {
sb.append(j); sb.append(j);
sb.append(' '); sb.append(' ');

View File

@ -19,7 +19,7 @@
<title>Continuation-passing style demo</title> <title>Continuation-passing style demo</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript" charset="utf-8" src="teavm/stdout.js"></script> <script type="text/javascript" charset="utf-8" src="teavm/stdout.js"></script>
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script> <script type="text/javascript" charset="utf-8" src="js/async.js"></script>
<script type="text/javascript" charset="utf-8" src="highlight.pack.js"></script> <script type="text/javascript" charset="utf-8" src="highlight.pack.js"></script>
<link rel="stylesheet" type="text/css" href="style.css"> <link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="syntax.css"> <link rel="stylesheet" type="text/css" href="syntax.css">

1
samples/benchmark/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/CMakeFiles

View File

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.9)
project(teavm_benchmark C) project(teavm_benchmark C)
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/target/) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build/dist/)
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release) set(CMAKE_BUILD_TYPE Release)
@ -17,6 +17,6 @@ pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
include_directories(${GTK3_INCLUDE_DIRS}) include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS}) link_directories(${GTK3_LIBRARY_DIRS})
add_definitions(${GTK3_CFLAGS_OTHER}) add_definitions(${GTK3_CFLAGS_OTHER})
add_executable(teavm_benchmark target/generated/c/all.c) add_executable(teavm_benchmark build/generated/teavm-c/all.c)
target_link_libraries(teavm_benchmark ${GTK3_LIBRARIES} m rt) target_link_libraries(teavm_benchmark ${GTK3_LIBRARIES} m rt)

View File

@ -1,23 +1,18 @@
TeaVM, GWT, HotSpot, Bck2Brwsr JBox2D Benchmark TeaVM, GWT, HotSpot, JBox2D Benchmark
=============================================== ===============================================
Compares the speed of execution on a complex [JBox2D](http://www.jbox2d.org/) CPU extensive Compares the speed of execution on a complex [JBox2D](http://www.jbox2d.org/) CPU extensive
computation. JavaScript produced by TeaVM and GWT can be compared by running computation. JavaScript produced by TeaVM and GWT can be compared by running
``` ```
$ mvn clean install $ gradle appStartWar
``` ```
then just open the generated HTML versions Also, in Linux it's possible to build and run native file:
``` ```
$ open target/teavm-samples-benchmark-*-SNAPSHOT/index.html $ gradle runNativeLinux
``` ```
In addition to that one can run the same demo with classical HotSpot virtual machine. Just try: Please, refer to your Linux distribution documentation to find out how to install required dependencies
(cmake and gtk-devel).
```
$ mvn -Pfx exec:java
```

View File

@ -0,0 +1,20 @@
#
# Copyright 2023 Alexey Andreev.
#
# 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.
#
cmake -S . -B build/cmake
pushd build/cmake
make
popd

View File

@ -0,0 +1,81 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
java
war
id("org.teavm")
id("org.wisepersist.gwt")
}
val gwtVersionNum = "2.10.0"
var jbox2d = "org.jbox2d:jbox2d-library:2.2.1.1"
dependencies {
teavm(teavm.libs.jsoApis)
teavm(teavm.libs.interop)
teavm(jbox2d)
teavm("com.google.gwt:gwt-user:$gwtVersionNum")
gwt("$jbox2d:sources")
}
gwt {
gwtVersion = gwtVersionNum
modules.add("org.teavm.samples.benchmark.benchmark")
devWar = File(buildDir, "gwt-war")
}
val generatedCSources = File(buildDir, "generated/teavm-c")
val executableFile = File(buildDir, "dist/teavm_benchmark")
teavm {
js {
addedToWebApp.set(true)
mainClass.set("org.teavm.samples.benchmark.teavm.BenchmarkStarter")
debugInformation.set(true)
}
wasm {
addedToWebApp.set(true)
mainClass.set("org.teavm.samples.benchmark.teavm.WasmBenchmarkStarter")
}
c {
mainClass.set("org.teavm.samples.benchmark.teavm.Gtk3BenchmarkStarter")
relativePathInOutputDir.set("")
outputDir.set(generatedCSources)
}
}
tasks.build.configure {
dependsOn(tasks.generateC)
}
val buildNativeLinux by tasks.register<Exec>("buildNativeLinux") {
group = "build"
dependsOn(tasks.generateC)
inputs.dir(generatedCSources)
inputs.file(project.file("CMakeLists.txt"))
outputs.file(executableFile)
executable = "./build-native.sh"
workingDir = project.projectDir
}
tasks.register<Exec>("runNativeLinux") {
group = "run"
dependsOn(buildNativeLinux)
inputs.file(executableFile)
executable = executableFile.relativeTo(project.projectDir).path
workingDir = project.projectDir
}

View File

@ -1,250 +0,0 @@
<!--
~ Copyright 2016 Alexey Andreev.
~
~ 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.
-->
<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>
<parent>
<groupId>org.teavm</groupId>
<artifactId>teavm-samples</artifactId>
<version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>teavm-samples-benchmark</artifactId>
<packaging>war</packaging>
<name>TeaVM performance benchmark</name>
<description>Compares performance of the JavaScript code produced by TeaVM and GWT</description>
<properties>
<bck2brwsr.version>0.22</bck2brwsr.version>
<gwt.version>2.8.2</gwt.version>
</properties>
<dependencies>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso-apis</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-interop</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jbox2d</groupId>
<artifactId>jbox2d-library</artifactId>
<version>2.2.1.1</version>
</dependency>
<dependency>
<groupId>org.jbox2d</groupId>
<artifactId>jbox2d-library</artifactId>
<version>2.2.1.1</version>
<classifier>sources</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>emul</artifactId>
<version>${bck2brwsr.version}</version>
<classifier>rt</classifier>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.dukescript.canvas</groupId>
<artifactId>html5-canvas</artifactId>
<version>0.7.2</version>
</dependency>
<dependency>
<groupId>org.apidesign.bck2brwsr</groupId>
<artifactId>ko-bck2brwsr</artifactId>
<version>${bck2brwsr.version}</version>
<classifier>bck2brwsr</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.netbeans.html</groupId>
<artifactId>net.java.html.boot</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/generated/js</directory>
</resource>
<resource>
<directory>${project.build.directory}/generated/wasm</directory>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>org.teamvm.samples.benchmark.htmljava.BenchmarkStarter</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
<excludes>
<exclude>**/gwt/*</exclude>
<exclude>**/teavm/*</exclude>
<exclude>**/benchmark/jvm/*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>web-client</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
<mainClass>org.teavm.samples.benchmark.teavm.BenchmarkStarter</mainClass>
<minifying>true</minifying>
<debugInformationGenerated>true</debugInformationGenerated>
<optimizationLevel>ADVANCED</optimizationLevel>
</configuration>
</execution>
<execution>
<id>wasm-client</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<targetDirectory>${project.build.directory}/generated/wasm/teavm-wasm</targetDirectory>
<mainClass>org.teavm.samples.benchmark.teavm.WasmBenchmarkStarter</mainClass>
<debugInformationGenerated>true</debugInformationGenerated>
<targetType>WEBASSEMBLY</targetType>
<optimizationLevel>FULL</optimizationLevel>
<minHeapSize>1</minHeapSize>
<maxHeapSize>16</maxHeapSize>
</configuration>
</execution>
<execution>
<id>native-client</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<targetDirectory>${project.build.directory}/generated/c</targetDirectory>
<mainClass>org.teavm.samples.benchmark.teavm.Gtk3BenchmarkStarter</mainClass>
<debugInformationGenerated>true</debugInformationGenerated>
<targetType>C</targetType>
<optimizationLevel>FULL</optimizationLevel>
<minHeapSize>1</minHeapSize>
<maxHeapSize>16</maxHeapSize>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwt.version}</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<optimizationLevel>9</optimizationLevel>
<compileSourcesArtifacts>
<item>org.jbox2d:jbox2d-library</item>
</compileSourcesArtifacts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../../checkstyle.xml</configLocation>
<propertyExpansion>config_loc=${basedir}/../..</propertyExpansion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>fx</id>
<dependencies>
<dependency>
<groupId>org.netbeans.html</groupId>
<artifactId>net.java.html.boot.fx</artifactId>
<version>1.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<mainClass>org.teavm.samples.benchmark.htmljava.BenchmarkFX</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -1,127 +0,0 @@
/*
* Copyright 2015 Jaroslav Tulach.
*
* 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 org.teavm.samples.benchmark.htmljava;
import com.dukescript.api.canvas.GraphicsContext2D;
import com.dukescript.api.canvas.Style;
import com.dukescript.canvas.html.HTML5Graphics;
import java.util.Timer;
import java.util.TimerTask;
import net.java.html.BrwsrCtx;
import net.java.html.js.JavaScriptBody;
import org.jbox2d.collision.shapes.CircleShape;
import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.collision.shapes.Shape;
import org.jbox2d.collision.shapes.ShapeType;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.Fixture;
import org.teavm.samples.benchmark.shared.Scene;
public final class BenchmarkStarter {
private BenchmarkStarter() {
}
private static final Timer TIMER = new Timer("Make Step");
private static final Scene scene = new Scene();
private static double startMillisecond;
private static int currentSecond;
private static double timeSpentCalculating;
private static BrwsrCtx ctx;
public static void main(String[] args) {
startMillisecond = System.currentTimeMillis();
ctx = BrwsrCtx.findDefault(BenchmarkStarter.class);
makeStep();
}
static void makeStep() {
ctx.execute(() -> makeStep0());
}
private static void makeStep0() {
double start = System.currentTimeMillis();
scene.calculate();
double end = System.currentTimeMillis();
int second = (int) ((System.currentTimeMillis() - startMillisecond) / 1000);
if (second > currentSecond) {
publishResults(second, timeSpentCalculating);
timeSpentCalculating = 0;
currentSecond = second;
}
timeSpentCalculating += end - start;
render();
TIMER.schedule(new TimerTask() {
@Override
public void run() {
makeStep();
}
}, scene.timeUntilNextStep());
}
private static void render() {
GraphicsContext2D context = HTML5Graphics.getOrCreate("benchmark-canvas");
context.setFillStyle(new Style.Color("white"));
context.setStrokeStyle(new Style.Color("grey"));
context.fillRect(0, 0, 600, 600);
context.save();
context.translate(0, 600);
context.scale(1, -1);
context.scale(100, 100);
context.setLineWidth(0.01);
for (Body body = scene.getWorld().getBodyList(); body != null; body = body.getNext()) {
Vec2 center = body.getPosition();
context.save();
context.translate(center.x, center.y);
context.rotate(body.getAngle());
for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
Shape shape = fixture.getShape();
if (shape.getType() == ShapeType.CIRCLE) {
CircleShape circle = (CircleShape) shape;
context.beginPath();
context.arc(circle.m_p.x, circle.m_p.y, circle.getRadius(), 0, Math.PI * 2, true);
context.closePath();
context.stroke();
} else if (shape.getType() == ShapeType.POLYGON) {
PolygonShape poly = (PolygonShape) shape;
Vec2[] vertices = poly.getVertices();
context.beginPath();
context.moveTo(vertices[0].x, vertices[0].y);
for (int i = 1; i < poly.getVertexCount(); ++i) {
context.lineTo(vertices[i].x, vertices[i].y);
}
context.closePath();
context.stroke();
}
}
context.restore();
}
context.restore();
}
@JavaScriptBody(args = { "second", "timeSpentCalculating" }, body = ""
+ "var resultTableBody = document.getElementById('result-table-body');\n"
+ "var row = document.createElement(\"tr\");\n"
+ "resultTableBody.appendChild(row);\n"
+ "var secondCell = document.createElement(\"td\");\n"
+ "row.appendChild(secondCell);\n"
+ "secondCell.appendChild(document.createTextNode(second));\n"
+ "var timeCell = document.createElement(\"td\");\n"
+ "row.appendChild(timeCell);\n"
+ "timeCell.appendChild(document.createTextNode(timeSpentCalculating));\n"
)
private static native void publishResults(int second, double timeSpentCalculating);
}

View File

@ -17,14 +17,13 @@
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>TeaVM vs. GWT vs. Bck2Brwsr performance comparison</title> <title>TeaVM vs. GWT performance comparison</title>
</head> </head>
<body onload="main()"> <body>
<h1>TeaVM vs. GWT vs. Bck2Brwsr performance</h1> <h1>TeaVM vs. GWT performance</h1>
<ul> <ul>
<li><a href="teavm.html">TeaVM</a></li> <li><a href="teavm.html">TeaVM</a></li>
<li><a href="gwt.html">GWT</a></li> <li><a href="gwt.html">GWT</a></li>
<li><a href="bck2brwsr.html">Bck2Brwsr VM</a></li>
<li><a href="teavm-wasm.html">TeaVM (experimental WebAssembly backend)</a></li> <li><a href="teavm-wasm.html">TeaVM (experimental WebAssembly backend)</a></li>
</ul> </ul>
</body> </body>

View File

@ -18,7 +18,7 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>TeaVM WebAssembly jbox2d benchmark</title> <title>TeaVM WebAssembly jbox2d benchmark</title>
<script src="teavm-wasm/classes.wasm-runtime.js" type="text/javascript"></script> <script src="wasm/benchmark.wasm-runtime.js" type="text/javascript"></script>
<script src="teavm-wasm.js" type="text/javascript"></script> <script src="teavm-wasm.js" type="text/javascript"></script>
</head> </head>
<body> <body>

View File

@ -21,10 +21,10 @@ var Benchmark = function() {
this.resultTableBody = document.getElementById("result-table-body"); this.resultTableBody = document.getElementById("result-table-body");
} }
Benchmark.prototype.load = function() { Benchmark.prototype.load = function() {
TeaVM.wasm.load("teavm-wasm/classes.wasm", { TeaVM.wasm.load("wasm/benchmark.wasm", {
installImports: installImports.bind(this), installImports: installImports.bind(this),
}).then(teavm => { }).then(teavm => {
this.instance = teavm; this.instance = teavm.instance;
teavm.main(); teavm.main();
}) })
}; };

View File

@ -18,7 +18,7 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>TeaVM jbox2d benchmark</title> <title>TeaVM jbox2d benchmark</title>
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script> <script type="text/javascript" charset="utf-8" src="js/benchmark.js"></script>
</head> </head>
<body onload="main()"> <body onload="main()">
<h1>TeaVM performance</h1> <h1>TeaVM performance</h1>

21
samples/build.gradle.kts Normal file
View File

@ -0,0 +1,21 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
id("org.teavm") version "0.7.0-SNAPSHOT" apply false
id("org.wisepersist.gwt") version "1.1.19" apply false
}

View File

@ -1,106 +0,0 @@
<!--
Copyright 2014 Alexey Andreev.
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.
-->
<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>
<parent>
<groupId>org.teavm</groupId>
<artifactId>teavm-samples</artifactId>
<version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>teavm-samples-gamepad</artifactId>
<packaging>war</packaging>
<name>TeaVM Web gamepad web application</name>
<description>A sample application that demonstrate how to use Web gamepad API.</description>
<dependencies>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso-apis</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/generated/js</directory>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>web-client</id>
<phase>prepare-package</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
<mainClass>org.teavm.samples.gamepad.Application</mainClass>
<minifying>false</minifying>
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>
<sourceFilesCopied>true</sourceFilesCopied>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../../checkstyle.xml</configLocation>
<propertyExpansion>config_loc=${basedir}/../..</propertyExpansion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

17
samples/gradle.properties Normal file
View File

@ -0,0 +1,17 @@
#
# Copyright 2023 Alexey Andreev.
#
# 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.
#
org.gradle.parallel=true

Binary file not shown.

View File

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

240
samples/gradlew vendored Executable file
View File

@ -0,0 +1,240 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original 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
#
# https://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.
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"

91
samples/gradlew.bat vendored Normal file
View File

@ -0,0 +1,91 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@ -0,0 +1,31 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
java
war
id("org.teavm")
}
dependencies {
teavm(teavm.libs.jsoApis)
compileOnly("javax.servlet:javax.servlet-api:3.0.1")
}
teavm.js {
addedToWebApp.set(true)
mainClass.set("org.teavm.samples.hello.Client")
}

View File

@ -1,105 +0,0 @@
<!--
Copyright 2014 Alexey Andreev.
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.
-->
<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>
<parent>
<groupId>org.teavm</groupId>
<artifactId>teavm-samples</artifactId>
<version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>teavm-samples-hello</artifactId>
<packaging>war</packaging>
<name>TeaVM Hello world web application</name>
<description>A sample application that shows how TeaVM can communicate with the server</description>
<dependencies>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/generated/js</directory>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>web-client</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
<mainClass>org.teavm.samples.hello.Client</mainClass>
<minifying>false</minifying>
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>
<sourceFilesCopied>true</sourceFilesCopied>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../../checkstyle.xml</configLocation>
<propertyExpansion>config_loc=${basedir}/../..</propertyExpansion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -16,7 +16,6 @@
package org.teavm.samples.hello; package org.teavm.samples.hello;
import java.io.IOException; import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet; import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -24,16 +23,14 @@ import javax.servlet.http.HttpServletResponse;
@WebServlet("/hello") @WebServlet("/hello")
public class Server extends HttpServlet { public class Server extends HttpServlet {
private static final long serialVersionUID = -5014505771271825585L;
@Override @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
try { try {
Thread.sleep(500); Thread.sleep(500);
} catch (InterruptedException e) { } catch (InterruptedException e) {
return; return;
} }
String userAgent = req.getHeader("User-Agent"); var userAgent = req.getHeader("User-Agent");
resp.getWriter().println("Hello, " + userAgent); resp.getWriter().println("Hello, " + userAgent);
} }
} }

View File

@ -18,7 +18,7 @@
<head> <head>
<title>Hello web application</title> <title>Hello web application</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script> <script type="text/javascript" charset="utf-8" src="js/hello.js"></script>
</head> </head>
<body onload="main()"> <body onload="main()">
<h1>Hello web application</h1> <h1>Hello web application</h1>

View File

@ -37,14 +37,14 @@ public final class Client {
private static void sayHello() { private static void sayHello() {
helloButton.setDisabled(true); helloButton.setDisabled(true);
thinkingPanel.getStyle().setProperty("display", ""); thinkingPanel.getStyle().setProperty("display", "");
XMLHttpRequest xhr = XMLHttpRequest.create(); var xhr = XMLHttpRequest.create();
xhr.onComplete(() -> receiveResponse(xhr.getResponseText())); xhr.onComplete(() -> receiveResponse(xhr.getResponseText()));
xhr.open("GET", "hello"); xhr.open("GET", "hello");
xhr.send(); xhr.send();
} }
private static void receiveResponse(String text) { private static void receiveResponse(String text) {
HTMLElement responseElem = document.createElement("div"); var responseElem = document.createElement("div");
responseElem.appendChild(document.createTextNode(text)); responseElem.appendChild(document.createTextNode(text));
responsePanel.appendChild(responseElem); responsePanel.appendChild(responseElem);
helloButton.setDisabled(false); helloButton.setDisabled(false);

View File

@ -0,0 +1,30 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
kotlin("jvm") version "1.8.0"
war
id("org.teavm")
}
dependencies {
teavm(teavm.libs.jsoApis)
}
teavm.js {
addedToWebApp.set(true)
mainClass.set("org.teavm.samples.kotlin.HelloKt")
}

View File

@ -1,129 +0,0 @@
<!--
Copyright 2015 Alexey Andreev.
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.
-->
<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>
<parent>
<groupId>org.teavm</groupId>
<artifactId>teavm-samples</artifactId>
<version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>teavm-samples-kotlin</artifactId>
<packaging>war</packaging>
<name>TeaVM Kotlin web application</name>
<description>A sample application written in Kotlin and compiled by TeaVM</description>
<properties>
<kotlin.version>1.5.10</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso-apis</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>web-client</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
<mainClass>org.teavm.samples.kotlin.HelloKt</mainClass>
<minifying>false</minifying>
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>
<sourceFilesCopied>true</sourceFilesCopied>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/generated/js</directory>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -16,6 +16,6 @@
package org.teavm.samples.kotlin package org.teavm.samples.kotlin
fun main(args : Array<String>) { fun main() {
println("Hello from Kotlin") println("Hello from Kotlin")
} }

View File

@ -17,7 +17,7 @@ package org.teavm.samples.kotlin
import org.teavm.jso.browser.* import org.teavm.jso.browser.*
fun main(args : Array<String>) { fun main() {
val document = Window.current().document val document = Window.current().document
document.getElementById("hello-kotlin").addEventListener("click") { Window.alert("Hello, developer!") } document.getElementById("hello-kotlin").addEventListener("click") { Window.alert("Hello, developer!") }

View File

@ -3,7 +3,7 @@
<head> <head>
<title>Hello kotlin</title> <title>Hello kotlin</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script> <script type="text/javascript" charset="utf-8" src="js/kotlin.js"></script>
</head> </head>
<body onload="main()"> <body onload="main()">
<p><button id="hello-kotlin">Hello, Kotlin!</button></p> <p><button id="hello-kotlin">Hello, Kotlin!</button></p>

16
samples/pi/CMakeLists.txt Normal file
View File

@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.9)
project(calc_pi C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build/dist)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
add_executable(calc_pi build/generated/teavm/c/all.c)
target_link_libraries(calc_pi m rt)

20
samples/pi/build-native.sh Executable file
View File

@ -0,0 +1,20 @@
#
# Copyright 2023 Alexey Andreev.
#
# 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.
#
cmake -S . -B build/cmake
pushd build/cmake
make
popd

View File

@ -0,0 +1,64 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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.
*/
plugins {
java
war
id("org.teavm")
}
configurations {
create("war")
}
dependencies {
"war"(project(":stdout-helper", "war"))
}
teavm {
js {
addedToWebApp.set(true)
}
wasm {
addedToWebApp.set(true)
}
wasi {
outputDir.set(File(buildDir, "libs/wasi"))
relativePathInOutputDir.set("")
}
all {
mainClass.set("org.teavm.samples.pi.PiCalculator")
}
}
tasks.war {
dependsOn(configurations["war"])
from(provider { configurations["war"].map { zipTree(it) } })
}
tasks.assemble {
dependsOn(tasks.generateWasi,)
}
val buildNativeLinux by tasks.register<Exec>("buildNativeLinux") {
group = "build"
dependsOn(tasks.generateC)
inputs.dir(File(buildDir, "generated/teavm/c"))
inputs.file(project.file("CMakeLists.txt"))
outputs.file("build/dist/calc_pi")
executable = "./build-native.sh"
workingDir = project.projectDir
}

View File

@ -0,0 +1,154 @@
/*
* Copyright 2023 Alexey Andreev.
*
* 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 org.teavm.samples.pi;
import java.math.BigInteger;
public final class PiCalculator {
private static final int L = 10;
private PiCalculator() {
}
public static void main(String[] args) {
var start = System.currentTimeMillis();
int n = Integer.parseInt(args[0]);
int j = 0;
var digits = new PiDigitSpigot();
while (n > 0) {
if (n >= L) {
for (int i = 0; i < L; i++) {
System.out.print(digits.next());
}
j += L;
} else {
for (int i = 0; i < n; i++) {
System.out.print(digits.next());
}
for (int i = n; i < L; i++) {
System.out.print(" ");
}
j += n;
}
System.out.print("\t:");
System.out.println(j);
System.out.flush();
n -= L;
}
System.out.println("Time in millis: " + (System.currentTimeMillis() - start));
}
}
class PiDigitSpigot {
private Transformation z;
private Transformation x;
private Transformation inverse;
PiDigitSpigot() {
z = new Transformation(1, 0, 0, 1);
x = new Transformation(0, 0, 0, 0);
inverse = new Transformation(0, 0, 0, 0);
}
int next() {
int y = digit();
if (isSafe(y)) {
z = produce(y);
return y;
} else {
z = consume(x.next());
return next();
}
}
private int digit() {
return z.extract(3);
}
private boolean isSafe(int digit) {
return digit == z.extract(4);
}
private Transformation produce(int i) {
return inverse.qrst(10, -10 * i, 0, 1).compose(z);
}
private Transformation consume(Transformation a) {
return z.compose(a);
}
}
class Transformation {
private BigInteger q;
private BigInteger r;
private BigInteger s;
private BigInteger t;
private int k;
Transformation(int q, int r, int s, int t) {
this.q = BigInteger.valueOf(q);
this.r = BigInteger.valueOf(r);
this.s = BigInteger.valueOf(s);
this.t = BigInteger.valueOf(t);
k = 0;
}
private Transformation(BigInteger q, BigInteger r, BigInteger s, BigInteger t) {
this.q = q;
this.r = r;
this.s = s;
this.t = t;
k = 0;
}
Transformation next() {
k++;
q = BigInteger.valueOf(k);
r = BigInteger.valueOf(4 * k + 2);
s = BigInteger.valueOf(0);
t = BigInteger.valueOf(2 * k + 1);
return this;
}
int extract(int j) {
var bigj = BigInteger.valueOf(j);
var numerator = q.multiply(bigj).add(r);
var denominator = s.multiply(bigj).add(t);
return numerator.divide(denominator).intValue();
}
Transformation qrst(int q, int r, int s, int t) {
this.q = BigInteger.valueOf(q);
this.r = BigInteger.valueOf(r);
this.s = BigInteger.valueOf(s);
this.t = BigInteger.valueOf(t);
k = 0;
return this;
}
Transformation compose(Transformation a) {
return new Transformation(
q.multiply(a.q),
q.multiply(a.r).add(r.multiply(a.t)),
s.multiply(a.q).add(t.multiply(a.s)),
s.multiply(a.r).add(t.multiply(a.t))
);
}
}

View File

@ -0,0 +1,29 @@
<!--
Copyright 2014 Alexey Andreev.
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.
-->
<!DOCTYPE html>
<html>
<head>
<title>PI calculator example</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>
<h1>Choose language</h1>
<ul>
<li><a href="js.html">JavaScript</a></li>
<li><a href="wasm.html">WebAssembly</a></li>
</ul>
</body>
</html>

Some files were not shown because too many files have changed in this diff Show More