Add CompilerPaths with defaults for MADS and MP. Display documentation paths and defaults paths as tables. Fix broken hardware icon in help.

This commit is contained in:
peterdell 2021-09-27 02:22:52 +02:00
parent 229c92d859
commit fedec9d2f0
13 changed files with 238 additions and 28 deletions

View File

@ -224,6 +224,7 @@ public final class Texts extends NLS {
public static String TOC_COMPILER_NAME_LABEL;
public static String TOC_COMPILER_HOME_PAGE_LABEL;
public static String TOC_COMPILER_HELP_DOCUMENTS_LABEL;
public static String TOC_COMPILER_DEFAULT_PATHS_LABEL;
public static String TOC_COMPILER_DEFAULT_HARDWARE_LABEL;
public static String TOC_COMPILER_SUPPORTED_TARGETS_LABEL;
public static String TOC_COMPILER_DEFAULT_PARAMETERS_LABEL;

View File

@ -121,6 +121,7 @@ TOC_COMPILER_GENERAL_TOPIC_LABEL=General
TOC_COMPILER_NAME_LABEL=Name
TOC_COMPILER_HOME_PAGE_LABEL=Home Page
TOC_COMPILER_HELP_DOCUMENTS_LABEL=Help Documents
TOC_COMPILER_DEFAULT_PATHS_LABEL=Default Paths
TOC_COMPILER_DEFAULT_HARDWARE_LABEL=Default Hardware
TOC_COMPILER_SUPPORTED_TARGETS_LABEL=Supported Targets
TOC_COMPILER_DEFAULT_PARAMETERS_LABEL=Default Parameters

View File

@ -119,6 +119,7 @@ TOC_COMPILER_GENERAL_TOPIC_LABEL=Allgemein
TOC_COMPILER_NAME_LABEL=Name
TOC_COMPILER_HOME_PAGE_LABEL=Home Page
TOC_COMPILER_HELP_DOCUMENTS_LABEL=Hilfe Dokomente
TOC_COMPILER_DEFAULT_PATHS_LABEL=Default Paths
TOC_COMPILER_DEFAULT_HARDWARE_LABEL=Standardhardware
TOC_COMPILER_SUPPORTED_TARGETS_LABEL=Unterstütze Ziele
TOC_COMPILER_DEFAULT_PARAMETERS_LABEL=Standardparameter

View File

@ -35,6 +35,7 @@ import com.wudsn.ide.lng.LanguageUtility;
import com.wudsn.ide.lng.Target;
import com.wudsn.ide.lng.Texts;
import com.wudsn.ide.lng.compiler.CompilerHelp.HelpDocument;
import com.wudsn.ide.lng.compiler.CompilerPaths.CompilerPath;
import com.wudsn.ide.lng.compiler.syntax.CompilerSyntax;
/**
@ -297,7 +298,7 @@ public final class CompilerDefinition implements Comparable<CompilerDefinition>
* does not specify a help path or no help file can be
* found.
*/
public final List<HelpDocument> getHelpDocuments(String compilerExecutablePath) throws CoreException {
public final List<HelpDocument> getInstalledHelpDocuments(String compilerExecutablePath) throws CoreException {
if (compilerExecutablePath == null) {
throw new IllegalArgumentException("Parameter 'compilerExecutablePath' must not be null.");
}
@ -315,12 +316,17 @@ public final class CompilerDefinition implements Comparable<CompilerDefinition>
TextUtility.format(Texts.MESSAGE_E130, name, compilerText, compilerPreferencesText)));
}
return getHelpDocuments(compilerExecutablePath);
}
public final List<HelpDocument> getHelpDocuments(String compilerExecutablePath) {
return CompilerHelp.getHelpDocuments(helpDocumentPaths, compilerExecutablePath);
}
public final HelpDocument getHelpForCurrentLocale(String compilerExecutablePath) throws CoreException {
List<HelpDocument> helpDocuments = getHelpDocuments(compilerExecutablePath);
List<HelpDocument> helpDocuments = getInstalledHelpDocuments(compilerExecutablePath);
String localeLanguage = Locale.getDefault().getLanguage();
@ -378,6 +384,11 @@ public final class CompilerDefinition implements Comparable<CompilerDefinition>
}
public List<CompilerPath> getDefaultPaths() {
CompilerPaths compilerPaths = new CompilerPaths();
return compilerPaths.getCompilerPaths(language, id);
}
/**
* Sets the list of supported targets. Called by {@link CompilerRegistry} only.
*

View File

@ -0,0 +1,143 @@
/**
* 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.compiler;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
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.common.FileUtility;
import com.wudsn.ide.lng.Language;
/**
* Computation of default paths for compilers.
*
* @author Peter Dell
*
* @since 1.7.2
*
*/
public final class CompilerPaths {
public static final class CompilerPath {
public final Language language;
public final String compilerId;
public final String os;
public final String osArch;
public final String executablePath;
private CompilerPath(Language language, String compilerId, String os, String osArch, String executablePath) {
this.language = language;
this.compilerId = compilerId;
this.os = os;
this.osArch = osArch;
this.executablePath = executablePath;
}
public static String getKey(Language language, String compilerId, String os, String osArch) {
return language.name() + "/" + compilerId + "/" + os + "/" + osArch;
}
public String getKey() {
return getKey(language, compilerId, os, osArch);
}
public String getRelativePath() {
return language.name() + "/" + compilerId.toUpperCase() + "/" + executablePath;
}
}
private Map<String, CompilerPath> compilerPaths;
// TODO: Make provide
public CompilerPaths() {
compilerPaths = new TreeMap<String, CompilerPath>();
add(Language.ASM, "mads", Platform.OS_WIN32, Platform.ARCH_X86_64, "mads.exe");
add(Language.PAS, "MP", Platform.OS_WIN32, Platform.ARCH_X86_64, "mp.exe"); //TODO make IDs all uppercase?
}
private void add(Language language, String compilerId, String os, String osArch, String executablePath) {
CompilerPath compilerPath = new CompilerPath(language, compilerId, os, osArch, executablePath);
compilerPaths.put(compilerPath.getKey(), compilerPath);
}
public String getRelativePath(Language language, String compilerId) {
String os = Platform.getOS();
String osArch = Platform.getOSArch();
String key = CompilerPath.getKey(language, compilerId, os, osArch);
CompilerPath compilerPath = compilerPaths.get(key);
if (compilerPath != null) {
return compilerPath.getRelativePath();
}
return null;
}
public File getAbsoluteFile(Language language, String compilerId) {
String path = getRelativePath(language, compilerId);
if (path == null) {
return null;
}
URL eclipseFolderURL = Platform.getInstallLocation().getURL();
if (eclipseFolderURL == null) {
return null;
}
URI uri;
try {
uri = eclipseFolderURL.toURI();
} catch (URISyntaxException ignore) {
return null;
}
File eclipseFolder = FileUtility.getCanonicalFile(new File(uri));
File ideFolder = eclipseFolder.getParentFile();
File toolsFolder = ideFolder.getParentFile();
File compilerFile = new File(toolsFolder, path);
return compilerFile;
}
public List<CompilerPath> getCompilerPaths(Language language, String id) {
if (language == null) {
throw new IllegalArgumentException("Parameter 'language' must not be null.");
}
if (id == null) {
throw new IllegalArgumentException("Parameter 'id' must not be null.");
}
List<CompilerPath> result = new ArrayList<>();
for (CompilerPath compilerPath : compilerPaths.values()) {
if (compilerPath.language.equals(language) && compilerPath.compilerId.equals(id)) {
result.add(compilerPath);
}
}
return Collections.unmodifiableList(result);
}
}

