Fix complex script ordering

This commit is contained in:
crschnick
2023-11-11 22:01:50 +00:00
parent 113dcabb08
commit 8babbb3247
2 changed files with 29 additions and 5 deletions
@@ -19,9 +19,7 @@ import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.*;
@SuperBuilder
@Getter
@@ -132,7 +130,27 @@ public abstract class ScriptStore extends JacksonizedValue implements DataStore,
var seen = new LinkedHashSet<SimpleScriptStore>();
scripts.forEach(scriptStoreDataStoreEntryRef ->
scriptStoreDataStoreEntryRef.getStore().queryFlattenedScripts(seen));
return seen.stream().toList();
var dependencies = new HashMap<ScriptStore, Set<SimpleScriptStore>>();
seen.forEach(simpleScriptStore -> {
var f = new HashSet<>(simpleScriptStore.queryFlattenedScripts());
f.remove(simpleScriptStore);
dependencies.put(simpleScriptStore, f);
});
var sorted = new ArrayList<>(seen);
sorted.sort((o1, o2) -> {
if (dependencies.get(o1).contains(o2)) {
return 1;
}
if (dependencies.get(o2).contains(o1)) {
return -1;
}
return 0;
});
return sorted;
}
protected final DataStoreEntryRef<ScriptGroupStore> group;
@@ -170,6 +188,12 @@ public abstract class ScriptStore extends JacksonizedValue implements DataStore,
// }
}
SequencedCollection<SimpleScriptStore> queryFlattenedScripts() {
var seen = new LinkedHashSet<SimpleScriptStore>();
queryFlattenedScripts(seen);
return seen;
}
protected abstract void queryFlattenedScripts(LinkedHashSet<SimpleScriptStore> all);
public abstract List<DataStoreEntryRef<ScriptStore>> getEffectiveScripts();
@@ -15,5 +15,5 @@ $defaultCreds = [System.Net.CredentialCache]::DefaultCredentials;^
if ($defaultCreds) {^
$downloader.Credentials = $defaultCreds^
}^
$downloader.DownloadFile("https://github.com/chrisant996/clink/releases/download/v1.5.7/clink.1.5.7.36d0c6.zip", "$env:TEMP\clink.zip");^
$downloader.DownloadFile("https://github.com/chrisant996/clink/releases/download/v1.5.13/clink.1.5.13.290610.zip", "$env:TEMP\clink.zip");^
Expand-Archive -Force -LiteralPath "$env:TEMP\clink.zip" -DestinationPath "$env:USERPROFILE\.xpipe\scriptdata\clink"; | powershell -NoLogo >NUL