-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Replace Legacy Architecture Model (#301)
* 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
Showing
117 changed files
with
619 additions
and
1,118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
...n/java/edu/kit/kastel/mcse/ardoco/core/api/models/LegacyModelExtractionStateByArCoTL.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
...ework/common/src/main/java/edu/kit/kastel/mcse/ardoco/core/api/models/ModelConnector.java
This file was deleted.
Oops, something went wrong.
3 changes: 1 addition & 2 deletions
3
...ardoco/core/models/ModelInstanceImpl.java → ...co/core/api/models/ModelInstanceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...rcotl/architecture/ArchitectureModel.java → .../api/models/arcotl/ArchitectureModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.