Plugins: Fix meta plugins to install bundled plugins with their real name (#28285)
Meta plugins move the unzipped plugin as is, but the inner plugins may have a different directory name than their corresponding plugin properties file specifies. This commit fixes installation to rename the directory if necessary.
This commit is contained in:
parent
e442a34acc
commit
de9d903b1e
|
@ -646,9 +646,11 @@ class InstallPluginCommand extends EnvironmentAwareCommand {
|
||||||
Environment env, List<Path> deleteOnFailure) throws Exception {
|
Environment env, List<Path> deleteOnFailure) throws Exception {
|
||||||
final MetaPluginInfo metaInfo = MetaPluginInfo.readFromProperties(tmpRoot);
|
final MetaPluginInfo metaInfo = MetaPluginInfo.readFromProperties(tmpRoot);
|
||||||
verifyPluginName(env.pluginsFile(), metaInfo.getName(), tmpRoot);
|
verifyPluginName(env.pluginsFile(), metaInfo.getName(), tmpRoot);
|
||||||
|
|
||||||
final Path destination = env.pluginsFile().resolve(metaInfo.getName());
|
final Path destination = env.pluginsFile().resolve(metaInfo.getName());
|
||||||
deleteOnFailure.add(destination);
|
deleteOnFailure.add(destination);
|
||||||
terminal.println(VERBOSE, metaInfo.toString());
|
terminal.println(VERBOSE, metaInfo.toString());
|
||||||
|
|
||||||
final List<Path> pluginPaths = new ArrayList<>();
|
final List<Path> pluginPaths = new ArrayList<>();
|
||||||
try (DirectoryStream<Path> paths = Files.newDirectoryStream(tmpRoot)) {
|
try (DirectoryStream<Path> paths = Files.newDirectoryStream(tmpRoot)) {
|
||||||
// Extract bundled plugins path and validate plugin names
|
// Extract bundled plugins path and validate plugin names
|
||||||
|
@ -665,19 +667,11 @@ class InstallPluginCommand extends EnvironmentAwareCommand {
|
||||||
for (Path plugin : pluginPaths) {
|
for (Path plugin : pluginPaths) {
|
||||||
final PluginInfo info = verify(terminal, plugin, isBatch, env);
|
final PluginInfo info = verify(terminal, plugin, isBatch, env);
|
||||||
pluginInfos.add(info);
|
pluginInfos.add(info);
|
||||||
Path tmpBinDir = plugin.resolve("bin");
|
installPluginSupportFiles(info, plugin, env.binFile().resolve(metaInfo.getName()),
|
||||||
if (Files.exists(tmpBinDir)) {
|
env.configFile().resolve(metaInfo.getName()), deleteOnFailure);
|
||||||
Path destBinDir = env.binFile().resolve(metaInfo.getName());
|
// ensure the plugin dir within the tmpRoot has the correct name
|
||||||
deleteOnFailure.add(destBinDir);
|
if (plugin.getFileName().toString().equals(info.getName()) == false) {
|
||||||
installBin(info, tmpBinDir, destBinDir);
|
Files.move(plugin, plugin.getParent().resolve(info.getName()), StandardCopyOption.ATOMIC_MOVE);
|
||||||
}
|
|
||||||
|
|
||||||
Path tmpConfigDir = plugin.resolve("config");
|
|
||||||
if (Files.exists(tmpConfigDir)) {
|
|
||||||
// some files may already exist, and we don't remove plugin config files on plugin removal,
|
|
||||||
// so any installed config files are left on failure too
|
|
||||||
Path destConfigDir = env.configFile().resolve(metaInfo.getName());
|
|
||||||
installConfig(info, tmpConfigDir, destConfigDir);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
movePlugin(tmpRoot, destination);
|
movePlugin(tmpRoot, destination);
|
||||||
|
@ -693,7 +687,7 @@ class InstallPluginCommand extends EnvironmentAwareCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installs the plugin from {@code tmpRoot} into the plugins dir.
|
* Installs the plugin from {@code tmpRoot} into the plugins dir.
|
||||||
* If the plugin has a bin dir and/or a config dir, those are copied.
|
* If the plugin has a bin dir and/or a config dir, those are moved.
|
||||||
*/
|
*/
|
||||||
private void installPlugin(Terminal terminal, boolean isBatch, Path tmpRoot,
|
private void installPlugin(Terminal terminal, boolean isBatch, Path tmpRoot,
|
||||||
Environment env, List<Path> deleteOnFailure) throws Exception {
|
Environment env, List<Path> deleteOnFailure) throws Exception {
|
||||||
|
@ -701,9 +695,20 @@ class InstallPluginCommand extends EnvironmentAwareCommand {
|
||||||
final Path destination = env.pluginsFile().resolve(info.getName());
|
final Path destination = env.pluginsFile().resolve(info.getName());
|
||||||
deleteOnFailure.add(destination);
|
deleteOnFailure.add(destination);
|
||||||
|
|
||||||
|
installPluginSupportFiles(info, tmpRoot, env.binFile().resolve(info.getName()),
|
||||||
|
env.configFile().resolve(info.getName()), deleteOnFailure);
|
||||||
|
movePlugin(tmpRoot, destination);
|
||||||
|
if (info.requiresKeystore()) {
|
||||||
|
createKeystoreIfNeeded(terminal, env, info);
|
||||||
|
}
|
||||||
|
terminal.println("-> Installed " + info.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Moves bin and config directories from the plugin if they exist */
|
||||||
|
private void installPluginSupportFiles(PluginInfo info, Path tmpRoot,
|
||||||
|
Path destBinDir, Path destConfigDir, List<Path> deleteOnFailure) throws Exception {
|
||||||
Path tmpBinDir = tmpRoot.resolve("bin");
|
Path tmpBinDir = tmpRoot.resolve("bin");
|
||||||
if (Files.exists(tmpBinDir)) {
|
if (Files.exists(tmpBinDir)) {
|
||||||
Path destBinDir = env.binFile().resolve(info.getName());
|
|
||||||
deleteOnFailure.add(destBinDir);
|
deleteOnFailure.add(destBinDir);
|
||||||
installBin(info, tmpBinDir, destBinDir);
|
installBin(info, tmpBinDir, destBinDir);
|
||||||
}
|
}
|
||||||
|
@ -712,14 +717,8 @@ class InstallPluginCommand extends EnvironmentAwareCommand {
|
||||||
if (Files.exists(tmpConfigDir)) {
|
if (Files.exists(tmpConfigDir)) {
|
||||||
// some files may already exist, and we don't remove plugin config files on plugin removal,
|
// some files may already exist, and we don't remove plugin config files on plugin removal,
|
||||||
// so any installed config files are left on failure too
|
// so any installed config files are left on failure too
|
||||||
Path destConfigDir = env.configFile().resolve(info.getName());
|
|
||||||
installConfig(info, tmpConfigDir, destConfigDir);
|
installConfig(info, tmpConfigDir, destConfigDir);
|
||||||
}
|
}
|
||||||
movePlugin(tmpRoot, destination);
|
|
||||||
if (info.requiresKeystore()) {
|
|
||||||
createKeystoreIfNeeded(terminal, env, info);
|
|
||||||
}
|
|
||||||
terminal.println("-> Installed " + info.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Moves the plugin directory into its final destination. **/
|
/** Moves the plugin directory into its final destination. **/
|
||||||
|
|
Loading…
Reference in New Issue