Add runner paths and test

This commit is contained in:
Peter Dell 2023-01-05 01:39:58 +01:00
parent 55dccf7091
commit 29d3fdc913
3 changed files with 224 additions and 3 deletions

View File

@ -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<QualifiedName, String>(10);
languages = new ArrayList<Language>(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 <code>null</code>.
*/
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 <code>null</code>.
*/
public RunnerPaths getRunnerPaths() {
if (runnerPaths == null) {
throw new IllegalStateException("Field 'runnerPaths' must not be null.");
}
return runnerPaths;
}
/**
* Gets the preferences for this plugin.
*

View File

@ -0,0 +1,135 @@
/**
* Copyright (C) 2009 - 2021 <a href="https://www.wudsn.com" target="_top">Peter Dell</a>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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<String, RunnerPath> runnerPaths;
/**
* Created by the {@linkplain LanguagePlugin}.
*/
public RunnerPaths() {
runnerPaths = new TreeMap<String, RunnerPath>();
// 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<RunnerPath> getRunnerPaths() {
return Collections.unmodifiableList(new ArrayList<RunnerPath>(runnerPaths.values()));
}
public List<RunnerPath> 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<RunnerPath> result = new ArrayList<>();
for (RunnerPath runnerPath : runnerPaths.values()) {
if (runnerPath.hardware.equals(hardware) && runnerPath.runnerId.equals(id)) {
result.add(runnerPath);
}
}
return Collections.unmodifiableList(result);
}
}

View File

@ -0,0 +1,58 @@
/**
* Copyright (C) 2009 - 2021 <a href="https://www.wudsn.com" target="_top">Peter Dell</a>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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<RunnerPath> 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);
}
}
}