Stable Plugin API modules and analysis interfaces (#88775)

This commit adds stable analysis plugin API with analysis components interfaces and annotations.
It does not contain any usage of it yet. Separate changes to introduce example plugins or refactoring to existing ones will follow later.

It contains two gradle modules. One plugin-api with two annotations Nameable and NamedComponent, which can be reused for plugins other than analysis.
And second analysis-plugin-api which contains analysis components (TokenFilterFactory, CharFilterFactory etc)

NamedComponent - used by plugin developer - indicates that a Nameable component will be registered under a given name.
Nameable - for analysis plugins it is only used by the stable analysis api designers (ES) - indicates that component have a name and should be declared with NamedComponent

additional tasks that will follow: #88980
This commit is contained in:
Przemyslaw Gomulka 2022-08-30 11:04:39 +02:00 committed by GitHub
parent 22c478080e
commit bc4c6784dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 1034 additions and 0 deletions

View file

@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
apply plugin: 'elasticsearch.publish'
apply plugin: 'elasticsearch.build'
tasks.named("loggerUsageCheck").configure {enabled = false }
tasks.named('forbiddenApisMain').configure {
replaceSignatureFiles 'jdk-signatures'
}

View file

@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
module org.elasticsearch.plugin.api {
exports org.elasticsearch.plugin.api;
}

View file

@ -0,0 +1,30 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.plugin.api;
/**
* A named plugin component. Components with a name can be registered and fetched under a name given in
* <code>@NamedComponent</code>
* @see NamedComponent
*/
public interface Nameable {
/**
* Returns a name from NamedComponent annotation.
* @return a name used on NamedComponent annotation or null when a class implementing this interface is not annotated
*/
default String name() {
NamedComponent[] annotationsByType = this.getClass().getAnnotationsByType(NamedComponent.class);
if (annotationsByType.length == 1) {
return annotationsByType[0].name();
}
return null;
}
}

View file

@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.plugin.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation used on plugin components which will be registered under a given name by Elasticsearch server.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
public @interface NamedComponent {
/**
* A name used for registration and lookup
* @return a name
*/
String name();
}

View file

@ -0,0 +1,24 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
/**
* An api used by plugin developers to implement custom Elasticsearch plugins.
* The package convention in plugin apis is as follows:
* <ul>
* <li> The root package is org.elasticsearch.plugin</li>
* <li> Specialised API jars have their name following the root package.
* i.e. org.elasticsearch.analysis
* </li>
* <li> Interfaces and annotations used by plugin developers are in `api` package
* i.e org.elasticsearch.analysis.api or org.elasticsearch.api
* <li> packages which are not meant to be used by plugin developers should not be subpackages of api
* i.e org.elasticsearch.analysis.internal
* </li>
* </ul>
*/
package org.elasticsearch.plugin.api;