Skip to content

Commit

Permalink
Application data, User Library and Preferences are now stored specifi…
Browse files Browse the repository at this point in the history
…c to each SceneBuilder version. Thus multiple versions can run in parallel.
  • Loading branch information
Oliver-Loeffler committed Aug 29, 2021
1 parent 487965e commit ff8d084
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 15 deletions.
8 changes: 8 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
<artifactId>kit</artifactId>
<version>16.0.0-SNAPSHOT</version>
</dependency>

<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Gluon and/or its affiliates.
* Copyright (c) 2017, 2021, Gluon and/or its affiliates.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
Expand Down Expand Up @@ -32,6 +32,7 @@
*/
package com.oracle.javafx.scenebuilder.app;

import com.oracle.javafx.scenebuilder.app.util.AppSettings;
import com.oracle.javafx.scenebuilder.app.util.MessageBox;
import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform;
import static com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform.IS_LINUX;
Expand Down Expand Up @@ -61,26 +62,41 @@ public static synchronized String getApplicationDataFolder() {

if (applicationDataFolder == null) {
final String appName = "Scene Builder"; //NOI18N

final String appVersion = getApplicationVersion();
if (IS_WINDOWS) {
applicationDataFolder
= System.getenv("APPDATA") + "\\" + appName; //NOI18N
= System.getenv("APPDATA") + "\\" + appName + "-" + appVersion; //NOI18N
} else if (IS_MAC) {
applicationDataFolder
= System.getProperty("user.home") //NOI18N
+ "/Library/Application Support/" //NOI18N
+ appName;
+ appName + "-" + appVersion; //NOI18N
} else if (IS_LINUX) {
applicationDataFolder
= System.getProperty("user.home") + "/.scenebuilder"; //NOI18N
= System.getProperty("user.home") + "/.scenebuilder-"+appVersion; //NOI18N
}
}

assert applicationDataFolder != null;

return applicationDataFolder;
}


/*
* TODO:
* How to deal with snapshot versions?
* Shall the suffix "-SNAPSHOT" be ignored?
*
* For testing it would be helpful to have
* the snapshot suffix as with that one could run
* released vs. non-released SB versions.
*/
private static String getApplicationVersion() {
String version = AppSettings.getSceneBuilderVersion();
assert version != null;
assert !version.isBlank();
return version;
}

