Skip to content

Commit ffc6a12

Browse files
authored
fix: update quarkus templates
1 parent 12c1dc0 commit ffc6a12

39 files changed

+966
-890
lines changed

pkged.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/quarkus/events/.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Eclipse
2+
.project
3+
.classpath
4+
.settings/
5+
bin/
6+
7+
# IntelliJ
8+
.idea
9+
*.ipr
10+
*.iml
11+
*.iws
12+
13+
# NetBeans
14+
nb-configuration.xml
15+
16+
# Visual Studio Code
17+
.vscode
18+
.factorypath
19+
20+
# OSX
21+
.DS_Store
22+
23+
# Vim
24+
*.swp
25+
*.swo
26+
27+
# patch
28+
*.orig
29+
*.rej
30+
31+
# Maven
32+
target/
33+
pom.xml.tag
34+
pom.xml.releaseBackup
35+
pom.xml.versionsBackup
36+
release.properties
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2007-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import java.net.*;
17+
import java.io.*;
18+
import java.nio.channels.*;
19+
import java.util.Properties;
20+
21+
public class MavenWrapperDownloader {
22+
23+
private static final String WRAPPER_VERSION = "0.5.6";
24+
/**
25+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26+
*/
27+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29+
30+
/**
31+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32+
* use instead of the default one.
33+
*/
34+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35+
".mvn/wrapper/maven-wrapper.properties";
36+
37+
/**
38+
* Path where the maven-wrapper.jar will be saved to.
39+
*/
40+
private static final String MAVEN_WRAPPER_JAR_PATH =
41+
".mvn/wrapper/maven-wrapper.jar";
42+
43+
/**
44+
* Name of the property which should be used to override the default download url for the wrapper.
45+
*/
46+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47+
48+
public static void main(String args[]) {
49+
System.out.println("- Downloader started");
50+
File baseDirectory = new File(args[0]);
51+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52+
53+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
54+
// wrapperUrl parameter.
55+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56+
String url = DEFAULT_DOWNLOAD_URL;
57+
if(mavenWrapperPropertyFile.exists()) {
58+
FileInputStream mavenWrapperPropertyFileInputStream = null;
59+
try {
60+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61+
Properties mavenWrapperProperties = new Properties();
62+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64+
} catch (IOException e) {
65+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66+
} finally {
67+
try {
68+
if(mavenWrapperPropertyFileInputStream != null) {
69+
mavenWrapperPropertyFileInputStream.close();
70+
}
71+
} catch (IOException e) {
72+
// Ignore ...
73+
}
74+
}
75+
}
76+
System.out.println("- Downloading from: " + url);
77+
78+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79+
if(!outputFile.getParentFile().exists()) {
80+
if(!outputFile.getParentFile().mkdirs()) {
81+
System.out.println(
82+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83+
}
84+
}
85+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86+
try {
87+
downloadFileFromURL(url, outputFile);
88+
System.out.println("Done");
89+
System.exit(0);
90+
} catch (Throwable e) {
91+
System.out.println("- Error downloading");
92+
e.printStackTrace();
93+
System.exit(1);
94+
}
95+
}
96+
97+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99+
String username = System.getenv("MVNW_USERNAME");
100+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101+
Authenticator.setDefault(new Authenticator() {
102+
@Override
103+
protected PasswordAuthentication getPasswordAuthentication() {
104+
return new PasswordAuthentication(username, password);
105+
}
106+
});
107+
}
108+
URL website = new URL(urlString);
109+
ReadableByteChannel rbc;
110+
rbc = Channels.newChannel(website.openStream());
111+
FileOutputStream fos = new FileOutputStream(destination);
112+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113+
fos.close();
114+
rbc.close();
115+
}
116+
117+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

templates/quarkus/events/.vscode/tasks.json

-47
This file was deleted.

templates/quarkus/events/README.md

+66-50
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,86 @@
1-
# Quarkus Cloud Events Function
1+
# Function project
22

3-
Welcome to your new Quarkus function project! This sample project contains three functions:
4-
* org.funqy.demo.GreetingFunctions.greet()
5-
* org.funqy.demo.PrimitiveFunctions.toLowerCase()
6-
* org.funqy.demo.PrimitiveFunctions.doubleIt()
3+
Welcome to your new Quarkus function project!
74

