Skip to content

Commit a22a807

Browse files
author
jantje
committed
Sort the options on the optionID #1126
I needed a sorting for the regression tests
1 parent fbb9870 commit a22a807

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed

io.sloeber.autoBuild/src/io/sloeber/autoBuild/extensionPoint/providers/MakeRule.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
import java.nio.file.attribute.BasicFileAttributes;
1313
import java.util.ArrayList;
1414
import java.util.Arrays;
15-
import java.util.HashMap;
1615
import java.util.HashSet;
1716
import java.util.LinkedHashMap;
1817
import java.util.LinkedHashSet;
1918
import java.util.List;
2019
import java.util.Map;
2120
import java.util.Map.Entry;
2221
import java.util.Set;
22+
import java.util.TreeMap;
2323

2424
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
2525
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper;
@@ -32,7 +32,6 @@
3232
import org.eclipse.core.resources.IProject;
3333
import org.eclipse.core.runtime.IPath;
3434

35-
import io.sloeber.autoBuild.api.IAutoBuildConfigurationDescription;
3635
import io.sloeber.autoBuild.integration.AutoBuildConfigurationDescription;
3736
import io.sloeber.schema.api.IInputType;
3837
import io.sloeber.schema.api.IOption;
@@ -219,7 +218,7 @@ public String[] getRecipes(IFolder buildFolder, AutoBuildConfigurationDescriptio
219218
//from all the options for this project; get the options for this tool/prerequisites
220219
// not there is a filtering happening in this step and there may be duplicates
221220
// here we will assume this is handled properly by AutoBuildConfigurationDescription
222-
Map<IOption, String> selectedOptions = autoBuildConfData.getSelectedOptions(inputFiles, myTool);
221+
TreeMap<IOption, String> selectedOptions = autoBuildConfData.getSelectedOptions(inputFiles, myTool);
223222

224223
//with all the options applicable for this makerule generate variables to expand in the recipes
225224
Map<String, String> toolCommandVars = myTool.getToolCommandVars(autoBuildConfData, selectedOptions);
@@ -243,7 +242,9 @@ public String[] getRecipes(IFolder buildFolder, AutoBuildConfigurationDescriptio
243242
curCommandVarValue = curCommandVarValue + curFileName + WHITESPACE;
244243
}
245244
}
246-
toolCommandVars.put(var, curCommandVarValue.trim());
245+
if (!curCommandVarValue.isBlank()) {
246+
toolCommandVars.put(var, curCommandVarValue.trim());
247+
}
247248
}
248249

249250
//add the provider items to the flags

io.sloeber.autoBuild/src/io/sloeber/autoBuild/integration/AutoBuildConfigurationDescription.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.util.Map;
1010
import java.util.Map.Entry;
1111
import java.util.Set;
12+
import java.util.TreeMap;
13+
1214
import org.eclipse.cdt.core.cdtvariables.ICdtVariablesContributor;
1315
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
1416
import org.eclipse.cdt.core.settings.model.extension.CBuildData;
@@ -702,8 +704,15 @@ public String setProperty(String key, String value) {
702704
return myProperties.put(key, value);
703705
}
704706

