From ead3b44b7462b78c484a1221383139b9b4b51d6b Mon Sep 17 00:00:00 2001 From: "stephan.pirnbaum" Date: Wed, 31 Jul 2019 08:07:22 +0200 Subject: [PATCH] #26 moved configuration of cohesion criterion to cohesion descriptor and toggle cohesion criterion based on xml config --- .../core/framework/ClassificationRunner.java | 2 -- .../ClassificationConfigurationDescriptor.java | 17 ----------------- ...lassificationConfigurationMaterializer.java | 17 ++++++++++++----- .../framework/configuration/Optimization.java | 3 ++- .../cohesion/CohesionCriterionDescriptor.java | 18 ++++++++++++++++++ .../cohesion/CohesionCriterionExecutor.java | 16 +++++----------- 6 files changed, 37 insertions(+), 36 deletions(-) diff --git a/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/ClassificationRunner.java b/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/ClassificationRunner.java index 5195e84..b197b7a 100644 --- a/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/ClassificationRunner.java +++ b/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/ClassificationRunner.java @@ -2,7 +2,6 @@ import com.buschmais.sarf.core.framework.configuration.*; import com.buschmais.sarf.core.framework.repository.TypeRepository; -import com.buschmais.sarf.core.plugin.cohesion.CohesionCriterionDescriptor; import com.buschmais.xo.api.XOManager; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -42,7 +41,6 @@ public void startNewIteration(ClassificationConfigurationXmlMapper configuration this.xOManager.createQuery("MATCH (t:Type:Internal) REMOVE t:Internal").execute(); } ClassificationConfigurationDescriptor descriptor = materializer.materialize(configuration); - descriptor.getClassificationCriteria().add(this.xOManager.create(CohesionCriterionDescriptor.class)); this.xOManager.currentTransaction().commit(); this.setUpData(descriptor); this.executor.execute(descriptor); diff --git a/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/configuration/ClassificationConfigurationDescriptor.java b/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/configuration/ClassificationConfigurationDescriptor.java index 9505715..094610c 100644 --- a/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/configuration/ClassificationConfigurationDescriptor.java +++ b/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/configuration/ClassificationConfigurationDescriptor.java @@ -27,22 +27,6 @@ public interface ClassificationConfigurationDescriptor extends SARFDescriptor { Integer getIteration(); - void setDecomposition(Decomposition decomposition); - - Decomposition getDecomposition(); - - void setOptimization(Optimization optimization); - - Optimization getOptimization(); - - void setGenerations(Integer generations); - - Integer getGenerations(); - - void setPopulationSize(Integer populationSize); - - Integer getPopulationSize(); - void setTypeName(String typeName); String getTypeName(); @@ -55,5 +39,4 @@ public interface ClassificationConfigurationDescriptor extends SARFDescriptor { String getArtifact(); - } diff --git a/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/configuration/ClassificationConfigurationMaterializer.java b/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/configuration/ClassificationConfigurationMaterializer.java index 5dcbf4f..75cc920 100644 --- a/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/configuration/ClassificationConfigurationMaterializer.java +++ b/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/configuration/ClassificationConfigurationMaterializer.java @@ -3,10 +3,12 @@ import com.buschmais.sarf.core.framework.metamodel.ComponentDescriptor; import com.buschmais.sarf.core.framework.metamodel.ComponentXmlMapper; import com.buschmais.sarf.core.framework.repository.AnnotationResolver; -import com.buschmais.sarf.core.plugin.api.*; +import com.buschmais.sarf.core.plugin.api.ContainedIn; +import com.buschmais.sarf.core.plugin.api.Materializable; import com.buschmais.sarf.core.plugin.api.criterion.RuleBasedCriterionDescriptor; import com.buschmais.sarf.core.plugin.api.criterion.RuleDescriptor; import com.buschmais.sarf.core.plugin.api.criterion.RuleXmlMapper; +import com.buschmais.sarf.core.plugin.cohesion.CohesionCriterionDescriptor; import com.buschmais.xo.api.XOManager; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Lazy; @@ -33,10 +35,6 @@ public ClassificationConfigurationDescriptor materialize(ClassificationConfigura classificationConfigurationDescriptor.setBasePackage(mapper.basePackage); classificationConfigurationDescriptor.setTypeName(mapper.typeName); classificationConfigurationDescriptor.setArtifact(mapper.artifact); - classificationConfigurationDescriptor.setGenerations(mapper.generations); - classificationConfigurationDescriptor.setPopulationSize(mapper.populationSize); - classificationConfigurationDescriptor.setDecomposition(mapper.decomposition); - classificationConfigurationDescriptor.setOptimization(mapper.optimization); // materialize components Set componentDescriptors = @@ -56,6 +54,15 @@ public ClassificationConfigurationDescriptor materialize(ClassificationConfigura classificationCriterion.getRules().addAll(v); classificationConfigurationDescriptor.getClassificationCriteria().add(classificationCriterion); }); + // create cohesion criterion if configured + if (mapper.optimization != Optimization.NONE) { + CohesionCriterionDescriptor cohesionCriterionDescriptor = this.xoManager.create(CohesionCriterionDescriptor.class); + cohesionCriterionDescriptor.setGenerations(mapper.generations); + cohesionCriterionDescriptor.setPopulationSize(mapper.populationSize); + cohesionCriterionDescriptor.setDecomposition(mapper.decomposition); + cohesionCriterionDescriptor.setOptimization(mapper.optimization); + classificationConfigurationDescriptor.getClassificationCriteria().add(cohesionCriterionDescriptor); + } return classificationConfigurationDescriptor; } diff --git a/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/configuration/Optimization.java b/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/configuration/Optimization.java index d5041d9..95e0d85 100644 --- a/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/configuration/Optimization.java +++ b/sar-framework-core/src/main/java/com/buschmais/sarf/core/framework/configuration/Optimization.java @@ -8,5 +8,6 @@ @XmlEnum public enum Optimization { @XmlEnumValue("similarity") SIMILARITY, - @XmlEnumValue("coupling") COUPLING + @XmlEnumValue("coupling") COUPLING, + @XmlEnumValue("none") NONE } diff --git a/sar-framework-core/src/main/java/com/buschmais/sarf/core/plugin/cohesion/CohesionCriterionDescriptor.java b/sar-framework-core/src/main/java/com/buschmais/sarf/core/plugin/cohesion/CohesionCriterionDescriptor.java index c5a973f..4c3b76f 100644 --- a/sar-framework-core/src/main/java/com/buschmais/sarf/core/plugin/cohesion/CohesionCriterionDescriptor.java +++ b/sar-framework-core/src/main/java/com/buschmais/sarf/core/plugin/cohesion/CohesionCriterionDescriptor.java @@ -1,5 +1,7 @@ package com.buschmais.sarf.core.plugin.cohesion; +import com.buschmais.sarf.core.framework.configuration.Decomposition; +import com.buschmais.sarf.core.framework.configuration.Optimization; import com.buschmais.sarf.core.plugin.api.ExecutedBy; import com.buschmais.sarf.core.plugin.api.criterion.ClassificationCriterionDescriptor; import com.buschmais.xo.neo4j.api.annotation.Label; @@ -11,4 +13,20 @@ @Label("CohesionCriterion") public interface CohesionCriterionDescriptor extends ClassificationCriterionDescriptor { + void setDecomposition(Decomposition decomposition); + + Decomposition getDecomposition(); + + void setOptimization(Optimization optimization); + + Optimization getOptimization(); + + void setGenerations(Integer generations); + + Integer getGenerations(); + + void setPopulationSize(Integer populationSize); + + Integer getPopulationSize(); + } diff --git a/sar-framework-core/src/main/java/com/buschmais/sarf/core/plugin/cohesion/CohesionCriterionExecutor.java b/sar-framework-core/src/main/java/com/buschmais/sarf/core/plugin/cohesion/CohesionCriterionExecutor.java index 3f943c6..4b5cf84 100644 --- a/sar-framework-core/src/main/java/com/buschmais/sarf/core/plugin/cohesion/CohesionCriterionExecutor.java +++ b/sar-framework-core/src/main/java/com/buschmais/sarf/core/plugin/cohesion/CohesionCriterionExecutor.java @@ -1,8 +1,6 @@ package com.buschmais.sarf.core.plugin.cohesion; import com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor; -import com.buschmais.sarf.core.framework.configuration.ClassificationConfigurationDescriptor; -import com.buschmais.sarf.core.framework.configuration.ClassificationConfigurationRepository; import com.buschmais.sarf.core.framework.configuration.Decomposition; import com.buschmais.sarf.core.framework.configuration.Optimization; import com.buschmais.sarf.core.framework.metamodel.ComponentDescriptor; @@ -50,14 +48,10 @@ public Set execute(CohesionCriterionDescriptor descriptor, private Set execute(CohesionCriterionDescriptor descriptor, Map> initialPartitioning) { LOGGER.info("Partitioning the System"); - ClassificationConfigurationRepository classificationConfigurationRepository = - this.xOManager.getRepository(ClassificationConfigurationRepository.class); - ClassificationConfigurationDescriptor currentConfiguration = classificationConfigurationRepository.getCurrentConfiguration(); - Integer iteration = currentConfiguration.getIteration(); - boolean similarityBased = currentConfiguration.getOptimization() == Optimization.SIMILARITY; - boolean hierarchical = currentConfiguration.getDecomposition() == Decomposition.DEEP; - Integer generations = currentConfiguration.getGenerations(); - Integer populationSize = currentConfiguration.getPopulationSize(); + boolean similarityBased = descriptor.getOptimization() == Optimization.SIMILARITY; + boolean hierarchical = descriptor.getDecomposition() == Decomposition.DEEP; + Integer generations = descriptor.getGenerations(); + Integer populationSize = descriptor.getPopulationSize(); List tIds = getTypeIds(); long[] ids = tIds.stream().mapToLong(l -> l).toArray(); @@ -72,7 +66,7 @@ private Set execute(CohesionCriterionDescriptor descriptor, this.xOManager.currentTransaction().begin(); Map> partitioning = Partitioner.partition(ids, initialPartitioning, generations, populationSize, similarityBased); this.xOManager.currentTransaction().commit(); - Set identifiedGroups = materializeGroups(partitioning, iteration, componentLevel, !hierarchical); + Set identifiedGroups = materializeGroups(partitioning, descriptor.getIteration(), componentLevel, !hierarchical); if (!hierarchical) { this.xOManager.currentTransaction().begin(); Set res = new HashSet<>();