Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public void printStatistics(LinkedList<IProject> projects, String folder) {

public void createInterface(IProject mplProject, IFeatureProject featureProject, Collection<String> featureNames) {
final ArrayList<LongRunningMethod<?>> arguments = new ArrayList<>(1);
arguments.add(new SliceFeatureModel(featureProject.getFeatureModel(), featureNames, true));
arguments.add(new SliceFeatureModel(featureProject.getFeatureModelManager().getPersistentFormula(), featureNames, true));
FMCorePlugin.startJobs(arguments, StringTable.CREATE_INTERFACE, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.prop4j.Node;

Expand All @@ -47,7 +48,7 @@ public abstract class AConstraint extends AFeatureModelElement implements IConst

protected final IPropertyContainer propertyContainer;

protected final List<IFeature> containedFeatureList = new ArrayList<>();
protected final List<String> containedFeatureList = new ArrayList<>();

protected Node propNode;
boolean featureSelected;
Expand All @@ -68,7 +69,7 @@ public abstract class AConstraint extends AFeatureModelElement implements IConst
public AConstraint(IConstraint oldConstraint, IFeatureModel featureModel, boolean copyId) {
super(oldConstraint, featureModel, copyId);
setNode(oldConstraint.getNode().clone());
description = oldConstraint.getDescription();
description = new String(oldConstraint.getDescription());
tags = new HashSet<>(oldConstraint.getTags());
propertyContainer = new MapPropertyContainer(oldConstraint.getCustomProperties());
if (oldConstraint instanceof AConstraint) {
Expand Down Expand Up @@ -106,7 +107,7 @@ public IPropertyContainer getCustomProperties() {
@Override
public Collection<IFeature> getContainedFeatures() {
synchronized (containedFeatureList) {
return new ArrayList<>(containedFeatureList);
return new ArrayList<>(containedFeatureList.stream().map(featureModel::getFeature).collect(Collectors.toList()));
}
}

Expand Down Expand Up @@ -136,8 +137,9 @@ public void setNode(Node node) {
synchronized (containedFeatureList) {
containedFeatureList.clear();
if (propNode != null) {
for (final String featureName : propNode.getContainedFeatures()) {
containedFeatureList.add(featureModel.getFeature(featureName));
final List<String> containedFeatureNames = propNode.getContainedFeatures();
for (final String containedFeatureName : containedFeatureNames) {
containedFeatureList.add(new String(containedFeatureName));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ private void parseArguments(List<String> args) {
break;
}
default: {
throw new IllegalArgumentException(arg);
throw new IllegalArgumentException("Unknown argument: " + arg);
}
}
} else {
throw new IllegalArgumentException(arg);
throw new IllegalArgumentException("Unknown value: " + arg);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public static void main(String[] args) {
System.err.println("No operation specified!");
return;
}
System.err.println(Arrays.asList(args));

final String functionName = args[0];

LibraryManager.registerLibrary(FMCoreLibrary.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public int hashCode() {

protected AbstractJob(String name, int priority) {
super(name);
setPriority(priority);
setJobPriority(priority);
}

@SuppressWarnings("rawtypes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public int getValue() {

void schedule();

void setPriority(int priority);
void setJobPriority(int priority);

void setIntermediateFunction(Consumer<T> intermediateFunction);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ public void setTimeout(int timeout) {
this.timeout = timeout;
}

@Override
public void setJobPriority(int priority) {
setPriority(priority);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.List;
import java.util.function.Consumer;

import org.eclipse.core.runtime.jobs.Job;

import de.ovgu.featureide.fm.core.Logger;
import de.ovgu.featureide.fm.core.job.monitor.IMonitor;
import de.ovgu.featureide.fm.core.job.monitor.NullMonitor;
Expand Down Expand Up @@ -165,4 +167,23 @@ public void setStoppable(boolean stoppable) {
this.stoppable = stoppable;
}

@Override
public void setJobPriority(int priority) {
switch (priority) {
case Job.INTERACTIVE:
setPriority(Thread.MAX_PRIORITY);
break;
case Job.SHORT:
setPriority(Thread.NORM_PRIORITY);
break;
case Job.LONG:
case Job.BUILD:
case Job.DECORATE:
setPriority(Thread.MIN_PRIORITY);
break;
default:
throw new IllegalArgumentException(String.valueOf(priority));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@
import de.ovgu.featureide.fm.core.analysis.cnf.solver.SimpleSatSolver;
import de.ovgu.featureide.fm.core.base.FeatureUtils;
import de.ovgu.featureide.fm.core.base.IConstraint;
import de.ovgu.featureide.fm.core.base.IFeature;
import de.ovgu.featureide.fm.core.base.IFeatureModel;
import de.ovgu.featureide.fm.core.base.IFeatureModelFactory;
import de.ovgu.featureide.fm.core.base.IFeatureStructure;
import de.ovgu.featureide.fm.core.base.impl.FMFactoryManager;
import de.ovgu.featureide.fm.core.base.impl.FeatureModel;
import de.ovgu.featureide.fm.core.io.manager.FeatureModelManager;
import de.ovgu.featureide.fm.core.job.monitor.IMonitor;
import de.ovgu.featureide.fm.core.localization.StringTable;

/**
* Create mpl interfaces.
* Slices a feature model while preserving as much of its hierarchy and cross-tree constrains as possible.
*
* @author Sebastian Krieter
* @author Marcus Pinnecke (Feature Interface)
Expand All @@ -57,28 +55,28 @@ public class SliceFeatureModel implements LongRunningMethod<IFeatureModel> {

private static final int GROUP_OR = 1, GROUP_AND = 2, GROUP_ALT = 3, GROUP_NO = 0;

private final FeatureModelFormula formula;
private final Collection<String> featureNames;
private final IFeatureModel featureModel;
private final Collection<String> featuresToKeep, featuresToRemove;
private final CNF cnfFormula;
private final IFeatureModel slicedFeatureModel;
private final IFeatureModelFactory factory;
private final boolean useSlicing;

private IFeatureModel slicedFeatureModel;
private boolean slicingNecesary;

public SliceFeatureModel(IFeatureModel featureModel, Collection<String> featureNames, boolean useSlicing) {
this(featureModel, featureNames, useSlicing, true);
this(new FeatureModelFormula(featureModel), featureNames, useSlicing);
}

public SliceFeatureModel(IFeatureModel featureModel, Collection<String> featureNames, boolean useSlicing, boolean usePersistentFormula) {
if (usePersistentFormula) {
formula = FeatureModelManager.getInstance(featureModel).getPersistentFormula();
this.featureModel = formula.getFeatureModel();
} else {
formula = FeatureModelManager.getInstance(featureModel).getVariableFormula();
this.featureModel = featureModel;
}
public SliceFeatureModel(FeatureModelFormula formula, Collection<String> featureNames, boolean useSlicing) {
final IFeatureModel featureModelObject = formula.getFeatureModel();
factory = FMFactoryManager.getInstance().getFactory(featureModelObject);
slicedFeatureModel = featureModelObject.clone();
cnfFormula = formula.getCNF();
featuresToKeep = featureNames;
featuresToRemove = new HashSet<>(FeatureUtils.getFeatureNames(featureModelObject));
featuresToRemove.removeAll(featuresToKeep);

this.useSlicing = useSlicing;
this.featureNames = featureNames;
}

@Override
Expand All @@ -90,27 +88,26 @@ public IFeatureModel execute(IMonitor<IFeatureModel> monitor) throws Exception {
monitor.checkCancel();
final CNF slicedFeatureModelCNF = sliceFormula(monitor.subTask(80));
monitor.checkCancel();
merge(FMFactoryManager.getInstance().getFactory(featureModel), slicedFeatureModelCNF, featureTree, monitor.subTask(18));
merge(factory, slicedFeatureModelCNF, featureTree, monitor.subTask(18));
}

return featureTree;
}

private CNF sliceFormula(IMonitor<?> monitor) {
monitor.setTaskName("Slicing Feature Model Formula");
final HashSet<String> removeFeatures = new HashSet<>(FeatureUtils.getFeatureNames(featureModel));
removeFeatures.removeAll(featureNames);
return LongRunningWrapper.runMethod(new CNFSlicer(formula.getCNF(), removeFeatures), monitor.subTask(1));
return LongRunningWrapper.runMethod(new CNFSlicer(cnfFormula, featuresToRemove), monitor.subTask(1));
}

private IFeatureModel sliceTree(IMonitor<?> monitor) {
monitor.setTaskName("Slicing Feature Tree");
monitor.setRemainingWork(2);
slicingNecesary = false;
slicedFeatureModel = featureModel.clone();

IFeatureStructure root = slicedFeatureModel.getStructure().getRoot();
final List<IConstraint> constraints = new ArrayList<>(slicedFeatureModel.getConstraints());
slicedFeatureModel.reset();

postOrderProcessing(root);
if (isToBeRemoved(root)) {
if ((root.getChildrenCount() == 1) && root.getFirstChild().isMandatory()) {
Expand All @@ -126,17 +123,9 @@ private IFeatureModel sliceTree(IMonitor<?> monitor) {
slicedFeatureModel.getStructure().setRoot(root);
monitor.step();

for (final IConstraint constaint : featureModel.getConstraints()) {
final Collection<IFeature> containedFeatures = constaint.getContainedFeatures();
boolean containsOnlyRemainingFeatures = !containedFeatures.isEmpty();
for (final IFeature feature : containedFeatures) {
if (!featureNames.contains(feature.getName())) {
containsOnlyRemainingFeatures = false;
break;
}
}
if (containsOnlyRemainingFeatures) {
slicedFeatureModel.addConstraint(constaint);
for (final IConstraint constraint : constraints) {
if (featuresToKeep.containsAll(constraint.getNode().getContainedFeatures())) {
slicedFeatureModel.addConstraint(constraint);
} else {
slicingNecesary = true;
}
Expand Down Expand Up @@ -311,7 +300,7 @@ private void toAnd(final IFeatureStructure parent) {
}

private boolean isToBeRemoved(final IFeatureStructure feat) {
return !featureNames.contains(feat.getFeature().getName());
return !featuresToKeep.contains(feat.getFeature().getName());
}

}
1 change: 1 addition & 0 deletions plugins/de.ovgu.featureide.fm.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@ Export-Package: de.ovgu.featureide.fm.ui,
Bundle-ClassPath: .,
lib/org.abego.treelayout.core-1.0.3.jar
Automatic-Module-Name: de.ovgu.featureide.fm.ui
Import-Package: org.eclipse.core.runtime
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import static de.ovgu.featureide.fm.core.localization.StringTable.SELECT_THE_FEATURE_MODEL_FOR_THE_CURRENT_PROJECT;

import java.net.URL;
import java.util.Arrays;
import java.util.Optional;

Expand All @@ -30,6 +31,12 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
Expand Down Expand Up @@ -83,7 +90,13 @@ public static FMUIPlugin getDefault() {
}

public static Image getImage(String name) {
return getDefault().getImageDescriptor("icons/" + name).createImage();
final URL url = FileLocator.find(Platform.getBundle(PLUGIN_ID), new Path("icons/" + name), null);
if (url != null) {
return ImageDescriptor.createFromURL(url).createImage();
} else {
getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, "Image not found: " + name));
return null;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public Boolean execute(IMonitor<Boolean> monitor) throws Exception {
return true;
}
}, ANALYZE_FEATURE_MODEL);
analyzeJob.setPriority(Job.LONG);
analyzeJob.setJobPriority(Job.LONG);
LongRunningWrapper.startJob(analysisToken, analyzeJob);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* FeatureIDE - A Framework for Feature-Oriented Software Development
* Copyright (C) 2005-2019 FeatureIDE team, University of Magdeburg, Germany
* 2025 Malte Grave, VaSiCS, LIT CPS Lab, Johannes Kepler University, Linz
*
* This file is part of FeatureIDE.
*
Expand Down Expand Up @@ -38,26 +39,38 @@
* @author Jonas Weigt
* @author Christian Harnisch
* @author Marcus Pinnecke
* @author Malte Grave
*/

public class ToolBarMenuManager extends MenuManager {

private Image image;
private ImageDescriptor imageDescriptor;

public ToolBarMenuManager(String text) {
super(text);
}

public ToolBarMenuManager(String text, ImageDescriptor image, String id) {
super(text, image, id);
this.image = image.createImage();
public ToolBarMenuManager(String text, ImageDescriptor imageDescriptor, String id) {
super(text, imageDescriptor, id);
this.imageDescriptor = imageDescriptor;
}

@Override
public void fill(final ToolBar toolbar, int index) {
final ToolItem toolItem = (index >= 0) ? new ToolItem(toolbar, SWT.DROP_DOWN, index) : new ToolItem(toolbar, SWT.DROP_DOWN);
toolItem.setText(getMenuText());
toolItem.setImage(image);

if (imageDescriptor != null) {
final Image img = imageDescriptor.createImage();
toolItem.setImage(img);

toolItem.addDisposeListener(e -> {
if ((img != null) && !img.isDisposed()) {
img.dispose();
}
});
}

toolItem.addSelectionListener(new SelectionListener() {

@Override
Expand All @@ -73,5 +86,4 @@ public void widgetSelected(SelectionEvent e) {
public void widgetDefaultSelected(SelectionEvent e) {}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected FeatureIDEEvent operation(IFeatureModel featureModel) {

oldModel = featureModel.clone();

final LongRunningMethod<IFeatureModel> method = new SliceFeatureModel(featureModel, notSelectedFeatureNames, useSlicing, false);
final LongRunningMethod<IFeatureModel> method = new SliceFeatureModel(featureModel, notSelectedFeatureNames, useSlicing);
final IFeatureModel slicingModel = LongRunningWrapper.runMethod(method);

replaceFeatureModel(featureModel, slicingModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void singleAction(final IFile file) {
wizard.putData(WizardConstants.KEY_IN_FEATUREMODEL, featureModel);
if (Window.OK == new WizardDialog(Display.getCurrent().getActiveShell(), wizard).open()) {
final Collection<String> selectedFeatures = (Collection<String>) wizard.getData(WizardConstants.KEY_OUT_FEATURES);
final LongRunningMethod<IFeatureModel> method = new SliceFeatureModel(featureModel, selectedFeatures, true);
final LongRunningMethod<IFeatureModel> method = new SliceFeatureModel(manager.getPersistentFormula(), selectedFeatures, true);

final IRunner<IFeatureModel> runner = LongRunningWrapper.getRunner(method, "Slicing Feature Model");
runner.addJobFinishedListener(finishedJob -> save(finishedJob, file, format));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected Parent[] calculateChidren(boolean expand) {
if (lazy) {
final TreeJob job = new StatisticTreeJob(this, expand);
final IRunner<Boolean> runner = LongRunningWrapper.getRunner(job, CALCULATE + this.getClass().getName());
runner.setPriority(Job.SHORT);
runner.setJobPriority(Job.SHORT);
if (runner instanceof LongRunningJob<?>) {
((LongRunningJob<?>) runner).addJobChangeListener(JobDoneListener.getInstance());
}
Expand Down
Loading