Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1371,3 +1371,50 @@ Just set extension property `tomitribe.crest.useInPlaceRegistrations` to `true`:
----

This enables to use the same scanning for both tasks and therefore to have a common and unified scanning for java and native runs.

== Run commands from source

There is an experimental mode in crest enabling you to write commands in a standalone `.java` and run it with `tomitribe-crest.jar` fatjar directly.
The trick is to pass as first parameter `--crest.source=/path/to/file/with/commands.java`.

[source,java]
.commands.java
----
import org.tomitribe.crest.api.Command;
import java.time.LocalDate;

class Command1 {
@Command
String ok() {
return "ok";
}
}

@Command
class Command2 {
@Command
String time() {
return LocalDate.now().toString();
}
}
----

IMPORTANT: this mode has some limitation like not supporting (yet) a dynamic classpath so it just uses the script and the launching classpath.

TIP: to ease writing scripts with completion the lines starting with `//-- ` will drop this prefix.
It avoids compilations errors in general on classes no in the classpath (crest there).

Usage example:

[source,bash]
----
java \
-jar tomitribe-crest-0.20-fatjar.jar \
--crest.source=mycommands.java \
my-command \
--foo=bar
----

IMPORTANT: this requires to run with a *JDK* to work.

TIP: you can also use it in a script easily.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.tomitribe.crest.arthur.svm;

import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import org.tomitribe.crest.Main;

@TargetClass(Main.class)
public final class MainSubstitute {
@Substitute
private void handleSource(final String command) {
throw new UnsupportedOperationException("In native mode, compiler feature is disabled");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.tomitribe.crest.arthur.svm;

import com.oracle.svm.core.annotate.Delete;
import com.oracle.svm.core.annotate.TargetClass;
import org.tomitribe.crest.compiler.SimpleCompiler;

@Delete("native mode will not support compilation on the fly")
@TargetClass(SimpleCompiler.class)
public final class SimpleCompilerDelete {
}
54 changes: 48 additions & 6 deletions tomitribe-crest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,22 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.0-rc2</version>
<optional>true</optional>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<proc>none</proc>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand All @@ -103,6 +109,42 @@
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>fatjar</shadedClassifierName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.tomitribe.crest.Main</mainClass>
</transformer>
</transformers>
<artifactSet>
<excludes>
<exclude>org.apache.xbean:*</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/LICENSE.txt</exclude>
<exclude>META-INF/NOTICE.txt</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading