Skip to content

Commit

Permalink
Merge branch 'main' into gradle_jvm_toolchains_support
Browse files Browse the repository at this point in the history
  • Loading branch information
mshabarov authored Sep 16, 2024
2 parents e9fe495 + 91a399f commit 0d05f6a
Show file tree
Hide file tree
Showing 26 changed files with 158 additions and 64 deletions.
17 changes: 7 additions & 10 deletions flow-jandex/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,46 +35,43 @@
<groupId>com.vaadin</groupId>
<artifactId>flow-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-polymer-template</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-lit-template</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-push</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-data</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-html-components</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-server-production-mode</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-dnd</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-dev-server</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.vaadin.gradle

import com.vaadin.flow.internal.StringUtil
import com.vaadin.flow.server.InitParameters
import elemental.json.Json
import org.gradle.testkit.runner.BuildResult
Expand Down Expand Up @@ -124,7 +125,9 @@ open class MiscMultiModuleTest : AbstractGradleTest() {

val tokenFile = File(testProject.dir, "web/build/resources/main/META-INF/VAADIN/config/flow-build-info.json")
val tokenFileContent = Json.parse(tokenFile.readText())
expect("web") { tokenFileContent.getString(InitParameters.APPLICATION_IDENTIFIER) }
expect("app-" + StringUtil.getHash("web",
java.nio.charset.StandardCharsets.UTF_8
)) { tokenFileContent.getString(InitParameters.APPLICATION_IDENTIFIER) }
}