705-
private Map<IOption, String> convertOptionIDToOption(Map<String, String> input, ITool tool) {
706-
Map<IOption, String> ret = new HashMap<>();
707+
private TreeMap<IOption, String> convertOptionIDToOption(Map<String, String> input, ITool tool) {
708+
TreeMap<IOption, String> ret = new TreeMap<>(new java.util.Comparator<>() {
709+
710+
@Override
711+
public int compare(IOption o1, IOption o2) {
712+
// TODO Auto-generated method stub
713+
return o1.getId().compareTo(o2.getId());
714+
}
715+
});
707716
for (Entry<String, String> cur : input.entrySet()) {
708717
IOption curKey = tool.getOption(cur.getKey());
709718
ret.put(curKey, cur.getValue());
@@ -712,7 +721,7 @@ private Map<IOption, String> convertOptionIDToOption(Map<String, String> input,
712721
}
713722

714723
@Override
715-
public Map<IOption, String> getSelectedOptions(Set<? extends IResource> file, ITool tool) {
724+
public TreeMap<IOption, String> getSelectedOptions(Set<? extends IResource> file, ITool tool) {
716725
Map<String, String> ret = new HashMap<>();
717726
for (IResource curFile : file) {
718727
Map<String, String> fileOptions = getSelectedOptionNames(curFile, tool);
@@ -763,7 +772,7 @@ public Map<String, String> getSelectedOptionNames(IResource file, ITool tool) {
763772
}
764773
}
765774
}
766-
Map<String, String> ret = new HashMap<>();
775+
Map<String, String> ret = new TreeMap<>();
767776
ret.putAll(retProject);
768777
ret.putAll(retFolder);
769778
ret.putAll(retFile);

io.sloeber.autoBuild/src/io/sloeber/schema/api/IOption.java

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.eclipse.core.resources.IResource;
2222
import io.sloeber.autoBuild.api.BuildException;
2323
import io.sloeber.autoBuild.api.IAutoBuildConfigurationDescription;
24-
import io.sloeber.autoBuild.integration.AutoBuildConfigurationDescription;
2524
import static io.sloeber.autoBuild.integration.AutoBuildConstants.*;
2625

2726
import java.util.Map;

io.sloeber.autoBuild/src/io/sloeber/schema/internal/Option.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ public class Option extends SchemaObject implements IOption {
6868
public static final String[] EMPTY_STRING_ARRAY = new String[0];
6969
public static final OptionStringValue[] EMPTY_LV_ARRAY = new OptionStringValue[0];
7070
private static final String EMPTY_QUOTED_STRING = "\"\""; //$NON-NLS-1$
71-
private static final String STRING_SEPERATOR = "\n\r";//$NON-NLS-1$
72-
private static final String STRING_SEPARATOR_REGEX = Pattern.quote(STRING_SEPERATOR);
71+
private static final String STRING_NEW_LINE_SEPERATOR = "\n\r";//$NON-NLS-1$
72+
private static final String STRING_NEW_LINE_SEPARATOR_REGEX = Pattern.quote(STRING_NEW_LINE_SEPERATOR);
73+
private static final String STRING_SEMICOLON_SEPERATOR = SEMICOLON;
74+
private static final String STRING_SEMICOLON_SEPARATOR_REGEX = Pattern.quote(STRING_SEMICOLON_SEPERATOR);
7375

7476
private String[] modelCategoryId;
7577
private String[] modelResFilterStr;
@@ -437,7 +439,7 @@ public String getDefaultValueString() {
437439
for (TreeOption curTreeOption : myTreeOptions.values()) {
438440
curTreeOption.getDefaultValueStrings(defaultValues);
439441
}
440-
return String.join(STRING_SEPERATOR, defaultValues);
442+
return String.join(STRING_NEW_LINE_SEPERATOR, defaultValues);
441443
}
442444

443445
}
@@ -726,7 +728,7 @@ public Map<String, String> getCommandVars(String optionValue, IAutoBuildConfigur
726728
return ret;
727729
}
728730
case IOption.TREE: {
729-
String[] values = optionValue.split(STRING_SEPARATOR_REGEX);
731+
String[] values = optionValue.split(STRING_NEW_LINE_SEPARATOR_REGEX);
730732
String retValue = new String();
731733
if (myTreeRoot != null) {
732734
for (String curptionValue : values) {
@@ -759,7 +761,10 @@ public Map<String, String> getCommandVars(String optionValue, IAutoBuildConfigur
759761
case IOption.PREPROCESSOR_SYMBOLS:
760762
case IOption.UNDEF_PREPROCESSOR_SYMBOLS: {
761763
String listCmd = modelCommand[SUPER];
762-
String[] values = optionValue.split(STRING_SEPARATOR_REGEX);
764+
String[] values = optionValue.split(STRING_NEW_LINE_SEPARATOR_REGEX);
765+
if (values.length == 1) {
766+
values = optionValue.split(STRING_SEMICOLON_SEPARATOR_REGEX);
767+
}
763768
String[] resolvedList = resolveStringListValues(values, autoConfData, true);
764769
String retValue = new String();
765770
for (String curResolved : resolvedList) {
@@ -925,7 +930,7 @@ public boolean isCommandLineContributionBlank(IResource resource, String optionV
925930
return selectedEnumValue.getCommandLIneDistribution().isBlank();
926931
}
927932
case IOption.TREE: {
928-
String[] values = optionValue.split(STRING_SEPARATOR_REGEX);
933+
String[] values = optionValue.split(STRING_NEW_LINE_SEPARATOR_REGEX);
929934
if (myTreeRoot != null) {
930935
for (String curptionValue : values) {
931936
ITreeOption treeNode = myTreeRoot.findNode(curptionValue);
@@ -954,7 +959,7 @@ public boolean isCommandLineContributionBlank(IResource resource, String optionV
954959
case IOption.UNDEF_MACRO_FILES:
955960
case IOption.PREPROCESSOR_SYMBOLS:
956961
case IOption.UNDEF_PREPROCESSOR_SYMBOLS: {
957-
String[] values = optionValue.split(STRING_SEPARATOR_REGEX);
962+
String[] values = optionValue.split(STRING_NEW_LINE_SEPARATOR_REGEX);
958963
String[] resolvedList = resolveStringListValues(values, autoConfData, true);
959964
for (String curResolved : resolvedList) {
960965
if (!curResolved.isBlank() && !curResolved.contains(EMPTY_QUOTED_STRING))

io.sloeber.autoBuild/src/io/sloeber/schema/internal/Tool.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ public Map<String, String> getToolCommandVars(IAutoBuildConfigurationDescription
408408
for (Entry<String, String> curVar : optionVars.entrySet()) {
409409
String varName = curVar.getKey();
410410
String varValue = curVar.getValue();
411+
if (varValue.isBlank()) {
412+
//blank items will add unnecessary spaces
413+
continue;
414+
}
411415
List<String> alreadyFoundArguments = allVars.get(varName);
412416
if (alreadyFoundArguments == null) {
413417
alreadyFoundArguments = new LinkedList<>();
@@ -544,9 +548,11 @@ public String[] getRecipes(IAutoBuildConfigurationDescription autoBuildConfData,
544548
GetNiceFileName(buildFolder, depFile));
545549
depFlag = depFlag.replace(OUT_MACRO, GetNiceFileName(buildFolder, targetFile));
546550

547-
String flagsValue = toolCommandVars.get(FLAGS_PRM_NAME);
548-
flagsValue = flagsValue.trim() + WHITESPACE + depFlag;
549-
toolCommandVars.put(FLAGS_PRM_NAME, flagsValue.trim());
551+
if (!depFlag.isBlank()) {
552+
String flagsValue = toolCommandVars.get(FLAGS_PRM_NAME);
553+
flagsValue = flagsValue.trim() + WHITESPACE + depFlag;
554+
toolCommandVars.put(FLAGS_PRM_NAME, flagsValue.trim());
555+
}
550556
}
551557

552558
//add some more variables to the list

0 commit comments

Comments
 (0)