Skip to content

Commit

Permalink
Feature: Replace Legacy Architecture Model (#301)
Browse files Browse the repository at this point in the history
* Use wrapping strategy for legacy model extraction state

Also upgrade to Java 21

* Initial Impl with Legacy SAM

* Access Type of Components

* Documentation about Java 21

* Fix issues that are not related to deprecation

* Fix bugs

* Bump versions

* Revert version bump of httpclient5

* Fix further code issues

* Remove NotNull annotations
  • Loading branch information
dfuchss authored Dec 4, 2023
1 parent d18dc0f commit 7992f41
Show file tree
Hide file tree
Showing 117 changed files with 619 additions and 1,118 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Future user interfaces like an enhanced GUI or a web interface are planned.

For more information about the setup or the architecture have a look on the [Wiki](https://github.com/ArDoCo/Core/wiki).
The docs are at some points deprecated, the general overview and setup should still hold.
You can find the generated JavaDocs at [ArDoCo.github.io/Core-Docs](https://ArDoCo.github.io/Core-Docs/).

## Case Studies / Benchmarks

Expand Down
4 changes: 2 additions & 2 deletions docs/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ JavaDocs can be found [here](https://ardoco.github.io/Core-Docs/).
The `complete` profile includes all the requirements that the special profiles also need. This profile is activated by
default.

All profiles require JDK 17.
All profiles require JDK 21.

The dependencies of the other profiles at a glance:

Expand Down Expand Up @@ -46,4 +46,4 @@ This project is currently developed by researchers of the Karlsruhe Institute of

You find us on our
websites: [Jan Keim](https://mcse.kastel.kit.edu/staff_Keim_Jan.php), [Sophie Corallo](https://mcse.kastel.kit.edu/staff_sophie_corallo.php),
and [Dominik Fuchß](https://mcse.kastel.kit.edu/staff_dominik_fuchss.php)
and [Dominik Fuchß](https://mcse.kastel.kit.edu/staff_dominik_fuchss.php)
4 changes: 2 additions & 2 deletions framework/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<dependency>
<groupId>org.apache.opennlp</groupId>
<artifactId>opennlp-tools</artifactId>
<version>2.3.0</version>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.collections</groupId>
Expand All @@ -58,7 +58,7 @@
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.44.0.0</version>
<version>3.44.1.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

/**
* The Interface IModelState defines the information directly extracted from the models.
*
* @deprecated use {@link ModelStates#getModel(String)}
*/
public interface ModelExtractionState extends IConfigurable {
@Deprecated(since = "0.32.0")
public interface LegacyModelExtractionState extends IConfigurable {
/**
* Returns the unique id of the model
*
Expand Down Expand Up @@ -53,6 +56,4 @@ public interface ModelExtractionState extends IConfigurable {
*/
ImmutableList<ModelInstance> getInstances();

void addAllOf(ModelExtractionState other);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/* Licensed under MIT 2023. */
package edu.kit.kastel.mcse.ardoco.core.api.models;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;

import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.SortedSets;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.set.sorted.ImmutableSortedSet;
import org.eclipse.collections.api.set.sorted.MutableSortedSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.ArchitectureModel;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.CodeModel;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureComponent;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureInterface;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureItem;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureMethod;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.*;

public class LegacyModelExtractionStateByArCoTL implements LegacyModelExtractionState {
private static final Logger logger = LoggerFactory.getLogger(LegacyModelExtractionStateByArCoTL.class);

private final String modelId;
private final Metamodel metamodel;

private final ImmutableList<ModelInstance> instances;

private final MutableSortedSet<String> instanceTypes;
private final MutableSortedSet<String> names;
private SortedMap<String, String> lastConfig;

public LegacyModelExtractionStateByArCoTL(ArchitectureModel architectureModel) {
this.modelId = architectureModel.getId();
this.instances = initArchitectureInstances(architectureModel);
this.metamodel = Metamodel.ARCHITECTURE;
instanceTypes = SortedSets.mutable.empty();
names = SortedSets.mutable.empty();
collectTypesAndNames();
}

public LegacyModelExtractionStateByArCoTL(CodeModel codeModel) {
this.modelId = codeModel.getId();
this.instances = initCodeInstances(codeModel);
this.metamodel = Metamodel.CODE;

instanceTypes = SortedSets.mutable.empty();
names = SortedSets.mutable.empty();
collectTypesAndNames();
}

private static ImmutableList<ModelInstance> initArchitectureInstances(ArchitectureModel architectureModel) {
MutableList<ModelInstance> instances = Lists.mutable.empty();
for (ArchitectureItem architectureItem : architectureModel.getEndpoints()) {
switch (architectureItem) {
case ArchitectureComponent component -> instances.add(new ModelInstanceImpl(component.getName(), component.getType(), component.getId()));
case ArchitectureInterface ignored -> logger.debug("Skipping .. ArchitectureInterface not supported yet");
case ArchitectureMethod ignored -> logger.debug("Skipping .. ArchitectureMethod not supported yet");
}
}
return instances.toImmutable();
}

private static ImmutableList<ModelInstance> initCodeInstances(CodeModel codeModel) {
List<ModelInstance> instances = new ArrayList<>();
fillPackages(codeModel.getAllPackages(), instances);
fillCompilationUnits(codeModel.getEndpoints(), instances);
return Lists.immutable.withAll(instances);
}

private static void fillPackages(Collection<? extends CodePackage> packages, List<ModelInstance> instances) {
for (var modelElement : packages) {
String path = modelElement.getName();
CodeModule parent = modelElement.getParent();
while (parent != null) {
path = parent.getName() + "/" + path;
parent = parent.getParent();
}
// Ensure that package is handled as directory
path += "/";
instances.add(new ModelInstanceImpl(modelElement.getName(), "Package", path));
}
}

private static void fillCompilationUnits(Collection<? extends CodeCompilationUnit> units, List<ModelInstance> instances) {
for (var unit : units) {
String type = findType(unit);
instances.add(new ModelInstanceImpl(unit.getName(), type, unit.getPath()));
}

}

private static String findType(CodeCompilationUnit unit) {
// Assumption mostly one class per unit
var content = unit.getContent().stream().filter(it -> unit.getName().contains(it.getName())).findFirst().orElse(null);
if (content instanceof ClassUnit) {
return "Class";
}
if (content instanceof InterfaceUnit) {
return "Interface";
}
if (unit.getPath().endsWith("package-info.java")) {
return "PackageInfo";
}
if (unit.getPath().endsWith(".java")) {
// Default to Class
return "Class";
}
if (unit.getLanguage() == ProgrammingLanguage.SHELL) {
return "ShellScript";
}
throw new IllegalStateException("Unknown type of CodeCompilationUnit");
}

private void collectTypesAndNames() {
for (ModelInstance i : instances) {
instanceTypes.addAll(i.getTypeParts().castToCollection());
names.addAll(i.getNameParts().castToCollection());
}
}

@Override
public String getModelId() {
return this.modelId;
}

@Override
public Metamodel getMetamodel() {
return this.metamodel;
}

@Override
public ImmutableList<ModelInstance> getInstancesOfType(String type) {
return instances.select(i -> i.getTypeParts().contains(type));
}

@Override
public ImmutableSortedSet<String> getInstanceTypes() {
return instanceTypes.toImmutable();
}

@Override
public ImmutableSortedSet<String> getNames() {
return names.toImmutable();
}

@Override
public ImmutableList<ModelInstance> getInstances() {
return instances;
}

@Override
public String toString() {
var output = new StringBuilder("Instances:\n");
for (ModelInstance i : instances) {
output.append(i.toString()).append("\n");
}
return output.toString();
}

@Override
public void applyConfiguration(SortedMap<String, String> additionalConfiguration) {
this.lastConfig = new TreeMap<>(additionalConfiguration);
}

@Override
public SortedMap<String, String> getLastAppliedConfiguration() {
return lastConfig;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* Licensed under MIT 2021-2023. */
package edu.kit.kastel.mcse.ardoco.core.models;
package edu.kit.kastel.mcse.ardoco.core.api.models;

import java.util.Objects;

import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.list.MutableList;

import edu.kit.kastel.mcse.ardoco.core.api.models.ModelInstance;
import edu.kit.kastel.mcse.ardoco.core.common.util.CommonUtilities;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,47 @@
import java.util.TreeMap;
import java.util.TreeSet;

import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.ArchitectureModel;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.CodeModel;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.Model;
import edu.kit.kastel.mcse.ardoco.core.data.PipelineStepData;

public class ModelStates implements PipelineStepData {
public static final String ID = "ModelStatesData";

private transient SortedMap<String, ModelExtractionState> modelExtractionStates = new TreeMap<>();
private transient SortedMap<String, Model> models = new TreeMap<>();
private transient SortedMap<String, LegacyModelExtractionState> legacyModels = new TreeMap<>();

/**
* Constructor to create a {@link ModelStates} object that holds all {@link ModelExtractionState}s
* Constructor to create a {@link ModelStates} object that holds all {@link LegacyModelExtractionState}s
*/
public ModelStates() {
super();
}

/**
* Returns the {@link ModelExtractionState} with the given id
* Returns the {@link LegacyModelExtractionState} with the given id
*
* @param id the id
* @return the corresponding {@link ModelExtractionState}
* @return the corresponding {@link LegacyModelExtractionState}
* @deprecated use {@link #getModel(String)} instead
*/
public ModelExtractionState getModelExtractionState(String id) {
return modelExtractionStates.get(id);
}
@Deprecated
public LegacyModelExtractionState getModelExtractionState(String id) {
if (legacyModels.containsKey(id))
return legacyModels.get(id);

/**
* Adds a {@link ModelExtractionState} with the given id to the set of {@link ModelExtractionState}s
*
* @param id the id
* @param modelState the {@link ModelExtractionState}
*/
public void addModelExtractionState(String id, ModelExtractionState modelState) {
modelExtractionStates.put(id, modelState);
}
var model = models.get(id);
if (model == null)
return null;

/**
* Return the set of IDs of all {@link ModelExtractionState ModelExtractionStates} that are contained within this object.
*
* @return the IDs of all contained {@link ModelExtractionState ModelExtractionStates}
*/
public SortedSet<String> extractionModelIds() {
return new TreeSet<>(modelExtractionStates.keySet());
var legacyModel = switch (model) {
case ArchitectureModel am -> new LegacyModelExtractionStateByArCoTL(am);
case CodeModel cm -> new LegacyModelExtractionStateByArCoTL(cm);
};

legacyModels.put(id, legacyModel);
return legacyModel;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* Licensed under MIT 2023. */
package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture;
package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl;

import java.util.List;

import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.Model;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.architecture.ArchitectureItem;

/**
* An architecture model that is an AMTL instance.
*/
public class ArchitectureModel extends Model {
public final class ArchitectureModel extends Model {

private final List<ArchitectureItem> content;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Licensed under MIT 2023. */
package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code;
package edu.kit.kastel.mcse.ardoco.core.api.models.arcotl;

import java.util.ArrayList;
import java.util.Comparator;
Expand All @@ -12,12 +12,15 @@
import com.fasterxml.jackson.annotation.JsonProperty;

import edu.kit.kastel.mcse.ardoco.core.api.models.Entity;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.Model;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeCompilationUnit;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeItem;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodeItemRepository;
import edu.kit.kastel.mcse.ardoco.core.api.models.arcotl.code.CodePackage;

/**
* A code model that is a CMTL instance.
*/
public class CodeModel extends Model {
public final class CodeModel extends Model {

@JsonProperty
private CodeItemRepository codeItemRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import edu.kit.kastel.mcse.ardoco.core.api.models.Entity;
import edu.kit.kastel.mcse.ardoco.core.api.models.ModelElement;

public abstract class Model extends ModelElement {
public abstract sealed class Model extends ModelElement permits ArchitectureModel, CodeModel {

/**
* Returns the content of this model.
Expand Down
Loading

0 comments on commit 7992f41

Please sign in to comment.