Skip to content

Commit

Permalink
Merge pull request #42308 from gcw-it/pr_lbupg
Browse files Browse the repository at this point in the history
Upgrade dependencies liquibase to 4.29.1 and liquibase-mongodb to 4.28.0
  • Loading branch information
gsmet authored Aug 8, 2024
2 parents c934094 + a9fcc8d commit 4ad4bba
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 250 deletions.
4 changes: 2 additions & 2 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@
<flyway.version>10.17.0</flyway.version>
<yasson.version>3.0.4</yasson.version>
<!-- liquibase-mongodb is not released everytime with liquibase anymore, but the two versions need to be compatible -->
<liquibase.version>4.27.0</liquibase.version>
<liquibase-mongodb.version>4.24.0</liquibase-mongodb.version>
<liquibase.version>4.29.1</liquibase.version>
<liquibase-mongodb.version>4.28.0</liquibase-mongodb.version>
<snakeyaml.version>2.2</snakeyaml.version>
<osgi.version>6.0.0</osgi.version>
<mongo-client.version>4.11.1</mongo-client.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.deployment.annotations;

import java.util.Collection;

import io.quarkus.builder.item.BuildItem;

/**
Expand All @@ -16,4 +18,7 @@ public interface BuildProducer<T extends BuildItem> {

void produce(T item);

default void produce(Collection<T> items) {
items.forEach(this::produce);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.deployment.util.ArtifactResourceResolver;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.paths.PathFilter;
import io.quarkus.util.GlobUtil;

/**
* A build item that indicates that a static resource should be included in the native image.
* <p>
* A static resource is a file that is not processed by the build steps, but is included in the native image as-is.
* The resource path passed to the constructor is a {@code /}-separated path name (with the same semantics as the parameters
* The resource path passed to the constructor is a {@code /}-separated path name (with the same semantics as the parameters)
* passed to {@link java.lang.ClassLoader#getResources(String)}.
* <p>
* Related build items:
Expand All @@ -23,6 +29,23 @@ public final class NativeImageResourceBuildItem extends MultiBuildItem {

private final List<String> resources;

/**
* Builds a {@code NativeImageResourceBuildItem} for the given artifact and path
*
* @param dependencies the resolved dependencies of the build
* @param artifactCoordinates the coordinates of the artifact containing the resources
* @param resourceFilter the filter for the resources in glob syntax (see {@link GlobUtil})
* @return
*/
public static NativeImageResourceBuildItem ofDependencyResources(
Collection<ResolvedDependency> dependencies,
ArtifactCoords artifactCoordinates,
PathFilter resourceFilter) {

var resolver = ArtifactResourceResolver.of(dependencies, artifactCoordinates);
return new NativeImageResourceBuildItem(resolver.resourceList(resourceFilter));
}

