mirror of
https://github.com/JHUAPL/Jackfruit.git
synced 2026-01-09 20:37:58 -05:00
Add JackfruitDemo
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
@@ -31,14 +32,13 @@
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/jackfruit"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
||||
<attributes>
|
||||
<attribute name="ignore_optional_problems" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="ignore_optional_problems" value="true"/>
|
||||
<attribute name="m2e-apt" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
|
||||
BIN
demo/jackfruit/demo/DemoConfigFactory$1.class
Normal file
BIN
demo/jackfruit/demo/DemoConfigFactory$1.class
Normal file
Binary file not shown.
BIN
demo/jackfruit/demo/DemoConfigFactory$2.class
Normal file
BIN
demo/jackfruit/demo/DemoConfigFactory$2.class
Normal file
Binary file not shown.
BIN
demo/jackfruit/demo/DemoConfigFactory.class
Normal file
BIN
demo/jackfruit/demo/DemoConfigFactory.class
Normal file
Binary file not shown.
75
demo/jackfruit/demo/DemoConfigFactory.java
Normal file
75
demo/jackfruit/demo/DemoConfigFactory.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package jackfruit.demo;
|
||||
|
||||
import jackfruit.processor.ConfigFactory;
|
||||
import java.lang.Double;
|
||||
import java.lang.Override;
|
||||
import java.lang.String;
|
||||
import org.apache.commons.configuration2.Configuration;
|
||||
import org.apache.commons.configuration2.PropertiesConfiguration;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public final class DemoConfigFactory implements ConfigFactory<DemoConfig> {
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
|
||||
@Override
|
||||
public PropertiesConfiguration toConfig(DemoConfig t) {
|
||||
PropertiesConfiguration config = new PropertiesConfiguration();
|
||||
config.setProperty("prefix.key", t.intMethod());
|
||||
config.setProperty("prefix.doubleMethod", t.doubleMethod());
|
||||
config.setProperty("prefix.StringMethod", t.StringMethod());
|
||||
SomeRandomClassParser randomClassparser = new SomeRandomClassParser();
|
||||
config.setProperty("prefix.randomClass", randomClassparser.toString(t.randomClass()));
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DemoConfig fromConfig(Configuration config) {
|
||||
return new DemoConfig() {
|
||||
/**
|
||||
* field comment
|
||||
*/
|
||||
public int intMethod() {
|
||||
return config.getInt("prefix.key");
|
||||
}
|
||||
|
||||
public Double doubleMethod() {
|
||||
return config.getDouble("prefix.doubleMethod");
|
||||
}
|
||||
|
||||
public String StringMethod() {
|
||||
return config.getString("prefix.StringMethod");
|
||||
}
|
||||
|
||||
public SomeRandomClass randomClass() {
|
||||
SomeRandomClassParser parser = new SomeRandomClassParser();
|
||||
return parser.fromString(config.getString("prefix.randomClass"));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public DemoConfig getTemplate() {
|
||||
return new DemoConfig() {
|
||||
/**
|
||||
* field comment
|
||||
*/
|
||||
public int intMethod() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Double doubleMethod() {
|
||||
return 0.;
|
||||
}
|
||||
|
||||
public String StringMethod() {
|
||||
return "Default String";
|
||||
}
|
||||
|
||||
public SomeRandomClass randomClass() {
|
||||
SomeRandomClassParser parser = new SomeRandomClassParser();
|
||||
return parser.fromString("serialized string");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
BIN
demo/src/main/java/jackfruit/demo/DemoConfig.class
Normal file
BIN
demo/src/main/java/jackfruit/demo/DemoConfig.class
Normal file
Binary file not shown.
@@ -46,7 +46,7 @@ import jackfruit.annotations.ParserClass;
|
||||
*/
|
||||
|
||||
@ConfigParams(prefix = "prefix")
|
||||
public interface ConfigTemplate {
|
||||
public interface DemoConfig {
|
||||
|
||||
// default key is field name
|
||||
@Key("key")
|
||||
BIN
demo/src/main/java/jackfruit/demo/JackfruitDemo.class
Normal file
BIN
demo/src/main/java/jackfruit/demo/JackfruitDemo.class
Normal file
Binary file not shown.
36
demo/src/main/java/jackfruit/demo/JackfruitDemo.java
Normal file
36
demo/src/main/java/jackfruit/demo/JackfruitDemo.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package jackfruit.demo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import org.apache.commons.configuration2.PropertiesConfiguration;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
|
||||
public class JackfruitDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// this factory is built by the annotation processor after reading the DemoConfig interface
|
||||
DemoConfigFactory factory = new DemoConfigFactory();
|
||||
|
||||
// get an example config object
|
||||
DemoConfig template = factory.getTemplate();
|
||||
|
||||
// generate an Apache PropertiesConfiguration object. This can be written out to a file
|
||||
PropertiesConfiguration config = factory.toConfig(template);
|
||||
|
||||
try {
|
||||
config.write(new PrintWriter(System.out));
|
||||
} catch (ConfigurationException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// create a config object from an Apache PropertiesConfiguration
|
||||
template = factory.fromConfig(config);
|
||||
|
||||
System.out.printf("config.StringMethod() = %s\n", template.StringMethod());
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
BIN
demo/src/main/java/jackfruit/demo/SomeRandomClass.class
Normal file
BIN
demo/src/main/java/jackfruit/demo/SomeRandomClass.class
Normal file
Binary file not shown.
@@ -2,4 +2,14 @@ package jackfruit.demo;
|
||||
|
||||
public class SomeRandomClass {
|
||||
|
||||
private String internalString;
|
||||
|
||||
public String getInternalString() {
|
||||
return internalString;
|
||||
}
|
||||
|
||||
public SomeRandomClass(String internalString) {
|
||||
this.internalString = internalString;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BIN
demo/src/main/java/jackfruit/demo/SomeRandomClassParser.class
Normal file
BIN
demo/src/main/java/jackfruit/demo/SomeRandomClassParser.class
Normal file
Binary file not shown.
@@ -1,22 +1,17 @@
|
||||
package jackfruit.demo;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import jackfruit.annotations.Parser;
|
||||
|
||||
public class SomeRandomClassParser implements Parser<SomeRandomClass> {
|
||||
|
||||
public static Logger logger = LogManager.getLogger();
|
||||
|
||||
@Override
|
||||
public SomeRandomClass fromString(String s) {
|
||||
logger.info("deserialize SomeRandomClass from " + s);
|
||||
return new SomeRandomClass();
|
||||
return new SomeRandomClass(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(SomeRandomClass src) {
|
||||
return "";
|
||||
return src.getInternalString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
BIN
demo/src/test/java/jackfruit/demo/TestProcessor.class
Normal file
BIN
demo/src/test/java/jackfruit/demo/TestProcessor.class
Normal file
Binary file not shown.
@@ -36,7 +36,7 @@ public class TestProcessor {
|
||||
System.out.println(System.getProperty("java.class.path"));
|
||||
*/
|
||||
|
||||
boolean ignore = true;
|
||||
boolean ignore = false;
|
||||
if (!ignore) {
|
||||
Log4j2Configurator lc = Log4j2Configurator.getInstance();
|
||||
lc.setPattern("%highlight{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%c{1}:%L] %msg%n%throwable}");
|
||||
|
||||
Reference in New Issue
Block a user