Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Helidon 2.x examples #39

Merged
merged 10 commits into from
Apr 11, 2024
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Download Maven Artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: io-helidon-maven-artifacts
path: ~/.m2/repository/io/helidon
Expand All @@ -82,7 +82,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Download Maven Artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: io-helidon-maven-artifacts
path: ~/.m2/repository/io/helidon
Expand All @@ -104,7 +104,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Download Maven Artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: io-helidon-maven-artifacts
path: ~/.m2/repository/io/helidon
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@

# Helidon Examples

Examples for Helidon 3.
Examples for Helidon 2.

[Helidon 4 Examples](https://github.com/helidon-io/helidon/tree/main/examples) and [Helidon 2 Examples](https://github.com/helidon-io/helidon/tree/helidon-2.x/examples) are in the primary Helidon repository.

## How to Run

To build and run Helidon 3 examples you need:
To build and run Helidon 2 examples you need:

* Java 17 or later
* Java 11 or later
* Maven 3.6.1 or later

Then:

```
git clone https://github.com/helidon-io/helidon-examples.git
cd helidon-examples
git checkout helidon-3.x
git checkout helidon-2.x
mvn clean install
```

Expand All @@ -26,22 +26,24 @@ mvn clean install
| Branch | Description |
| ------------- |-------------|
| helidon-3.x | Examples for the current release of Helidon 3 |
| helidon-2.x | Examples for the current release of Helidon 2 |
| dev-3.x | Development branch for Helidon 3 release currently under development |
| dev-2.x | Development branch for Helidon 2 release currently under development |

| Tags | Description |
| ------------- |-------------|
| N.N.N | Examples for a specific version of Helion |

To checkout examples for the most recent release of Helidon 3:
To checkout examples for the most recent release of Helidon 2:

```
git checkout helidon-3.x
git checkout helidon-2.x
```

To checkout examples for a specific release of Helidon:

```
git checkout tags/3.2.5
git checkout tags/2.X.Y
```

## Documentation
Expand Down
18 changes: 16 additions & 2 deletions etc/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--

Copyright (c) 2016, 2023 Oracle and/or its affiliates.
Copyright (c) 2016, 2024 Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,7 @@
"http://checkstyle.sourceforge.net/dtds/suppressions_1_1.dtd">

<suppressions>
<!-- Code generated by openapi tools -->
<!-- Java comments, import order and style of the files should be generated by OpenApi Tools. -->
<suppress checks="ConstantName"
files="examples/openapi-tools/"/>
<suppress checks="ImportOrder"
Expand All @@ -43,4 +43,18 @@
files="examples/openapi-tools/"/>
<suppress checks="HideUtilityClassConstructor"
files="examples/openapi-tools/"/>

<suppress checks="UnusedImports"
files="examples/openapi-tools/"/>
<suppress checks="JavadocPackage"
files="examples/openapi-tools/"/>
<suppress checks="AvoidStarImport"
files="examples/openapi-tools/"/>
<suppress checks="WhitespaceAround"
files="examples/openapi-tools/"/>
<suppress checks="LineLength"
files="examples/openapi-tools/"/>
<suppress checks="MethodParamPad"
files="examples/openapi-tools/"/>

</suppressions>
38 changes: 38 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<p align="center">
<img src="../etc/images/Primary_logo_blue.png" height="180">
</p>

# Helidon Examples

Welcome to the Helidon Examples! If this is your first experience with
Helidon we recommend you start with our
[quickstart](https://helidon.io/docs/v2/#/about/03_prerequisites)
That will quickly get you going with your first Helidon application.

After that you can come back here and dig into the examples.

Our examples are Maven projects and can be built and run with
Java 11 or newer -- so make sure you have those:

```
java -version
mvn -version
```

# Building an Example

Each example has a `README` that you will follow. To build most examples
just `cd` to the directory and run `mvn package`:

```
cd examples/microprofile/hello-world-explicit
mvn package
```

Usually the example will produce an application jar file that you can run:

```
java -jar target/example-name.jar
```

But always see the example's `README` for details.
5 changes: 5 additions & 0 deletions examples/config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

# Helidon SE Config Examples

Each subdirectory contains example code that highlights specific aspects of
Helidon configuration.
16 changes: 16 additions & 0 deletions examples/config/basics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Helidon Config Basic Example

This example shows the basics of using Helidon SE Config. The
[Main.java](./src/main/java/io/helidon/config/examples/basics/Main.java) class shows:

* loading configuration from a resource
[`application.conf`](./src/main/resources/application.conf) on the classpath
containing config in HOCON (Human-Optimized Config Object Notation) format
* getting configuration values of various types

## Build and run

```shell
mvn package
java -jar target/helidon-examples-config-basics.jar
```
66 changes: 66 additions & 0 deletions examples/config/basics/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2017, 2024 Oracle and/or its affiliates.

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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.helidon.applications</groupId>
<artifactId>helidon-se</artifactId>
<version>2.6.8-SNAPSHOT</version>
<relativePath/>
</parent>
<groupId>io.helidon.examples.config</groupId>
<artifactId>helidon-examples-config-basics</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>Helidon Config Examples Basics</name>

<description>
The simplest example shows how to use Configuration API.
</description>

<properties>
<mainClass>io.helidon.config.examples.basics.Main</mainClass>
</properties>

<dependencies>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-hocon</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-libs</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2017, 2024 Oracle and/or its affiliates.
*
* 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 io.helidon.config.examples.basics;

import java.nio.file.Path;
import java.util.List;

import io.helidon.config.Config;

import static io.helidon.config.ConfigSources.classpath;

/**
* Basics example.
*/
public class Main {

private Main() {
}

/**
* Executes the example.
*
* @param args arguments
*/
public static void main(String... args) {
Config config = Config.create(classpath("application.conf"));

int pageSize = config.get("app.page-size").asInt().get();

boolean storageEnabled = config.get("app.storageEnabled").asBoolean().orElse(false);

List<Integer> basicRange = config.get("app.basic-range").asList(Integer.class).get();

Path loggingOutputPath = config.get("logging.outputs.file.name").as(Path.class).get();

System.out.println(pageSize);
System.out.println(storageEnabled);
System.out.println(basicRange);
System.out.println(loggingOutputPath);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2017, 2024 Oracle and/or its affiliates.
*
* 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.
*/

/**
* The simplest example shows how to use Configuration API.
*/
package io.helidon.config.examples.basics;
69 changes: 69 additions & 0 deletions examples/config/basics/src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#
# Copyright (c) 2017, 2024 Oracle and/or its affiliates.
#
# 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.
#

app {
greeting = "Hello"
name = "Demo"
page-size = 20
basic-range = [ -20, 20 ]
storagePassphrase = "${AES=thisIsEncriptedPassphrase}"
}

logging {
outputs {
console {
pattern = simple.colored
level = INFO
}
file {
pattern = verbose.colored
level = DEBUG
name = target/root.log
}
}
level = INFO
app.level = DEBUG
com.oracle.prime.level = WARN
}

# (this is snippet of complex configuration of security component)
security {
providers: [ # First provider in the list is the default one
{
name = "BMCS"
class = "com.oracle.prime.security.bmcs.BmcsProvider"
BmcsProvider {
# Configuration of OPC (Bare metal) security provider
# (configuration cleaned to be short ...)

# targets for outbound configuration
targets: [
{
name = "s2s"
transports = ["http"]
hosts = ["127.0.0.1"]
s2sType = "S2S"
}
#, other targets ...
]
}
},
{
name = "ForEndUsers"
class = "com.oracle.prime.examples.security.primeruntime.bmcs.ExampleSecurityProvider"
}
]
}
Loading