Skip to content

Commit

Permalink
Skip creating a file if there are not custom types defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddie Carpenter committed Aug 23, 2024
1 parent b005c3b commit fe8cfa3
Showing 1 changed file with 58 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,60 +228,66 @@ public void process(String outputDir, List<String> classList) throws JPALiteTool
processClass(ctClass);
}//for

try (FileOutputStream outputStream = new FileOutputStream(outputDir + "/META-INF/persistenceUnits.properties");
FileOutputStream nativeImageStream = new FileOutputStream(outputDir + "/META-INF/native-image/org.jpalite.persistent/reflect-config.json")) {
nativeImageStream.write("[\n".getBytes());
boolean first = true;
for (Map.Entry<String, String> entry : entityClasses.entrySet()) {
outputStream.write(entry.getKey().getBytes());
outputStream.write('=');
outputStream.write(entry.getValue().getBytes());
outputStream.write('\n');

if (first) {
first = false;
} else {
nativeImageStream.write(',');
}//else

nativeImageStream.write("{\n\"name\": \"".getBytes());
nativeImageStream.write(entry.getValue().getBytes());
nativeImageStream.write(vAttrs.getBytes());

}

try (FileOutputStream converterStream = new FileOutputStream(outputDir + "/META-INF/services/org.jpalite.FieldConvertType")) {
for (CtClass convertClass : converterClasses) {

try {
converterStream.write(convertClass.getName().getBytes());
converterStream.write('\n');

if (first) {
first = false;
} else {
nativeImageStream.write(',');
}//else

nativeImageStream.write("{\n\"name\": \"".getBytes());
nativeImageStream.write(convertClass.getName().getBytes());
nativeImageStream.write(vAttrs.getBytes());

CtMethod convertToEntityAttribute = convertClass.getDeclaredMethod("convertToEntityAttribute");
if (convertToEntityAttribute != null) {
nativeImageStream.write(",{\n\"name\": \"".getBytes());
nativeImageStream.write(convertToEntityAttribute.getReturnType().getName().getBytes());
nativeImageStream.write(vAttrs.getBytes());
}
}
catch (Exception ex) {
LOG.error("Converter {} not correctly implemented", convertClass.getName());
}
}//for
boolean first = true;
if (!entityClasses.isEmpty() || !converterClasses.isEmpty()) {
try (FileOutputStream outputStream = new FileOutputStream(outputDir + "/META-INF/persistenceUnits.properties");
FileOutputStream nativeImageStream = new FileOutputStream(outputDir + "/META-INF/native-image/org.jpalite.persistent/reflect-config.json")) {
nativeImageStream.write("[\n".getBytes());

for (Map.Entry<String, String> entry : entityClasses.entrySet()) {
outputStream.write(entry.getKey().getBytes());
outputStream.write('=');
outputStream.write(entry.getValue().getBytes());
outputStream.write('\n');

if (first) {
first = false;
} else {
nativeImageStream.write(',');
}//else

nativeImageStream.write("{\n\"name\": \"".getBytes());
nativeImageStream.write(entry.getValue().getBytes());
nativeImageStream.write(vAttrs.getBytes());

}

if (!converterClasses.isEmpty()) {
try (FileOutputStream converterStream = new FileOutputStream(outputDir + "/META-INF/services/org.jpalite.FieldConvertType")) {
for (CtClass convertClass : converterClasses) {

try {
converterStream.write(convertClass.getName().getBytes());
converterStream.write('\n');

if (first) {
first = false;
} else {
nativeImageStream.write(',');
}//else

nativeImageStream.write("{\n\"name\": \"".getBytes());
nativeImageStream.write(convertClass.getName().getBytes());
nativeImageStream.write(vAttrs.getBytes());

CtMethod convertToEntityAttribute = convertClass.getDeclaredMethod("convertToEntityAttribute");
if (convertToEntityAttribute != null) {
nativeImageStream.write(",{\n\"name\": \"".getBytes());
nativeImageStream.write(convertToEntityAttribute.getReturnType().getName().getBytes());
nativeImageStream.write(vAttrs.getBytes());
}
}
catch (Exception ex) {
LOG.error("Converter {} not correctly implemented", convertClass.getName());
}
}//for
}//try

nativeImageStream.write(']');
}
}//try
}

nativeImageStream.write(']');
}//try
}//try
catch (NotFoundException ex) {
throw new JPALiteToolingException(ERROR_PROCESSING_FILE, ex);
Expand Down

0 comments on commit fe8cfa3

Please sign in to comment.