Skip to content

Commit

Permalink
Merge pull request #3 from JakobGretenkort/main
Browse files Browse the repository at this point in the history
add capabilities to TraVarT and restructure interfaces
  • Loading branch information
coemgen1992 authored Aug 22, 2024
2 parents d5e5008 + 98e3ace commit 2a8c096
Show file tree
Hide file tree
Showing 18 changed files with 669 additions and 214 deletions.
9 changes: 5 additions & 4 deletions .factorypath
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<factorypathentry kind="VARJAR" id="M2_REPO/org/pf4j/pf4j/3.8.0/pf4j-3.8.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/github/zafarkhaja/java-semver/0.9.0/java-semver-0.9.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/de/vill/uvl-parser/1.0-SNAPSHOT/uvl-parser-1.0-SNAPSHOT.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/antlr/antlr4-runtime/4.7.1/antlr4-runtime-4.7.1.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/io/github/universal-variability-language/uvl-parser/0.3/uvl-parser-0.3.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/antlr/antlr4-runtime/4.13.1/antlr4-runtime-4.13.1.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/io/github/universal-variability-language/uvl-metamodel/1.0/uvl-metamodel-1.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/guava/31.0.1-jre/guava-31.0.1-jre.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar" enabled="true" runInBatchMode="false"/>
Expand All @@ -13,8 +14,8 @@
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/apache/logging/log4j/log4j-core/2.20.0/log4j-core-2.20.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/apache/logging/log4j/log4j-api/2.20.0/log4j-api-2.20.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/logicng/logicng/2.4.1/logicng-2.4.1.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/de/ovgu/featureide/lib.fm/3.9.1/lib.fm-3.9.1.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/logicng/logicng-j11/2.4.3/logicng-j11-2.4.3.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/de/ovgu/featureide/lib.fm/3.10.0/lib.fm-3.10.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/opt4j/opt4j-satdecoding/3.1.4/opt4j-satdecoding-3.1.4.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/ow2/sat4j/org.ow2.sat4j.pb/2.3.3/org.ow2.sat4j.pb-2.3.3.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/ow2/sat4j/org.ow2.sat4j.core/2.3.3/org.ow2.sat4j.core-2.3.3-tests.jar" enabled="true" runInBatchMode="false"/>
Expand Down
2 changes: 1 addition & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,4 @@
<property name="optional" value="true"/>
</module>
</module>
</module>
</module>
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.jku.cps</groupId>
<artifactId>travart-core</artifactId>
<version>1.1.0</version>
<version>2.0.0</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<javadoc.disabled>true</javadoc.disabled>
<deploy.disabled>true</deploy.disabled>
<source.disabled>true</source.disabled>
<checkstyle-maven-plugin.version>3.2.1</checkstyle-maven-plugin.version>
<checkstyle-maven-plugin.version>3.4.0</checkstyle-maven-plugin.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.pf4j/pf4j -->
Expand All @@ -23,8 +23,8 @@
</dependency>
<dependency>
<groupId>io.github.universal-variability-language</groupId>
<artifactId>uvl-parser</artifactId>
<version>0.3</version>
<artifactId>uvl-parser</artifactId>
<version>0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*******************************************************************************
* This Source Code Form is subject to the terms of the Mozilla
* Public License, v. 2.0. If a copy of the MPL was not distributed
* with this file, You can obtain one at
* https://mozilla.org/MPL/2.0/.
*
* Contributors:
* @author Jakob Gretenkort
*
* The base interface for obtaining statistical data of a variability artifact.
*
* Copyright 2023 Johannes Kepler University Linz
* LIT Cyber-Physical Systems Lab
* All rights reserved
*******************************************************************************/
package at.jku.cps.travart.core.basic;

import java.util.List;

import at.jku.cps.travart.core.common.IPrettyPrinter;
import at.jku.cps.travart.core.common.ISerializer;
import at.jku.cps.travart.core.exception.NotSupportedVariabilityTypeException;

