Skip to content

Commit 9aa1007

Browse files
mcollovatimshabarov
authored andcommitted
feat: enable premium features when building with banner (#21973)
1 parent b6da980 commit 9aa1007

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/plugin/base/BuildFrontendUtil.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -892,22 +892,23 @@ public static void updateBuildFile(PluginAdapterBuild adapter,
892892
buildInfo.put(SERVLET_PARAMETER_PRODUCTION_MODE, true);
893893
buildInfo.put(APPLICATION_IDENTIFIER,
894894
adapter.applicationIdentifier());
895+
boolean applyCommercialBanner = needsCommercialBanner
896+
&& adapter.isCommercialBannerEnabled();
895897
if (licenseRequired) {
896898
if (LocalSubscriptionKey.get() != null) {
897899
adapter.logInfo("Daily Active User tracking enabled");
898900
buildInfo.put(Constants.DAU_TOKEN, true);
899901
checkLicenseCheckerAtRuntime(adapter);
900902
}
901-
if (needsCommercialBanner
902-
&& adapter.isCommercialBannerEnabled()) {
903+
if (applyCommercialBanner) {
903904
adapter.logInfo("Application commercial banner enabled");
904905
buildInfo.put(Constants.COMMERCIAL_BANNER_TOKEN, true);
905906
}
906907
}
907908
if (isControlCenterAvailable(adapter.getClassFinder())
908-
&& LicenseChecker.isValidLicense(
909+
&& (applyCommercialBanner || LicenseChecker.isValidLicense(
909910
"vaadin-commercial-cc-client", null,
910-
BuildType.PRODUCTION)) {
911+
BuildType.PRODUCTION))) {
911912
adapter.logInfo("Premium Features are enabled");
912913
buildInfo.put(Constants.PREMIUM_FEATURES, true);
913914
}

flow-plugins/flow-plugin-base/src/test/java/com/vaadin/flow/plugin/base/BuildFrontendUtilTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,36 @@ public void updateBuildFile_tokenExisting_licenseRequiredAndIsNotPremiumLike_pre
458458
});
459459
}
460460

461+
@Test
462+
public void updateBuildFile_tokenExisting_commercialBannerBuildRequiredAndIsPremiumLike_premiumFeaturesFlagAdded()
463+
throws Exception {
464+
Mockito.when(adapter.isCommercialBannerEnabled()).thenReturn(true);
465+
File tokenFile = prepareAndAssertTokenFile();
466+
467+
addPremiumFeatureAndDAUFlagTrue(tokenFile);
468+
469+
ClassLoader classLoader = new URLClassLoader(
470+
new URL[] { new File(baseDir, "target/test-classes/").toURI()
471+
.toURL() },
472+
BuildFrontendUtilTest.class.getClassLoader());
473+
ClassFinder classFinder = new ClassFinder.DefaultClassFinder(
474+
classLoader);
475+
Mockito.when(adapter.getClassFinder()).thenReturn(classFinder);
476+
477+
withMockedLicenseChecker(false, () -> {
478+
BuildFrontendUtil.updateBuildFile(adapter, true, true);
479+
Assert.assertTrue("Token file should still exist",
480+
tokenFile.exists());
481+
JsonNode buildInfoJsonProd = JacksonUtils
482+
.readTree(Files.readString(tokenFile.toPath()));
483+
Assert.assertTrue(
484+
Constants.PREMIUM_FEATURES
485+
+ " flag should be active in token file",
486+
buildInfoJsonProd.get(Constants.PREMIUM_FEATURES)
487+
.booleanValue());
488+
});
489+
}
490+
461491
@Test
462492
public void updateBuildFile_tokenExisting_commercialBannerBuildRequired_commercialBannerBuildEnabled_commercialBannerFlagAdded()
463493
throws Exception {

0 commit comments

Comments
 (0)