Skip to content

Plugin scanning with asm in lib #89887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public class InternalDistributionModuleCheckTaskProvider {
"org.elasticsearch.geo",
"org.elasticsearch.logging",
"org.elasticsearch.lz4",
"org.elasticsearch.plugin.analysis.api",
"org.elasticsearch.plugin.api",
"org.elasticsearch.plugin.scanner",
"org.elasticsearch.pluginclassloader",
"org.elasticsearch.securesm",
"org.elasticsearch.server",
Expand Down
11 changes: 6 additions & 5 deletions libs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ configure(subprojects - project('elasticsearch-log4j')) {
Project depProject = dep.dependencyProject
if (depProject != null
&& false == isPluginApi(project, depProject)
&& false == project.path.equals(':libs:elasticsearch-plugin-scanner') //TODO how should we implement plugin scanning?
&& false == depProject.path.equals(':libs:elasticsearch-x-content')
&& false == depProject.path.equals(':libs:elasticsearch-core')
&& depProject.path.startsWith(':libs')
&& depProject.name.startsWith('elasticsearch-')) {
throw new InvalidUserDataException("projects in :libs "
+ "may not depend on other projects libs except "
+ ":libs:elasticsearch-core but "
+ "${project.path} depends on ${depProject.path}")
// throw new InvalidUserDataException("projects in :libs "
// + "may not depend on other projects libs except "
// + ":libs:elasticsearch-core but "
// + "${project.path} depends on ${depProject.path}")
}
}
}
}
}

boolean isPluginApi(Project project, Project depProject) {
return project.path.matches(".*elasticsearch-plugin-.*-api") && depProject.path.equals(':libs:elasticsearch-plugin-api')
return project.path.matches(".*elasticsearch-plugin-.*api")
}
2 changes: 1 addition & 1 deletion libs/core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@

exports org.elasticsearch.core;
exports org.elasticsearch.jdk;
exports org.elasticsearch.core.internal.provider to org.elasticsearch.xcontent;
exports org.elasticsearch.core.internal.provider to org.elasticsearch.xcontent, org.elasticsearch.plugin.scanner;
}
4 changes: 0 additions & 4 deletions libs/logging/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import org.elasticsearch.gradle.transform.UnzipTransform

import java.util.stream.Collectors

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
package org.elasticsearch.plugin.analysis.api;

import org.apache.lucene.analysis.Analyzer;
import org.elasticsearch.plugin.api.Extensible;
import org.elasticsearch.plugin.api.Nameable;

/**
* An analysis component used to create Analyzers.
*/
@Extensible
public interface AnalyzerFactory extends Nameable {
/**
* Returns a lucene org.apache.lucene.analysis.Analyzer instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.elasticsearch.plugin.analysis.api;

import org.elasticsearch.plugin.api.Extensible;
import org.elasticsearch.plugin.api.Nameable;

import java.io.Reader;
Expand All @@ -16,6 +17,7 @@
* An analysis component used to create char filters.
*
*/
@Extensible
public interface CharFilterFactory extends Nameable {
/**
* Wraps the given Reader with a CharFilter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
package org.elasticsearch.plugin.analysis.api;

import org.apache.lucene.analysis.TokenStream;
import org.elasticsearch.plugin.api.Extensible;
import org.elasticsearch.plugin.api.Nameable;

/**
* An analysis component used to create token filters.
*/
@Extensible
public interface TokenFilterFactory extends Nameable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
package org.elasticsearch.plugin.analysis.api;

import org.apache.lucene.analysis.Tokenizer;
import org.elasticsearch.plugin.api.Extensible;
import org.elasticsearch.plugin.api.Nameable;

/**
* An analysis component used to create tokenizers.
*/
@Extensible
public interface TokenizerFactory extends Nameable {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"org.elasticsearch.plugin.analysis.api.AnalyzerFactory":"org.elasticsearch.plugin.analysis.api.AnalyzerFactory",
"org.elasticsearch.plugin.analysis.api.CharFilterFactory":"org.elasticsearch.plugin.analysis.api.CharFilterFactory",
"org.elasticsearch.plugin.analysis.api.TokenFilterFactory":"org.elasticsearch.plugin.analysis.api.TokenFilterFactory",
"org.elasticsearch.plugin.analysis.api.TokenizerFactory":"org.elasticsearch.plugin.analysis.api.TokenizerFactory"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.TYPE;

/**
* Marker for things that can be loaded by component loader.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(value = { TYPE })
public @interface Extensible {
}
80 changes: 80 additions & 0 deletions libs/plugin-scanner/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import org.elasticsearch.gradle.transform.UnzipTransform

import java.util.stream.Collectors

/*
* 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'

def isImplAttr = Attribute.of("is.impl", Boolean)
tasks.named("jarHell").configure { enabled = false } //TODO FIX
configurations {
providerImpl {
attributes.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE)
attributes.attribute(isImplAttr, true)
}
}

dependencies {
registerTransform(
UnzipTransform.class, transformSpec -> {
transformSpec.getFrom()
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.JAR_TYPE)
.attribute(isImplAttr, true)
transformSpec.getTo()
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE)
.attribute(isImplAttr, true)
transformSpec.parameters(parameters -> {
parameters.includeArtifactName.set(true)
})

})

api project(':libs:elasticsearch-core')
api project(":libs:elasticsearch-logging")
providerImpl project(':libs:elasticsearch-plugin-scanner:impl')

testImplementation(project(":test:framework")) {
exclude group: 'org.elasticsearch', module: 'elasticsearch-x-content'
}
}

tasks.named('forbiddenApisMain').configure {
// :libs:elasticsearch-logging does not depend on server
replaceSignatureFiles 'jdk-signatures'
}
tasks.named("compileJava").configure {
options.compilerArgs.add("-Xlint:-requires-automatic,-requires-transitive-automatic")
options.compilerArgs.add("-Xlint:-module") // qualified exports
options.compilerArgs.add("-Xlint:-exports") // implements Message!!
}


File generatedResourcesDir = new File(buildDir, 'generated-resources')
def generateProviderManifest = tasks.register("generateProviderManifest") {
File manifestFile = new File(generatedResourcesDir, "LISTING.TXT")
inputs.property('jars', configurations.providerImpl)
outputs.file(manifestFile)
doLast {
manifestFile.parentFile.mkdirs()
manifestFile.setText(configurations.providerImpl.files.stream()
.map(f -> f.name).collect(Collectors.joining('\n')), 'UTF-8')
}
}

def generateProviderImpl = tasks.register("generateProviderImpl", Copy) {
destinationDir = new File(generatedResourcesDir, "impl")
into("IMPL-JARS/plugin-scanner") {
from(configurations.providerImpl)
from(generateProviderManifest)
}
}
sourceSets.main.output.dir(generateProviderImpl)

47 changes: 47 additions & 0 deletions libs/plugin-scanner/impl/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.java'


archivesBaseName = "plugin-scanner-impl"

tasks.named("loggerUsageCheck").configure {enabled = false }
String jacksonVersion = "2.13.2"
String asmVersion = "9.2"

dependencies {
compileOnly project(":libs:elasticsearch-plugin-api")
compileOnly project(":libs:elasticsearch-logging")
// api project(":libs:elasticsearch-x-content")
compileOnly project(":libs:elasticsearch-plugin-scanner")
implementation "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
implementation "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
implementation "org.ow2.asm:asm:${asmVersion}"

// logging
compileOnly "org.apache.logging.log4j:log4j-api:${versions.log4j}"

testImplementation(project(":test:framework")) {
exclude group: 'org.elasticsearch', module: 'elasticsearch-server'
}
}
tasks.named("dependencyLicenses").configure {
mapping from: /jackson-.*/, to: 'jackson'
}
tasks.named('forbiddenApisMain').configure {
// :libs:elasticsearch-logging does not depend on server
replaceSignatureFiles 'jdk-signatures'
}

tasks.named("compileJava").configure {
options.compilerArgs.add("-Xlint:-requires-automatic,-requires-transitive-automatic")
options.compilerArgs.add("-Xlint:-module") // qualified exports
options.compilerArgs.add("-Xlint:-exports") // implements Message!!
}
1 change: 1 addition & 0 deletions libs/plugin-scanner/impl/licenses/asm-9.2.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
81a03f76019c67362299c40e0ba13405f5467bff
26 changes: 26 additions & 0 deletions libs/plugin-scanner/impl/licenses/asm-LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2012 France Télécom
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions libs/plugin-scanner/impl/licenses/asm-NOTICE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

8 changes: 8 additions & 0 deletions libs/plugin-scanner/impl/licenses/jackson-LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This copy of Jackson JSON processor streaming parser/generator is licensed under the
Apache (Software) License, version 2.0 ("the License").
See the License for details about distribution rights, and the
specific rights regarding derivate works.

You may obtain a copy of the License at:

http://www.apache.org/licenses/LICENSE-2.0
20 changes: 20 additions & 0 deletions libs/plugin-scanner/impl/licenses/jackson-NOTICE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Jackson JSON processor

Jackson is a high-performance, Free/Open Source JSON processing library.
It was originally written by Tatu Saloranta (tatu.saloranta@iki.fi), and has
been in development since 2007.
It is currently developed by a community of developers, as well as supported
commercially by FasterXML.com.

## Licensing

Jackson core and extension components may licensed under different licenses.
To find the details that apply to this artifact see the accompanying LICENSE file.
For more information, including possible other licensing options, contact
FasterXML.com (http://fasterxml.com).

## Credits

A list of contributors may be found from CREDITS file, which is included
in some artifacts (usually source distributions); but is always available
from the source code management (SCM) system project uses.
27 changes: 27 additions & 0 deletions libs/plugin-scanner/impl/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -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.
*/

module org.elasticsearch.plugin.scanner.impl {
requires org.objectweb.asm;
requires com.fasterxml.jackson.core;
requires com.fasterxml.jackson.databind;
requires com.fasterxml.jackson.annotation;

requires org.elasticsearch.logging;
requires org.apache.logging.log4j;
requires org.elasticsearch.plugin.api;
requires org.elasticsearch.base;

requires org.elasticsearch.plugin.scanner;

exports org.elasticsearch.plugin.scanner.impl to org.elasticsearch.plugin.scanner;

provides org.elasticsearch.plugin.scanner.spi.StablePluginRegistryProvider
with
org.elasticsearch.plugin.scanner.impl.StablePluginRegistryProviderImpl;
}
Loading