From 4f727effa26037580768eabd1474debd4d38a403 Mon Sep 17 00:00:00 2001 From: Frank Hossfeld Date: Fri, 5 Jan 2024 09:46:38 +0100 Subject: [PATCH] #347 fixed --- .github/workflows/build.yaml | 2 +- ...ow-runs.yaml => delete-workflow-runs.yaml} | 0 .../nalukit/nalu/processor/NaluProcessor.java | 11 ++- .../generator/ControllerGenerator.java | 12 +-- .../processor/generator/ModuleGenerator.java | 29 ++---- .../generator/PopUpControllerGenerator.java | 9 +- .../processor/generator/ShellGenerator.java | 13 +-- .../nalu/processor/model/MetaModel.java | 92 +++++++++++-------- pom.xml | 9 -- 9 files changed, 84 insertions(+), 93 deletions(-) rename .github/workflows/{delete-old-workflow-runs.yaml => delete-workflow-runs.yaml} (100%) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 4655cbf4..cca24b7a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -63,7 +63,7 @@ jobs: needs: test services: owasp-db: - image: philkohl/owasp-maven-action:latest + image: nalusolutionsgmbh/owasp-maven-action:latest options: --entrypoint /bin/sh --name owasp-db --hostname owasp-db steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/delete-old-workflow-runs.yaml b/.github/workflows/delete-workflow-runs.yaml similarity index 100% rename from .github/workflows/delete-old-workflow-runs.yaml rename to .github/workflows/delete-workflow-runs.yaml diff --git a/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/NaluProcessor.java b/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/NaluProcessor.java index 0071e6a2..9b133dc1 100644 --- a/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/NaluProcessor.java +++ b/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/NaluProcessor.java @@ -481,7 +481,7 @@ private void handleErrorPopUpControllerAnnotation(RoundEnvironment roundEnv) errorPopUpControllerModels.add(errorPopUpControllerModel); } // save data in metaModel - if (errorPopUpControllerModels.size() > 0) { + if (!errorPopUpControllerModels.isEmpty()) { this.metaModel.setErrorPopUpController(errorPopUpControllerModels.get(0)); } } @@ -845,9 +845,12 @@ private MetaModel restore() { .getResource(StandardLocation.CLASS_OUTPUT, "", this.createRelativeFileName()); - return gson.fromJson(resource.getCharContent(true) - .toString(), - MetaModel.class); + MetaModel model = gson.fromJson(resource.getCharContent(true) + .toString(), + MetaModel.class); + // clear working lists + model.clearGeneratedConditionList(); + return model; } catch (IOException e) { // every thing is ok -> no operation return null; diff --git a/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/ControllerGenerator.java b/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/ControllerGenerator.java index e6974e6d..9328746b 100644 --- a/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/ControllerGenerator.java +++ b/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/ControllerGenerator.java @@ -81,9 +81,8 @@ private void generateLoadControllers() { .getSimpleName() + ProcessorConstants.CREATOR_IMPL)); - if (controllerModel.getComposites() - .size() > 0) { - List generatedConditionClassNames = new ArrayList<>(); + if (!controllerModel.getComposites() + .isEmpty()) { controllerModel.getComposites() .forEach(controllerCompositeModel -> { if (AlwaysLoadComposite.class.getSimpleName() @@ -103,8 +102,7 @@ private void generateLoadControllers() { .getSimpleName()); } else { String conditionVariableName; - if (generatedConditionClassNames.contains(controllerCompositeModel.getCondition() - .getClassName())) { + if (this.metaModel.isCondtionAlreadyGenerated(controllerCompositeModel.getCondition())) { conditionVariableName = this.setFirstCharacterToLowerCase(controllerCompositeModel.getCondition() .getSimpleName()) + this.getNameWithVariableCount(controllerCompositeModel.getCondition(), @@ -114,7 +112,6 @@ private void generateLoadControllers() { .getSimpleName()) + this.getNameWithVariableCount(controllerCompositeModel.getCondition(), true); - loadComponentsMethodBuilder.addStatement("$T $L = new $T()", ClassName.get(controllerCompositeModel.getCondition() .getPackage(), @@ -128,8 +125,7 @@ private void generateLoadControllers() { .addStatement("$L.setContext(super.context)", conditionVariableName); // remember generated condition to avoid creating the same class again! - generatedConditionClassNames.add(controllerCompositeModel.getCondition() - .getClassName()); + this.metaModel.addGeneratedCondition(controllerCompositeModel.getCondition()); } loadComponentsMethodBuilder.addStatement("$T.INSTANCE.registerCondition($S, $S, $L)", ClassName.get(CompositeConditionFactory.class), diff --git a/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/ModuleGenerator.java b/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/ModuleGenerator.java index c625f6cb..f2212f28 100644 --- a/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/ModuleGenerator.java +++ b/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/ModuleGenerator.java @@ -190,9 +190,8 @@ private void generateLoadShellFactory(TypeSpec.Builder typeSpec) { .getSimpleName() + ProcessorConstants.CREATOR_IMPL)); - if (shellModel.getComposites() - .size() > 0) { - List generatedConditionClassNames = new ArrayList<>(); + if (!shellModel.getComposites() + .isEmpty()) { shellModel.getComposites() .forEach(controllerCompositeModel -> { if (AlwaysLoadComposite.class.getSimpleName() @@ -211,8 +210,7 @@ private void generateLoadShellFactory(TypeSpec.Builder typeSpec) { controllerCompositeModel.getComposite() .getSimpleName()); } else { - if (!generatedConditionClassNames.contains(controllerCompositeModel.getCondition() - .getClassName())) { + if (!this.metaModel.isCondtionAlreadyGenerated(controllerCompositeModel.getCondition())) { loadShellFactoryMethodBuilder.addStatement("$T $L = new $T()", ClassName.get(controllerCompositeModel.getCondition() .getPackage(), @@ -228,8 +226,7 @@ private void generateLoadShellFactory(TypeSpec.Builder typeSpec) { this.setFirstCharacterToLowerCase(controllerCompositeModel.getCondition() .getSimpleName())); // remember generated condition to avoid creating the same class again! - generatedConditionClassNames.add(controllerCompositeModel.getCondition() - .getClassName()); + this.metaModel.addGeneratedCondition(controllerCompositeModel.getCondition()); } loadShellFactoryMethodBuilder.addStatement("$T.INSTANCE.registerCondition($S, $S, $L)", ClassName.get(CompositeConditionFactory.class), @@ -293,9 +290,8 @@ private void generateLoadContollers(TypeSpec.Builder typeSpec) { .getSimpleName() + ProcessorConstants.CREATOR_IMPL)); - if (controllerModel.getComposites() - .size() > 0) { - List generatedConditionClassNames = new ArrayList<>(); + if (!controllerModel.getComposites() + .isEmpty()) { controllerModel.getComposites() .forEach(controllerCompositeModel -> { if (AlwaysLoadComposite.class.getSimpleName() @@ -314,8 +310,7 @@ private void generateLoadContollers(TypeSpec.Builder typeSpec) { controllerCompositeModel.getComposite() .getSimpleName()); } else { - if (!generatedConditionClassNames.contains(controllerCompositeModel.getCondition() - .getClassName())) { + if (!this.metaModel.isCondtionAlreadyGenerated(controllerCompositeModel.getCondition())) { loadComponentsMethodBuilder.addStatement("$T $L = new $T()", ClassName.get(controllerCompositeModel.getCondition() .getPackage(), @@ -331,8 +326,7 @@ private void generateLoadContollers(TypeSpec.Builder typeSpec) { this.setFirstCharacterToLowerCase(controllerCompositeModel.getCondition() .getSimpleName())); // remember generated condition to avoid creating the same class again! - generatedConditionClassNames.add(controllerCompositeModel.getCondition() - .getClassName()); + this.metaModel.addGeneratedCondition(controllerCompositeModel.getCondition()); } loadComponentsMethodBuilder.addStatement("$T.INSTANCE.registerCondition($S, $S, $L)", ClassName.get(CompositeConditionFactory.class), @@ -514,7 +508,6 @@ private void generateLoadPopUpControllers(TypeSpec.Builder typeSpec) { MethodSpec.Builder loadPopUpControllersMethod = MethodSpec.methodBuilder("loadPopUpControllers") .addAnnotation(Override.class) .addModifiers(Modifier.PUBLIC); - List generatedConditionClassNames = new ArrayList<>(); this.metaModel.getPopUpControllers() .forEach(popUpControllerModel -> { loadPopUpControllersMethod.addStatement("$T.INSTANCE.registerPopUpController($S, new $L(super.router, super.moduleContext, super.eventBus))", @@ -533,8 +526,7 @@ private void generateLoadPopUpControllers(TypeSpec.Builder typeSpec) { popUpControllerModel.getName()); } else { String conditionVariableName; - if (generatedConditionClassNames.contains(popUpControllerModel.getCondition() - .getClassName())) { + if (this.metaModel.isCondtionAlreadyGenerated(popUpControllerModel.getCondition())) { conditionVariableName = this.setFirstCharacterToLowerCase(popUpControllerModel.getCondition() .getSimpleName()) + this.getNameWithVariableCount(popUpControllerModel.getCondition(), @@ -558,8 +550,7 @@ private void generateLoadPopUpControllers(TypeSpec.Builder typeSpec) { .addStatement("$L.setContext(super.context)", conditionVariableName); // remember generated condition to avoid creating the same class again! - generatedConditionClassNames.add(popUpControllerModel.getCondition() - .getClassName()); + this.metaModel.addGeneratedCondition(popUpControllerModel.getCondition()); } loadPopUpControllersMethod.addStatement("$T.INSTANCE.registerCondition($S, $L)", ClassName.get(PopUpConditionFactory.class), diff --git a/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/PopUpControllerGenerator.java b/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/PopUpControllerGenerator.java index 989e32b7..c9dad451 100644 --- a/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/PopUpControllerGenerator.java +++ b/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/PopUpControllerGenerator.java @@ -26,9 +26,7 @@ import com.squareup.javapoet.TypeSpec; import javax.lang.model.element.Modifier; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; public class PopUpControllerGenerator { @@ -56,7 +54,6 @@ void generate() { MethodSpec.Builder loadPopUpControllerFactoryMethodBuilder = MethodSpec.methodBuilder("loadPopUpControllerFactory") .addModifiers(Modifier.PUBLIC) .addAnnotation(Override.class); - List generatedConditionClassNames = new ArrayList<>(); this.metaModel.getPopUpControllers() .forEach(popUpControllerModel -> { loadPopUpControllerFactoryMethodBuilder.addStatement("$T.INSTANCE.registerPopUpController($S, new $L(router, context, eventBus))", @@ -75,8 +72,7 @@ void generate() { popUpControllerModel.getName()); } else { String conditionVariableName; - if (generatedConditionClassNames.contains(popUpControllerModel.getCondition() - .getClassName())) { + if (this.metaModel.isCondtionAlreadyGenerated(popUpControllerModel.getCondition())) { conditionVariableName = this.setFirstCharacterToLowerCase(popUpControllerModel.getCondition() .getSimpleName()) + this.getNameWithVariableCount(popUpControllerModel.getCondition(), @@ -100,8 +96,7 @@ void generate() { .addStatement("$L.setContext(super.context)", conditionVariableName); // remember generated condition to avoid creating the same class again! - generatedConditionClassNames.add(popUpControllerModel.getCondition() - .getClassName()); + this.metaModel.addGeneratedCondition(popUpControllerModel.getCondition()); } loadPopUpControllerFactoryMethodBuilder.addStatement("$T.INSTANCE.registerCondition($S, $L)", ClassName.get(PopUpConditionFactory.class), diff --git a/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/ShellGenerator.java b/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/ShellGenerator.java index a3dae479..d269f3b2 100644 --- a/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/ShellGenerator.java +++ b/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/generator/ShellGenerator.java @@ -27,9 +27,7 @@ import com.squareup.javapoet.TypeSpec; import javax.lang.model.element.Modifier; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; public class ShellGenerator { @@ -96,9 +94,8 @@ private void generateLoadShellFactory() { .getSimpleName() + ProcessorConstants.CREATOR_IMPL)); - if (shellModel.getComposites() - .size() > 0) { - List generatedConditionClassNames = new ArrayList<>(); + if (!shellModel.getComposites() + .isEmpty()) { shellModel.getComposites() .forEach(controllerCompositeModel -> { if (AlwaysLoadComposite.class.getSimpleName() @@ -118,8 +115,7 @@ private void generateLoadShellFactory() { .getSimpleName()); } else { String conditionVariableName; - if (generatedConditionClassNames.contains(controllerCompositeModel.getCondition() - .getClassName())) { + if (this.metaModel.isCondtionAlreadyGenerated(controllerCompositeModel.getCondition())) { conditionVariableName = this.setFirstCharacterToLowerCase(controllerCompositeModel.getCondition() .getSimpleName()) + this.getNameWithVariableCount(controllerCompositeModel.getCondition(), @@ -143,8 +139,7 @@ private void generateLoadShellFactory() { .addStatement("$L.setContext(super.context)", conditionVariableName); // remember generated condition to avoid creating the same class again! - generatedConditionClassNames.add(controllerCompositeModel.getCondition() - .getClassName()); + this.metaModel.addGeneratedCondition(controllerCompositeModel.getCondition()); } loadShellFactoryMethodBuilder.addStatement("$T.INSTANCE.registerCondition($S, $S, $L)", ClassName.get(CompositeConditionFactory.class), diff --git a/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/model/MetaModel.java b/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/model/MetaModel.java index df338ea3..32d089f2 100644 --- a/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/model/MetaModel.java +++ b/nalu-processor/src/main/java/com/github/nalukit/nalu/processor/model/MetaModel.java @@ -36,53 +36,54 @@ public class MetaModel { - private String generateToPackage; - private ClassNameModel application; - private ClassNameModel loader; - private ClassNameModel postLoader; - private ClassNameModel customAlertPresenter; - private ClassNameModel customConfirmPresenter; - private final List modules; - private boolean usingHash; - private boolean usingColonForParametersInUrl; - private boolean stayOnSide; + private String generateToPackage; + private ClassNameModel application; + private ClassNameModel loader; + private ClassNameModel postLoader; + private ClassNameModel customAlertPresenter; + private ClassNameModel customConfirmPresenter; + private final List modules; + private boolean usingHash; + private boolean usingColonForParametersInUrl; + private boolean stayOnSide; /* this model represents the plugin interface */ /* is the model not null, we have to deal */ /* with a a plugin and not with application */ - private ModuleModel moduleModel; - private final List shells; - private ClassNameModel context; - private String startRoute; - private String illegalRouteTarget; - private ErrorPopUpControllerModel errorPopUpController; - private boolean hasPluginsAnnotation; - private boolean hasLoggerAnnotation; - private List controllers; - private List blockControllers; - private List parameterConstraintRules; - private List popUpControllers; - private TrackerModel tracker; - private List filters; - private List popUpFilters; - private List handlers; - private ClassNameModel componentType; - private final List compositeModels; - private ClassNameModel logger; - private ClassNameModel clientLogger; + private ModuleModel moduleModel; + private final List shells; + private ClassNameModel context; + private String startRoute; + private String illegalRouteTarget; + private ErrorPopUpControllerModel errorPopUpController; + private boolean hasPluginsAnnotation; + private boolean hasLoggerAnnotation; + private List controllers; + private List blockControllers; + private List parameterConstraintRules; + private List popUpControllers; + private TrackerModel tracker; + private List filters; + private List popUpFilters; + private List handlers; + private ClassNameModel componentType; + private final List compositeModels; + private ClassNameModel logger; + private ClassNameModel clientLogger; /* flag, that indicates, if a Nalu application */ /* uses a history token or not. */ - private boolean history; + private boolean history; /* Version of the applicaiton set by the */ /* Version annotation */ - private String applicationVersion; + private String applicationVersion; /* does the context extends */ /* AbstractModuleContext? */ - private boolean extendingIsModuleContext; + private boolean extendingIsModuleContext; /* do we have to remove the URL parameter */ /* from the URL */ - private boolean removeUrlParameterAtStart; + private boolean removeUrlParameterAtStart; /* list of used parameter constraints */ - private final List usedParameterConstraints; + private final List usedParameterConstraints; + private final List generatedConditions; public MetaModel() { this.modules = new ArrayList<>(); @@ -96,6 +97,7 @@ public MetaModel() { this.compositeModels = new ArrayList<>(); this.parameterConstraintRules = new ArrayList<>(); this.usedParameterConstraints = new ArrayList<>(); + this.generatedConditions = new ArrayList<>(); this.applicationVersion = "APPLCIATION-VERSION-NOT-AVAILABLE"; this.extendingIsModuleContext = false; @@ -362,7 +364,7 @@ public void addParameterConstraintUsing(ClassNameModel model) { .filter(m -> m.getClassName() .equals(model.getClassName())) .findFirst(); - if (!optional.isPresent()) { + if (optional.isEmpty()) { this.usedParameterConstraints.add(model); } } @@ -371,6 +373,24 @@ public List getUsedParameterConstraints() { return usedParameterConstraints; } + public void addGeneratedCondition(ClassNameModel condition) { + this.generatedConditions.add(condition); + } + + public void clearGeneratedConditionList() { + this.generatedConditions.clear(); + } + + public boolean isCondtionAlreadyGenerated(ClassNameModel condition) { + if (Objects.isNull(condition)) { + return false; + } + return this.generatedConditions.stream() + .map(ClassNameModel::getClassName) + .anyMatch(m -> condition.getClassName() + .equals(m)); + } + public TrackerModel getTracker() { return tracker; } diff --git a/pom.xml b/pom.xml index 31dbc113..423dfb71 100644 --- a/pom.xml +++ b/pom.xml @@ -62,15 +62,6 @@ Java Developer - - Philipp Kohl - philippkohl - contact@nalu-solutions.de - Nalu Solutions GmbH - - Java Developer - -