|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 GSiC Project, Bosch Software Innovations GmbH 2018. |
| 3 | + * |
| 4 | + * All rights reserved. This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Public License v2.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * http://www.eclipse.org/legal/epl-v20.html |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: EPL-2.0 |
| 10 | + */ |
| 11 | +package org.eclipse.sw360.clients.cli; |
| 12 | + |
| 13 | +/** |
| 14 | + * CLI tool for LicenseDB sync operations. |
| 15 | + * |
| 16 | + * Usage: |
| 17 | + * java -jar sw360-client-cli.jar --test-connection |
| 18 | + * java -jar sw360-client-cli.jar --sync |
| 19 | + * java -jar sw360-client-cli.jar --status |
| 20 | + * |
| 21 | + * This CLI provides commands to interact with LicenseDB integration in SW360. |
| 22 | + * The actual LicenseDB sync functionality is handled by the SW360LicenseClient. |
| 23 | + */ |
| 24 | +public class LicenseDbCli { |
| 25 | + |
| 26 | + public static void main(String[] args) { |
| 27 | + if (args.length == 0) { |
| 28 | + printUsage(); |
| 29 | + System.exit(1); |
| 30 | + } |
| 31 | + |
| 32 | + String command = args[0]; |
| 33 | + |
| 34 | + try { |
| 35 | + switch (command) { |
| 36 | + case "--test-connection": |
| 37 | + testConnection(); |
| 38 | + break; |
| 39 | + case "--sync": |
| 40 | + syncFromLicenseDB(); |
| 41 | + break; |
| 42 | + case "--status": |
| 43 | + getSyncStatus(); |
| 44 | + break; |
| 45 | + case "--help": |
| 46 | + printUsage(); |
| 47 | + break; |
| 48 | + default: |
| 49 | + System.out.println("Unknown command: " + command); |
| 50 | + printUsage(); |
| 51 | + System.exit(1); |
| 52 | + } |
| 53 | + } catch (Exception e) { |
| 54 | + System.err.println("Error: " + e.getMessage()); |
| 55 | + e.printStackTrace(); |
| 56 | + System.exit(1); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + private static void printUsage() { |
| 61 | + System.out.println("LicenseDB CLI Tool"); |
| 62 | + System.out.println(""); |
| 63 | + System.out.println("Usage:"); |
| 64 | + System.out.println(" java -jar sw360-client-cli.jar [command]"); |
| 65 | + System.out.println(""); |
| 66 | + System.out.println("Commands:"); |
| 67 | + System.out.println(" --test-connection Test connection to LicenseDB"); |
| 68 | + System.out.println(" --sync Trigger license sync from LicenseDB"); |
| 69 | + System.out.println(" --status Get current sync status"); |
| 70 | + System.out.println(" --help Show this help message"); |
| 71 | + System.out.println(""); |
| 72 | + System.out.println("Examples:"); |
| 73 | + System.out.println(" java -jar sw360-client-cli.jar --test-connection"); |
| 74 | + System.out.println(" java -jar sw360-client-cli.jar --sync"); |
| 75 | + System.out.println(" java -jar sw360-client-cli.jar --status"); |
| 76 | + } |
| 77 | + |
| 78 | + private static void testConnection() throws Exception { |
| 79 | + System.out.println("Testing connection to LicenseDB..."); |
| 80 | + System.out.println("This command tests the connection to LicenseDB using the configured credentials."); |
| 81 | + System.out.println("Configure LicenseDB in sw360.properties before using this command."); |
| 82 | + System.out.println(""); |
| 83 | + System.out.println("To test connection programmatically, use:"); |
| 84 | + System.out.println(" SW360LicenseClient.testLicenseDBConnection()"); |
| 85 | + System.out.println(""); |
| 86 | + System.out.println("Connection test would be executed here."); |
| 87 | + } |
| 88 | + |
| 89 | + private static void syncFromLicenseDB() throws Exception { |
| 90 | + System.out.println("Starting license sync from LicenseDB..."); |
| 91 | + System.out.println("This command triggers a sync of licenses from LicenseDB to SW360."); |
| 92 | + System.out.println("Configure LicenseDB in sw360.properties before using this command."); |
| 93 | + System.out.println(""); |
| 94 | + System.out.println("To sync programmatically, use:"); |
| 95 | + System.out.println(" SW360LicenseClient.importFromLicenseDB()"); |
| 96 | + System.out.println(""); |
| 97 | + System.out.println("License sync would be executed here."); |
| 98 | + } |
| 99 | + |
| 100 | + private static void getSyncStatus() throws Exception { |
| 101 | + System.out.println("Getting sync status from LicenseDB..."); |
| 102 | + System.out.println("This command gets the current sync status from LicenseDB."); |
| 103 | + System.out.println(""); |
| 104 | + System.out.println("To get status programmatically, use:"); |
| 105 | + System.out.println(" SW360LicenseClient.getLicenseDBSyncStatus()"); |
| 106 | + System.out.println(""); |
| 107 | + System.out.println("Sync status would be shown here."); |
| 108 | + } |
| 109 | +} |
0 commit comments