From 29d3fdc913aacfefd4f7bb16a8753b5edbc55bd5 Mon Sep 17 00:00:00 2001 From: Peter Dell Date: Thu, 5 Jan 2023 01:39:58 +0100 Subject: [PATCH] Add runner paths and test --- .../src/com/wudsn/ide/lng/LanguagePlugin.java | 34 ++++- .../com/wudsn/ide/lng/runner/RunnerPaths.java | 135 ++++++++++++++++++ .../wudsn/ide/lng/runner/RunnerPathsTest.java | 58 ++++++++ 3 files changed, 224 insertions(+), 3 deletions(-) create mode 100644 com.wudsn.ide.lng/src/com/wudsn/ide/lng/runner/RunnerPaths.java create mode 100644 com.wudsn.ide.lng/src/com/wudsn/ide/lng/runner/RunnerPathsTest.java diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/LanguagePlugin.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/LanguagePlugin.java index 4f8ffaef..84eed441 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/LanguagePlugin.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/LanguagePlugin.java @@ -51,6 +51,8 @@ import com.wudsn.ide.lng.preferences.LanguagePreferencesChangeListener; import com.wudsn.ide.lng.preferences.LanguagePreferencesConstants; import com.wudsn.ide.lng.preferences.LanguagesPreferences; import com.wudsn.ide.lng.preferences.TextAttributeDefinition; +import com.wudsn.ide.lng.runner.RunnerPaths; +import com.wudsn.ide.lng.runner.RunnerPathsTest; import com.wudsn.ide.lng.runner.RunnerRegistry; /** @@ -97,6 +99,11 @@ public final class LanguagePlugin extends AbstractIDEPlugin { * The runner registry. */ private RunnerRegistry runnerRegistry; + + /** + * The runner paths. + */ + private RunnerPaths runnerPaths; /** * The UI properties. @@ -113,6 +120,7 @@ public final class LanguagePlugin extends AbstractIDEPlugin { compilerPaths = new CompilerPaths(); compilerConsole = null; runnerRegistry = new RunnerRegistry(); + runnerPaths = new RunnerPaths(); properties = new HashMap(10); languages = new ArrayList(2); languages.add(Language.ASM); @@ -174,6 +182,7 @@ public final class LanguagePlugin extends AbstractIDEPlugin { // TODO: Call unit tests CompilerPathsTest.main(new String[0]); + RunnerPathsTest.main(new String[0]); } @@ -224,9 +233,10 @@ public final class LanguagePlugin extends AbstractIDEPlugin { } catch (URISyntaxException ignore) { return null; } - File eclipseFolder = FileUtility.getCanonicalFile(new File(uri)); - File ideFolder = eclipseFolder.getParentFile(); - File toolsFolder = ideFolder.getParentFile(); + File eclipseVersionFolder = FileUtility.getCanonicalFile(new File(uri)); // "eclipse" + File eclipseFolder = eclipseVersionFolder.getParentFile(); // "Eclipse" + File ideFolder = eclipseFolder.getParentFile(); // "IDE" + File toolsFolder = ideFolder.getParentFile(); // "Tools File compilerFile = new File(toolsFolder, relativePath); return compilerFile; } @@ -244,12 +254,18 @@ public final class LanguagePlugin extends AbstractIDEPlugin { return compilerRegistry; } + /** + * Gets the compiler paths for this plugin. + * + * @return The compiler paths, not null. + */ public CompilerPaths getCompilerPaths() { if (compilerPaths == null) { throw new IllegalStateException("Field 'compilerPaths' must not be null."); } return compilerPaths; } + /** * Gets the compiler console for this plugin. * @@ -274,6 +290,18 @@ public final class LanguagePlugin extends AbstractIDEPlugin { return runnerRegistry; } + /** + * Gets the runner paths for this plugin. + * + * @return The compiler paths, not null. + */ + public RunnerPaths getRunnerPaths() { + if (runnerPaths == null) { + throw new IllegalStateException("Field 'runnerPaths' must not be null."); + } + return runnerPaths; + } + /** * Gets the preferences for this plugin. * diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/runner/RunnerPaths.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/runner/RunnerPaths.java new file mode 100644 index 00000000..43215efe --- /dev/null +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/runner/RunnerPaths.java @@ -0,0 +1,135 @@ +/** + * Copyright (C) 2009 - 2021 Peter Dell + * + * This file is part of WUDSN IDE. + * + * WUDSN IDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * WUDSN IDE 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WUDSN IDE. If not, see . + */ + +package com.wudsn.ide.lng.runner; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import org.eclipse.core.runtime.Platform; + +import com.wudsn.ide.base.hardware.Hardware; +import com.wudsn.ide.lng.LanguagePlugin; + +/** + * Computation of default paths for runners. + * + * @author Peter Dell + * + * @since 1.7.2 + * + */ +public final class RunnerPaths { + + public static final class RunnerPath { + public final Hardware hardware; + public final String runnerId; + public final String os; + public final String osArch; + public final String executablePath; + + private RunnerPath(Hardware hardware, String runnerId, String os, String osArch, String executablePath) { + this.hardware = hardware; + this.runnerId = runnerId; + this.os = os; + this.osArch = osArch; + this.executablePath = executablePath; + + } + + public static String getKey(Hardware hardware, String runnerId, String os, String osArch) { + return hardware.name() + "/" + runnerId + "/" + os + "/" + osArch; + } + + public String getKey() { + return getKey(hardware, runnerId, os, osArch); + } + + public String getRelativePath() { + return "EMU/" + executablePath; + } + + public File getAbsoluteFile() { + return LanguagePlugin.getInstance().getAbsoluteToolsFile(getRelativePath()); + } + + } + + private Map runnerPaths; + + /** + * Created by the {@linkplain LanguagePlugin}. + */ + public RunnerPaths() { + runnerPaths = new TreeMap(); + // See https://github.com/peterdell/wudsn-ide-tools + add(Hardware.ATARI8BIT, "altirra", Platform.WS_WIN32,Platform.ARCH_X86, "Altirra/Altirra.exe"); + add(Hardware.ATARI8BIT, "altirra", Platform.WS_WIN32, Platform.ARCH_X86_64, "Altirra/Altirra64.exe"); + + } + + private void add(Hardware hardware, String runnerId, String os, String osArch, String executablePath) { + if (!runnerId.equals(runnerId.toLowerCase())) { + throw new IllegalArgumentException("Parameter 'runnerId' value " + runnerId + " must be lower case."); + } + RunnerPath runnerPath = new RunnerPath(hardware, runnerId, os, osArch, executablePath); + runnerPaths.put(runnerPath.getKey(), runnerPath); + } + + public RunnerPath getDefaultRunnerrPath(Hardware hardware, String runnerId) { + String os = Platform.getOS(); + String osArch = Platform.getOSArch(); + String key = RunnerPath.getKey(hardware, runnerId, os, osArch); + RunnerPath runnerPath = runnerPaths.get(key); + // Default to 32-bit version if 64-bit version not defined? + if (runnerPath == null) { + if (osArch.equals(Platform.ARCH_X86_64)) { + osArch = Platform.ARCH_X86; + key = RunnerPath.getKey(hardware, runnerId, os, osArch); + runnerPath = runnerPaths.get(key); + } + } + return runnerPath; + } + + public List getRunnerPaths() { + return Collections.unmodifiableList(new ArrayList(runnerPaths.values())); + } + + public List getRunnerPaths(Hardware hardware, String id) { + if (hardware == null) { + throw new IllegalArgumentException("Parameter 'hardware' must not be null."); + } + if (id == null) { + throw new IllegalArgumentException("Parameter 'id' must not be null."); + } + List result = new ArrayList<>(); + for (RunnerPath runnerPath : runnerPaths.values()) { + if (runnerPath.hardware.equals(hardware) && runnerPath.runnerId.equals(id)) { + result.add(runnerPath); + } + } + return Collections.unmodifiableList(result); + } + +} \ No newline at end of file diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/runner/RunnerPathsTest.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/runner/RunnerPathsTest.java new file mode 100644 index 00000000..a3f9a6f6 --- /dev/null +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/runner/RunnerPathsTest.java @@ -0,0 +1,58 @@ +/** + * Copyright (C) 2009 - 2021 Peter Dell + * + * This file is part of WUDSN IDE. + * + * WUDSN IDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * WUDSN IDE 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WUDSN IDE. If not, see . + */ + +package com.wudsn.ide.lng.runner; + +import java.io.File; +import java.util.List; + +import com.wudsn.ide.base.common.Test; +import com.wudsn.ide.base.common.TestMethod; +import com.wudsn.ide.lng.LanguagePlugin; +import com.wudsn.ide.lng.runner.RunnerPaths.RunnerPath; + +/** + * Computation of default paths for runners. + * + * @author Peter Dell + * + * @since 1.7.2 + * + */ +public final class RunnerPathsTest { + + @TestMethod + public static void main(String[] args) { + RunnerPaths runnerPaths = LanguagePlugin.getInstance().getRunnerPaths(); + List runnerPathList = runnerPaths.getRunnerPaths(); + for (RunnerPath runnerPath : runnerPathList) { + File file = runnerPath.getAbsoluteFile(); + String filePath = ""; + String result = "NOT defined"; + if (file != null) { + filePath = file.getAbsolutePath(); + result = file.exists() ? "found" : "NOT found"; + } + Test.log("Hardware " + runnerPath.hardware + ", runner " + runnerPath.runnerId + ", OS " + + runnerPath.os + ", OS architecture " + runnerPath.osArch + ": File " + filePath + " " + + result); + } + } + +} \ No newline at end of file