View File

@ -250,7 +250,7 @@ final class LanguageEditorCompileCommand {
String compilerDefinitionText = LanguageUtility.getCompilerTextLower(compilerDefinition.getLanguage());
String compilerPreferencesText = LanguageUtility.getCompilerPreferencesText(compilerDefinition.getLanguage());
String compilerExecutablePath = languageEditor.getCompilerPreferences().getCompilerExecutablePath();
String compilerExecutablePath = languageEditor.getCompilerPreferences().getCompilerExecutablePathOrDefault();
if (StringUtility.isEmpty(compilerExecutablePath)) {
// ERROR: Path to '{0}' {1} executable is not set in the '{2}' preferences.
createMainSourceFileMessage(files, IMarker.SEVERITY_ERROR, Texts.MESSAGE_E100, compilerDefinitionText,

View File

@ -56,7 +56,7 @@ public final class LanguageEditorCompilerHelpCommandHandler extends AbstractHand
CompilerDefinition compilerDefinition = languageEditor.getCompilerDefinition();
CompilerPreferences compilerPreferences = languageEditor.getCompilerPreferences();
String compilerExecutablePath = compilerPreferences.getCompilerExecutablePath();
String compilerExecutablePath = compilerPreferences.getCompilerExecutablePathOrDefault();
try {
HelpDocument helpDocument = compilerDefinition.getHelpForCurrentLocale(compilerExecutablePath);

View File

@ -39,6 +39,6 @@ final class HTMLConstants {
+ NL + HTMLConstants.CONTENT_TYPE + NL + HTMLConstants.STYLE_SHEETS + NL + "</head><body>";
public static final String SUFFIX = "</body>" + NL + "</html>";
public static final String BR = "<br>";
public static final String BR = "<br/>";
}

View File

@ -55,6 +55,7 @@ import com.wudsn.ide.lng.TargetUtility;
import com.wudsn.ide.lng.Texts;
import com.wudsn.ide.lng.compiler.CompilerDefinition;
import com.wudsn.ide.lng.compiler.CompilerHelp.HelpDocument;
import com.wudsn.ide.lng.compiler.CompilerPaths.CompilerPath;
import com.wudsn.ide.lng.compiler.CompilerRegistry;
import com.wudsn.ide.lng.compiler.syntax.CompilerSyntax;
import com.wudsn.ide.lng.compiler.syntax.CompilerSyntaxUtility;
@ -106,6 +107,7 @@ public final class LanguageHelpContentProducer implements IHelpContentProducer {
public static final String SCHEMA_TARGET = "target/";
private static final String ICONS_PATH = "/help/topic/com.wudsn.ide.lng/icons/";
private static final String HARDWARE_ICONS_PATH = "/help/topic/com.wudsn.ide.base/icons/";
@Override
public InputStream getInputStream(String pluginID, String href, Locale locale) {
@ -310,19 +312,10 @@ public final class LanguageHelpContentProducer implements IHelpContentProducer {
LanguagePreferences languagePreferences = languagePlugin.getLanguagePreferences(language);
CompilerPreferences compilerPreferences = languagePreferences.getCompilerPreferences(compilerDefinition,
Hardware.GENERIC);
String compilerExecutablePath = compilerPreferences.getCompilerExecutablePath();
if (StringUtility.isEmpty(compilerExecutablePath)) {
// ERROR: Help for the '{0}' compiler cannot be
// displayed because the path to the compiler executable
// is not set in the preferences.
String message = TextUtility.format(Texts.MESSAGE_E130, compilerDefinition.getName());
HTMLWriter writer = createHeader();
writer.writeText(message);
return getInputStream(writer);
}
try {
HelpDocument helpDocDocument = compilerDefinition.getHelpForCurrentLocale(compilerExecutablePath);
HelpDocument helpDocDocument = compilerDefinition
.getHelpForCurrentLocale(compilerPreferences.getCompilerExecutablePathOrDefault());
File file = helpDocDocument.file;
if (file == null) {
throw new RuntimeException(
@ -380,12 +373,42 @@ public final class LanguageHelpContentProducer implements IHelpContentProducer {
writer.writeTableRow(Texts.TOC_COMPILER_HOME_PAGE_LABEL,
HTMLWriter.getLink(compilerDefinition.getHomePageURL(), compilerDefinition.getHomePageURL()));
String helpDocumentPaths = compilerDefinition.getHelpDocumentPaths().replace(",", HTMLConstants.BR);
writer.writeTableRowCode(Texts.TOC_COMPILER_HELP_DOCUMENTS_LABEL, helpDocumentPaths);
List<HelpDocument> helpDocuments = compilerDefinition.getHelpDocuments("");
HTMLWriter innerWriter = new HTMLWriter(); // TODO: Breaks layout if there are no paths
if (!helpDocuments.isEmpty()) {
innerWriter.beginTable(false);
for (HelpDocument helpDocument : helpDocuments) {
innerWriter.beginTableRow();
if (helpDocument.uri != null) {
innerWriter.writeTableCell(HTMLWriter.getLink(helpDocument.path, helpDocument.path));
} else {
innerWriter.writeTableCell(helpDocument.path);
}
innerWriter.writeTableCell(helpDocument.language);
innerWriter.end();
}
innerWriter.end();
}
writer.writeTableRowCode(Texts.TOC_COMPILER_HELP_DOCUMENTS_LABEL, innerWriter.toHTML());
List<CompilerPath> defaultPaths = compilerDefinition.getDefaultPaths();
innerWriter = new HTMLWriter(); // TODO: Breaks layout if there are no paths
if (!defaultPaths.isEmpty()) {
innerWriter.beginTable(false);
for (CompilerPath compilerPath : defaultPaths) {
innerWriter.beginTableRow();
innerWriter.writeTableCell(compilerPath.os);
innerWriter.writeTableCell(compilerPath.osArch);
innerWriter.writeTableCell(compilerPath.getRelativePath());
innerWriter.end();
}
innerWriter.end();
}
writer.writeTableRowCode(Texts.TOC_COMPILER_DEFAULT_PATHS_LABEL, innerWriter.toHTML());
Hardware hardware = compilerDefinition.getDefaultHardware();
writer.writeTableRow(Texts.TOC_COMPILER_DEFAULT_HARDWARE_LABEL, HTMLWriter
.getImage(ICONS_PATH + HardwareUtility.getImagePath(hardware), hardware.name(), hardware.name()));
writer.writeTableRow(Texts.TOC_COMPILER_DEFAULT_HARDWARE_LABEL, getHardwareIconImage(hardware));
List<Target> cpus = compilerDefinition.getSupportedTargets();
writer.beginTableRow();
@ -587,6 +610,14 @@ public final class LanguageHelpContentProducer implements IHelpContentProducer {
writer.end();
}
private String getHardwareIconImage(Hardware hardware) {
if (hardware == null) {
throw new IllegalArgumentException("Parameter 'hardware' must not be null.");
}
return HTMLWriter.getImage(HARDWARE_ICONS_PATH + HardwareUtility.getImagePath(hardware), hardware.name(),
hardware.name());
}
private InputStream getHardwareInputStream(String href) {
if (href == null) {
throw new IllegalArgumentException("Parameter 'href' must not be null.");
@ -604,8 +635,7 @@ public final class LanguageHelpContentProducer implements IHelpContentProducer {
writer.beginTable();
writer.writeTableRow(Texts.TOC_HARDWARE_NAME_LABEL, EnumUtility.getText(hardware));
writer.writeTableRow(Texts.TOC_HARDWARE_ID_LABEL, hardware.name());
writer.writeTableRow(Texts.TOC_HARDWARE_ICON_LABEL,
HTMLWriter.getImage(ICONS_PATH + HardwareUtility.getImagePath(hardware), hardware.name(), ""));
writer.writeTableRow(Texts.TOC_HARDWARE_ICON_LABEL, getHardwareIconImage(hardware));
writer.writeTableRow(Texts.TOC_HARDWARE_DEFAULT_FILE_EXTENSION_LABEL,
HardwareUtility.getDefaultFileExtension(hardware));

View File

@ -270,7 +270,7 @@ public final class LanguageTocProvider extends AbstractTocProvider {
.getLanguagePreferences(compilerDefinition.getLanguage());
CompilerPreferences compilerPreferences = languagePreferences.getCompilerPreferences(compilerDefinition,
Hardware.GENERIC);
String compilerExecutablePath = compilerPreferences.getCompilerExecutablePath();
String compilerExecutablePath = compilerPreferences.getCompilerExecutablePathOrDefault();
String icon = "";
List<ITopic> manualTopics = new ArrayList<ITopic>();

View File

@ -19,10 +19,13 @@
package com.wudsn.ide.lng.preferences;
import java.io.File;
import com.wudsn.ide.base.common.StringUtility;
import com.wudsn.ide.base.hardware.Hardware;
import com.wudsn.ide.lng.Target;
import com.wudsn.ide.lng.compiler.CompilerOutputFolderMode;
import com.wudsn.ide.lng.compiler.CompilerPaths;
import com.wudsn.ide.lng.runner.RunnerId;
/**
@ -65,7 +68,7 @@ public final class CompilerPreferences {
}
/**
* Gets the executable path for the compiler.
* Gets the configured executable path for the compiler.
*
* @return The executable path for the runner, may be empty, not
* <code>null</code>.
@ -74,6 +77,28 @@ public final class CompilerPreferences {
return languagePreferences.getString(LanguagePreferencesConstants.getCompilerExecutablePathName(compilerId));
}
/**
* Gets the executable path for the compiler.
*
* @return The executable path for the runner, may be empty, not
* <code>null</code>.
*/
public String getCompilerExecutablePathOrDefault() {
String compilerExecutablePath = getCompilerExecutablePath();
CompilerPaths compilerPaths = new CompilerPaths();
if (StringUtility.isEmpty(compilerExecutablePath)) {
File compilerFile = compilerPaths.getAbsoluteFile(languagePreferences.getLanguage(), compilerId);
if (compilerFile != null) {
if (compilerFile.exists() && compilerFile.isFile() && compilerFile.canExecute()) {
compilerExecutablePath = compilerFile.getAbsolutePath();
}
}
}
return compilerExecutablePath;
}
/**
* Gets the hardware for which the compiler is invoked.
*

View File

@ -79,7 +79,6 @@ public abstract class LanguagePreferencesCompilersPage extends FieldEditorPrefer
private static final class Tab {
public final CompilerDefinition compilerDefinition;
public final String compilerId;
public final int tabIndex;
public final TabItem tabItem;
public final Control enabledControl;
@ -91,7 +90,6 @@ public abstract class LanguagePreferencesCompilersPage extends FieldEditorPrefer
public Tab(CompilerDefinition compilerDefinition, int tabIndex, TabItem tabItem, Control enabledControl,
Control disabledControl, List<ControlDecoration> controlDecorations) {
this.compilerDefinition = compilerDefinition;
this.compilerId = compilerDefinition.getId();
this.tabIndex = tabIndex;
this.tabItem = tabItem;
this.enabledControl = enabledControl;
@ -462,7 +460,7 @@ public abstract class LanguagePreferencesCompilersPage extends FieldEditorPrefer
LanguagePreferences languagePreferences = plugin.getLanguagePreferences(language);
CompilerPreferences compilerPreferences = languagePreferences.getCompilerPreferences(tab.compilerDefinition,
hardware);
boolean enabled = StringUtility.isSpecified(compilerPreferences.getCompilerExecutablePath());
boolean enabled = StringUtility.isSpecified(compilerPreferences.getCompilerExecutablePathOrDefault());
if (!tab.initialized || enabled != tab.enabled) {
tab.initialized = true;

View File

@ -78,7 +78,7 @@ public final class HardwareUtility {
}
/**
* Gets the image path for a hardware image.
* Gets the relative image path for a hardware image.
*
* @param hardware The hardware, not <code>null</code>.
* @return The image path for the hardware image, not empty and not