diff --git a/duniter4j-cmd/lib/j-text-utils-0.3.3.jar b/duniter4j-client/lib/j-text-utils-0.3.3.jar similarity index 100% rename from duniter4j-cmd/lib/j-text-utils-0.3.3.jar rename to duniter4j-client/lib/j-text-utils-0.3.3.jar diff --git a/duniter4j-cmd/lib/j-text-utils-0.3.3.pom b/duniter4j-client/lib/j-text-utils-0.3.3.pom similarity index 100% rename from duniter4j-cmd/lib/j-text-utils-0.3.3.pom rename to duniter4j-client/lib/j-text-utils-0.3.3.pom diff --git a/duniter4j-client/pom.xml b/duniter4j-client/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..4a32116a5a1f76eef0813080e32a0b8766615051 --- /dev/null +++ b/duniter4j-client/pom.xml @@ -0,0 +1,628 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>duniter4j</artifactId> + <groupId>org.duniter</groupId> + <version>0.9.2-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>duniter4j-client</artifactId> + <name>Duniter4j :: Client</name> + + <properties> + <jTextUtilsVersion>0.3.3</jTextUtilsVersion> + <opencsvVersion>2.3</opencsvVersion> + + <!-- i18n configuration --> + <i18n.bundleOutputName>duniter4j-client-i18n</i18n.bundleOutputName> + <i18n.bundleCsvFile>${i18n.bundleOutputName}.csv</i18n.bundleCsvFile> + + <maven.jar.main.class> + fr.duniter.client.Main + </maven.jar.main.class> + + <bundlePrefix>duniter4j-client-${project.version}</bundlePrefix> + + <!-- Default log file path (used for development) --> + <duniter4j.log.file>duniter4j-client-${project.version}.log</duniter4j.log.file> + + </properties> + + <repositories> + <repository> + <id>d-maven</id> + <url>https://github.com/neilpanchal/j-text-utils/tree/master/repo</url> + </repository> + </repositories> + + <dependencies> + <dependency> + <groupId>org.duniter</groupId> + <artifactId>duniter4j-core-client</artifactId> + <version>${project.version}</version> + </dependency> + + <!-- logging --> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </dependency> + + <dependency> + <groupId>com.beust</groupId> + <artifactId>jcommander</artifactId> + <version>1.60</version> + </dependency> + + <dependency> + <groupId>dnl.utils</groupId> + <artifactId>j-text-utils</artifactId> + <version>${jTextUtilsVersion}</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.6</version> + </dependency> + + <!-- for CSV network output --> + <dependency> + <groupId>net.sf.opencsv</groupId> + <artifactId>opencsv</artifactId> + <version>${opencsvVersion}</version> + </dependency> + + <dependency> + <groupId>org.jline</groupId> + <artifactId>jline</artifactId> + <version>3.2.0</version> + </dependency> + </dependencies> + + <build> + <resources> + <resource> + <directory>src/main/filtered-resources</directory> + <filtering>true</filtering> + <includes> + <include>*.config</include> + <include>**/*.properties</include> + </includes> + </resource> + <resource> + <directory>src/main/resources</directory> + <includes> + <include>**/*</include> + </includes> + </resource> + </resources> + + <plugins> + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + <executions> + <execution> + <id>generate-directories</id> + <phase>validate</phase> + <goals> + <goal>run</goal> + </goals> + <configuration> + <target> + <mkdir dir="${maven.gen.dir}/java/"/> + </target> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.nuiton.i18n</groupId> + <artifactId>i18n-maven-plugin</artifactId> + <executions> + <execution> + <id>scan-sources</id> + <configuration> + <entries> + <entry> + <basedir>${maven.gen.dir}/java/</basedir> + </entry> + <entry> + <specificGoal>parserValidation</specificGoal> + <basedir>${maven.src.dir}/main/java/</basedir> + <includes> + <param>**/**-validation.xml</param> + </includes> + </entry> + </entries> + </configuration> + <goals> + <goal>parserJava</goal> + <goal>parserValidation</goal> + <goal>gen</goal> + </goals> + </execution> + <execution> + <id>make-bundle</id> + <goals> + <goal>bundle</goal> + <goal>generate-csv-bundle</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifest> + <addDefaultImplementationEntries>true</addDefaultImplementationEntries> + <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> + <useUniqueVersions>false</useUniqueVersions> + <addClasspath>true</addClasspath> + <classpathPrefix>./lib/</classpathPrefix> + <mainClass>${maven.jar.main.class}</mainClass> + </manifest> + </archive> + </configuration> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>install-missing-libs</id> + <activation> + <file> + <missing>${settings.localRepository}/dnl/utils/j-text-utils/${jTextUtilsVersion}/j-text-utils-${jTextUtilsVersion}.jar</missing> + </file> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-install-plugin</artifactId> + <version>2.5.2</version> + <executions> + <execution> + <id>installing j-text-utils.jar</id> + <phase>initialize</phase> + <goals> + <goal>install-file</goal> + </goals> + <configuration> + <groupId>dnl.utils</groupId> + <artifactId>j-text-utils</artifactId> + <version>${jTextUtilsVersion}</version> + <packaging>jar</packaging> + <file>${project.basedir}/lib/j-text-utils-${jTextUtilsVersion}.jar</file> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + <executions> + <execution> + <id>enforce-dependencies-exists</id> + <phase>generate-sources</phase> + <goals> + <goal>run</goal> + </goals> + <configuration> + <target> + + <condition property="displayMessage"> + <and> + <not><available file="${project.basedir}/.maven/install.log" /></not> + <!-- do not failed here if performRelease --> + <isfalse value="${performRelease}" /> + </and> + </condition> + <property name="installSuccessMessage">* + ************************************************************************* + * + * IMPORTANT: + * + * Missing lib dependencies successfully installed on [${settings.localRepository}] + * You should now re-run the build. + * This message will NOT appear again + * + ************************************************************************* + </property> + + <echo file="${project.basedir}/.maven/install.log">${installSuccessMessage}</echo> + + <fail message="${installSuccessMessage}" > + <condition> + <istrue value="${displayMessage}"/> + </condition> + </fail> + </target> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + + <profile> + <id>use-installed-libs</id> + <activation> + <file> + <exists>${settings.localRepository}/dnl/utils/j-text-utils/${jTextUtilsVersion}/j-text-utils-${jTextUtilsVersion}.jar</exists> + </file> + </activation> + <dependencies> + <dependency> + <groupId>dnl.utils</groupId> + <artifactId>j-text-utils</artifactId> + <version>${jTextUtilsVersion}</version> + </dependency> + </dependencies> + </profile> + + <profile> + <id>add-release-properties</id> + <activation> + <property> + <name>performRelease</name> + <value>true</value> + </property> + </activation> + <properties> + <duniter4j.log.file>$\{duniter4j.log.file\}</duniter4j.log.file> + </properties> + </profile> + + <profile> + <id>default-bundle</id> + <activation> + <property> + <name>performRelease</name> + <value>true</value> + </property> + </activation> + <build> + <defaultGoal>package</defaultGoal> + <plugins> + + <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> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <executions> + <execution> + <id>assembly-standalone</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <attach>true</attach> + <descriptors> + <descriptor> + src/main/assembly/standalone.xml + </descriptor> + <descriptor> + src/main/assembly/i18n.xml + </descriptor> + </descriptors> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + + <profile> + <id>linux-x64-bundle</id> + <activation> + <property> + <name>performFullRelease64</name> + <value>true</value> + </property> + </activation> + <build> + <defaultGoal>package</defaultGoal> + <plugins> + + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>get-linux-x64-jre</id> + <phase>prepare-package</phase> + <goals> + <goal>unpack</goal> + </goals> + <configuration> + <outputDirectory> + ${project.build.directory}/jre-linux-x64 + </outputDirectory> + <artifactItems> + <artifactItem> + <groupId>com.oracle</groupId> + <artifactId>jre</artifactId> + <version>${jreVersion}</version> + <type>zip</type> + <classifier>linux-x64</classifier> + </artifactItem> + </artifactItems> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <configuration> + <finalName>${bundlePrefix}</finalName> + </configuration> + <executions> + <execution> + <id>assembly-full-linux-x64</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <attach>false</attach> + <descriptors> + <descriptor> + src/main/assembly/full-linux-x64.xml + </descriptor> + </descriptors> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + + <profile> + <id>linux-i586-bundle</id> + <activation> + <property> + <name>performFullRelease</name> + <value>true</value> + </property> + </activation> + <build> + <defaultGoal>package</defaultGoal> + <plugins> + + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>get-linux-i586-jre</id> + <phase>prepare-package</phase> + <goals> + <goal>unpack</goal> + </goals> + <configuration> + <outputDirectory> + ${project.build.directory}/jre-linux-i586 + </outputDirectory> + <artifactItems> + <artifactItem> + <groupId>com.oracle</groupId> + <artifactId>jre</artifactId> + <version>${jreVersion}</version> + <type>zip</type> + <classifier>linux-i586</classifier> + </artifactItem> + </artifactItems> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <configuration> + <finalName>${bundlePrefix}</finalName> + </configuration> + <executions> + <execution> + <id>assembly-full-linux-i586</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <attach>false</attach> + <descriptors> + <descriptor> + src/main/assembly/full-linux-i586.xml + </descriptor> + </descriptors> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + + <profile> + <id>windows-i586-bundle</id> + <activation> + <property> + <name>performFullRelease</name> + <value>true</value> + </property> + </activation> + <build> + <defaultGoal>package</defaultGoal> + <plugins> + + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>get-windows-i586-jre</id> + <phase>prepare-package</phase> + <goals> + <goal>unpack</goal> + </goals> + <configuration> + <outputDirectory> + ${project.build.directory}/jre-windows-i586 + </outputDirectory> + <artifactItems> + <artifactItem> + <groupId>com.oracle</groupId> + <artifactId>jre</artifactId> + <version>${jreVersion}</version> + <type>zip</type> + <classifier>windows-i586</classifier> + </artifactItem> + </artifactItems> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <configuration> + <finalName>${bundlePrefix}</finalName> + </configuration> + <executions> + <execution> + <id>assembly-full-windows-i586</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <attach>false</attach> + <descriptors> + <descriptor> + src/main/assembly/full-windows-i586.xml + </descriptor> + </descriptors> + </configuration> + </execution> + + <!-- Ifremer + FIXME : uncomment when stable release, for production + <execution> + <id>assembly-full-windows-i586-ifremer</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <attach>false</attach> + <descriptors> + <descriptor> + src/main/assembly/prod/full-windows-i586-ifremer.xml + </descriptor> + </descriptors> + </configuration> + </execution> + --> + </executions> + </plugin> + </plugins> + </build> + </profile> + + <profile> + <id>windows-x64-bundle</id> + <activation> + <property> + <name>performFullRelease</name> + <value>true</value> + </property> + </activation> + <build> + <defaultGoal>package</defaultGoal> + <plugins> + + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>get-windows-x64-jre</id> + <phase>prepare-package</phase> + <goals> + <goal>unpack</goal> + </goals> + <configuration> + <outputDirectory> + ${project.build.directory}/jre-windows-x64 + </outputDirectory> + <artifactItems> + <artifactItem> + <groupId>com.oracle</groupId> + <artifactId>jre</artifactId> + <version>${jreVersion}</version> + <type>zip</type> + <classifier>windows-x64</classifier> + </artifactItem> + </artifactItems> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <configuration> + <finalName>${bundlePrefix}</finalName> + </configuration> + <executions> + <execution> + <id>assembly-full-windows-x64</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <attach>false</attach> + <descriptors> + <descriptor> + src/main/assembly/full-windows-x64.xml + </descriptor> + </descriptors> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> \ No newline at end of file diff --git a/duniter4j-client/src/main/assembly/full-linux-component.xml b/duniter4j-client/src/main/assembly/full-linux-component.xml new file mode 100644 index 0000000000000000000000000000000000000000..08e5daad0014c07696a1819d44df9d7dfaad2724 --- /dev/null +++ b/duniter4j-client/src/main/assembly/full-linux-component.xml @@ -0,0 +1,89 @@ +<?xml version="1.0" encoding="UTF-8"?> + + +<component + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/component/1.1.2" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/component/1.1.2 http://maven.apache.org/xsd/component-1.1.2.xsd"> + + <fileSets> + + <fileSet> + <includes> + <include>LICENSE*</include> + </includes> + </fileSet> + + <!-- Duniter4j component --> + <fileSet> + <directory>target</directory> + <outputDirectory>duniter4j</outputDirectory> + <includes> + <include>${project.build.finalName}.${project.packaging}</include> + </includes> + </fileSet> + + <fileSet> + <directory>target/lib</directory> + <outputDirectory>duniter4j/lib</outputDirectory> + <includes> + <include>*.jar</include> + </includes> + <excludes> + <exclude>junit-*.jar</exclude> + </excludes> + </fileSet> + + <fileSet> + <directory>src/main/assembly/min</directory> + <outputDirectory/> + <filtered>true</filtered> + <fileMode>0755</fileMode> + <includes> + <include>*.sh</include> + </includes> + </fileSet> + + <fileSet> + <directory>src/main/assembly/min</directory> + <outputDirectory>duniter4j</outputDirectory> + <filtered>true</filtered> + <includes> + <include>*</include> + </includes> + <excludes> + <exclude>*.sh</exclude> + <exclude>*.bat</exclude> + </excludes> + </fileSet> + + <fileSet> + <directory>src/main/assembly/min</directory> + <outputDirectory>i18n</outputDirectory> + <filtered>true</filtered> + <includes> + <include>version.appup</include> + </includes> + </fileSet> + + <!-- I18N component --> + <fileSet> + <directory>target/classes/META-INF</directory> + <outputDirectory>i18n</outputDirectory> + <includes> + <include>duniter4j-client-i18n*.properties</include> + <include>duniter4j-client-i18n*.csv</include> + </includes> + </fileSet> + + <fileSet> + <directory>src/main/assembly/min</directory> + <outputDirectory>i18n</outputDirectory> + <filtered>true</filtered> + <includes> + <include>version.appup</include> + </includes> + </fileSet> + + </fileSets> +</component> diff --git a/duniter4j-client/src/main/assembly/full-linux-i586.xml b/duniter4j-client/src/main/assembly/full-linux-i586.xml new file mode 100644 index 0000000000000000000000000000000000000000..02d734ab8cfa18603c2bfe19df5d8af551790534 --- /dev/null +++ b/duniter4j-client/src/main/assembly/full-linux-i586.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> + + +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> + + <id>full-linux-i586</id> + <formats> + <format>zip</format> + </formats> + + <componentDescriptors> + <componentDescriptor> + src/main/assembly/full-linux-component.xml + </componentDescriptor> + </componentDescriptors> + + <fileSets> + + <fileSet> + <directory>${project.build.directory}/jre-linux-i586/jre</directory> + <outputDirectory>jre</outputDirectory> + <includes> + <include>**/*</include> + </includes> + </fileSet> + + </fileSets> + +</assembly> diff --git a/duniter4j-client/src/main/assembly/full-linux-x64.xml b/duniter4j-client/src/main/assembly/full-linux-x64.xml new file mode 100644 index 0000000000000000000000000000000000000000..6a3ded846f3f304b169dd9fe5db44628a146f8d3 --- /dev/null +++ b/duniter4j-client/src/main/assembly/full-linux-x64.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> + + + + +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> + + <id>full-linux-x64</id> + <formats> + <format>zip</format> + </formats> + + <componentDescriptors> + <componentDescriptor> + src/main/assembly/full-linux-component.xml + </componentDescriptor> + </componentDescriptors> + + <fileSets> + + <fileSet> + <directory>${project.build.directory}/jre-linux-x64/jre</directory> + <outputDirectory>/jre</outputDirectory> + <includes> + <include>**/*</include> + </includes> + </fileSet> + + </fileSets> + +</assembly> diff --git a/duniter4j-client/src/main/assembly/full-windows-component.xml b/duniter4j-client/src/main/assembly/full-windows-component.xml new file mode 100644 index 0000000000000000000000000000000000000000..42900d5f940cfd0bf0ef8992eb3c7486a40ec25f --- /dev/null +++ b/duniter4j-client/src/main/assembly/full-windows-component.xml @@ -0,0 +1,81 @@ +<?xml version="1.0" encoding="UTF-8"?> + + + +<component + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/component/1.1.2" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/component/1.1.2 http://maven.apache.org/xsd/component-1.1.2.xsd"> + + <fileSets> + + <fileSet> + <directory>src/main/assembly/min</directory> + <outputDirectory/> + <filtered>true</filtered> + <fileMode>0755</fileMode> + <includes> + <include>*.bat</include> + </includes> + </fileSet> + + <fileSet> + <includes> + <include>LICENSE*</include> + </includes> + </fileSet> + + <!-- Reef DB component --> + <fileSet> + <directory>target</directory> + <outputDirectory>duniter4j</outputDirectory> + <includes> + <include>${project.build.finalName}.${project.packaging}</include> + </includes> + </fileSet> + + <fileSet> + <directory>target/lib</directory> + <outputDirectory>duniter4j/lib</outputDirectory> + <includes> + <include>*.jar</include> + </includes> + <excludes> + <exclude>junit-*.jar</exclude> + </excludes> + </fileSet> + + <fileSet> + <directory>src/main/assembly/min</directory> + <outputDirectory>duniter4j</outputDirectory> + <filtered>true</filtered> + <includes> + <include>*</include> + </includes> + <excludes> + <exclude>*.sh</exclude> + <exclude>*.bat</exclude> + </excludes> + </fileSet> + + <!-- I18N component --> + <fileSet> + <directory>target/classes/META-INF</directory> + <outputDirectory>i18n</outputDirectory> + <includes> + <include>duniter4j-client-i18n*.properties</include> + <include>duniter4j-client-i18n*.csv</include> + </includes> + </fileSet> + + <fileSet> + <directory>src/main/assembly/min</directory> + <outputDirectory>i18n</outputDirectory> + <filtered>true</filtered> + <includes> + <include>version.appup</include> + </includes> + </fileSet> + + </fileSets> +</component> diff --git a/duniter4j-client/src/main/assembly/full-windows-i586.xml b/duniter4j-client/src/main/assembly/full-windows-i586.xml new file mode 100644 index 0000000000000000000000000000000000000000..165eafbc414ba72068e01c8942e7076320214e4a --- /dev/null +++ b/duniter4j-client/src/main/assembly/full-windows-i586.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> + + + +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> + + <id>full-windows-i586</id> + <formats> + <format>zip</format> + </formats> + + <componentDescriptors> + <componentDescriptor> + src/main/assembly/full-windows-component.xml + </componentDescriptor> + </componentDescriptors> + + <fileSets> + + <fileSet> + <directory>${project.build.directory}/jre-windows-i586/jre</directory> + <outputDirectory>jre</outputDirectory> + <includes> + <include>**/*</include> + </includes> + </fileSet> + + </fileSets> + +</assembly> diff --git a/duniter4j-client/src/main/assembly/full-windows-x64.xml b/duniter4j-client/src/main/assembly/full-windows-x64.xml new file mode 100644 index 0000000000000000000000000000000000000000..de4542eec6c67e38b7b2c3ab9e4cb31f5752e6e0 --- /dev/null +++ b/duniter4j-client/src/main/assembly/full-windows-x64.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> + + + +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> + + <id>full-windows-x64</id> + <formats> + <format>zip</format> + </formats> + + <componentDescriptors> + <componentDescriptor> + src/main/assembly/full-windows-component.xml + </componentDescriptor> + </componentDescriptors> + + <fileSets> + + <fileSet> + <directory>${project.build.directory}/jre-windows-x64/jre</directory> + <outputDirectory>jre</outputDirectory> + <includes> + <include>**/*</include> + </includes> + </fileSet> + + </fileSets> +</assembly> diff --git a/duniter4j-client/src/main/assembly/i18n.xml b/duniter4j-client/src/main/assembly/i18n.xml new file mode 100644 index 0000000000000000000000000000000000000000..e85717edaf31521cb62eb6f3e841551f09e41870 --- /dev/null +++ b/duniter4j-client/src/main/assembly/i18n.xml @@ -0,0 +1,32 @@ + +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> + <id>i18n</id> + <formats> + <format>zip</format> + </formats> + + <fileSets> + + <fileSet> + <directory>target/classes/META-INF</directory> + <outputDirectory/> + <includes> + <include>duniter4j-client-i18n*.properties</include> + <include>duniter4j-client-i18n*.csv</include> + </includes> + </fileSet> + + <fileSet> + <directory>src/main/assembly/min</directory> + <outputDirectory/> + <filtered>true</filtered> + <includes> + <include>version.appup</include> + </includes> + </fileSet> + + </fileSets> +</assembly> diff --git a/duniter4j-client/src/main/assembly/min/README.txt b/duniter4j-client/src/main/assembly/min/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..fbc83393918d6af311cc756051f6479d431aafcc --- /dev/null +++ b/duniter4j-client/src/main/assembly/min/README.txt @@ -0,0 +1,23 @@ +----------------------------- +-- README Duniter4j Client -- +----------------------------- + +# Linux + +./duniter4j.sh <command> <options> + +# Windows + +duniter4j.bat <command> <options> + + +Need HELP ? +----------- + +# Linux + +./duniter4j.sh --help + +# Windows + +duniter4j.bar --help \ No newline at end of file diff --git a/duniter4j-client/src/main/assembly/min/duniter4j-client.config b/duniter4j-client/src/main/assembly/min/duniter4j-client.config new file mode 100644 index 0000000000000000000000000000000000000000..1b8b35f3c1331dca1badbe9277af2a0e80c325b2 --- /dev/null +++ b/duniter4j-client/src/main/assembly/min/duniter4j-client.config @@ -0,0 +1 @@ +# Duniter4j Configuration diff --git a/duniter4j-client/src/main/assembly/min/duniter4j.bat b/duniter4j-client/src/main/assembly/min/duniter4j.bat new file mode 100644 index 0000000000000000000000000000000000000000..8850b60b476ede038642844312598c8a5f2f7956 --- /dev/null +++ b/duniter4j-client/src/main/assembly/min/duniter4j.bat @@ -0,0 +1,23 @@ +@echo off + +set OLDDIR=%CD% +cd /d %~dp0% + +set DUNITER4j_BASEDIR="%CD%" +set JAVA_HOME=%DUNITER4j_BASEDIR%\jre +set JAVA_COMMAND=%JAVA_HOME%\bin\java +set DUNITER4j_CONFIG_DIR=%DUNITER4j_BASEDIR%\config + +echo "Running Duniter4j Client..." +echo " basedir: %DUNITER4j_BASEDIR%" +echo " jre home: %JAVA_HOME%" + +:start + +call duniter4j\launch.bat --option duniter4j.launch.mode full --option duniter4j.basedir %DUNITER4j_BASEDIR% --option config.path %DUNITER4j_CONFIG_DIR% +if errorlevel 88 goto start + +goto quit + +:quit +cd %OLDDIR% diff --git a/duniter4j-client/src/main/assembly/min/duniter4j.sh b/duniter4j-client/src/main/assembly/min/duniter4j.sh new file mode 100644 index 0000000000000000000000000000000000000000..344b7600978c3d01a7e60a0b07d288b614201109 --- /dev/null +++ b/duniter4j-client/src/main/assembly/min/duniter4j.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +READLINK=`which readlink` +if [ -z "$READLINK" ]; then + message "Required tool 'readlink' is missing. Please install before launch \"$0\" file." + exit 1 +fi + +# ------------------------------------------------------------------ +# Ensure BASEDIR points to the directory where the soft is installed. +# ------------------------------------------------------------------ +SCRIPT_LOCATION=$0 +if [ -x "$READLINK" ]; then + while [ -L "$SCRIPT_LOCATION" ]; do + SCRIPT_LOCATION=`"$READLINK" -e "$SCRIPT_LOCATION"` + done +fi + +export APPDIR=`dirname "$SCRIPT_LOCATION"` +export JARDIR="$APPDIR/duniter4j" +export JAR="$JARDIR/${project.build.finalName}.${project.packaging}" +export I18N_DIR="$APPDIR/i18n" + +# Retrieve the JAVA installation +if [ "~$JAVA_HOME" -eq "~" ]; then + export JAVA_HOME="$APPDIR/jre" + export JAVA_COMMAND="$JAVA_HOME/bin/java" + + if [ -f "$JAVA_HOME/bin/java" ]; then + # If embedded JRE exists, make sure java is executable + chmod +x "$JAVA_COMMAND" + else + # If not Embedded JRE, use the default binary + export JAVA_COMMAND=java + fi +else + export JAVA_COMMAND="$JAVA_HOME/bin/java" +fi + +if [ -d "$HOME" ]; then + export BASEDIR="$HOME/.config/duniter4j" + export CONFIG_DIR="$BASEDIR/config" + export CONFIG_FILE="$CONFIG_DIR/duniter4j-client.config" + export LOG_FILE="$BASEDIR/logs/${project.build.finalName}.log" +else + export BASEDIR="$APPDIR" + export CONFIG_DIR="$APPDIR/config" + export CONFIG_FILE="$CONFIG_DIR/config/duniter4j-client.config" + export LOG_FILE="$APPDIR/logs/${project.build.finalName}.log" + + echo "Using base" +fi + +# Create the config dir if need +mkdir -p "$CONFIG_DIR" + +# Create the config file (if need) +if [ ! -f "$CONFIG_FILE" ]; then + echo "INFO - Initialized configuration file: $CONFIG_FILE" + cp -u $JARDIR/duniter4j-client.config $CONFIG_FILE +fi + + +cd $APPDIR + +while true; do + + $JAVA_COMMAND $JAVA_OPTS -Dduniter4j.log.file=$LOG_FILE -Dduniter4j.i18n.directory=$I18N_DIR -jar $JAR --basedir $BASEDIR --config $CONFIG_FILE $* + exitcode=$? + + if [ ! "$exitcode" -eq "130" ]; then + echo "INFO - Application stopped with exitcode: $exitcode" + fi + + ## Continue only if exitcode=88 (will restart the application) + if [ ! "$exitcode" -eq "88" ]; then + # quit now! + exit $exitcode + fi +done diff --git a/duniter4j-client/src/main/assembly/min/version.appup b/duniter4j-client/src/main/assembly/min/version.appup new file mode 100644 index 0000000000000000000000000000000000000000..f2ab45c3b0ef08a7742373cd3434573d500b3b22 --- /dev/null +++ b/duniter4j-client/src/main/assembly/min/version.appup @@ -0,0 +1 @@ +${project.version} \ No newline at end of file diff --git a/duniter4j-client/src/main/assembly/standalone.xml b/duniter4j-client/src/main/assembly/standalone.xml new file mode 100644 index 0000000000000000000000000000000000000000..8c044a15696053e36391f64a9ff82b9a2c0dbf67 --- /dev/null +++ b/duniter4j-client/src/main/assembly/standalone.xml @@ -0,0 +1,72 @@ +<?xml version="1.0" encoding="UTF-8"?> + + + +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> + <id>standalone</id> + <formats> + <format>zip</format> + </formats> + + + <fileSets> + + <fileSet> + <directory>target</directory> + <outputDirectory/> + <includes> + <include>${project.build.finalName}.${project.packaging}</include> + </includes> + </fileSet> + + <fileSet> + <directory>target/lib</directory> + <outputDirectory>lib</outputDirectory> + <includes> + <include>*.jar</include> + </includes> + <excludes> + <exclude>junit-*.jar</exclude> + </excludes> + </fileSet> + + <fileSet> + <directory>src/main/assembly/full</directory> + <outputDirectory/> + <filtered>true</filtered> + <includes> + <include>*.sh</include> + <include>*.bat</include> + </includes> + </fileSet> + + <fileSet> + <directory>src/main/assembly/min</directory> + <outputDirectory/> + <filtered>true</filtered> + <includes> + <include>version.appup</include> + </includes> + </fileSet> + + <fileSet> + <includes> + <include>README*</include> + <include>LICENSE*</include> + </includes> + </fileSet> + + + <!--add basic configuration--> + <fileSet> + <directory>src/main/assembly/min</directory> + <outputDirectory>config</outputDirectory> + <includes> + <include>duniter4j-client.config</include> + </includes> + </fileSet> + </fileSets> +</assembly> diff --git a/duniter4j-client/src/main/filtered-resources/duniter4j-client.config b/duniter4j-client/src/main/filtered-resources/duniter4j-client.config new file mode 100644 index 0000000000000000000000000000000000000000..9ad61c03358ef8203a174530c2c17c1560cf18e2 --- /dev/null +++ b/duniter4j-client/src/main/filtered-resources/duniter4j-client.config @@ -0,0 +1,11 @@ +# Static config: +duniter4j.version=${project.version} +duniter4j.inceptionYear=${project.inceptionYear} +duniter4j.organizationName=${license.organizationName} + + +duniter4j.node.host=192.168.0.5 +duniter4j.node.port=10901 + +duniter4j.node.elasticsearch.host=localhost +duniter4j.node.elasticsearch.port=9200 diff --git a/duniter4j-cmd/src/main/resources/log4j.properties b/duniter4j-client/src/main/filtered-resources/log4j.properties similarity index 73% rename from duniter4j-cmd/src/main/resources/log4j.properties rename to duniter4j-client/src/main/filtered-resources/log4j.properties index d8de0e034ef1eff28110bf44117d35019512e496..998366881a6063fc16080ec9508af9c2b2333b2b 100644 --- a/duniter4j-cmd/src/main/resources/log4j.properties +++ b/duniter4j-client/src/main/filtered-resources/log4j.properties @@ -9,7 +9,7 @@ log4j.appender.stdout.layout.ConversionPattern=%p - %m%n # File appender log4j.appender.file=org.apache.log4j.RollingFileAppender -log4j.appender.file.file=duniter4j-client.log +log4j.appender.file.file=${duniter4j.log.file} log4j.appender.file.MaxFileSize=10MB log4j.appender.file.MaxBackupIndex=4 @@ -18,12 +18,9 @@ log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %5p %c - %m%n # Duniter4j levels log4j.logger.org.duniter=INFO -#log4j.logger.org.duniter.cmd=INFO -#log4j.logger.org.duniter.core.client.service=DEBUG -#log4j.logger.org.duniter.core.client.service.local=DEBUG -#log4j.logger.org.duniter.core.client.service.bma=DEBUG log4j.logger.org.duniter.core.beans=WARN -#log4j.logger.org.duniter.core.client.service=TRACE +# Avoid warning on leaf not found (Duniter issue) +log4j.logger.org.duniter.core.client.service.local.NetworkServiceImpl=ERROR # Other frameworks levels log4j.logger.org.apache.http=ERROR diff --git a/duniter4j-cmd/src/main/java/fr/duniter/cmd/Main.java b/duniter4j-client/src/main/java/fr/duniter/client/Main.java similarity index 66% rename from duniter4j-cmd/src/main/java/fr/duniter/cmd/Main.java rename to duniter4j-client/src/main/java/fr/duniter/client/Main.java index 8dca20495513f330756052cfc7271a1bae3bcc36..ff48c43f7aebeeb8dcc8686f64f9cda1553a88cd 100644 --- a/duniter4j-cmd/src/main/java/fr/duniter/cmd/Main.java +++ b/duniter4j-client/src/main/java/fr/duniter/client/Main.java @@ -1,38 +1,69 @@ -package fr.duniter.cmd; +package fr.duniter.client; + +/* + * #%L + * Duniter4j :: Client + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; -import com.beust.jcommander.ParameterDescription; import com.beust.jcommander.ParameterException; +import com.beust.jcommander.Parameters; import com.google.common.collect.Lists; -import fr.duniter.cmd.actions.NetworkAction; -import fr.duniter.cmd.actions.TransactionAction; +import fr.duniter.client.actions.NetworkAction; +import fr.duniter.client.actions.TransactionAction; import org.apache.commons.io.FileUtils; import org.duniter.core.client.config.Configuration; +import org.duniter.core.client.config.ConfigurationOption; import org.duniter.core.client.service.ServiceLocator; import org.duniter.core.util.StringUtils; +import org.jline.terminal.Terminal; +import org.jline.terminal.TerminalBuilder; import org.nuiton.i18n.I18n; import org.nuiton.i18n.init.DefaultI18nInitializer; import org.nuiton.i18n.init.UserI18nInitializer; import java.io.File; import java.io.IOException; -import java.util.*; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; /** * Created by blavenie on 22/03/17. */ +@Parameters(resourceBundle = "i18n.duniter4j-client") public class Main { - @Parameter(names = "-debug", description = "Debug mode", arity = 1) + @Parameter(names = "-debug", description = "Debug mode", descriptionKey = "duniter4j.params.debug") private boolean debug = false; @Parameter(names = "--help", help = true) private boolean help; - @Parameter(names = "-config", description = "Configuration file path") - private String configFilename = "duniter-cmd.config"; + @Parameter(names = "--basedir", hidden = true) + private File basedir; + @Parameter(names = "--config", description = "Configuration file path", descriptionKey="duniter4j.params.config" ) + private String configFilename = "duniter-client.config"; public static void main(String ... args) { Main main = new Main(); @@ -104,7 +135,7 @@ public class Main { protected String getI18nBundleName() { - return "duniter4j-core-client-i18n"; + return "duniter4j-client-i18n"; } /* -- -- */ @@ -113,7 +144,6 @@ public class Main { * Convenience methods that could be override to initialize other configuration * * @param configFilename - * @param configArgs */ protected void initConfiguration(String configFilename) { String[] configArgs = getConfigArgs(); @@ -127,7 +157,7 @@ public class Main { // --------------------------------------------------------------------// // init i18n // --------------------------------------------------------------------// - File i18nDirectory = new File(config.getDataDirectory(), "i18n"); + File i18nDirectory = config.getI18nDirectory(); if (i18nDirectory.exists()) { // clean i18n cache FileUtils.cleanDirectory(i18nDirectory); @@ -136,13 +166,21 @@ public class Main { FileUtils.forceMkdir(i18nDirectory); if (debug) { - System.out.println("I18N directory: " + i18nDirectory); + System.out.println("INFO - I18N directory: " + i18nDirectory); } Locale i18nLocale = config.getI18nLocale(); + // Fix locale + if (i18nLocale.equals(Locale.FRENCH)) { + i18nLocale = Locale.FRANCE; + } + else if (i18nLocale.equals(Locale.ENGLISH)) { + i18nLocale = Locale.UK; + } + if (debug) { - System.out.println(String.format("Starts i18n with locale [%s] at [%s]", + System.out.println(String.format("INFO - Starts i18n with locale [%s] at [%s]", i18nLocale, i18nDirectory)); } I18n.init(new UserI18nInitializer( @@ -152,8 +190,11 @@ public class Main { protected String[] getConfigArgs() { List<String> configArgs = Lists.newArrayList(); - /*configArgs.addAll(Lists.newArrayList( - "--option", ConfigurationOption.BASEDIR.getKey(), getResourceDirectory().getAbsolutePath()));*/ + + if (basedir != null) { + configArgs.addAll(Lists.newArrayList( + "--option", ConfigurationOption.BASEDIR.getKey(), basedir.getAbsolutePath())); + } return configArgs.toArray(new String[configArgs.size()]); } diff --git a/duniter4j-client/src/main/java/fr/duniter/client/actions/AbstractAction.java b/duniter4j-client/src/main/java/fr/duniter/client/actions/AbstractAction.java new file mode 100644 index 0000000000000000000000000000000000000000..796f52d8fbdac15f521f412d5a6b617c8d70eee6 --- /dev/null +++ b/duniter4j-client/src/main/java/fr/duniter/client/actions/AbstractAction.java @@ -0,0 +1,47 @@ +package fr.duniter.client.actions; + +/* + * #%L + * Duniter4j :: Client + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +/** + * Created by blavenie on 28/03/17. + */ + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class AbstractAction implements Runnable { + + protected Logger log; + + protected AbstractAction() { + log = LoggerFactory.getLogger(getClass()); + } + + protected void fail(Exception e) { + fail(e.getMessage()); + } + protected void fail(String message) { + log.error(message); + System.exit(-1); + } +} diff --git a/duniter4j-client/src/main/java/fr/duniter/client/actions/NetworkAction.java b/duniter4j-client/src/main/java/fr/duniter/client/actions/NetworkAction.java new file mode 100644 index 0000000000000000000000000000000000000000..171326abf2c5716957b6224cfc19edcf50f445cc --- /dev/null +++ b/duniter4j-client/src/main/java/fr/duniter/client/actions/NetworkAction.java @@ -0,0 +1,283 @@ +package fr.duniter.client.actions; + +/* + * #%L + * Duniter4j :: Client + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.beust.jcommander.Parameter; +import com.beust.jcommander.Parameters; +import com.beust.jcommander.ParametersDelegate; +import com.beust.jcommander.internal.Lists; +import dnl.utils.text.table.TextTable; +import fr.duniter.client.actions.params.PeerParameters; +import fr.duniter.client.actions.utils.ClearableConsole; +import fr.duniter.client.actions.utils.Formatters; +import org.apache.commons.io.IOUtils; +import org.duniter.core.client.model.local.Peer; +import org.duniter.core.client.service.ServiceLocator; +import org.duniter.core.client.service.bma.BlockchainRemoteService; +import org.duniter.core.client.service.local.NetworkService; +import org.duniter.core.util.CollectionUtils; +import org.duniter.core.util.FileUtils; +import org.nuiton.i18n.I18n; + +import java.io.*; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Created by blavenie on 22/03/17. + */ +@Parameters(resourceBundle = "i18n.duniter4j-client", commandDescription = "Display network peers", commandDescriptionKey = "duniter4j.client.network.action") +public class NetworkAction extends AbstractAction { + + @ParametersDelegate + public PeerParameters peerParameters = new PeerParameters(); + + @Parameter(names = "--continue", description = "Continue scanning ?", descriptionKey = "duniter4j.client.network.params.continue") + private boolean autoRefresh = false; + + @Parameter(names = "--output", description = "Output file (CSV format)", descriptionKey = "duniter4j.client.network.params.output") + private File outputFile = null; + + private ClearableConsole console; + + private DateFormat dateFormat; + private List<String> knownBlocks = Lists.newArrayList(); + + public NetworkAction() { + super(); + } + + @Override + public void run() { + + peerParameters.parse(); + final Peer mainPeer = peerParameters.getPeer(); + checkOutputFileIfNotNull(); // make sure the file (if any) is writable + + dateFormat = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, I18n.getDefaultLocale()); + + console = new ClearableConsole(System.out) + .putRegexColor(I18n.t("duniter4j.client.network.ssl"), ClearableConsole.Color.green) + .putRegexColor(I18n.t("duniter4j.client.network.mirror"), ClearableConsole.Color.lightgray); + + System.setOut(console); + + log.info(I18n.t("duniter4j.client.network.loadingPeers")); + List<Peer> peers = loadPeers(mainPeer); + + showPeersTable(peers, true/*autoRefresh*/); + + if (autoRefresh) { + BlockchainRemoteService bcService = ServiceLocator.instance().getBlockchainRemoteService(); + + peers.stream().forEach(peer -> { + String buid = peer.getStats().getBlockNumber() + "-" + peer.getStats().getBlockHash(); + if (!knownBlocks.contains(buid)) { + knownBlocks.add(buid); + } + }); + + // Start listening for new peer... + bcService.addPeerListener(mainPeer, message -> updatePeers(mainPeer, knownBlocks)); + // Start listening for new block... + bcService.addBlockListener(mainPeer, message -> updatePeers(mainPeer, knownBlocks)); + + try { + while(true) { + Thread.sleep(10000); // 10 s + + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + // TODO: DEV only + /* else { + try { + int blockCount = 1500; + while(true) { + Thread.sleep(2000); // 2 s + + List<Peer> updatedPeers = new ArrayList<>(); + + for (int i=0; i<5; i++) { + Peer peer = Peer.newBuilder().setHost("p1").setPort(80) + .build(); + peer.getStats().setBlockNumber(blockCount); + updatedPeers.add(peer); + } + updatedPeers.addAll(peers); + + showPeersTable(updatedPeers, true); + blockCount++; + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + }*/ + + } + + /* -- protected methods -- */ + + public List<Peer> loadPeers(Peer mainPeer) { + NetworkService service = ServiceLocator.instance().getNetworkService(); + return service.getPeers(mainPeer); + } + + public void showPeersTable(List<Peer> peers, boolean clearConsole) { + + // Clearing console + if (clearConsole) { + clearConsole(); + } + + if (CollectionUtils.isEmpty(peers)) { + console.println(I18n.t("duniter4j.client.network.noPeers")); + return; + } + + Peer mainConsensusPeer = peers.get(0); + if (mainConsensusPeer.getStats().isMainConsensus()) { + Long mediantTime = mainConsensusPeer.getStats().getMedianTime(); + if (mediantTime != null) { + console.println(I18n.t("duniter4j.client.network.medianTime", + dateFormat.format(new Date(mediantTime * 1000)))); + } + + knownBlocks.stream().forEach(buid -> { + console.putRegexColor(Formatters.formatBuid(buid), ClearableConsole.Color.lightgray); + }); + + console.putRegexColor(formatBuid(mainConsensusPeer.getStats()), ClearableConsole.Color.green); + } + + String[] columnNames = { + "Uid", + "Pubkey", + "Address", + "Status", + "API", + "Version", + "Difficulty", + "Block #"}; + + List<Object[]> data = peers.stream().map(peer -> { + boolean isUp = peer.getStats().getStatus() == Peer.PeerStatus.UP; + return new Object[] { + Formatters.formatUid(peer.getStats().getUid()), + Formatters.formatPubkey(peer.getPubkey()), + peer.getHost() + ":" + peer.getPort(), + peer.getStats().getStatus().name(), + isUp && peer.isUseSsl() ? I18n.t("duniter4j.client.network.ssl") : "", + isUp ? peer.getStats().getVersion() : "", + (isUp && peer.getStats().getHardshipLevel() != null) ? peer.getStats().getHardshipLevel() : I18n.t("duniter4j.client.network.mirror"), + isUp ? formatBuid(peer.getStats()) : "" + }; + }) + .collect(Collectors.toList()); + + Object[][] rows = new Object[data.size()][]; + int i = 0; + for (Object[] row : data) { + rows[i++] = row; + } + + + TextTable tt = new TextTable(columnNames, rows); + + // Write result to filCSV + if (outputFile != null) { + checkOutputFileIfNotNull(); + + OutputStream os = null; + try { + os = new BufferedOutputStream(new FileOutputStream(outputFile)); + tt.toCsv(os); + os.flush(); + } + catch (IOException e) { + fail(e); + } + finally { + IOUtils.closeQuietly(os); + } + } + + // Print result to console + else { + // this adds the numbering on the left + tt.setAddRowNumbering(true); + tt.printTable(console, 0); + } + } + + + protected void checkOutputFileIfNotNull() { + if (outputFile != null) { + if (outputFile.getParentFile() != null && !outputFile.getParentFile().exists()) { + try { + FileUtils.forceMkdir(outputFile.getParentFile()); + } catch (IOException e) { + fail(e); + } + } + + if (outputFile.exists()) { + if (!outputFile.delete() && !outputFile.canWrite()) { + fail(I18n.t("duniter4j.client.network.error.outputFieNotWritable")); + } + } + } + } + + protected void updatePeers(Peer mainPeer, List<String> knownBlocks) { + List<Peer> updatedPeers = loadPeers(mainPeer); + + int knowBlockSize = knownBlocks.size(); + updatedPeers.stream().forEach(peer -> { + String buid = peer.getStats().getBlockNumber() + "-" + peer.getStats().getBlockHash(); + if (!knownBlocks.contains(buid)) { + knownBlocks.add(buid); + } + }); + + // new block received: refresh console + if (knowBlockSize < knownBlocks.size()) { + showPeersTable(updatedPeers, true); + } + } + + protected void clearConsole() { + console.clearConsole(); + } + + protected String formatBuid(Peer.Stats stats) { + return Formatters.formatBuid(stats.getBlockNumber() + "-" + stats.getBlockHash()); + } +} diff --git a/duniter4j-cmd/src/main/java/fr/duniter/cmd/actions/TransactionAction.java b/duniter4j-client/src/main/java/fr/duniter/client/actions/TransactionAction.java similarity index 73% rename from duniter4j-cmd/src/main/java/fr/duniter/cmd/actions/TransactionAction.java rename to duniter4j-client/src/main/java/fr/duniter/client/actions/TransactionAction.java index c738c0dfbf291695185f3b155199ce9b7a638339..77c3f121b078ea1b2bf9bd655f5f702f77e5dad1 100644 --- a/duniter4j-cmd/src/main/java/fr/duniter/cmd/actions/TransactionAction.java +++ b/duniter4j-client/src/main/java/fr/duniter/client/actions/TransactionAction.java @@ -1,13 +1,36 @@ -package fr.duniter.cmd.actions; +package fr.duniter.client.actions; + +/* + * #%L + * Duniter4j :: Client + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; +import com.beust.jcommander.Parameters; import com.beust.jcommander.ParametersDelegate; import com.beust.jcommander.validators.PositiveInteger; import com.google.common.collect.ImmutableList; -import fr.duniter.cmd.actions.params.AuthParameters; -import fr.duniter.cmd.actions.params.PeerParameters; -import fr.duniter.cmd.actions.utils.Formatters; +import fr.duniter.client.actions.params.AuthParameters; +import fr.duniter.client.actions.params.PeerParameters; +import fr.duniter.client.actions.utils.Formatters; import org.duniter.core.client.model.bma.EndpointApi; import org.duniter.core.client.model.local.Currency; import org.duniter.core.client.model.local.Peer; @@ -21,6 +44,7 @@ import org.duniter.core.exception.TechnicalException; import org.duniter.core.service.CryptoService; import org.duniter.core.util.CollectionUtils; import org.duniter.core.util.crypto.KeyPair; +import org.nuiton.i18n.I18n; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,7 +53,8 @@ import java.util.List; /** * Created by blavenie on 22/03/17. */ -public class TransactionAction implements Runnable { +@Parameters(resourceBundle = "i18n.duniter4j-client", commandDescription = "Send a transaction", commandDescriptionKey = "duniter4j.client.transaction.action") +public class TransactionAction extends AbstractAction { private static Logger log = LoggerFactory.getLogger(TransactionAction.class); @@ -51,6 +76,10 @@ public class TransactionAction implements Runnable { private int mainConsensusPeerCount = 0; private int forkConsensusPeerCount = 0; + public TransactionAction() { + super(); + } + @Override public void run() { try { @@ -85,7 +114,7 @@ public class TransactionAction implements Runnable { )); } else { - fail("Unknwon authentification type"); + fail(I18n.t("duniter4j.client.transaction.error.unknownAuth")); return; } @@ -111,18 +140,13 @@ public class TransactionAction implements Runnable { } } - protected void fail(String message) { - log.error(message); - System.exit(-1); - } - protected void sendToPeer(Peer peer, Wallet wallet) { TransactionRemoteService txService = ServiceLocator.instance().getTransactionRemoteService(); logTxSummary(wallet); txService.transfer(peer, wallet, output, amount, comment); - JCommander.getConsole().println("Transaction successfully sent."); + JCommander.getConsole().println(I18n.t("duniter4j.client.transaction.sent")); } protected void sendBroadcast(Peer mainPeer, Currency currency, Wallet wallet, boolean useSsl) { @@ -130,7 +154,7 @@ public class TransactionAction implements Runnable { TransactionRemoteService txService = ServiceLocator.instance().getTransactionRemoteService(); PeerService peerService = ServiceLocator.instance().getPeerService(); - log.info("Loading member peers..."); + log.info(I18n.t("duniter4j.client.transaction.loadingMemberPeers")); // Filter to [member + UP] peers NetworkService.Filter peersFilter = new NetworkService.Filter(); @@ -151,12 +175,12 @@ public class TransactionAction implements Runnable { List<Peer> peers = ServiceLocator.instance().getNetworkService().getPeers(mainPeer, peersFilter, sortLesserDifficulty); if (CollectionUtils.isEmpty(peers)) { - log.warn("No members peers found! Skipping --broadcast option."); + log.warn(I18n.t("duniter4j.client.transaction.error.broadcast.noMemberPeer")); sendToPeer(mainPeer, wallet); return; } - log.info(String.format("%d member peers found for broadcast", peers.size())); + log.info(I18n.t("duniter4j.client.transaction.broadcast.memberPeerCount", peers.size())); logTxSummary(wallet); @@ -169,7 +193,7 @@ public class TransactionAction implements Runnable { try { txService.transfer(peer, wallet, output, amount, comment); - log.warn(String.format("Successfully sent to [%s]", peer)); + log.debug(String.format("Successfully sent to [%s]", peer)); if (peer.getStats() != null) { if (peer.getStats().isMainConsensus()) { @@ -181,18 +205,18 @@ public class TransactionAction implements Runnable { } catch (Exception e) { - log.warn(String.format("Could not send transaction to [%s]: %s", peer, e.getMessage())); + log.debug(String.format("Could not send transaction to [%s]: %s", peer, e.getMessage())); } }); if (mainConsensusPeerCount > 0) { - JCommander.getConsole().println(String.format("Transaction successfully sent (to %d nodes on the main blockchain consensus).", mainConsensusPeerCount)); + JCommander.getConsole().println(I18n.t("duniter4j.client.transaction.broadcast.success", mainConsensusPeerCount)); } else if (forkConsensusPeerCount > 0){ - fail(String.format("Transaction has NOT been sent to the main consensus BlockChain, but ONLY to %d peers on a fork of the blockchain.", forkConsensusPeerCount)); + fail(I18n.t("duniter4j.client.transaction.broadcast.successOnForkOnly", forkConsensusPeerCount)); } else { - fail(String.format("Transaction has NOT been sent. Not a single peer has accepted the transaction.")); + fail(I18n.t("duniter4j.client.transaction.broadcast.failed")); } } @@ -200,14 +224,11 @@ public class TransactionAction implements Runnable { protected void logTxSummary(Wallet wallet) { // Log TX summary - JCommander.getConsole().println(String.format("Generate Transation:\n\t- From: %s\n\t- To: %s\n\t- Amount: %s %s", + JCommander.getConsole().println(I18n.t("duniter4j.client.transaction.broadcast.summary", Formatters.formatPubkey(wallet.getPubKeyHash()), Formatters.formatPubkey(output), amount, Formatters.currencySymbol(wallet.getCurrency()))); } - protected void fail(Exception e) { - fail(e.getMessage()); - } } diff --git a/duniter4j-cmd/src/main/java/fr/duniter/cmd/actions/params/AuthParameters.java b/duniter4j-client/src/main/java/fr/duniter/client/actions/params/AuthParameters.java similarity index 66% rename from duniter4j-cmd/src/main/java/fr/duniter/cmd/actions/params/AuthParameters.java rename to duniter4j-client/src/main/java/fr/duniter/client/actions/params/AuthParameters.java index 17fd1f99df6e78ce52ae0a1a8ed77e1b16f884ad..a8311da002f40673737cb5e652a5b8541c05b07b 100644 --- a/duniter4j-cmd/src/main/java/fr/duniter/cmd/actions/params/AuthParameters.java +++ b/duniter4j-client/src/main/java/fr/duniter/client/actions/params/AuthParameters.java @@ -1,4 +1,26 @@ -package fr.duniter.cmd.actions.params; +package fr.duniter.client.actions.params; + +/* + * #%L + * Duniter4j :: Client + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; @@ -8,6 +30,7 @@ import com.beust.jcommander.validators.PositiveInteger; import com.google.common.collect.ImmutableList; import org.duniter.core.service.Ed25519CryptoServiceImpl; import org.duniter.core.util.StringUtils; +import org.nuiton.i18n.I18n; import java.util.Arrays; import java.util.List; @@ -35,15 +58,15 @@ public class AuthParameters { public void parse() { // Compute keypair and wallet if (StringUtils.isBlank(salt) && authScrypt) { - JCommander.getConsole().print("Please enter your Scrypt Salt (Secret identifier): "); + JCommander.getConsole().print(I18n.t("duniter4j.client.params.authScrypt.ask.salt")); salt = JCommander.getConsole().readPassword(true); } if (StringUtils.isBlank(password) && authScrypt){ - JCommander.getConsole().print("Please enter your Scrypt password (masked): "); + JCommander.getConsole().print(I18n.t("duniter4j.client.params.authScrypt.ask.passwd")); password = JCommander.getConsole().readPassword(true); } if (scryptPArams == null && authScrypt) { - JCommander.getConsole().print(String.format("Please enter your Scrypt parameters (N,r,p): [%d,%d,%d] ", + JCommander.getConsole().print(I18n.t("duniter4j.client.params.authScrypt.ask.scryptParams", Ed25519CryptoServiceImpl.SCRYPT_PARAMS_N, Ed25519CryptoServiceImpl.SCRYPT_PARAMS_r, Ed25519CryptoServiceImpl.SCRYPT_PARAMS_p)); @@ -51,7 +74,7 @@ public class AuthParameters { if (StringUtils.isNotBlank(scryptsParamsStr)) { String[] parts = new String(scryptsParamsStr).split(","); if (parts.length != 3) { - throw new ParameterException("Invalid Scrypt parameters (expected 3 values)"); + throw new ParameterException(I18n.t("duniter4j.client.params.authScrypt.error.scryptParams")); } scryptPArams = Arrays.asList(parts).stream().map(part -> Integer.parseInt(part)).collect(Collectors.toList()); } diff --git a/duniter4j-cmd/src/main/java/fr/duniter/cmd/actions/params/PeerParameters.java b/duniter4j-client/src/main/java/fr/duniter/client/actions/params/PeerParameters.java similarity index 62% rename from duniter4j-cmd/src/main/java/fr/duniter/cmd/actions/params/PeerParameters.java rename to duniter4j-client/src/main/java/fr/duniter/client/actions/params/PeerParameters.java index a08a8a6780ec6c2649baef3c79fab220e9b596c7..4f0b12a291fdf3b934ebca503c456307088d854e 100644 --- a/duniter4j-cmd/src/main/java/fr/duniter/cmd/actions/params/PeerParameters.java +++ b/duniter4j-client/src/main/java/fr/duniter/client/actions/params/PeerParameters.java @@ -1,12 +1,34 @@ -package fr.duniter.cmd.actions.params; +package fr.duniter.client.actions.params; + +/* + * #%L + * Duniter4j :: Client + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ -import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; import com.beust.jcommander.ParameterException; import org.duniter.core.client.config.Configuration; import org.duniter.core.client.model.local.Peer; import org.duniter.core.util.Preconditions; import org.duniter.core.util.StringUtils; +import org.nuiton.i18n.I18n; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,7 +39,7 @@ public class PeerParameters { private static Logger log = LoggerFactory.getLogger(PeerParameters.class); - @Parameter(names = {"-p", "--peer"}, description = "Peer address (use format: 'host:port')") + @Parameter(names = {"-p", "--peer"}, description = "Peer address (use format: 'host:port')", descriptionKey = "duniter4j.params.peer") public String peerStr; @Parameter(names = "--broadcast", description = "Broadcast document sent to all nodes") @@ -35,7 +57,7 @@ public class PeerParameters { if (StringUtils.isNotBlank(peerStr)) { String[] parts = peerStr.split(":"); if (parts.length > 2) { - throw new ParameterException("Invalid --peer parameter"); + throw new ParameterException(I18n.t("duniter4j.client.params.error.invalidOption", "--peer")); } String host = parts[0]; Integer port = parts.length == 2 ? Integer.parseInt(parts[1]) : null; @@ -49,14 +71,14 @@ public class PeerParameters { } peer = peerBuilder.build(); - log.info(String.format("Duniter node: [%s:%s]", peer.getHost(), peer.getPort())); + log.info(I18n.t("duniter4j.client.params.peer", peer.getHost(), peer.getPort())); } else { Configuration config = Configuration.instance(); peer = Peer.newBuilder().setHost(config.getNodeHost()) .setPort(config.getNodePort()) .build(); - log.info(String.format("Fallback to default Duniter node: [%s:%d]", peer.getHost(), peer.getPort())); + log.info(I18n.t("duniter4j.client.params.peer.fallback", peer.getHost(), peer.getPort())); } } diff --git a/duniter4j-client/src/main/java/fr/duniter/client/actions/utils/ClearableConsole.java b/duniter4j-client/src/main/java/fr/duniter/client/actions/utils/ClearableConsole.java new file mode 100644 index 0000000000000000000000000000000000000000..168bdc6f35870c1b504854c66bf49c3b58c17efb --- /dev/null +++ b/duniter4j-client/src/main/java/fr/duniter/client/actions/utils/ClearableConsole.java @@ -0,0 +1,214 @@ +package fr.duniter.client.actions.utils; + +/* + * #%L + * Duniter4j :: Client + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.beust.jcommander.internal.Maps; +import org.duniter.core.util.Preconditions; + +import java.io.PrintStream; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Created by blavenie on 28/03/17. + */ +public class ClearableConsole extends PrintStream { + + public interface Color { + int black = 30; + int red = 31; + int green = 32; + int brown = 33; + int blue = 34; + int magenta = 35; + int cyan = 36; + int lightgray = 37; + } + + private int rowsCount = 0; + + private Map<Pattern, Integer> regexColors = Maps.newHashMap(); + + public ClearableConsole() { + super(System.out, true); + } + + public ClearableConsole(PrintStream delegate) { + super(delegate, true); + } + + public void clearConsole() { + if (rowsCount == 0) { + super.print("\033[H\033[2J"); + super.flush(); + } + else { + moveCursor(rowsCount); + } + rowsCount = 0; + } + + public ClearableConsole putRegexColor(String regex, int color) { + Preconditions.checkArgument(color >= 30 && color <= 37); + + regexColors.put(Pattern.compile(regex), color); + return this; + } + + public ClearableConsole removeRegex(String regex) { + + regexColors.remove(Pattern.compile(regex)); + return this; + } + + public void moveCursor(int nbLinesUp) { + for (int i = 1; i <= nbLinesUp; i++) { + super.print("\033[1A"); // Move up + super.print("\033[2K"); // Erase line content + } + + super.flush(); + } + + @Override + public void println(boolean x) { + super.println(x); + rowsCount++; + } + + @Override + public void println(char x) { + super.println(x); + rowsCount++; + } + + @Override + public void println(int x) { + super.println(x); + rowsCount++; + } + + @Override + public void println(long x) { + super.println(x); + rowsCount++; + } + + @Override + public void println(float x) { + super.println(x); + rowsCount++; + } + + @Override + public void println(double x) { + super.println(x); + rowsCount++; + } + + @Override + public void println(char[] x) { + super.println(x); + rowsCount++; + } + + @Override + public void println(String x) { + + super.println(x); + rowsCount++; + } + + @Override + public void println(Object x) { + super.println(x); + rowsCount++; + } + + @Override + public void print(char c) { + super.print(c); + } + + @Override + public void print(char[] x) { + super.print(x); + for (int i=0; i< x.length; i++) { + if (x[i] == '\n') { + rowsCount++; + } + } + } + + @Override + public void print(String s) { + + for (Pattern pattern: regexColors.keySet()) { + Matcher matcher = pattern.matcher(s); + if (matcher.find()) { + StringBuilder sb = new StringBuilder(); + if (matcher.start() > 0) { + sb.append(s.substring(0, matcher.start())); + } + sb.append(String.format("\033[0;%sm", regexColors.get(pattern))); + sb.append(s.substring(matcher.start(), matcher.end())); + sb.append("\033[0m"); + if (matcher.end() < s.length()) { + sb.append(s.substring(matcher.end())); + } + s = sb.toString(); + } + } + super.print(s); + for (int i=0; i< s.length(); i++) { + if (s.charAt(i) == '\n') { + rowsCount++; + } + } + } + + @Override + public void print(Object obj) { + String s = String.valueOf(obj); + print(s); + } + + @Override + public PrintStream append(CharSequence csq, int start, int end) { + for (int i=start; i<=end; i++) { + if (csq.charAt(i) == '\n') { + rowsCount++; + } + } + return super.append(csq, start, end); + } + + @Override + public PrintStream append(char c) { + if (c == '\n') { + rowsCount++; + } + return super.append(c); + } +} diff --git a/duniter4j-client/src/main/java/fr/duniter/client/actions/utils/Formatters.java b/duniter4j-client/src/main/java/fr/duniter/client/actions/utils/Formatters.java new file mode 100644 index 0000000000000000000000000000000000000000..57ef912edfec1c8682f67536e27b296b52ccff5c --- /dev/null +++ b/duniter4j-client/src/main/java/fr/duniter/client/actions/utils/Formatters.java @@ -0,0 +1,76 @@ +package fr.duniter.client.actions.utils; + +/* + * #%L + * Duniter4j :: Client + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.duniter.core.util.StringUtils; + +/** + * Created by blavenie on 24/03/17. + */ +public class Formatters { + + public static String formatPubkey(String pubkey) { + if (pubkey == null) { + return ""; + } + if (pubkey != null && pubkey.length() > 8) { + return pubkey.substring(0, 8); + } + return pubkey; + } + + public static String formatUid(String uid) { + if (StringUtils.isBlank(uid)) { + return ""; + } + if (uid != null && uid.length() > 20) { + return uid.substring(0, 19); + } + return uid; + } + + public static String currencySymbol(String currencyName) { + String[] parts = currencyName.split("-_"); + if (parts.length < 2) { + if (currencyName.length() <= 3) { + return currencyName.toUpperCase(); + } + else { + return currencyName.toUpperCase().substring(0,1); + } + } + return currencySymbol(parts[0]) + currencySymbol(parts[1]); + } + + public static String formatBuid(String buid) { + if (StringUtils.isBlank(buid)) { + return ""; + } + int index = buid.indexOf('-'); + if (index + 10 >= buid.length()) { + return buid; + } + return buid.substring(0, index + 10); + } + +} diff --git a/duniter4j-cmd/src/main/resources/META-INF/services/org.duniter.core.beans.Bean b/duniter4j-client/src/main/resources/META-INF/services/org.duniter.core.beans.Bean similarity index 100% rename from duniter4j-cmd/src/main/resources/META-INF/services/org.duniter.core.beans.Bean rename to duniter4j-client/src/main/resources/META-INF/services/org.duniter.core.beans.Bean diff --git a/duniter4j-cmd/pom.xml b/duniter4j-cmd/pom.xml deleted file mode 100644 index 0491353b51545e4e1ebc3fde7d3df65e6ed439fa..0000000000000000000000000000000000000000 --- a/duniter4j-cmd/pom.xml +++ /dev/null @@ -1,156 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <parent> - <artifactId>duniter4j</artifactId> - <groupId>org.duniter</groupId> - <version>0.9.2-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>duniter4j-cmd</artifactId> - - <properties> - <jTextUtilsVersion>0.3.3</jTextUtilsVersion> - </properties> - - <repositories> - <repository> - <id>d-maven</id> - <url>https://github.com/neilpanchal/j-text-utils/tree/master/repo</url> - </repository> - </repositories> - - <dependencies> - <dependency> - <groupId>org.duniter</groupId> - <artifactId>duniter4j-core-client</artifactId> - <version>${project.version}</version> - </dependency> - - <!-- logging --> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </dependency> - - - <dependency> - <groupId>com.beust</groupId> - <artifactId>jcommander</artifactId> - <version>1.60</version> - </dependency> - - <dependency> - <groupId>dnl.utils</groupId> - <artifactId>j-text-utils</artifactId> - <version>${jTextUtilsVersion}</version> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.6</version> - </dependency> - - </dependencies> - - <profiles> - <profile> - <id>install-missing-libs</id> - <activation> - <file> - <missing>${settings.localRepository}/dnl/utils/j-text-utils/${jTextUtilsVersion}/j-text-utils-${jTextUtilsVersion}.jar</missing> - </file> - </activation> - <build> - <plugins> - <plugin> - <artifactId>maven-install-plugin</artifactId> - <version>2.5.2</version> - <executions> - <execution> - <id>installing j-text-utils.jar</id> - <phase>initialize</phase> - <goals> - <goal>install-file</goal> - </goals> - <configuration> - <groupId>dnl.utils</groupId> - <artifactId>j-text-utils</artifactId> - <version>${jTextUtilsVersion}</version> - <packaging>jar</packaging> - <file>${project.basedir}/lib/j-text-utils-${jTextUtilsVersion}.jar</file> - </configuration> - </execution> - </executions> - </plugin> - - <plugin> - <artifactId>maven-antrun-plugin</artifactId> - <executions> - <execution> - <id>enforce-dependencies-exists</id> - <phase>generate-sources</phase> - <goals> - <goal>run</goal> - </goals> - <configuration> - <target> - - <condition property="displayMessage"> - <and> - <not><available file="${project.basedir}/.maven/install.log" /></not> - <!-- do not failed here if performRelease --> - <isfalse value="${performRelease}" /> - </and> - </condition> - <property name="installSuccessMessage">* - ************************************************************************* - * - * IMPORTANT: - * - * Missing lib dependencies successfully installed on [${settings.localRepository}] - * You should now re-run the build. - * This message will NOT appear again - * - ************************************************************************* - </property> - - <echo file="${project.basedir}/.maven/install.log">${installSuccessMessage}</echo> - - <fail message="${installSuccessMessage}" > - <condition> - <istrue value="${displayMessage}"/> - </condition> - </fail> - </target> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - - <profile> - <id>use-installed-libs</id> - <activation> - <file> - <exists>${settings.localRepository}/dnl/utils/j-text-utils/${jTextUtilsVersion}/j-text-utils-${jTextUtilsVersion}.jar</exists> - </file> - </activation> - <dependencies> - <dependency> - <groupId>dnl.utils</groupId> - <artifactId>j-text-utils</artifactId> - <version>${jTextUtilsVersion}</version> - </dependency> - </dependencies> - </profile> - </profiles> -</project> \ No newline at end of file diff --git a/duniter4j-cmd/src/main/java/fr/duniter/cmd/actions/NetworkAction.java b/duniter4j-cmd/src/main/java/fr/duniter/cmd/actions/NetworkAction.java deleted file mode 100644 index 2da6b804efcb3729a01a0ecc33d40cf2005c2543..0000000000000000000000000000000000000000 --- a/duniter4j-cmd/src/main/java/fr/duniter/cmd/actions/NetworkAction.java +++ /dev/null @@ -1,151 +0,0 @@ -package fr.duniter.cmd.actions; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.beust.jcommander.Parameters; -import com.beust.jcommander.ParametersDelegate; -import com.beust.jcommander.internal.Lists; -import dnl.utils.text.table.SeparatorPolicy; -import dnl.utils.text.table.TextTable; -import fr.duniter.cmd.actions.params.PeerParameters; -import fr.duniter.cmd.actions.utils.Formatters; -import org.duniter.core.client.model.local.Peer; -import org.duniter.core.client.service.ServiceLocator; -import org.duniter.core.client.service.local.NetworkService; -import org.duniter.core.util.CollectionUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.stream.Collectors; - -/** - * Created by blavenie on 22/03/17. - */ -@Parameters(commandDescription = "Display network peers") -public class NetworkAction implements Runnable { - private static Logger log = LoggerFactory.getLogger(NetworkAction.class); - - @ParametersDelegate - public PeerParameters peerParameters = new PeerParameters(); - - @Parameter(names = "--continue", description = "Continue scanning ?") - private boolean autoRefresh = false; - - private int previousRowDisplayed = 0; - - @Override - public void run() { - - peerParameters.parse(); - Peer mainPeer = peerParameters.getPeer(); - - log.info("Loading peers..."); - NetworkService service = ServiceLocator.instance().getNetworkService(); - List<Peer> peers = service.getPeers(mainPeer); - showPeersTable(peers, autoRefresh); - - if (autoRefresh) { - final List<String> knownBlocks = Lists.newArrayList(); - peers.stream().forEach(peer -> { - String buid = peer.getStats().getBlockNumber() + "-" + peer.getStats().getBlockHash(); - if (!knownBlocks.contains(buid)) { - knownBlocks.add(buid); - } - }); - - // Start listening for new block... - CompletableFuture.runAsync(() -> - ServiceLocator.instance().getBlockchainRemoteService().addPeerListener(mainPeer, message -> { - List<Peer> updatedPeers = service.getPeers(mainPeer); - - int knowBlockSize = knownBlocks.size(); - updatedPeers.stream().forEach(peer -> { - String buid = peer.getStats().getBlockNumber() + "-" + peer.getStats().getBlockHash(); - if (!knownBlocks.contains(buid)) { - knownBlocks.add(buid); - } - }); - - // new block received: refresh console - if (knowBlockSize < knownBlocks.size()) { - showPeersTable(updatedPeers, true); - } - - })); - - try { - while(true) { - Thread.sleep(10000); // 10 s - } - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - - } - - /* -- protected methods -- */ - - public void showPeersTable(List<Peer> peers, boolean clearConsole) { - - // Clearing console - if (clearConsole) { - clearConsole(); - } - - if (CollectionUtils.isEmpty(peers)) { - JCommander.getConsole().println("No peers found"); - return; - } - String[] columnNames = { - "Uid", - "Pubkey", - "Address", - "Status", - "API", - "Version", - "Difficulty", - "Block #"}; - - List<Object[]> data = peers.stream().map(peer -> { - boolean isUp = peer.getStats().getStatus() == Peer.PeerStatus.UP; - return new Object[] { - Formatters.formatUid(peer.getStats().getUid()), - Formatters.formatPubkey(peer.getPubkey()), - peer.getHost() + ":" + peer.getPort(), - peer.getStats().getStatus().name(), - isUp && peer.isUseSsl() ? "SSL" : null, - isUp ? peer.getStats().getVersion() : null, - (isUp && peer.getStats().getHardshipLevel() != null) ? peer.getStats().getHardshipLevel() : "Mirror", - isUp ? peer.getStats().getBlockNumber() : null - }; - }) - .collect(Collectors.toList()); - - Object[][] rows = new Object[data.size()][]; - int i = 0; - for (Object[] row : data) { - rows[i++] = row; - } - - - TextTable tt = new TextTable(columnNames, rows); - // this adds the numbering on the left - tt.setAddRowNumbering(true); - tt.printTable(); - - previousRowDisplayed = 3/*header rows*/ + rows.length; - } - - protected void moveCursor(int nbLinesUp) { - System.out.print(String.format("\033[%dA",nbLinesUp)); // Move up - System.out.print("\033[2K"); // Erase line content - } - - protected void clearConsole() { - System.out.print(String.format("\033[2J")); - } -} diff --git a/duniter4j-cmd/src/main/java/fr/duniter/cmd/actions/utils/Formatters.java b/duniter4j-cmd/src/main/java/fr/duniter/cmd/actions/utils/Formatters.java deleted file mode 100644 index 0f8cdc9bdbbf0b2df6d3c8399b93e881e6f5262b..0000000000000000000000000000000000000000 --- a/duniter4j-cmd/src/main/java/fr/duniter/cmd/actions/utils/Formatters.java +++ /dev/null @@ -1,34 +0,0 @@ -package fr.duniter.cmd.actions.utils; - -/** - * Created by blavenie on 24/03/17. - */ -public class Formatters { - - public static String formatPubkey(String pubkey) { - if (pubkey != null && pubkey.length() > 8) { - return pubkey.substring(0, 8); - } - return pubkey; - } - - public static String formatUid(String uid) { - if (uid != null && uid.length() > 20) { - return uid.substring(0, 19); - } - return uid; - } - - public static String currencySymbol(String currencyName) { - String[] parts = currencyName.split("-_"); - if (parts.length < 2) { - if (currencyName.length() <= 3) { - return currencyName.toUpperCase(); - } - else { - return currencyName.toUpperCase().substring(0,1); - } - } - return currencySymbol(parts[0]) + currencySymbol(parts[1]); - } -} diff --git a/duniter4j-cmd/src/main/resources/duniter4j-cmd.config b/duniter4j-cmd/src/main/resources/duniter4j-cmd.config deleted file mode 100644 index d9f4f75b7e5ea3263c1a2c3b4ac7eecaba84c90e..0000000000000000000000000000000000000000 --- a/duniter4j-cmd/src/main/resources/duniter4j-cmd.config +++ /dev/null @@ -1,5 +0,0 @@ -duniter4j.node.host=192.168.0.5 -duniter4j.node.port=10901 - -duniter4j.node.elasticsearch.host=localhost -duniter4j.node.elasticsearch.port=9200 diff --git a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/CertificationDeserializer.java b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/CertificationDeserializer.java index 0d869e6232c132942325317beef28a39ee468e8d..207e04389394a7849975b4bc3b59969bba47349b 100644 --- a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/CertificationDeserializer.java +++ b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/CertificationDeserializer.java @@ -1,5 +1,27 @@ package org.duniter.core.client.model.bma.jackson; +/* + * #%L + * Duniter4j :: Core Client API + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; diff --git a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/EndpointDeserializer.java b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/EndpointDeserializer.java index 7a877fe64949a229086429b08e7cd279ccc7bea3..7a1387aacfb2daca3cff34f0c40a83a9c2ee309c 100644 --- a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/EndpointDeserializer.java +++ b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/EndpointDeserializer.java @@ -1,5 +1,27 @@ package org.duniter.core.client.model.bma.jackson; +/* + * #%L + * Duniter4j :: Core Client API + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; diff --git a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/IdentityDeserializer.java b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/IdentityDeserializer.java index 42f6612fa516ae32e7299640f2e414400d0a1944..e19145533449ccf29d32758ed38db3a112055727 100644 --- a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/IdentityDeserializer.java +++ b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/IdentityDeserializer.java @@ -1,5 +1,27 @@ package org.duniter.core.client.model.bma.jackson; +/* + * #%L + * Duniter4j :: Core Client API + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; diff --git a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/JacksonUtils.java b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/JacksonUtils.java index e51c2a1b25f5176390110ca4b607df4b4fc0c7b3..11aed3fdc065c8878bd9023129578c1493236028 100644 --- a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/JacksonUtils.java +++ b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/JacksonUtils.java @@ -1,5 +1,27 @@ package org.duniter.core.client.model.bma.jackson; +/* + * #%L + * Duniter4j :: Core Client API + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import org.duniter.core.client.model.bma.BlockchainBlock; diff --git a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/JoinerDeserializer.java b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/JoinerDeserializer.java index 5e18c24e163d98847ba5c40bf0893ad6f567b4c4..2b03baf8d063eee88d0fb3f5c1f11ae9af8dd51a 100644 --- a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/JoinerDeserializer.java +++ b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/JoinerDeserializer.java @@ -1,5 +1,27 @@ package org.duniter.core.client.model.bma.jackson; +/* + * #%L + * Duniter4j :: Core Client API + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; diff --git a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/RevokedDeserializer.java b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/RevokedDeserializer.java index b0ea88426e4189dce843e4e9fb7475fad0e09b60..25d418a858b973319185dbdfb7570ef70199a1de 100644 --- a/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/RevokedDeserializer.java +++ b/duniter4j-core-client/src/main/java/org/duniter/core/client/model/bma/jackson/RevokedDeserializer.java @@ -1,5 +1,27 @@ package org.duniter.core.client.model.bma.jackson; +/* + * #%L + * Duniter4j :: Core Client API + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; diff --git a/duniter4j-core-client/src/main/java/org/duniter/core/client/service/local/NetworkService.java b/duniter4j-core-client/src/main/java/org/duniter/core/client/service/local/NetworkService.java index 501b5a87f3c11e88eb4631dc6e84e49dd3a541b7..0cc7f547f6c694039bb59b01b950c484edfc2345 100644 --- a/duniter4j-core-client/src/main/java/org/duniter/core/client/service/local/NetworkService.java +++ b/duniter4j-core-client/src/main/java/org/duniter/core/client/service/local/NetworkService.java @@ -1,5 +1,27 @@ package org.duniter.core.client.service.local; +/* + * #%L + * Duniter4j :: Core Client API + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import org.duniter.core.beans.Service; import org.duniter.core.client.model.local.Peer; diff --git a/duniter4j-core-client/src/main/java/org/duniter/core/client/service/local/NetworkServiceImpl.java b/duniter4j-core-client/src/main/java/org/duniter/core/client/service/local/NetworkServiceImpl.java index 6d0d6679c5176639f82adaa3fbc32538501818e3..2834bb298e43936e11df39de184d47c51f995477 100644 --- a/duniter4j-core-client/src/main/java/org/duniter/core/client/service/local/NetworkServiceImpl.java +++ b/duniter4j-core-client/src/main/java/org/duniter/core/client/service/local/NetworkServiceImpl.java @@ -1,5 +1,27 @@ package org.duniter.core.client.service.local; +/* + * #%L + * Duniter4j :: Core Client API + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import com.fasterxml.jackson.databind.JsonNode; import com.google.common.collect.ImmutableList; import org.duniter.core.client.model.bma.Constants; diff --git a/duniter4j-core-shared/src/main/java/org/duniter/core/util/concurrent/CompletableFutures.java b/duniter4j-core-shared/src/main/java/org/duniter/core/util/concurrent/CompletableFutures.java index b0b78f91ae42fd04bdd2234d8968d971c0cede18..e7700d607ef5e394edf53bcf61d711f76e74df27 100644 --- a/duniter4j-core-shared/src/main/java/org/duniter/core/util/concurrent/CompletableFutures.java +++ b/duniter4j-core-shared/src/main/java/org/duniter/core/util/concurrent/CompletableFutures.java @@ -1,5 +1,27 @@ package org.duniter.core.util.concurrent; +/* + * #%L + * Duniter4j :: Core Shared + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; diff --git a/duniter4j-core-shared/src/main/java/org/duniter/core/util/http/InetAddressUtils.java b/duniter4j-core-shared/src/main/java/org/duniter/core/util/http/InetAddressUtils.java index b88050ef68d830a8cbda7a38c41177a87b36a6fc..5f2c60b61595d23153de0ef60c1ab05c3bd56733 100644 --- a/duniter4j-core-shared/src/main/java/org/duniter/core/util/http/InetAddressUtils.java +++ b/duniter4j-core-shared/src/main/java/org/duniter/core/util/http/InetAddressUtils.java @@ -1,5 +1,27 @@ package org.duniter.core.util.http; +/* + * #%L + * Duniter4j :: Core Shared + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import java.util.regex.Pattern; /** diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/i18n/I18nInitializer.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/i18n/I18nInitializer.java index 6517a675f32ed1f798100f6fb7c504fd1a7edcde..9adbe5f06b548ae9eae4ebfb498e113785e1e9ef 100644 --- a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/i18n/I18nInitializer.java +++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/i18n/I18nInitializer.java @@ -1,5 +1,27 @@ package org.duniter.elasticsearch.i18n; +/* + * #%L + * Duniter4j :: ElasticSearch Core plugin + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.i18n.bundle.I18nBundle; diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/model/Peer.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/model/Peer.java index 0ba62a06b5a12c589b2b6e1a34f3e6c6d0e00ccf..917b08187f23f634a32efa296197d13f703c2cc0 100644 --- a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/model/Peer.java +++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/model/Peer.java @@ -1,5 +1,27 @@ package org.duniter.elasticsearch.model; +/* + * #%L + * Duniter4j :: ElasticSearch Core plugin + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import java.io.Serializable; public class Peer implements Serializable { diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/model/SynchroResult.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/model/SynchroResult.java index d0cef017bc6ab3a2c2c127c8783bbd0a05e1fd60..51f6050560e4918e3280a0ae984f564f24269d8b 100644 --- a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/model/SynchroResult.java +++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/model/SynchroResult.java @@ -1,5 +1,27 @@ package org.duniter.elasticsearch.model; +/* + * #%L + * Duniter4j :: ElasticSearch Core plugin + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import java.util.HashMap; import java.util.Map; diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/security/RedirectionRestRequest.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/security/RedirectionRestRequest.java index 4462863e1a272c7705ee95d8fb725433bf916ad4..263c0cd613b44d4be208c6fb31e1e855dcfbce64 100644 --- a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/security/RedirectionRestRequest.java +++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/security/RedirectionRestRequest.java @@ -1,5 +1,27 @@ package org.duniter.elasticsearch.rest.security; +/* + * #%L + * Duniter4j :: ElasticSearch Core plugin + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.unit.ByteSizeValue; diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/threadpool/ScheduledActionFuture.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/threadpool/ScheduledActionFuture.java index 45819a977e09bd3df2c7580688e0b9cda3a5076c..473e807f6ea292a2ac1771538b3719ceb78d7743 100644 --- a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/threadpool/ScheduledActionFuture.java +++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/threadpool/ScheduledActionFuture.java @@ -1,5 +1,27 @@ package org.duniter.elasticsearch.threadpool; +/* + * #%L + * Duniter4j :: ElasticSearch Core plugin + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchTimeoutException; import org.elasticsearch.action.ActionFuture; diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/event/GchangeEventCodes.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/event/GchangeEventCodes.java index 445cdae0f3bdb026441edc98b83155795c5a26df..3ab5a4010ad98ba4e837ab0bf5fdea2c12f212e9 100644 --- a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/event/GchangeEventCodes.java +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/event/GchangeEventCodes.java @@ -1,5 +1,27 @@ package org.duniter.elasticsearch.gchange.model.event; +/* + * #%L + * Duniter4j :: ElasticSearch GChange plugin + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + /** * Created by blavenie on 01/12/16. */ diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/market/MarketRecord.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/market/MarketRecord.java index 499b3231956eb5deaa3076c0bc5b838a9d9bba9d..33ab56540dfbbe73a6eb7293277526cabcf813ca 100644 --- a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/market/MarketRecord.java +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/market/MarketRecord.java @@ -1,5 +1,27 @@ package org.duniter.elasticsearch.gchange.model.market; +/* + * #%L + * Duniter4j :: ElasticSearch GChange plugin + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import org.duniter.core.client.model.elasticsearch.Record; import java.util.HashMap; diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/registry/RegistryRecord.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/registry/RegistryRecord.java index dc93447d923616168e07e4eacc99b192d6ec2263..e04d30131b5d068909bff27913cd46a790bb5443 100644 --- a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/registry/RegistryRecord.java +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/registry/RegistryRecord.java @@ -1,5 +1,27 @@ package org.duniter.elasticsearch.gchange.model.registry; +/* + * #%L + * Duniter4j :: ElasticSearch GChange plugin + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import org.duniter.core.client.model.elasticsearch.Record; import java.util.HashMap; diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/AbstractService.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/AbstractService.java index 87b5fb67a48d1bf676ed9f16f158eb9e81ff5bf8..e394717a2eaec4c0d0633179fc1ed4d7cd22eabf 100644 --- a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/AbstractService.java +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/AbstractService.java @@ -1,5 +1,27 @@ package org.duniter.elasticsearch.gchange.service; +/* + * #%L + * Duniter4j :: ElasticSearch GChange plugin + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import org.duniter.core.service.CryptoService; import org.duniter.elasticsearch.gchange.PluginSettings; import org.elasticsearch.client.Client; diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/user/RestUserEventSearchAction.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/user/RestUserEventSearchAction.java index 57dc1e7c48f130e4e3c153b02e806efe689807f3..eccc64263e68d17f88e11d7b596bad8158913f91 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/user/RestUserEventSearchAction.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/user/RestUserEventSearchAction.java @@ -1,5 +1,27 @@ package org.duniter.elasticsearch.user.rest.user; +/* + * #%L + * Duniter4j :: ElasticSearch User plugin + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import org.duniter.elasticsearch.rest.security.RestSecurityController; import org.duniter.elasticsearch.user.service.UserEventService; import org.elasticsearch.common.inject.Inject; diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/AbstractService.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/AbstractService.java index cc5c6ed5aca25d6ef974ecb9b2c0a9c0a3aaa7f7..58555b9de9f77c11ee135d7dc719923aff64b804 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/AbstractService.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/AbstractService.java @@ -1,5 +1,27 @@ package org.duniter.elasticsearch.user.service; +/* + * #%L + * Duniter4j :: ElasticSearch User plugin + * %% + * Copyright (C) 2014 - 2017 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import org.duniter.core.service.CryptoService; import org.duniter.elasticsearch.user.PluginSettings; import org.elasticsearch.client.Client; diff --git a/pom.xml b/pom.xml index c5c5a9db4363cd31a6d667af45de2e10577fb8df..446da6f8318b6eabf8300826b65aa1e3680a5309 100644 --- a/pom.xml +++ b/pom.xml @@ -37,8 +37,10 @@ <junit.version>4.12</junit.version> <jetty.version>9.0.4.v20130625</jetty.version> + <!--license-maven-plugin config --> <maven.license.file>${project.basedir}/LICENSE</maven.license.file> + <license.licenseFile>${maven.license.file}</license.licenseFile> <license.useMissingFile>true</license.useMissingFile> <license.failIfWarning>true</license.failIfWarning> <license.organizationName>EIS</license.organizationName> @@ -51,6 +53,9 @@ <preparationGoals>verify</preparationGoals> <projectInfoReportsPluginVersion>2.7</projectInfoReportsPluginVersion> + <!-- Last JRE version to use --> + <jreVersion>1.8.77</jreVersion> + <jarPluginVersion>2.5</jarPluginVersion> <locales>en,fr</locales> @@ -100,11 +105,11 @@ <modules> <module>duniter4j-core-shared</module> <module>duniter4j-core-client</module> + <module>duniter4j-client</module> <module>duniter4j-es-core</module> <module>duniter4j-es-user</module> <module>duniter4j-es-gchange</module> <module>duniter4j-es-assembly</module> - <module>duniter4j-cmd</module> </modules> <scm> @@ -612,6 +617,9 @@ <licenseMerge> Lesser General Public License (LPGL)|GNU Lesser General Public License|GNU LESSER GENERAL PUBLIC LICENSE|LGPL|lgpl </licenseMerge> + <licenseMerge> + Lesser General Public License (LPGL) version 3.0|GNU General Lesser Public License (LGPL) version 3.0|LGPL_v3|lgpl_v3 + </licenseMerge> <licenseMerge> COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0|Common Development and Distribution License (CDDL) v1.0