mirror of
https://github.com/mitb-archive/filebot
synced 2025-03-09 13:59:49 -04:00
+ added portable profile
This commit is contained in:
parent
cb16e56f87
commit
bb8f4fb3e7
29
build.xml
29
build.xml
@ -213,8 +213,22 @@
|
||||
<arg line="${dir.dist}/msi.wixobj -sval -ext WixUIExtension -out ${installer}" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
|
||||
|
||||
|
||||
<target name="portable" depends="fatjar" description="Portable application package">
|
||||
<mkdir dir="${dir.dist}/portable"/>
|
||||
<copy file="${path.fatjar}" tofile="${dir.dist}/portable/FileBot.jar" />
|
||||
<copy todir="${dir.dist}/portable">
|
||||
<fileset dir="${dir.installer}/portable" includes="*.exe, *.ini, *.sh" />
|
||||
</copy>
|
||||
|
||||
<zip destfile="${dir.dist}/FileBot_${version}-portable.zip">
|
||||
<zipfileset dir="${dir.dist}/portable" includes="*.jar, *.exe, *.ini" />
|
||||
<zipfileset dir="${dir.dist}/portable" includes="*.sh" filemode="755" />
|
||||
</zip>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="webstart" depends="jar" description="Build and compress jars used for webstart deployment">
|
||||
<!-- create dirs -->
|
||||
<mkdir dir="${dir.dist}/webstart" />
|
||||
@ -378,17 +392,18 @@
|
||||
</target>
|
||||
|
||||
|
||||
<target name="deploy-release" depends="svn-update, fatjar, appbundle, deb, msi, webstart">
|
||||
<target name="deploy-release" depends="svn-update, fatjar, appbundle, deb, msi, portable, webstart">
|
||||
<mkdir dir="${dir.dist}/release" />
|
||||
|
||||
<!-- prepare release packages -->
|
||||
<copy todir="${dir.dist}/release/${title}_${version}" file="${path.fatjar}" />
|
||||
<copy todir="${dir.dist}/release/${title}_${version}" file="${path.appbundle.tar.gz}" />
|
||||
<copy todir="${dir.dist}/release/${title}_${version}" file="${path.source.zip}" />
|
||||
<copy todir="${dir.dist}/release/${title}_${version}" file="${dir.dist}/filebot_${version}_i386.deb" />
|
||||
<copy todir="${dir.dist}/release/${title}_${version}" file="${dir.dist}/filebot_${version}_amd64.deb" />
|
||||
<copy todir="${dir.dist}/release/${title}_${version}" file="${dir.dist}/FileBot_${version}_x86.msi" />
|
||||
<copy todir="${dir.dist}/release/${title}_${version}" file="${dir.dist}/FileBot_${version}_x64.msi" />
|
||||
<copy todir="${dir.dist}/release/${title}_${version}" file="${dir.dist}/FileBot_${version}-portable.zip" />
|
||||
<copy todir="${dir.dist}/release/${title}_${version}" file="${path.source.zip}" />
|
||||
|
||||
<!-- ask for sourceforge password -->
|
||||
<property name="sf.user" value="rednoah,filebot" />
|
||||
@ -404,6 +419,12 @@
|
||||
<scp todir="${sf.user}:${sf.password}@${deploy.release}" trust="yes" verbose="true">
|
||||
<fileset dir="${dir.dist}/release" includes="**/*.jar" />
|
||||
</scp>
|
||||
|
||||
<!-- deploy portable application package -->
|
||||
<sleep seconds="5" />
|
||||
<scp todir="${sf.user}:${sf.password}@${deploy.release}" trust="yes" verbose="true">
|
||||
<fileset dir="${dir.dist}/release" includes="**/*-portable.zip" />
|
||||
</scp>
|
||||
|
||||
<!-- deploy windows installers -->
|
||||
<sleep seconds="5" />
|
||||
|
@ -19,6 +19,5 @@
|
||||
<maxVersion></maxVersion>
|
||||
<jdkPreference>preferJre</jdkPreference>
|
||||
<maxHeapSize>256</maxHeapSize>
|
||||
<opt>-Dapplication.deployment=msi</opt>
|
||||
</jre>
|
||||
</launch4jConfig>
|
@ -15,7 +15,7 @@
|
||||
<icon>..\icons\shortcut.ico</icon>
|
||||
<singleInstance>
|
||||
<mutexName>net.sourceforge.filebot</mutexName>
|
||||
<windowTitle>FileBot</windowTitle>
|
||||
<windowTitle></windowTitle>
|
||||
</singleInstance>
|
||||
<jre>
|
||||
<path></path>
|
||||
|
@ -17,6 +17,7 @@
|
||||
<File Id='filebot.platform.launcher.exe' Name='filebot.platform.launcher.exe' Source='filebot.platform.launcher.exe'>
|
||||
<Shortcut Id="shortcut.menu.filebot.platform" Directory="ProgramMenuDir" Name="FileBot (platform)" Description="Launch FileBot with platform-independent configuration" WorkingDirectory='INSTALLDIR' Icon="icon.ico" IconIndex="0" Advertise="no" />
|
||||
</File>
|
||||
<File Id='filebot.launcher.l4j.ini' Name='filebot.launcher.l4j.ini' Source='filebot.launcher.l4j.ini' />
|
||||
<File Id='filebot.platform.launcher.l4j.ini' Name='filebot.platform.launcher.l4j.ini' Source='filebot.platform.launcher.l4j.ini' />
|
||||
<Shortcut Id="shortcut.uninstall" Directory="ProgramMenuDir" Name="Uninstall" Description="Uninstall FileBot" Target="[SystemFolder]msiexec.exe" Arguments="/x [ProductCode]" Advertise="no" />
|
||||
</Component>
|
||||
|
@ -1,2 +1,2 @@
|
||||
@ECHO OFF
|
||||
java -Dapplication.deployment=msi -Xmx256m -jar "%~dp0FileBot.jar" %*
|
||||
java -Dapplication.dir="%APPDATA%\FileBot" -Dapplication.deployment=msi -Djava.io.tmpdir="%APPDATA%\FileBot\temp" -Xmx256m -jar "%~dp0FileBot.jar" %*
|
||||
|
Binary file not shown.
7
installer/msi/filebot.launcher.l4j.ini
Normal file
7
installer/msi/filebot.launcher.l4j.ini
Normal file
@ -0,0 +1,7 @@
|
||||
# FileBot launch4j runtime config
|
||||
-Dapplication.deployment=msi
|
||||
-Dapplication.dir="%APPDATA%\FileBot"
|
||||
-Djava.io.tmpdir="%APPDATA%\FileBot\temp"
|
||||
|
||||
# memory settings
|
||||
-Xmx256m
|
Binary file not shown.
@ -1,12 +1,14 @@
|
||||
# FileBot launch4j runtime config
|
||||
-Dapplication.deployment=msi
|
||||
-Dfile.encoding=UTF-8
|
||||
-Dapplication.dir="%APPDATA%\FileBot"
|
||||
-Djava.io.tmpdir="%APPDATA%\FileBot\temp"
|
||||
|
||||
# memory settings
|
||||
-Xms64m
|
||||
-Xmx512m
|
||||
|
||||
# force english locale
|
||||
-Dfile.encoding=UTF-8
|
||||
-Duser.country=US
|
||||
-Duser.country.format=US
|
||||
-Duser.language=en
|
||||
|
23
installer/portable/FileBot-launch4j.xml
Normal file
23
installer/portable/FileBot-launch4j.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<launch4jConfig>
|
||||
<dontWrapJar>true</dontWrapJar>
|
||||
<headerType>gui</headerType>
|
||||
<jar>FileBot.jar</jar>
|
||||
<outfile>FileBot.exe</outfile>
|
||||
<errTitle></errTitle>
|
||||
<cmdLine></cmdLine>
|
||||
<chdir></chdir>
|
||||
<priority>normal</priority>
|
||||
<downloadUrl>http://java.com/download</downloadUrl>
|
||||
<supportUrl></supportUrl>
|
||||
<customProcName>false</customProcName>
|
||||
<stayAlive>false</stayAlive>
|
||||
<manifest></manifest>
|
||||
<icon>..\icons\shortcut.ico</icon>
|
||||
<jre>
|
||||
<path></path>
|
||||
<minVersion>1.6.0</minVersion>
|
||||
<maxVersion></maxVersion>
|
||||
<jdkPreference>preferJre</jdkPreference>
|
||||
<maxHeapSize>256</maxHeapSize>
|
||||
</jre>
|
||||
</launch4jConfig>
|
BIN
installer/portable/FileBot.exe
Normal file
BIN
installer/portable/FileBot.exe
Normal file
Binary file not shown.
15
installer/portable/FileBot.l4j.ini
Normal file
15
installer/portable/FileBot.l4j.ini
Normal file
@ -0,0 +1,15 @@
|
||||
# FileBot launch4j runtime config
|
||||
-Dapplication.deployment=portable
|
||||
-Dapplication.dir="%EXEDIR%"
|
||||
-Duser.home="%EXEDIR%"
|
||||
-Djava.io.tmpdir="%EXEDIR%\temp"
|
||||
|
||||
# memory settings
|
||||
-Xmx256m
|
||||
|
||||
# look for native libs here
|
||||
-Djna.library.path="%EXEDIR%"
|
||||
|
||||
# store preferences to text file
|
||||
-Djava.util.prefs.PreferencesFactory=net.sourceforge.tuned.prefs.FilePreferencesFactory
|
||||
-Dnet.sourceforge.tuned.prefs.file=prefs.properties
|
7
installer/portable/filebot.sh
Normal file
7
installer/portable/filebot.sh
Normal file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
||||
dir_bin="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
|
||||
# WARNING: NOT TESTED / HERE THERE BE DRAGONS
|
||||
javaw -Dapplication.deployment=portable -Dapplication.dir="$dir_bin" -Duser.home="$dir_bin" -Djava.io.tmpdir="$dir_bin/temp" -Djna.library.path="$dir_bin" -Djava.util.prefs.PreferencesFactory=net.sourceforge.tuned.prefs.FilePreferencesFactory -Dnet.sourceforge.tuned.prefs.file=prefs.properties -Xmx256m -jar "$dir_app/FileBot.jar" "$@"
|
@ -27,7 +27,8 @@
|
||||
|
||||
<resources>
|
||||
<property name="application.deployment" value="webstart" />
|
||||
<property name="jnlp.packEnabled" value="true" />
|
||||
<property name="application.update" value="skip" />
|
||||
<property name="jnlp.packEnabled" value="true" />
|
||||
|
||||
<java version="1.6+" max-heap-size="256m" />
|
||||
<jar href="filebot.jar" download="eager" main="true" />
|
||||
|
@ -39,7 +39,7 @@
|
||||
|
||||
Subdirectories can be specified below the property e.g. java.io.tmpdir/one
|
||||
-->
|
||||
<diskStore path="user.home/.filebot/cache" />
|
||||
<diskStore path="java.io.tmpdir/filebot-ehcache" />
|
||||
|
||||
<!--
|
||||
Cache configuration
|
||||
|
@ -117,7 +117,7 @@ public class Main {
|
||||
MediaTypes.getDefault();
|
||||
|
||||
// check for application updates (only when installed, i.e. not running via fatjar or webstart)
|
||||
if (!isPortableDeployment()) {
|
||||
if (!"skip".equals(System.getProperty("application.update"))) {
|
||||
checkUpdate();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -51,21 +51,26 @@ public final class Settings {
|
||||
|
||||
|
||||
public static File getApplicationFolder() {
|
||||
// special handling for web start
|
||||
if (getApplicationDeployment() != null) {
|
||||
// can't use working directory for web start applications
|
||||
File folder = new File(System.getProperty("user.home"), ".filebot");
|
||||
|
||||
// create folder if necessary
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
}
|
||||
|
||||
return folder;
|
||||
String applicationDirPath = System.getProperty("application.dir");
|
||||
File applicationFolder = null;
|
||||
|
||||
if (applicationDirPath != null && applicationDirPath.length() > 0) {
|
||||
// use given path
|
||||
applicationFolder = new File(applicationDirPath);
|
||||
} else if (getApplicationDeployment() != null) {
|
||||
// create folder in user home (can't use working directory for web start applications)
|
||||
applicationFolder = new File(System.getProperty("user.home"), ".filebot");
|
||||
} else {
|
||||
// use working directory
|
||||
applicationFolder = new File(System.getProperty("user.dir"));
|
||||
}
|
||||
|
||||
// use working directory
|
||||
return new File(System.getProperty("user.dir"));
|
||||
// create folder if necessary
|
||||
if (!applicationFolder.exists()) {
|
||||
applicationFolder.mkdirs();
|
||||
}
|
||||
|
||||
return applicationFolder;
|
||||
}
|
||||
|
||||
|
||||
@ -137,12 +142,6 @@ public final class Settings {
|
||||
}
|
||||
|
||||
|
||||
public static boolean isPortableDeployment() {
|
||||
String deployment = getApplicationDeployment();
|
||||
return deployment == null || deployment.equals("webstart");
|
||||
}
|
||||
|
||||
|
||||
public static int getApplicationRevisionNumber() {
|
||||
try {
|
||||
Manifest manifest = new Manifest(Settings.class.getResourceAsStream("/META-INF/MANIFEST.MF"));
|
||||
|
@ -26,19 +26,19 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
private final Preferences prefs;
|
||||
private final Adapter<T> adapter;
|
||||
|
||||
|
||||
|
||||
public PreferencesMap(Preferences prefs, Adapter<T> adapter) {
|
||||
this.prefs = prefs;
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public T get(Object key) {
|
||||
return adapter.get(prefs, key.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public T put(String key, T value) {
|
||||
adapter.put(prefs, key, value);
|
||||
@ -47,7 +47,7 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public T remove(Object key) {
|
||||
adapter.remove(prefs, key.toString());
|
||||
@ -56,7 +56,7 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String[] keys() {
|
||||
try {
|
||||
return adapter.keys(prefs);
|
||||
@ -65,7 +65,7 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
for (String key : keys()) {
|
||||
@ -73,7 +73,7 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
if (key instanceof String) {
|
||||
@ -83,7 +83,7 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
for (String key : keys()) {
|
||||
@ -94,7 +94,7 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Set<Entry<String, T>> entrySet() {
|
||||
Set<Map.Entry<String, T>> entries = new LinkedHashSet<Map.Entry<String, T>>();
|
||||
@ -106,19 +106,19 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Set<String> keySet() {
|
||||
return new LinkedHashSet<String>(Arrays.asList(keys()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void putAll(Map<? extends String, ? extends T> map) {
|
||||
for (Map.Entry<? extends String, ? extends T> entry : map.entrySet()) {
|
||||
@ -126,13 +126,13 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return keys().length;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<T> values() {
|
||||
List<T> values = new ArrayList<T>();
|
||||
@ -144,48 +144,48 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static PreferencesMap<String> map(Preferences prefs) {
|
||||
return map(prefs, new StringAdapter());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static <T> PreferencesMap<T> map(Preferences prefs, Adapter<T> adapter) {
|
||||
return new PreferencesMap<T>(prefs, adapter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static interface Adapter<T> {
|
||||
|
||||
public String[] keys(Preferences prefs) throws BackingStoreException;
|
||||
|
||||
|
||||
|
||||
public T get(Preferences prefs, String key);
|
||||
|
||||
|
||||
|
||||
public void put(Preferences prefs, String key, T value);
|
||||
|
||||
|
||||
|
||||
public void remove(Preferences prefs, String key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static abstract class AbstractAdapter<T> implements Adapter<T> {
|
||||
|
||||
@Override
|
||||
public abstract T get(Preferences prefs, String key);
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public abstract void put(Preferences prefs, String key, T value);
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String[] keys(Preferences prefs) throws BackingStoreException {
|
||||
return prefs.keys();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void remove(Preferences prefs, String key) {
|
||||
prefs.remove(key);
|
||||
@ -193,7 +193,7 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class StringAdapter extends AbstractAdapter<String> {
|
||||
|
||||
@Override
|
||||
@ -201,7 +201,7 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
return prefs.get(key, null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void put(Preferences prefs, String key, String value) {
|
||||
prefs.put(key, value);
|
||||
@ -209,12 +209,12 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class SimpleAdapter<T> extends AbstractAdapter<T> {
|
||||
|
||||
private final Constructor<T> constructor;
|
||||
|
||||
|
||||
|
||||
public SimpleAdapter(Class<T> type) {
|
||||
try {
|
||||
constructor = type.getConstructor(String.class);
|
||||
@ -223,7 +223,7 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public T get(Preferences prefs, String key) {
|
||||
String value = prefs.get(key, null);
|
||||
@ -242,20 +242,20 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void put(Preferences prefs, String key, T value) {
|
||||
prefs.put(key, value.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static <T> SimpleAdapter<T> forClass(Class<T> type) {
|
||||
return new SimpleAdapter<T>(type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class SerializableAdapter<T extends Serializable> extends AbstractAdapter<T> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -277,7 +277,7 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void put(Preferences prefs, String key, T value) {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
@ -294,7 +294,7 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class PreferencesEntry<T> implements Entry<String, T> {
|
||||
|
||||
private final String key;
|
||||
@ -303,50 +303,45 @@ public class PreferencesMap<T> implements Map<String, T> {
|
||||
|
||||
private final Adapter<T> adapter;
|
||||
|
||||
|
||||
private T defaultValue = null;
|
||||
|
||||
|
||||
public PreferencesEntry(Preferences prefs, String key, Adapter<T> adapter) {
|
||||
this.key = key;
|
||||
this.prefs = prefs;
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public T getValue() {
|
||||
return adapter.get(prefs, key);
|
||||
T value = adapter.get(prefs, key);
|
||||
return value != null ? value : defaultValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public T setValue(T value) {
|
||||
adapter.put(prefs, key, value);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public PreferencesEntry<T> defaultValue(T value) {
|
||||
try {
|
||||
// check if value valid and not null
|
||||
getValue().getClass();
|
||||
} catch (Exception e) {
|
||||
// illegal value or null, just override
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
|
||||
public PreferencesEntry<T> defaultValue(T defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void remove() {
|
||||
adapter.remove(prefs, key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
216
source/net/sourceforge/tuned/prefs/FilePreferences.java
Normal file
216
source/net/sourceforge/tuned/prefs/FilePreferences.java
Normal file
@ -0,0 +1,216 @@
|
||||
// https://github.com/sonatype/nexus/blob/2f0e154ec565969b4fd8698883ab76a461210f4f/nexus/nexus-test-harness/nexus-it-helper-plugin/src/main/java/org/sonatype/nexus/rt/prefs/FilePreferences.java
|
||||
|
||||
package net.sourceforge.tuned.prefs;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeMap;
|
||||
import java.util.prefs.AbstractPreferences;
|
||||
import java.util.prefs.BackingStoreException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Preferences implementation that stores to a user-defined file. See FilePreferencesFactory. Modified by cstamas,
|
||||
* switched to SLF4J logging, and exposed preferences file property.
|
||||
*
|
||||
* Modified to use '/' as path separator and not '.' because it breaks when keys containing '.' are used.
|
||||
*
|
||||
* @author David Croft (<a href="http://www.davidc.net">www.davidc.net</a>)
|
||||
* @version $Id: FilePreferences.java 283 2009-06-18 17:06:58Z david $
|
||||
*/
|
||||
public class FilePreferences extends AbstractPreferences {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(FilePreferences.class.getName());
|
||||
|
||||
private Map<String, String> root;
|
||||
|
||||
private Map<String, FilePreferences> children;
|
||||
|
||||
private boolean isRemoved = false;
|
||||
|
||||
|
||||
public FilePreferences(AbstractPreferences parent, String name) {
|
||||
super(parent, name);
|
||||
|
||||
log.debug("Instantiating node {}", name);
|
||||
|
||||
root = new TreeMap<String, String>();
|
||||
children = new TreeMap<String, FilePreferences>();
|
||||
|
||||
try {
|
||||
sync();
|
||||
} catch (BackingStoreException e) {
|
||||
log.error("Unable to sync on creation of node " + name, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void putSpi(String key, String value) {
|
||||
root.put(key, value);
|
||||
try {
|
||||
flush();
|
||||
} catch (BackingStoreException e) {
|
||||
log.error("Unable to flush after putting " + key, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getSpi(String key) {
|
||||
return root.get(key);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void removeSpi(String key) {
|
||||
root.remove(key);
|
||||
try {
|
||||
flush();
|
||||
} catch (BackingStoreException e) {
|
||||
log.error("Unable to flush after removing " + key, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void removeNodeSpi() throws BackingStoreException {
|
||||
isRemoved = true;
|
||||
flush();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String[] keysSpi() throws BackingStoreException {
|
||||
return root.keySet().toArray(new String[root.keySet().size()]);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String[] childrenNamesSpi() throws BackingStoreException {
|
||||
return children.keySet().toArray(new String[children.keySet().size()]);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected FilePreferences childSpi(String name) {
|
||||
FilePreferences child = children.get(name);
|
||||
if (child == null || child.isRemoved()) {
|
||||
child = new FilePreferences(this, name);
|
||||
children.put(name, child);
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void syncSpi() throws BackingStoreException {
|
||||
if (isRemoved()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final File file = FilePreferencesFactory.getPreferencesFile();
|
||||
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (file) {
|
||||
Properties p = new Properties();
|
||||
try {
|
||||
p.load(new FileInputStream(file));
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
getPath(sb);
|
||||
String path = sb.toString();
|
||||
|
||||
final Enumeration<?> pnen = p.propertyNames();
|
||||
while (pnen.hasMoreElements()) {
|
||||
String propKey = (String) pnen.nextElement();
|
||||
if (propKey.startsWith(path)) {
|
||||
String subKey = propKey.substring(path.length());
|
||||
// Only load immediate descendants
|
||||
if (subKey.indexOf('/') == -1) {
|
||||
root.put(subKey, p.getProperty(propKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new BackingStoreException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void getPath(StringBuilder sb) {
|
||||
final FilePreferences parent = (FilePreferences) parent();
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
parent.getPath(sb);
|
||||
sb.append(name()).append('/');
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void flushSpi() throws BackingStoreException {
|
||||
final File file = FilePreferencesFactory.getPreferencesFile();
|
||||
|
||||
synchronized (file) {
|
||||
Properties p = new Properties();
|
||||
try {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
getPath(sb);
|
||||
String path = sb.toString();
|
||||
|
||||
if (file.exists()) {
|
||||
p.load(new FileInputStream(file));
|
||||
|
||||
List<String> toRemove = new ArrayList<String>();
|
||||
|
||||
// Make a list of all direct children of this node to be removed
|
||||
final Enumeration<?> pnen = p.propertyNames();
|
||||
while (pnen.hasMoreElements()) {
|
||||
String propKey = (String) pnen.nextElement();
|
||||
if (propKey.startsWith(path)) {
|
||||
String subKey = propKey.substring(path.length());
|
||||
// Only do immediate descendants
|
||||
if (subKey.indexOf('/') == -1) {
|
||||
toRemove.add(propKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove them now that the enumeration is done with
|
||||
for (String propKey : toRemove) {
|
||||
p.remove(propKey);
|
||||
}
|
||||
}
|
||||
|
||||
// If this node hasn't been removed, add back in any values
|
||||
if (!isRemoved) {
|
||||
for (String s : root.keySet()) {
|
||||
p.setProperty(path + s, root.get(s));
|
||||
}
|
||||
}
|
||||
|
||||
p.store(new FileOutputStream(file), "FilePreferences");
|
||||
} catch (IOException e) {
|
||||
throw new BackingStoreException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
// https://github.com/sonatype/nexus/blob/2f0e154ec565969b4fd8698883ab76a461210f4f/nexus/nexus-test-harness/nexus-it-helper-plugin/src/main/java/org/sonatype/nexus/rt/prefs/FilePreferencesFactory.java
|
||||
|
||||
package net.sourceforge.tuned.prefs;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.prefs.Preferences;
|
||||
import java.util.prefs.PreferencesFactory;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* PreferencesFactory implementation that stores the preferences in a user-defined file. To use it, set the system
|
||||
* property <tt>java.util.prefs.PreferencesFactory</tt> to <tt>net.sourceforge.tuned.pref.FilePreferencesFactory</tt>
|
||||
* <p/>
|
||||
* The file defaults to [user.home]/.fileprefs, but may be overridden with the system property
|
||||
* <tt>net.sourceforge.tuned.pref.FilePreferencesFactory.file</tt>. Modified by cstamas, switched to SLF4J logging, and
|
||||
* exposed preferences file property.
|
||||
*
|
||||
* @author David Croft (<a href="http://www.davidc.net">www.davidc.net</a>)
|
||||
* @version $Id: FilePreferencesFactory.java 282 2009-06-18 17:05:18Z david $
|
||||
*/
|
||||
public class FilePreferencesFactory implements PreferencesFactory {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(FilePreferencesFactory.class.getName());
|
||||
|
||||
Preferences rootPreferences;
|
||||
|
||||
public static final String SYSTEM_PROPERTY_FILE = "net.sourceforge.tuned.prefs.file";
|
||||
|
||||
|
||||
public Preferences systemRoot() {
|
||||
return userRoot();
|
||||
}
|
||||
|
||||
|
||||
public Preferences userRoot() {
|
||||
if (rootPreferences == null) {
|
||||
log.debug("Instantiating root preferences");
|
||||
|
||||
rootPreferences = new FilePreferences(null, "");
|
||||
}
|
||||
|
||||
return rootPreferences;
|
||||
}
|
||||
|
||||
|
||||
private static File preferencesFile;
|
||||
|
||||
|
||||
public static File getPreferencesFile() {
|
||||
if (preferencesFile == null) {
|
||||
String prefsFile = System.getProperty(SYSTEM_PROPERTY_FILE);
|
||||
|
||||
if (prefsFile == null || prefsFile.length() == 0) {
|
||||
prefsFile = System.getProperty("user.home") + File.separator + ".fileprefs";
|
||||
}
|
||||
|
||||
preferencesFile = new File(prefsFile).getAbsoluteFile();
|
||||
|
||||
log.info("Preferences file is {}", preferencesFile);
|
||||
}
|
||||
|
||||
return preferencesFile;
|
||||
}
|
||||
|
||||
|
||||
public static void setPreferencesFile(File file) {
|
||||
preferencesFile = file;
|
||||
}
|
||||
}
|
@ -13,6 +13,8 @@ if ($type == 'app')
|
||||
$file = 'FileBot_'.$version.'.app.tar.gz';
|
||||
if ($type == 'jar')
|
||||
$file = 'FileBot_'.$version.'.jar';
|
||||
if ($type == 'portable')
|
||||
$file = 'FileBot_'.$version.'-portable.zip';
|
||||
if ($type == 'src')
|
||||
$file = 'filebot-'.$version.'-src.zip';
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user