Skip to content
Snippets Groups Projects
Commit 775a4184 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

- Fix packaging (standlone and plugin)

- Fix 'mvn -Prun' test
- Use ServiceLocator and beans resolution issue
parent a08d7dce
No related branches found
No related tags found
No related merge requests found
......@@ -51,10 +51,12 @@ public class ServiceLocator implements Closeable {
private BeanFactory beanFactory = null;
protected ServiceLocator() {
init();
}
protected ServiceLocator(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
init();
}
public void init() {
......
......@@ -50,26 +50,6 @@
<artifactId>javax.websocket-api</artifactId>
</dependency>
<!--dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
</dependency-->
<dependency>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-config</artifactId>
......
......@@ -48,6 +48,9 @@ public class BeanFactory implements Closeable{
beansCache = new HashMap<>();
beansLoader = ServiceLoader.load(Bean.class);
beansClassMap = new HashMap<>();
if (log.isTraceEnabled()) {
log.trace("Creating new BeanFactory...");
}
}
public <S extends Bean> S getBean(Class<S> clazz) {
......
......@@ -40,6 +40,12 @@
<groupId>org.duniter</groupId>
<artifactId>duniter4j-core-client</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- LOGGING DEPENDENCIES - SLF4J -->
<dependency>
......@@ -55,6 +61,7 @@
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<optional>true</optional>
<scope>runtime</scope>
</dependency>
<!-- Elastic Search -->
......@@ -72,10 +79,17 @@
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<exclusions>
<exclusion>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Unit test -->
......@@ -166,24 +180,6 @@
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<silent>true</silent>
<includeScope>runtime</includeScope>
<excludeScope>test</excludeScope>
<excludeGroupIds>org.elasticsearch,net.java.dev.jna,com.google.guava</excludeGroupIds>
<excludeArtifactIds>elasticsearch,jna,guava</excludeArtifactIds>
</configuration>
</execution>
<execution>
<id>unpack-dependencies</id>
<goals>
......@@ -199,29 +195,70 @@
<type>zip</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}</outputDirectory>
<outputDirectory>${project.build.directory}/</outputDirectory>
<silent>true</silent>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>download-attachment-mapper-plugin</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- download file -->
<get src="https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/mapper-attachments/${elasticsearch.version}/mapper-attachments-${elasticsearch.version}.zip"
dest="${project.build.directory}/mapper-attachments-${elasticsearch.version}.zip"
verbose="false"
usetimestamp="true"/>
<unzip src="${project.build.directory}/mapper-attachments-${elasticsearch.version}.zip"
dest="${project.build.directory}/elasticsearch-${elasticsearch.version}/plugins/mapper-attachments"
overwrite="true">
</unzip>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assembly-standalone</id>
<id>assembly-plugin</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<attach>true</attach>
<appendAssemblyId>false</appendAssemblyId>
<finalName>${bundlePrefix}</finalName>
<descriptors>
<descriptor>
${basedir}/src/main/assembly/plugin.xml
</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>assembly-standalone</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<attach>true</attach>
<finalName>${bundlePrefix}</finalName>
<descriptors>
<descriptor>
${basedir}/src/main/assembly/standalone.xml
</descriptor>
......@@ -270,6 +307,140 @@
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-dependencies</id>
<goals>
<goal>unpack</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.elasticsearch.distribution.zip</groupId>
<artifactId>elasticsearch</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/</outputDirectory>
<silent>true</silent>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>initialize</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/es-home/plugins/${project.artifactId}</outputDirectory>
<excludeArtifactIds>jna,jackson-core,log4j,elasticsearch</excludeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<executions>
<execution>
<id>download-attachment-mapper-plugin</id>
<phase>initialize</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<copy todir="${project.build.directory}/es-home">
<fileset dir="${project.build.directory}/elasticsearch-${elasticsearch.version}">
</fileset>
</copy>
<chmod perm="u+x">
<fileset dir="${project.build.directory}/es-home/bin">
<include name="elasticsearch"/>
</fileset>
</chmod>
<copy todir="${project.build.directory}/es-home/config" overwrite="true">
<fileset dir="${basedir}/src/main/assembly/config">
</fileset>
</copy>
<!-- download attachment plugin -->
<get src="https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/mapper-attachments/${elasticsearch.version}/mapper-attachments-${elasticsearch.version}.zip"
dest="${project.build.directory}/mapper-attachments-${elasticsearch.version}.zip"
verbose="false"
usetimestamp="true"/>
<unzip src="${project.build.directory}/mapper-attachments-${elasticsearch.version}.zip"
dest="${project.build.directory}/es-home/plugins/mapper-attachments"
overwrite="true">
</unzip>
<copy todir="${project.build.directory}/es-home/plugins/${project.artifactId}">
<fileset dir="${project.build.directory}/classes">
<include name="plugin-descriptor.properties"/>
<include name="plugin-security.policy"/>
</fileset>
</copy>
<!-- remove redundant lib in duniter plugin -->
<ac:for param="file" xmlns:ac="antlib:net.sf.antcontrib">
<path>
<fileset dir="${project.build.directory}/es-home/plugins/${project.artifactId}">
<include name="**/*.jar"/>
</fileset>
</path>
<sequential>
<local name="filename" />
<basename property="filename" file="@{file}"/>
<ac:if>
<available file="${project.build.directory}/es-home/lib/${filename}"/>
<then>
<!--echo message="Remove lib from plugin: ${filename}"/-->
<delete file="${project.build.directory}/es-home/plugins/${project.artifactId}/${filename}"/>
</then>
</ac:if>
</sequential>
</ac:for>
<delete>
<fileset dir="${project.build.directory}/es-home/plugins/${project.artifactId}">
<include name="guava-*.jar"/>
</fileset>
</delete>
<copy todir="${project.build.directory}/es-home/plugins/${project.artifactId}">
<fileset dir="${project.build.directory}">
<include name="${project.artifactId}-${project.version}.${project.packaging}"/>
</fileset>
</copy>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
......@@ -277,23 +448,12 @@
<execution>
<id>run</id>
<goals>
<goal>java</goal>
<goal>exec</goal>
</goals>
<phase>compile</phase>
<configuration>
<mainClass>${exec.mainClass}</mainClass>
<classpathScope>${exec.classpathScope}</classpathScope>
<commandlineArgs>start</commandlineArgs>
<systemProperties>
<property>
<key>duniter4j-elasticsearch.config</key>
<value>${duniter4j-elasticsearch.config}</value>
</property>
<property>
<key>es.path.home</key>
<value>${basedir}/src/test/es-home</value>
</property>
</systemProperties>
<executable>${project.build.directory}/es-home/bin/elasticsearch</executable>
<workingDirectory>${basedir}/src/test/es-home</workingDirectory>
</configuration>
</execution>
</executions>
......@@ -309,9 +469,9 @@
<duniter4j.basedir>${project.build.directory}</duniter4j.basedir>
<duniter4j.plugins.directory>${basedir}}/src/test/es-home/plugins</duniter4j.plugins.directory>
<es.http.cors.allow-origin>*</es.http.cors.allow-origin>
<exec.args>
start index --host metab.ucoin.fr --port 9201
</exec.args>
<!--exec.args>
start index - -host metab.ucoin.fr - -port 9201
</exec.args-->
</properties>
</profile>
</profiles>
......
# you can override this using by setting a system property, for example -Des.logger.level=DEBUG
es.logger.level: INFO
rootLogger: ${es.logger.level}, console, file
logger:
# log action execution errors for easier debugging
action: DEBUG
# deprecation logging, turn to DEBUG to see them
deprecation: INFO, deprecation_log_file
# reduce the logging for aws, too much is logged under the default INFO
com.amazonaws: WARN
# aws will try to do some sketchy JMX stuff, but its not needed.
com.amazonaws.jmx.SdkMBeanRegistrySupport: ERROR
com.amazonaws.metrics.AwsSdkMetrics: ERROR
org.apache.http: INFO
org.duniter: TRACE
# gateway
#gateway: DEBUG
#index.gateway: DEBUG
# peer shard recovery
#indices.recovery: DEBUG
# discovery
#discovery: TRACE
index.search.slowlog: TRACE, index_search_slow_log_file
index.indexing.slowlog: TRACE, index_indexing_slow_log_file
additivity:
index.search.slowlog: false
index.indexing.slowlog: false
deprecation: false
appender:
console:
type: console
layout:
type: consolePattern
conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"
file:
type: dailyRollingFile
file: ${path.logs}/${cluster.name}.log
datePattern: "'.'yyyy-MM-dd"
layout:
type: pattern
conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %.10000m%n"
# Use the following log4j-extras RollingFileAppender to enable gzip compression of log files.
# For more information see https://logging.apache.org/log4j/extras/apidocs/org/apache/log4j/rolling/RollingFileAppender.html
#file:
#type: extrasRollingFile
#file: ${path.logs}/${cluster.name}.log
#rollingPolicy: timeBased
#rollingPolicy.FileNamePattern: ${path.logs}/${cluster.name}.log.%d{yyyy-MM-dd}.gz
#layout:
#type: pattern
#conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"
deprecation_log_file:
type: dailyRollingFile
file: ${path.logs}/${cluster.name}_deprecation.log
datePattern: "'.'yyyy-MM-dd"
layout:
type: pattern
conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"
index_search_slow_log_file:
type: dailyRollingFile
file: ${path.logs}/${cluster.name}_index_search_slowlog.log
datePattern: "'.'yyyy-MM-dd"
layout:
type: pattern
conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"
index_indexing_slow_log_file:
type: dailyRollingFile
file: ${path.logs}/${cluster.name}_index_indexing_slowlog.log
datePattern: "'.'yyyy-MM-dd"
layout:
type: pattern
conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"
......@@ -2,6 +2,7 @@
<assembly>
<id>plugin</id>
<formats>
<format>zip</format>
</formats>
......@@ -16,6 +17,8 @@
<excludes>
<exclude>org.elasticsearch:elasticsearch</exclude>
<exclude>net.java.dev.jna:jna</exclude>
<exclude>com.fasterxml.jackson.core:jackson-core</exclude>
<exclude>log4j:log4j</exclude>
</excludes>
</dependencySet>
</dependencySets>
......@@ -23,7 +26,7 @@
<fileSets>
<fileSet>
<includes>
<include>LICENSE*</include>
<include>LICENSE</include>
</includes>
</fileSet>
......
......@@ -38,26 +38,37 @@
<outputDirectory/>
<excludes>
<exclude>config/elasticsearch.yml</exclude>
<exclude>config/logging.yml</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>target/elasticsearch-${elasticsearch.version}/config</directory>
<outputDirectory>config/old</outputDirectory>
<includes>
<include>plugin-descriptor.properties</include>
<include>plugin-security.policy</include>
</includes>
</fileSet>
<!-- default configuration file -->
<fileSet>
<directory>src/main/assembly/config</directory>
<outputDirectory>config</outputDirectory>
<includes>
<include>elasticsearch.yml</include>
<include>logging.yml</include>
</includes>
</fileSet>
<!-- mapper attachment plugin -->
<!-- mapper attachment plugin
<fileSet>
<directory>src/test/es-home</directory>
<outputDirectory/>
<directory>target/assembly</directory>
<outputDirectory>plugins</outputDirectory>
<includes>
<include>plugins/mapper-attachments/**/*.*</include>
<include>mapper-attachments-${elasticsearch.mapper-attachments.version}.zip</include>
</includes>
</fileSet>
</fileSet>-->
<fileSet>
<directory>target</directory>
......@@ -68,34 +79,33 @@
</fileSet>
<fileSet>
<directory>src/main/filtered-resources</directory>
<directory>target/classes</directory>
<outputDirectory>plugins/${project.artifactId}</outputDirectory>
<filtered>true</filtered>
<includes>
<include>plugin-descriptor.properties</include>
<include>plugin-security.policy</include>
</includes>
</fileSet>
<fileSet>
<directory>target/lib</directory>
<outputDirectory>plugins/${project.artifactId}</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
<excludes>
<exclude>guava-*.jar</exclude>
<exclude>jna-4.1.0.jar</exclude>
<exclude>jackson-core-*.jar</exclude>
</excludes>
</fileSet>
<fileSet>
<outputDirectory>plugins/${project.artifactId}</outputDirectory>
<includes>
<include>LICENSE</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>plugins/${project.artifactId}</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<useTransitiveFiltering>true</useTransitiveFiltering>
<excludes>
<exclude>org.elasticsearch:elasticsearch</exclude>
<exclude>net.java.dev.jna:jna</exclude>
<exclude>com.fasterxml.jackson.core:jackson-core</exclude>
<exclude>log4j:log4j</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
name=duniter4j-elasticsearch
description=${project.description}
version=1.0
description=Plugin for Duniter node indexation
version=${project.version}
site=false
jvm=true
classname=org.duniter.elasticsearch.Plugin
java.version=1.7
elasticsearch.version=2.3.3
isolated=true
\ No newline at end of file
isolated=true
......@@ -40,17 +40,13 @@ import org.duniter.core.client.service.local.PeerServiceImpl;
import org.duniter.core.exception.TechnicalException;
import org.duniter.core.service.CryptoService;
import org.duniter.core.service.Ed25519CryptoServiceImpl;
import org.duniter.elasticsearch.PluginSettings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.Provider;
import org.elasticsearch.common.inject.Singleton;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory;
import java.io.IOException;
import java.util.HashMap;
import java.util.ServiceLoader;
@Singleton
public class ServiceLocator
......@@ -58,6 +54,7 @@ public class ServiceLocator
{
private static final ESLogger logger = ESLoggerFactory.getLogger(ServiceLocator.class.getName());
private static BeanFactory beanFactory = null;
@Inject
public ServiceLocator(Injector injector) {
......@@ -65,8 +62,7 @@ public class ServiceLocator
if (logger.isDebugEnabled()) {
logger.debug("Starting Duniter4j client ServiceLocator...");
}
//setBeanFactory(new BeanFactory(injector));
setBeanFactory(createBeanFactory());
setBeanFactory(getOrCreateBeanFactory());
org.duniter.core.client.service.ServiceLocator.setInstance(this);
}
......@@ -84,20 +80,11 @@ public class ServiceLocator
/* -- Internal methods -- */
class BeanFactory extends org.duniter.core.beans.BeanFactory{
private final Injector injector;
public BeanFactory(Injector injector) {
super();
this.injector = injector;
protected static BeanFactory getOrCreateBeanFactory() {
if (beanFactory != null) {
return beanFactory;
}
public <S extends Bean> S newBean(Class<S> clazz) {
return injector.getInstance(clazz);
}
}
protected static org.duniter.core.beans.BeanFactory createBeanFactory() {
org.duniter.core.beans.BeanFactory beanFactory = new org.duniter.core.beans.BeanFactory()
beanFactory = org.duniter.core.client.service.ServiceLocator.instance().getBeanFactory()
.bind(BlockchainRemoteService.class, BlockchainRemoteServiceImpl.class)
.bind(NetworkRemoteService.class, NetworkRemoteServiceImpl.class)
.bind(WotRemoteService.class, WotRemoteServiceImpl.class)
......@@ -115,13 +102,15 @@ public class ServiceLocator
public static class Provider<T extends Bean> implements org.elasticsearch.common.inject.Provider<T> {
private final Class<T> clazz;
private final BeanFactory beanFactory;
public Provider(Class<T> clazz) {
this.clazz = clazz;
this.beanFactory = getOrCreateBeanFactory();
}
public T get() {
return ServiceLocator.instance().getBean(clazz);
return beanFactory.getBean(clazz);
}
}
}
......@@ -68,6 +68,9 @@
<!-- Could be overriding in modules -->
<maven.jar.main.class/>
<!-- skip javadoc for now - FIXME fix java 8 javadoc errors -->
<maven.javadoc.skip>true</maven.javadoc.skip>
<!-- distribution management -->
<distribution.site.id>eis-public-reports</distribution.site.id>
<distribution.site.host>server.e-is.pro:22</distribution.site.host>
......@@ -419,6 +422,18 @@
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
</plugin>
<plugin>
<artifactId>maven-changes-plugin</artifactId>
<version>2.11</version>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment