Esempio n. 1
0
  @Override
  @Port(name = "files", method = "delete")
  public boolean delete(String relativePath) {
    File f1 = new File(baseFolder.getAbsolutePath() + relativePath);

    if (f1.exists() && f1.delete()) {
      removeFileToRepository(f1);
      return true;
    }
    return false;
  }
Esempio n. 2
0
  @Override
  @Port(name = "files", method = "mkdirs")
  public boolean mkdirs(String relativePath) {
    File f1 = new File(baseFolder.getAbsolutePath() + relativePath);

    addFileToRepository(f1);
    commitRepository(
        " folders " + f1.getPath() + " created ", " name ", " email "); // TODO fix name and email

    return !f1.exists() && f1.mkdirs();
  }
Esempio n. 3
0
  @Override
  @Port(name = "files", method = "move")
  public boolean move(String oldRelativePath, String newRelativePath) {

    File oldFile = new File(baseFolder.getAbsolutePath() + File.separator + oldRelativePath);
    File newFile = new File(baseFolder.getAbsolutePath() + File.separator + newRelativePath);

    if (oldFile.renameTo(newFile)) {
      addFileToRepository(newFile);
      removeFileToRepository(oldFile);
      return true;
    } else {
      logger.debug("Unable to move file {} on {}", oldRelativePath, newRelativePath);
      return false;
    }
  }
Esempio n. 4
0
 public boolean addFileToRepository(File fileToAdd) {
   Boolean result = false;
   try {
     String finalFilePath =
         fileToAdd
             .getPath()
             .substring(
                 fileToAdd.getPath().indexOf(baseFolder.getPath())
                     + baseFolder.getPath().length()
                     + 1);
     git.add().addFilepattern(finalFilePath).call();
     result = true;
   } catch (NoFilepatternException e) {
     logger.debug("Unable to add file on repository ", e);
   } catch (GitAPIException e) {
     logger.debug("Unable to add file on repository ", e);
   }
   return result;
 }
Esempio n. 5
0
 public boolean removeFileToRepository(File fileToRemove) {
   Boolean result = false;
   try {
     String finalFilePath =
         fileToRemove
             .getPath()
             .substring(
                 fileToRemove.getPath().indexOf(baseFolder.getPath())
                     + baseFolder.getPath().length()
                     + 1);
     logger.debug(" file f " + fileToRemove.getPath() + " string " + finalFilePath);
     git.rm().addFilepattern(finalFilePath).call();
     commitRepository(
         " File " + finalFilePath + " removed ", " name ", " email "); // TODO fix name and email
     result = true;
   } catch (NoFilepatternException e) {
     logger.debug("Cannot remove file to repository " + e);
   } catch (GitAPIException e) {
     logger.debug("Unable to remove file on repository ", e);
   }
   return result;
 }
Esempio n. 6
0
 public void process(File file, FolderItem item) {
   if (!file.getName().contains(".git") && !file.getName().endsWith("~")) {
     if (file.isFile()) {
       FileItem itemToAdd = new FileItem();
       itemToAdd.setName(file.getName());
       itemToAdd.setParent(item);
       itemToAdd.setPath(getRelativePath(file.getPath()));
       item.add(itemToAdd);
     } else if (file.isDirectory()) {
       FolderItem folder = new FolderItem();
       folder.setName(file.getName());
       folder.setParent(item);
       folder.setPath(getRelativePath(file.getPath() + "/"));
       item.add(folder);
       File[] listOfFiles = file.listFiles();
       if (listOfFiles != null) {
         for (File listOfFile : listOfFiles) process(listOfFile, folder);
       }
     }
   }
 }
Esempio n. 7
0
  @Override
  @Port(name = "files", method = "saveFile")
  public boolean saveFile(String relativePath, byte[] data) {
    boolean result = true; // super.saveFile(relativePath, data);
    File f = new File(baseFolder.getAbsolutePath() + relativePath);
    if (f.exists()) {
      result = save(relativePath, data);

      /*String relativePathClean = relativePath;
      if (relativePath.startsWith("/")) {
      	relativePathClean = relativePath.substring(relativePath.indexOf("/") + 1);
      }*/
      commitRepository(
          " File " + relativePath + " saved ",
          " from site ",
          " [email protected] "); // TODO fix name and email

      try {

        // addFileToRepository(f);
        git.pull().call();

        /*} catch (Exception e) {
        	logger.error("error while unlock and commit git ", e);
        }*/
      } catch (DetachedHeadException e) {
        try {

          git.revert().call();
          save(relativePath + ".bak_" + new Date(), data);
          commitRepository(
              " File " + relativePath + " saved with conflict ",
              " name ",
              " email "); // TODO fix name and email
          UsernamePasswordCredentialsProvider user =
              new UsernamePasswordCredentialsProvider(
                  (String) this.getDictionary().get("login"),
                  (String) this.getDictionary().get("pass"));
          git.push().setCredentialsProvider(user).call();
          return false;

        } catch (GitAPIException e1) {
          e1.printStackTrace(); // To change body of catch statement use File | Settings | File
          // Templates.
        }

        e.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      } catch (NoHeadException e) {
        e.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      } catch (TransportException e) {
        e.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      } catch (InvalidConfigurationException e) {
        e.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      } catch (InvalidRemoteException e) {
        e.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      } catch (CanceledException e) {
        e.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      } catch (WrongRepositoryStateException e) {
        e.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      } catch (RefNotFoundException e) {
        e.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      } catch (GitAPIException e) {
        e.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      }
      try {
        UsernamePasswordCredentialsProvider user =
            new UsernamePasswordCredentialsProvider(
                (String) this.getDictionary().get("login"),
                (String) this.getDictionary().get("pass"));
        git.push().setCredentialsProvider(user).call();
        return true;
      } catch (GitAPIException e) {
        e.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      }
    }

    return true;
  }