Skip to content

Commit

Permalink
#26 moved configuration of cohesion criterion to cohesion descriptor …
Browse files Browse the repository at this point in the history
…and toggle cohesion criterion based on xml config
  • Loading branch information
StephanPirnbaum committed Jul 31, 2019
1 parent e4ca572 commit ead3b44
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -55,5 +39,4 @@ public interface ClassificationConfigurationDescriptor extends SARFDescriptor {

String getArtifact();


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ComponentDescriptor> componentDescriptors =
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
@XmlEnum
public enum Optimization {
@XmlEnumValue("similarity") SIMILARITY,
@XmlEnumValue("coupling") COUPLING
@XmlEnumValue("coupling") COUPLING,
@XmlEnumValue("none") NONE
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -50,14 +48,10 @@ public Set<ComponentDescriptor> execute(CohesionCriterionDescriptor descriptor,

private Set<ComponentDescriptor> execute(CohesionCriterionDescriptor descriptor, Map<Long, Set<Long>> 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<Long> tIds = getTypeIds();
long[] ids = tIds.stream().mapToLong(l -> l).toArray();
Expand All @@ -72,7 +66,7 @@ private Set<ComponentDescriptor> execute(CohesionCriterionDescriptor descriptor,
this.xOManager.currentTransaction().begin();
Map<Long, Set<Long>> partitioning = Partitioner.partition(ids, initialPartitioning, generations, populationSize, similarityBased);
this.xOManager.currentTransaction().commit();
Set<Long> identifiedGroups = materializeGroups(partitioning, iteration, componentLevel, !hierarchical);
Set<Long> identifiedGroups = materializeGroups(partitioning, descriptor.getIteration(), componentLevel, !hierarchical);
if (!hierarchical) {
this.xOManager.currentTransaction().begin();
Set<ComponentDescriptor> res = new HashSet<>();
Expand Down

0 comments on commit ead3b44

Please sign in to comment.