Skip to content

Commit

Permalink
Add online plugin repository and a 'plugin' command to download them, c…
Browse files Browse the repository at this point in the history
…loses #157
  • Loading branch information
kimchy committed May 3, 2010
1 parent 2d20ba0 commit b0e1c58
Show file tree
Hide file tree
Showing 5 changed files with 519 additions and 1 deletion.
33 changes: 33 additions & 0 deletions bin/plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh

SCRIPT="$0"

# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
# Drop everything prior to ->
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

# determine elasticsearch home
ES_HOME=`dirname "$SCRIPT"`/..

# make ELASTICSEARCH_HOME absolute
ES_HOME=`cd $ES_HOME; pwd`


if [ -x $JAVA_HOME/bin/java ]; then
JAVA=$JAVA_HOME/bin/java
else
JAVA=`which java`
fi

CLASSPATH=$CLASSPATH:$ES_HOME/lib/*

$JAVA -Delasticsearch -Des.path.home=$ES_HOME -cp $CLASSPATH org.elasticsearch.plugins.PluginManager $*

25 changes: 25 additions & 0 deletions bin/plugin.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@echo off

SETLOCAL

if NOT DEFINED JAVA_HOME goto err

set SCRIPT_DIR=%~dp0
for %%I in ("%SCRIPT_DIR%..") do set ES_HOME=%%~dpfI


set ES_CLASSPATH=$CLASSPATH;"%ES_HOME%/lib/*"
set ES_PARAMS=-Delasticsearch -Des.path.home="%ES_HOME%"

"%JAVA_HOME%\bin\java" %JAVA_OPTS% %ES_JAVA_OPTS% %ES_PARAMS% -cp "%ES_CLASSPATH%" "org.elasticsearch.plugins.PluginManager" %*
goto finally


:err
echo JAVA_HOME environment variable must be set!
pause


:finally

ENDLOCAL
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ task explodedDist(dependsOn: [configurations.distLib], description: 'Builds a mi
ant.delete { fileset(dir: explodedDistLibDir, includes: "slf4j-*.jar") } // no need for slf4j
ant.delete { fileset(dir: explodedDistLibDir, includes: "jackson-*.jar") } // no need jackson, we jarjar it
ant.delete { fileset(dir: explodedDistLibDir, includes: "joda-*.jar") } // no need joda, we jarjar it
ant.delete { fileset(dir: explodedDistLibDir, includes: "snakeyaml-*.jar") } // no need joda, we jarjar it
ant.delete { fileset(dir: explodedDistLibDir, includes: "snakeyaml-*.jar") } // no need snakeyaml, we jarjar it

ant.chmod(dir: "$explodedDistDir/bin", perm: "ugo+rx", includes: "**/*")
}
Expand All @@ -88,6 +88,7 @@ task zip(type: Zip, dependsOn: ['explodedDist']) {
from(explodedDistDir) {
into zipRootFolder
exclude 'bin/elasticsearch'
exclude 'bin/plugin'
exclude 'bin/service/elasticsearch'
exclude 'bin/service/elasticsearch32'
exclude 'bin/service/elasticsearch64'
Expand All @@ -96,6 +97,7 @@ task zip(type: Zip, dependsOn: ['explodedDist']) {
from(explodedDistDir) {
into zipRootFolder
include 'bin/elasticsearch'
include 'bin/plugin'
include 'bin/service/elasticsearch'
include 'bin/service/elasticsearch32'
include 'bin/service/elasticsearch64'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.elasticsearch.plugins;

import org.elasticsearch.Version;
import org.elasticsearch.env.Environment;
import org.elasticsearch.node.internal.InternalSettingsPerparer;
import org.elasticsearch.util.Tuple;
import org.elasticsearch.util.http.HttpDownloadHelper;
import org.elasticsearch.util.settings.Settings;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*;

/**
* @author kimchy (shay.banon)
*/
public class PluginManager {

private final Environment environment;

private final String url;

public PluginManager(Environment environment, String url) {
this.environment = environment;
this.url = url;
}

public void downloadPlugin(String name) throws IOException {
HttpDownloadHelper downloadHelper = new HttpDownloadHelper();

URL pluginUrl = new URL(url + "/" + name + "/elasticsearch-" + name + "-" + Version.number() + ".zip");
downloadHelper.download(pluginUrl, new File(environment.pluginsFile(), name + ".zip"), new HttpDownloadHelper.VerboseProgress(System.out));
}

public static void main(String[] args) {
Tuple<Settings, Environment> initialSettings = InternalSettingsPerparer.prepareSettings(EMPTY_SETTINGS, true);

if (!initialSettings.v2().pluginsFile().exists()) {
initialSettings.v2().pluginsFile().mkdirs();
}

PluginManager pluginManager = new PluginManager(initialSettings.v2(), "http://elasticsearch.googlecode.com/svn/plugins");

if (args.length < 1) {
System.out.println("Usage:");
System.out.println(" - get [list of plugin names]: Downloads all the listed plugins");
}
String command = args[0];
if (command.equals("get") || command.equals("-get") || command.equals("-g") || command.equals("--get")) {
if (args.length < 2) {
System.out.println("'get' requires an additional parameter with the plugin name");
}
for (int i = 1; i < args.length; i++) {
String pluginName = args[i];
System.out.print("-> Downloading " + pluginName + " ");
try {
pluginManager.downloadPlugin(pluginName);
System.out.println(" DONE");
} catch (IOException e) {
System.out.println("Failed to download " + pluginName + ", reason: " + e.getMessage());
}
}
} else {
System.out.println("No command matching '" + command + "' found");
}
}
}
Loading

0 comments on commit b0e1c58

Please sign in to comment.