Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Apr 19, 2023
2 parents 2284a45 + 17c1de0 commit e8673d8
Show file tree
Hide file tree
Showing 19 changed files with 174 additions and 168 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
java: [8, 11, 17]
java: [11, 17]
os: [ubuntu-latest]
distribution: [temurin]

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/maven-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Deploy snapshots to Sonatpe OSS repository and deploy site to GitHub Pages
# Deploy snapshots to Sonatype OSS repository and deploy site to GitHub Pages

name: Deploy

Expand All @@ -15,19 +15,19 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Configure GIT
run: |
git config --global user.email "${{ secrets.GH_SITE_DEPLOY_EMAIL }}"
git config --global user.name "${{ secrets.GH_SITE_DEPLOY_NAME }}"
- name: Setup JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
cache: 'maven'
java-version: 11
cache: maven

- name: Build, verify, deploy, generate site
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-from-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ncipollo/release-action@v1
with:
body: 'Changes: https://wcm.io/sling/commons/changes-report.html'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ npm-debug.log
.vlt
.vlt-sync*
.brackets.json
dependency-reduced-pom.xml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Common Sling utility and helper functions.

Documentation: https://wcm.io/sling/commons/<br/>
Issues: https://wcm-io.atlassian.net/browse/WSLI<br/>
Issues: https://github.com/wcm-io/io.wcm.sling.commons/issues<br/>
Wiki: https://wcm-io.atlassian.net/wiki/<br/>
Continuous Integration: https://github.com/wcm-io/io.wcm.sling.commons/actions<br/>
Commercial support: https://wcm.io/commercial-support.html
Expand Down
9 changes: 9 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
<body>

<release version="1.6.2" date="2023-04-19">
<action type="update" dev="sseifert">
Switch to Java 11 as minimum version.
</action>
<action type="update" dev="sseifert" issue="9">
Eliminate dependency to Guava. Embed Caffeine as replacement for Guava Cache.
</action>
</release>

<release version="1.6.0" date="2022-12-05">
<action type="add" dev="sseifert">
ContextAwareServiceResolver: Add ContextAwareServiceCollectionResolver that allows context-aware filtering of a pre-propulated service collections (e.g. managed by Declarative Services).
Expand Down
63 changes: 54 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<parent>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.parent_toplevel</artifactId>
<version>2.1.0</version>
<version>2.2.0</version>
<relativePath/>
</parent>

<groupId>io.wcm</groupId>
<artifactId>io.wcm.sling.commons</artifactId>
<version>1.6.0</version>
<version>1.6.2</version>
<packaging>jar</packaging>

<name>Sling Commons</name>
Expand All @@ -49,7 +49,7 @@
<site.url.module.prefix>sling/commons</site.url.module.prefix>

<!-- Enable reproducible builds -->
<project.build.outputTimestamp>2022-12-05T12:35:44Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2023-04-19T11:06:55Z</project.build.outputTimestamp>
</properties>

<dependencies>
Expand All @@ -65,6 +65,13 @@
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>3.1.5</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down Expand Up @@ -110,12 +117,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down Expand Up @@ -148,6 +149,14 @@
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<configuration>
<bnd>
<!-- Caffeine is embedded -->
Import-Package: \
!com.github.benmanes.caffeine.*, \
*
</bnd>
</configuration>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
Expand All @@ -163,6 +172,42 @@
</configuration>
</plugin>

<!-- Embed shaded version of Caffeine to avoid classpath issues in unit tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<artifactSet>
<includes>
<include>com.github.ben-manes.caffeine:caffeine</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>com.github.benmanes.caffeine</pattern>
<shadedPattern>io.wcm.sling.commons.shaded.com.github.benmanes.caffeine</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>com.github.ben-manes.caffeine:caffeine</artifact>
<excludes>
<exclude>module-info.class</exclude>
<exclude>META-INF/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalNotification;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.github.benmanes.caffeine.cache.RemovalCause;

import io.wcm.sling.commons.caservice.ContextAwareService;
import io.wcm.sling.commons.caservice.ContextAwareServiceCollectionResolver;
Expand All @@ -62,22 +61,19 @@ class ContextAwareServiceCollectionResolverImpl<S extends ContextAwareService, D