@Test
Expand Down Expand Up @@ -178,7 +181,9 @@ open class MiscMultiModuleTest : AbstractGradleTest() {

val tokenFile = File(testProject.dir, "web/build/resources/main/META-INF/VAADIN/config/flow-build-info.json")
val tokenFileContent = Json.parse(tokenFile.readText())
expect("MY_APP_ID") { tokenFileContent.getString(InitParameters.APPLICATION_IDENTIFIER) }
expect("app-" + StringUtil.getHash("MY_APP_ID",
java.nio.charset.StandardCharsets.UTF_8
)) { tokenFileContent.getString(InitParameters.APPLICATION_IDENTIFIER) }
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.vaadin.gradle

import com.vaadin.flow.internal.StringUtil
import com.vaadin.flow.server.InitParameters
import elemental.json.Json
import org.gradle.testkit.runner.BuildResult
Expand Down Expand Up @@ -70,7 +71,9 @@ class MiscSingleModuleTest : AbstractGradleTest() {
doTestWarProjectProductionMode()
val tokenFile = File(testProject.dir, "build/resources/main/META-INF/VAADIN/config/flow-build-info.json")
val tokenFileContent = Json.parse(tokenFile.readText())
expect(testProject.dir.name) { tokenFileContent.getString(InitParameters.APPLICATION_IDENTIFIER) }
expect("app-" + StringUtil.getHash(testProject.dir.name,
java.nio.charset.StandardCharsets.UTF_8
)) { tokenFileContent.getString(InitParameters.APPLICATION_IDENTIFIER) }
}

@Test
Expand All @@ -79,7 +82,9 @@ class MiscSingleModuleTest : AbstractGradleTest() {
doTestWarProjectProductionMode()
val tokenFile = File(testProject.dir, "build/resources/main/META-INF/VAADIN/config/flow-build-info.json")
val tokenFileContent = Json.parse(tokenFile.readText())
expect("my-test-project") { tokenFileContent.getString(InitParameters.APPLICATION_IDENTIFIER) }
expect("app-" + StringUtil.getHash("my-test-project",
java.nio.charset.StandardCharsets.UTF_8
)) { tokenFileContent.getString(InitParameters.APPLICATION_IDENTIFIER) }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.vaadin.gradle
import java.io.File
import kotlin.test.assertContains
import kotlin.test.expect
import com.vaadin.flow.internal.StringUtil
import com.vaadin.flow.server.InitParameters
import com.vaadin.flow.server.frontend.FrontendUtils
import elemental.json.JsonObject
Expand Down Expand Up @@ -101,7 +102,9 @@ open class VaadinSmokeTest : AbstractGradleTest() {
val tokenFile = File(testProject.dir, "build/resources/main/META-INF/VAADIN/config/flow-build-info.json")
val buildInfo: JsonObject = JsonUtil.parse(tokenFile.readText())
expect(true, buildInfo.toJson()) { buildInfo.getBoolean(InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE) }
expect(testProject.dir.name, buildInfo.toJson()) { buildInfo.getString(InitParameters.APPLICATION_IDENTIFIER) }
expect("app-" + StringUtil.getHash(testProject.dir.name,
java.nio.charset.StandardCharsets.UTF_8
), buildInfo.toJson()) { buildInfo.getString(InitParameters.APPLICATION_IDENTIFIER) }
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.vaadin.gradle

import com.vaadin.flow.plugin.base.BuildFrontendUtil
import com.vaadin.flow.internal.StringUtil
import com.vaadin.flow.server.Constants
import com.vaadin.flow.server.InitParameters
import com.vaadin.flow.server.frontend.FrontendTools
Expand All @@ -30,6 +31,7 @@ import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import java.io.File
import java.nio.charset.StandardCharsets
import javax.inject.Inject

public abstract class VaadinFlowPluginExtension @Inject constructor(private val project: Project) {
Expand Down Expand Up @@ -430,7 +432,11 @@ public class PluginEffectiveConfiguration(
public val cleanFrontendFiles: Property<Boolean> = extension.cleanFrontendFiles
.convention(true)

public val applicationIdentifier: Provider<String> = extension.applicationIdentifier.convention(project.name)
public val applicationIdentifier: Provider<String> = extension.applicationIdentifier
.convention(
"app-" + StringUtil.getHash(project.name,
java.nio.charset.StandardCharsets.UTF_8
))
.overrideWithSystemProperty("vaadin.${InitParameters.APPLICATION_IDENTIFIER}")

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
Expand All @@ -26,6 +27,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.vaadin.flow.internal.StringUtil;
import com.vaadin.flow.plugin.base.BuildFrontendUtil;
import com.vaadin.flow.plugin.base.PluginAdapterBase;
import com.vaadin.flow.server.Constants;
Expand Down Expand Up @@ -535,6 +537,8 @@ public String applicationIdentifier() {
if (applicationIdentifier != null && !applicationIdentifier.isBlank()) {
return applicationIdentifier;
}
return project.getGroupId() + ":" + project.getArtifactId();
return "app-" + StringUtil.getHash(
project.getGroupId() + ":" + project.getArtifactId(),
StandardCharsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.stream.Stream;

import com.vaadin.flow.di.Lookup;
import com.vaadin.flow.internal.StringUtil;
import com.vaadin.flow.plugin.TestUtils;
import com.vaadin.flow.server.Constants;
import com.vaadin.flow.server.InitParameters;
Expand Down Expand Up @@ -507,7 +508,8 @@ public void existingTokenFile_parametersShouldBeRemoved()
@Test
public void existingTokenFile_defaultApplicationIdentifierWritten()
throws IOException, MojoExecutionException, MojoFailureException {
String expectedAppId = "com.vaadin.testing:my-application";
String expectedAppId = "app-" + StringUtil.getHash(
"com.vaadin.testing:my-application", StandardCharsets.UTF_8);

JsonObject initialBuildInfo = Json.createObject();
initialBuildInfo.put(SERVLET_PARAMETER_PRODUCTION_MODE, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import static com.vaadin.flow.server.Constants.CONNECT_APPLICATION_PROPERTIES_TOKEN;
import static com.vaadin.flow.server.Constants.CONNECT_JAVA_SOURCE_FOLDER_TOKEN;
import static com.vaadin.flow.server.Constants.CONNECT_OPEN_API_FILE_TOKEN;
import static com.vaadin.flow.server.Constants.DAU_TOKEN;
import static com.vaadin.flow.server.Constants.DISABLE_PREPARE_FRONTEND_CACHE;
import static com.vaadin.flow.server.Constants.FRONTEND_TOKEN;
import static com.vaadin.flow.server.Constants.JAVA_RESOURCE_FOLDER_TOKEN;
Expand Down Expand Up @@ -752,13 +751,20 @@ public static void updateBuildFile(PluginAdapterBuild adapter,
buildInfo.remove(Constants.CONNECT_OPEN_API_FILE_TOKEN);
buildInfo.remove(Constants.PROJECT_FRONTEND_GENERATED_DIR_TOKEN);
buildInfo.remove(InitParameters.BUILD_FOLDER);
// Premium features flag is always true, because Vaadin CI server
// uses Enterprise sub, thus it's always true.
// Thus, resets the premium feature flag and DAU flag before asking
// license-server
buildInfo.remove(Constants.PREMIUM_FEATURES);
buildInfo.remove(Constants.DAU_TOKEN);

buildInfo.put(SERVLET_PARAMETER_PRODUCTION_MODE, true);
buildInfo.put(APPLICATION_IDENTIFIER,
adapter.applicationIdentifier());
if (licenseRequired) {
if (LocalSubscriptionKey.get() != null) {
adapter.logInfo("Daily Active User tracking enabled");
buildInfo.put(DAU_TOKEN, true);
buildInfo.put(Constants.DAU_TOKEN, true);
}
if (LicenseChecker.isValidLicense("vaadin-commercial-cc-client",
null, BuildType.PRODUCTION)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ default Lookup createLookup(ClassFinder classFinder) {
* Gets the application identifier.
* <p>
* The application identifier is usually computed against project unique
* information, such as {@literal groupId} and {@literal artifactId}, but it
* can be any kind of not blank string.
* information, such as hashed {@literal groupId} and {@literal artifactId},
* but it can be any kind of not blank string.
*
* @return application identifier, never {@literal null} nor
* {@literal blank}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.vaadin.flow.server.ExecutionFailedException;
import com.vaadin.flow.server.InitParameters;
import com.vaadin.flow.server.frontend.EndpointGeneratorTaskFactory;
import com.vaadin.flow.server.frontend.FileIOUtils;
import com.vaadin.flow.server.frontend.FrontendTools;
import com.vaadin.flow.server.frontend.FrontendUtils;
import com.vaadin.flow.server.frontend.TaskGenerateEndpoint;
Expand All @@ -54,6 +55,7 @@

import elemental.json.Json;
import elemental.json.JsonObject;
import elemental.json.impl.JsonUtil;

import static com.vaadin.flow.server.frontend.FrontendUtils.FEATURE_FLAGS_FILE_NAME;
import static com.vaadin.flow.server.frontend.FrontendUtils.TOKEN_FILE;
Expand Down Expand Up @@ -367,6 +369,8 @@ public void updateBuildFile_tokenExisting_licenseNotRequiredAndSubscriptionKey_d
throws Exception {
File tokenFile = prepareAndAssertTokenFile();

addPremiumFeatureAndDAUFlagTrue(tokenFile);

String subscriptionKey = System.getProperty("vaadin.subscriptionKey");
System.setProperty("vaadin.subscriptionKey", "sub-123");
try {
Expand Down Expand Up @@ -417,6 +421,8 @@ public void updateBuildFile_tokenExisting_licenseRequiredAndIsPremiumLike_premiu
throws Exception {
File tokenFile = prepareAndAssertTokenFile();

addPremiumFeatureAndDAUFlagTrue(tokenFile);

withMockedLicenseChecker(true, () -> {
BuildFrontendUtil.updateBuildFile(adapter, true);
Assert.assertTrue("Token file should still exist",
Expand All @@ -435,6 +441,8 @@ public void updateBuildFile_tokenExisting_licenseRequiredAndIsNotPremiumLike_pre
throws Exception {
File tokenFile = prepareAndAssertTokenFile();

addPremiumFeatureAndDAUFlagTrue(tokenFile);

withMockedLicenseChecker(false, () -> {
BuildFrontendUtil.updateBuildFile(adapter, true);
Assert.assertTrue("Token file should still exist",
Expand Down Expand Up @@ -578,4 +586,18 @@ private void setupPluginAdapterDefaults() throws URISyntaxException {
this.getClass().getClassLoader()));
Mockito.when(adapter.runNpmInstall()).thenReturn(true);
}

private void addPremiumFeatureAndDAUFlagTrue(File tokenFile)
throws IOException {
// simulates true value placed into pre-compiled bundle
// when bundle is compiled on Vaadin CI server
String tokenJson = FileUtils.readFileToString(tokenFile,
StandardCharsets.UTF_8);
JsonObject buildInfo = JsonUtil.parse(tokenJson);
buildInfo.put(Constants.PREMIUM_FEATURES, true);
buildInfo.put(Constants.DAU_TOKEN, true);

FileIOUtils.writeIfChanged(tokenFile,
JsonUtil.stringify(buildInfo, 2) + "\n");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Set;
import java.util.regex.Pattern;

import org.apache.commons.io.FileUtils;
Expand All @@ -28,10 +29,14 @@
import org.slf4j.LoggerFactory;

import com.vaadin.flow.internal.StringUtil;
import com.vaadin.flow.router.Layout;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.ExecutionFailedException;
import com.vaadin.flow.server.Version;

import elemental.json.Json;
import elemental.json.JsonArray;
import elemental.json.JsonObject;
import static com.vaadin.flow.server.frontend.FileIOUtils.compareIgnoringIndentationEOLAndWhiteSpace;
import static java.nio.charset.StandardCharsets.UTF_8;

Expand Down Expand Up @@ -102,6 +107,7 @@ function build() {
private static final String VAADIN_REACT_TSX = "vaadin-react.tsx";
private static final String REACT_ADAPTER_TEMPLATE = "ReactAdapter.template";
private static final String REACT_ADAPTER_TSX = "ReactAdapter.tsx";
private static final String LAYOUTS_JSON = "layouts.json";
static final String FLOW_FLOW_TSX = "flow/" + FLOW_TSX;
static final String FLOW_REACT_ADAPTER_TSX = "flow/" + REACT_ADAPTER_TSX;
private static final String ROUTES_JS_IMPORT_PATH_TOKEN = "%routesJsImportPath%";
Expand Down Expand Up @@ -158,6 +164,8 @@ private void doExecute() throws ExecutionFailedException {
writeFile(flowTsx, getFileContent(FLOW_TSX));
writeFile(vaadinReactTsx,
getVaadinReactTsContent(routesTsx.exists()));
writeFile(new File(frontendGeneratedFolder, LAYOUTS_JSON),
layoutsContent());
if (fileAvailable(REACT_ADAPTER_TEMPLATE)) {
String reactAdapterContent = getFileContent(
REACT_ADAPTER_TEMPLATE);
Expand Down Expand Up @@ -193,6 +201,19 @@ && serverRoutesAvailable()) {
}
}

private String layoutsContent() {
JsonArray availableLayouts = Json.createArray();
Set<Class<?>> layoutClasses = options.getClassFinder()
.getAnnotatedClasses(Layout.class);
for (Class<?> layout : layoutClasses) {
JsonObject layoutObject = Json.createObject();
layoutObject.put("path",
layout.getAnnotation(Layout.class).value());
availableLayouts.set(availableLayouts.length(), layoutObject);
}
return availableLayouts.toJson();
}

private void cleanup() throws ExecutionFailedException {
try {
File frontendDirectory = options.getFrontendDirectory();
Expand All @@ -204,7 +225,9 @@ private void cleanup() throws ExecutionFailedException {
FLOW_REACT_ADAPTER_TSX);
File frontendGeneratedFolderRoutesTsx = new File(
frontendGeneratedFolder, FrontendUtils.ROUTES_TSX);
File layoutsJson = new File(frontendGeneratedFolder, LAYOUTS_JSON);
FileUtils.deleteQuietly(flowTsx);
FileUtils.deleteQuietly(layoutsJson);
FileUtils.deleteQuietly(vaadinReactTsx);
FileUtils.deleteQuietly(reactAdapterTsx);
FileUtils.deleteQuietly(frontendGeneratedFolderRoutesTsx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import static com.vaadin.flow.server.Constants.EXTERNAL_STATS_URL_TOKEN;
import static com.vaadin.flow.server.Constants.FRONTEND_TOKEN;
import static com.vaadin.flow.server.Constants.NPM_TOKEN;
import static com.vaadin.flow.server.Constants.PREMIUM_FEATURES;
import static com.vaadin.flow.server.Constants.PROJECT_FRONTEND_GENERATED_DIR_TOKEN;
import static com.vaadin.flow.server.Constants.VAADIN_PREFIX;
import static com.vaadin.flow.server.InitParameters.APPLICATION_IDENTIFIER;
Expand Down Expand Up @@ -181,6 +182,10 @@ protected Map<String, String> getConfigParametersUsingTokenData(
params.put(DAU_TOKEN,
String.valueOf(buildInfo.getBoolean(DAU_TOKEN)));
}
if (buildInfo.hasKey(PREMIUM_FEATURES)) {
params.put(PREMIUM_FEATURES,
String.valueOf(buildInfo.getBoolean(PREMIUM_FEATURES)));
}

setDevModePropertiesUsingTokenData(params, buildInfo);
return params;
Expand Down
Loading

0 comments on commit 0d05f6a

Please sign in to comment.