public NativeImageResourceBuildItem(String... resources) {
this.resources = Arrays.asList(resources);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
import java.util.Set;

import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.deployment.util.ArtifactResourceResolver;
import io.quarkus.deployment.util.ServiceUtil;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.paths.PathFilter;

/**
* Represents a Service Provider registration.
Expand All @@ -21,6 +25,8 @@
public final class ServiceProviderBuildItem extends MultiBuildItem {

public static final String SPI_ROOT = "META-INF/services/";
private static final PathFilter SPI_FILTER = PathFilter.forIncludes(List.of(SPI_ROOT + "*"));

private final String serviceInterface;
private final List<String> providers;

Expand Down Expand Up @@ -52,7 +58,7 @@ public static ServiceProviderBuildItem allProviders(final String serviceInterfac
line = line.substring(0, commentIndex);
}
line = line.trim();
if (line.length() != 0) {
if (!line.isEmpty()) {
classNames.add(line);
}
}
Expand Down Expand Up @@ -87,6 +93,48 @@ public static ServiceProviderBuildItem allProvidersFromClassPath(final String se
}
}

/**
* Creates a new {@link Collection} of {@code ServiceProviderBuildItem}s for the selected artifact.
* It includes all the providers, that are contained in all the service interface descriptor files defined in
* {@code "META-INF/services/"} in the selected artifact.
*
* @param dependencies the resolved dependencies of the build
* @param artifactCoordinates the coordinates of the artifact containing the service definitions
* @return a {@link Collection} of {@code ServiceProviderBuildItem}s containing all the found service providers
*/
public static Collection<ServiceProviderBuildItem> allProvidersOfDependency(
Collection<ResolvedDependency> dependencies,
ArtifactCoords artifactCoordinates) {

return allProvidersOfDependencies(dependencies, List.of(artifactCoordinates));
}

/**
* Creates a new {@link Collection} of {@code ServiceProviderBuildItem}s for the selected artifacts.
* It includes all the providers, that are contained in all the service interface descriptor files defined in
* {@code "META-INF/services/"} in all the selected artifacts.
*
* @param dependencies the resolved dependencies of the build
* @param artifactCoordinatesCollection a {@link Collection} of coordinates of the artifacts containing the service
* definitions
* @return a {@link Collection} of {@code ServiceProviderBuildItem}s containing all the found service providers
*/
public static Collection<ServiceProviderBuildItem> allProvidersOfDependencies(
Collection<ResolvedDependency> dependencies,
Collection<ArtifactCoords> artifactCoordinatesCollection) {

var resolver = ArtifactResourceResolver.of(dependencies, artifactCoordinatesCollection);
return resolver.resourcePathList(SPI_FILTER).stream()
.map(ServiceProviderBuildItem::ofSpiPath)
.toList();
}

private static ServiceProviderBuildItem ofSpiPath(Path spiPath) {
return new ServiceProviderBuildItem(
spiPath.getFileName().toString(),
ServiceUtil.classNamesNamedIn(spiPath.toString()));
}

/**
* Registers the specified service interface descriptor to be embedded and allow reflection (instantiation only)
* of the specified provider classes. Note that the service interface descriptor file has to exist and match the
Expand Down Expand Up @@ -136,12 +184,12 @@ private ServiceProviderBuildItem(String serviceInterfaceClassName, List<String>
this.providers = providers;

// Validation
if (serviceInterface.length() == 0) {
if (serviceInterface.isEmpty()) {
throw new IllegalArgumentException("The serviceDescriptorFile interface cannot be blank");
}

providers.forEach(s -> {
if (s == null || s.length() == 0) {
if (s == null || s.isEmpty()) {
throw new IllegalArgumentException("The provider class name cannot be null or blank");
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package io.quarkus.deployment.util;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ArtifactCoordsPattern;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.paths.PathFilter;
import io.quarkus.paths.PathVisit;
import io.quarkus.util.GlobUtil;

/**
* Utility class to extract a list of resource paths from a given artifact and path.
*/
public final class ArtifactResourceResolver {
private final Collection<ResolvedDependency> artifacts;

/**
* Creates a {@code ArtifactResourceResolver} for the given artifact
*
* @param dependencies the resolved dependencies of the build
* @param artifactCoordinates the coordinates of the artifact containing the resources
*/
public static ArtifactResourceResolver of(
Collection<ResolvedDependency> dependencies, ArtifactCoords artifactCoordinates) {

return new ArtifactResourceResolver(dependencies, List.of(artifactCoordinates));
}

/**
* Creates a {@code ArtifactResourceResolver} for the given artifact
*
* @param dependencies the resolved dependencies of the build
* @param artifactCoordinatesCollection a coordinates {@link Collection} for the artifacts containing the resources
*/
public static ArtifactResourceResolver of(
Collection<ResolvedDependency> dependencies, Collection<ArtifactCoords> artifactCoordinatesCollection) {

return new ArtifactResourceResolver(dependencies, artifactCoordinatesCollection);
}

private ArtifactResourceResolver(
Collection<ResolvedDependency> dependencies, Collection<ArtifactCoords> artifactCoordinates) {

var patterns = ArtifactCoordsPattern.toPatterns(artifactCoordinates);
artifacts = patterns.stream()
.map(p -> findArtifact(dependencies, p))
.collect(Collectors.toSet());
}

private static ResolvedDependency findArtifact(
Collection<ResolvedDependency> dependencies, ArtifactCoordsPattern pattern) {

return dependencies.stream()
.filter(pattern::matches)
.findFirst()
.orElseThrow(() -> new IllegalArgumentException(
"%s artifact not found".formatted(pattern.toString())));
}

/**
* Extracts a {@link Collection} of resource paths with the given filter
*
* @param pathFilter the filter for the resources in glob syntax (see {@link GlobUtil})
* @return a collection of the found resource paths
*/
public Collection<Path> resourcePathList(PathFilter pathFilter) {
return artifacts.stream()
.map(a -> pathsForArtifact(a, pathFilter))
.flatMap(Collection::stream)
.toList();
}

private Collection<Path> pathsForArtifact(ResolvedDependency artifact, PathFilter pathFilter) {
var pathList = new ArrayList<Path>();
var pathTree = artifact.getContentTree(pathFilter);
pathTree.walk(visit -> pathList.add(relativePath(visit)));
return pathList;
}

private Path relativePath(PathVisit visit) {
var path = visit.getPath();
return path.getRoot().relativize(path);
}

/**
* Extracts a {@link List} of resource paths as strings with the given filter
*
* @param pathFilter the filter for the resources in glob syntax (see {@link GlobUtil})
* @return a list of the found resource paths as strings
*/
public List<String> resourceList(PathFilter pathFilter) {
return resourcePathList(pathFilter).stream()
.map(Path::toString)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/**
*/
public final class ServiceUtil {

private ServiceUtil() {
}

Expand Down Expand Up @@ -59,6 +60,14 @@ public static Set<String> classNamesNamedIn(Path path) throws IOException {
return set;
}

public static Set<String> classNamesNamedIn(String filePath) {
try {
return classNamesNamedIn(Thread.currentThread().getContextClassLoader(), filePath);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}

/**
* - Lines starting by a # (or white spaces and a #) are ignored. - For
* lines containing data before a comment (#) are parsed and only the value
Expand Down
6 changes: 6 additions & 0 deletions extensions/liquibase-mongodb/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-liquibase-mongodb</artifactId>
<exclusions>
<exclusion>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-commercial</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Loading

0 comments on commit 4ad4bba

Please sign in to comment.