private static <S extends ContextAwareService, D> LoadingCache<ServiceReference<S>, CollectionItemDecoration<S, D>> buildCache(
@NotNull BiFunction<@NotNull ServiceReference<S>, @Nullable S, @Nullable D> decorator, @NotNull BundleContext bundleContext) {
return CacheBuilder.newBuilder()
return Caffeine.newBuilder()
// expire cached entry after 24h
.expireAfterAccess(24, TimeUnit.HOURS)
// unget service on removal
.removalListener((RemovalNotification<ServiceReference<S>, CollectionItemDecoration<S, D>> notification) -> {
log.debug("Remove service {}", notification.getValue());
bundleContext.ungetService(notification.getKey());
.removalListener((ServiceReference<S> key, CollectionItemDecoration<S, D> value, RemovalCause cause) -> {
log.debug("Remove service {}", value);
bundleContext.ungetService(key);
})
// build cache lazily
.build(new CacheLoader<ServiceReference<S>, CollectionItemDecoration<S, D>>() {
@Override
public CollectionItemDecoration<S, D> load(ServiceReference<S> serviceReference) {
CollectionItemDecoration<S, D> item = new CollectionItemDecoration<>(serviceReference, decorator, bundleContext);
log.debug("Add service {}", item);
return item;
}
.build((ServiceReference<S> serviceReference) -> {
CollectionItemDecoration<S, D> item = new CollectionItemDecoration<>(serviceReference, decorator, bundleContext);
log.debug("Add service {}", item);
return item;
});
}

Expand Down Expand Up @@ -112,7 +108,7 @@ public CollectionItemDecoration<S, D> load(ServiceReference<S> serviceReference)
private @NotNull Stream<CollectionItemDecoration<S, D>> getMatching(@Nullable Adaptable adaptable) {
String resourcePath = resourcePathResolver.get(adaptable);
return serviceReferenceCollection.stream()
.map(decorationCache::getUnchecked)
.map(decorationCache::get)
.filter(CollectionItemDecoration::isValid)
.filter(item -> item.matches(resourcePath));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.util.Collection;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import java.util.stream.Collectors;
Expand All @@ -42,11 +41,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.github.benmanes.caffeine.cache.RemovalCause;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.wcm.sling.commons.caservice.ContextAwareService;
Expand Down Expand Up @@ -85,20 +82,9 @@ private void deactivate() {

private static <S extends ContextAwareService> LoadingCache<String, ContextAwareServiceTracker<S>> buildServiceTrackerCache(
BundleContext bundleContext) {
return CacheBuilder.newBuilder()
.removalListener(new RemovalListener<String, ContextAwareServiceTracker<S>>() {
@SuppressWarnings("null")
@Override
public void onRemoval(RemovalNotification<String, ContextAwareServiceTracker<S>> notification) {
notification.getValue().dispose();
}
})
.build(new CacheLoader<String, ContextAwareServiceTracker<S>>() {
@Override
public ContextAwareServiceTracker load(String className) {
return new ContextAwareServiceTracker<>(className, bundleContext);
}
});
return Caffeine.newBuilder()
.removalListener((String key, ContextAwareServiceTracker<S> value, RemovalCause reason) -> value.dispose())
.build(className -> new ContextAwareServiceTracker<>(className, bundleContext));
}

@Override
Expand Down Expand Up @@ -148,12 +134,7 @@ private <S extends ContextAwareService> Stream<ServiceInfo<S>> getMatchingServic
"unchecked"
})
private <S extends ContextAwareService> ContextAwareServiceTracker<S> getServiceTracker(Class<S> serviceClass) {
try {
return (ContextAwareServiceTracker)serviceTrackerCache.get(serviceClass.getName());
}
catch (ExecutionException ex) {
throw new RuntimeException("Error getting service tracker for " + serviceClass.getName() + " from cache.", ex);
}
return (ContextAwareServiceTracker)serviceTrackerCache.get(serviceClass.getName());
}

ConcurrentMap<String, ContextAwareServiceTracker<ContextAwareService>> getContextAwareServiceTrackerMap() {
Expand Down
Loading

0 comments on commit e8673d8

Please sign in to comment.