Skip to content

Commit

Permalink
Share config and preferences with Core module
Browse files Browse the repository at this point in the history
  • Loading branch information
nroduit committed Apr 25, 2024
1 parent 6881ce2 commit 55db284
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 171 deletions.
6 changes: 6 additions & 0 deletions weasis-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
</build>

<dependencies>
<dependency>
<groupId>org.weasis.launcher</groupId>
<artifactId>weasis-launcher</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.command</artifactId>
Expand Down
27 changes: 27 additions & 0 deletions weasis-core/src/main/java/org/weasis/core/api/service/UICore.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.management.ManagementFactory;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
Expand All @@ -36,6 +37,10 @@
import java.util.Locale.Category;
import java.util.Map;
import java.util.Properties;
import javax.management.InstanceNotFoundException;
import javax.management.JMException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -58,6 +63,7 @@
import org.weasis.core.ui.util.Toolbar;
import org.weasis.core.util.FileUtil;
import org.weasis.core.util.StringUtil;
import org.weasis.pref.ConfigData;

public final class UICore {
public static final String P_FORMAT_CODE = "locale.format.code";
Expand All @@ -79,6 +85,7 @@ public final class UICore {
private final WProperties systemPreferences;
private final WProperties localPersistence;
private final WProperties initialSystemPreferences;
private final ConfigData configData;
private final HashMap<String, WProperties> pluginPersistenceMap;
private final File propsFile;

Expand All @@ -92,6 +99,7 @@ private UICore() {
this.baseArea = dockingControl.getContentArea();
this.mainArea = dockingControl.createWorkingArea("mainArea");
this.toolbarContainer = new ToolBarContainer();
this.configData = retrieveconfigData();
this.initialSystemPreferences = new WProperties();
this.systemPreferences = new WProperties();
this.pluginPersistenceMap = new HashMap<>();
Expand Down Expand Up @@ -139,6 +147,21 @@ public boolean willGainFocus(CDockable dockable) {
FileUtil.readProperties(new File(dataFolder, "persistence.properties"), localPersistence);
}

private static ConfigData retrieveconfigData() {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
try {
ObjectName objectName = ObjectName.getInstance("weasis:name=MainWindow"); // NON-NLS
Object preferences = server.getAttribute(objectName, "ConfigData");
if (preferences instanceof ConfigData configData) {
return configData;
}
} catch (InstanceNotFoundException ignored) {
} catch (JMException e) {
LOGGER.debug("Error while receiving main window", e);
}
throw new IllegalStateException("Cannot retrieve ConfigData");
}

/**
* Thread safe singleton instance.
*
Expand Down Expand Up @@ -352,6 +375,10 @@ public List<Codec<MediaElement>> getCodecPlugins() {
return codecPlugins;
}

public ConfigData getConfigData() {
return configData;
}

/**
* This the persistence used at launch which can be stored remotely. These are the preferences
* necessary for launching unlike the preferences associated with the plugins.
Expand Down
2 changes: 1 addition & 1 deletion weasis-distributions/etc/config/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"weasisPreferences": [
{
"code": "framework.system.packages.extra.basic",
"value": "com.formdev.flatlaf, com.formdev.flatlaf.extras, com.formdev.flatlaf.extras.components, com.formdev.flatlaf.icons, com.formdev.flatlaf.ui, com.formdev.flatlaf.util, com.sun.awt, com.sun.image.codec.jpeg, com.sun.imageio.spi, javax.accessibility, javax.imageio, javax.imageio.event, javax.imageio.metadata, javax.imageio.plugins.jpeg, javax.imageio.spi, javax.imageio.stream, javax.media, javax.swing, javax.swing.border, javax.swing.event, javax.swing.filechooser, javax.swing.plaf, javax.swing.plaf.basic, javax.swing.plaf.metal, javax.swing.table, javax.swing.text, javax.swing.tree, javax.xml.bind, javax.xml.parsers, javax.xml.namespace, javax.xml.stream, javax.xml.transform, javax.xml.transform.stax, javax.xml.validation, net.miginfocom.layout, net.miginfocom.swing, org.w3c.dom, org.xml.sax, org.xml.sax.ext, org.xml.sax.helpers, sun.awt, sun.awt.geom, sun.awt.image, sun.awt.image.codec, sun.java2d.opengl, sun.security.action, sun.misc, sun.net.www.protocol.file, sun.reflect",
"value": "com.formdev.flatlaf, com.formdev.flatlaf.extras, com.formdev.flatlaf.extras.components, com.formdev.flatlaf.icons, com.formdev.flatlaf.ui, com.formdev.flatlaf.util, com.sun.awt, com.sun.image.codec.jpeg, com.sun.imageio.spi, javax.accessibility, javax.imageio, javax.imageio.event, javax.imageio.metadata, javax.imageio.plugins.jpeg, javax.imageio.spi, javax.imageio.stream, javax.media, javax.swing, javax.swing.border, javax.swing.event, javax.swing.filechooser, javax.swing.plaf, javax.swing.plaf.basic, javax.swing.plaf.metal, javax.swing.table, javax.swing.text, javax.swing.tree, javax.xml.bind, javax.xml.parsers, javax.xml.namespace, javax.xml.stream, javax.xml.transform, javax.xml.transform.stax, javax.xml.validation, net.miginfocom.layout, net.miginfocom.swing, org.w3c.dom, org.weasis.pref, org.xml.sax, org.xml.sax.ext, org.xml.sax.helpers, sun.awt, sun.awt.geom, sun.awt.image, sun.awt.image.codec, sun.java2d.opengl, sun.security.action, sun.misc, sun.net.www.protocol.file, sun.reflect",
"description": "List of additional packages for Felix (by default only java.* is visible in main class loader)",
"type": "A",
"category": "FELIX_CONFIG"
Expand Down
2 changes: 1 addition & 1 deletion weasis-launcher/conf/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"weasisPreferences": [
{
"code": "framework.system.packages.extra.basic",
"value": "ch.qos.logback.classic,ch.qos.logback.classic.encoder,ch.qos.logback.classic.spi,ch.qos.logback.core,ch.qos.logback.core.encoder,ch.qos.logback.core.rolling,ch.qos.logback.core.util,com.formdev.flatlaf, com.formdev.flatlaf.extras, com.formdev.flatlaf.extras.components, com.formdev.flatlaf.icons, com.formdev.flatlaf.ui, com.formdev.flatlaf.util, com.sun.awt, com.sun.image.codec.jpeg, com.sun.imageio.spi, javax.accessibility, javax.imageio, javax.imageio.event, javax.imageio.metadata, javax.imageio.plugins.jpeg, javax.imageio.spi, javax.imageio.stream, javax.media, javax.swing, javax.swing.border, javax.swing.event, javax.swing.filechooser, javax.swing.plaf, javax.swing.plaf.basic, javax.swing.plaf.metal, javax.swing.table, javax.swing.text, javax.swing.tree, javax.xml.bind, javax.xml.parsers, javax.xml.namespace, javax.xml.stream, javax.xml.transform, javax.xml.transform.stax, javax.xml.validation, net.miginfocom.layout, net.miginfocom.swing, org.slf4j, org.w3c.dom, org.xml.sax, org.xml.sax.ext, org.xml.sax.helpers, sun.awt, sun.awt.geom, sun.awt.image, sun.awt.image.codec, sun.java2d.opengl, sun.security.action, sun.misc, sun.net.www.protocol.file, sun.reflect",
"value": "ch.qos.logback.classic,ch.qos.logback.classic.encoder,ch.qos.logback.classic.spi,ch.qos.logback.core,ch.qos.logback.core.encoder,ch.qos.logback.core.rolling,ch.qos.logback.core.util,com.formdev.flatlaf, com.formdev.flatlaf.extras, com.formdev.flatlaf.extras.components, com.formdev.flatlaf.icons, com.formdev.flatlaf.ui, com.formdev.flatlaf.util, com.sun.awt, com.sun.image.codec.jpeg, com.sun.imageio.spi, javax.accessibility, javax.imageio, javax.imageio.event, javax.imageio.metadata, javax.imageio.plugins.jpeg, javax.imageio.spi, javax.imageio.stream, javax.media, javax.swing, javax.swing.border, javax.swing.event, javax.swing.filechooser, javax.swing.plaf, javax.swing.plaf.basic, javax.swing.plaf.metal, javax.swing.table, javax.swing.text, javax.swing.tree, javax.xml.bind, javax.xml.parsers, javax.xml.namespace, javax.xml.stream, javax.xml.transform, javax.xml.transform.stax, javax.xml.validation, net.miginfocom.layout, net.miginfocom.swing, org.slf4j, org.w3c.dom, org.weasis.pref, org.xml.sax, org.xml.sax.ext, org.xml.sax.helpers, sun.awt, sun.awt.geom, sun.awt.image, sun.awt.image.codec, sun.java2d.opengl, sun.security.action, sun.misc, sun.net.www.protocol.file, sun.reflect",
"description": "List of additional packages for Felix (by default only java.* is visible in main class loader)",
"type": "A",
"category": "FELIX_CONFIG"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.weasis.pref.ConfigData;

public class AppLauncher extends WeasisLauncher implements Singleton.SingletonApp {

Expand Down Expand Up @@ -72,10 +73,11 @@ private void waitWhenStarted() {
@Override
public boolean canStartNewActivation(Properties prop) {
boolean sameUser =
configData.isPropertyValueSimilar(P_WEASIS_USER, prop.getProperty(P_WEASIS_USER));
configData.isPropertyValueSimilar(
ConfigData.P_WEASIS_USER, prop.getProperty(ConfigData.P_WEASIS_USER));
boolean sameConfig =
configData.isPropertyValueSimilar(
P_WEASIS_CONFIG_HASH, prop.getProperty(P_WEASIS_CONFIG_HASH));
ConfigData.P_WEASIS_CONFIG_HASH, prop.getProperty(ConfigData.P_WEASIS_CONFIG_HASH));
return sameUser && sameConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tukaani.xz.XZInputStream;
import org.weasis.pref.ConfigData;

/**
* @author Richard S. Hall
Expand Down Expand Up @@ -239,7 +240,7 @@ private static void loadTranslationBundle(
String filename = p.toString();
String value = modulesi18n.getProperty(filename);
if (value != null) {
String baseURL = System.getProperty(WeasisLauncher.P_WEASIS_I18N);
String baseURL = System.getProperty(ConfigData.P_WEASIS_I18N);
if (baseURL != null) {
String uri = baseURL + (baseURL.endsWith("/") ? filename : "/" + filename);
String bundleName = getBundleNameFromLocation(filename);
Expand Down
11 changes: 8 additions & 3 deletions weasis-launcher/src/main/java/org/weasis/launcher/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,26 @@ public static URLConnection getAdaptedConnection(URL url, boolean useCaches) thr
// Prevent caching of Java WebStart.
connection.setUseCaches(useCaches);
// Support for http proxy authentication.
String p = url.getProtocol();
String protocol = url.getProtocol();
String pauth = System.getProperty("http.proxyAuth", null);
if (Utils.hasText(pauth) && ("http".equals(p) || "https".equals(p))) { // NON-NLS
if (hasProxyProperty(pauth, protocol)) {
String base64 = Util.base64Encode(pauth);
connection.setRequestProperty("Proxy-Authorization", "Basic " + base64); // NON-NLS
}

String auth = System.getProperty("http.authorization", null);
if (Utils.hasText(auth) && ("http".equals(p) || "https".equals(p))) { // NON-NLS
if (hasProxyProperty(auth, protocol)) {
connection.setRequestProperty("Authorization", auth);
}

return connection;
}

private static boolean hasProxyProperty(String propertyValue, String protocol) {
return Utils.hasText(propertyValue)
&& ("http".equals(protocol) || "https".equals(protocol)); // NON-NLS
}

private static void copyZip(InputStream in, File file) throws IOException {
if (in == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.weasis.pref.ConfigData;

public class Singleton {
private static final Logger LOGGER = LoggerFactory.getLogger(Singleton.class);
Expand Down Expand Up @@ -186,8 +187,8 @@ static boolean connectToServer(ConfigData configData) {

out.println(SI_PROP);
Properties p = configData.getProperties();
printProperty(out, WeasisLauncher.P_WEASIS_USER, p);
printProperty(out, WeasisLauncher.P_WEASIS_CONFIG_HASH, p);
printProperty(out, ConfigData.P_WEASIS_USER, p);
printProperty(out, ConfigData.P_WEASIS_CONFIG_HASH, p);

// indicate end of file transmission
out.println(SI_EOF);
Expand Down
4 changes: 0 additions & 4 deletions weasis-launcher/src/main/java/org/weasis/launcher/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ public static boolean hasLength(CharSequence str) {
return str != null && !str.isEmpty();
}

public static boolean hasLength(String str) {
return hasLength((CharSequence) str);
}

public static boolean hasText(CharSequence str) {
if (!hasLength(str)) {
return false;
Expand Down
Loading

0 comments on commit 55db284

Please sign in to comment.