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 84be64b + c2af75d commit 1e17562
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 105 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/handler/url/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 @@
URL resolving and processing.

Documentation: https://wcm.io/handler/url/<br/>
Issues: https://wcm-io.atlassian.net/projects/WHAN<br/>
Issues: https://github.com/wcm-io/io.wcm.handler.url/issues<br/>
Wiki: https://wcm-io.atlassian.net/wiki/<br/>
Continuous Integration: https://github.com/wcm-io/io.wcm.handler.url/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.10.2" date="2023-04-19">
<action type="update" dev="sseifert">
Switch to Java 11 as minimum version.
</action>
<action type="update" dev="sseifert" issue="4">
Eliminate dependency to Guava. Embed Caffeine as replacement for Guava Cache.
</action>
</release>

<release version="1.10.0" date="2022-12-15">
<action type="add" dev="sseifert">
Add UrlBuilder.disableSuffixSelector to allow to diable the automatic addition of a "suffix" selector in case a suffix is present.
Expand Down
64 changes: 58 additions & 6 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.handler.url</artifactId>
<version>1.10.0</version>
<version>1.10.2</version>
<packaging>jar</packaging>

<name>URL Handler</name>
Expand All @@ -49,7 +49,7 @@
<site.url.module.prefix>handler/url</site.url.module.prefix>

<!-- Enable reproducible builds -->
<project.build.outputTimestamp>2022-12-15T11:14:50Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2023-04-19T11:22:03Z</project.build.outputTimestamp>
</properties>

<dependencies>
Expand Down Expand Up @@ -86,6 +86,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.apache.sling</groupId>
<artifactId>org.apache.sling.testing.hamcrest</artifactId>
Expand Down Expand Up @@ -119,8 +126,15 @@
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<version>5.1.2</version>
<version>5.2.0</version>
<scope>test</scope>
<exclusions>
<!-- Exclude Sling XSS to avoid conflict with org.xml.sax packages exported -->
<exclusion>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.xss</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
Expand All @@ -137,7 +151,7 @@
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.wcm-io-mock.sling</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -179,9 +193,11 @@
Sling-Initial-Content: \
SLING-INF/app-root;overwrite:=true;ignoreImportProviders:=xml;path:=/apps/wcm-io/handler/url

<!-- For build compatibility with Java 11 -->
Import-Package: \
<!-- For build compatibility with Java 11 -->\
javax.annotation;version="[0.0,2)",\
<!-- Caffeine is embedded -->\
!com.github.benmanes.caffeine.*, \
*
</bnd>
</configuration>
Expand All @@ -200,6 +216,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.handler.url.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
15 changes: 4 additions & 11 deletions src/main/java/io/wcm/handler/url/impl/SiteRootDetectorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package io.wcm.handler.url.impl;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

import org.apache.sling.api.resource.Resource;
Expand All @@ -30,8 +29,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

