Package net.sourceforge.squirrel_sql.fw.util

Examples of net.sourceforge.squirrel_sql.fw.util.FileWrapper


   * @see net.sourceforge.squirrel_sql.client.update.gui.installer.PreLaunchHelper#installUpdates(boolean)
   */
  @Override
  public void installUpdates(boolean prompt)
  {
    FileWrapper changeListFile = updateUtil.getChangeListFile();
    if (hasChangesToBeApplied(changeListFile))
    {
      logInfo("Pre-launch update app detected a changeListFile to be processed");
      if (prompt)
      {
View Full Code Here


    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())
        {
View Full Code Here

  public boolean backupFiles() throws FileNotFoundException, IOException
  {
    boolean result = true;
    sendBackupStarted(_changeList.size());

    FileWrapper localReleaseFile = _util.getLocalReleaseFile();
    _util.copyFile(localReleaseFile, _util.getBackupDir());

    for (ArtifactStatus status : _changeList)
    {
      String artifactName = status.getName();
      sendFileBackupStarted(artifactName);
      // Skip files that are not installed - new files
      if (!status.isInstalled())
      {
        if (s_log.isInfoEnabled())
        {
          s_log.info("Skipping backup of artifact (" + status + ") which isn't installed.");
        }
        sendFileBackupComplete(artifactName);
        continue;
      }
      if (status.isCoreArtifact())
      {
        FileWrapper installDir = getCoreArtifactLocation(artifactName, installRootDir, coreInstallDir);
        FileWrapper coreFile = _util.getFile(installDir, artifactName);
        FileWrapper backupFile = _util.getFile(coreBackupDir, artifactName);
        _util.copyFile(coreFile, backupFile);
      }
      if (status.isPluginArtifact())
      {
        // artifact name for plugins is <plugin internal name>.zip
        FileWrapper pluginBackupFile = _util.getFile(pluginBackupDir, artifactName);
        String pluginDirectory = artifactName.replace(".zip", "");
        String pluginJarFilename = artifactName.replace(".zip", ".jar");

        ArrayList<FileWrapper> filesToZip = new ArrayList<FileWrapper>();
        FileWrapper pluginDirectoryFile = _util.getFile(pluginInstallDir, pluginDirectory);
        if (pluginDirectoryFile.exists())
        {
          filesToZip.add(pluginDirectoryFile);
        }
        FileWrapper pluginJarFile = _util.getFile(pluginInstallDir, pluginJarFilename);
        if (pluginJarFile.exists())
        {
          filesToZip.add(pluginJarFile);
        }
        if (filesToZip.size() > 0)
        {
          _util.createZipFile(pluginBackupFile, filesToZip.toArray(new FileWrapper[filesToZip.size()]));
        }
        else
        {
          s_log.error("Plugin (" + status.getName() + ") was listed as already installed, but it's "
            + "files didn't exist and couldn't be backed up: pluginDirectoryFile="
            + pluginDirectoryFile.getAbsolutePath() + " pluginJarFile="
            + pluginJarFile.getAbsolutePath());
        }
      }
      if (status.isTranslationArtifact())
      {
        FileWrapper translationFile = _util.getFile(i18nInstallDir, artifactName);
        FileWrapper backupFile = _util.getFile(translationBackupDir, artifactName);
        if (translationFile.exists())
        {
          _util.copyFile(translationFile, backupFile);
        }
      }
View Full Code Here

    List<InstallFileOperationInfo> filesToInstall = new ArrayList<InstallFileOperationInfo>();

    for (ArtifactStatus status : _changeList)
    {
      ArtifactAction action = status.getArtifactAction();
      FileWrapper installDir = null;
      FileWrapper fileToCopy = null;
      FileWrapper fileToRemove = null;
      String artifactName = status.getName();
      boolean isPlugin = false;

      if (status.isCoreArtifact())
      {
View Full Code Here

  public boolean restoreBackupFiles() throws FileNotFoundException, IOException
  {
    for (ArtifactStatus status : _changeList)
    {
      String name = status.getName();
      FileWrapper backupDir = null;
      FileWrapper installDir = null;

      if (status.isCoreArtifact())
      {
        backupDir = coreBackupDir;
        installDir = getCoreArtifactLocation(name, installRootDir, coreInstallDir);
      }
      if (status.isPluginArtifact())
      {
        backupDir = pluginBackupDir;
        installDir = pluginInstallDir;
      }
      if (status.isTranslationArtifact())
      {
        backupDir = translationBackupDir;
        installDir = coreInstallDir; // translations are most likely to be found in core lib dir.
      }
      FileWrapper backupJarPath = _util.getFile(backupDir, name);
      FileWrapper installJarPath = _util.getFile(installDir, name);

      if (!_util.deleteFile(installJarPath))
      {
        return false;
      }
      else
      {
        _util.copyFile(backupJarPath, installJarPath);
      }
    }
    if (!_util.deleteFile(_util.getLocalReleaseFile()))
    {
      return false;
    }
    else
    {
      FileWrapper backupReleaseFile = _util.getFile(_util.getBackupDir(), UpdateUtil.RELEASE_XML_FILENAME);
      _util.copyFile(backupReleaseFile, updateDir);
    }

    return true;
  }
View Full Code Here

        continue;
      }

      if (status.getArtifactAction() == ArtifactAction.INSTALL)
      {
        FileWrapper installedFileLocation = null;
        // Skip the artifact if it is identical to the one that is already installed
        if (status.isCoreArtifact())
        {
          installedFileLocation =
            _util.getFile(getCoreArtifactLocation(status.getName(), installRootDir, coreInstallDir),
              status.getName());
        }
        if (status.isTranslationArtifact())
        {
          installedFileLocation = _util.getFile(coreInstallDir, status.getName());
        }

        long installedSize = installedFileLocation.length();
        if (installedSize == status.getSize())
        {
          long installedCheckSum = _util.getCheckSum(installedFileLocation);
          if (installedCheckSum == status.getChecksum())
          {
View Full Code Here

      if (s_log.isInfoEnabled())
      {
        s_log.info("installNewReleaseXmlFile: release file to be replaced was missing.");
      }
    }
    FileWrapper downloadReleaseFile = _util.getFile(downloadsRootDir, UpdateUtil.RELEASE_XML_FILENAME);
    try
    {
      _util.copyFile(downloadReleaseFile, updateDir);
    }
    catch (FileNotFoundException e)
View Full Code Here

    return result;
  }

  private void installFile(InstallFileOperationInfo info) throws IOException
  {
    FileWrapper installDir = info.getInstallDir();
    FileWrapper fileToCopy = info.getFileToInstall();

    if (fileToCopy.getAbsolutePath().endsWith(".zip"))
    {
      // This file is a zip; it needs to be extracted into the install directory. All zips are packaged
      // in such a way that the extraction beneath install directory is all that is required.
      _util.extractZipFile(fileToCopy, installDir);
    }
View Full Code Here

     expect(mockArtifactStatus.getName()).andReturn(coreJarFilename);
//     FileWrapper mockDownloadsDirectory = mockHelper.createMock("mockDownloadsDirectory", FileWrapper.class);
//     expect(mockDownloadsDirectory.isDirectory()).andStubReturn(true);
//     expect(mockFileWrapperFactory.create(mockUpdateDirectory, UpdateUtil.DOWNLOADS_DIR_NAME));
//     expectLastCall().andReturn(mockDownloadsDirectory);
     FileWrapper mockDownloadsCoreDirectory = mockHelper.createMock("mockDownloadsCoreDirectory", FileWrapper.class);
     expect(mockDownloadsCoreDirectory.isDirectory()).andReturn(true);
     expect(mockFileWrapperFactory.create(mockDownloadsDirectory, UpdateUtil.CORE_ARTIFACT_ID));
     expectLastCall().andReturn(mockDownloadsCoreDirectory);
     FileWrapper mockSomeCoreJarFile = mockHelper.createMock("mockSomeCoreJarFile", FileWrapper.class);
     expect(mockFileWrapperFactory.create(mockDownloadsCoreDirectory, coreJarFilename));
     expectLastCall().andReturn(mockSomeCoreJarFile);
    
     mockHelper.replayAll();
     FileWrapper result = underTest.getDownloadFileLocation(mockArtifactStatus);
     mockHelper.verifyAll();
    
     assertEquals(mockSomeCoreJarFile, result);
   }
View Full Code Here

   }
  
   @Test
   public void testGetCheckSum() throws IOException {
    
     FileWrapper mockFile = mockHelper.createMock("mockFile", FileWrapper.class);
     expect(mockFile.getAbsolutePath()).andReturn("/path/To/Mock/File");
     expect(mockIOUtilities.getCheckSum(mockFile)).andReturn(1000L);
     mockHelper.replayAll();
     long checksumResult = underTest.getCheckSum(mockFile);
     mockHelper.verifyAll();
    
View Full Code Here

TOP

Related Classes of net.sourceforge.squirrel_sql.fw.util.FileWrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.