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

Updates to Helidon Common, Part 1 #4693

Merged
merged 9 commits into from
Aug 10, 2022
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ We are pleased to announce Helidon 4.0.0 a major release that includes significa

### Notable Changes

- Java 19 (with Loom support) as the minimal Java version
- Java 19 early access (with Loom support) as the minimal Java version
- Using System.Logger instead of java util logging (incremental change)
- `HelidonServiceLoader` is now part of `helidon-common` module
- Introduction of `@Weight`, `Weighted` and `Weights` instead of `@Priority` and `Prioritized`, to base ordering on a double (allows to fit a component between any other two components), all modules using priority are refactored (except for MicroProfile where required by specifications).
- higher weight means a component is more important
- moved priority related types to MP config (as that is the lowest level MP module)
- replaces all instances in SE that use priority with weight (no dependency on Jakarta, predictible and easy to understand behavior)
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ Helidon supports two programming models:

In either case your application is just a Java SE program.

## Early access branch
This branch requires Java 19 early access release with Loom support.
Applications written using this version will require `--enable-preview` to be used when starting JVM.
Kindly use latest official release to work with Java 17, unless you are interested in the newest and greatest!

## License

Helidon is available under Apache License 2.0.
Expand Down
5 changes: 0 additions & 5 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,6 @@
<artifactId>helidon-common-key-util</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common-service-loader</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common-media-type</artifactId>
Expand Down
31 changes: 18 additions & 13 deletions common/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@
<artifactId>helidon-common</artifactId>
<name>Helidon Common</name>

