|
| 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 java.io.File; |
| 19 | + |
| 20 | +import org.apache.maven.plugin.MojoExecutionException; |
| 21 | +import org.apache.maven.plugin.MojoFailureException; |
| 22 | +import org.apache.maven.plugins.annotations.Mojo; |
| 23 | + |
| 24 | +import com.vaadin.pro.licensechecker.LocalOfflineKey; |
| 25 | +import com.vaadin.pro.licensechecker.MachineId; |
| 26 | +import com.vaadin.pro.licensechecker.OfflineKeyValidator; |
| 27 | + |
| 28 | +/** |
| 29 | + * Goal that provides the URL to download a Vaadin offline license key. |
| 30 | + * <p> |
| 31 | + * This command displays a machine-specific URL that can be used to manually |
| 32 | + * download an offline license key. The offline license is tied to this |
| 33 | + * machine's hardware ID and must be saved manually to the file system |
| 34 | + * (~/.vaadin/offlineKey). |
| 35 | + * <p> |
| 36 | + * Unlike the online license (proKey), offline licenses work without internet |
| 37 | + * connectivity and are suitable for CI/CD environments and offline development. |
| 38 | + * |
| 39 | + * @since 25.0 |
| 40 | + */ |
| 41 | +@Mojo(name = "download-offline-license", requiresProject = false) |
| 42 | +public class DownloadOfflineLicenseMojo extends FlowModeAbstractMojo { |
| 43 | + |
| 44 | + @Override |
| 45 | + protected void executeInternal() |
| 46 | + throws MojoExecutionException, MojoFailureException { |
| 47 | + try { |
| 48 | + MachineId machineId = new MachineId(); |
| 49 | + String offlineUrl = OfflineKeyValidator.getOfflineUrl(machineId); |
| 50 | + |
| 51 | + // Get the primary offline key location (first in the priority list) |
| 52 | + File[] locations = LocalOfflineKey.getLocations(); |
| 53 | + String locationPath = locations.length > 0 |
| 54 | + ? locations[0].getAbsolutePath() |
| 55 | + : "~/.vaadin/offlineKeyV2"; |
| 56 | + |
| 57 | + getLog().info("========================================"); |
| 58 | + getLog().info("Vaadin Offline License Download"); |
| 59 | + getLog().info("========================================"); |
| 60 | + getLog().info(""); |
| 61 | + getLog().info( |
| 62 | + "To download an offline license for this machine, visit:"); |
| 63 | + getLog().info(""); |
| 64 | + getLog().info(" " + offlineUrl); |
| 65 | + getLog().info(""); |
| 66 | + getLog().info( |
| 67 | + "The offline license will be tied to this machine's hardware ID."); |
| 68 | + getLog().info("After downloading, save the license file to:"); |
| 69 | + getLog().info(" " + locationPath); |
| 70 | + getLog().info(""); |
| 71 | + getLog().info( |
| 72 | + "For CI/CD build servers, you can download a server license key"); |
| 73 | + getLog().info("that works on any machine from:"); |
| 74 | + getLog().info(" https://vaadin.com/myaccount/licenses"); |
| 75 | + getLog().info(""); |
| 76 | + } catch (Exception e) { |
| 77 | + throw new MojoFailureException( |
| 78 | + "Failed to generate offline license URL", e); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | +} |
0 commit comments