[jsword-svn]
jsword/java/jsword/org/crosswire/jsword/book/install/sword s
jswordcvs at crosswire.org
jswordcvs at crosswire.org
Sat Oct 2 07:01:44 MST 2004
Update of /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/install/sword
In directory www.crosswire.org:/tmp/cvs-serv15209/java/jsword/org/crosswire/jsword/book/install/sword
Modified Files:
HttpSwordInstaller.java FtpSwordInstaller.java
Log Message:
Installer improvements
BD-15
Index: HttpSwordInstaller.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/install/sword/HttpSwordInstaller.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** HttpSwordInstaller.java 29 Sep 2004 22:15:07 -0000 1.8
--- HttpSwordInstaller.java 2 Oct 2004 14:01:42 -0000 1.9
***************
*** 111,115 ****
/**
! * Utility to download a file by FTP from a remote site
* @param site The place to download from
* @param dir The directory from which to download the file
--- 111,115 ----
/**
! * Utility to download a file by HTTP from a remote site
* @param site The place to download from
* @param dir The directory from which to download the file
***************
*** 278,292 ****
job.setProgress(Msg.JOB_INIT.toString());
! ModuleType type = sbmd.getModuleType();
! String modpath = type.getInstallDirectory();
! String destname = modpath + '/' + sbmd.getInternalName();
!
! File dldir = SwordBookDriver.getDownloadDir();
! File moddir = new File(dldir, SwordConstants.DIR_DATA);
! File fulldir = new File(moddir, destname);
! fulldir.mkdirs();
! URL desturl = new URL(NetUtil.PROTOCOL_FILE, null, fulldir.getAbsolutePath());
downloadZip(job, host, directory + '/' + PACKAGE_DIR + '/' + sbmd.getInitials() + ZIP_SUFFIX, desturl);
job.setProgress(Msg.JOB_CONFIG.toString());
File confdir = new File(dldir, SwordConstants.DIR_CONF);
--- 278,286 ----
job.setProgress(Msg.JOB_INIT.toString());
! URL desturl = toLocalURL(sbmd);
! NetUtil.makeDirectory(desturl);
downloadZip(job, host, directory + '/' + PACKAGE_DIR + '/' + sbmd.getInitials() + ZIP_SUFFIX, desturl);
+ File dldir = SwordBookDriver.getDownloadDir();
job.setProgress(Msg.JOB_CONFIG.toString());
File confdir = new File(dldir, SwordConstants.DIR_CONF);
***************
*** 318,322 ****
* @see org.crosswire.jsword.book.install.Installer#toURL(org.crosswire.jsword.book.BookMetaData)
*/
! public URL toURL(BookMetaData bmd)
{
if (!(bmd instanceof SwordBookMetaData))
--- 312,316 ----
* @see org.crosswire.jsword.book.install.Installer#toURL(org.crosswire.jsword.book.BookMetaData)
*/
! public URL toRemoteURL(BookMetaData bmd)
{
if (!(bmd instanceof SwordBookMetaData))
***************
*** 330,334 ****
try
{
! return new URL("http://" + host + directory + '/' + PACKAGE_DIR + '/' + sbmd.getInitials() + ZIP_SUFFIX); //$NON-NLS-1$
}
catch (MalformedURLException e)
--- 324,328 ----
try
{
! return new URL(NetUtil.PROTOCOL_HTTP, host, directory + '/' + PACKAGE_DIR + '/' + sbmd.getInitials() + ZIP_SUFFIX); //$NON-NLS-1$
}
catch (MalformedURLException e)
***************
*** 339,342 ****
--- 333,387 ----
/* (non-Javadoc)
+ * @see org.crosswire.jsword.book.install.Installer#toLocalURL(org.crosswire.jsword.book.BookMetaData)
+ */
+ public URL toLocalURL(BookMetaData bmd)
+ {
+ File fulldir = toLocalDirectory(bmd);
+ try
+ {
+ return new URL(NetUtil.PROTOCOL_FILE, null, fulldir.getAbsolutePath());
+ }
+ catch (MalformedURLException e)
+ {
+ assert false;
+ return null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.crosswire.jsword.book.install.Installer#isNewer(org.crosswire.jsword.book.BookMetaData)
+ */
+ public boolean isNewer(BookMetaData bmd)
+ {
+ URL local = toLocalURL(bmd);
+ SwordBookMetaData sbmd = (SwordBookMetaData) bmd;
+ local = NetUtil.lengthenURL(local, sbmd.getInternalName() + SwordConstants.EXTENSION_CONF);
+ URL remote = toRemoteURL(bmd);
+ return NetUtil.isNewer(remote, local);
+ }
+
+ /* (non-Javadoc)
+ * @see org.crosswire.jsword.book.install.Installer#toLocalURL(org.crosswire.jsword.book.BookMetaData)
+ */
+ public File toLocalDirectory(BookMetaData bmd)
+ {
+ if (!(bmd instanceof SwordBookMetaData))
+ {
+ assert false;
+ return null;
+ }
+
+ SwordBookMetaData sbmd = (SwordBookMetaData) bmd;
+
+ ModuleType type = sbmd.getModuleType();
+ String modpath = type.getInstallDirectory();
+ String destname = modpath + '/' + sbmd.getInternalName();
+
+ File dldir = SwordBookDriver.getDownloadDir();
+ File moddir = new File(dldir, SwordConstants.DIR_DATA);
+ return new File(moddir, destname);
+ }
+
+ /* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
***************
*** 447,510 ****
if (!NetUtil.isFile(cache))
{
! log.info("Missing cache file: " + cache.toExternalForm()); //$NON-NLS-1$
}
! else
{
! try
{
! InputStream in = cache.openStream();
! GZIPInputStream gin = new GZIPInputStream(in);
! TarInputStream tin = new TarInputStream(gin);
! while (true)
{
! TarEntry entry = tin.getNextEntry();
! if (entry == null)
{
! break;
! }
! String internal = entry.getName();
! if (!entry.isDirectory())
! {
! try
{
! int size = (int) entry.getSize();
! byte[] buffer = new byte[size];
! tin.read(buffer);
!
! if (internal.endsWith(SwordConstants.EXTENSION_CONF))
! {
! internal = internal.substring(0, internal.length() - 5);
! }
! if (internal.startsWith(SwordConstants.DIR_CONF + '/'))
! {
! internal = internal.substring(7);
! }
! Reader rin = new InputStreamReader(new ByteArrayInputStream(buffer));
! SwordBookMetaData sbmd = new SwordBookMetaData(rin, internal);
! if (sbmd.isSupported())
! {
! entries.put(sbmd.getName(), sbmd);
! }
! }
! catch (Exception ex)
{
! log.warn("Failed to load config for entry: " + internal, ex); //$NON-NLS-1$
}
}
}
-
- tin.close();
- gin.close();
- in.close();
- loaded = true;
- }
- catch (IOException ex)
- {
- throw new InstallException(Msg.CACHE_ERROR, ex);
}
}
}
--- 492,552 ----
if (!NetUtil.isFile(cache))
{
! reloadIndex();
}
! try
{
! InputStream in = cache.openStream();
! GZIPInputStream gin = new GZIPInputStream(in);
! TarInputStream tin = new TarInputStream(gin);
!
! while (true)
{
! TarEntry entry = tin.getNextEntry();
! if (entry == null)
! {
! break;
! }
! String internal = entry.getName();
! if (!entry.isDirectory())
{
! try
{
! int size = (int) entry.getSize();
! byte[] buffer = new byte[size];
! tin.read(buffer);
! if (internal.endsWith(SwordConstants.EXTENSION_CONF))
{
! internal = internal.substring(0, internal.length() - 5);
! }
! if (internal.startsWith(SwordConstants.DIR_CONF + '/'))
! {
! internal = internal.substring(7);
! }
! Reader rin = new InputStreamReader(new ByteArrayInputStream(buffer));
! SwordBookMetaData sbmd = new SwordBookMetaData(rin, internal);
! if (sbmd.isSupported())
{
! entries.put(sbmd.getName(), sbmd);
}
}
+ catch (Exception ex)
+ {
+ log.warn("Failed to load config for entry: " + internal, ex); //$NON-NLS-1$
+ }
}
}
+
+ tin.close();
+ gin.close();
+ in.close();
+ loaded = true;
+ }
+ catch (IOException ex)
+ {
+ throw new InstallException(Msg.CACHE_ERROR, ex);
}
}
Index: FtpSwordInstaller.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/install/sword/FtpSwordInstaller.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** FtpSwordInstaller.java 29 Sep 2004 22:15:07 -0000 1.5
--- FtpSwordInstaller.java 2 Oct 2004 14:01:42 -0000 1.6
***************
*** 92,96 ****
* @see org.crosswire.jsword.book.install.Installer#toURL(org.crosswire.jsword.book.BookMetaData)
*/
! public URL toURL(BookMetaData bmd)
{
if (!(bmd instanceof SwordBookMetaData))
--- 92,96 ----
* @see org.crosswire.jsword.book.install.Installer#toURL(org.crosswire.jsword.book.BookMetaData)
*/
! public URL toRemoteURL(BookMetaData bmd)
{
if (!(bmd instanceof SwordBookMetaData))
***************
*** 104,108 ****
try
{
! return new URL(NetUtil.PROTOCOL_FTP + "://" + host + directory + "/" + sbmd.getInitials() + ZIP_SUFFIX); //$NON-NLS-1$ //$NON-NLS-2$
}
catch (MalformedURLException ex)
--- 104,108 ----
try
{
! return new URL(NetUtil.PROTOCOL_FTP, host, directory + "/" + sbmd.getInitials() + ZIP_SUFFIX); //$NON-NLS-1$ //$NON-NLS-2$
}
catch (MalformedURLException ex)
***************
*** 113,116 ****
--- 113,157 ----
/* (non-Javadoc)
+ * @see org.crosswire.jsword.book.install.Installer#toLocalURL(org.crosswire.jsword.book.BookMetaData)
+ */
+ public URL toLocalURL(BookMetaData bmd)
+ {
+ if (!(bmd instanceof SwordBookMetaData))
+ {
+ assert false;
+ return null;
+ }
+
+ SwordBookMetaData sbmd = (SwordBookMetaData) bmd;
+
+ ModuleType type = sbmd.getModuleType();
+ String modpath = type.getInstallDirectory();
+ String destname = modpath + '/' + sbmd.getInternalName();
+
+ File dldir = SwordBookDriver.getDownloadDir();
+ File moddir = new File(dldir, SwordConstants.DIR_DATA);
+ File fulldir = new File(moddir, destname);
+ try
+ {
+ return new URL(NetUtil.PROTOCOL_FILE, null, fulldir.getAbsolutePath());
+ }
+ catch (MalformedURLException e)
+ {
+ assert false;
+ return null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.crosswire.jsword.book.install.Installer#isNewer(org.crosswire.jsword.book.BookMetaData)
+ */
+ public boolean isNewer(BookMetaData bmd)
+ {
+ URL local = toLocalURL(bmd);
+ URL remote = toRemoteURL(bmd);
+ return NetUtil.isNewer(remote, local);
+ }
+
+ /* (non-Javadoc)
* @see org.crosswire.jsword.book.install.Installer#install(java.lang.String)
*/
***************
*** 147,162 ****
job.setProgress(Msg.JOB_INIT.toString());
ModuleType type = sbmd.getModuleType();
String modpath = type.getInstallDirectory();
String destname = modpath + '/' + sbmd.getInternalName();
-
- File dldir = SwordBookDriver.getDownloadDir();
- File moddir = new File(dldir, SwordConstants.DIR_DATA);
- File fulldir = new File(moddir, destname);
- fulldir.mkdirs();
- URL desturl = new URL(NetUtil.PROTOCOL_FILE, null, fulldir.getAbsolutePath());
-
downloadAll(job, host, USERNAME, PASSWORD, directory + '/' + SwordConstants.DIR_DATA + '/' + destname, desturl);
job.setProgress(Msg.JOB_CONFIG.toString());
File confdir = new File(dldir, SwordConstants.DIR_CONF);
--- 188,200 ----
job.setProgress(Msg.JOB_INIT.toString());
+ URL desturl = toLocalURL(sbmd);
+ NetUtil.makeDirectory(desturl);
+
ModuleType type = sbmd.getModuleType();
String modpath = type.getInstallDirectory();
String destname = modpath + '/' + sbmd.getInternalName();
downloadAll(job, host, USERNAME, PASSWORD, directory + '/' + SwordConstants.DIR_DATA + '/' + destname, desturl);
+ File dldir = SwordBookDriver.getDownloadDir();
job.setProgress(Msg.JOB_CONFIG.toString());
File confdir = new File(dldir, SwordConstants.DIR_CONF);
***************
*** 205,268 ****
if (!NetUtil.isFile(cache))
{
! log.info("Missing cache file: " + cache.toExternalForm()); //$NON-NLS-1$
}
! else
{
! try
{
! InputStream in = cache.openStream();
! GZIPInputStream gin = new GZIPInputStream(in);
! TarInputStream tin = new TarInputStream(gin);
! while (true)
{
! TarEntry entry = tin.getNextEntry();
! if (entry == null)
{
! break;
! }
! String internal = entry.getName();
! if (!entry.isDirectory())
! {
! try
{
! int size = (int) entry.getSize();
! byte[] buffer = new byte[size];
! tin.read(buffer);
!
! if (internal.endsWith(SwordConstants.EXTENSION_CONF))
! {
! internal = internal.substring(0, internal.length() - 5);
! }
! if (internal.startsWith(SwordConstants.DIR_CONF + '/'))
! {
! internal = internal.substring(7);
! }
! Reader rin = new InputStreamReader(new ByteArrayInputStream(buffer));
! SwordBookMetaData sbmd = new SwordBookMetaData(rin, internal);
! if (sbmd.isSupported())
! {
! entries.put(sbmd.getName(), sbmd);
! }
! }
! catch (Exception ex)
{
! log.warn("Failed to load config for entry: " + internal, ex); //$NON-NLS-1$
}
}
}
-
- tin.close();
- gin.close();
- in.close();
- loaded = true;
- }
- catch (IOException ex)
- {
- throw new InstallException(Msg.CACHE_ERROR, ex);
}
}
}
--- 243,303 ----
if (!NetUtil.isFile(cache))
{
! reloadIndex();
}
! try
{
! InputStream in = cache.openStream();
! GZIPInputStream gin = new GZIPInputStream(in);
! TarInputStream tin = new TarInputStream(gin);
!
! while (true)
{
! TarEntry entry = tin.getNextEntry();
! if (entry == null)
! {
! break;
! }
! String internal = entry.getName();
! if (!entry.isDirectory())
{
! try
{
! int size = (int) entry.getSize();
! byte[] buffer = new byte[size];
! tin.read(buffer);
! if (internal.endsWith(SwordConstants.EXTENSION_CONF))
{
! internal = internal.substring(0, internal.length() - 5);
! }
! if (internal.startsWith(SwordConstants.DIR_CONF + '/'))
! {
! internal = internal.substring(7);
! }
! Reader rin = new InputStreamReader(new ByteArrayInputStream(buffer));
! SwordBookMetaData sbmd = new SwordBookMetaData(rin, internal);
! if (sbmd.isSupported())
{
! entries.put(sbmd.getName(), sbmd);
}
}
+ catch (Exception ex)
+ {
+ log.warn("Failed to load config for entry: " + internal, ex); //$NON-NLS-1$
+ }
}
}
+
+ tin.close();
+ gin.close();
+ in.close();
+ loaded = true;
+ }
+ catch (IOException ex)
+ {
+ throw new InstallException(Msg.CACHE_ERROR, ex);
}
}
More information about the jsword-svn
mailing list