Skip to content

Commit a18581f

Browse files
authored
feat: add Maven goal to download Vaadin Pro license key (#22784)
Introduces a new 'download-license' goal that automates the process of obtaining a Pro license key through browser-based authentication. The downloaded key is saved to ~/.vaadin/proKey for use in validating commercial Vaadin components.
1 parent 0f593a6 commit a18581f

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2000-2025 Vaadin Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package com.vaadin.flow.plugin.maven;
17+
18+
import org.apache.maven.plugin.MojoExecutionException;
19+
import org.apache.maven.plugin.MojoFailureException;
20+
import org.apache.maven.plugins.annotations.Mojo;
21+
22+
import com.vaadin.pro.licensechecker.LicenseChecker;
23+
import com.vaadin.pro.licensechecker.LicenseChecker.DownloadOptions;
24+
import com.vaadin.pro.licensechecker.LicenseException;
25+
import com.vaadin.pro.licensechecker.LocalProKey;
26+
import com.vaadin.pro.licensechecker.Product;
27+
28+
/**
29+
* Goal that downloads a Vaadin Pro license key by opening the browser and
30+
* waiting for the user to log in.
31+
* <p>
32+
* The downloaded license key is saved to the local file system
33+
* (~/.vaadin/proKey) and can be used for validating commercial Vaadin
34+
* components.
35+
*
36+
* @since 25.0
37+
*/
38+
@Mojo(name = "download-license", requiresProject = false)
39+
public class DownloadLicenseMojo extends FlowModeAbstractMojo {
40+
41+
private static final String PRODUCT_NAME = "vaadin-maven-download";
42+
private static final int TIMEOUT_SECONDS = 300; // 5 minutes
43+
44+
@Override
45+
protected void executeInternal()
46+
throws MojoExecutionException, MojoFailureException {
47+
String version = getFlowVersion();
48+
49+
// Check if we already have a proKey
50+
if (LocalProKey.get() != null) {
51+
getLog().info("A license key already exists at "
52+
+ LocalProKey.getLocation());
53+
getLog().info(
54+
"Delete the existing key file if you want to download a new one.");
55+
return;
56+
}
57+
58+
try {
59+
LicenseChecker.downloadLicense(new DownloadOptions(
60+
new Product(PRODUCT_NAME, version), TIMEOUT_SECONDS));
61+
62+
getLog().info("License key downloaded and saved successfully to "
63+
+ LocalProKey.getLocation());
64+
} catch (LicenseException e) {
65+
throw new MojoFailureException("Failed to download license key", e);
66+
}
67+
}
68+
69+
/**
70+
* Gets the Flow version from the plugin version.
71+
*/
72+
private String getFlowVersion() {
73+
if (mojoExecution != null) {
74+
return mojoExecution.getMojoDescriptor().getPluginDescriptor()
75+
.getVersion();
76+
}
77+
// Fallback version when mojoExecution is not available
78+
return "0.0.1";
79+
}
80+
81+
}

0 commit comments

Comments
 (0)