import io.wcm.handler.url.SiteRootDetector;
import io.wcm.wcm.commons.util.Path;
Expand All @@ -50,7 +49,7 @@ public class SiteRootDetectorImpl implements SiteRootDetector {
private static final Logger log = LoggerFactory.getLogger(SiteRootDetectorImpl.class);

// cache resolving of site root level per resource path
private final Cache<String, Integer> cache = CacheBuilder.newBuilder()
private final Cache<String, Integer> cache = Caffeine.newBuilder()
.expireAfterWrite(1, TimeUnit.MINUTES)
.maximumSize(10000)
.build();
Expand All @@ -60,13 +59,7 @@ public int getSiteRootLevel(@Nullable Resource contextResource) {
if (contextResource == null) {
return INVALID_SITE_ROOT_LEVEL;
}
try {
return cache.get(contextResource.getPath(), () -> detectSiteRootLevel(contextResource));
}
catch (ExecutionException ex) {
log.warn("Unexpected exception.", ex);
return INVALID_SITE_ROOT_LEVEL;
}
return cache.get(contextResource.getPath(), path -> detectSiteRootLevel(contextResource));
}

private int detectSiteRootLevel(@Nullable Resource contextResource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package io.wcm.handler.url.impl;

import java.lang.annotation.Annotation;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

import org.apache.commons.lang3.StringUtils;
Expand All @@ -32,11 +31,9 @@
import org.apache.sling.caconfig.resource.ConfigurationResourceResolver;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

import io.wcm.handler.url.SiteConfig;
import io.wcm.handler.url.spi.UrlHandlerConfig;
Expand All @@ -59,10 +56,8 @@ public class UrlHandlerAdapterFactory implements AdapterFactory {
@Reference
private ConfigurationResourceResolver configurationResourceResolver;

private static final Logger log = LoggerFactory.getLogger(UrlHandlerAdapterFactory.class);

// cache resolving of site root level per resource path
private final Cache<String, SiteConfig> siteConfigCache = CacheBuilder.newBuilder()
private final Cache<String, SiteConfig> siteConfigCache = Caffeine.newBuilder()
.expireAfterWrite(5, TimeUnit.SECONDS)
.maximumSize(10000)
.build();
Expand Down Expand Up @@ -101,16 +96,10 @@ private SiteConfig getSiteConfigForSiteRoot(Resource contextResource) {
}

// get site config for site root resource and cache the result (for a short time)
try {
return siteConfigCache.get(contextRootPath, () -> {
Resource siteRootResource = contextResource.getResourceResolver().getResource(contextRootPath);
return getSiteConfigForResourceCacheable(siteRootResource);
});
}
catch (ExecutionException ex) {
log.warn("Unexpected exception.", ex);
return null;
}
return siteConfigCache.get(contextRootPath, path -> {
Resource siteRootResource = contextResource.getResourceResolver().getResource(contextRootPath);
return getSiteConfigForResourceCacheable(siteRootResource);
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static javax.jcr.observation.Event.PROPERTY_REMOVED;

import java.util.Collections;
import java.util.concurrent.ExecutionException;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
Expand All @@ -44,9 +43,8 @@
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.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;

/**
* Checks given path for client library folder and allowProxy flag status.
Expand All @@ -69,28 +67,25 @@ class ClientlibPathCache implements EventListener, AutoCloseable {
private static final String SERVICE_USER_MAPPING_WARNING = "Missing service user mapping for "
+ "'io.wcm.handler.url:" + CLIENTLIBS_SERVICE + "' - see https://wcm.io/handler/url/configuration.html";

private final LoadingCache<String, ClientlibPathCacheEntry> cache = CacheBuilder.newBuilder()
private final LoadingCache<String, ClientlibPathCacheEntry> cache = Caffeine.newBuilder()
.maximumSize(10000)
.build(new CacheLoader<String, ClientlibPathCacheEntry>() {
@Override
public ClientlibPathCacheEntry load(String path) throws Exception {
try (ResourceResolver resourceResolver = getServiceResourceResolver()) {
Resource resource = resourceResolver.getResource(path);
if (resource != null) {
Node node = resource.adaptTo(Node.class);
if (node != null && node.isNodeType(NT_CLIENTLIBRARY)) {
boolean isAllowProxy = resource.getValueMap().get(PN_ALLOWPROXY, false);
ClientlibPathCacheEntry entry = new ClientlibPathCacheEntry(path, true, isAllowProxy);
log.debug("Detected client library: {}", entry);
return entry;
}
.build(path -> {
try (ResourceResolver resourceResolver = getServiceResourceResolver()) {
Resource resource = resourceResolver.getResource(path);
if (resource != null) {
Node node = resource.adaptTo(Node.class);
if (node != null && node.isNodeType(NT_CLIENTLIBRARY)) {
boolean isAllowProxy = resource.getValueMap().get(PN_ALLOWPROXY, false);
ClientlibPathCacheEntry entry = new ClientlibPathCacheEntry(path, true, isAllowProxy);
log.debug("Detected client library: {}", entry);
return entry;
}
}
catch (LoginException ex) {
log.warn(SERVICE_USER_MAPPING_WARNING);
}
return new ClientlibPathCacheEntry(path, false, false);
}
catch (LoginException ex) {
log.warn(SERVICE_USER_MAPPING_WARNING);
}
return new ClientlibPathCacheEntry(path, false, false);
});

private static final Logger log = LoggerFactory.getLogger(ClientlibPathCache.class);
Expand Down Expand Up @@ -149,14 +144,8 @@ public void onEvent(EventIterator events) {
* @return true if it is a client library, and if it has set the "allowProxy" flag.
*/
public boolean isClientlibWithAllowProxy(String path) {
try {
ClientlibPathCacheEntry entry = cache.get(path);
return entry.isClientLibrary() && entry.isAllowProxy();
}
catch (ExecutionException ex) {
log.warn("Error accessing cache.", ex);
return false;
}
ClientlibPathCacheEntry entry = cache.get(path);
return entry.isClientLibrary() && entry.isAllowProxy();
}

@Override
Expand Down
Loading

0 comments on commit 1e17562

Please sign in to comment.