Skip to content

Commit

Permalink
Initial migration commit
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Nesen <[email protected]>
  • Loading branch information
senivam committed Jun 5, 2024
1 parent f749e8a commit b564ef9
Show file tree
Hide file tree
Showing 1,219 changed files with 74,590 additions and 15 deletions.
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/examples/config/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
```
65 changes: 65 additions & 0 deletions examples/config/basics/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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>4.1.0-SNAPSHOT</version>
</parent>
<groupId>io.helidon.examples.config</groupId>
<artifactId>helidon-examples-config-basics</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>Helidon Examples Config Basics</name>

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

<properties>
<mainClass>io.helidon.examples.config.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.examples.config.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.examples.config.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"
}
]
}
26 changes: 26 additions & 0 deletions examples/config/basics/src/main/resources/logging.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# 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.
#


handlers = java.util.logging.ConsoleHandler

java.util.logging.ConsoleHandler.level = FINEST
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format = [%1$tc] %4$s: %2$s - %5$s %6$s%n

.level = INFO
io.helidon.config.level = WARNING
io.helidon.config.examples.level = FINEST
29 changes: 29 additions & 0 deletions examples/config/changes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Helidon Config Changes Example

This example shows how an application can deal with changes to
configuration.

## Change notification

[`OnChangeExample.java`](src/main/java/io/helidon/examples/config/changes/OnChangeExample.java):
uses `Config.onChange`, passing either a method reference (a lambda expression
would also work) which the config system invokes when the config source changes
)

## Latest-value supplier

Recall that once your application obtains a `Config` instance, its config values
do not change. The
[`AsSupplierExample.java`](src/main/java/io/helidon/examples/config/changes/AsSupplierExample.java)
example shows how your application can get a config _supplier_ that always reports
the latest config value for a key, including any changes made after your
application obtained the `Config` object. Although this approach does not notify
your application _when_ changes occur, it _does_ permit your code to always use
the most up-to-date value. Sometimes that is all you need.

## Build and run

```shell
mvn package
java -jar target/helidon-examples-config-changes.jar
```
21 changes: 21 additions & 0 deletions examples/config/changes/conf/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# 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.
#

# In config.yaml we are going to override default configuration.
# It is supposed to be deployment dependent configuration.

app:
greeting: Hello
25 changes: 25 additions & 0 deletions examples/config/changes/conf/dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# 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.
#

# In dev.yaml we are going to override all lower layer configuration files.
# It is supposed to be development specific configuration.

# IT SHOULD NOT BE PLACED IN VCS. EACH DEVELOPER CAN CUSTOMIZE THE FILE AS NEEDED.
# I.e. for example with GIT place following line into .gitignore file:
#*/conf/dev.yaml

app:
name: Developer
1 change: 1 addition & 0 deletions examples/config/changes/conf/secrets/password
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
changeit
1 change: 1 addition & 0 deletions examples/config/changes/conf/secrets/username
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libor
Loading

0 comments on commit b564ef9

Please sign in to comment.