Skip to content

Commit c8abec7

Browse files
Merge pull request #169 from exadel-inc/feature/EB-168
[EB-168] remove the usages of Guava library
2 parents 40ea3f9 + 699a405 commit c8abec7

17 files changed

Lines changed: 368 additions & 70 deletions

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ When you select e.g. a page for inclusion into package, all the assets reference
1313

1414
### Project structure
1515

16-
The project consists of two modules:
16+
The project is organized as a multi-module Maven build:
1717

18-
* *core module* runs in an AEM instance containing to respond to user commands and provide data processing service.
19-
* *ui/application module* embeds into AEM administering interface and runs in browser to give to the user control over package creation and storage, as well as detailed feedback. This module is built upon the modern Coral 3 graphic interface and TouchUI-ready.
18+
* `core` — the server-side OSGi bundle. It contains the Java code that implements BackPack services, request processing, package handling logic, and tests.
19+
* `ui.apps` — the AEM application package. It contains the repository content installed under the application area, including the UI assets and browser-facing integration.
20+
* `ui.apps.structure` — the repository structure package. It defines the AEM repository roots required by the application packages.
21+
* `ui.config` — the AEM configuration package. It contains configuration content packaged separately from the application code.
22+
* `all` — the aggregate container package. It embeds the `core`, `ui.apps`, and `ui.config` artifacts into a single package for deployment.
2023

21-
The two modules communicate via JSON-based REST protocol. Basically, a user command is sent to an endpoint, parsed and processed by a specially designed AEM service, then result and/or status message returned to user.
2224

2325
### Installation
2426

@@ -57,10 +59,6 @@ There is also the specific "test" profile that helps to collect code quality sta
5759

5860
The project is in active development stage. Community contribution is heartily welcome.
5961

60-
### Known issues
61-
62-
The project uses `com.google.common.cache.Cache` bundled in `uber-jar-6.3.0` which is in "beta" status. Despite this class is out of beta stage in standalone Google Guava releases since *20.0*, we are currently sticking to *uber-jar* version to avoid inconsistency. We have tested this doesn't cause trouble in regular usage.
63-
6462
### Licensing
6563

66-
The project is licensed under [Apache License, Version 2.0](LICENSE). All runtime project dependencies are guaranteed to be compliant with the license. Dependencies such as Adobe's *uber-jar* are considered *provided* in the end-user environment and are not explicitly engaged. The end user is to comply with the regulations of the corresponding licenses.
64+
The project is licensed under [Apache License, Version 2.0](LICENSE). All runtime project dependencies are guaranteed to be compliant with the license. Dependencies such as Adobe's *uber-jar* are considered *provided* in the end-user environment and are not explicitly engaged. The end user is to comply with the regulations of the corresponding licenses.

core/pom.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@
5050
</executions>
5151
<configuration>
5252
<instructions>
53-
<Embed-Dependency>commons-lang3;scope=compile,guava;scope=compile</Embed-Dependency>
54-
<Import-Package>sun.misc;resolution:=optional,*</Import-Package>
53+
<Embed-Dependency>commons-lang3;scope=compile</Embed-Dependency>
5554
</instructions>
5655
</configuration>
5756
</plugin>
@@ -174,10 +173,6 @@
174173
<groupId>com.google.code.gson</groupId>
175174
<artifactId>gson</artifactId>
176175
</dependency>
177-
<dependency>
178-
<groupId>com.google.guava</groupId>
179-
<artifactId>guava</artifactId>
180-
</dependency>
181176
<!-- Testing -->
182177
<dependency>
183178
<groupId>junit</groupId>