public static synchronized String getUserLibraryFolder() {

Expand All @@ -96,15 +112,15 @@ public static synchronized String getUserLibraryFolder() {
* @return Directory path for Scene Builder logs
*/
public static synchronized String getLogFolder() {
final String appVersion = AppSettings.getSceneBuilderVersion();
if (logsFolder == null) {
logsFolder = Paths.get(System.getProperty("user.home"), ".scenebuilder", "logs").toString(); //NOI18N
logsFolder = Paths.get(System.getProperty("user.home"), ".scenebuilder-"+appVersion, "logs").toString(); //NOI18N
}
return logsFolder;
}

public static boolean requestStart(
AppNotificationHandler notificationHandler, Application.Parameters parameters)
throws IOException {
public static boolean requestStart(AppNotificationHandler notificationHandler,
Application.Parameters parameters) throws IOException {
if (EditorPlatform.isAssertionEnabled()) {
// Development mode : we do not delegate to the existing instance
notificationHandler.handleLaunch(parameters.getUnnamed());
Expand All @@ -126,9 +142,8 @@ public interface AppNotificationHandler {
* Private (requestStartGeneric)
*/

private static synchronized boolean requestStartGeneric(
AppNotificationHandler notificationHandler, Application.Parameters parameters)
throws IOException {
private static synchronized boolean requestStartGeneric(AppNotificationHandler notificationHandler,
Application.Parameters parameters) throws IOException {
assert notificationHandler != null;
assert parameters != null;
assert messageBox == null;
Expand Down Expand Up @@ -165,7 +180,7 @@ private static synchronized boolean requestStartGeneric(
return result;
}

private static String getMessageBoxFolder() {
protected static String getMessageBoxFolder() {
if (messageBoxFolder == null) {
messageBoxFolder = getApplicationDataFolder() + "/MB"; //NOI18N
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package com.oracle.javafx.scenebuilder.app.preferences;

import com.oracle.javafx.scenebuilder.app.DocumentWindowController;
import com.oracle.javafx.scenebuilder.app.util.AppSettings;
import com.oracle.javafx.scenebuilder.kit.preferences.PreferencesControllerBase;

import java.util.HashMap;
Expand All @@ -54,7 +55,7 @@ public class PreferencesController extends PreferencesControllerBase{
**************************************************************************/

// PREFERENCES NODE NAME
static final String SB_RELEASE_NODE = "SB_2.0"; //NOI18N
static final String SB_RELEASE_NODE = "SB_"+AppSettings.getSceneBuilderVersion(); //NOI18N

// GLOBAL PREFERENCES
static final String TOOL_THEME = "TOOL_THEME"; //NOI18N
Expand Down Expand Up @@ -180,4 +181,8 @@ public void clearRecentItems() {
public PreferencesRecordGlobal getRecordGlobal() {
return (PreferencesRecordGlobal) recordGlobal;
}

protected String getEffectiveUsedRootNode() {
return applicationRootPreferences.absolutePath();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright (c) 2021, Gluon and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
* This file is available and licensed under the following license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
* - Neither the name of Oracle Corporation and Gluon nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.oracle.javafx.scenebuilder.app;

import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Locale;

import org.junit.Test;

import com.oracle.javafx.scenebuilder.app.util.AppSettings;

public class AppPlatformTest {

private final String appVersion = AppSettings.getSceneBuilderVersion();

@Test
public void that_windows_application_data_directory_is_specific_to_version() {
assumeTrue(getOsName().contains("windows"));
Path appDataDir = Paths.get(AppPlatform.getApplicationDataFolder());
Path expected = Paths.get(System.getenv("APPDATA"))
.resolve("Scene Builder-"+appVersion);
assertEquals(expected, appDataDir);
}

@Test
public void that_mac_application_data_directory_is_specific_to_version() {
assumeTrue(getOsName().contains("mac"));
Path appDataDir = Paths.get(AppPlatform.getApplicationDataFolder());
Path expected = Paths.get(System.getProperty("user.home"))
.resolve("Library")
.resolve("Application Support")
.resolve("Scene Builder-"+appVersion);
assertEquals(expected, appDataDir);
}

@Test
public void that_linux_application_data_directory_is_specific_to_version() {
assumeTrue(getOsName().contains("linux"));
Path appDataDir = Paths.get(AppPlatform.getApplicationDataFolder());
Path expected = Paths.get(System.getProperty("user.home"))
.resolve(".scenebuilder-"+appVersion);
assertEquals(expected, appDataDir);
}

@Test
public void that_user_library_resides_in_application_settings_folder() {
Path userLibraryFolder = Paths.get(AppPlatform.getUserLibraryFolder());
Path expected = Paths.get(AppPlatform.getApplicationDataFolder())
.resolve("Library");
assertEquals(expected, userLibraryFolder);
}

@Test
public void that_logfile_stored_in_userhome_version_specific_log_dir() {
Path logDir = Paths.get(AppPlatform.getLogFolder());
Path expected = Paths.get(System.getProperty("user.home"))
.resolve(".scenebuilder-"+appVersion)
.resolve("logs");
assertEquals(expected, logDir);
}

@Test
public void that_messagebox_is_placed_in_application_dir() {
Path mboxDir = Paths.get(AppPlatform.getMessageBoxFolder());
Path expected = Paths.get(AppPlatform.getApplicationDataFolder())
.resolve("MB");
assertEquals(expected, mboxDir);
}

private String getOsName() {
return System.getProperty("os.name").toLowerCase(Locale.ROOT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2021, Gluon and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
* This file is available and licensed under the following license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
* - Neither the name of Oracle Corporation and Gluon nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.oracle.javafx.scenebuilder.app.preferences;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import com.oracle.javafx.scenebuilder.app.util.AppSettings;

public class PreferencesControllerTest {

@Test
public void that_preferences_are_stored_per_version() {
String appVersion = AppSettings.getSceneBuilderVersion();
String versionSpecificNode = "SB_"+appVersion;
assertEquals(versionSpecificNode, PreferencesController.SB_RELEASE_NODE);
}

@Test
public void that_prefs_root_node_is_version_specific() {
String prefsNodeUsed = PreferencesController.getSingleton()
.getEffectiveUsedRootNode();
String appVersion = AppSettings.getSceneBuilderVersion();
String versionSpecificNode = "SB_"+appVersion;
String expectedPrefsNode = "/com/oracle/javafx/scenebuilder/app/preferences/"+versionSpecificNode;
assertEquals(expectedPrefsNode, prefsNodeUsed);
}
}

0 comments on commit ff8d084

Please sign in to comment.