/**
* A pretty printer that supports a text-based representation based on the
* serialization provided by an
* {@link at.jku.cps.travart.core.common.ISerializer}.
*/
public class DefaultPrettyPrinter<T> implements IPrettyPrinter<T> {
private final ISerializer<T> serializer;

/**
* Creates a default pretty printer.
*
* @param serializer the serializer which will provide the text-based
* representation of this printer. It must use a text-based and human
* readable format.
*/
public DefaultPrettyPrinter(ISerializer<T> serializer) {
this.serializer = serializer;
}

@Override
public List<REPRESENTATION> representations() {
return List.of(REPRESENTATION.TEXT);
}

@Override
public String toText(T model) throws NotSupportedVariabilityTypeException {
if(!serializer.getFormat().isText() || !serializer.getFormat().isHumanReadable()) {
throw new NotSupportedVariabilityTypeException(
"The default pretty printer could not be generated from the given serializer. " +
"The given serializer does not have a human-readable text-based format!"
);
}
return serializer.serialize(model);
}

@Override
public String[][] toTable(T model) throws NotSupportedVariabilityTypeException {
throw new NotSupportedVariabilityTypeException("The default pretty printer does not support tabular representation for any model.");
}

@Override
public String toSvg(T model) throws NotSupportedVariabilityTypeException {
throw new NotSupportedVariabilityTypeException("The default pretty printer does not support svg representation for any model.");
}

}
63 changes: 63 additions & 0 deletions src/main/java/at/jku/cps/travart/core/basic/UVL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* This Source Code Form is subject to the terms of the Mozilla
* Public License, v. 2.0. If a copy of the MPL was not distributed
* with this file, You can obtain one at
* https://mozilla.org/MPL/2.0/.
*
* Contributors:
* @author Kevin Feichtinger
* @author Prankur Agarwal
* @author Jakob Gretenkort
*
* An implementation of the universal variability language.
*
* Copyright 2023 Johannes Kepler University Linz
* LIT Cyber-Physical Systems Lab
* All rights reserved
*******************************************************************************/
package at.jku.cps.travart.core.basic;

import at.jku.cps.travart.core.FeatureModelStatistics;
import at.jku.cps.travart.core.common.IDeserializer;
import at.jku.cps.travart.core.common.ILanguage;
import at.jku.cps.travart.core.common.ISerializer;
import at.jku.cps.travart.core.common.IStatistics;
import at.jku.cps.travart.core.io.UVLDeserializer;
import at.jku.cps.travart.core.io.UVLSerializer;
import de.vill.model.FeatureModel;

