|
@@ -37,12 +37,11 @@ import org.gradle.api.Action;
|
|
|
import org.gradle.api.Named;
|
|
|
import org.gradle.api.NamedDomainObjectContainer;
|
|
|
import org.gradle.api.Project;
|
|
|
+import org.gradle.api.artifacts.Configuration;
|
|
|
import org.gradle.api.file.FileTree;
|
|
|
import org.gradle.api.file.RegularFile;
|
|
|
-import org.gradle.api.file.RegularFileProperty;
|
|
|
import org.gradle.api.logging.Logger;
|
|
|
import org.gradle.api.logging.Logging;
|
|
|
-import org.gradle.api.provider.Property;
|
|
|
import org.gradle.api.provider.Provider;
|
|
|
import org.gradle.api.tasks.Classpath;
|
|
|
import org.gradle.api.tasks.Input;
|
|
@@ -61,7 +60,6 @@ import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.LineNumberReader;
|
|
|
import java.io.UncheckedIOException;
|
|
|
-import java.net.URI;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
@@ -70,6 +68,7 @@ import java.nio.file.StandardOpenOption;
|
|
|
import java.time.Instant;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.HashMap;
|
|
@@ -126,7 +125,8 @@ public class ElasticsearchNode implements TestClusterConfiguration {
|
|
|
private final Path workingDir;
|
|
|
|
|
|
private final LinkedHashMap<String, Predicate<TestClusterConfiguration>> waitConditions = new LinkedHashMap<>();
|
|
|
- private final List<Provider<URI>> plugins = new ArrayList<>();
|
|
|
+ private final Map<String, Configuration> pluginAndModuleConfigurations = new HashMap<>();
|
|
|
+ private final List<Provider<File>> plugins = new ArrayList<>();
|
|
|
private final List<Provider<File>> modules = new ArrayList<>();
|
|
|
private final LazyPropertyMap<String, CharSequence> settings = new LazyPropertyMap<>("Settings", this);
|
|
|
private final LazyPropertyMap<String, CharSequence> keystoreSettings = new LazyPropertyMap<>("Keystore", this);
|
|
@@ -262,45 +262,50 @@ public class ElasticsearchNode implements TestClusterConfiguration {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void plugin(RegularFileProperty plugin) {
|
|
|
- this.plugins.add(plugin.map(p -> p.getAsFile().toURI()));
|
|
|
+ // package protected so only TestClustersAware can access
|
|
|
+ @Internal
|
|
|
+ Collection<Configuration> getPluginAndModuleConfigurations() {
|
|
|
+ return pluginAndModuleConfigurations.values();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void plugin(Provider<URI> plugin) {
|
|
|
- requireNonNull(plugin, "Plugin name can't be null");
|
|
|
- checkFrozen();
|
|
|
- if (plugins.contains(plugin)) {
|
|
|
- throw new TestClustersException("Plugin already configured for installation " + plugin);
|
|
|
- }
|
|
|
- this.plugins.add(plugin);
|
|
|
+ // creates a configuration to depend on the given plugin project, then wraps that configuration
|
|
|
+ // to grab the zip as a file provider
|
|
|
+ private Provider<RegularFile> maybeCreatePluginOrModuleDependency(String path) {
|
|
|
+ Configuration configuration = pluginAndModuleConfigurations.computeIfAbsent(
|
|
|
+ path,
|
|
|
+ key -> project.getConfigurations()
|
|
|
+ .detachedConfiguration(project.getDependencies().project(Map.of("path", path, "configuration", "zip")))
|
|
|
+ );
|
|
|
+ Provider<File> fileProvider = configuration.getElements()
|
|
|
+ .map(
|
|
|
+ s -> s.stream()
|
|
|
+ .findFirst()
|
|
|
+ .orElseThrow(() -> new IllegalStateException("zip configuration of project " + path + " had no files"))
|
|
|
+ .getAsFile()
|
|
|
+ );
|
|
|
+ return project.getLayout().file(fileProvider);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void plugin(URI plugin) {
|
|
|
- Property<URI> uri = project.getObjects().property(URI.class);
|
|
|
- uri.set(plugin);
|
|
|
- this.plugin(uri);
|
|
|
+ public void plugin(Provider<RegularFile> plugin) {
|
|
|
+ checkFrozen();
|
|
|
+ this.plugins.add(plugin.map(RegularFile::getAsFile));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void plugin(File plugin) {
|
|
|
- Property<URI> uri = project.getObjects().property(URI.class);
|
|
|
- uri.set(plugin.toURI());
|
|
|
- this.plugin(uri);
|
|
|
+ public void plugin(String pluginProjectPath) {
|
|
|
+ plugin(maybeCreatePluginOrModuleDependency(pluginProjectPath));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void module(File module) {
|
|
|
- RegularFileProperty file = project.getObjects().fileProperty();
|
|
|
- file.fileValue(module);
|
|
|
- this.module(file);
|
|
|
+ public void module(Provider<RegularFile> module) {
|
|
|
+ checkFrozen();
|
|
|
+ this.modules.add(module.map(RegularFile::getAsFile));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void module(Provider<RegularFile> module) {
|
|
|
- this.modules.add(module.map(RegularFile::getAsFile));
|
|
|
+ public void module(String moduleProjectPath) {
|
|
|
+ module(maybeCreatePluginOrModuleDependency(moduleProjectPath));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -449,7 +454,7 @@ public class ElasticsearchNode implements TestClusterConfiguration {
|
|
|
logToProcessStdout("installing " + plugins.size() + " plugins in a single transaction");
|
|
|
final String[] arguments = Stream.concat(
|
|
|
Stream.of("install", "--batch"),
|
|
|
- plugins.stream().map(Provider::get).map(URI::toString)
|
|
|
+ plugins.stream().map(Provider::get).map(p -> p.toURI().toString())
|
|
|
).toArray(String[]::new);
|
|
|
runElasticsearchBinScript("elasticsearch-plugin", arguments);
|
|
|
} else {
|
|
@@ -1242,10 +1247,7 @@ public class ElasticsearchNode implements TestClusterConfiguration {
|
|
|
}
|
|
|
|
|
|
private List<File> getInstalledFileSet(Action<? super PatternFilterable> filter) {
|
|
|
- return Stream.concat(
|
|
|
- plugins.stream().map(Provider::get).filter(uri -> uri.getScheme().equalsIgnoreCase("file")).map(File::new),
|
|
|
- modules.stream().map(p -> p.get())
|
|
|
- )
|
|
|
+ return Stream.concat(plugins.stream().map(Provider::get), modules.stream().map(Provider::get))
|
|
|
.filter(File::exists)
|
|
|
// TODO: We may be able to simplify this with Gradle 5.6
|
|
|
// https://docs.gradle.org/nightly/release-notes.html#improved-handling-of-zip-archives-on-classpaths
|
|
@@ -1255,15 +1257,6 @@ public class ElasticsearchNode implements TestClusterConfiguration {
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- @Input
|
|
|
- public Set<URI> getRemotePlugins() {
|
|
|
- Set<URI> file = plugins.stream()
|
|
|
- .map(Provider::get)
|
|
|
- .filter(uri -> uri.getScheme().equalsIgnoreCase("file") == false)
|
|
|
- .collect(Collectors.toSet());
|
|
|
- return file;
|
|
|
- }
|
|
|
-
|
|
|
@Classpath
|
|
|
public List<File> getInstalledClasspath() {
|
|
|
return getInstalledFileSet(filter -> filter.include("**/*.jar"));
|