<properties>
<!-- Helidon common should be backward compatible with Java 11 -->
<version.java>11</version.java>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -71,17 +89,4 @@
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions common/common/src/main/java/io/helidon/common/Builder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2021 Oracle and/or its affiliates.
* Copyright (c) 2017, 2022 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 Down Expand Up @@ -39,7 +39,7 @@ public interface Builder<B extends Builder<B, T>, T> extends Supplier<T> {
T build();

/**
* Update the builder in a fluen API way.
* Update the builder in a fluent API way.
*
* @param consumer consumer of the builder instance
* @return updated builder instance
Expand Down
11 changes: 5 additions & 6 deletions common/common/src/main/java/io/helidon/common/Errors.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2021 Oracle and/or its affiliates.
* Copyright (c) 2017, 2022 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 @@ -20,7 +20,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.logging.Logger;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -115,7 +114,7 @@ public boolean hasHint() {
* otherwise.
*/

public boolean log(Logger logger) {
public boolean log(System.Logger logger) {
if (!isEmpty()) {
StringBuilder fatals = new StringBuilder("\n");
StringBuilder warnings = new StringBuilder();
Expand All @@ -141,14 +140,14 @@ public boolean log(Logger logger) {
if (hasFatal) {
fatals.append(warnings).append(hints);

logger.severe("Fatal issues found: " + fatals);
logger.log(System.Logger.Level.ERROR, "Fatal issues found: " + fatals);
} else {
if (warnings.length() > 0) {
logger.warning("Warnings found: \n" + warnings);
logger.log(System.Logger.Level.WARNING, "Warnings found: \n" + warnings);
}

if (hints.length() > 0) {
logger.config("Hints found: \n" + hints);
logger.log(System.Logger.Level.TRACE, "Hints found: \n" + hints);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2021 Oracle and/or its affiliates.
* Copyright (c) 2018, 2022 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 Down Expand Up @@ -62,6 +62,11 @@
* @param <T> the generic type parameter
*/
public class GenericType<T> implements Type {
/**
* Generic type for String.
*/
public static final GenericType<String> STRING = GenericType.create(String.class);

private final Type type;
private final Class<?> rawType;

Expand Down
39 changes: 21 additions & 18 deletions common/common/src/main/java/io/helidon/common/HelidonFeatures.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020 Oracle and/or its affiliates.
* Copyright (c) 2019, 2022 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 @@ -16,6 +16,7 @@

package io.helidon.common;

import java.lang.System.Logger.Level;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.HashMap;
Expand All @@ -28,7 +29,6 @@
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Logger;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -56,8 +56,8 @@
* </pre>
*/
public final class HelidonFeatures {
private static final Logger LOGGER = Logger.getLogger(HelidonFeatures.class.getName());
private static final Logger EXPERIMENTAL = Logger.getLogger(HelidonFeatures.class.getName() + ".experimental");
private static final System.Logger LOGGER = System.getLogger(HelidonFeatures.class.getName());
private static final System.Logger EXPERIMENTAL = System.getLogger(HelidonFeatures.class.getName() + ".experimental");
private static final AtomicBoolean PRINTED = new AtomicBoolean();
private static final AtomicBoolean SCANNED = new AtomicBoolean();
private static final AtomicReference<HelidonFlavor> CURRENT_FLAVOR = new AtomicReference<>();
Expand Down Expand Up @@ -145,16 +145,16 @@ private static void features(HelidonFlavor flavor, String version, boolean detai

Set<FeatureDescriptor> features = FEATURES.get(currentFlavor);
if (null == features) {
LOGGER.info("Helidon " + currentFlavor + " " + version + " has no registered features");
LOGGER.log(Level.INFO, "Helidon " + currentFlavor + " " + version + " has no registered features");
} else {
String featureString = "[" + features.stream()
.map(FeatureDescriptor::name)
.collect(Collectors.joining(", "))
+ "]";
LOGGER.info("Helidon " + currentFlavor + " " + version + " features: " + featureString);
LOGGER.log(Level.INFO, "Helidon " + currentFlavor + " " + version + " features: " + featureString);
}
if (details) {
LOGGER.info("Detailed feature tree:");
LOGGER.log(Level.INFO, "Detailed feature tree:");
FEATURES.get(currentFlavor)
.forEach(feature -> printDetails(feature.name(),
ROOT_FEATURE_NODES.get(currentFlavor).get(feature.path()[0]),
Expand All @@ -166,9 +166,11 @@ private static void features(HelidonFlavor flavor, String version, boolean detai
ROOT_FEATURE_NODES.get(currentFlavor).get(feature.path()[0])));

if (!allExperimental.isEmpty()) {
EXPERIMENTAL.info("You are using experimental features. These APIs may change, please follow changelog!");
EXPERIMENTAL.log(Level.INFO,
"You are using experimental features. These APIs may change, please follow changelog!");
allExperimental
.forEach(it -> EXPERIMENTAL.info("\tExperimental feature: " + it.name() + " (" + it.stringPath() + ")"));
.forEach(it -> EXPERIMENTAL.log(Level.INFO,
"\tExperimental feature: " + it.name() + " (" + it.stringPath() + ")"));
}
}
}
Expand All @@ -184,20 +186,21 @@ private static void gatherExperimental(List<FeatureDescriptor> allExperimental,
* Will scan all features and log errors and warnings for features that have a
* native image limitation.
* This method is automatically called when building a native image with Helidon.
*
* @param classLoader to look for features in
*/
public static void nativeBuildTime(ClassLoader classLoader) {
scan(classLoader);
for (FeatureDescriptor feat : ALL_FEATURES) {
if (!feat.nativeSupported()) {
LOGGER.severe("Feature '" + feat.name()
+ "' for path '" + feat.stringPath()
+ "' IS NOT SUPPORTED in native image. Image may still build and run.");
LOGGER.log(Level.ERROR, "Feature '" + feat.name()
+ "' for path '" + feat.stringPath()
+ "' IS NOT SUPPORTED in native image. Image may still build and run.");
} else {
if (!feat.nativeDescription().isBlank()) {
LOGGER.warning("Feature '" + feat.name()
+ "' for path '" + feat.stringPath()
+ "' has limited support in native image: " + feat.nativeDescription());
LOGGER.log(Level.WARNING, "Feature '" + feat.name()
+ "' for path '" + feat.stringPath()
+ "' has limited support in native image: " + feat.nativeDescription());
}
}
}
Expand Down Expand Up @@ -230,7 +233,7 @@ private static void scan(ClassLoader classLoader) {
Set<FeatureDescriptor> featureDescriptors = FeatureCatalog.get(packageName);
if (featureDescriptors == null) {
if (packageName.startsWith("io.helidon.")) {
LOGGER.fine("No catalog entry for package " + packageName);
LOGGER.log(Level.TRACE, "No catalog entry for package " + packageName);
}
} else {
featureDescriptors.forEach(HelidonFeatures::register);
Expand All @@ -244,15 +247,15 @@ private static void scan(ClassLoader classLoader) {
if (feature.nativeSupported()) {
String desc = feature.nativeDescription();
if (desc != null && !desc.isBlank()) {
LOGGER.warning("Native image for feature "
LOGGER.log(Level.WARNING, "Native image for feature "
+ feature.name()
+ "("
+ feature.stringPath()
+ "): "
+ desc);
}
} else {
LOGGER.severe("You are using a feature not supported in native image: "
LOGGER.log(Level.ERROR, "You are using a feature not supported in native image: "
+ feature.name()
+ "("
+ feature.stringPath()
Expand Down
Loading