|
| 1 | +/* |
| 2 | + * #%L |
| 3 | + * Java to distributable |
| 4 | + * %% |
| 5 | + * Copyright (C) 2023 - 2024 Miguel Jose Da Silva Araujo, Daniel Glez-Peña, |
| 6 | + * Hugo López-Fernández, and Miguel Reboiro-Jato |
| 7 | + * %% |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License as |
| 10 | + * published by the Free Software Foundation, either version 3 of the |
| 11 | + * License, or (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public |
| 19 | + * License along with this program. If not, see |
| 20 | + * <http://www.gnu.org/licenses/gpl-3.0.html>. |
| 21 | + * #L% |
| 22 | + */ |
| 23 | +/** |
| 24 | + * |
| 25 | + */ |
| 26 | +package es.uvigo.esei.sing.java_to_distributable.cli.command; |
| 27 | + |
| 28 | +import java.io.File; |
| 29 | +import java.util.ArrayList; |
| 30 | +import java.util.Arrays; |
| 31 | +import java.util.List; |
| 32 | +import java.util.Map; |
| 33 | + |
| 34 | +import org.slf4j.Logger; |
| 35 | +import org.slf4j.LoggerFactory; |
| 36 | + |
| 37 | +import es.uvigo.ei.sing.yacli.command.option.EnumOption; |
| 38 | +import es.uvigo.ei.sing.yacli.command.option.Option; |
| 39 | +import es.uvigo.ei.sing.yacli.command.option.StringOption; |
| 40 | +import es.uvigo.esei.sing.java_to_distributable.enums.OptionCategoryEnum; |
| 41 | +import es.uvigo.esei.sing.java_to_distributable.enums.UbuntuCodeNameEnum; |
| 42 | +import es.uvigo.esei.sing.java_to_distributable.model.AppInfo; |
| 43 | +import es.uvigo.esei.sing.java_to_distributable.utils.output.AppOutputGenerator; |
| 44 | +import es.uvigo.esei.sing.java_to_distributable.utils.output.PPAAppOutputGenerator; |
| 45 | +import es.uvigo.esei.sing.java_to_distributable.utils.output.OutputGenerator; |
| 46 | +import es.uvigo.esei.sing.java_to_distributable.utils.output.sign.PPASignerAppOutputGenerator; |
| 47 | +import es.uvigo.esei.sing.java_to_distributable.utils.output.publish.PPAPublisherAppOutputGenerator; |
| 48 | + |
| 49 | +/** |
| 50 | + * An specialization of {@link GenerateDistributableCommand} that generates a |
| 51 | + * Debian sources packages that can be published to a PPA. |
| 52 | + * |
| 53 | + * @author Miguel José Da Silva Araujo |
| 54 | + * |
| 55 | + */ |
| 56 | +public class GeneratePPADistributableCommand extends GenerateDistributableCommand { |
| 57 | + |
| 58 | + private static final StringOption MAINTAINER_OPTION = new StringOption( |
| 59 | + Arrays.asList(OptionCategoryEnum.CUSTOM.getCategory()), "maintainer", "m", |
| 60 | + "The maintainer's name of the package/application.", true, true, false |
| 61 | + ); |
| 62 | + |
| 63 | + private static final StringOption CONTACT_NAME_OPTION = new StringOption( |
| 64 | + Arrays.asList(OptionCategoryEnum.CUSTOM.getCategory()), "contact-name", "cn", |
| 65 | + "The name of the person responsible for contact.", true, true, false |
| 66 | + ); |
| 67 | + |
| 68 | + private static final StringOption CONTACT_EMAIL_OPTION = new StringOption( |
| 69 | + Arrays.asList(OptionCategoryEnum.CUSTOM.getCategory()), "contact-email", "ce", |
| 70 | + "The E-mail of the person responsible for contact.", true, true, false |
| 71 | + ); |
| 72 | + |
| 73 | + private static final EnumOption<UbuntuCodeNameEnum> UBUNTU_CODE_NAME_OPTION = new EnumOption<>( |
| 74 | + Arrays.asList(OptionCategoryEnum.CUSTOM.getCategory()), "ubuntu-code-name", "ucn", |
| 75 | + "The first word of the Ubuntu version code name.", UbuntuCodeNameEnum.class, "jammy", true, true, false |
| 76 | + ); |
| 77 | + |
| 78 | + private static final StringOption LICENSE_OPTION = new StringOption( |
| 79 | + Arrays.asList(OptionCategoryEnum.CUSTOM.getCategory()), "licence", "l", |
| 80 | + "The name of the licence of the application.", true, true, false |
| 81 | + ); |
| 82 | + |
| 83 | + private static final StringOption KEY_OPTION = new StringOption( |
| 84 | + Arrays.asList(OptionCategoryEnum.SIGN.getCategory()), "key", "k", |
| 85 | + "The GPG secret key ID for package signing.", true, true, false |
| 86 | + ); |
| 87 | + |
| 88 | + private static final StringOption PPA_USERNAME_OPTION = new StringOption( |
| 89 | + Arrays.asList(OptionCategoryEnum.PUBLISH.getCategory()), "ppa-username", "pu", |
| 90 | + "The Launchpad username of the PPA repository owner.", true, true, false |
| 91 | + ); |
| 92 | + |
| 93 | + private static final StringOption PPA_NAME_OPTION = new StringOption( |
| 94 | + Arrays.asList(OptionCategoryEnum.PUBLISH.getCategory()), "ppa-name", "pn", |
| 95 | + "The name of the PPA repository.", true, true, false |
| 96 | + ); |
| 97 | + |
| 98 | + /** |
| 99 | + * Gets the command name. |
| 100 | + * |
| 101 | + * @return the command name as a {@code String}. |
| 102 | + * |
| 103 | + */ |
| 104 | + @Override |
| 105 | + public String getName() { |
| 106 | + return "generate-ppa-distributable"; |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Gets the command descriptive name. |
| 111 | + * |
| 112 | + * @return the command descriptive name as a {@code String}. |
| 113 | + * |
| 114 | + */ |
| 115 | + @Override |
| 116 | + public String getDescriptiveName() { |
| 117 | + return "Generate GNU/Linux Debian source packages from Java for PPA (Personal Package Archives)"; |
| 118 | + } |
| 119 | + |
| 120 | + /** |
| 121 | + * Gets the command description. |
| 122 | + * |
| 123 | + * @return the command description as a {@code String}. |
| 124 | + * |
| 125 | + */ |
| 126 | + @Override |
| 127 | + public String getDescription() { |
| 128 | + return "Generates the corresponding GNU/Linux Debian source packages from a set of Java sources for publishing in a PPA (Personal Package Archives) repository."; |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + protected List<Option<?>> createDistributableOptions() { |
| 133 | + final List<Option<?>> options = new ArrayList<>(); |
| 134 | + |
| 135 | + options.add(MAINTAINER_OPTION); |
| 136 | + options.add(CONTACT_NAME_OPTION); |
| 137 | + options.add(CONTACT_EMAIL_OPTION); |
| 138 | + options.add(UBUNTU_CODE_NAME_OPTION); |
| 139 | + options.add(LICENSE_OPTION); |
| 140 | + options.add(KEY_OPTION); |
| 141 | + options.add(PPA_USERNAME_OPTION); |
| 142 | + options.add(PPA_NAME_OPTION); |
| 143 | + |
| 144 | + return options; |
| 145 | + } |
| 146 | + |
| 147 | + @Override |
| 148 | + protected OutputGenerator getOutputGenerator(File output, AppInfo info, Map<String, Boolean> options) { |
| 149 | + AppOutputGenerator gen = new PPAAppOutputGenerator(info, output); |
| 150 | + for (String option : options.keySet()) { |
| 151 | + switch (option.toUpperCase()) { |
| 152 | + case "SIGN": |
| 153 | + if (options.get(option) == true) |
| 154 | + gen = new PPASignerAppOutputGenerator(gen); |
| 155 | + break; |
| 156 | + case "PUBLISH": |
| 157 | + if (options.get(option) == true) |
| 158 | + gen = new PPAPublisherAppOutputGenerator(gen); |
| 159 | + break; |
| 160 | + default: |
| 161 | + LOGGER.warn("Option: " + option + " not supported."); |
| 162 | + break; |
| 163 | + } |
| 164 | + } |
| 165 | + return gen; |
| 166 | + } |
| 167 | + |
| 168 | + /** |
| 169 | + * Gets and returns the command {@code Logger}. |
| 170 | + * |
| 171 | + * @return the command {@code Logger} |
| 172 | + * |
| 173 | + */ |
| 174 | + @Override |
| 175 | + protected Logger getLogger() { |
| 176 | + return LoggerFactory.getLogger(GeneratePPADistributableCommand.class); |
| 177 | + } |
| 178 | + |
| 179 | +} |
0 commit comments