core/src/main/java/com/exadel/etoolbox/backpack/core/model/PackageEntriesDatasource.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.exadel.etoolbox.backpack.core.servlets.model.PackageInfoModel;
1212
import com.exadel.etoolbox.backpack.request.RequestAdapter;
1313
import com.exadel.etoolbox.backpack.request.validator.ValidatorResponse;
14-
import com.google.common.collect.ImmutableMap;
1514
import org.apache.sling.api.SlingHttpServletRequest;
1615
import org.apache.sling.api.resource.Resource;
1716
import org.apache.sling.api.resource.ValueMap;
@@ -110,7 +109,7 @@ private Resource createPackageEntry(String type, String title, Map<String, Objec
110109
private void addSubsidiaries(List<Resource> subsidiaries, Set<String> subsidiaryPaths, String type) {
111110
if (!subsidiaryPaths.isEmpty()) {
112111
subsidiaries.addAll(subsidiaryPaths.stream()
113-
.map(path -> createPackageEntry(type, path, ImmutableMap.of("upstream", path)))
112+
.map(path -> createPackageEntry(type, path, Collections.singletonMap("upstream", path)))
114113
.collect(Collectors.toList()));
115114
}
116115
}

core/src/main/java/com/exadel/etoolbox/backpack/core/services/pckg/BasePackageService.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import javax.jcr.RepositoryException;
2626
import javax.jcr.Session;
2727
import java.util.Collection;
28-
import java.util.concurrent.ConcurrentMap;
29-
3028
/**
3129
* Represents a service running in an AEM instance responsible for base operation with package
3230
*/
@@ -83,7 +81,6 @@ public interface BasePackageService {
8381
* @param jcrPackageDefinition {@code JcrPackageDefinition} Definition of the package to update
8482
* @param userSession Current user {@code Session} as adapted from the acting {@code ResourceResolver}
8583
* @param packageInfo {@code PackageInfo} object to store status information in
86-
* @param paths {@code List} of {@code PathModel} will be stored in package metadata information and used in future package modifications
8784
* @param filter {@code DefaultWorkspaceFilter} instance representing resource selection mechanism for the package
8885
*/
8986
void setPackageInfo(JcrPackageDefinition jcrPackageDefinition,
@@ -125,13 +122,11 @@ boolean isPackageExist(JcrPackageManager packageMgr,
125122
String version) throws RepositoryException;
126123

127124
/**
128-
* Gets current {@link PackageInfo} objects cache
125+
* Gets current {@link PackageInfo} objects cache via a narrow cache-specific API
129126
*
130-
* @return {@code Cache<String, PackageInfo>} object
127+
* @return {@link PackageInfoCache} object
131128
*/
132-
@SuppressWarnings("UnstableApiUsage")
133-
// sticking to Guava Cache version bundled in uber-jar; still safe to use
134-
ConcurrentMap<String, PackageInfo> getPackageCacheAsMap();
129+
PackageInfoCache getPackageCache();
135130

136131
/**
137132
* @param resourceResolver {@code ResourceResolver} used to collect assets details
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.exadel.etoolbox.backpack.core.services.pckg;
2+
3+
import com.exadel.etoolbox.backpack.core.dto.response.PackageInfo;
4+
5+
/**
6+
* Narrow cache-facing API for storing and retrieving package build information.
7+
*/
8+
public interface PackageInfoCache {
9+
10+
PackageInfo get(String packagePath);
11+
12+
PackageInfo put(String packagePath, PackageInfo packageInfo);
13+
14+
PackageInfo remove(String packagePath);
15+
16+
void clear();
17+
}
18+

core/src/main/java/com/exadel/etoolbox/backpack/core/services/pckg/impl/BasePackageServiceImpl.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
import com.exadel.etoolbox.backpack.core.dto.response.PackageInfo;
1919
import com.exadel.etoolbox.backpack.core.dto.response.PackageStatus;
2020
import com.exadel.etoolbox.backpack.core.services.pckg.BasePackageService;
21+
import com.exadel.etoolbox.backpack.core.services.pckg.PackageInfoCache;
2122
import com.exadel.etoolbox.backpack.core.services.util.constants.BackpackConstants;
2223
import com.exadel.etoolbox.backpack.core.servlets.model.PackageModel;
23-
import com.google.common.cache.Cache;
24-
import com.google.common.cache.CacheBuilder;
2524
import com.google.gson.Gson;
2625
import org.apache.commons.lang3.StringUtils;
2726
import org.apache.commons.lang3.exception.ExceptionUtils;
@@ -53,7 +52,6 @@
5352
import java.util.HashMap;
5453
import java.util.List;
5554
import java.util.Map;
56-
import java.util.concurrent.ConcurrentMap;
5755
import java.util.concurrent.TimeUnit;
5856
import java.util.stream.Collectors;
5957
import java.util.stream.Stream;
@@ -78,10 +76,8 @@ public class BasePackageServiceImpl implements BasePackageService {
7876
private SlingRepository slingRepository;
7977

8078

81-
@SuppressWarnings("UnstableApiUsage") // sticking to Guava Cache version bundled in uber-jar; still safe to use
82-
protected Cache<String, PackageInfo> packageInfos;
83-
8479
protected boolean enableStackTrace;
80+
private PackageInfoCache packageCache;
8581

8682
/**
8783
* Run upon this OSGi service activation to initialize cache storage of collected {@link PackageInfo} objects
@@ -92,10 +88,8 @@ public class BasePackageServiceImpl implements BasePackageService {
9288
@SuppressWarnings("unused") // run internally by the OSGi mechanism
9389
private void activate(Configuration config) {
9490
enableStackTrace = config.enableStackTraceShowing();
95-
packageInfos = CacheBuilder.newBuilder()
96-
.maximumSize(100)
97-
.expireAfterWrite(config.buildInfoTTL(), TimeUnit.DAYS)
98-
.build();
91+
long cacheTtlMillis = TimeUnit.DAYS.toMillis(config.buildInfoTTL());
92+
packageCache = new PackageInfoCacheImpl(cacheTtlMillis);
9993
}
10094

10195
@Override
@@ -110,7 +104,8 @@ public boolean isEnableStackTrace() {
110104
@interface Configuration {
111105
@AttributeDefinition(
112106
name = "Package Build Info TTL",
113-
description = "Specify TTL for package build information cache (in days).",
107+
description = "Specify TTL for package build information cache (in days). " +
108+
"A negative value means that the cache is indefinite, 0 means that the cache is disabled.",
114109
type = AttributeType.INTEGER
115110
)
116111
int buildInfoTTL() default 1;
@@ -297,11 +292,9 @@ public long getAssetSize(ResourceResolver resourceResolver, String path) {
297292
/**
298293
* {@inheritDoc}
299294
*/
300-
@SuppressWarnings("UnstableApiUsage")
301-
// sticking to Guava Cache version bundled in uber-jar; still safe to use
302295
@Override
303-
public ConcurrentMap<String, PackageInfo> getPackageCacheAsMap() {
304-
return packageInfos.asMap();
296+
public PackageInfoCache getPackageCache() {
297+
return packageCache;
305298
}
306299

307300
@Override
@@ -371,6 +364,6 @@ private String getPackageId(final String packageGroupName, final String packageN
371364
}
372365

373366
private void clearCache(String key) {
374-
getPackageCacheAsMap().remove(key);
367+
getPackageCache().remove(key);
375368
}
376369
}

core/src/main/java/com/exadel/etoolbox/backpack/core/services/pckg/impl/BuildPackageServiceImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import com.exadel.etoolbox.backpack.core.services.util.SessionService;
2323
import com.exadel.etoolbox.backpack.core.services.util.constants.BackpackConstants;
2424
import com.exadel.etoolbox.backpack.core.servlets.model.BuildPackageModel;
25-
import com.google.common.reflect.TypeToken;
2625
import com.google.gson.Gson;
26+
import com.google.gson.reflect.TypeToken;
2727
import org.apache.commons.lang3.StringUtils;
2828
import org.apache.commons.lang3.time.StopWatch;
2929
import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
@@ -57,7 +57,6 @@
5757
*/
5858
@Component(service = BuildPackageService.class)
5959
public class BuildPackageServiceImpl implements BuildPackageService {
60-
private static final String SERVICE_NAME = "backpack-service";
6160

6261
private static final Logger LOGGER = LoggerFactory.getLogger(BuildPackageServiceImpl.class);
6362

@@ -197,7 +196,7 @@ public PackageInfo buildPackage(final ResourceResolver resourceResolver,
197196
if (!PackageStatus.BUILD_IN_PROGRESS.equals(packageInfo.getPackageStatus()) && !PackageStatus.INSTALL_IN_PROGRESS.equals(packageInfo.getPackageStatus())) {
198197
packageInfo.setPackageStatus(PackageStatus.BUILD_IN_PROGRESS);
199198
packageInfo.clearLog();
200-
basePackageService.getPackageCacheAsMap().put(requestInfo.getPackagePath(), packageInfo);
199+
basePackageService.getPackageCache().put(requestInfo.getPackagePath(), packageInfo);
201200
buildPackageAsync(resourceResolver.getUserID(), packageInfo, requestInfo.getReferencedResources());
202201
}
203202

core/src/main/java/com/exadel/etoolbox/backpack/core/services/pckg/impl/CreatePackageServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public PackageInfo createPackage(ResourceResolver resourceResolver, PackageModel
5555
createPackage(session, packageInfo, basePackageService.buildWorkspaceFilter(packageInfo.getPaths()));
5656

5757
if (PackageStatus.CREATED.equals(packageInfo.getPackageStatus())) {
58-
basePackageService.getPackageCacheAsMap().put(packageInfo.getPackagePath(), packageInfo);
58+
basePackageService.getPackageCache().put(packageInfo.getPackagePath(), packageInfo);
5959
}
6060

6161
return packageInfo;

core/src/main/java/com/exadel/etoolbox/backpack/core/services/pckg/impl/EditPackageServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public PackageInfo editPackage(final ResourceResolver resourceResolver, final Pa
8181
modifyPackage(session, modificationPackageModel.getPackagePath(), packageInfo, basePackageService.buildWorkspaceFilter(packageInfo.getPaths()));
8282

8383
if (PackageStatus.MODIFIED.equals(packageInfo.getPackageStatus())) {
84-
basePackageService.getPackageCacheAsMap().remove(modificationPackageModel.getPackagePath());
85-
basePackageService.getPackageCacheAsMap().put(packageInfo.getPackagePath(), packageInfo);
84+
basePackageService.getPackageCache().remove(modificationPackageModel.getPackagePath());
85+
basePackageService.getPackageCache().put(packageInfo.getPackagePath(), packageInfo);
8686
}
8787

8888
return packageInfo;

core/src/main/java/com/exadel/etoolbox/backpack/core/services/pckg/impl/InstallPackageServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public PackageInfo installPackage(ResourceResolver resourceResolver, InstallPack
6060
packageInfo.clearLog();
6161
packageInfo.addLogMessage(START_INSTALL_MESSAGE + packageInfo.getPackagePath());
6262
packageInfo.addLogMessage(LocalDateTime.now().format(BackpackConstants.DATE_TIME_FORMATTER));
63-
basePackageService.getPackageCacheAsMap().put(installPackageModel.getPackagePath(), packageInfo);
63+
basePackageService.getPackageCache().put(installPackageModel.getPackagePath(), packageInfo);
6464
installPackageAsync(resourceResolver.getUserID(), installPackageModel, packageInfo);
6565
}
6666
return packageInfo;

0 commit comments

Comments
 (0)