Revision: 5916
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=5916&view=rev
Author: manningr
Date: 2010-10-12 11:38:26 +0000 (Tue, 12 Oct 2010)
Log Message:
-----------
Moved I/O methods from FileUtils to IOUtilities and removed redundant FileUtils. Added fixer for classpath building function in squirrel-sql.sh. PreLaunchHelper now copies the splash screen image (splash.jpg) from squirrel-sql.jar into the icons folder. Added call to updateLauncherScript and copySplashScreenImage to the shutdown routine. For now this is needed due to a bug in the classpath building routine in squirrel-sql.sh.
Modified Paths:
--------------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/Application.java
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
trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/update/gui/installer/ArtifactInstallerImplIntegrationTest.java
trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperImplIntegrationTest.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/IOUtilities.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/IOUtilitiesImpl.java
Added Paths:
-----------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/ClasspathFunctionFixer.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperFactory.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperFactoryImpl.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/SplashScreenFixer.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/ScriptLineFixer.java
trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/util/net.sourceforge.squirrel_sql.fw.util.applicationContext.xml
Removed 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
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/Application.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/Application.java 2010-10-12 11:29:33 UTC (rev 5915)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/Application.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -66,6 +66,9 @@
import net.sourceforge.squirrel_sql.client.session.schemainfo.SchemaInfoCacheSerializer;
import net.sourceforge.squirrel_sql.client.update.autocheck.UpdateCheckTimer;
import net.sourceforge.squirrel_sql.client.update.autocheck.UpdateCheckTimerImpl;
+import net.sourceforge.squirrel_sql.client.update.gui.installer.PreLaunchHelper;
+import net.sourceforge.squirrel_sql.client.update.gui.installer.PreLaunchHelperFactory;
+import net.sourceforge.squirrel_sql.client.update.gui.installer.PreLaunchHelperFactoryImpl;
import net.sourceforge.squirrel_sql.client.util.ApplicationFiles;
import net.sourceforge.squirrel_sql.fw.datasetviewer.CellImportExportInfoSaver;
import net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DTProperties;
@@ -159,6 +162,8 @@
private UpdateCheckTimer updateCheckTimer = null;
+ private PreLaunchHelperFactory preLaunchHelperFactory = new PreLaunchHelperFactoryImpl();
+
/**
* Default ctor.
*/
@@ -223,6 +228,8 @@
closeOutputStreams();
SchemaInfoCacheSerializer.waitTillStoringIsDone();
+
+ updateLaunchScript();
String msg = s_stringMgr.getString("Application.shutdowncomplete", Calendar.getInstance().getTime());
s_log.info(msg);
@@ -385,6 +392,27 @@
return result;
}
+ /**
+ * Ideally, it would be unnecessary to update the launch script here. Unfortunately, in squirrel-sql.sh
+ * due to a bug in how the updater's CLASSPATH is being built, the update application uses the old
+ * application and library jars instead of the ones in the downloads section. So, the new code that
+ * fixes the launch scripts doesn't get executed until the second update. Once that code is out there,
+ * ( that is, the 3.2 version has been released for a while, and we are pretty sure there are no older
+ * 3.x installations that still need to be upgraded), then it would be safe to remove this code.
+ */
+ private void updateLaunchScript() {
+ try
+ {
+ PreLaunchHelper helper = preLaunchHelperFactory.createPreLaunchHelper();
+ helper.updateLaunchScript();
+ helper.copySplashImage();
+ }
+ catch (Exception e)
+ {
+ s_log.error("Unexpected exception while attempting to update the launch script: "+e.getMessage(), e);
+ }
+ }
+
public IPluginManager getPluginManager()
{
return _pluginManager;
@@ -1188,4 +1216,9 @@
public void setUpdateCheckTimer(UpdateCheckTimer timer) {
this.updateCheckTimer = timer;
}
+
+ public void setPreLaunchHelperFactory(PreLaunchHelperFactory preLaunchHelperFactory)
+ {
+ this.preLaunchHelperFactory = preLaunchHelperFactory;
+ }
}
Added: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/ClasspathFunctionFixer.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/ClasspathFunctionFixer.java (rev 0)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/ClasspathFunctionFixer.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -0,0 +1,80 @@
+package net.sourceforge.squirrel_sql.client.update.gui.installer;
+
+import net.sourceforge.squirrel_sql.fw.util.IOUtilities;
+import net.sourceforge.squirrel_sql.fw.util.ScriptLineFixer;
+
+/*
+ * 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
+ */
+
+public class ClasspathFunctionFixer implements ScriptLineFixer
+{
+
+ private boolean inFunctionDeclaration = false;
+
+ private boolean scriptWasAlreadyFixed = false;
+
+ private boolean sawOpenCurlyBrace = false;
+
+ @Override
+ public String fixLine(String line)
+ {
+ if (scriptWasAlreadyFixed) {
+ return line;
+ }
+
+ String osName = System.getProperty("os.name");
+ if (osName.toLowerCase().startsWith("windows")) {
+ return line;
+ }
+
+ if (line.contains("buildCPFromDir()")) {
+ inFunctionDeclaration = true;
+ return line;
+ }
+ if (inFunctionDeclaration) {
+
+ if (line.contains("{")) {
+ sawOpenCurlyBrace = true;
+ return line;
+ }
+
+ // Perhaps the line has already been added. If so, skip future checks.
+ if (line.contains("CP=\"\"")) {
+ scriptWasAlreadyFixed = true;
+ return line;
+ }
+
+ // At this point we are still in the function declaration, and the current line is neither the
+ // opening curly brace, nor the 'CP=""' line, so it must be the first actual line of the function.
+ // So, add in the
+
+ if (sawOpenCurlyBrace) {
+ inFunctionDeclaration = false;
+ scriptWasAlreadyFixed = true;
+ StringBuilder alteredLine = new StringBuilder();
+ alteredLine.append("\tCP=\"\"");
+ alteredLine.append(IOUtilities.NEW_LINE);
+ alteredLine.append(line);
+ return alteredLine.toString();
+ }
+ }
+ return line;
+ }
+
+}
Deleted: 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 2010-10-12 11:29:33 UTC (rev 5915)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/FileUtils.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -1,56 +0,0 @@
-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
Deleted: 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 2010-10-12 11:29:33 UTC (rev 5915)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/FileUtilsImpl.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -1,75 +0,0 @@
-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-12 11:29:33 UTC (rev 5915)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelper.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -46,5 +46,11 @@
* @throws IOException if an I/O error occurs
*/
public void updateLaunchScript() throws IOException;
+
+ /**
+ * Copies the splash image from
+ * @throws IOException
+ */
+ public void copySplashImage() throws IOException;
}
\ No newline at end of file
Added: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperFactory.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperFactory.java (rev 0)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperFactory.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -0,0 +1,27 @@
+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
+ */
+
+public interface PreLaunchHelperFactory
+{
+
+ public abstract PreLaunchHelper createPreLaunchHelper();
+
+}
\ No newline at end of file
Added: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperFactoryImpl.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperFactoryImpl.java (rev 0)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperFactoryImpl.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -0,0 +1,49 @@
+package net.sourceforge.squirrel_sql.client.update.gui.installer;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/*
+ * 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
+ */
+
+public class PreLaunchHelperFactoryImpl implements PreLaunchHelperFactory
+{
+
+ /**
+ * @see net.sourceforge.squirrel_sql.client.update.gui.installer.PreLaunchHelperFactory#createPreLaunchHelper()
+ */
+ public PreLaunchHelper createPreLaunchHelper() {
+ String[] appCtx = new String[] {
+ "classpath:net/sourceforge/squirrel_sql/fw/util/net.sourceforge.squirrel_sql.fw.util.applicationContext.xml",
+ "classpath:net/sourceforge/squirrel_sql/client/update/gui/installer/net.sourceforge.squirrel_sql.client.update.gui.installer.applicationContext.xml",
+ "classpath:net/sourceforge/squirrel_sql/client/update/gui/installer/event/net.sourceforge.squirrel_sql.client.update.gui.installer.event.applicationContext.xml",
+ "classpath:net/sourceforge/squirrel_sql/client/update/gui/installer/util/net.sourceforge.squirrel_sql.client.update.gui.installer.util.applicationContext.xml",
+ "classpath:net/sourceforge/squirrel_sql/client/update/util/net.sourceforge.squirrel_sql.client.update.util.applicationContext.xml"
+ };
+
+// System.out.println("Loading beans from the following application context files: ");
+// for (String location : appCtx) {
+// System.out.println("appCtx: "+location);
+// }
+
+ ApplicationContext ctx = new ClassPathXmlApplicationContext(appCtx);
+ return (PreLaunchHelper)ctx.getBean(PreLaunchHelper.class.getName());
+ }
+
+}
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-12 11:29:33 UTC (rev 5915)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperImpl.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -24,20 +24,22 @@
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;
import net.sourceforge.squirrel_sql.client.update.gui.installer.event.InstallStatusListenerImpl;
import net.sourceforge.squirrel_sql.client.update.xmlbeans.ChangeListXmlBean;
import net.sourceforge.squirrel_sql.fw.util.FileWrapper;
+import net.sourceforge.squirrel_sql.fw.util.IOUtilities;
+import net.sourceforge.squirrel_sql.fw.util.ScriptLineFixer;
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;
+import org.springframework.beans.factory.annotation.Required;
+
/**
* This is a bean that the prelaunch app uses. The pre-launch app main class (PreLaunchUpdateApplication)
* loads the spring context, and therefore can't managed by spring. So, it is very small and most of it's
@@ -108,12 +110,16 @@
}
/* Spring-injected */
- FileUtils fileUtils = null;
+ private IOUtilities ioutils = null;
+ /**
+ * @param ioutils the ioutils to set
+ */
@Required
- public void setFileUtils(FileUtils fileUtils) {
- Utilities.checkNull("setFileUtils", "fileUtils", fileUtils);
- this.fileUtils = fileUtils;
+ public void setIoutils(IOUtilities ioutils)
+ {
+ Utilities.checkNull("setIoutils", "ioutils", ioutils);
+ this.ioutils = ioutils;
}
/* ----------------------------------- Public API ------------------------------------------------------*/
@@ -153,6 +159,7 @@
/**
* @see net.sourceforge.squirrel_sql.client.update.gui.installer.PreLaunchHelper#installUpdates(boolean)
*/
+ @Override
public void installUpdates(boolean prompt)
{
FileWrapper changeListFile = updateUtil.getChangeListFile();
@@ -182,6 +189,7 @@
*
* @throws IOException if an I/O error occurs
*/
+ @Override
public void updateLaunchScript() throws IOException {
// 1. determine which script to fix.
@@ -198,15 +206,26 @@
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);
+ List<String> lines = ioutils.getLinesFromFile(scriptFilename, scriptLineFixers);
// 3. Write the fixed lines back out to the file.
- fileUtils.writeLinesToFile(scriptFilename, lines);
+ ioutils.writeLinesToFile(scriptFilename, lines);
}
+ @Override
+ public void copySplashImage() throws IOException
+ {
+ String jarFilename = "update/downloads/core/squirrel-sql.jar";
+ String resourceName = "splash.jpg";
+ String destinationFile = "icons/splash.jpg";
+
+ ioutils.copyResourceFromJarFile(jarFilename, resourceName, destinationFile);
+ }
+
/**
* @see net.sourceforge.squirrel_sql.client.update.gui.installer.PreLaunchHelper#restoreFromBackup()
*/
+ @Override
public void restoreFromBackup()
{
if (showConfirmDialog(RESTORE_FROM_BACKUP_MESSAGE, RESTORE_FROM_BACKUP_TITLE))
@@ -388,4 +407,5 @@
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-12 11:29:33 UTC (rev 5915)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchUpdateApplication.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -30,8 +30,6 @@
import org.apache.log4j.Layout;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.PropertyConfigurator;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* This is a small application that will be launched each time SQuirreL is started to quickly check to see if
@@ -45,7 +43,7 @@
public static final String PROMPT_MODE = "prompt";
- public static final String RESTORE_MODE = "restore";
+ public static final String RESTORE_MODE = "restore";
/**
* Entry point of the
@@ -57,10 +55,11 @@
initializeLogger();
boolean prompt = getMode(PROMPT_MODE);
boolean restore = getMode(RESTORE_MODE);
- setupSpringContext();
+ setupHelper();
if (!restore) {
helper.installUpdates(prompt);
helper.updateLaunchScript();
+ helper.copySplashImage();
} else {
helper.restoreFromBackup();
}
@@ -68,13 +67,10 @@
// Helper methods
- private static void setupSpringContext()
+ private static void setupHelper()
{
- String[] appCtx = new String[] {
- "classpath:net/sourceforge/squirrel_sql/**/*applicationContext.xml"
- };
- ApplicationContext ctx = new ClassPathXmlApplicationContext(appCtx);
- helper = (PreLaunchHelper)ctx.getBean(PreLaunchHelper.class.getName());
+ PreLaunchHelperFactory preLaunchHelperFactory = new PreLaunchHelperFactoryImpl();
+ helper = preLaunchHelperFactory.createPreLaunchHelper();
}
private static boolean getMode(String mode)
Deleted: 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 2010-10-12 11:29:33 UTC (rev 5915)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/ScriptLineFixer.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -1,36 +0,0 @@
-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);
-}
Deleted: 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 2010-10-12 11:29:33 UTC (rev 5915)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/SplashScreenFixer.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -1,69 +0,0 @@
-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;
- }
-
-
-}
Copied: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/SplashScreenFixer.java (from rev 5913, 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-12 11:38:26 UTC (rev 5916)
@@ -0,0 +1,72 @@
+package net.sourceforge.squirrel_sql.client.update.gui.installer;
+
+import net.sourceforge.squirrel_sql.fw.util.ScriptLineFixer;
+
+
+/*
+ * 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.fw.util.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-12 11:29:33 UTC (rev 5915)
+++ 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-12 11:38:26 UTC (rev 5916)
@@ -14,8 +14,8 @@
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 id="net.sourceforge.squirrel_sql.client.update.gui.installer.ClasspathFunctionFixer"
+ class="net.sourceforge.squirrel_sql.client.update.gui.installer.ClasspathFunctionFixer">
</bean>
<bean id="net.sourceforge.squirrel_sql.client.update.gui.installer.PreLaunchHelper"
@@ -26,10 +26,11 @@
<property name="scriptLineFixers">
<list>
<ref bean="net.sourceforge.squirrel_sql.client.update.gui.installer.SplashScreenFixer"/>
+ <ref bean="net.sourceforge.squirrel_sql.client.update.gui.installer.ClasspathFunctionFixer"/>
</list>
</property>
- <property name="fileUtils"
- ref="net.sourceforge.squirrel_sql.client.update.gui.installer.FileUtils" />
+ <property name="ioutils"
+ ref="net.sourceforge.squirrel_sql.fw.util.IOUtilities" />
</bean>
@@ -48,4 +49,5 @@
<property name="updateUtil"
ref="net.sourceforge.squirrel_sql.client.update.UpdateUtil"/>
</bean>
+
</beans>
\ No newline at end of file
Modified: trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/update/gui/installer/ArtifactInstallerImplIntegrationTest.java
===================================================================
--- trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/update/gui/installer/ArtifactInstallerImplIntegrationTest.java 2010-10-12 11:29:33 UTC (rev 5915)
+++ trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/update/gui/installer/ArtifactInstallerImplIntegrationTest.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -31,6 +31,7 @@
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({})
@ContextConfiguration (locations={
+ "/net/sourceforge/squirrel_sql/fw/util/net.sourceforge.squirrel_sql.fw.util.applicationContext.xml",
"/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",
Modified: 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 2010-10-12 11:29:33 UTC (rev 5915)
+++ trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/update/gui/installer/PreLaunchHelperImplIntegrationTest.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -27,9 +27,7 @@
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;
@@ -43,6 +41,7 @@
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners( {})
@ContextConfiguration(locations = {
+ "/net/sourceforge/squirrel_sql/fw/util/net.sourceforge.squirrel_sql.fw.util.applicationContext.xml",
"/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",
@@ -54,33 +53,19 @@
{
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();
+ @Autowired
+ private IOUtilities ioutils;
- public void setFileWrapperFactory(FileWrapperFactory factory)
- {
- _fileWrapperFactory = factory;
- }
-
+ @Autowired
+ private FileWrapperFactory _fileWrapperFactory;
/**
* This test confirms that the launch script can be updated to include the new Splash screen icon
@@ -94,7 +79,7 @@
FileWrapper sourceScriptFile = _fileWrapperFactory.create(SOURCE_SCRIPT_FILE_TO_TEST);
FileWrapper targetScriptFile = _fileWrapperFactory.create(TARGET_SCRIPT_FILE_TO_TEST);
- _iou.copyFile(sourceScriptFile, targetScriptFile);
+ ioutils.copyFile(sourceScriptFile, targetScriptFile);
// Confirm that the script doesn't contain the splash screen icon setting.
checkScriptFile(false);
@@ -109,7 +94,7 @@
private void checkScriptFile(boolean containsSplashIconArgument) throws IOException
{
- List<String> linesFromScriptFile = fileUtils.getLinesFromFile(TARGET_SCRIPT_FILE_TO_TEST, null);
+ List<String> linesFromScriptFile = ioutils.getLinesFromFile(TARGET_SCRIPT_FILE_TO_TEST, null);
boolean foundMainClassLine = false;
for (String line : linesFromScriptFile)
{
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/IOUtilities.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/IOUtilities.java 2010-10-12 11:29:33 UTC (rev 5915)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/IOUtilities.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -19,6 +19,7 @@
package net.sourceforge.squirrel_sql.fw.util;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -26,10 +27,14 @@
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.List;
+import java.util.zip.ZipException;
public interface IOUtilities
{
+ public static String NEW_LINE = System.getProperty("line.separator");
+
String HTTP_PROTOCOL_PREFIX = "http";
void closeInputStream(InputStream is);
@@ -105,16 +110,58 @@
/**
* Downloads a file using HTTP.
*
- * @param url the URL of the file to be retrieved
- * @param destFile the file to download the URL file into
- * @param proxySettings the ProxySettings to use
+ * @param url
+ * the URL of the file to be retrieved
+ * @param destFile
+ * the file to download the URL file into
+ * @param proxySettings
+ * the ProxySettings to use
* @return the number of bytes that were read and written to the file.
* @throws Exception
*/
- public int downloadHttpFile(final URL url, FileWrapper destFile, IProxySettings proxySettings)
- throws IOException;
+ int downloadHttpFile(final URL url, FileWrapper destFile, IProxySettings proxySettings) throws IOException;
- public URL constructHttpUrl(final String host, final int port, final String fileToGet)
+ URL constructHttpUrl(final String host, final int port, final String fileToGet)
throws MalformedURLException;
+ /**
+ * 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;
+
+ /**
+ * Copies the resource specified from the jarfile specified to the specified destination directory.
+ *
+ * @param jarFilename
+ * the jarfile to look in.
+ * @param resourceName
+ * the resource to pull out.
+ * @param destinationDir
+ * the directory to write the resource to.
+ * @throws IOException
+ * @throws ZipException
+ */
+ void copyResourceFromJarFile(String jarFilename, String resourceName, String destinationDir)
+ throws ZipException, IOException;
+
}
\ No newline at end of file
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/IOUtilitiesImpl.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/IOUtilitiesImpl.java 2010-10-12 11:29:33 UTC (rev 5915)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/IOUtilitiesImpl.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -20,18 +20,27 @@
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
import java.util.zip.CRC32;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
@@ -48,10 +57,23 @@
/** The size of the byte array which is used to fetch data from disk to do various I/O operations */
public static final int DISK_DATA_BUFFER_SIZE = 8192;
+
/** Logger for this class. */
private final ILogger s_log = LoggerController.createLogger(IOUtilitiesImpl.class);
+ /* Spring-Injected */
+
+ private FileWrapperFactory fileWrapperFactory;
/**
+ * @param fileWrapperFactory the fileWrapperFactory to set
+ */
+ public void setFileWrapperFactory(FileWrapperFactory fileWrapperFactory)
+ {
+ this.fileWrapperFactory = fileWrapperFactory;
+ }
+
+
+ /**
* @see net.sourceforge.squirrel_sql.fw.util.IOUtilities#closeInputStream(java.io.InputStream)
*/
public void closeInputStream(InputStream is)
@@ -257,7 +279,8 @@
* @see net.sourceforge.squirrel_sql.fw.util.IOUtilities# downloadHttpFile(java.lang.String, int,
* java.lang.String, net.sourceforge.squirrel_sql.fw.util.FileWrapper)
*/
- public int downloadHttpFile(URL url, FileWrapper destFile, IProxySettings proxySettings) throws IOException
+ public int downloadHttpFile(URL url, FileWrapper destFile, IProxySettings proxySettings)
+ throws IOException
{
BufferedInputStream is = null;
HttpMethod method = null;
@@ -281,11 +304,8 @@
s_log.debug("downloadHttpFile: response code was: " + resultCode);
}
- if (resultCode != 200)
- {
- throw new FileNotFoundException(
- "Failed to download file from url (" + url + "): HTTP Response Code=" + resultCode);
- }
+ if (resultCode != 200) { throw new FileNotFoundException("Failed to download file from url (" + url
+ + "): HTTP Response Code=" + resultCode); }
InputStream mis = method.getResponseBodyAsStream();
is = new BufferedInputStream(mis);
@@ -312,22 +332,24 @@
return result;
}
- /**
- * Setup proxy configuration specified in proxySettings. This setup is skipped if:
- * 1) proxySettings is null.
- * 2) proxySettings.getHttpUseProxy() is false (HttpClient doesn't support SOCKS proxy)
- * 3) The url's host component is in the "non-proxy" host list
- *
- * @param proxySettings the ProxySettings to use
- * @param client the instance of HttpClient to configure
- * @param url the URL of the file to be retrieved
- */
+ /**
+ * Setup proxy configuration specified in proxySettings. This setup is skipped if: 1) proxySettings is
+ * null. 2) proxySettings.getHttpUseProxy() is false (HttpClient doesn't support SOCKS proxy) 3) The url's
+ * host component is in the "non-proxy" host list
+ *
+ * @param proxySettings
+ * the ProxySettings to use
+ * @param client
+ * the instance of HttpClient to configure
+ * @param url
+ * the URL of the file to be retrieved
+ */
private void setupProxy(IProxySettings proxySettings, HttpClient client, URL url)
{
if (proxySettings == null) { return; }
if (!proxySettings.getHttpUseProxy()) { return; }
- if (proxySettings.getHttpNonProxyHosts() != null
- && proxySettings.getHttpNonProxyHosts().contains(url.getHost())) { return; }
+ if (proxySettings.getHttpNonProxyHosts() != null
+ && proxySettings.getHttpNonProxyHosts().contains(url.getHost())) { return; }
String proxyHost = proxySettings.getHttpProxyServer();
int proxyPort = Integer.parseInt(proxySettings.getHttpProxyPort());
@@ -342,4 +364,77 @@
}
}
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.util.IOUtilities#getLinesFromFile(java.lang.String, java.util.List)
+ */
+ @Override
+ 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.fw.util.IOUtilities#writeLinesToFile(java.lang.String, java.util.List)
+ */
+ @Override
+ 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(NEW_LINE);
+ }
+ out.close();
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.util.IOUtilities# copyResourceFromJarFile(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public void copyResourceFromJarFile(String jarFilename, String resourceName, String destinationFile)
+ throws ZipException, IOException
+ {
+ ZipFile appJar = new ZipFile(new File(jarFilename));
+ Enumeration<? extends ZipEntry> entries = appJar.entries();
+ while (entries.hasMoreElements())
+ {
+ ZipEntry entry = entries.nextElement();
+ String entryName = entry.getName();
+ if (entryName.endsWith(resourceName))
+ {
+ InputStream is = null;
+ try {
+ FileWrapper destinationFileWrapper = fileWrapperFactory.create(destinationFile);
+ is = appJar.getInputStream(entry);
+ copyBytesToFile(is, destinationFileWrapper);
+ } finally {
+ closeInputStream(is);
+ }
+ break;
+ }
+ }
+
+ }
+
+
+
}
Copied: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/ScriptLineFixer.java (from rev 5913, trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/update/gui/installer/ScriptLineFixer.java)
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/ScriptLineFixer.java (rev 0)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/ScriptLineFixer.java 2010-10-12 11:38:26 UTC (rev 5916)
@@ -0,0 +1,36 @@
+package net.sourceforge.squirrel_sql.fw.util;
+
+/*
+ * 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/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/util/net.sourceforge.squirrel_sql.fw.util.applicationContext.xml
===================================================================
--- trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/util/net.sourceforge.squirrel_sql.fw.util.applicationContext.xml (rev 0)
+++ trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/util/net.sourceforge.squirrel_sql.fw.util.applicationContext.xml 2010-10-12 11:38:26 UTC (rev 5916)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
+
+
+ <bean id="net.sourceforge.squirrel_sql.fw.util.FileWrapperFactory"
+ class="net.sourceforge.squirrel_sql.fw.util.FileWrapperFactoryImpl"/>
+
+ <bean id="net.sourceforge.squirrel_sql.fw.util.IOUtilities"
+ class="net.sourceforge.squirrel_sql.fw.util.IOUtilitiesImpl">
+ <property name="fileWrapperFactory" ref="net.sourceforge.squirrel_sql.fw.util.FileWrapperFactory" />
+ </bean>
+
+</beans>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|