Skip to content

Commit 0008674

Browse files
mcollovatimshabarov
authored andcommitted
feat: enable premium features when building with banner (#21973)
1 parent 7702d81 commit 0008674

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
@@ -907,22 +907,23 @@ public static void updateBuildFile(PluginAdapterBuild adapter,
907907
buildInfo.put(SERVLET_PARAMETER_PRODUCTION_MODE, true);
908908
buildInfo.put(APPLICATION_IDENTIFIER,
909909
adapter.applicationIdentifier());
910+
boolean applyCommercialBanner = needsCommercialBanner
911+
&& adapter.isCommercialBannerEnabled();
910912
if (licenseRequired) {
911913
if (LocalSubscriptionKey.get() != null) {
912914
adapter.logInfo("Daily Active User tracking enabled");
913915
buildInfo.put(Constants.DAU_TOKEN, true);
914916
checkLicenseCheckerAtRuntime(adapter);
915917
}
916-
if (needsCommercialBanner
917-
&& adapter.isCommercialBannerEnabled()) {
918+
if (applyCommercialBanner) {
918919
adapter.logInfo("Application commercial banner enabled");
919920
buildInfo.put(Constants.COMMERCIAL_BANNER_TOKEN, true);
920921
}
921922
}
922923
if (isControlCenterAvailable(adapter.getClassFinder())
923-
&& LicenseChecker.isValidLicense(
924+
&& (applyCommercialBanner || LicenseChecker.isValidLicense(
924925
"vaadin-commercial-cc-client", null,
925-
BuildType.PRODUCTION)) {
926+
BuildType.PRODUCTION))) {
926927
adapter.logInfo("Premium Features are enabled");
927928
buildInfo.put(Constants.PREMIUM_FEATURES, true);
928929
}

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)