|
| 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