Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
9368e21
updated JUnit from 5.9.0 to 5.10.0
Apr 25, 2025
c25b718
WIP Shell
Jun 3, 2025
71082d6
WIP(extensions ShellCommands ShellSession ShellScanner): implement ex…
Jun 23, 2025
a2181b5
progress
Nic-KL Jun 24, 2025
b519daf
implemented shell load commands
Nic-KL Jun 24, 2025
cb6674b
added extension point for load commands
Nic-KL Jun 24, 2025
a811055
removed unused classes and implemented a proper PrintShellCommand
Nic-KL Jun 24, 2025
5bc5955
added extension point for PrintShellCommand
Nic-KL Jun 24, 2025
aea349c
refactor: removed unnecessary classes
Nic-KL Jul 2, 2025
2a0d8b0
refactor: changed names to more meaningful ones
Nic-KL Jul 2, 2025
da6ca44
feat : new shell commands
Nic-KL Jul 2, 2025
6f416eb
fix: removed old class extension
Nic-KL Jul 2, 2025
e2f7b40
feat: added appropriate shortnames
Nic-KL Jul 2, 2025
a696b4f
feat: shortnames for print
Nic-KL Jul 2, 2025
d228f60
feat: added getDescription
Nic-KL Jul 2, 2025
721865b
feat: added getDescription
Nic-KL Jul 2, 2025
73b1282
refactor: removed duplicated code and simplified some method calls
Nic-KL Jul 2, 2025
7a227d2
style: comments and unused code
Nic-KL Jul 2, 2025
57131e9
refactor: removed unused contructors
Nic-KL Jul 2, 2025
c96dd84
fix: added missing Annotation for getDescription
Nic-KL Jul 2, 2025
2492802
feat(Shellcommands): added help, print, clear
Nic-KL Jul 19, 2025
87b361d
feat(StringFormats): added various string formats for LoadShellCommand
Nic-KL Jul 19, 2025
a8c4149
fix(creates now a correct HelpShellCommand)
Nic-KL Jul 19, 2025
4e8fcfc
progress
Nic-KL Aug 9, 2025
2312bed
progress
Nic-KL Oct 4, 2025
f3c01ed
progress
Nic-KL Oct 5, 2025
21c0306
progress
Nic-KL Oct 6, 2025
52a0eb9
progress
Nic-KL Oct 7, 2025
0ea0047
progress
Nic-KL Oct 9, 2025
c168d91
progress
Nic-KL Oct 9, 2025
99f0d19
feat: LoadPah
Nic-KL Oct 13, 2025
eb4af29
chore: delete useless file
Nic-KL Oct 14, 2025
28e80c1
fix: use correct extension point
Nic-KL Oct 14, 2025
5100a15
fix: use correct info instead of message
Nic-KL Oct 14, 2025
6aac49f
chore: deleted useless file
Nic-KL Oct 14, 2025
ac609b6
fix: adjusted format, refactor name
Nic-KL Oct 14, 2025
f8ac5ef
chore: small naming improvements
Nic-KL Oct 24, 2025
1ef1f24
style: removed todo
Nic-KL Oct 24, 2025
48fbedb
feat: Added a type selection for every format
Nic-KL Oct 30, 2025
cf2cd56
fix: small textual improvements
Nic-KL Oct 30, 2025
dd86b2a
feat: small help info improvements
Nic-KL Oct 30, 2025
4e4af8f
fix: align descriptions of shellcommands
Nic-KL Oct 31, 2025
c6535db
refactor: changed format names and changed the extension configuratio…
Nic-KL Nov 6, 2025
9964d28
style: formatting
Nic-KL Nov 7, 2025
cc878b4
refactor-fix: naming changes and fixed format issue
Nic-KL Nov 10, 2025
70131e2
refactor: remove unnecessary format
Nic-KL Nov 10, 2025
5484234
refactor-docs: adjusted naming, typos and descriptions
Nic-KL Nov 11, 2025
bcb1db8
refactor-fix: switched from optional to result, fixed error handling …
Nic-KL Nov 11, 2025
0500f54
refactor: clearer naming of some methods
Nic-KL Nov 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ plugins {
dependencies {
api 'de.featjar:formula'
api testFixtures('de.featjar:formula')
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
// testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

license {
Expand Down
167 changes: 167 additions & 0 deletions src/main/java/de/featjar/feature/model/ALoadShellCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* Copyright (C) 2025 FeatJAR-Development-Team
*
* This file is part of FeatJAR-feature-model.
*
* feature-model is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License,
* or (at your option) any later version.
*
* feature-model is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with feature-model. If not, see <https://www.gnu.org/licenses/>.
*
* See <https://github.com/FeatureIDE/FeatJAR-feature-model> for further information.
*/
package de.featjar.feature.model;

import de.featjar.base.FeatJAR;
import de.featjar.base.data.Problem;
import de.featjar.base.data.Result;
import de.featjar.base.io.IO;
import de.featjar.base.io.format.AFormats;
import de.featjar.base.log.Log.Verbosity;
import de.featjar.base.shell.IShellCommand;
import de.featjar.base.shell.Shell;
import de.featjar.base.shell.ShellSession;
import de.featjar.formula.assignment.BooleanAssignment;
import de.featjar.formula.assignment.BooleanAssignmentGroups;
import de.featjar.formula.assignment.BooleanAssignmentList;
import de.featjar.formula.structure.IFormula;
import java.nio.file.Paths;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
* The abstract class for any shell command that loads formats into the shell.
*
* @author Niclas Kleinert
*/
public abstract class ALoadShellCommand implements IShellCommand {

/**
* {@return a format name that is used for prompts}
*/
protected abstract Optional<String> getFormatName();

/**
* {@return the default format name that is used for the auto naming}
*/
protected abstract Optional<String> getDefaultName();

protected String setPath(List<String> cmdParams) {
return cmdParams.size() > 1
? cmdParams.get(1)
: Shell.readCommand("\nEnter a path to load a "
+ getFormatName().orElse("") + " or leave blank to abort:\n")
.orElse("");
}

protected String setVariableName(ShellSession session, List<String> cmdParams) {
return cmdParams.size() > 0
? cmdParams.get(0)
: Shell.readCommand("\nChoose a name for your "
+ getFormatName().orElse("")
+ " or enter for default ("
+ getDefaultName().orElse("") + (session.getSize() + 1)
+ "):\n")
.orElse(getDefaultName().orElse("") + (session.getSize() + 1));
}

private Result<String> resolveKeyDoubling(String key, ShellSession session) {
while (session.containsKey(key)) {
FeatJAR.log().info("This session already contains a Variable with that name: \n");
session.printSingleELement(key);
String choice = Shell.readCommand("Overwrite " + key + " ? (y)es, (r)ename, (a)bort")
.orElse("")
.toLowerCase();
if (Objects.equals("y", choice)) {
session.remove(choice)
.ifPresent(e -> FeatJAR.log().message("Removing of " + e + " successful"))
.orElseLog(Verbosity.ERROR);
break;
} else if (Objects.equals("r", choice)) {
key = Shell.readCommand("Enter another vaiable name: ").orElse("");
} else if (Objects.equals("a", choice)) {
FeatJAR.log().message("Aborted\n");
return Result.empty();
}
}
return Result.of(key);
}

private <T> void loadFormat(Result<T> result, String key, ShellSession session) {

Result<String> newKey = resolveKeyDoubling(key, session);

if (newKey.isEmpty()) {
return;
} else {
key = newKey.get();
}

if (result.isPresent()) {
if (FeatureModel.class.isAssignableFrom(result.get().getClass())) {
session.put(key, (FeatureModel) result.get(), FeatureModel.class);

} else if (IFormula.class.isAssignableFrom(result.get().getClass())) {
session.put(key, (IFormula) result.get(), IFormula.class);

} else if (BooleanAssignment.class.isAssignableFrom(result.get().getClass())) {
session.put(
key,
((BooleanAssignmentGroups) result.get()).getFirstGroup().getFirst(),
BooleanAssignment.class);

} else if (BooleanAssignmentList.class.isAssignableFrom(result.get().getClass())) {
session.put(key, ((BooleanAssignmentGroups) result.get()).getFirstGroup(), BooleanAssignmentList.class);

} else if (BooleanAssignmentGroups.class.isAssignableFrom(
result.get().getClass())) {
session.put(key, (BooleanAssignmentGroups) result.get(), BooleanAssignmentGroups.class);
}
FeatJAR.log().message(key + " successfully loaded\n");
} else {
printFormatIssue(result, key);
}
}

private <T> void printFormatIssue(Result<T> result, String key) {
String wrongFormat = "Possible formats:";
String input = Problem.printProblems(result.getProblems());

if (input.contains(wrongFormat)) {
int firstIndex = input.indexOf(wrongFormat) + wrongFormat.length();
int SecondIndex = input.lastIndexOf("]") + 1;
String message = input.substring(0, firstIndex);
String possibleFormats = input.substring(firstIndex, SecondIndex);
possibleFormats = possibleFormats.replace(",", ",\n");

FeatJAR.log().error(message + "\n");
FeatJAR.log().error(possibleFormats);
} else {
FeatJAR.log()
.error("Could not load file '" + result.getProblems().get(0).getMessage() + "' for variable '" + key
+ "'");
FeatJAR.log().problems(result.getProblems(), Verbosity.DEBUG);
}
}

protected <T> void parseArguments(ShellSession session, List<String> cmdParams, AFormats<T> format) {
String name = setVariableName(session, cmdParams);
String path = setPath(cmdParams);

if (path.isBlank()) {
FeatJAR.log()
.debug("No correct path for '%s' specified", getFormatName().orElse(""));
return;
}
loadFormat(IO.load(Paths.get(path), format), name, session);
}
}
3 changes: 2 additions & 1 deletion src/main/java/de/featjar/feature/model/IConstraint.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
*/
package de.featjar.feature.model;

import de.featjar.base.data.*;
import de.featjar.base.data.Result;
import de.featjar.base.data.Sets;
import de.featjar.feature.model.mixins.IHasCommonAttributes;
import de.featjar.formula.structure.IFormula;
import de.featjar.formula.structure.term.value.Variable;
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/de/featjar/feature/model/LoadConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2025 FeatJAR-Development-Team
*
* This file is part of FeatJAR-feature-model.
*
* feature-model is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License,
* or (at your option) any later version.
*
* feature-model is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with feature-model. If not, see <https://www.gnu.org/licenses/>.
*
* See <https://github.com/FeatureIDE/FeatJAR-feature-model> for further information.
*/
package de.featjar.feature.model;

import de.featjar.base.shell.ShellSession;
import de.featjar.formula.assignment.BooleanAssignment;
import de.featjar.formula.io.BooleanAssignmentGroupsFormats;
import java.util.List;
import java.util.Optional;

/**
* Loads a configuration {@link BooleanAssignment} into the shell.
*
* @author Niclas Kleinert
*/
public class LoadConfig extends ALoadShellCommand {

@Override
public void execute(ShellSession session, List<String> cmdParams) {
parseArguments(session, cmdParams, BooleanAssignmentGroupsFormats.getInstance());
}

@Override
public Optional<String> getShortName() {
return Optional.of("loadConfig");
}

@Override
public Optional<String> getDescription() {
return Optional.of("<var> <path> - load a configuration");
}

@Override
public Optional<String> getFormatName() {
return Optional.of("Configuration");
}

@Override
public Optional<String> getDefaultName() {
return Optional.of("config");
}
}
59 changes: 59 additions & 0 deletions src/main/java/de/featjar/feature/model/LoadFeatureModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2025 FeatJAR-Development-Team
*
* This file is part of FeatJAR-feature-model.
*
* feature-model is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License,
* or (at your option) any later version.
*
* feature-model is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with feature-model. If not, see <https://www.gnu.org/licenses/>.
*
* See <https://github.com/FeatureIDE/FeatJAR-feature-model> for further information.
*/
package de.featjar.feature.model;

import de.featjar.base.shell.ShellSession;
import de.featjar.feature.model.io.FeatureModelFormats;
import java.util.List;
import java.util.Optional;

/**
* Loads a {@link FeatureModel} into the shell.
*
* @author Niclas Kleinert
*/
public class LoadFeatureModel extends ALoadShellCommand {

@Override
public void execute(ShellSession session, List<String> cmdParams) {
parseArguments(session, cmdParams, FeatureModelFormats.getInstance());
}

@Override
public Optional<String> getShortName() {
return Optional.of("loadFeatureModel");
}

@Override
public Optional<String> getDescription() {
return Optional.of("<var> <path> - load a feature model");
}

@Override
public Optional<String> getFormatName() {
return Optional.of("FeatureModel");
}

@Override
public Optional<String> getDefaultName() {
return Optional.of("fm");
}
}
60 changes: 60 additions & 0 deletions src/main/java/de/featjar/feature/model/LoadFormula.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2025 FeatJAR-Development-Team
*
* This file is part of FeatJAR-feature-model.
*
* feature-model is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License,
* or (at your option) any later version.
*
* feature-model is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with feature-model. If not, see <https://www.gnu.org/licenses/>.
*
* See <https://github.com/FeatureIDE/FeatJAR-feature-model> for further information.
*/
package de.featjar.feature.model;

import de.featjar.base.shell.ShellSession;
import de.featjar.formula.io.FormulaFormats;
import de.featjar.formula.structure.IFormula;
import java.util.List;
import java.util.Optional;

/**
* Loads a {@link IFormula} into the shell.
*
* @author Niclas Kleinert
*/
public class LoadFormula extends ALoadShellCommand {

@Override
public void execute(ShellSession session, List<String> cmdParams) {
parseArguments(session, cmdParams, FormulaFormats.getInstance());
}

@Override
public Optional<String> getShortName() {
return Optional.of("loadFormula");
}

@Override
public Optional<String> getDescription() {
return Optional.of("<var> <path> - load a formula");
}

@Override
public Optional<String> getFormatName() {
return Optional.of("Formula");
}

@Override
public Optional<String> getDefaultName() {
return Optional.of("form");
}
}
Loading