First Commit, ORM V1

This commit is contained in:
jeffcheasey88 2023-07-05 10:38:16 +02:00
commit 3f80808e9c
6 changed files with 115 additions and 0 deletions

7
.classpath Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="PeerAtCodeParser.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
.settings/
bin/
.project

BIN
PeerAtCodeParser.jar Normal file

Binary file not shown.

View file

@ -0,0 +1 @@
be.jeffcheasey88.peeratcode.mapping.TreasureProcessor

View file

@ -0,0 +1,12 @@
package be.jeffcheasey88.peeratcode.mapping;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface Treasure {
}

View file

@ -0,0 +1,92 @@
package be.jeffcheasey88.peeratcode.mapping;
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Messager;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic.Kind;
import javax.tools.FileObject;
import javax.tools.StandardLocation;
public class TreasureProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv){
Messager messager = processingEnv.getMessager();
for(TypeElement annotation : annotations){
for(Element element : roundEnv.getElementsAnnotatedWith(annotation)){
messager.printMessage(Kind.WARNING, "["+roundEnv.processingOver()+"] I tried", element);
for(Entry<String, String> opt : processingEnv.getOptions().entrySet()){
messager.printMessage(Kind.WARNING, opt.getKey()+" -> "+opt.getValue(), element);
}
File file = null;
try {
// FileObject resource = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", "");
// messager.printMessage(Kind.WARNING, resource.toUri().toString(), element);
// resource.delete();
FileObject resource = processingEnv.getFiler().getResource(StandardLocation.SOURCE_OUTPUT, "", "");
File clazz = new File(resource.toUri().toString().substring(6)+"/be/jeffcheasey88/peeratcode/model/Badge.class");
if(clazz.exists()){
messager.printMessage(Kind.WARNING, "["+roundEnv.processingOver()+"] I was created it", element);
return true;
}
file = new File(resource.toUri().toString().substring(6)+"/be/jeffcheasey88/peeratcode/model/Badge.java");
if(!file.exists()){
File parent = file.getParentFile();
if(!parent.exists()) parent.mkdirs();
file.createNewFile();
}
// JavaFileObject resource = processingEnv.getFiler().createSourceFile("be/jeffcheasey88/peeratcode/model/"+element.getSimpleName());
Writer writer = new FileWriter(file);
writer.append("package be.jeffcheasey88.peeratcode.model;\n\n");
writer.append("public class Badge{\n");
writer.append("public Badge(){ }\n");
writer.append("}\n");
writer.flush();
writer.close();
Process p = Runtime.getRuntime().exec("javac be/jeffcheasey88/peeratcode/model/Badge.java", new String[0], new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\.generated"));
p.waitFor();
file.delete();
// Runtime.getRuntime().exec("copy /Y \"C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\.generated\\be\\jeffcheasey88\\peeratcode\\model\\Badge.class\" \"./../bin/be/jeffcheasey88/peeratcode/model/Badge.class\"").waitFor();
messager.printMessage(Kind.WARNING, "["+roundEnv.processingOver()+"] We created it !", element);
} catch (Exception e) {
e.printStackTrace();
messager.printMessage(Kind.WARNING, "["+roundEnv.processingOver()+"] We not created it ! ("+file+") "+e.getMessage(), element);
}
}
}
return true;
}
@Override
public Set<String> getSupportedAnnotationTypes(){
return new HashSet<>(Arrays.asList(Treasure.class.getCanonicalName()));
}
@Override
public SourceVersion getSupportedSourceVersion(){
return SourceVersion.RELEASE_8;
}
}