/**
* An implementation of the universal variability language, providing
*/
public class UVL implements ILanguage<FeatureModel> {

@Override
public IDeserializer<FeatureModel> getDeserializer() {
return new UVLDeserializer();
}

@Override
public IStatistics<FeatureModel> getStatistics() {
return FeatureModelStatistics.getInstance();
}

@Override
public ISerializer<FeatureModel> getSerializer() {
return new UVLSerializer();
}

@Override
public String getName() {
return "Universal Variability Language";
}

@Override
public String getAbbreviation(){
return "UVL";
}

@Override
public Iterable<String> getSupportedFileExtensions() {
return getDeserializer().fileExtensions();
}
}
30 changes: 15 additions & 15 deletions src/main/java/at/jku/cps/travart/core/cli/TransformCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
import at.jku.cps.travart.core.common.IModelTransformer;
import at.jku.cps.travart.core.common.IModelTransformer.STRATEGY;
import at.jku.cps.travart.core.common.IPlugin;
import at.jku.cps.travart.core.common.IReader;
import at.jku.cps.travart.core.common.IWriter;
import at.jku.cps.travart.core.common.IDeserializer;
import at.jku.cps.travart.core.common.ISerializer;
import at.jku.cps.travart.core.exception.NotSupportedVariabilityTypeException;
import at.jku.cps.travart.core.exception.TransformationException;
import at.jku.cps.travart.core.helpers.TraVarTPluginManager;
import at.jku.cps.travart.core.io.FileUtils;
import at.jku.cps.travart.core.io.UVLReader;
import at.jku.cps.travart.core.io.UVLWriter;
import at.jku.cps.travart.core.io.UVLDeserializer;
import at.jku.cps.travart.core.io.UVLSerializer;
import de.vill.model.FeatureModel;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
Expand Down Expand Up @@ -81,8 +81,8 @@ private static String toStringList(final Iterable<String> fileExtensions) {
// "--validate" }, description = "Validate the resulting variability artifact as with the validate command.")
// private boolean validate;

private IReader reader;
private IWriter writer;
private IDeserializer deserializer;
private ISerializer serializer;
private final Queue<IModelTransformer> transformers = new LinkedList<>();

private boolean startUVL = false;
Expand Down Expand Up @@ -134,7 +134,7 @@ public Integer call() throws Exception {
private int initializeTransformations() {
if (CORE_MODEL_UVL.equalsIgnoreCase(sourceType)) {
LOGGER.debug("Deteced source type UVL...");
reader = new UVLReader();
deserializer = new UVLDeserializer();
startUVL = true;
} else {
IPlugin plugin = findPlugin(sourceType);
Expand All @@ -143,20 +143,20 @@ private int initializeTransformations() {
return 1;
}
LOGGER.debug(String.format("Deteced source type %s...", plugin.getName()));
reader = plugin.getReader();
deserializer = plugin.getDeserializer();
transformers.add(plugin.getTransformer());
}
if (CORE_MODEL_UVL.equalsIgnoreCase(targetType)) {
LOGGER.debug("Deteced target type UVL...");
writer = new UVLWriter();
serializer = new UVLSerializer();
} else {
IPlugin plugin = findPlugin(targetType);
if (plugin == null) {
LOGGER.error("Could not find plugin for given target type!");
return 2;
}
LOGGER.debug(String.format("Deteced target type %s...", plugin.getName()));
writer = plugin.getWriter();
serializer = plugin.getSerializer();
transformers.add(plugin.getTransformer());
}
return 0;
Expand All @@ -174,8 +174,8 @@ private static IPlugin findPlugin(final String type) {

private Integer transformDirectory() throws IOException, NotSupportedVariabilityTypeException {
Set<Path> files = new HashSet<>();
LOGGER.debug(String.format("Collect files of type %s...", toStringList(reader.fileExtensions())));
for (Object elem : reader.fileExtensions()) {
LOGGER.debug(String.format("Collect files of type %s...", toStringList(deserializer.fileExtensions())));
for (Object elem : deserializer.fileExtensions()) {
String extension = (String) elem;
Set<Path> filesFound = FileUtils.getPathSet(sourcePath, extension);
files.addAll(filesFound);
Expand All @@ -194,7 +194,7 @@ private Integer transformDirectory() throws IOException, NotSupportedVariability

private Integer transformSingleFile(final Path file) throws IOException, NotSupportedVariabilityTypeException {
LOGGER.debug(String.format("Start transforming file %s...", file.getFileName()));
Object model = reader.read(file);
Object model = deserializer.deserializeFromFile(file);
Object newModel = model;
boolean intermediate = false;
for (IModelTransformer transformer : transformers) {
Expand All @@ -207,9 +207,9 @@ private Integer transformSingleFile(final Path file) throws IOException, NotSupp
intermediate = true;
}
}
Path newPath = targetPath.resolve(file.getFileName() + writer.getFileExtension());
Path newPath = targetPath.resolve(file.getFileName() + serializer.getFileExtension());
LOGGER.debug(String.format("Write transformed file to %s...", newPath.toAbsolutePath()));
writer.write(newModel, newPath);
serializer.serializeToFile(newModel, newPath);
// if (validate) {
// LOGGER.debug("Validate the transformed model...");
// // TODO validate newModel with model
Expand Down
107 changes: 107 additions & 0 deletions src/main/java/at/jku/cps/travart/core/common/Format.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*******************************************************************************
* This Source Code Form is subject to the terms of the Mozilla
* Public License, v. 2.0. If a copy of the MPL was not distributed
* with this file, You can obtain one at
* https://mozilla.org/MPL/2.0/.
*
* Contributors:
* @author Jakob Gretenkort
*
* The base interface for obtaining statistical data of a variability artifact.
*
* Copyright 2023 Johannes Kepler University Linz
* LIT Cyber-Physical Systems Lab
* All rights reserved
*******************************************************************************/
package at.jku.cps.travart.core.common;

import java.util.Objects;

/**
* This class represents a data storage or serialization format in which a
* variability model might be represented.
*
* @author Jakob Gretenkort
*/
public class Format {
private final String name;
private final String extension;
private final boolean isText;
private final boolean isHumanReadable;

/**
* Create a format.
*
* @param name The name of the format.
* @param extension The file extension used when writing models to
* disk in this format.
* @param isText Whether the format is text-based.
* @param isHumanReadable Whether the format is human readable.
*/
public Format(String name, String extension, boolean isText, boolean isHumanReadable) {
this.name = name;
this.extension = extension;
this.isText = isText;
this.isHumanReadable = isHumanReadable;
}

/**
* The name of the format.
* @return the name of the format.
*/
public String name() {
return name;
}

/**
* The file extension used when writing models to disk in this format.
* @return the file extension used when writing models to disk in this format.
*/
public String extension() {
return extension;
}

/**
* Whether the format is text-based.
* @return whether the format is text-based.
*/
public boolean isText() {
return isText;
}

/**
* Whether the format is human readable.
* @return whether the format is human readable.
*/
public boolean isHumanReadable() {
return isHumanReadable;
}

@Override
public int hashCode() {
return Objects.hash(name, extension, isText, isHumanReadable);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (!(obj instanceof Format)) {
return false;
} else {
Format other = (Format) obj;
return Objects.equals(this.name, other.name) &&
Objects.equals(this.extension, other.extension) &&
Objects.equals(this.isText, other.isText) &&
Objects.equals(this.isHumanReadable, other.isHumanReadable);
}
}

@Override
public String toString() {
return "Format [name=" + this.name +
"extension=" + this.extension +
"isText=" + this.isText +
"isHumanReadable=" + this.isHumanReadable + "]";
}
}
Loading

0 comments on commit 2a8c096

Please sign in to comment.