Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 17 additions & 30 deletions core/launcher/src/main/java/org/phoebus/product/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import javafx.application.Application;
import org.phoebus.framework.preferences.PropertyPreferenceLoader;
import org.phoebus.framework.preferences.PropertyPreferenceWriter;
import org.phoebus.framework.spi.AppDescriptor;
import org.phoebus.framework.spi.AppResourceDescriptor;
import org.phoebus.framework.workbench.ApplicationService;
import org.phoebus.framework.workbench.Locations;
import org.phoebus.ui.application.ApplicationServer;
import org.phoebus.ui.application.PhoebusApplication;

import java.io.*;
import java.io.File;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.util.ArrayList;
Expand All @@ -23,16 +25,13 @@
import java.util.prefs.Preferences;
import java.util.stream.Collectors;

import static org.phoebus.ui.application.PhoebusApplication.logger;

@SuppressWarnings("nls")
public class Launcher {
private static final String LOGGING_OPTION = "-logging";
private static final String DEFAULT_LOGGING_FILE="/logging.properties";
private static final String LOGGING_PROP = "java.util.logging.config.file";
private static final String SETTINGS_SNAPSHOT = "settings_snapshot";

public static void main(final String[] original_args) throws Exception {

Check warning on line 34 in core/launcher/src/main/java/org/phoebus/product/Launcher.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 149 to 64, Complexity from 31 to 14, Nesting Level from 5 to 2, Number of Variables from 28 to 6.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ1kMlrPs6QQoj5JptY0&open=AZ1kMlrPs6QQoj5JptY0&pullRequest=3771
// First Handle arguments, potentially not even starting the UI
// settings and logging will define the phoebus.install value if not exist
final List<String> args = new ArrayList<>(List.of(original_args));
Expand Down Expand Up @@ -96,11 +95,15 @@
Locations.initialize();
// Check for site-specific settings.ini bundled into distribution
// before potentially adding command-line settings.
final File siteSettings = new File(Locations.install(), "settings.ini");
if (siteSettings.canRead())
final File site_settings = new File(Locations.install(), "settings.ini");

Check warning on line 98 in core/launcher/src/main/java/org/phoebus/product/Launcher.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ1kJxMYV80h1QdmoePL&open=AZ1kJxMYV80h1QdmoePL&pullRequest=3771
if (site_settings.canRead())
{
logger.info("Loading bundled settings from " + siteSettings.getAbsolutePath());
loadSettings(siteSettings.getAbsolutePath());
logger.info("Loading bundled settings from " + site_settings.getAbsolutePath());
final FileInputStream fileInputStream = new FileInputStream(site_settings);
if (site_settings.getName().endsWith(".xml"))
Preferences.importPreferences(fileInputStream);
else
PropertyPreferenceLoader.load(fileInputStream);
}

// Handle arguments, potentially not even starting the UI
Expand Down Expand Up @@ -137,7 +140,11 @@
iter.remove();

logger.info("Loading settings from " + location);
loadSettings(location);
if (location.endsWith(".xml"))
Preferences.importPreferences(new FileInputStream(location));
else
PropertyPreferenceLoader.load(location);

} else if (cmd.equals("-export_settings")) {
if (!iter.hasNext())
throw new Exception("Missing -export_settings file name");
Expand Down Expand Up @@ -213,26 +220,6 @@
Application.launch(PhoebusApplication.class, args.toArray(new String[args.size()]));
}

private static void loadSettings(String location) throws Exception {
if (location.endsWith(".xml"))
Preferences.importPreferences(new FileInputStream(location));
else
PropertyPreferenceLoader.load(location);

// Preference settings
final ByteArrayOutputStream prefsBuf = new ByteArrayOutputStream();
try
{
PropertyPreferenceWriter.save(prefsBuf);
}
catch (Exception ex)
{
logger.log(Level.WARNING, "Cannot list preferences", ex);
}

Preferences.userRoot().put(SETTINGS_SNAPSHOT, prefsBuf.toString());
}

private static void help() {
System.out.println(" _______ _______ _______ ______ _______ ");
System.out.println("( ____ )|\\ /|( ___ )( ____ \\( ___ \\ |\\ /|( ____ \\");
Expand Down
24 changes: 19 additions & 5 deletions core/ui/src/main/java/org/phoebus/ui/help/OpenAbout.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
*******************************************************************************/
package org.phoebus.ui.help;

import static org.phoebus.ui.application.PhoebusApplication.logger;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.prefs.Preferences;
import java.util.logging.Level;

import org.phoebus.framework.preferences.PropertyPreferenceWriter;
import org.phoebus.framework.workbench.ApplicationService;
import org.phoebus.framework.workbench.Locations;
import org.phoebus.ui.application.Messages;
Expand Down Expand Up @@ -46,7 +50,6 @@
@SuppressWarnings("nls")
public class OpenAbout implements MenuEntry
{
private static final String SETTINGS_SNAPSHOT = "settings_snapshot";
/** Non-<code>null</code> while the 'about' dialog is shown */
private Alert dialog;

Expand Down Expand Up @@ -191,19 +194,30 @@
area.setEditable(false);
final Tab props = new Tab(Messages.HelpAboutSysFea, area);

String settingsSnapshot = Preferences.userRoot().get(SETTINGS_SNAPSHOT, "");
// Preference settings
final ByteArrayOutputStream prefs_buf = new ByteArrayOutputStream();

Check warning on line 198 in core/ui/src/main/java/org/phoebus/ui/help/OpenAbout.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ1kMlo2s6QQoj5JptYy&open=AZ1kMlo2s6QQoj5JptYy&pullRequest=3771
try
{
PropertyPreferenceWriter.save(prefs_buf);
}
catch (Exception ex)
{
logger.log(Level.WARNING, "Cannot list preferences", ex);
}

WebView webView = new WebView();
String content = "<html><head><style>" +
"body {font-family: monospace;}" +
"</style></head><body>";
content += settingsSnapshot;
content += prefs_buf.toString();
content += "</body></html>";
webView.getEngine().loadContent(content);

VBox.setVgrow(webView, Priority.ALWAYS);

final Tab prefs = new Tab(Messages.HelpAboutPrefs, webView);

return new TabPane(apps, envs, props, prefs);
final TabPane tabs = new TabPane(apps, envs, props, prefs);

Check warning on line 220 in core/ui/src/main/java/org/phoebus/ui/help/OpenAbout.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Immediately return this expression instead of assigning it to the temporary variable "tabs".

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ1kMlo2s6QQoj5JptYz&open=AZ1kMlo2s6QQoj5JptYz&pullRequest=3771
return tabs;
}
}
Loading