Compare commits

...

15 Commits
main ... dev

26 changed files with 1343 additions and 536 deletions

View File

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/scenarium-logger">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="out/eclipse/classes"/>
</classpath>

5
.gitignore vendored
View File

@ -1,3 +1,5 @@
/__pycache__/
# Compiled python modules. # Compiled python modules.
*.pyc *.pyc
@ -6,4 +8,5 @@
/build/ /build/
# Python egg metadata, regenerated from source files by setuptools. # Python egg metadata, regenerated from source files by setuptools.
/*.egg-info /*.egg-info
/target/

View File

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>atriasoft-death</name>
<comment></comment>
<projects>
<project>atriasoft-death</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
</projectDescription>

View File

@ -1 +0,0 @@
/classes/

119
pom.xml Normal file
View File

@ -0,0 +1,119 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.atriasoft</groupId>
<artifactId>death</artifactId>
<version>0.1.0</version>
<properties>
<maven.compiler.version>3.1</maven.compiler.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.dependency.version>3.1.1</maven.dependency.version>
</properties>
<repositories>
<repository>
<id>gitea</id>
<url>https://gitea.atria-soft.org/api/packages/org.atriasoft/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitea</id>
<url>https://gitea.atria-soft.org/api/packages/org.atriasoft/maven</url>
</repository>
<snapshotRepository>
<id>gitea</id>
<url>https://gitea.atria-soft.org/api/packages/org.atriasoft/maven</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.0-M2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.1.0-alpha1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test/src</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<!--<encoding>${project.build.sourceEncoding}</encoding>-->
</configuration>
</plugin>
<!-- Create the source bundle -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- junit results -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<!-- Java-doc generation for stand-alone site -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
</configuration>
</plugin>
</plugins>
</build>
<!-- Generate Java-docs As Part Of Project Reports -->
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<show>public</show>
</configuration>
</plugin>
</plugins>
</reporting>
</project>

View File

@ -4,7 +4,8 @@
open module org.atriasoft.death { open module org.atriasoft.death {
exports org.atriasoft.death; exports org.atriasoft.death;
exports org.atriasoft.death.annotation;
requires transitive io.scenarium.logger; requires transitive org.atriasoft.reggol;
requires java.base; requires java.base;
} }

View File

@ -0,0 +1,33 @@
package org.atriasoft.death;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.atriasoft.death.internal.Log;
public class ActionList {
private final Map<String, Class<?>> subActions = new HashMap<>();
public void add(final Class<?> clazz) {
final String name = PropertiesInterface.getCommand(clazz);
if (name == null || name.isEmpty()) {
LOGGER.error("Can not add an action without name. for: {}", clazz.getCanonicalName());
return;
}
this.subActions.put(name, clazz);
}
public boolean exist(final String value) {
return this.subActions.get(value) != null;
}
public Set<String> getActions() {
return this.subActions.keySet();
}
public Class<?> getInterface(final String action) {
return this.subActions.get(action);
}
}

View File

@ -1,127 +0,0 @@
package org.atriasoft.death;
import java.util.ArrayList;
import java.util.List;
record ArgChoice(String val, String description) {
}
/**
* @brief Declare a possibility of an argument value
*/
public class ArgDefine {
String option_small = "";
String option_big = "";
private List<ArgChoice> list = new ArrayList<>();
/**
* @brief Contructor.
* @param[in] this Class handle
* @param[in] smallOption (char) Value for the small option ex: '-v' '-k' ... 1 single char element (no need of '-')
* @param[in] bigOption (string) Value of the big option name ex: '--verbose' '--kill' ... stated with -- and with the full name (no need of '--')
* @param[in] list ([[string,string],...]) Optionnal list of availlable option: '--mode=debug' ==> [['debug', 'debug mode'],['release', 'release the software']]
* @param[in] desc (string) user friendly description with this parameter (default "")
* @param[in] haveParam (bool) The option must have a parameter (default False)
*/
public ArgDefine(
smallOption="",// like v for -v
bigOption="",// like verbose for --verbose
list=[],// ["val", "description"]
desc="",
haveParam=False):
this.option_small = smallOption;
this.option_big = bigOption;
this.list = list;
if len(this.list)!=0:
this.have_param = True
else:
if True==haveParam:
this.have_param = True
else:
this.have_param = False
this.description = desc;
public boolean is_parsable(this):
return True
/**
* @brief Get the small name of the option ex: '-v'
* @param[in] this Class handle
* @return (string) Small name value
*/
def get_option_small(this):
return this.option_small
/**
* @brief Get the big name of the option ex: '--verbose'
* @param[in] this Class handle
* @return (string) Big name value
*/
publis String get_option_big(this) {
return this.option_big
}
/**
* @brief Get the status of getting user parameter value
* @param[in] this Class handle
* @return True The user must write a value
* @return False The user must NOT write a value
*/
def need_parameters(this):
return this.have_param
/**
* @brief Compatibility with @ref ArgSection class
* @param[in] this Class handle
* @return (string) empty string
*/
def get_porperties(this):
return ""
/**
* @brief Check if the user added value is correct or not with the list of availlable value
* @param[in] this Class handle
* @param[in] argument (string) User parameter value (string)
* @return True The parameter is OK
* @return False The parameter is NOT Availlable
*/
def check_availlable(this, argument):
if len(this.list)==0:
return True
for element,desc in this.list:
if element == argument:
return True
return False
/**
* @brief Display the argument property when user request help
* @param[in] this Class handle
*/
def display(this):
color = debug.get_color_set()
if this.option_small != "" and this.option_big != "":
print(" " + color['red'] + "-" + this.option_small + "" + color['default'] + " / " + color['red'] + "--" + this.option_big + color['default'])
elif this.option_small != "":
print(" " + color['red'] + "-" + this.option_small + color['default'])
elif this.option_big != "":
print(" " + color['red'] + "--" + this.option_big + color['default'])
else:
print(" ???? ==> internal error ...")
if this.description != "":
print(" " + this.description)
if len(this.list)!=0:
hasDescriptiveElement=False
for val,desc in this.list:
if desc!="":
hasDescriptiveElement=True
break;
if hasDescriptiveElement==True:
for val,desc in this.list:
print(" " + val + " : " + desc)
else:
tmpElementPrint = ""
for val,desc in this.list:
if len(tmpElementPrint)!=0:
tmpElementPrint += " / "
tmpElementPrint += val
print(" { " + tmpElementPrint + " }")
}

