Prepara base para plugins online (config, erros, store, manifesto)

This commit is contained in:
tonyhcj committed 2026-11-05 01:44:43 -03:00
1 parent 489e43c125
commit 18f3f643bb
7 files changed
+44 -19

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
Manifest-Version: 1.0 Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build X-COMMENT: Main-Class will be added automatically by build
Implementation-Version: 1.0.0
+7 -1
View File
@@ -7,7 +7,13 @@ public enum ErrorCode {
PLUGIN_INSTALL_FAILED("Não foi possível instalar o plugin."), PLUGIN_INSTALL_FAILED("Não foi possível instalar o plugin."),
PLUGIN_REMOVE_FAILED("Não foi possível remover o plugin."), PLUGIN_REMOVE_FAILED("Não foi possível remover o plugin."),
PLUGIN_LOAD_FAILED("Falha ao carregar um plugin."), PLUGIN_LOAD_FAILED("Falha ao carregar um plugin."),
INVALID_PATH("Caminho de arquivo inválido."); INVALID_PATH("Caminho de arquivo inválido."),
PLUGIN_SERVER_UNREACHABLE("Não foi possível acessar o servidor de plugins."),
PLUGIN_LIST_INVALID("A lista de plugins do servidor está inválida."),
PLUGIN_DOWNLOAD_FAILED("Não foi possível baixar o plugin."),
PLUGIN_HASH_MISMATCH("O arquivo baixado não confere com o hash da lista. Instalação cancelada."),
PLUGIN_SERVER_START_FAILED("Não foi possível iniciar o servidor de plugins."),
UPDATE_FAILED("Não foi possível atualizar o Pitiupi.");
private final String userMessage; private final String userMessage;
+7
View File
@@ -37,6 +37,13 @@ public abstract class Plugin {
public abstract String getAuthor(); public abstract String getAuthor();
public abstract String getVersion(); public abstract String getVersion();
/**
* Descrição curta exibida na lista de plugins online. Padrão: vazia.
*/
public String getDescription() {
return "";
}
public abstract String getIdentifier(); public abstract String getIdentifier();
/** /**
@@ -50,6 +50,15 @@ public final class ConfigLoader {
store(); store();
} }
public String getString(String key, String defaultValue) {
return properties.getProperty(key, defaultValue);
}
public void setString(String key, String value) throws IOException {
properties.setProperty(key, value);
store();
}
public boolean isMigrationCwdPluginsDone() { public boolean isMigrationCwdPluginsDone() {
return getBoolean("migration.cwdPluginsDone", false); return getBoolean("migration.cwdPluginsDone", false);
} }
@@ -21,6 +21,7 @@ public final class PluginMetadataWriter {
props.setProperty("displayName", plugin.getDisplayName()); props.setProperty("displayName", plugin.getDisplayName());
props.setProperty("author", plugin.getAuthor()); props.setProperty("author", plugin.getAuthor());
props.setProperty("version", plugin.getVersion()); props.setProperty("version", plugin.getVersion());
props.setProperty("description", java.util.Objects.requireNonNullElse(plugin.getDescription(), ""));
String arquivoId = deriveArquivoId(jarPath, plugin); String arquivoId = deriveArquivoId(jarPath, plugin);
props.setProperty("arquivoId", arquivoId); props.setProperty("arquivoId", arquivoId);
@@ -29,7 +30,7 @@ public final class PluginMetadataWriter {
} }
} }
static Path metaPathFor(Path jarPath) { public static Path metaPathFor(Path jarPath) {
return Path.of(jarPath.toString() + ".plugin.meta"); return Path.of(jarPath.toString() + ".plugin.meta");
} }
@@ -55,27 +55,28 @@ public final class PluginStore {
} }
public Path installFromFile(Path sourceJar) throws PitiupiException, IOException { public Path installFromFile(Path sourceJar) throws PitiupiException, IOException {
if (sourceJar == null || !Files.isRegularFile(sourceJar)) { return installFromFile(sourceJar, null, true);
throw new PitiupiException(ErrorCode.INVALID_PATH); }
}
String fileName = sourceJar.getFileName().toString();
if (!fileName.endsWith(".jar") || fileName.contains("..")) {
throw new PitiupiException(ErrorCode.INVALID_PATH);
}
Files.createDirectories(pluginsDir);
Files.createDirectories(cacheDir);
Path dest = pluginsDir.resolve(fileName).normalize();
if (!dest.startsWith(pluginsDir.normalize().toAbsolutePath())) {
throw new PitiupiException(ErrorCode.INVALID_PATH);
}
public Path installFromFile(Path sourceJar, String targetName, boolean updateCatalog)
throws PitiupiException, IOException {
if (sourceJar == null || !Files.isRegularFile(sourceJar)) {
throw new PitiupiException(ErrorCode.INVALID_PATH);
}
String fileName = targetName != null ? targetName : sourceJar.getFileName().toString();
if (!fileName.endsWith(".jar") || fileName.contains("..")
|| fileName.contains("/") || fileName.contains("\\")) {
throw new PitiupiException(ErrorCode.INVALID_PATH);
}
Path tmp = cacheDir.resolve(fileName + "." + UUID.randomUUID() + ".part"); Path tmp = cacheDir.resolve(fileName + "." + UUID.randomUUID() + ".part");
Path dest = pluginsDir.resolve(fileName);
try { try {
Files.copy(sourceJar, tmp, StandardCopyOption.REPLACE_EXISTING); Files.copy(sourceJar, tmp, StandardCopyOption.REPLACE_EXISTING);
Files.move(tmp, dest, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); Files.move(tmp, dest, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
rememberInCatalog(sourceJar, fileName); if (updateCatalog) {
rememberInCatalog(sourceJar, fileName);
}
return dest; return dest;
} catch (IOException e) { } catch (IOException e) {
try { try {
+1 -1
View File
@@ -238,7 +238,7 @@ link_plugins_from_selection() {
local mode="${1:-link}" local mode="${1:-link}"
local id dir jar_rel link_name src_abs local id dir jar_rel link_name src_abs
mkdir -p "${PLUGINS_DIR}" mkdir -p "${PLUGINS_DIR}"
rm -f "${PLUGINS_DIR}/"*.jar find "${PLUGINS_DIR}" -maxdepth 1 -type l -name '*.jar' -delete
while IFS= read -r id; do while IFS= read -r id; do
[[ -z "$id" ]] && continue [[ -z "$id" ]] && continue