8-
Only one of the function is active at the time.
9-
Which one is determined by the `quarkus.funqy.export` property in `src/main/resources/application.properties`.
10-
11-
The `greet` function demonstrates work with java beans,
12-
it accepts `Identity` bean (data of incoming cloud event)
13-
and it returns `Greeting` bean (data of outgoing cloud event).
14-
15-
The `toLowerCase` function accepts string and returns string.
16-
As its name suggests it returns input string with all characters in lowercase.
17-
18-
The `doubleIt` function accepts integer and returns its value doubled.
19-
20-
You can test those functions by using `curl` cmd utility.
21-
Parameters for `curl` can be found at [Cloud Event emulation](#cloud-event-emulation).
5+
This sample project contains single function: `functions.Function.echo()`,
6+
the function just returns its argument.
227

238
## Local execution
24-
Make sure that `maven 3.6.2` and `Java 11 SDK` is installed.
9+
Make sure that `Java 11 SDK` is installed.
2510

26-
To start server locally run `mvn quarkus:dev`.
11+
To start server locally run `./mvnw quarkus:dev`.
2712
The command starts http server and automatically watches for changes of source code.
2813
If source code changes the change will be propagated to running server. It also opens debugging port `5005`
2914
so debugger can be attached if needed.
3015

31-
To run test locally run `mvn test`.
16+
To run test locally run `./mvnw test`.
17+
18+
## The `faas` CLI
19+
20+
It's recommended to set `FAAS_REGISTRY` environment variable.
21+
```shell script
22+
# replace ~/.bashrc by your shell rc file
23+
# replace docker.io/johndoe with your registry
24+
export FAAS_REGISTRY=docker.io/johndoe
25+
echo "export FAAS_REGISTRY=docker.io/johndoe" >> ~/.bashrc
26+
```
27+
28+
### Building
29+
30+
This command builds OCI image for the function.
31+
32+
```shell script
33+
faas build # build jar
34+
faas build --builder native # build native binary
35+
```
36+
37+
### Running
38+
39+
This command runs the function locally in a container
40+
using the image created above.
41+
```shell script
42+
faas run
43+
```
44+
45+
### Deploying
3246

33-
## Cloud Event emulation
47+
This commands will build and deploy the function into cluster.
3448

35-
sample cloud event for the `greet` function
3649
```shell script
37-
curl -v "localhost:8080" \
38-
-X POST \
39-
-H "Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f79" \
40-
-H "Ce-specversion: 0.3" \
41-
-H "Ce-Type: dev.nodeshift.samples.quarkus-funqy" \
42-
-H "Ce-Source: dev.nodeshift.samples/quarkus-funqy-source" \
43-
-H "Content-Type: application/json" \
44-
-d "{\"name\": \"$(whoami)\"}\"";
50+
faas deploy # also triggers build
51+
```
52+
53+
## Function invocation
54+
55+
Do not forget to set `URL` variable to the route of your function.
4556

57+
You get the route by following command.
58+
```shell script
59+
faas describe
4660
```
4761

48-
sample event for the `toLowerCase` function
62+
### cURL
63+
4964
```shell script
50-
curl -v "localhost:8080" \
51-
-X POST \
52-
-H "Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f79" \
53-
-H "Ce-specversion: 0.3" \
54-
-H "Ce-Type: dev.nodeshift.samples.quarkus-funqy" \
55-
-H "Ce-Source: dev.nodeshift.samples/quarkus-funqy-source" \
56-
-H "Content-Type: application/json" \
57-
-d '"wEiRDly CaPiTaLisEd sTrInG"'
65+
URL=http://localhost:8080/
66+
curl -v ${URL} \
67+
-H "Content-Type:application/json" \
68+
-H "Ce-Id:1" \
69+
-H "Ce-Source:cloud-event-example" \
70+
-H "Ce-Type:dev.knative.example" \
71+
-H "Ce-Specversion:1.0" \
72+
-d "{\"name\": \"$(whoami)\"}\""
5873
```
5974

60-
sample event for the `doubleIt` function
75+
### HTTPie
76+
6177
```shell script
62-
curl -v "localhost:8080" \
63-
-X POST \
64-
-H "Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f79" \
65-
-H "Ce-specversion: 0.3" \
66-
-H "Ce-Type: dev.nodeshift.samples.quarkus-funqy" \
67-
-H "Ce-Source: dev.nodeshift.samples/quarkus-funqy-source" \
68-
-H "Content-Type: application/json" \
69-
-d '21'
78+
URL=http://localhost:8080/
79+
http -v ${URL} \
80+
Content-Type:application/json \
81+
Ce-Id:1 \
82+
Ce-Source:cloud-event-example \
83+
Ce-Type:dev.knative.example \
84+
Ce-Specversion:1.0 \
85+
name=$(whoami)
7086
```

templates/quarkus/events/mvnw

+9-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# ----------------------------------------------------------------------------
2020

2121
# ----------------------------------------------------------------------------
22-
# Maven2 Start Up Batch script
22+
# Maven Start Up Batch script
2323
#
2424
# Required ENV vars:
2525
# ------------------
@@ -212,9 +212,9 @@ else
212212
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
213213
fi
214214
if [ -n "$MVNW_REPOURL" ]; then
215-
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar"
215+
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
216216
else
217-
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar"
217+
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
218218
fi
219219
while IFS="=" read key value; do
220220
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
@@ -246,7 +246,7 @@ else
246246
else
247247
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
248248
fi
249-
249+
250250
else
251251
if [ "$MVNW_VERBOSE" = true ]; then
252252
echo "Falling back to using Java to download"
@@ -296,6 +296,11 @@ if $cygwin; then
296296
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
297297
fi
298298

299+
# Provide a "standardized" way to retrieve the CLI args that will
300+
# work with both Windows and non-Windows executions.
301+
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
302+
export MAVEN_CMD_LINE_ARGS
303+
299304
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
300305

301306
exec "$JAVACMD" \

0 commit comments

Comments
 (0)