Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fqqb committed Sep 21, 2023
1 parent 873a84d commit 9c9069b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
*******************************************************************************/
package org.yamcs.studio.core;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import java.util.Properties;

import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.Platform;

public class SiteConfiguration {

Expand All @@ -24,18 +24,56 @@ public class SiteConfiguration {
static {
// Read site-specific configuration, this can be used to toggle some functionality
// in a site-controlled manner.
var configLocation = ConfigurationScope.INSTANCE.getLocation().toFile();
var configFile = new File(configLocation, "site-config.ini");
if (configFile.exists()) {
try (var fileIn = Files.newInputStream(configFile.toPath())) {
props.load(fileIn);
} catch (IOException e) {
System.err.println("Failed to load site configuration");
e.printStackTrace();

System.out.println("Platform location " + Platform.getLocation());
System.out.println("Platform install location " + Platform.getInstallLocation().getURL());
System.out.println("Platform conf location " + Platform.getConfigurationLocation().getURL());

var configurationDir = findInstallationConfigurationDir();
if (configurationDir != null) {
var siteConfig = configurationDir.resolve("site-config.ini");
System.out.println("File exists ? " + Files.exists(siteConfig));
if (Files.exists(siteConfig)) {
try (var fileIn = Files.newInputStream(siteConfig)) {
props.load(fileIn);
} catch (IOException e) {
System.err.println("Failed to load site configuration");
e.printStackTrace();
}
}
}
}

/**
* Search for the location of the 'configuration' dir, under the installation root.
* <p>
* Note that we cannot use something like {@code ConfigurationScope.INSTANCE.getLocation()} because it is not
* reliable in package installations where the installation directory is readonly. In such cases Eclipse will return
* a non-shared path under {@code ~/.eclipse/} which does not help is in locating any {@code site-config.ini} file.
*/
private static Path findInstallationConfigurationDir() {
var installDir = Path.of(Platform.getInstallLocation().getURL().getPath());

// Location on Linux/Windows
var configurationDir = installDir.resolve("configuration");
System.out.println("Searching " + configurationDir);
if (Files.exists(configurationDir)) {
System.out.println("exists");
return configurationDir;
}

// Location on macOS
var productName = Platform.getProduct().getName();
configurationDir = installDir.resolve(productName + ".app").resolve("Contents/Eclipse/configuration");
System.out.println("Searching " + configurationDir);
if (Files.exists(configurationDir)) {
System.out.println("exists");
return configurationDir;
}

return null;
}

public static Optional<Boolean> isSpellEnabled() {
var spellEnabled = props.getProperty("spell.enabled");
if (spellEnabled != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ public boolean isSpellEnabled() {
var spellEnabled = getPreferenceStore().getBoolean("spell.enabled");

var override = SiteConfiguration.isSpellEnabled();
System.out.println("Override present ? " + override.isPresent());
if (override.isPresent()) {
System.out.println("enabled " + override.get());
spellEnabled = override.get();
}
return spellEnabled;
Expand Down

0 comments on commit 9c9069b

Please sign in to comment.