View File

@ -0,0 +1,305 @@
package org.atriasoft.death;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.atriasoft.death.internal.Log;
public class ArgumentManager {
private final List<String> arguments = new ArrayList<>();
private final List<String> argumentResidual = new ArrayList<>();
private final List<String> argumentPostConfigure = new ArrayList<>();
private String actionDetected = null;
private final PropertiesInterface properties;
private final boolean enableStoreConfig;
public ArgumentManager(final String[] args, final Object tmp) {
this(args, tmp, false);
}
public ArgumentManager(final String[] args, final Object tmp, final boolean enableStoreConfig) {
this.enableStoreConfig = enableStoreConfig;
for (int iii = 0; iii < args.length; iii++) {
this.arguments.add(args[iii]);
}
this.properties = new PropertiesInterface(tmp.getClass());
if (this.enableStoreConfig) {
}
configure(tmp);
if (this.enableStoreConfig) {
}
}
private void configure(final Object tmp) {
boolean endParsing = false;
for (int iii = 0; iii < this.arguments.size(); iii++) {
final String value = this.arguments.get(iii);
if (endParsing) {
this.argumentResidual.add(value);
continue;
}
if (value.startsWith("--")) {
final String[] elements = value.split("=");
elements[0] = elements[0].substring(2);
LOGGER.trace("find element (--) : {}", Arrays.toString(elements));
final String parameter = elements[0];
String newValue = null;
if (!this.properties.existParameter(parameter)) {
LOGGER.error("Parameter Does not exist for '{}'", value);
showHelpAndExitError();
}
if (!this.properties.haveParameter(parameter)) {
// Boolean value
if (elements.length != 1) {
LOGGER.error("Boolean parameter can not have parameters for '{}", value);
showHelpAndExitError();
}
} else if (elements.length == 1) {
if (iii == this.arguments.size() - 1) {
LOGGER.error("Missing parameters for '{}' (no more arguments)", value);
showHelpAndExitError();
}
newValue = this.arguments.get(iii + 1);
if (newValue.startsWith("-")) {
LOGGER.error("Missing parameters for '{}' (next argument is a parameter (start with '-'))", value);
showHelpAndExitError();
}
iii++;
} else if (elements.length == 2) {
newValue = elements[1];
} else {
LOGGER.error("too much parameters for '{}' (only 1 = is authorized)", value);
showHelpAndExitError();
}
this.properties.setParameter(tmp, parameter, newValue);
} else if (value.startsWith("-")) {
final String[] elements = value.split("=");
elements[0] = elements[0].substring(1);
LOGGER.trace("find element (-) : {}", Arrays.toString(elements));
if (elements[0].length() != 1) {
LOGGER.error("Can not parse alias argument with a size != 1 for '{}'", value);
showHelpAndExitError();
}
final char parameter = elements[0].charAt(0);
String newValue = null;
if (!this.properties.existParameterAlias(parameter)) {
LOGGER.error("Parameter Does not exist for '{}'", value);
showHelpAndExitError();
}
if (!this.properties.haveParameterAlias(parameter)) {
// Boolean value
if (elements.length != 1) {
LOGGER.critical("Boolean parameter can not have parameters for '{}'", value);
showHelpAndExitError();
}
} else if (elements.length == 1) {
if (iii == this.arguments.size() - 1) {
LOGGER.error("Missing parameters for '{}' (no more arguments)", value);
showHelpAndExitError();
}
newValue = this.arguments.get(iii + 1);
if (newValue.startsWith("-")) {
LOGGER.error("Missing parameters for '{}' (next argument is a parameter (start with '-'))", value);
showHelpAndExitError();
}
iii++;
} else if (elements.length == 2) {
newValue = elements[1];
} else {
LOGGER.error("too much parameters for '{}' (only 1 = is authorized)", value);
showHelpAndExitError();
}
this.properties.setParameterAlias(tmp, parameter, newValue);
} else {
LOGGER.trace("find element ( ) : {}", value);
if (this.properties.actions != null && this.properties.actions.exist(value)) {
// Find end of parsing ...
endParsing = true;
this.actionDetected = value;
continue;
}
this.argumentPostConfigure.add(value);
}
}
}
public void executeAction() {
if (this.actionDetected == null) {
return;
}
final Class<?> actionClass = this.properties.getAction(this.actionDetected);
if (actionClass == null) {
return;
}
Object obj;
try {
obj = actionClass.getConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
final ArgumentManager localManager = new ArgumentManager(this.argumentResidual.toArray(new String[0]), obj);
//localManager.showHelp();
final int nbParameters = localManager.argumentPostConfigure.size();
final List<Method> executor = localManager.properties.getExecutor();
for (final Method exec : executor) {
if (nbParameters != exec.getParameterCount()) {
LOGGER.error("Rejected executor, {} nbParameter={} injected={}", exec.getName(), exec.getParameterCount(), nbParameters);
continue;
}
LOGGER.trace("find executor, {}", exec.getName());
try {
switch (nbParameters) {
case 0:
exec.invoke(obj);
break;
case 1:
exec.invoke(obj, //
localManager.argumentPostConfigure.get(0));
break;
case 2:
exec.invoke(obj, //
localManager.argumentPostConfigure.get(0), //
localManager.argumentPostConfigure.get(1));
break;
case 3:
exec.invoke(obj, //
localManager.argumentPostConfigure.get(0), //
localManager.argumentPostConfigure.get(1), //
localManager.argumentPostConfigure.get(2));
break;
case 4:
exec.invoke(obj, //
localManager.argumentPostConfigure.get(0), //
localManager.argumentPostConfigure.get(1), //
localManager.argumentPostConfigure.get(2), //
localManager.argumentPostConfigure.get(3));
break;
case 5:
exec.invoke(obj, //
localManager.argumentPostConfigure.get(0), //
localManager.argumentPostConfigure.get(1), //
localManager.argumentPostConfigure.get(2), //
localManager.argumentPostConfigure.get(3), //
localManager.argumentPostConfigure.get(4));
break;
case 6:
exec.invoke(obj, //
localManager.argumentPostConfigure.get(0), //
localManager.argumentPostConfigure.get(1), //
localManager.argumentPostConfigure.get(2), //
localManager.argumentPostConfigure.get(3), //
localManager.argumentPostConfigure.get(4), //
localManager.argumentPostConfigure.get(5));
break;
case 7:
exec.invoke(obj, //
localManager.argumentPostConfigure.get(0), //
localManager.argumentPostConfigure.get(1), //
localManager.argumentPostConfigure.get(2), //
localManager.argumentPostConfigure.get(3), //
localManager.argumentPostConfigure.get(4), //
localManager.argumentPostConfigure.get(5), //
localManager.argumentPostConfigure.get(6));
case 8:
exec.invoke(obj, //
localManager.argumentPostConfigure.get(0), //
localManager.argumentPostConfigure.get(1), //
localManager.argumentPostConfigure.get(2), //
localManager.argumentPostConfigure.get(3), //
localManager.argumentPostConfigure.get(4), //
localManager.argumentPostConfigure.get(5), //
localManager.argumentPostConfigure.get(6), //
localManager.argumentPostConfigure.get(7));
case 9:
exec.invoke(obj, //
localManager.argumentPostConfigure.get(0), //
localManager.argumentPostConfigure.get(1), //
localManager.argumentPostConfigure.get(2), //
localManager.argumentPostConfigure.get(3), //
localManager.argumentPostConfigure.get(4), //
localManager.argumentPostConfigure.get(5), //
localManager.argumentPostConfigure.get(6), //
localManager.argumentPostConfigure.get(7), //
localManager.argumentPostConfigure.get(8));
case 10:
exec.invoke(obj, //
localManager.argumentPostConfigure.get(0), //
localManager.argumentPostConfigure.get(1), //
localManager.argumentPostConfigure.get(2), //
localManager.argumentPostConfigure.get(3), //
localManager.argumentPostConfigure.get(4), //
localManager.argumentPostConfigure.get(5), //
localManager.argumentPostConfigure.get(6), //
localManager.argumentPostConfigure.get(7), //
localManager.argumentPostConfigure.get(8), //
localManager.argumentPostConfigure.get(9));
case 11:
exec.invoke(obj, //
localManager.argumentPostConfigure.get(0), //
localManager.argumentPostConfigure.get(1), //
localManager.argumentPostConfigure.get(2), //
localManager.argumentPostConfigure.get(3), //
localManager.argumentPostConfigure.get(4), //
localManager.argumentPostConfigure.get(5), //
localManager.argumentPostConfigure.get(6), //
localManager.argumentPostConfigure.get(7), //
localManager.argumentPostConfigure.get(8), //
localManager.argumentPostConfigure.get(9), //
localManager.argumentPostConfigure.get(10));
break;
default:
LOGGER.error("Does not manage more than 11 arguments");
break;
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public List<String> getArgumentDetected() {
return this.argumentPostConfigure;
}
public boolean hasArgumentDetected() {
return this.argumentPostConfigure.size() != 0;
}
public boolean hasDetectedAction() {
return this.actionDetected != null;
}
/**
* Display help of the global elements
*/
public void showHelp() {
this.properties.displayHelp();
}
/**
* Display help of the global elements and the help of each sub-actions
*/
public void showHelpAndExitError() {
showHelp();
System.exit(-2);
}
/**
* Display help of the global elements and the help of each sub-actions
*/
public void showHelpFull() {
this.properties.displayHelp(true);
}
}

View File

@ -1,151 +0,0 @@
package org.atriasoft.death;
//!/usr/bin/python
// -*- coding: utf-8 -*-
//#
//# @author Edouard DUPIN
//#
//# @copyright 2012, Edouard DUPIN, all right reserved
//#
//# @license MPL v2.0 (see license file)
//#
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
// Local import
import org.atriasoft.death.internal.Log;
public class Env {
public static final int ret_manifest_is_not_existing = -5;
public static final int ret_action_is_not_existing = -10;
public static final int ret_action_executing_system_error = -11;
public static final int ret_action_wrong_parameters = -12;
public static final int ret_action_partial_done = -13;
public static final int ret_action_fail = -14;
public static int ret_action_need_updtate = 15;
public static String system_base_name = "island";
public static void set_system_base_name(String val) {
system_base_name = val;
}
public static String get_system_base_name() {
return system_base_name;
}
public static String get_system_config_name() {
return "." + system_base_name + "Config.json";
}
private static boolean fetch_manifest = true;
public static void set_fetch_manifest(boolean val) {
fetch_manifest = val;
}
public static boolean get_fetch_manifest() {
return fetch_manifest;
}
private static int wait_between_sever_command = 0;
public static void set_wait_between_sever_command(int val) {
wait_between_sever_command = val;
}
public static int get_wait_between_sever_command() {
return wait_between_sever_command;
}
public static String filter_command = "";
public static void set_filter_command(String val) {
filter_command = val;
}
public static String get_filter_command() {
return filter_command;
}
public static boolean need_process_with_filter(String data) {
if (filter_command.equals("")) {
return true;
}
if (data.length() < filter_command.length()) {
return false;
}
if (data.substring(0,filter_command.length()).equals(filter_command)) {
return true;
}
return false;
}
private static boolean display_folder_instead_of_git_name = true;
public static void set_display_folder_instead_of_git_name(boolean val) {
display_folder_instead_of_git_name = val;
}
public static boolean get_display_folder_instead_of_git_name() {
return display_folder_instead_of_git_name;
}
private static Path island_root_path = null;
private static Path island_path_user_config = null;
private static Path island_path = null;
private static Path island_path_config_old = null;
private static Path island_path_config = null;
private static Path island_path_manifest = null;
static {
//String tmp = island_root_path.toAbsolutePath().toString();
//Log.info("Current absolute path is: " + tmp);
island_root_path = Paths.get("");
Path tmpPath = island_root_path;
while (!Files.isDirectory(tmpPath.resolve("." + get_system_base_name()))) {
tmpPath = tmpPath.getParent();
if (tmpPath == null) {
Log.critical("the root path of " + get_system_base_name() + " must not be upper parent paths of (" + island_root_path.toAbsolutePath() + ")");
}
}
island_root_path = tmpPath;
island_path_user_config = island_root_path.resolve(get_system_config_name());
island_path = island_root_path.resolve("." + get_system_base_name());
island_path_config_old = island_path.resolve("config.txt");
island_path_config = island_path.resolve("config.json");
island_path_manifest = island_path.resolve("manifest");
}
//#
//# @brief to use later to know where the ".island" parent path is ...
//# @return the parent path of the ".island"
//#
public static Path get_island_root_path() {
return island_root_path;
}
public static Path get_island_path() {
return island_path;
}
public static Path get_island_path_config() {
return island_path_config;
}
public static Path get_island_path_config_old() {
return island_path_config_old;
}
public static Path get_island_path_manifest() {
return island_path_manifest;
}
public static Path get_island_path_user_config() {
return island_path_user_config;
}
public static void main(String[] args) {
Log.error("island_root_path = " + island_root_path.toAbsolutePath());
Log.error("island_path_user_config = " + island_path_user_config.toAbsolutePath());
Log.error("island_path = " + island_path.toAbsolutePath());
Log.error("island_path_config_old = " + island_path_config_old.toAbsolutePath());
Log.error("island_path_config = " + island_path_config.toAbsolutePath());
Log.error("island_path_manifest = " + island_path_manifest.toAbsolutePath());
}
}

View File

@ -0,0 +1,116 @@
package org.atriasoft.death;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.atriasoft.death.internal.Log;
public class FieldProperty {
public record ChoiceElement(
String origin,
String destination) {}
public Field field;
public String name;
public Character alias;
public String description;
public String[] choice;
public Class<?>[] types;
public FieldProperty(final Field elem) {
try {
this.name = ReflectTools.getName(elem);
this.alias = ReflectTools.getAlias(elem);
this.description = ReflectTools.getDescription(elem);
this.choice = ReflectTools.getChoice(elem);
this.types = ReflectTools.getTypeField(elem);
if (this.name == null && this.alias == null) {
this.field = null;
}
this.field = elem;
} catch (final Exception e) {
this.name = null;
this.alias = null;
this.description = null;
this.choice = null;
final Class<?>[] types = null;
if (this.name == null && this.alias == null) {
this.field = null;
}
this.field = elem;
e.printStackTrace();
}
}
public String convertChoice(final String newValue) {
if (this.choice == null) {
return newValue;
}
final List<ChoiceElement> available = getChoiceList();
for (final ChoiceElement elem : available) {
if (elem.destination == null) {
if (elem.origin.contentEquals(newValue)) {
return newValue;
}
} else {
if (elem.origin.contentEquals(newValue)) {
return elem.destination;
}
if (elem.destination.contentEquals(newValue)) {
return elem.destination;
}
}
}
String list = null;
for (final ChoiceElement elem : available) {
if (list == null) {
list = "[";
} else {
list += ",";
}
list += elem;
}
list += "]";
LOGGER.critical("Can not find property '{}'in the choice values : {}", newValue, list);
return null;
}
List<ChoiceElement> getChoiceList() {
final List<ChoiceElement> out = new ArrayList<>();
for (final String value : this.choice) {
final String[] split = value.split(">>");
if (split.length == 1) {
out.add(new ChoiceElement(split[0], null));
} else {
out.add(new ChoiceElement(split[0], split[1]));
}
}
return out;
}
public boolean isValid() {
return this.field != null;
}
public void print() {
if (this.name != null) {
LOGGER.print("Detect element: --{}", this.name);
}
if (this.alias != null) {
LOGGER.print(" alias: -{}", this.alias);
}
if (this.types[1] == null) {
LOGGER.print(" type: {}", this.types[0].getCanonicalName());
} else {
LOGGER.print(" type: {} / {}", this.types[0].getCanonicalName(), this.types[1].getCanonicalName());
}
LOGGER.print(" description: {}", this.description);
if (this.choice != null) {
LOGGER.print(" choice: {}", Arrays.toString(this.choice));
}
}
}

View File

@ -1,185 +0,0 @@
package org.atriasoft.death;
public class MainIsland {
debug.verbose("List of actions: " + str(actions.get_list_of_action()))
my_args = arguments.Arguments()
my_args.add_section("option", "Can be set one time in all case")
my_args.add("h", "help", desc="Display this help")
my_args.add("v", "verbose", list=[
["0","None"],
["1","error"],
["2","warning"],
["3","info"],
["4","debug"],
["5","verbose"],
["6","extreme_verbose"],
], desc="display debug level (verbose) default =2")
my_args.add("c", "color", desc="Display message in color")
my_args.add("n", "no-fetch-manifest", haveParam=false, desc="Disable the fetch of the manifest")
my_args.add("F", "filter", haveParam=true, desc="Filter the action on a list of path or subpath: -f library")
my_args.add("f", "folder", haveParam=false, desc="Display the folder instead of the git repository name")
my_args.add("w", "wait", haveParam=true, desc="Wait between 2 acces on the server (needed when the server is really slow to remove ssh connection) (default=" + str(env.get_wait_between_sever_command()) + ")")
my_args.set_stop_at(actions.get_list_of_action())
local_argument = my_args.parse()
//
// @brief Display the help of this makefile.
//
public void usage():
color = debug.get_color_set()
// generic argument displayed :
my_args.display()
print(" Action availlable" )
list_actions = actions.get_list_of_action();
for elem in list_actions:
print(" " + color['green'] + elem + color['default'])
print(" " + actions.get_action_help(elem))
"""
print(" " + color['green'] + "init" + color['default'])
print(" initialize a 'island' interface with a manifest in a git ")
print(" " + color['green'] + "sync" + color['default'])
print(" Syncronise the currect environement")
print(" " + color['green'] + "status" + color['default'])
print(" Dump the status of the environement")
"""
print(" ex: " + sys.argv[0] + " -c init http://github.com/atria-soft/manifest.git")
print(" ex: " + sys.argv[0] + " sync")
exit(0)
public void check_boolean(value):
if value == "" \
or value == "1" \
or value == "true" \
or value == "true" \
or value == true:
return true
return false
// preparse the argument to get the verbose element for debug mode
public void parse_generic_arg(argument, active):
debug.extreme_verbose("parse arg : " + argument.get_option_name() + " " + argument.get_arg() + " active=" + str(active))
if argument.get_option_name() == "help":
if active == false:
usage()
return true
elif argument.get_option_name()=="jobs":
if active == true:
//multiprocess.set_core_number(int(argument.get_arg()))
pass
return true
elif argument.get_option_name()=="wait":
if active == true:
env.set_wait_between_sever_command(int(argument.get_arg()))
return true
elif argument.get_option_name() == "verbose":
if active == true:
debug.set_level(int(argument.get_arg()))
return true
elif argument.get_option_name() == "folder":
if active == true:
env.set_display_folder_instead_of_git_name(true)
return true
elif argument.get_option_name() == "color":
if active == true:
if check_boolean(argument.get_arg()) == true:
debug.enable_color()
else:
debug.disable_color()
return true
elif argument.get_option_name() == "filter":
if active == true:
env.set_filter_command(str(argument.get_arg()))
return true
elif argument.get_option_name() == "no-fetch-manifest":
if active == false:
env.set_fetch_manifest(false)
return true
return false
// open configuration of island:
config_file = env.get_island_path_user_config()
if os.path.isfile(config_file) == true:
sys.path.append(os.path.dirname(config_file))
debug.debug("Find basic configuration file: '" + config_file + "'")
// the file exist, we can open it and get the initial configuration:
configuration_file = __import__(env.get_system_config_name()[:-3])
if "get_exclude_path" in dir(configuration_file):
data = configuration_file.get_exclude_path()
debug.debug(" get default config 'get_exclude_path' val='" + str(data) + "'")
env.set_exclude_search_path(data)
if "get_default_color" in dir(configuration_file):
data = configuration_file.get_default_color()
debug.debug(" get default config 'get_default_color' val='" + str(data) + "'")
parse_generic_arg(arg_element.ArgElement("color", str(data)), true)
if "get_default_debug_level" in dir(configuration_file):
data = configuration_file.get_default_debug_level()
debug.debug(" get default config 'get_default_debug_level' val='" + str(data) + "'")
parse_generic_arg(arg_element.ArgElement("verbose", str(data)), true)
if "get_default_folder" in dir(configuration_file):
data = configuration_file.get_default_folder()
debug.debug(" get default config 'get_default_folder' val='" + str(data) + "'")
parse_generic_arg(arg_element.ArgElement("folder", str(data)), true)
if "get_default_wait" in dir(configuration_file):
data = configuration_file.get_default_wait()
debug.debug(" get default config 'get_default_wait' val='" + str(data) + "'")
parse_generic_arg(arg_element.ArgElement("wait", str(data)), true)
if "get_default_filter" in dir(configuration_file):
data = configuration_file.get_default_filter()
debug.debug(" get default config 'get_default_filter' val='" + str(data) + "'")
parse_generic_arg(arg_element.ArgElement("filter", str(data)), true)
// parse default unique argument:
for argument in local_argument:
parse_generic_arg(argument, true)
// remove all generic arguments:
new_argument_list = []
for argument in local_argument:
if parse_generic_arg(argument, false) == true:
continue
new_argument_list.append(argument)
// now the first argument is: the action:
if len(new_argument_list) == 0:
debug.warning("--------------------------------------")
debug.warning("Missing the action to do ...")
debug.warning("--------------------------------------")
usage()
// TODO : move tin in actions ...
list_actions = actions.get_list_of_action();
action_to_do = new_argument_list[0].get_arg()
new_argument_list = new_argument_list[1:]
if action_to_do not in list_actions:
debug.warning("--------------------------------------")
debug.warning("Wrong action type : '" + str(action_to_do) + "' availlable list: " + str(list_actions) )
debug.warning("--------------------------------------")
usage()
// todo : Remove this
if action_to_do != "init" \
and os.path.exists(env.get_island_path()) == false:
debug.error("Can not execute a island cmd if we have not initialize a config: '" + str("." + env.get_system_base_name()) + "' in upper 6 parent path")
exit(-1)
ret = actions.execute(action_to_do, my_args.get_last_parsed()+1)
exit (ret)
// stop all started threads;
//multiprocess.un_init()

View File

@ -0,0 +1,317 @@
package org.atriasoft.death;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.atriasoft.death.FieldProperty.ChoiceElement;
import org.atriasoft.death.internal.Log;
public class PropertiesInterface {
public static String getCommand(final Class<?> clazz) {
try {
return ReflectTools.getCommand(clazz);
} catch (final Exception ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
return null;
}
public static String getDescription(final Class<?> clazz) {
try {
return ReflectTools.getDescription(clazz);
} catch (final Exception ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
return null;
}
final List<FieldProperty> properties = new ArrayList<>();
ActionList actions = null;
final String classDescription;
final String classCommand;
final List<Method> executes = new ArrayList<>();
public PropertiesInterface(final Class<?> clazz) {
// ------------------------------------------------------------------------
// -- Find class description
// ------------------------------------------------------------------------
this.classDescription = PropertiesInterface.getDescription(clazz);
this.classCommand = PropertiesInterface.getCommand(clazz);
// ------------------------------------------------------------------------
// -- Find property Field
// ------------------------------------------------------------------------
final Field[] fields = clazz.getFields();
LOGGER.trace(" Fields: ({})", fields.length);
for (final Field elem : fields) {
// we does not manage static field
if (Modifier.isStatic(elem.getModifiers())) {
try {
final boolean subAction = ReflectTools.isSubAction(elem);
if (!subAction) {
continue;
}
final Class<?>[] type = ReflectTools.getTypeField(elem);
if (type[0] == ActionList.class) {
final Object data = elem.get(null);
if (data == null) {
LOGGER.error("set a @ArgSubActions on a wrong field");
} else if (data instanceof final ActionList tmp) {
this.actions = tmp;
}
}
} catch (final Exception e) {
LOGGER.error("get error on @ArgSubActions !!!");
e.printStackTrace();
}
continue;
}
// we does not manage private field
// NOTE: if the field is private I do not check the elements ==> the user want a private API !!! (maybe change ...)
if (!Modifier.isPublic(elem.getModifiers())) {
continue;
}
final FieldProperty element = new FieldProperty(elem);
if (!element.isValid()) {
continue;
}
if (element.types[0] == boolean.class || element.types[0] == Boolean.class || element.types[0] == int.class || element.types[0] == Integer.class || element.types[0] == short.class
|| element.types[0] == Short.class || element.types[0] == long.class || element.types[0] == Long.class || element.types[0] == float.class || element.types[0] == Float.class
|| element.types[0] == double.class || element.types[0] == Double.class || element.types[0] == String.class) {
// all is good
} else {
LOGGER.error("Can not manage other type than: [boolean,Boolean,String,int,Integer,long,Long,short,Short,float,Float,double,Double]");
}
this.properties.add(element);
//element.print();
}
// ------------------------------------------------------------------------
// -- find execution element
// ------------------------------------------------------------------------
final Method[] methods = clazz.getMethods();
for (final Method elem : methods) {
LOGGER.trace("Detect function : {}", elem.getName());
// we does not manage static field
if (Modifier.isStatic(elem.getModifiers())) {
continue;
}
// we does not manage private field
// NOTE: if the field is private I do not check the elements ==> the user want a private API !!! (maybe change ...)
if (!Modifier.isPublic(elem.getModifiers())) {
continue;
}
try {
if (ReflectTools.isExecutable(elem)) {
this.executes.add(elem);
}
} catch (final Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void displayHelp() {
displayHelp(false);
}
public void displayHelp(final boolean withActions) {
displayHelp(withActions, 0);
}
public void displayHelp(final boolean withActions, int baseIndent) {
if (baseIndent == 0) {
LOGGER.print("Usage:");
}
final StringBuilder applicationLine = new StringBuilder(spaces(4 + baseIndent));
if (baseIndent != 0) {
baseIndent += 4;
LOGGER.print("{}-----------------------------", spaces(baseIndent));
}
if (this.classCommand != null) {
applicationLine.append(this.classCommand).append(" ");
} else {
applicationLine.append("XXX ");
}
if (this.properties.size() != 0) {
applicationLine.append("[options] ");
}
if (this.actions != null && this.actions.getActions().size() != 0) {
applicationLine.append("<actions> [options-action]");
}
LOGGER.print(applicationLine.toString());
if (this.classDescription != null) {
LOGGER.print("{}{}", spaces(baseIndent), this.classDescription);
}
if (this.properties.size() != 0) {
LOGGER.print("{} [options]", spaces(baseIndent));
for (final FieldProperty prop : this.properties) {
final String parameterExpect = haveParameter(prop) ? " [PARAMETER]" : "";
if (prop.alias != null && prop.name != null) {
LOGGER.print("{} -{} / --{}{}", spaces(baseIndent), prop.alias, prop.name, parameterExpect);
} else if (prop.alias != null) {
LOGGER.print("{} -{}{}", spaces(baseIndent), prop.alias, parameterExpect);
} else if (prop.name != null) {
LOGGER.print("{} --{}{}", spaces(baseIndent), prop.name, parameterExpect);
}
if (prop.description != null) {
LOGGER.print("{} {}", spaces(baseIndent), prop.description);
}
if (prop.choice != null) {
for (final ChoiceElement elem : prop.getChoiceList()) {
if (elem.destination() == null) {
LOGGER.print("{} - {}", spaces(baseIndent), elem.origin());
} else {
LOGGER.print("{} - {} ==> {}", spaces(baseIndent), elem.origin(), elem.destination());
}
}
}
}
}
if (this.actions != null && this.actions.getActions().size() != 0) {
LOGGER.print("{} <actions>", spaces(baseIndent));
final Set<String> actions = this.actions.getActions();
int sizeOfActions = 0;
for (final String action : actions) {
sizeOfActions = Math.max(sizeOfActions, action.length());
}
for (final String action : actions) {
final Class<?> clazz = this.actions.getInterface(action);
if (!withActions) {
final String description = PropertiesInterface.getDescription(clazz);
if (description == null || description.isEmpty()) {
LOGGER.print("{} {}", spaces(baseIndent), action);
} else {
final String emptyString = spaces(sizeOfActions - action.length());
LOGGER.print("{} {}:{} {}", spaces(baseIndent), action, emptyString, description);
}
} else {
final PropertiesInterface tmpInterface = new PropertiesInterface(clazz);
tmpInterface.displayHelp(false, baseIndent + 4);
}
}
if (!withActions) {
LOGGER.print(" [options-action]");
LOGGER.print(" Action have theire specifi help. (add -h or --help after action)");
}
}
}
public boolean existParameter(final String parameterName) {
return findField(parameterName) != null;
}
public boolean existParameterAlias(final char parameterName) {
return findFieldAlias(parameterName) != null;
}
public FieldProperty findField(final String parameterName) {
for (final FieldProperty elem : this.properties) {
if (elem.name != null && elem.name.contentEquals(parameterName)) {
return elem;
}
}
return null;
}
public FieldProperty findFieldAlias(final char parameterName) {
for (final FieldProperty elem : this.properties) {
if (elem.alias != null && elem.alias == parameterName) {
return elem;
}
}
return null;
}
public Class<?> getAction(final String action) {
if (this.actions == null) {
return null;
}
return this.actions.getInterface(action);
}
public List<Method> getExecutor() {
return this.executes;
}
public boolean haveParameter(final FieldProperty field) {
if (field.types[0] == boolean.class || field.types[0] == Boolean.class) {
return false;
}
return true;
}
public boolean haveParameter(final String parameterName) {
final FieldProperty field = findField(parameterName);
return haveParameter(field);
}
public boolean haveParameterAlias(final char parameterName) {
final FieldProperty field = findFieldAlias(parameterName);
return haveParameter(field);
}
public List<FieldProperty> parseFields() {
return this.properties;
}
public void setParameter(final Object tmp, final String parameter, String newValue) {
try {
final FieldProperty property = findField(parameter);
newValue = property.convertChoice(newValue);
if (property.types[0] == boolean.class || property.types[0] == Boolean.class) {
//Boolean value = Boolean.valueOf(newValue);
//property.field.setBoolean(tmp, value);
property.field.setBoolean(tmp, true);
} else if (property.types[0] == int.class || property.types[0] == Integer.class) {
final Integer value = Integer.valueOf(newValue);
property.field.setInt(tmp, value);
} else if (property.types[0] == short.class || property.types[0] == Short.class) {
final Short value = Short.valueOf(newValue);
property.field.setShort(tmp, value);
} else if (property.types[0] == long.class || property.types[0] == Long.class) {
final Long value = Long.valueOf(newValue);
property.field.setLong(tmp, value);
} else if (property.types[0] == float.class || property.types[0] == Float.class) {
final Float value = Float.valueOf(newValue);
property.field.setFloat(tmp, value);
} else if (property.types[0] == double.class || property.types[0] == Double.class) {
final Double value = Double.valueOf(newValue);
property.field.setDouble(tmp, value);
} else if (property.types[0] == String.class) {
property.field.set(tmp, newValue);
} else {
// Impossible case !!!
LOGGER.critical("Dead code");
}
} catch (IllegalArgumentException | IllegalAccessException e) {
// TODO Auto-generated catch block
LOGGER.critical("Can not SET the value : {}: {}", parameter, newValue);
}
}
public void setParameterAlias(final Object tmp, final char parameter, final String newValue) {
final FieldProperty property = findFieldAlias(parameter);
setParameter(tmp, property.name, newValue);
}
/**
* Creates a string of spaces that is 'spaces' spaces long.
*
* @param spaces The number of spaces to add to the string.
*/
private String spaces(final int spaces) {
return CharBuffer.allocate(spaces).toString().replace('\0', ' ');
}
}

View File

@ -0,0 +1,207 @@
package org.atriasoft.death;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import org.atriasoft.death.annotation.ArgAlias;
import org.atriasoft.death.annotation.ArgChoice;
import org.atriasoft.death.annotation.ArgCommand;
import org.atriasoft.death.annotation.ArgDescription;
import org.atriasoft.death.annotation.ArgExecute;
import org.atriasoft.death.annotation.ArgName;
import org.atriasoft.death.annotation.ArgParams;
import org.atriasoft.death.annotation.ArgSample;
import org.atriasoft.death.annotation.ArgSubActions;
import org.atriasoft.death.internal.Log;
public class ReflectTools {
public static Character getAlias(final Field element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgAlias.class);
if (annotation.length == 0) {
return null;
}
if (annotation.length > 1) {
throw new Exception("Must not have more than 1 element @ArgAlias on " + element.getClass().getCanonicalName());
}
return ((ArgAlias) annotation[0]).value();
}
public static String[] getChoice(final Field element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgChoice.class);
if (annotation.length == 0) {
return null;
}
if (annotation.length > 1) {
throw new Exception("Must not have more than 1 element @ArgChoice on " + element.getClass().getCanonicalName());
}
return ((ArgChoice) annotation[0]).value();
}
public static String getCommand(final Class<?> clazz) throws Exception {
final Annotation[] annotation = clazz.getDeclaredAnnotationsByType(ArgCommand.class);
if (annotation.length == 0) {
return null;
}
if (annotation.length > 1) {
throw new Exception("Must not have more than 1 element @ArgCommand on " + clazz.getCanonicalName());
}
return ((ArgCommand) annotation[0]).value();
}
public static String getDescription(final Class<?> clazz) throws Exception {
final Annotation[] annotation = clazz.getDeclaredAnnotationsByType(ArgDescription.class);
if (annotation.length == 0) {
return null;
}
if (annotation.length > 1) {
throw new Exception("Must not have more than 1 element @ArgDescription on " + clazz.getCanonicalName());
}
return ((ArgDescription) annotation[0]).value();
}
public static String getDescription(final Field element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgDescription.class);
if (annotation.length == 0) {
return null;
}
if (annotation.length > 1) {
throw new Exception("Must not have more than 1 element @ArgDescription on " + element.getClass().getCanonicalName());
}
return ((ArgDescription) annotation[0]).value();
}
public static String getName(final Field element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgName.class);
if (annotation.length == 0) {
return null;
}
if (annotation.length > 1) {
throw new Exception("Must not have more than 1 element @ArgName on " + element.getClass().getCanonicalName());
}
return ((ArgName) annotation[0]).value();
}
public static String[] getParams(final Field element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgParams.class);
if (annotation.length == 0) {
return null;
}
if (annotation.length > 1) {
throw new Exception("Must not have more than 1 element @ArgParams on " + element.getClass().getCanonicalName());
}
return ((ArgParams) annotation[0]).value();
}
public static String[] getSample(final Field element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgSample.class);
if (annotation.length == 0) {
return null;
}
if (annotation.length > 1) {
throw new Exception("Must not have more than 1 element @ArgSample on " + element.getClass().getCanonicalName());
}
return ((ArgSample) annotation[0]).value();
}
public static Class<?>[] getTypeField(final Field fieldDescription) {
final Class<?> type = fieldDescription.getType();
Class<?> subType = null;
final Type empppe = fieldDescription.getGenericType();
if (empppe instanceof final ParameterizedType plopppppp) {
final Type[] realType = plopppppp.getActualTypeArguments();
if (realType.length > 0) {
try {
subType = Class.forName(realType[0].getTypeName());
} catch (final ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return new Class<?>[] { type, subType };
}
public static Class<?>[] getTypeParameterfunction(final Constructor<?> elem, final int paramId) throws ClassNotFoundException {
Class<?> type = null;
Class<?> subType = null;
type = elem.getParameters()[paramId].getType();
if (List.class.isAssignableFrom(type)) {
Class<?> internalModelClass = null;
final Type[] empppe = elem.getGenericParameterTypes();
if (empppe.length > paramId) {
if (empppe[paramId] instanceof final ParameterizedType plopppppp) {
final Type[] realType = plopppppp.getActualTypeArguments();
//LOGGER.info("ppplllppp: {}", realType.length);
if (realType.length > 0) {
LOGGER.warn(" -->> {}", realType[0]);
internalModelClass = Class.forName(realType[0].getTypeName());
}
}
}
subType = internalModelClass;
}
return new Class<?>[] { type, subType };
}
public static Class<?>[] getTypeParameterfunction(final Method setter) throws Exception {
Class<?> type = null;
Class<?> subType = null;
type = setter.getParameters()[0].getType();
if (List.class.isAssignableFrom(type)) {
Class<?> internalModelClass = null;
final Type[] empppe = setter.getGenericParameterTypes();
if (empppe.length > 0) {
if (empppe[0] instanceof final ParameterizedType plopppppp) {
final Type[] realType = plopppppp.getActualTypeArguments();
if (realType.length > 0) {
LOGGER.warn(" -->> {}", realType[0]);
internalModelClass = Class.forName(realType[0].getTypeName());
}
}
}
subType = internalModelClass;
}
return new Class<?>[] { type, subType };
}
public static Class<?>[] getTypeReturnFunction(/*@NotNull*/ final Method getter) throws Exception {
Class<?> type = null;
Class<?> subType = null;
type = getter.getReturnType();
if (!Enum.class.isAssignableFrom(type)) {
final Type empppe = getter.getGenericReturnType();
if (empppe instanceof final ParameterizedType plopppppp) {
final Type[] realType = plopppppp.getActualTypeArguments();
if (realType.length > 0) {
subType = Class.forName(realType[0].getTypeName());
}
}
}
return new Class<?>[] { type, subType };
}
public static boolean isExecutable(final Method element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgExecute.class);
if (annotation.length == 0) {
return false;
}
return true;
}
public static boolean isSubAction(final Field element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ArgSubActions.class);
if (annotation.length == 0) {
return false;
}
return true;
}
private ReflectTools() {}
}

View File

@ -0,0 +1,21 @@
package org.atriasoft.death.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marker annotation that can be used to define an other name of the attribute or the Element name.
*
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@DepthArgAnnotation
public @interface ArgAlias {
/**
* Short argument of this value (-n) (Without -)
* @return The short argument
*/
char value();
}

View File

@ -0,0 +1,21 @@
package org.atriasoft.death.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marker annotation that can be used to define an other name of the attribute or the Element name.
*
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@DepthArgAnnotation
public @interface ArgChoice {
/**
* List of available value with a transcription of type like : "warning>>45" ==> "45" and "warning" are both available, and warning is transformed in 45 when detected.
* @return list of available values
*/
String[] value();
}

View File

@ -0,0 +1,21 @@
package org.atriasoft.death.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marker annotation that can be used to define an other name of the attribute or the Element name.
*
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@DepthArgAnnotation
public @interface ArgCommand {
/**
* Short argument of this value (-n) (Without -)
* @return The short argument
*/
String value();
}

View File

@ -0,0 +1,21 @@
package org.atriasoft.death.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marker annotation that can be used to define an other name of the attribute or the Element name.
*
*/
@Target({ ElementType.FIELD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@DepthArgAnnotation
public @interface ArgDescription {
/**
* Short argument of this value (-n) (Without -)
* @return The short argument
*/
String value();
}

View File

@ -0,0 +1,17 @@
package org.atriasoft.death.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marker annotation that can be used to define an other name of the attribute or the Element name.
*
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@DepthArgAnnotation
public @interface ArgExecute {
}

View File

@ -0,0 +1,21 @@
package org.atriasoft.death.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marker annotation that can be used to define an other name of the attribute or the Element name.
*
*/
@Target( ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@DepthArgAnnotation
public @interface ArgName {
/**
* Names of the argument (--NyBeautifullName) (Without --)
* @return The name of the argument
*/
String value();
}

View File

@ -0,0 +1,21 @@
package org.atriasoft.death.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marker annotation that can be used to define an other name of the attribute or the Element name.
*
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@DepthArgAnnotation
public @interface ArgParams {
/**
* Names of the argument of the function
* @return The names of the arguments
*/
String[] value();
}

View File

@ -0,0 +1,21 @@
package org.atriasoft.death.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marker annotation that can be used to define an other name of the attribute or the Element name.
*
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@DepthArgAnnotation
public @interface ArgParamsDescription {
/**
* Names of the argument of the function
* @return The names of the arguments
*/
String[] value();
}

View File

@ -0,0 +1,21 @@
package org.atriasoft.death.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marker annotation that can be used to define an other name of the attribute or the Element name.
*
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@DepthArgAnnotation
public @interface ArgSample {
/**
* All sample available for the specific Command
* @return Descriptive string of the commands samples
*/
String[] value();
}

View File

@ -0,0 +1,13 @@
package org.atriasoft.death.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target( ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@DepthArgAnnotation
public @interface ArgSubActions {
}

View File

@ -0,0 +1,20 @@
package org.atriasoft.death.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Meta-annotation (annotations used on other annotations)
* used for marking all annotations that are
* part of Death package. Can be used for recognizing all
* Death annotations generically, and in future also for
* passing other generic annotation configuration.
*/
@Target(ElementType.ANNOTATION_TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface DepthArgAnnotation {
// for now, a pure tag annotation, no parameters
}

View File

@ -1,7 +1,7 @@
package org.atriasoft.death.internal; package org.atriasoft.death.internal;
import io.scenarium.logger.LogLevel; import org.atriasoft.reggol.LogLevel;
import io.scenarium.logger.Logger; import org.atriasoft.reggol.Logger;
public class Log { public class Log {
private static final String LIB_NAME = "death"; private static final String LIB_NAME = "death";
@ -15,12 +15,6 @@ public class Log {
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO); private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT); private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
public static void critical(final String data) {
if (PRINT_CRITICAL) {
Logger.critical(LIB_NAME_DRAW, data);
}
}
public static void critical(final String data, final Exception e) { public static void critical(final String data, final Exception e) {
e.printStackTrace(); e.printStackTrace();
if (PRINT_CRITICAL) { if (PRINT_CRITICAL) {
@ -28,45 +22,51 @@ public class Log {
} }
} }
public static void debug(final String data) { public static void critical(final String data, final Object... objects) {
if (PRINT_CRITICAL) {
Logger.critical(LIB_NAME_DRAW, data, objects);
}
}
public static void debug(final String data, final Object... objects) {
if (PRINT_DEBUG) { if (PRINT_DEBUG) {
Logger.debug(LIB_NAME_DRAW, data); Logger.debug(LIB_NAME_DRAW, data, objects);
} }
} }
public static void error(final String data) { public static void error(final String data, final Object... objects) {
if (PRINT_ERROR) { if (PRINT_ERROR) {
Logger.error(LIB_NAME_DRAW, data); Logger.error(LIB_NAME_DRAW, data, objects);
} }
} }
public static void info(final String data) { public static void info(final String data, final Object... objects) {
if (PRINT_INFO) { if (PRINT_INFO) {
Logger.info(LIB_NAME_DRAW, data); Logger.info(LIB_NAME_DRAW, data, objects);
} }
} }
public static void print(final String data) { public static void print(final String data, final Object... objects) {
if (PRINT_PRINT) { if (PRINT_PRINT) {
Logger.print(LIB_NAME_DRAW, data); Logger.print(LIB_NAME_DRAW, data, objects);
} }
} }
public static void todo(final String data) { public static void todo(final String data, final Object... objects) {
if (PRINT_TODO) { if (PRINT_TODO) {
Logger.todo(LIB_NAME_DRAW, data); Logger.todo(LIB_NAME_DRAW, data, objects);
} }
} }
public static void verbose(final String data) { public static void verbose(final String data, final Object... objects) {
if (PRINT_VERBOSE) { if (PRINT_VERBOSE) {
Logger.verbose(LIB_NAME_DRAW, data); Logger.verbose(LIB_NAME_DRAW, data, objects);
} }
} }
public static void warning(final String data) { public static void warning(final String data, final Object... objects) {
if (PRINT_WARNING) { if (PRINT_WARNING) {
Logger.warning(LIB_NAME_DRAW, data); Logger.warning(LIB_NAME_DRAW, data, objects);
} }
} }