Exemplo 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;
  }
Exemplo 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();
  }
Exemplo n.º 3
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;
  }