Revision: 5913
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=5913&view=rev
Author: manningr
Date: 2010-10-11 15:10:24 +0000 (Mon, 11 Oct 2010)
Log Message:
-----------
Added ability for the pre-launch application to fix the application launch line so that it contains the splash screen icon setting.
Modified Paths:
--------------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelper.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperImpl.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchUpdateApplication.java
trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/update/gui/installer/net.sourceforge.squirrel_sql.client.update.gui.installer.applicationContext.xml
Added Paths:
-----------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/FileUtils.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/FileUtilsImpl.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/ScriptLineFixer.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/SplashScreenFixer.java
trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperImplIntegrationTest.java
trunk/sql12/app/src/test/resources/
trunk/sql12/app/src/test/resources/squirrel-sql.sh
Added: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/FileUtils.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/FileUtils.java (rev 0)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/FileUtils.java 2010-10-11 15:10:24 UTC (rev 5913)
@@ -0,0 +1,56 @@
+package net.sourceforge.squirrel_sql.client.update.gui.installer;
+
+/*
+ * Copyright (C) 2010 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Interface for file utility methods.
+ */
+public interface FileUtils
+{
+
+ /**
+ * Reads the file specified by filename and builds a list of lines, applying the line fixers specified.
+ *
+ * @param filename
+ * the name of the file to read lines from.
+ * @param lineFixers
+ * a list of fixers to apply to each line. This can be null if no line manipulation is required.
+ * @return a list of lines
+ * @throws IOException
+ * if an I/O error occurs.
+ */
+ List<String> getLinesFromFile(String filename, List<ScriptLineFixer> lineFixers)
+ throws IOException;
+
+ /**
+ * Writes the specified list of line to the specified filename. This will overrite the current contents
+ * of the file.
+ *
+ * @param filename the file to overwrite
+ * @param lines the lines to write to the file.
+ * @throws FileNotFoundException
+ */
+ void writeLinesToFile(String filename, List<String> lines) throws FileNotFoundException;
+
+}
\ No newline at end of file
Added: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/FileUtilsImpl.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/FileUtilsImpl.java (rev 0)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/FileUtilsImpl.java 2010-10-11 15:10:24 UTC (rev 5913)
@@ -0,0 +1,75 @@
+package net.sourceforge.squirrel_sql.client.update.gui.installer;
+
+/*
+ * Copyright (C) 2010 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+public class FileUtilsImpl implements FileUtils
+{
+
+ public static String newline = System.getProperty("line.separator");
+
+ /**
+ * @see net.sourceforge.squirrel_sql.client.update.gui.installer.FileUtils#
+ * getLinesFromFile(java.lang.String, java.util.List)
+ */
+ public List<String> getLinesFromFile(String filename, List<ScriptLineFixer> lineFixers) throws IOException
+ {
+ ArrayList<String> lines = new ArrayList<String>();
+
+ BufferedReader reader = new BufferedReader(new FileReader(filename));
+ String line = null;
+
+ while ((line = reader.readLine()) != null)
+ {
+ if (lineFixers != null) {
+ for (ScriptLineFixer fixer : lineFixers)
+ {
+ line = fixer.fixLine(line);
+ }
+ }
+ lines.add(line);
+ }
+ reader.close();
+ return lines;
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.client.update.gui.installer.FileUtils#
+ * writeLinesToFile(java.lang.String, java.util.List)
+ */
+ public void writeLinesToFile(String filename, List<String> lines) throws FileNotFoundException
+ {
+ PrintWriter out = new PrintWriter(new File(filename));
+ for (String outline : lines)
+ {
+ out.write(outline);
+ out.write(newline);
+ }
+ out.close();
+ }
+}
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelper.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelper.java 2010-10-11 15:07:21 UTC (rev 5912)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelper.java 2010-10-11 15:10:24 UTC (rev 5913)
@@ -18,6 +18,8 @@
*/
package net.sourceforge.squirrel_sql.client.update.gui.installer;
+import java.io.IOException;
+
/**
* Interface for the class that does the heavy lifting with regard to checking for and installing any updates
* prior to launching the application.
@@ -38,4 +40,11 @@
*/
void restoreFromBackup();
+ /**
+ * Updates the launch script with changes made necessary by the new release.
+ *
+ * @throws IOException if an I/O error occurs
+ */
+ public void updateLaunchScript() throws IOException;
+
}
\ No newline at end of file
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperImpl.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperImpl.java 2010-10-11 15:07:21 UTC (rev 5912)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperImpl.java 2010-10-11 15:10:24 UTC (rev 5913)
@@ -24,6 +24,8 @@
import javax.swing.JOptionPane;
+import org.springframework.beans.factory.annotation.Required;
+
import net.sourceforge.squirrel_sql.client.update.UpdateUtil;
import net.sourceforge.squirrel_sql.client.update.gui.ArtifactStatus;
import net.sourceforge.squirrel_sql.client.update.gui.installer.event.InstallStatusListener;
@@ -32,6 +34,7 @@
import net.sourceforge.squirrel_sql.fw.util.FileWrapper;
import net.sourceforge.squirrel_sql.fw.util.StringManager;
import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+import net.sourceforge.squirrel_sql.fw.util.Utilities;
import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
@@ -69,24 +72,49 @@
/** Logger for this class. */
private ILogger s_log;
-
+
+ /** Used to override logic for calculating script location for testing purposes */
+ private String scriptLocation = null;
+
/* --------------------------- Spring=injected dependencies --------------------------------------------*/
/* Spring-injected */
private UpdateUtil updateUtil = null;
+ @Required
public void setUpdateUtil(UpdateUtil util)
{
+ Utilities.checkNull("setUpdateUtil", "util", util);
this.updateUtil = util;
}
/* Spring-injected */
private ArtifactInstallerFactory artifactInstallerFactory = null;
+ @Required
public void setArtifactInstallerFactory(ArtifactInstallerFactory artifactInstallerFactory)
{
+ Utilities.checkNull("setArtifactInstallerFactory", "artifactInstallerFactory", artifactInstallerFactory);
this.artifactInstallerFactory = artifactInstallerFactory;
}
+
+ /* Spring-injected */
+ private List<ScriptLineFixer> scriptLineFixers = null;
+
+ @Required
+ public void setScriptLineFixers(List<ScriptLineFixer> scriptLineFixers) {
+ Utilities.checkNull("setScriptLineFixers", "scriptLineFixers", scriptLineFixers);
+ this.scriptLineFixers = scriptLineFixers;
+ }
+
+ /* Spring-injected */
+ FileUtils fileUtils = null;
+
+ @Required
+ public void setFileUtils(FileUtils fileUtils) {
+ Utilities.checkNull("setFileUtils", "fileUtils", fileUtils);
+ this.fileUtils = fileUtils;
+ }
/* ----------------------------------- Public API ------------------------------------------------------*/
@@ -150,6 +178,67 @@
}
/**
+ * Updates the launch script with changes made necessary by the new release.
+ *
+ * @throws IOException if an I/O error occurs
+ */
+ public void updateLaunchScript() throws IOException {
+
+ // 1. determine which script to fix.
+ String os = System.getProperty("os.name");
+
+ String scriptFilename = "squirrel-sql.sh";
+ if (scriptLocation != null) {
+ scriptFilename = scriptLocation;
+ } else {
+ if (os != null && os.toLowerCase().startsWith("windows")) {
+ scriptFilename = "squirrel-sql.bat";
+ }
+ }
+ logInfo("Applying updates to launch script: "+scriptFilename);
+
+ // 2. Get the lines from the file, applying the line fixers
+ List<String> lines = fileUtils.getLinesFromFile(scriptFilename, scriptLineFixers);
+
+ // 3. Write the fixed lines back out to the file.
+ fileUtils.writeLinesToFile(scriptFilename, lines);
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.client.update.gui.installer.PreLaunchHelper#restoreFromBackup()
+ */
+ public void restoreFromBackup()
+ {
+ if (showConfirmDialog(RESTORE_FROM_BACKUP_MESSAGE, RESTORE_FROM_BACKUP_TITLE))
+ {
+
+ try
+ {
+ FileWrapper backupDir = updateUtil.getBackupDir();
+ FileWrapper changeListFile = updateUtil.getFile(backupDir, UpdateUtil.CHANGE_LIST_FILENAME);
+ ChangeListXmlBean changeList = updateUtil.getChangeList(changeListFile);
+
+ ArtifactInstaller installer = artifactInstallerFactory.create(changeList, null);
+ if (!installer.restoreBackupFiles())
+ {
+ showErrorDialog(RESTORE_FAILED_MESSAGE);
+ s_log.error("restoreFromBackup: " + RESTORE_FAILED_MESSAGE);
+ }
+
+ }
+ catch (Throwable e)
+ {
+ s_log.error("Unexpected error while attempting restore from backup: " + e.getMessage(), e);
+ showErrorDialog(RESTORE_FAILED_MESSAGE);
+ }
+
+ }
+ shutdown("Pre-launch update app finished");
+ }
+
+ /* ------------------------------------- Helper methods ------------------------------------------------*/
+
+ /**
* Peeks into the changelist file to see if there are artifacts to change. This is precautionary as the GUI
* should prevent the changeList file from being created if there are no artifacts to be changed.
*
@@ -192,42 +281,8 @@
return result;
}
-
+
/**
- * @see net.sourceforge.squirrel_sql.client.update.gui.installer.PreLaunchHelper#restoreFromBackup()
- */
- public void restoreFromBackup()
- {
- if (showConfirmDialog(RESTORE_FROM_BACKUP_MESSAGE, RESTORE_FROM_BACKUP_TITLE))
- {
-
- try
- {
- FileWrapper backupDir = updateUtil.getBackupDir();
- FileWrapper changeListFile = updateUtil.getFile(backupDir, UpdateUtil.CHANGE_LIST_FILENAME);
- ChangeListXmlBean changeList = updateUtil.getChangeList(changeListFile);
-
- ArtifactInstaller installer = artifactInstallerFactory.create(changeList, null);
- if (!installer.restoreBackupFiles())
- {
- showErrorDialog(RESTORE_FAILED_MESSAGE);
- s_log.error("restoreFromBackup: " + RESTORE_FAILED_MESSAGE);
- }
-
- }
- catch (Throwable e)
- {
- s_log.error("Unexpected error while attempting restore from backup: " + e.getMessage(), e);
- showErrorDialog(RESTORE_FAILED_MESSAGE);
- }
-
- }
- shutdown("Pre-launch update app finished");
- }
-
- /* ------------------------------------- Helper methods ------------------------------------------------*/
-
- /**
* Shuts down this small pre-launch helper application.
*/
private void shutdown(String message)
@@ -317,4 +372,20 @@
}
}
+ /**
+ * @param scriptLocation the scriptLocation to set
+ */
+ public void setScriptLocation(String scriptLocation)
+ {
+ this.scriptLocation = scriptLocation;
+ }
+
+ /**
+ * @return the scriptLocation
+ */
+ public String getScriptLocation()
+ {
+ return scriptLocation;
+ }
+
}
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchUpdateApplication.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchUpdateApplication.java 2010-10-11 15:07:21 UTC (rev 5912)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchUpdateApplication.java 2010-10-11 15:10:24 UTC (rev 5913)
@@ -60,6 +60,7 @@
setupSpringContext();
if (!restore) {
helper.installUpdates(prompt);
+ helper.updateLaunchScript();
} else {
helper.restoreFromBackup();
}
Added: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/ScriptLineFixer.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/ScriptLineFixer.java (rev 0)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/ScriptLineFixer.java 2010-10-11 15:10:24 UTC (rev 5913)
@@ -0,0 +1,36 @@
+package net.sourceforge.squirrel_sql.client.update.gui.installer;
+
+/*
+ * Copyright (C) 2010 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/**
+ * Interface for line fixer implementations.
+ */
+public interface ScriptLineFixer
+{
+
+ /**
+ * Fixes the line specified, returning the "fixed" version
+ *
+ * @param line
+ * the line that needs to be fixed
+ * @return the fixed line
+ */
+ String fixLine(String line);
+}
Added: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/SplashScreenFixer.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/SplashScreenFixer.java (rev 0)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/SplashScreenFixer.java 2010-10-11 15:10:24 UTC (rev 5913)
@@ -0,0 +1,69 @@
+package net.sourceforge.squirrel_sql.client.update.gui.installer;
+
+/*
+ * Copyright (C) 2010 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+/**
+ * A line fixer implementation that adds the splash screen icon to the line that launches the SQuirreL
+ * application in the launcher scripts.
+ */
+public class SplashScreenFixer implements ScriptLineFixer {
+
+ /** The main class. Assumption is that this line is where the splash setting needs to be added */
+ public static final String CLIENT_MAIN_CLASS = "net.sourceforge.squirrel_sql.client.Main";
+
+ /** The splash setting */
+ public static final String SPLASH_ICON_ARGUMENT = "-splash:icons/splash.jpg";
+
+ /** A regex pattern version of the main class */
+ private static final String MAIN_CLASS_PATTERN = "net\\.sourceforge\\.squirrel_sql\\.client\\.Main";
+
+ /** The platform-dependent newline string */
+ public static String newline = System.getProperty("line.separator");
+
+ /**
+ * @see net.sourceforge.squirrel_sql.client.update.gui.installer.ScriptLineFixer#fixLine(java.lang.String)
+ */
+ @Override
+ public String fixLine(String line) {
+ String result = line;
+ if (line.contains(CLIENT_MAIN_CLASS)) {
+ if (!line.contains(SPLASH_ICON_ARGUMENT)) {
+ String[] parts = line.split(MAIN_CLASS_PATTERN);
+ if (parts.length == 2) {
+ StringBuilder newline = new StringBuilder();
+ newline.append(parts[0]);
+ newline.append(" ");
+ newline.append(SPLASH_ICON_ARGUMENT);
+ newline.append(" ");
+ newline.append(CLIENT_MAIN_CLASS);
+ newline.append(" ");
+ newline.append(parts[1]);
+ result = newline.toString();
+ } else {
+ System.err.println("Uh-oh, expected parts to be 2");
+ }
+ }
+ }
+ return result;
+ }
+
+
+}
Modified: trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/update/gui/installer/net.sourceforge.squirrel_sql.client.update.gui.installer.applicationContext.xml
===================================================================
--- trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/update/gui/installer/net.sourceforge.squirrel_sql.client.update.gui.installer.applicationContext.xml 2010-10-11 15:07:21 UTC (rev 5912)
+++ trunk/sql12/app/src/main/resources/net/sourceforge/squirrel_sql/client/update/gui/installer/net.sourceforge.squirrel_sql.client.update.gui.installer.applicationContext.xml 2010-10-11 15:10:24 UTC (rev 5913)
@@ -10,11 +10,27 @@
class="net.sourceforge.squirrel_sql.client.update.UpdateUtilImpl">
</bean>
+ <bean id="net.sourceforge.squirrel_sql.client.update.gui.installer.SplashScreenFixer"
+ class="net.sourceforge.squirrel_sql.client.update.gui.installer.SplashScreenFixer">
+ </bean>
+
+ <bean id="net.sourceforge.squirrel_sql.client.update.gui.installer.FileUtils"
+ class="net.sourceforge.squirrel_sql.client.update.gui.installer.FileUtilsImpl">
+ </bean>
+
<bean id="net.sourceforge.squirrel_sql.client.update.gui.installer.PreLaunchHelper"
class="net.sourceforge.squirrel_sql.client.update.gui.installer.PreLaunchHelperImpl">
<property name="updateUtil" ref="net.sourceforge.squirrel_sql.client.update.UpdateUtil"/>
<property name="artifactInstallerFactory"
ref="net.sourceforge.squirrel_sql.client.update.gui.installer.ArtifactInstallerFactory" />
+ <property name="scriptLineFixers">
+ <list>
+ <ref bean="net.sourceforge.squirrel_sql.client.update.gui.installer.SplashScreenFixer"/>
+ </list>
+ </property>
+ <property name="fileUtils"
+ ref="net.sourceforge.squirrel_sql.client.update.gui.installer.FileUtils" />
+
</bean>
<bean id="net.sourceforge.squirrel_sql.client.update.gui.installer.ArtifactInstallerFactory"
Added: trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperImplIntegrationTest.java
===================================================================
--- trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperImplIntegrationTest.java (rev 0)
+++ trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperImplIntegrationTest.java 2010-10-11 15:10:24 UTC (rev 5913)
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2007 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.squirrel_sql.client.update.gui.installer;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.List;
+
+import net.sourceforge.squirrel_sql.client.ApplicationArguments;
+import net.sourceforge.squirrel_sql.fw.util.FileWrapper;
+import net.sourceforge.squirrel_sql.fw.util.FileWrapperFactory;
+import net.sourceforge.squirrel_sql.fw.util.FileWrapperFactoryImpl;
+import net.sourceforge.squirrel_sql.fw.util.IOUtilities;
+import net.sourceforge.squirrel_sql.fw.util.IOUtilitiesImpl;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.TestExecutionListeners;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@TestExecutionListeners( {})
+@ContextConfiguration(locations = {
+ "/net/sourceforge/squirrel_sql/client/update/gui/installer/net.sourceforge.squirrel_sql.client.update.gui.installer.applicationContext.xml",
+ "/net/sourceforge/squirrel_sql/client/update/gui/installer/event/net.sourceforge.squirrel_sql.client.update.gui.installer.event.applicationContext.xml",
+ "/net/sourceforge/squirrel_sql/client/update/gui/installer/util/net.sourceforge.squirrel_sql.client.update.gui.installer.util.applicationContext.xml",
+ "/net/sourceforge/squirrel_sql/client/update/util/net.sourceforge.squirrel_sql.client.update.util.applicationContext.xml" })
+public class PreLaunchHelperImplIntegrationTest extends AbstractJUnit4SpringContextTests
+{
+
+ static
+ {
+ ApplicationArguments.initialize(new String[] { "-home", "./target" });
+ }
+
+ @Autowired
+ private FileUtils fileUtils;
+
+ public static final String beanIdToTest =
+ "net.sourceforge.squirrel_sql.client.update.gui.installer.PreLaunchHelper";
+
+ private static final String SOURCE_SCRIPT_FILE_TO_TEST = "src/test/resources/squirrel-sql.sh";
+
+ private static final String TARGET_SCRIPT_FILE_TO_TEST = "target/squirrel-sql-copy.sh";
+
+ /** TODO: Spring-inject when this class is a Spring bean */
+ private IOUtilities _iou = new IOUtilitiesImpl();
+
+ public void setIOUtilities(IOUtilities iou)
+ {
+ _iou = iou;
+ }
+
+ /** TODO: Spring-inject when this class is a Spring bean */
+ private FileWrapperFactory _fileWrapperFactory = new FileWrapperFactoryImpl();
+
+ public void setFileWrapperFactory(FileWrapperFactory factory)
+ {
+ _fileWrapperFactory = factory;
+ }
+
+
+ /**
+ * This test confirms that the launch script can be updated to include the new Splash screen icon
+ * configuration.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testUpdateLaunchScript() throws IOException
+ {
+
+ FileWrapper sourceScriptFile = _fileWrapperFactory.create(SOURCE_SCRIPT_FILE_TO_TEST);
+ FileWrapper targetScriptFile = _fileWrapperFactory.create(TARGET_SCRIPT_FILE_TO_TEST);
+ _iou.copyFile(sourceScriptFile, targetScriptFile);
+
+ // Confirm that the script doesn't contain the splash screen icon setting.
+ checkScriptFile(false);
+
+ PreLaunchHelperImpl beanToTest = (PreLaunchHelperImpl) applicationContext.getBean(beanIdToTest);
+ beanToTest.setScriptLocation(TARGET_SCRIPT_FILE_TO_TEST);
+ beanToTest.updateLaunchScript();
+
+ // Confirm that the script now contain the splash screen icon setting.
+ checkScriptFile(true);
+ }
+
+ private void checkScriptFile(boolean containsSplashIconArgument) throws IOException
+ {
+ List<String> linesFromScriptFile = fileUtils.getLinesFromFile(TARGET_SCRIPT_FILE_TO_TEST, null);
+ boolean foundMainClassLine = false;
+ for (String line : linesFromScriptFile)
+ {
+ if (line.contains(SplashScreenFixer.CLIENT_MAIN_CLASS))
+ {
+ foundMainClassLine = true;
+ if (!containsSplashIconArgument) {
+ assertFalse(line.contains(SplashScreenFixer.SPLASH_ICON_ARGUMENT));
+ } else {
+ assertTrue(line.contains(SplashScreenFixer.SPLASH_ICON_ARGUMENT));
+ }
+ }
+ }
+ Assert.assertTrue(foundMainClassLine);
+ }
+}
Added: trunk/sql12/app/src/test/resources/squirrel-sql.sh
===================================================================
--- trunk/sql12/app/src/test/resources/squirrel-sql.sh (rev 0)
+++ trunk/sql12/app/src/test/resources/squirrel-sql.sh 2010-10-11 15:10:24 UTC (rev 5913)
@@ -0,0 +1,123 @@
+#! /bin/sh
+
+# This function sets a global variable named "CP" to a command-path separated list of jars located beneath the
+# specified folder. If the specified folder contains a lib directory, then jars beneath the lib folder are
+# @ added as well as the squirrel-sql.jar file located in the directory specified as the first argument to
+# this function.
+buildCPFromDir()
+{
+ if [ -d "$1"/lib ]; then
+ # First entry in classpath is the Squirrel application.
+ CP="$1/squirrel-sql.jar"
+
+ # Then add all library jars to the classpath.
+ for a in "$1"/lib/*; do
+ CP="$CP":"$a"
+ done
+ else
+ for a in "$1"/*; do
+ CP="$CP":"$a"
+ done
+ fi
+}
+
+# IZPACK_JAVA_HOME is filtered in by the IzPack installer when this script is installed
+IZPACK_JAVA_HOME=/opt/jdk1.6.0_14_x64/jre
+
+# We detect the java executable to use according to the following algorithm:
+#
+# 1. If it is located in JAVA_HOME, then we use that; or
+# 2. If the one used by the IzPack installer is available then use that, otherwise
+# 3. Use the java that is in the command path.
+#
+if [ -d "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then
+ JAVACMD="$JAVA_HOME/bin/java"
+elif [ -d "$IZPACK_JAVA_HOME" -a -x "$IZPACK_JAVA_HOME/bin/java" ]; then
+ JAVACMD="$IZPACK_JAVA_HOME/bin/java"
+else
+ JAVACMD=java
+fi
+
+# Are we running within Cygwin on some version of Windows or on Mac OS X?
+cygwin=false;
+macosx=false;
+case "`uname -s`" in
+ CYGWIN*)
+ cygwin=true
+ ;;
+ Darwin*)
+ macosx=true
+ ;;
+esac
+
+# SQuirreL home.
+if $macosx ; then
+ SQUIRREL_SQL_HOME='/tmp/squirrel-sql-Snapshot-20100918_1720/Contents/Resources/Java'
+else
+ SQUIRREL_SQL_HOME='/tmp/squirrel-sql-Snapshot-20100918_1720'
+fi
+
+# SQuirreL home in Unix format.
+if $cygwin ; then
+ UNIX_STYLE_HOME=`cygpath "$SQUIRREL_SQL_HOME"`
+else
+ UNIX_STYLE_HOME="$SQUIRREL_SQL_HOME"
+fi
+
+cd "$UNIX_STYLE_HOME"
+
+# Check to see if the JVM meets the minimum required to run SQuirreL and inform the user if not and skip
+# launch. versioncheck.jar is a special jar file which has been compiled with javac version 1.2.2, which
+# should be able to be run by that version or higher. The arguments to JavaVersionChecker below specify the
+# minimum acceptable version (first arg) and any other acceptable subsequent versions. <MAJOR>.<MINOR> should
+# be all that is necessary for the version form.
+$JAVACMD -cp "$UNIX_STYLE_HOME/lib/versioncheck.jar" JavaVersionChecker 1.6 1.7
+if [ "$?" = "1" ]; then
+ exit
+fi
+
+# Build a command-path separated list of installed jars from the lib folder and squirrel-sql.jar
+buildCPFromDir "$UNIX_STYLE_HOME"
+TMP_CP=$CP
+
+# Set the update app's classpath to use jars in download area first, then the installed jars
+buildCPFromDir "$UNIX_STYLE_HOME/update/downloads/core"
+UPDATE_CP=$CP:$TMP_CP
+
+# Now add the system classpath to the classpath. If running
+# Cygwin we also need to change the classpath to Windows format.
+if $cygwin ; then
+ TMP_CP=`cygpath -w -p $TMP_CP`
+ UPDATE_CP=`cygpath -w -p $UPDATE_CP`
+ TMP_CP=$TMP_CP';'$CLASSPATH
+ UPDATE_CP=$UPDATE_CP';'$CLASSPATH
+else
+ TMP_CP=$TMP_CP:$CLASSPATH
+ UPDATE_CP=$UPDATE_CP:$CLASSPATH
+fi
+
+if $macosx ; then
+ # Define mac-specific system properties if running on Mac OS X
+ MACOSX_UPDATER_PROPS="-Dapple.laf.useScreenMenuBar=true -Dcom.apple.mrj.application.apple.menu.about.name=SQuirreLSQLUpdater"
+ MACOSX_SQUIRREL_PROPS="-Dapple.laf.useScreenMenuBar=true -Dcom.apple.mrj.application.apple.menu.about.name=SQuirreLSQL"
+ NATIVE_LAF_PROP="--native-laf"
+fi
+
+# Check for updates and prompt to apply if any are available
+if [ -f "$UNIX_STYLE_HOME/update/downloads/core/squirrel-sql.jar" -a -f "$UNIX_STYLE_HOME/update/changeList.xml" ]; then
+ $JAVACMD -cp "$UPDATE_CP" $MACOSX_UPDATER_PROPS -Dlog4j.defaultInitOverride=true -Dprompt=true net.sourceforge.squirrel_sql.client.update.gui.installer.PreLaunchUpdateApplication -l "$UNIX_STYLE_HOME/update-log4j.properties"
+fi
+
+if $macosx ; then
+ # macosx provides unknown args to the script, causing SQuirreL to bail..
+ SCRIPT_ARGS=""
+else
+ SCRIPT_ARGS="$1 $2 $3 $4 $5 $6 $7 $8 $9"
+fi
+
+# Now, pickup all jars once again from the installation and lib directories in case any new jars were
+# downloaded during the update process. The variable "CP" is assigned this value.
+buildCPFromDir "$UNIX_STYLE_HOME"
+
+# Launch SQuirreL application
+$JAVACMD -Xmx256m -cp "$CP" $MACOSX_SQUIRREL_PROPS net.sourceforge.squirrel_sql.client.Main --log-config-file "$UNIX_STYLE_HOME"/log4j.properties --squirrel-home "$UNIX_STYLE_HOME" $NATIVE_LAF_PROP $SCRIPT_ARGS
Property changes on: trunk/sql12/app/src/test/resources/squirrel-sql.sh
___________________________________________________________________
Added: svn:executable
+ *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|