Skip to content

Commit 8881606

Browse files
committed
Update README to reflect changes in 2.0
Closes elastic#13
1 parent 2b87eb9 commit 8881606

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

README.textile

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,46 @@ bc.. .
1212
|- pom.xml
1313
|- src
1414
|- main
15-
|- assemblies
16-
| |- plugin.xml
15+
| |- java
16+
| | |- ... source code ...
17+
|- test
1718
|- java
1819
| |- ... source code ...
1920
|- resources
20-
|- es-plugin.properties
21+
|- ... test resources ...
22+
2123

2224
p. An Elasticsearch plugin can be created by following these six steps.
2325

2426
* Create pom.xml file in the root directory of your plugin. The "pom.xml":https://github.com/imotov/elasticsearch-native-script-example/blob/master/pom.xml file in this project can be used as a starting point.
2527
* Create source code directories:
26-
** @mkdir -p src/main/assemblies@
2728
** @mkdir -p src/main/java@
28-
** @mkdir -p src/main/resources@
29-
* Download "plugin.xml":https://github.com/imotov/elasticsearch-native-script-example/blob/master/src/main/assemblies/plugin.xml to the @src/main/assemblies@ directory. This file specifies how plugin .zip package should be built. By default, the project artifact with all its dependencies is going to be included in the plugin package. For more information on how to configure the content of the package, see "Maven Assembly Plugin Documentation":http://maven.apache.org/plugins/maven-assembly-plugin/.
29+
** @mkdir -p src/test/java@
30+
** @mkdir -p src/test/resources@
31+
* The parent project @org.elasticsearch.plugin:plugins@ provides all needed tasks to assemble the plugin. It is using the following properties that should be modified to match the project's plugin class name and license file definition.
32+
33+
bc.. <properties>
34+
<!-- define class name for the descriptor file -->
35+
<elasticsearch.plugin.classname>org.elasticsearch.examples.nativescript.plugin.NativeScriptExamplesPlugin</elasticsearch.plugin.classname>
36+
37+
<!-- we have custom licence header in this project -->
38+
<elasticsearch.license.header>${project.basedir}/dev-tools/src/main/resources/license-check/native_script_example_license_header.txt</elasticsearch.license.header>
39+
<elasticsearch.license.headerDefinition>${project.basedir}/dev-tools/src/main/resources/license-check/license_header_definition.xml</elasticsearch.license.headerDefinition>
40+
41+
... other properties ......
42+
43+
</properties>
44+
45+
p.
46+
3047
* Create main Plugin class in the @src/main/java@ directory. This project is using @org.elasticsearch.examples.nativescript.plugin.NativeScriptExamplesPlugin@ class as an example, so the it has to be saved as @src/main/java/org/elasticsearch/examples/nativescript/plugin/NativeScriptExamplesPlugin.java@
3148

3249
bc.. package org.elasticsearch.examples.nativescript.plugin;
3350

34-
import org.elasticsearch.plugins.AbstractPlugin;
51+
import org.elasticsearch.plugins.Plugin;
3552
import org.elasticsearch.script.ScriptModule;
3653

37-
public class NativeScriptExamplesPlugin extends AbstractPlugin {
54+
public class NativeScriptExamplesPlugin extends Plugin {
3855
@Override
3956
public String name() {
4057
return "native-script-examples";
@@ -46,14 +63,24 @@ public class NativeScriptExamplesPlugin extends AbstractPlugin {
4663
}
4764
}
4865

49-
p.
50-
51-
* Create @es-plugin.properties@ file in the @src/main/resources@ directory to point to the Plugin class that was created in the previous step:
66+
p.
5267

53-
bc. plugin=org.elasticsearch.examples.nativescript.plugin.NativeScriptExamplesPlugin
68+
* The parent project will automatically create @plugin-descriptor.properties@ for you.
69+
* If you are not using the standard parent project, you can create this file manually by using this "plugin-descriptor.properties":https://github.com/elastic/elasticsearch/blob/master/dev-tools/src/main/resources/plugin-metadata/plugin-descriptor.properties as a template. You will also need to package the plugin into .zip file, which can be done using maven assemble task and "plugin-assembly.xml":https://github.com/elastic/elasticsearch/blob/master/dev-tools/src/main/resources/plugin-metadata/plugin-assembly.xml assembly definition.
5470

5571
* The plugin can be built using @mvn package@ command. The assembled .zip package can be found in the @target/releases/@ directory and deployed to elasticsearch installation using @plugin -install plugin-name -url path/to/plugin/zip/file@.
5672

73+
h2. Migration from 1.x
74+
75+
p. The plugin infrastructure significantly changed in 2.0. So, the plugin project will need to be modified in order to be used with elasticsearch 2.0:
76+
77+
* Instead of using @es-plugin.properties@ file that in 1.x was places in the plugin jar, the plugin infrastructure is now using the @plugin-descriptor.properties@ file that describes not only the main plugin class, version and description but also plugin type (_site and/or jvm), required minimal java and Elasticsearch versions. The @plugin-descriptor.properties@ file should be placed into root directory of the .zip file that the plugin is packaged into. The simplest way to deal with this change is by switching the plugin project to @org.elasticsearch.plugin:plugins@ as a parent.
78+
* Elasticsearch 2.0 is also stricter when it comes to plugin classes. For example, the "jar hell" prevention mechanism will not allow the plugin to contain classes that are already defined in the Elasticsearch classpath. Make sure that your project doesn't have any dependencies that are conflicting with existing elasticsearch classes.
79+
* In 2.0 the base class for the plugin was renamed from @AbstractPlugin@ to @Plugin@
80+
* Plugins are no longer loaded from the classpath, so they have to be "explicitly loaded":https://github.com/imotov/elasticsearch-native-script-example/commit/96f8b93f27f80346503dfa91e564b87c9334fbdf in the tests.
81+
* Some base test classes need to be "renamed":https://github.com/imotov/elasticsearch-native-script-example/commit/6c4ba4ab967b938fd06200b51e78dcf523861c40.
82+
* Native scripts now have to "indicate":https://github.com/imotov/elasticsearch-native-script-example/commit/4cda2ccdaa8094c5de3e86ccfeea0fe56b26d353 whether they use the `_score` or not.
83+
5784
h2. Adding Native Scripts
5885

5986
p. Now that the plugin infrastructure is complete, it's possible to add a native script.

0 commit comments

Comments
 (0)