Commit a61b56a4 authored by Mathijs den Burger's avatar Mathijs den Burger

ESSENTIALS-978 Reintegrate bugfix/ESSENTIALS-978

parents cae538b3 90785574
......@@ -175,14 +175,21 @@ public class ContentBeansService {
continue;
}
}
log.info("@Missing declaration for: {}. Method will be deleted", internalName);
final boolean deleted = JavaSourceUtils.deleteMethod(method, path);
final String methodName = method.getMethodName();
if (deleted) {
context.addPluginContextData(CONTEXT_BEAN_DATA, new BeanWriterLogEntry(path.toString(), methodName, ActionType.DELETED_METHOD));
eventBus.post(new MessageEvent(String.format("Successfully deleted method: %s", methodName)));
final HippoEssentialsGeneratedObject annotation = JavaSourceUtils.getHippoEssentialsAnnotation(path, method.getMethodDeclaration());
final boolean allowUpdate = annotation != null && annotation.isAllowModifications();
if(allowUpdate) {
log.info("@Missing declaration for: {}. Method will be deleted", internalName);
final boolean deleted = JavaSourceUtils.deleteMethod(method, path);
final String methodName = method.getMethodName();
if (deleted) {
context.addPluginContextData(CONTEXT_BEAN_DATA, new BeanWriterLogEntry(path.toString(), methodName, ActionType.DELETED_METHOD));
eventBus.post(new MessageEvent(String.format("Successfully deleted method: %s", methodName)));
} else {
context.addPluginContextData(CONTEXT_BEAN_DATA, new BeanWriterLogEntry(String.format("Failed to delete method: %s", methodName)));
}
} else {
context.addPluginContextData(CONTEXT_BEAN_DATA, new BeanWriterLogEntry(String.format("Failed to delete method: %s", methodName)));
context.addPluginContextData(CONTEXT_BEAN_DATA, new BeanWriterLogEntry("Method should be removed, but modifications are disabled: "
+ method.getInternalName() + ", " + method.getMethodName()));
}
}
}
......@@ -624,6 +631,8 @@ public class ContentBeansService {
continue;
}
final ExistingMethodsVisitor methods = JavaSourceUtils.getMethodCollection(path);
final HippoEssentialsGeneratedObject annotation = JavaSourceUtils.getHippoGeneratedAnnotation(path);
final boolean allowUpdate = annotation != null && annotation.isAllowModifications();
final List<EssentialsGeneratedMethod> generatedMethods = methods.getGeneratedMethods();
for (EssentialsGeneratedMethod m : generatedMethods) {
final Type type = m.getMethodDeclaration().getReturnType2();
......@@ -633,13 +642,20 @@ public class ContentBeansService {
// check if image type and different than new return type
if (imageTypes.containsKey(returnType) && !returnType.equals(newReturnType)) {
log.info("Found image type: {}", returnType);
updateImageMethod(path, returnType, newReturnType, imageTypes.get(newReturnType));
if (allowUpdate) {
updateImageMethod(path, returnType, newReturnType, imageTypes.get(newReturnType));
} else{
context.addPluginContextData(CONTEXT_BEAN_DATA, new BeanWriterLogEntry("Method return type should be changed, but modifications are disabled: "
+ m.getInternalName() + ", " + m.getMethodName()));
}
}
} else if (JavaSourceUtils.getParameterizedType(type) != null) {
final String returnType = JavaSourceUtils.getParameterizedType(type);
if (imageTypes.containsKey(returnType) && !returnType.equals(newReturnType)) {
log.info("Found image type: {}", returnType);
updateImageMethod(path, returnType, newReturnType, imageTypes.get(newReturnType));
if (allowUpdate) {
updateImageMethod(path, returnType, newReturnType, imageTypes.get(newReturnType));
}
}
}
}
......@@ -739,14 +755,30 @@ public class ContentBeansService {
if (existing.contains(name)) {
log.debug("Property already exists {}. Checking if method signature has changed e.g. single value to multiple", name);
final ExistingMethodsVisitor methodCollection = JavaSourceUtils.getMethodCollection(beanPath);
final List<EssentialsGeneratedMethod> generatedMethods = methodCollection.getGeneratedMethods();
for (EssentialsGeneratedMethod generatedMethod : generatedMethods) {
final HippoEssentialsGeneratedObject annotation = JavaSourceUtils.getHippoEssentialsAnnotation(beanPath, generatedMethod.getMethodDeclaration());
final boolean allowUpdate = annotation != null && annotation.isAllowModifications();
final String internalName = generatedMethod.getInternalName();
if (name.equals(internalName)) {
// check if single/multiple changed:
if (generatedMethod.isMultiType() != multiple) {
log.info("Property changed (single/multiple): {}", internalName);
return JavaSourceUtils.deleteMethod(generatedMethod, beanPath);
if (allowUpdate) {
log.info("Property changed (single/multiple): {}", internalName);
return JavaSourceUtils.deleteMethod(generatedMethod, beanPath);
}else{
// there was a change, however, method is marked as read only
log.warn("Property changed (single/multiple): {}, but changes not allowed", internalName);
context.addPluginContextData(CONTEXT_BEAN_DATA, new BeanWriterLogEntry("Method return type should be changed, but modifications are disabled: "
+ internalName + ", " + generatedMethod.getMethodName()));
return false;
}
}
// TODO: check check if signature changed:
}
......
......@@ -999,6 +999,15 @@ public final class JavaSourceUtils {
return false;
}
public static HippoEssentialsGeneratedObject getHippoEssentialsAnnotation(final Path beanPath, final MethodDeclaration node) {
@SuppressWarnings({UNCHECKED, RAWTYPES})
final List modifiers = node.modifiers();
if (modifiers == null) {
return null;
}
return getGeneratedObject(modifiers, beanPath);
}
public static String getHippoEssentialsAnnotation(final MethodDeclaration node) {
@SuppressWarnings({UNCHECKED, RAWTYPES})
final List modifiers = node.modifiers();
......@@ -1038,6 +1047,10 @@ public final class JavaSourceUtils {
public static HippoEssentialsGeneratedObject getHippoGeneratedAnnotation(final Path path) {
@SuppressWarnings({UNCHECKED, RAWTYPES})
final List modifiers = getClassAnnotations(path);
return getGeneratedObject(modifiers, path);
}
private static HippoEssentialsGeneratedObject getGeneratedObject(final List modifiers, final Path path) {
for (Object modifier : modifiers) {
if (modifier instanceof NormalAnnotation) {
final NormalAnnotation annotation = (NormalAnnotation) modifier;
......@@ -1055,6 +1068,8 @@ public final class JavaSourceUtils {
private static HippoEssentialsGeneratedObject populateGeneratedObject(final Path path, final NormalAnnotation annotation) {
final HippoEssentialsGeneratedObject o = new HippoEssentialsGeneratedObject();
// set default:
o.setAllowModifications(true);
o.setFilePath(path);
@SuppressWarnings(RAWTYPES)
final List values = annotation.values();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment