public void testBasic() throws Exception {
    if (!Dpkg.available()) {
      return;
    }

    DebPackagingFormat packagingFormat = (DebPackagingFormat) lookup(PackagingFormat.ROLE, "deb");

    FileObject dpkgTest = VFS.getManager().resolveFile(getTestPath("target/deb-test"));
    FileObject packageRoot = dpkgTest.resolveFile("root");
    File packageFile = VfsUtil.asFile(dpkgTest.resolveFile("file.deb"));

    PackageVersion version = packageVersion("1.0", "123", false, some("1"));
    PackageParameters parameters =
        packageParameters(
                "mygroup",
                "myartifact",
                version,
                "id",
                "default-name",
                Option.<java.lang.String>none(),
                EMPTY,
                EMPTY)
            .contact("Kurt Cobain")
            .architecture("all");

    List<String> nil = List.nil();
    packagingFormat
        .start()
        .parameters(parameters)
        .debParameters(Option.<String>none(), some("devel"), false, nil, nil, nil, nil, nil, nil)
        .debug(true)
        .workingDirectory(packageRoot)
        .packageToFile(packageFile, ScriptUtil.Strategy.SINGLE);

    assertTrue(packageFile.canRead());
  }
 private FileObject createFile(FileObject directory, String fileName) throws Exception {
   FileObject f = VFS.getManager().resolveFile(directory, fileName);
   OutputStream os = f.getContent().getOutputStream();
   os.write(TestStringSpecifications.SimpleAlternateCalculatorTest.getBytes());
   os.close();
   return f;
 }
 public boolean validateLoginData() throws FileSystemException {
   if (loginData == null) {
     return true;
   }
   final FileObject vfsConnection = PublishUtil.createVFSConnection(VFS.getManager(), loginData);
   try {
     final FileSystem fileSystem = vfsConnection.getFileSystem();
     if (fileSystem instanceof WebSolutionFileSystem) {
       final WebSolutionFileSystem webSolutionFileSystem = (WebSolutionFileSystem) fileSystem;
       final Long l =
           (Long)
               webSolutionFileSystem.getAttribute(
                   WebSolutionFileSystem.LAST_REFRESH_TIME_ATTRIBUTE);
       if (l != null) {
         if ((System.currentTimeMillis() - l) > 500) {
           webSolutionFileSystem.getLocalFileModel().refresh();
         }
       }
       return true;
     }
   } catch (FileSystemException fse) {
     // not all file systems support attributes ..
   } catch (IOException e) {
     return false;
   }
   final FileType type = vfsConnection.getType();
   if (type != FileType.FOLDER) {
     return false;
   }
   return true;
 }
  @Before
  public void setUp() throws Exception {
    moduleFolder = new InMemoryModuleFolder(VFS.getManager());

    moduleSystem =
        new ModuleBuilder().withAutoDeployFolder(moduleFolder.getModuleDirectory()).build();
  }
Beispiel #5
0
 private BlobStoreShell(String uri) throws FileSystemException {
   remoteMgr = new DefaultFileSystemManager();
   remoteMgr.setFilesCache(new SoftRefFilesCache());
   remoteMgr.addProvider("blobstore", new BlobStoreFileProvider());
   remoteMgr.init();
   remoteCwd = remoteMgr.resolveFile(checkNotNull(uri, "uri"));
   mgr = VFS.getManager();
   cwd = mgr.resolveFile(System.getProperty("user.dir"));
   reader = new BufferedReader(new InputStreamReader(System.in));
 }
 public OpcPackage get(String filepath) throws Docx4JException {
   OpcPackage thePackage = null;
   try {
     FileObject fo = VFS.getManager().resolveFile(filepath);
     thePackage = getPackageFromFileObject(fo);
   } catch (FileSystemException exc) {
     exc.printStackTrace();
     throw new Docx4JException("Couldn't get FileObject", exc);
   }
   return thePackage;
 }
  protected FileSystemManager getFileSystemManager() {
    if (fsManager == null) {
      try {
        fsManager = VFS.getManager();
      } catch (FileSystemException e) {
        throw new RuntimeException(e);
      }
    }

    return fsManager;
  }
Beispiel #8
0
  private void initData() {
    try {
      FileSystemManager fsManager = VFS.getManager();
      currentFileObject = fsManager.resolveFile("jar://" + filename);
      textLocation.setText(currentFileObject.getName().getPath());

    } catch (Exception e) {
      e.printStackTrace();
    }
    changeCurrentNode();
  }
 public PentahoXmlaServlet() {
   super();
   repo = PentahoSystem.get(IUnifiedRepository.class);
   mondrianCatalogService =
       (MondrianCatalogHelper) PentahoSystem.get(IMondrianCatalogService.class);
   try {
     DefaultFileSystemManager dfsm = (DefaultFileSystemManager) VFS.getManager();
     if (dfsm.hasProvider("mondrian") == false) {
       dfsm.addProvider("mondrian", new MondrianVfs());
     }
   } catch (FileSystemException e) {
     logger.error(e.getMessage());
   }
 }
  /**
   * Save the contained Package as a Zip file in the file system
   *
   * @param filepath The destination file path whose syntax has to follow Apache Commons-VFS uri
   *     file system syntax.
   * @return true if successful; false, otherwise.
   * @throws Docx4JException if there is an error
   */
  public boolean save(String filepath) throws Docx4JException {
    log.info("Saving to" + filepath);

    boolean success = true;

    try {
      FileObject fo = VFS.getManager().resolveFile(filepath);
      success = save(fo);
    } catch (FileSystemException exc) {
      exc.printStackTrace();
      throw new Docx4JException("Couldn't get FileObject", exc);
    }

    return success;
  }
  public OpcPackage getPackageFromFileObject(FileObject fo) throws Docx4JException {
    OpcPackage thePackage = null;

    if (!(fo instanceof LocalFile)) {
      // Non-Local file such as webdav file.
      // We make a temporary local copy of the file.
      // TODO: 28/03/08 - This is a second approach of dealing with non-local file.
      // The first approach which is more preferable and done in SVN version 233
      // does not create a temporary local copy of the file.
      // It uses Commons-VFS "zip://" uri scheme to directly access the non-local file.
      // This second approach is being carried out because the writing operation cannot
      // use Commons-VFS "zip://" scheme as the scheme does not support writing to
      // zip file yet.
      // TODO: 28/03/08 - DO NOT use "tmp://" scheme to make a temporary file.
      // as it is going to fail. The current Commons-VFS library is still buggy.
      StringBuffer sb = new StringBuffer("file:///");
      sb.append(System.getProperty("user.home"));
      sb.append("/.docx4j/tmp/");
      sb.append(fo.getName().getBaseName());
      String tmpPath = sb.toString().replace('\\', '/');

      LocalFile localCopy = null;
      try {
        localCopy = (LocalFile) VFS.getManager().resolveFile(tmpPath);
        localCopy.copyFrom(fo, new FileTypeSelector(FileType.FILE));
        localCopy.close();

        thePackage = getPackageFromLocalFile(localCopy);
      } catch (FileSystemException exc) {
        exc.printStackTrace();
        throw new Docx4JException("Could not create a temporary local copy", exc);
      } finally {
        if (localCopy != null) {
          try {
            localCopy.delete();
          } catch (FileSystemException exc) {
            exc.printStackTrace();
            log.warn("Couldn't delete temporary file " + tmpPath);
          }
        }
      }
    } else {
      thePackage = getPackageFromLocalFile((LocalFile) fo);
    }

    return thePackage;
  }
  public static void main(String[] args) {
    try {
      // UIManager.setLookAndFeel(new org.jvnet.substance.skin.SubstanceCremeCoffeeLookAndFeel());
      LookAndFeelFactory.installDefaultLookAndFeel();
      ImageFileExplorer explorer =
          new ImageFileExplorer(VFS.getManager().resolveFile("C:/javacode"));
      SearchableImageFileExplorer sexplorer = new SearchableImageFileExplorer(explorer);

      JFrame frame = new JFrame();
      frame.add(sexplorer.getComponent(), BorderLayout.CENTER);
      frame.pack();
      frame.setVisible(true);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 public void testDefault() throws Exception {
   Heuristics heuristics = RuleBasedHeuristics.getDefaultInstance();
   FileSystemManager fsm = VFS.getManager();
   FileObject root =
       fsm.resolveFile(
               RuleBasedHeuristicsTest.class.getResource("/heuristics/.root").toExternalForm())
           .getParent();
   for (Reason reason : Reason.values()) {
     for (FileObject file : root.resolveFile(reason.toString().toLowerCase()).getChildren()) {
       InputStream is = file.getContent().getInputStream();
       DeliveryStatus ds = new DeliveryStatus(is);
       is.close();
       assertEquals(
           "Reason for " + file,
           reason,
           heuristics.getReason(ds.getPerRecipientParts()[0].getDiagnostic()));
     }
   }
 }
  protected void setUp() throws Exception {
    String tempDir = System.getProperty("java.io.tmpdir");
    FileSystemManager fsm = VFS.getManager();

    rootDir = fsm.resolveFile(tempDir + "/testfsr");
    rootDir.createFolder();
    tempFile = createFile(rootDir, "fsp.html");

    subdir1 = fsm.resolveFile(rootDir, "SubDir1");
    subdir1.createFolder();

    createFile(subdir1, "toto.html");
    createFile(subdir1, "titi.HTML");
    subdir2 = fsm.resolveFile(rootDir, "SubDir2");
    subdir2.createFolder();

    createFile(subdir2, "toto.html");
    subsubdir = fsm.resolveFile(subdir2, "subsubdir");
    subsubdir.createFolder();

    createFile(subsubdir, "momo.html");
    createFile(subsubdir, "mimi.html");
  }
  public void setPath(String path) {

    FileSystemManager fileSystemManager;
    try {
      fileSystemManager = VFS.getManager();

      FileObject fileObject;
      fileObject = fileSystemManager.resolveFile(path);
      if (fileObject == null) {
        throw new IOException("File cannot be resolved: " + path);
      }
      if (!fileObject.exists()) {
        throw new IOException("File does not exist: " + path);
      }
      repoURL = fileObject.getURL();
      if (repoURL == null) {
        throw new Exception("Cannot load connection repository from path: " + path);
      } else {
        load();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @Test
  public void testHappyPath() throws IOException, URISyntaxException, InternalException {
    LibraryModelBuilder libraryModelBuilder =
        new LibraryModelBuilder(
            new LibraryVersionResource(
                "com.pongasoft", "com.pongasoft.kiwidoc.builder.doclet", "1.0"));

    SourceCodeParser sourceCodeParser = new SourceCodeParser();

    FileObject sources =
        VFS.getManager().toFileObject(new File("../com.pongasoft.kiwidoc.testdata/src/main/java"));

    sourceCodeParser.parseSources(
        libraryModelBuilder, sources, "overview.html", null, Collections.<FileObject>emptyList());

    for (PackageModelBuilder packageModelBuilder : libraryModelBuilder.getAllPackages()) {
      for (ClassModelBuilder classModelBuilder : packageModelBuilder.getAllClasses()) {
        System.out.println(classModelBuilder.buildModel().getGenericTypeVariables());
      }
    }

    // sourceCodeParser.parse(new
    // File("../com.pongasoft.kiwidoc.testdata/src/main/java/com/pongasoft/kiwidoc/testdata/pubdir1/I1G.java"));
  }
Beispiel #17
0
 private Shell() throws FileSystemException {
   mgr = VFS.getManager();
   cwd = mgr.resolveFile(System.getProperty("user.dir"));
   reader = new BufferedReader(new InputStreamReader(System.in));
 }
Beispiel #18
0
  public String getFileContent(String fileName) throws Exception {
    FileSystemManager fsManager = null;
    FileObject sftpFile = null;
    FileObject src = null; // used for cleanup in release()
    String fileContent = null;

    try {
      System.out.println("SFTP download");
      FileSystemOptions opts = null;
      // app.initialize();
      try {
        fsManager = VFS.getManager();
      } catch (FileSystemException ex) {
        throw new RuntimeException("failed to get fsManager from VFS", ex);
      }

      UserAuthenticator auth = new StaticUserAuthenticator(null, this.user, this.password);
      opts = new FileSystemOptions();
      try {
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
        SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
      } catch (FileSystemException ex) {
        throw new RuntimeException("setUserAuthenticator failed", ex);
      }

      // app.process();
      String startPath =
          "sftp://"
              + this.user
              + ":"
              + this.password
              + "@"
              + this.host
              + ":22"
              + this.remoteDir
              + fileName;

      // Set starting path on remote SFTP server.
      try {
        sftpFile = fsManager.resolveFile(startPath, opts);

        System.out.println("SFTP connection successfully established to " + startPath);
      } catch (FileSystemException ex) {
        throw new RuntimeException("SFTP error parsing path " + this.remoteDir, ex);
      }

      if (sftpFile.exists()) {
        FileContent fc = sftpFile.getContent();
        StringWriter writer = new StringWriter();
        IOUtils.copy(fc.getInputStream(), writer, encoding);
        String theString = writer.toString();
        //	         	System.out.println(theString);
        fileContent = theString;
      }

    } finally {
      // app.release();
      /** Release system resources, close connection to the filesystem. */
      try {
        FileSystem fs = null;
        if (sftpFile != null) {
          fs = sftpFile.getFileSystem(); // This works even if the src is closed.
          fsManager.closeFileSystem(fs);
        } // TODO if sftpFile != null
      } catch (Exception e) {
        System.out.println(e);
      }
    }
    return fileContent;
  }