예제 #1
0
 @NbBundle.Messages({"LBL_generator_progress_title=Generating TestNG tests"})
 ProgressIndicator() {
   //        String msg = NbBundle.getMessage(ProgressIndicator.class,
   //                                        "LBL_generator_progress_title");//NOI18N
   String msg = Bundle.LBL_generator_progress_title();
   progressHandle = ProgressHandleFactory.createHandle(msg);
 }
예제 #2
0
 @Override
 protected Object doInBackground() {
   hashDb.indexing = true;
   progress =
       ProgressHandleFactory.createHandle(
           NbBundle.getMessage(
               this.getClass(), "HashDbManager.progress.indexingHashSet", hashDb.hashSetName));
   progress.start();
   progress.switchToIndeterminate();
   try {
     SleuthkitJNI.createLookupIndexForHashDatabase(hashDb.handle);
   } catch (TskCoreException ex) {
     Logger.getLogger(HashDb.class.getName())
         .log(Level.SEVERE, "Error indexing hash database", ex); // NON-NLS
     JOptionPane.showMessageDialog(
         null,
         NbBundle.getMessage(
             this.getClass(),
             "HashDbManager.dlgMsg.errorIndexingHashSet",
             hashDb.getHashSetName()),
         NbBundle.getMessage(this.getClass(), "HashDbManager.hashDbIndexingErr"),
         JOptionPane.ERROR_MESSAGE);
   }
   return null;
 }
 public void run() {
   ProgressHandle ph =
       ProgressHandleFactory.createHandle(
           NbBundle.getMessage(RetrieverEngineImpl.class, "LBL_PROGRESSBAR_Retrieve_XML"),
           new Cancellable() {
             public boolean cancel() {
               synchronized (RetrieverEngineImpl.this) {
                 if (!RetrieverEngineImpl.this.STOP_PULL) {
                   RetrieverEngineImpl.this.STOP_PULL = true;
                   // taskThread.interrupt();
                 }
               }
               return true;
             }
           },
           new AbstractAction() {
             public void actionPerformed(ActionEvent e) {
               getOPWindow().setOutputVisible(true);
               getOPWindow().select();
             }
           });
   ph.start();
   ph.switchToIndeterminate();
   try {
     pullRecursively();
   } finally {
     ph.finish();
   }
 }
예제 #4
0
    @Override
    public void run() {
      if (!EventQueue.isDispatchThread()) {
        ProgressHandle ph;
        ph =
            ProgressHandleFactory.createHandle(
                NbBundle.getMessage(ResultsTopComponent.class, "PreparingResultsWindow.msg"));
        ph.start();
        n = new ResultsNode(query);
        rtcsc = query.getColumns();
        List cols = Arrays.asList(rtcsc);
        Iterator colsIt = cols.iterator();
        alps = new ArrayList();
        while (colsIt.hasNext()) {
          RtcQueryColumn rsc = (RtcQueryColumn) colsIt.next();
          alps.add(rsc.getColumnIdentifier());
          alps.add(rsc.getColumnDisplayName());
        }
        actualCols = alps.toArray(new String[] {});
        EventQueue.invokeLater(this);
        ph.finish();
      } else {
        outlineView.setPropertyColumns(alps.toArray(new String[] {}));
        Outline outline = outlineView.getOutline();
        removeDefaultColumn(outline);
        ETableColumnModel etcm = (ETableColumnModel) outline.getColumnModel();

        // TODO: szymon : change j to proper sort order
        int j = 1;
        for (int i = 1; i < rtcsc.length; i++) {
          ETableColumn etc = (ETableColumn) etcm.getColumn(i);
          if (alps.get(i * 2 - 2).equals("id")) {
            etc.setMaxWidth(20);
          }
          if (alps.get(i * 2 - 2).equals("internalSeverity")) {
            etc.setMaxWidth(20);
          }
          if (alps.get(i * 2 - 2).equals("internalPriority")) {
            etc.setMaxWidth(20);
          }
          if (alps.get(i * 2 - 2).equals("workItemType")) {
            etc.setMaxWidth(20);
          }
          if (alps.get(i * 2 - 2).equals("internalState")) {
            etc.setMaxWidth(85);
          }
          if (alps.get(i * 2 - 2).equals("summary")) {
            etc.setMaxWidth(550);
            etc.setWidth(475);
            etc.setMinWidth(400);
          }
          if (rtcsc[i].isSortColumn()) {
            etcm.setColumnSorted(etc, rtcsc[i].isAscending(), j);
            j++;
          }
        }

        manager.setRootContext(n);
      }
    }
    @Override
    protected Object doInBackground() throws Exception {
      registerWriter(
          this); // register (synchronized on class) outside of writerLock to prevent deadlock
      final String queryStr = query.getQueryString();
      final String queryDisp =
          queryStr.length() > QUERY_DISPLAY_LEN
              ? queryStr.substring(0, QUERY_DISPLAY_LEN - 1) + " ..."
              : queryStr;
      // block until previous writer is done
      // writerLock.lock();

      try {
        progress =
            ProgressHandleFactory.createHandle(
                NbBundle.getMessage(
                    this.getClass(), "KeywordSearchResultFactory.progress.saving", queryDisp),
                new Cancellable() {
                  @Override
                  public boolean cancel() {
                    return BlackboardResultWriter.this.cancel(true);
                  }
                });

        // Create blackboard artifacts
        newArtifacts = hits.writeAllHitsToBlackBoard(progress, null, this, false);
      } finally {
        finalizeWorker();
      }

      return null;
    }
  protected void onStateChange() {
    switch (getState()) {
      case DONE:
        makeBusy(false);

        loadingPanel.setLoading(false);
        raView.refresh();

        if (progressHandle != null) {
          progressHandle.finish();
        }

        break;
      case PENDING:
        runButton.setEnabled(true);
        break;
      case STARTED:
        runButton.setEnabled(false);
        loadingPanel.setLoading(true);
        progressHandle =
            ProgressHandleFactory.createHandle(
                "Processing Time Series...",
                new Cancellable() {
                  @Override
                  public boolean cancel() {
                    runButton.setEnabled(true);
                    return worker.cancel(true);
                  }
                });
        progressHandle.start();
        break;
    }
  }
 private ProgressHandle createProgress() {
   ProgressHandle ph =
       ProgressHandleFactory.createHandle(
           NbBundle.getMessage(
               TakeScreenshotActionProvider.class, "MSG_TakingApplicationScreenshot"));
   ph.setInitialDelay(500);
   ph.start();
   return ph;
 }
 @Override
 public Spatial loadAsset() {
   ProgressHandle handle = ProgressHandleFactory.createHandle("Converting OgreBinary");
   handle.start();
   // mesh
   OgreXMLConvertOptions options = new OgreXMLConvertOptions(getPrimaryFile().getPath());
   options.setBinaryFile(true);
   OgreXMLConvert conv = new OgreXMLConvert();
   conv.doConvert(options, handle);
   // try skeleton
   if (getPrimaryFile().existsExt("skeleton")) {
     OgreXMLConvertOptions options2 =
         new OgreXMLConvertOptions(
             getPrimaryFile()
                 .getParent()
                 .getFileObject(getPrimaryFile().getName(), "skeleton")
                 .getPath());
     options2.setBinaryFile(true);
     OgreXMLConvert conv2 = new OgreXMLConvert();
     conv2.doConvert(options2, handle);
   }
   handle.progress("Convert Model");
   ProjectAssetManager mgr = getLookup().lookup(ProjectAssetManager.class);
   if (mgr == null) {
     DialogDisplayer.getDefault()
         .notifyLater(
             new NotifyDescriptor.Message(
                 "File is not part of a project!\nCannot load without ProjectAssetManager."));
     return null;
   }
   String assetKey = mgr.getRelativeAssetPath(options.getDestFile());
   FileLock lock = null;
   try {
     lock = getPrimaryFile().lock();
     listListener.start();
     Spatial spatial = mgr.loadModel(assetKey);
     // replace transient xml files in list of assets for this model
     replaceXmlFiles();
     listListener.stop();
     savable = spatial;
     lock.releaseLock();
     File deleteFile = new File(options.getDestFile());
     deleteFile.delete();
     handle.finish();
     return spatial;
   } catch (IOException ex) {
     Exceptions.printStackTrace(ex);
     if (lock != null) {
       lock.releaseLock();
     }
   }
   File deleteFile = new File(options.getDestFile());
   deleteFile.delete();
   handle.finish();
   return null;
 }
 public void start() {
   int totalFiles = buildFiles.length + runFiles.length;
   if (totalFiles == 0) {
     return;
   }
   progress = ProgressHandleFactory.createHandle("Executing...", this);
   progress.setInitialDelay(0);
   progress.start(totalFiles);
   next();
 }
  public void run() {
    assert task != null;
    try {
      startTime = System.currentTimeMillis();
      ProgressHandle handle = ProgressHandleFactory.createHandle(title, this);
      handle.setDisplayName(titleMsg);
      handle.start();
      try {
        handle.switchToIndeterminate();
        dataView.setInfoStatusText(""); // NOI18N
        errorMsg = ""; // NOI18N
        dataView.disableButtons();

        conn = DBConnectionFactory.getInstance().getConnection(dataView.getDatabaseConnection());
        String msg = "";
        if (conn == null) {
          Throwable connEx = DBConnectionFactory.getInstance().getLastException();
          if (connEx != null) {
            msg = connEx.getMessage();
          } else {
            msg =
                NbBundle.getMessage(
                    SQLStatementExecutor.class,
                    "MSG_connection_failure",
                    dataView.getDatabaseConnection());
          }
          NotifyDescriptor nd = new NotifyDescriptor.Message(msg);
          DialogDisplayer.getDefault().notify(nd);
          return;
        }
        lastCommitState = setAutocommit(conn, false);
        execute(); // delegate
      } finally {
        handle.finish();
      }
    } catch (Exception e) {
      this.ex = e;
    } finally {
      if (ex != null) {
        errorMsg += ex.getMessage();
        error = true;
      }
      finished(); // delegate
      resetAutocommitState(conn, lastCommitState);
    }
  }
예제 #11
0
    @Override
    protected Object doInBackground() throws Exception {

      final String displayName = "Queueing Ingest";
      progress =
          ProgressHandleFactory.createHandle(
              displayName,
              new Cancellable() {
                @Override
                public boolean cancel() {
                  logger.log(Level.INFO, "Queueing ingest cancelled by user.");
                  if (progress != null) {
                    progress.setDisplayName(displayName + " (Cancelling...)");
                  }
                  return EnqueueWorker.this.cancel(true);
                }
              });

      progress.start(2 * inputs.size());
      // progress.switchToIndeterminate();
      queueAll(modules, inputs);
      return null;
    }
예제 #12
0
 @NbBundle.Messages({
   "# {0} - project name",
   "InternalWebServer.stopping=Stopping PHP built-in web server for project {0}..."
 })
 @SuppressWarnings("SleepWhileHoldingLock")
 private static boolean ensureServerStopped(InternalWebServer instance) {
   assert !EventQueue.isDispatchThread();
   ProgressHandle progressHandle =
       ProgressHandleFactory.createHandle(
           Bundle.InternalWebServer_stopping(instance.project.getName()));
   try {
     progressHandle.start();
     // stop server
     instance.stop();
     // wait for shutdown
     RunConfigInternal runConfig = RunConfigInternal.forProject(instance.project);
     String host = runConfig.getHostname();
     int port = Integer.valueOf(runConfig.getPort());
     for (int i = 0; i < 20; ++i) {
       try {
         Socket socket = new Socket(host, port);
         socket.close();
         Thread.sleep(200);
       } catch (InterruptedException ex) {
         Thread.currentThread().interrupt();
       } catch (UnknownHostException ex) {
         return true;
       } catch (IOException ex) {
         return true;
       }
     }
     return false;
   } finally {
     progressHandle.finish();
   }
 }
 @Override
 public void actionPerformed(ActionEvent ev) {
   Runnable runnable =
       new Runnable() {
         @Override
         public void run() {
           cssMinify();
         }
       };
   final RequestProcessor.Task theTask = RP.create(runnable);
   final ProgressHandle ph =
       ProgressHandleFactory.createHandle(
           "Minifying CSS " + context.getPrimaryFile().getName(), theTask);
   theTask.addTaskListener(
       new TaskListener() {
         @Override
         public void taskFinished(org.openide.util.Task task) {
           // JOptionPane.showMessageDialog(null, "Image Compressed Successfully");
           ph.finish();
         }
       });
   ph.start();
   theTask.schedule(0);
 }
예제 #14
0
  public void actionPerformed(ActionEvent e) {
    final JButton source = (e.getSource() instanceof JButton) ? (JButton) e.getSource() : null;
    final TopComponent mainWindow =
        WindowManager.getDefault().findTopComponent("KenaiTopComponent"); // NOI18N
    mainWindow.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    final ProgressHandle progress =
        ProgressHandleFactory.createHandle(
            NbBundle.getMessage(CreateChatAction.class, "LBL_CheckPermissions"));
    progress.setInitialDelay(0);
    progress.start();
    if (source != null) source.setEnabled(true);
    RequestProcessor.getDefault()
        .post(
            new Runnable() {

              public void run() {
                try {
                  if (!project.getKenai().isAuthorized(project, KenaiActivity.PROJECTS_ADMIN)) {
                    SwingUtilities.invokeLater(
                        new Runnable() {

                          public void run() {
                            progress.finish();
                            JOptionPane.showMessageDialog(
                                null,
                                NbBundle.getMessage(
                                    CreateChatAction.class,
                                    "CTL_NotAuthorizedToCreateChat",
                                    getValue(NAME)));
                            mainWindow.setCursor(Cursor.getDefaultCursor());
                            if (source != null) source.setEnabled(true);
                          }
                        });
                    return;
                  }
                } catch (KenaiException ex) {
                  Exceptions.printStackTrace(ex);
                }

                SwingUtilities.invokeLater(
                    new Runnable() {

                      public void run() {
                        int value =
                            JOptionPane.showOptionDialog(
                                null,
                                NbBundle.getMessage(
                                    CreateChatAction.class, "LBL_CreateChatQuestions"),
                                NbBundle.getMessage(CreateChatAction.class, "LBL_CreateChatTitle"),
                                JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE,
                                null,
                                null,
                                null);
                        if (value == JOptionPane.YES_OPTION) {
                          progress.setDisplayName(
                              NbBundle.getMessage(
                                  CreateChatAction.class, "CTL_CreatingChatProgress"));
                          RequestProcessor.getDefault()
                              .post(
                                  new Runnable() {

                                    public void run() {
                                      try {
                                        final KenaiFeature f =
                                            project.createProjectFeature(
                                                project.getName(),
                                                NbBundle.getMessage(
                                                    CreateChatAction.class,
                                                    "CTL_ChatRoomName",
                                                    project.getName()),
                                                NbBundle.getMessage(
                                                    CreateChatAction.class,
                                                    "CTL_ChatRoomDescription",
                                                    project.getName()),
                                                KenaiService.Names.XMPP_CHAT,
                                                null,
                                                null,
                                                null);

                                        SwingUtilities.invokeLater(
                                            new Runnable() {

                                              public void run() {
                                                final ChatTopComponent chatTc =
                                                    ChatTopComponent.findInstance();
                                                chatTc.open();
                                                chatTc.addChat(
                                                    new ChatPanel(
                                                        KenaiConnection.getDefault(
                                                                project.getKenai())
                                                            .getChat(f)));
                                                mainWindow.setCursor(Cursor.getDefaultCursor());
                                                progress.finish();
                                                if (source != null) source.setEnabled(true);
                                                chatTc.requestActive();
                                              }
                                            });
                                      } catch (KenaiException kenaiException) {
                                        Exceptions.printStackTrace(kenaiException);
                                        mainWindow.setCursor(Cursor.getDefaultCursor());
                                        progress.finish();
                                        if (source != null) source.setEnabled(true);
                                      }
                                    }
                                  });

                        } else {
                          mainWindow.setCursor(Cursor.getDefaultCursor());
                          progress.finish();
                          if (source != null) source.setEnabled(true);
                        }
                      }
                    });
              }
            });
  }
  public static synchronized ServiceGeneratorResult generate(final E2EDataObject dataObject) {
    if (dataObject.getServerProject() == null) {
      final NotifyDescriptor.Message dd =
          new NotifyDescriptor.Message(
              NbBundle.getMessage(
                  E2EDataObject.class,
                  "ERR_ServerProjectNotOpened", // NOI18N
                  dataObject.getConfiguration().getServerConfigutation().getProjectName()));
      DialogDisplayer.getDefault().notify(dd);
      if (Util.openProject(dataObject.getConfiguration().getServerConfigutation().getProjectPath())
          == null) {
        // It is OK don't notify user here. All notifications
        // are already inside <code>openProject</code> method
        return null;
      }
    }

    // Call save before generate
    final SaveCookie saveCookie = dataObject.getCookie(SaveCookie.class);
    if (saveCookie != null) {
      try {
        saveCookie.save();
      } catch (IOException ex) {
        ErrorManager.getDefault().notify(ex);
      }
    }

    // Get configuration
    final Configuration config = dataObject.getConfiguration();
    if (config == null) {
      final NotifyDescriptor.Message dd =
          new NotifyDescriptor.Message(
              NbBundle.getMessage(E2EDataObject.class, "ERR_ConfigurationFileCorrupted")); // NOI18N
      DialogDisplayer.getDefault().notify(dd);
      return null;
    }

    if (Configuration.WSDLCLASS_TYPE.equals(config.getServiceType())) {
      final FileObject fo =
          dataObject
              .getServerProject()
              .getProjectDirectory()
              .getFileObject("build/generated/wsimport/"); // NOI18N
      if (fo == null) {
        DialogDisplayer.getDefault()
            .notify(
                new NotifyDescriptor.Message(
                    NbBundle.getMessage(
                        ConnectionGenerator.class, "MSG_WebProjectNotBuilt"))); // NOI18N
        return null;
      }
    }

    /*
     * All failures notifications was done via dialog windows.
     * Starting now logging will be done via  OutputLogger class.
     */

    final ProgressHandle ph =
        ProgressHandleFactory.createHandle(
            NbBundle.getMessage(ConnectionGenerator.class, "MSG_GeneratingJavonBridge"), // NOI18N
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                OutputLogger.getInstance().open();
              }
            });
    ph.start();
    ph.switchToIndeterminate();
    String message =
        NbBundle.getMessage(ConnectionGenerator.class, "MSG_GeneratingProxyStubs"); // NOI18N
    ph.progress(message);
    OutputLogger.getInstance().log(message);
    // FIXME: check for proper type
    //        config.getServices();
    //
    if (Configuration.WSDLCLASS_TYPE.equals(config.getServiceType())) {
      ph.progress(NbBundle.getMessage(ConnectionGenerator.class, "MSG_GeneratingProxyStubs"));
      final ProxyGenerator pg = new ProxyGenerator(dataObject);
      final String className = pg.generate();
      if (className == null) {
        ph.finish();
        StatusDisplayer.getDefault()
            .setStatusText(NbBundle.getMessage(ConnectionGenerator.class, "MSG_Failure")); // NOI18N
        return null;
      }
      config.getServices().get(0).getData().get(0).setProxyClassType(className);
    }
    //        JavonOutput[] outputs;
    //        Type type = null;
    //
    //        final InputOutput io = IOProvider.getDefault().getIO(
    //                NbBundle.getMessage( ConnectionGenerator.class, "LBL_JavonTab" ) // NOI18N
    //                , true);
    //        final OutputWriter ow = io.getOut();
    try {
      String scanning =
          NbBundle.getMessage(ConnectionGenerator.class, "MSG_ScanningDataStructures"); // NOI18N
      ph.progress(scanning);
      OutputLogger.getInstance().log(scanning);

      final JavonMappingImpl mapping = dataObject.getMapping();
      if (Configuration.WSDLCLASS_TYPE.equals(config.getServiceType())) {
        mapping.setProperty("serviceType", "WSDL");
      } else {
        mapping.setProperty("serviceType", "CLASS");
      }
      //            //ph.progress(70);
      String creating =
          NbBundle.getMessage(ConnectionGenerator.class, "MSG_CreatingJavaFiles"); // NOI18N
      ph.progress(creating);
      OutputLogger.getInstance().log(creating);
      //
      Javon javon = new Javon(mapping);
      if (javon.generate(ph)) {
        StatusDisplayer.getDefault()
            .setStatusText(
                NbBundle.getMessage(ConnectionGenerator.class, "MSG_SuccessGenerated")); // NOI18N
        OutputLogger.getInstance()
            .log(NbBundle.getMessage(ConnectionGenerator.class, "TXT_GenerationSuccess")); // NOI18N
      } else {
        StatusDisplayer.getDefault()
            .setStatusText(NbBundle.getMessage(ConnectionGenerator.class, "MSG_Failure")); // NOI18N
        OutputLogger.getInstance()
            .log(
                NbBundle.getMessage(
                    ConnectionGenerator.class, "TXT_GenerationUnsuccess")); // NOI18N
      }
      //            Streams.setOut(ow);
      //            Streams.setErr(ow);
      //            outputs = new Main().run( mapping, "" ); // NOI18N
      //
      //            for( int j = 0; j < outputs.length; j++ ) {
      //                final String list[] = outputs[j].getCreatedFiles();
      //                for( int i = 0; i < list.length; i++ ) {
      //                    final File f = new File(list[i]);
      //                    final FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(f));
      //                    fo.refresh();
      //                    JavaModel.getResource(fo);
      //                }
      //            }
      //            //add servlet to container
      //            Util.addServletToWebProject(dataObject.getServerProject(),
      // dataObject.getConfiguration().getServerConfigutation().getClassDescriptor().getType());
      //
      //            final ClassDescriptor clientClassDescriptor =
      // dataObject.getConfiguration().getClientConfiguration().getClassDescriptor();
      //            final Sources s = ProjectUtils.getSources(dataObject.getClientProject());
      //            final SourceGroup sourceGroup = Util.getPreselectedGroup(
      //                    s.getSourceGroups( JavaProjectConstants.SOURCES_TYPE_JAVA ),
      //                    clientClassDescriptor.getLocation());
      //            final FileObject srcDirectory = sourceGroup.getRootFolder();
      //            final ClassPath cp = ClassPath.getClassPath(srcDirectory,ClassPath.SOURCE);
      //            JavaModel.getJavaRepository().beginTrans(false);
      //            try {
      //                JavaModel.setClassPath(cp);
      //                type =
      // JavaModel.getDefaultExtent().getType().resolve(clientClassDescriptor.getType());
      //            } catch (Exception e){
      //                ErrorManager.getDefault().notify(e);
      //            } finally {
      //                JavaModel.getJavaRepository().endTrans();
      //            }
    } finally {
      ph.finish();
      OutputLogger.getInstance().close();
    }
    //        if (type != null){
    //            //ow.println("Run / Redeploy Web Project to get changes reflected!");
    //            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(
    // ConnectionGenerator.class, "MSG_SuccessGenerated" )); // NOI18N
    //        } else {
    //            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(
    // ConnectionGenerator.class, "MSG_Failure" )); // NOI18N
    //            return null;
    //        }
    //        final JavaClass resultClass = (JavaClass)type;
    //        final List<Feature> features = resultClass.getFeatures();
    //        final List<Method> methods = new ArrayList<Method>();
    //        for ( final Feature elem : features ) {
    //            if (elem instanceof Method){
    //                final Method m = (Method)elem;
    //                if ("getGroupedResults".equals(m.getName())){ //NOI18N //not supported
    //                    continue;
    //                }
    //                if (m.getName().endsWith("Grouped")){ //NOI18N //not supported
    //                    continue;
    //                }
    //                if ( Modifier.isPublic(m.getModifiers()) ){
    //                    methods.add(m);
    //                }
    //            }
    //        }
    //        return new ServiceGeneratorResult(resultClass,
    //                methods.toArray(new Method[methods.size()]),
    //                Util.getServerURL(dataObject.getServerProject(),
    // dataObject.getConfiguration()));
    return null;
  }
예제 #16
0
  /**
   * Unpack the file to local folder and return a list of derived files
   *
   * @param pipelineContext current ingest context
   * @param archiveFile file to unpack
   * @return list of unpacked derived files
   */
  void unpack(AbstractFile archiveFile) {
    String archiveFilePath;
    try {
      archiveFilePath = archiveFile.getUniquePath();
    } catch (TskCoreException ex) {
      archiveFilePath = archiveFile.getParentPath() + archiveFile.getName();
    }

    // check if already has derived files, skip
    try {
      if (archiveFile.hasChildren()) {
        // check if local unpacked dir exists
        if (new File(EmbeddedFileExtractorIngestModule.getUniqueName(archiveFile)).exists()) {
          logger.log(
              Level.INFO,
              "File already has been processed as it has children and local unpacked file, skipping: {0}",
              archiveFilePath); // NON-NLS
          return;
        }
      }
    } catch (TskCoreException e) {
      logger.log(
          Level.INFO,
          "Error checking if file already has been processed, skipping: {0}",
          archiveFilePath); // NON-NLS
      return;
    }

    List<AbstractFile> unpackedFiles = Collections.<AbstractFile>emptyList();

    // recursion depth check for zip bomb
    final long archiveId = archiveFile.getId();
    SevenZipExtractor.ArchiveDepthCountTree.Archive parentAr =
        archiveDepthCountTree.findArchive(archiveId);
    if (parentAr == null) {
      parentAr = archiveDepthCountTree.addArchive(null, archiveId);
    } else if (parentAr.getDepth() == MAX_DEPTH) {
      String msg =
          NbBundle.getMessage(
              this.getClass(),
              "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.warnMsg.zipBomb",
              archiveFile.getName());
      String details =
          NbBundle.getMessage(
              this.getClass(),
              "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.warnDetails.zipBomb",
              parentAr.getDepth(),
              archiveFilePath);
      // MessageNotifyUtil.Notify.error(msg, details);
      services.postMessage(
          IngestMessage.createWarningMessage(
              EmbeddedFileExtractorModuleFactory.getModuleName(), msg, details));
      return;
    }

    boolean hasEncrypted = false;
    boolean fullEncryption = true;

    ISevenZipInArchive inArchive = null;
    SevenZipContentReadStream stream = null;

    final ProgressHandle progress =
        ProgressHandleFactory.createHandle(
            NbBundle.getMessage(
                this.getClass(), "EmbeddedFileExtractorIngestModule.ArchiveExtractor.moduleName"));
    int processedItems = 0;

    boolean progressStarted = false;
    try {
      stream = new SevenZipContentReadStream(new ReadContentInputStream(archiveFile));

      // for RAR files we need to open them explicitly as RAR. Otherwise, if there is a ZIP archive
      // inside RAR archive
      // it will be opened incorrectly when using 7zip's built-in auto-detect functionality.
      // All other archive formats are still opened using 7zip built-in auto-detect functionality.
      ArchiveFormat options = get7ZipOptions(archiveFile);
      inArchive = SevenZip.openInArchive(options, stream);

      int numItems = inArchive.getNumberOfItems();
      logger.log(
          Level.INFO,
          "Count of items in archive: {0}: {1}",
          new Object[] {archiveFilePath, numItems}); // NON-NLS
      progress.start(numItems);
      progressStarted = true;

      final ISimpleInArchive simpleInArchive = inArchive.getSimpleInterface();

      // setup the archive local root folder
      final String uniqueArchiveFileName =
          EmbeddedFileExtractorIngestModule.getUniqueName(archiveFile);
      final String localRootAbsPath = getLocalRootAbsPath(uniqueArchiveFileName);
      final File localRoot = new File(localRootAbsPath);
      if (!localRoot.exists()) {
        try {
          localRoot.mkdirs();
        } catch (SecurityException e) {
          logger.log(
              Level.SEVERE,
              "Error setting up output path for archive root: {0}",
              localRootAbsPath); // NON-NLS
          // bail
          return;
        }
      }

      // initialize tree hierarchy to keep track of unpacked file structure
      SevenZipExtractor.UnpackedTree unpackedTree =
          new SevenZipExtractor.UnpackedTree(
              moduleDirRelative + "/" + uniqueArchiveFileName, archiveFile);

      long freeDiskSpace = services.getFreeDiskSpace();

      // unpack and process every item in archive
      int itemNumber = 0;
      for (ISimpleInArchiveItem item : simpleInArchive.getArchiveItems()) {
        String pathInArchive = item.getPath();

        if (pathInArchive == null || pathInArchive.isEmpty()) {
          // some formats (.tar.gz) may not be handled correctly -- file in archive has no name/path
          // handle this for .tar.gz and tgz but assuming the child is tar,
          // otherwise, unpack using itemNumber as name

          // TODO this should really be signature based, not extension based
          String archName = archiveFile.getName();
          int dotI = archName.lastIndexOf(".");
          String useName = null;
          if (dotI != -1) {
            String base = archName.substring(0, dotI);
            String ext = archName.substring(dotI);
            switch (ext) {
              case ".gz": // NON-NLS
                useName = base;
                break;
              case ".tgz": // NON-NLS
                useName = base + ".tar"; // NON-NLS
                break;
            }
          }

          if (useName == null) {
            pathInArchive = "/" + archName + "/" + Integer.toString(itemNumber);
          } else {
            pathInArchive = "/" + useName;
          }

          String msg =
              NbBundle.getMessage(
                  this.getClass(),
                  "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.unknownPath.msg",
                  archiveFilePath,
                  pathInArchive);
          logger.log(Level.WARNING, msg);
        }
        ++itemNumber;
        logger.log(Level.INFO, "Extracted item path: {0}", pathInArchive); // NON-NLS

        // check if possible zip bomb
        if (isZipBombArchiveItemCheck(archiveFile, item)) {
          continue; // skip the item
        }

        // find this node in the hierarchy, create if needed
        SevenZipExtractor.UnpackedTree.UnpackedNode unpackedNode =
            unpackedTree.addNode(pathInArchive);

        String fileName = unpackedNode.getFileName();

        // update progress bar
        progress.progress(archiveFile.getName() + ": " + fileName, processedItems);

        final boolean isEncrypted = item.isEncrypted();
        final boolean isDir = item.isFolder();

        if (isEncrypted) {
          logger.log(
              Level.WARNING, "Skipping encrypted file in archive: {0}", pathInArchive); // NON-NLS
          hasEncrypted = true;
          continue;
        } else {
          fullEncryption = false;
        }

        final Long size = item.getSize();
        if (size == null) {
          // If the size property cannot be determined, out-of-disk-space
          // situations cannot be ascertained.
          // Hence skip this file.
          logger.log(
              Level.WARNING,
              "Size cannot be determined. Skipping file in archive: {0}",
              pathInArchive); // NON-NLS
          continue;
        }

        // check if unpacking this file will result in out of disk space
        // this is additional to zip bomb prevention mechanism
        if (freeDiskSpace != IngestMonitor.DISK_FREE_SPACE_UNKNOWN
            && size > 0) { // if known free space and file not empty
          long newDiskSpace = freeDiskSpace - size;
          if (newDiskSpace < MIN_FREE_DISK_SPACE) {
            String msg =
                NbBundle.getMessage(
                    this.getClass(),
                    "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.notEnoughDiskSpace.msg",
                    archiveFilePath,
                    fileName);
            String details =
                NbBundle.getMessage(
                    this.getClass(),
                    "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.notEnoughDiskSpace.details");
            // MessageNotifyUtil.Notify.error(msg, details);
            services.postMessage(
                IngestMessage.createErrorMessage(
                    EmbeddedFileExtractorModuleFactory.getModuleName(), msg, details));
            logger.log(
                Level.INFO,
                "Skipping archive item due to insufficient disk space: {0}, {1}",
                new Object[] {archiveFilePath, fileName}); // NON-NLS
            logger.log(
                Level.INFO, "Available disk space: {0}", new Object[] {freeDiskSpace}); // NON-NLS
            continue; // skip this file
          } else {
            // update est. disk space during this archive, so we don't need to poll for every file
            // extracted
            freeDiskSpace = newDiskSpace;
          }
        }

        final String uniqueExtractedName =
            uniqueArchiveFileName
                + File.separator
                + (item.getItemIndex() / 1000)
                + File.separator
                + item.getItemIndex()
                + new File(pathInArchive).getName();

        // final String localRelPath = unpackDir + File.separator + localFileRelPath;
        final String localRelPath = moduleDirRelative + File.separator + uniqueExtractedName;
        final String localAbsPath = moduleDirAbsolute + File.separator + uniqueExtractedName;

        // create local dirs and empty files before extracted
        File localFile = new java.io.File(localAbsPath);
        // cannot rely on files in top-bottom order
        if (!localFile.exists()) {
          try {
            if (isDir) {
              localFile.mkdirs();
            } else {
              localFile.getParentFile().mkdirs();
              try {
                localFile.createNewFile();
              } catch (IOException ex) {
                logger.log(
                    Level.SEVERE,
                    "Error creating extracted file: " + localFile.getAbsolutePath(),
                    ex); // NON-NLS
              }
            }
          } catch (SecurityException e) {
            logger.log(
                Level.SEVERE,
                "Error setting up output path for unpacked file: {0}",
                pathInArchive); // NON-NLS
            // TODO consider bail out / msg to the user
          }
        }

        // skip the rest of this loop if we couldn't create the file
        if (localFile.exists() == false) {
          continue;
        }

        final Date createTime = item.getCreationTime();
        final Date accessTime = item.getLastAccessTime();
        final Date writeTime = item.getLastWriteTime();
        final long createtime = createTime == null ? 0L : createTime.getTime() / 1000;
        final long modtime = writeTime == null ? 0L : writeTime.getTime() / 1000;
        final long accesstime = accessTime == null ? 0L : accessTime.getTime() / 1000;

        // record derived data in unode, to be traversed later after unpacking the archive
        unpackedNode.addDerivedInfo(
            size, !isDir, 0L, createtime, accesstime, modtime, localRelPath);

        // unpack locally if a file
        if (!isDir) {
          SevenZipExtractor.UnpackStream unpackStream = null;
          try {
            unpackStream = new SevenZipExtractor.UnpackStream(localAbsPath);
            item.extractSlow(unpackStream);
          } catch (Exception e) {
            // could be something unexpected with this file, move on
            logger.log(
                Level.WARNING,
                "Could not extract file from archive: " + localAbsPath,
                e); // NON-NLS
          } finally {
            if (unpackStream != null) {
              unpackStream.close();
            }
          }
        }

        // update units for progress bar
        ++processedItems;
      }

      // add them to the DB. We wait until the end so that we have the metadata on all of the
      // intermediate nodes since the order is not guaranteed
      try {
        unpackedTree.addDerivedFilesToCase();
        unpackedFiles = unpackedTree.getAllFileObjects();

        // check if children are archives, update archive depth tracking
        for (AbstractFile unpackedFile : unpackedFiles) {
          if (isSevenZipExtractionSupported(unpackedFile)) {
            archiveDepthCountTree.addArchive(parentAr, unpackedFile.getId());
          }
        }

      } catch (TskCoreException e) {
        logger.log(
            Level.SEVERE,
            "Error populating complete derived file hierarchy from the unpacked dir structure"); // NON-NLS
        // TODO decide if anything to cleanup, for now bailing
      }

    } catch (SevenZipException ex) {
      logger.log(Level.SEVERE, "Error unpacking file: " + archiveFile, ex); // NON-NLS
      // inbox message

      // print a message if the file is allocated
      if (archiveFile.isMetaFlagSet(TskData.TSK_FS_META_FLAG_ENUM.ALLOC)) {
        String msg =
            NbBundle.getMessage(
                this.getClass(),
                "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.errUnpacking.msg",
                archiveFile.getName());
        String details =
            NbBundle.getMessage(
                this.getClass(),
                "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.errUnpacking.details",
                archiveFilePath,
                ex.getMessage());
        services.postMessage(
            IngestMessage.createErrorMessage(
                EmbeddedFileExtractorModuleFactory.getModuleName(), msg, details));
      }
    } finally {
      if (inArchive != null) {
        try {
          inArchive.close();
        } catch (SevenZipException e) {
          logger.log(Level.SEVERE, "Error closing archive: " + archiveFile, e); // NON-NLS
        }
      }

      if (stream != null) {
        try {
          stream.close();
        } catch (IOException ex) {
          logger.log(
              Level.SEVERE,
              "Error closing stream after unpacking archive: " + archiveFile,
              ex); // NON-NLS
        }
      }

      // close progress bar
      if (progressStarted) {
        progress.finish();
      }
    }

    // create artifact and send user message
    if (hasEncrypted) {
      String encryptionType = fullEncryption ? ENCRYPTION_FULL : ENCRYPTION_FILE_LEVEL;
      try {
        BlackboardArtifact artifact =
            archiveFile.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED);
        artifact.addAttribute(
            new BlackboardAttribute(
                BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getTypeID(),
                EmbeddedFileExtractorModuleFactory.getModuleName(),
                encryptionType));
        services.fireModuleDataEvent(
            new ModuleDataEvent(
                EmbeddedFileExtractorModuleFactory.getModuleName(),
                BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED));
      } catch (TskCoreException ex) {
        logger.log(
            Level.SEVERE,
            "Error creating blackboard artifact for encryption detected for file: "
                + archiveFilePath,
            ex); // NON-NLS
      }

      String msg =
          NbBundle.getMessage(
              this.getClass(),
              "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.encrFileDetected.msg");
      String details =
          NbBundle.getMessage(
              this.getClass(),
              "EmbeddedFileExtractorIngestModule.ArchiveExtractor.unpack.encrFileDetected.details",
              archiveFile.getName(),
              EmbeddedFileExtractorModuleFactory.getModuleName());
      services.postMessage(
          IngestMessage.createWarningMessage(
              EmbeddedFileExtractorModuleFactory.getModuleName(), msg, details));
    }

    // adding unpacked extracted derived files to the job after closing relevant resources.
    if (!unpackedFiles.isEmpty()) {
      // currently sending a single event for all new files
      services.fireModuleContentEvent(new ModuleContentEvent(archiveFile));
      context.addFilesToJob(unpackedFiles);
    }
  }
    @Override
    protected Object doInBackground() throws Exception {
      logger.log(Level.INFO, "Pending start of new searcher");

      final String displayName = "Keyword Search" + (finalRun ? " - Finalizing" : "");
      progress =
          ProgressHandleFactory.createHandle(
              displayName + (" (Pending)"),
              new Cancellable() {

                @Override
                public boolean cancel() {
                  logger.log(Level.INFO, "Cancelling the searcher by user.");
                  if (progress != null) {
                    progress.setDisplayName(displayName + " (Cancelling...)");
                  }
                  return Searcher.this.cancel(true);
                }
              });

      progress.start();
      progress.switchToIndeterminate();

      // block to ensure previous searcher is completely done with doInBackground()
      // even after previous searcher cancellation, we need to check this
      searcherLock.lock();
      try {
        logger.log(Level.INFO, "Started a new searcher");
        progress.setDisplayName(displayName);
        // make sure other searchers are not spawned
        searcherDone = false;
        runSearcher = false;
        if (searchTimer.isRunning()) {
          searchTimer.stop();
        }

        int numSearched = 0;

        updateKeywords();
        progress.switchToDeterminate(keywords.size());

        for (Keyword keywordQuery : keywords) {
          if (this.isCancelled()) {
            logger.log(
                Level.INFO,
                "Cancel detected, bailing before new keyword processed: "
                    + keywordQuery.getQuery());
            return null;
          }
          final String queryStr = keywordQuery.getQuery();
          final KeywordSearchList list = keywordToList.get(queryStr);
          final String listName = list.getName();

          // DEBUG
          // logger.log(Level.INFO, "Searching: " + queryStr);

          progress.progress(queryStr, numSearched);

          KeywordSearchQuery del = null;

          boolean isRegex = !keywordQuery.isLiteral();
          if (!isRegex) {
            del = new LuceneQuery(keywordQuery);
            del.escape();
          } else {
            del = new TermComponentQuery(keywordQuery);
          }

          Map<String, List<ContentHit>> queryResult = null;

          try {
            queryResult = del.performQuery();
          } catch (NoOpenCoreException ex) {
            logger.log(Level.WARNING, "Error performing query: " + keywordQuery.getQuery(), ex);
            // no reason to continue with next query if recovery failed
            // or wait for recovery to kick in and run again later
            // likely case has closed and threads are being interrupted
            return null;
          } catch (CancellationException e) {
            logger.log(
                Level.INFO,
                "Cancel detected, bailing during keyword query: " + keywordQuery.getQuery());
            return null;
          } catch (Exception e) {
            logger.log(Level.WARNING, "Error performing query: " + keywordQuery.getQuery(), e);
            continue;
          }

          // calculate new results but substracting results already obtained in this run
          Map<Keyword, List<ContentHit>> newResults = new HashMap<Keyword, List<ContentHit>>();

          for (String termResult : queryResult.keySet()) {
            List<ContentHit> queryTermResults = queryResult.get(termResult);
            Keyword termResultK = new Keyword(termResult, !isRegex);
            List<ContentHit> curTermResults = currentResults.get(termResultK);
            if (curTermResults == null) {
              currentResults.put(termResultK, queryTermResults);
              newResults.put(termResultK, queryTermResults);
            } else {
              // some AbstractFile hits already exist for this keyword
              for (ContentHit res : queryTermResults) {
                if (!previouslyHit(curTermResults, res)) {
                  // add to new results
                  List<ContentHit> newResultsFs = newResults.get(termResultK);
                  if (newResultsFs == null) {
                    newResultsFs = new ArrayList<ContentHit>();
                    newResults.put(termResultK, newResultsFs);
                  }
                  newResultsFs.add(res);
                  curTermResults.add(res);
                }
              }
            }
          }

          if (!newResults.isEmpty()) {

            // write results to BB

            // new artifacts created, to report to listeners
            Collection<BlackboardArtifact> newArtifacts = new ArrayList<BlackboardArtifact>();

            for (final Keyword hitTerm : newResults.keySet()) {
              List<ContentHit> contentHitsAll = newResults.get(hitTerm);
              Map<AbstractFile, Integer> contentHitsFlattened =
                  ContentHit.flattenResults(contentHitsAll);
              for (final AbstractFile hitFile : contentHitsFlattened.keySet()) {
                String snippet = null;
                final String snippetQuery =
                    KeywordSearchUtil.escapeLuceneQuery(hitTerm.getQuery(), true, false);
                int chunkId = contentHitsFlattened.get(hitFile);
                try {
                  snippet =
                      LuceneQuery.querySnippet(
                          snippetQuery, hitFile.getId(), chunkId, isRegex, true);
                } catch (NoOpenCoreException e) {
                  logger.log(Level.WARNING, "Error querying snippet: " + snippetQuery, e);
                  // no reason to continue
                  return null;
                } catch (Exception e) {
                  logger.log(Level.WARNING, "Error querying snippet: " + snippetQuery, e);
                  continue;
                }

                KeywordWriteResult written =
                    del.writeToBlackBoard(hitTerm.getQuery(), hitFile, snippet, listName);

                if (written == null) {
                  logger.log(
                      Level.WARNING,
                      "BB artifact for keyword hit not written, file: "
                          + hitFile
                          + ", hit: "
                          + hitTerm.toString());
                  continue;
                }

                newArtifacts.add(written.getArtifact());

                // generate a data message for each artifact
                StringBuilder subjectSb = new StringBuilder();
                StringBuilder detailsSb = new StringBuilder();
                // final int hitFiles = newResults.size();

                if (!keywordQuery.isLiteral()) {
                  subjectSb.append("RegExp hit: ");
                } else {
                  subjectSb.append("Keyword hit: ");
                }
                // subjectSb.append("<");
                String uniqueKey = null;
                BlackboardAttribute attr =
                    written.getAttribute(
                        BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD.getTypeID());
                if (attr != null) {
                  final String keyword = attr.getValueString();
                  subjectSb.append(keyword);
                  uniqueKey = keyword.toLowerCase();
                }

                // subjectSb.append(">");
                // String uniqueKey = queryStr;

                // details
                detailsSb.append("<table border='0' cellpadding='4' width='280'>");
                // hit
                detailsSb.append("<tr>");
                detailsSb.append("<th>Keyword hit</th>");
                detailsSb
                    .append("<td>")
                    .append(StringEscapeUtils.escapeHtml(attr.getValueString()))
                    .append("</td>");
                detailsSb.append("</tr>");

                // preview
                attr =
                    written.getAttribute(
                        BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD_PREVIEW.getTypeID());
                if (attr != null) {
                  detailsSb.append("<tr>");
                  detailsSb.append("<th>Preview</th>");
                  detailsSb
                      .append("<td>")
                      .append(StringEscapeUtils.escapeHtml(attr.getValueString()))
                      .append("</td>");
                  detailsSb.append("</tr>");
                }

                // file
                detailsSb.append("<tr>");
                detailsSb.append("<th>File</th>");
                if (hitFile.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.FS)) {
                  detailsSb
                      .append("<td>")
                      .append(((FsContent) hitFile).getParentPath())
                      .append(hitFile.getName())
                      .append("</td>");
                } else {
                  detailsSb.append("<td>").append(hitFile.getName()).append("</td>");
                }
                detailsSb.append("</tr>");

                // list
                attr =
                    written.getAttribute(
                        BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME.getTypeID());
                detailsSb.append("<tr>");
                detailsSb.append("<th>List</th>");
                detailsSb.append("<td>").append(attr.getValueString()).append("</td>");
                detailsSb.append("</tr>");

                // regex
                if (!keywordQuery.isLiteral()) {
                  attr =
                      written.getAttribute(
                          BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD_REGEXP.getTypeID());
                  if (attr != null) {
                    detailsSb.append("<tr>");
                    detailsSb.append("<th>RegEx</th>");
                    detailsSb.append("<td>").append(attr.getValueString()).append("</td>");
                    detailsSb.append("</tr>");
                  }
                }
                detailsSb.append("</table>");

                // check if should send messages on hits on this list
                if (list.getIngestMessages()) // post ingest inbox msg
                {
                  managerProxy.postMessage(
                      IngestMessage.createDataMessage(
                          ++messageID,
                          instance,
                          subjectSb.toString(),
                          detailsSb.toString(),
                          uniqueKey,
                          written.getArtifact()));
                }
              } // for each term hit
            } // for each file hit

            // update artifact browser
            if (!newArtifacts.isEmpty()) {
              IngestManager.fireServiceDataEvent(
                  new ServiceDataEvent(MODULE_NAME, ARTIFACT_TYPE.TSK_KEYWORD_HIT, newArtifacts));
            }
          }
          progress.progress(queryStr, ++numSearched);
        }

      } // end try block
      catch (Exception ex) {
        logger.log(Level.WARNING, "searcher exception occurred", ex);
      } finally {
        finalizeSearcher();
        searcherLock.unlock();
      }

      return null;
    }
예제 #18
0
  public void writePNG(
      final Dimension d, boolean withBackground, final String filepath, boolean sf) {
    if (!stillRendering) {
      Thread renderingThread =
          new Thread(
              new Runnable() {

                @Override
                public void run() {
                  stillRendering = true;
                  long timer = System.currentTimeMillis();
                  pHandle.start();
                  try {
                    if (sf) {
                      Color3f bgcolor = new Color3f();
                      background.getColor(bgcolor);
                      MySunflowRenderer r =
                          new MySunflowRenderer(
                              canting,
                              currentAppearance,
                              currentProjectionMode,
                              cameraPos,
                              cameraFocus,
                              up,
                              fieldOfView,
                              view.getScreenScale(),
                              FARTHEST,
                              CLOSEST,
                              lightState,
                              d.width,
                              d.height,
                              withBackground,
                              bgcolor.get());
                      r.toPNG(filepath);
                      r.cleanup();
                    } else {
                      File output = new File(filepath);
                      try {
                        ImageIO.write(getRenderedImage(d, withBackground), "png", output);
                      } catch (IOException ex) {
                        System.out.println("writing to png using Java3D offscreen canvas failed.");
                      }

                      output = null;
                    }
                  } catch (OutOfMemoryError | IllegalRenderingStateException e) {
                    stillRendering = false;
                    DialogDisplayer.getDefault()
                        .notify(
                            new NotifyDescriptor.Confirmation(
                                "Rendering PNG failed because of memory error.\nTry smaller output.",
                                "Failed",
                                NotifyDescriptor.DEFAULT_OPTION,
                                NotifyDescriptor.WARNING_MESSAGE));
                  }
                  System.gc();
                  System.out.println(
                      "RENDERING TIME: " + (System.currentTimeMillis() - timer) / 1000 + " s");
                  stillRendering = false;
                  pHandle.finish();
                }
              });

      String filename = (new File(filepath)).getName();
      filename = filename.substring(0, filename.length() - 4);

      String msg = "";
      msg = "Rendering " + filename + ".png";

      pHandle =
          ProgressHandleFactory.createHandle(
              msg,
              new Cancellable() {
                @Override
                public boolean cancel() {
                  pHandle.setDisplayName("Cancelling render ....");
                  Thread[] threads = new Thread[Thread.activeCount()];
                  Thread.enumerate(threads);
                  for (Thread thread : threads) {
                    if (MySunflowRenderer.isSunflowRenderingThread(thread)) {
                      thread.stop();
                    }
                  }
                  renderingThread.interrupt();
                  boolean deleted = false;
                  while (!deleted) {
                    deleted = (new File(filepath)).delete();
                  }
                  stillRendering = false;
                  pHandle.setDisplayName("Render cancelled.");
                  return true;
                }
              });
      renderingThread.start();
    } else {
      DialogDisplayer.getDefault()
          .notify(
              new NotifyDescriptor.Confirmation(
                  "Please wait until the current rendering process finished.",
                  "Still Rendering",
                  NotifyDescriptor.DEFAULT_OPTION,
                  NotifyDescriptor.PLAIN_MESSAGE));
    }
  }
    public ComputeNN(TaskListener tlistener) {

      super(tlistener, ProgressHandleFactory.createHandle("Computing NN..."));
    }
예제 #20
0
    @Override
    protected Object doInBackground() throws Exception {

      logger.log(Level.INFO, "Starting background ingest file processor");
      logger.log(Level.INFO, PlatformUtil.getAllMemUsageInfo());

      stats.start();

      // notify main thread modules started
      for (IngestModuleAbstractFile s : abstractFileModules) {
        IngestManager.fireModuleEvent(IngestModuleEvent.STARTED.toString(), s.getName());
      }

      final String displayName = "File Ingest";
      progress =
          ProgressHandleFactory.createHandle(
              displayName,
              new Cancellable() {
                @Override
                public boolean cancel() {
                  logger.log(Level.INFO, "Filed ingest cancelled by user.");
                  if (progress != null) {
                    progress.setDisplayName(displayName + " (Cancelling...)");
                  }
                  return IngestAbstractFileProcessor.this.cancel(true);
                }
              });

      final IngestScheduler.FileScheduler fileScheduler = scheduler.getFileScheduler();

      // initialize the progress bar
      progress.start();
      progress.switchToIndeterminate();
      // set initial totals and processed (to be updated as we process or new files are scheduled)
      int totalEnqueuedFiles = fileScheduler.getFilesEnqueuedEst();
      progress.switchToDeterminate(totalEnqueuedFiles);
      int processedFiles = 0;
      // process AbstractFiles queue
      while (fileScheduler.hasNext()) {
        final ProcessTask fileTask = fileScheduler.next();
        final PipelineContext<IngestModuleAbstractFile> filepipelineContext = fileTask.context;
        final ScheduledTask<IngestModuleAbstractFile> fileIngestTask =
            filepipelineContext.getScheduledTask();
        final AbstractFile fileToProcess = fileTask.file;

        // clear return values from modules for last file
        synchronized (abstractFileModulesRetValues) {
          abstractFileModulesRetValues.clear();
        }

        // logger.log(Level.INFO, "IngestManager: Processing: {0}", fileToProcess.getName());

        for (IngestModuleAbstractFile module : fileIngestTask.getModules()) {
          // process the file with every file module
          if (isCancelled()) {
            logger.log(Level.INFO, "Terminating file ingest due to cancellation.");
            return null;
          }
          progress.progress(
              fileToProcess.getName() + " (" + module.getName() + ")", processedFiles);

          try {
            stats.logFileModuleStartProcess(module);
            IngestModuleAbstractFile.ProcessResult result =
                module.process(filepipelineContext, fileToProcess);
            stats.logFileModuleEndProcess(module);

            // store the result for subsequent modules for this file
            synchronized (abstractFileModulesRetValues) {
              abstractFileModulesRetValues.put(module.getName(), result);
            }

          } catch (Exception e) {
            logger.log(
                Level.SEVERE, "Error: unexpected exception from module: " + module.getName(), e);
            stats.addError(module);
          } catch (OutOfMemoryError e) {
            logger.log(Level.SEVERE, "Error: out of memory from module: " + module.getName(), e);
            stats.addError(module);
          }
        } // end for every module

        // free the internal file resource after done with every module
        fileToProcess.close();

        int newTotalEnqueuedFiles = fileScheduler.getFilesEnqueuedEst();
        if (newTotalEnqueuedFiles > totalEnqueuedFiles) {
          // update if new enqueued
          totalEnqueuedFiles = newTotalEnqueuedFiles + 1; // + processedFiles + 1;
          // processedFiles = 0;
          // reset
          progress.switchToIndeterminate();
          progress.switchToDeterminate(totalEnqueuedFiles);
        }
        if (processedFiles
            < totalEnqueuedFiles) { // fix for now to handle the same datasource Content enqueued
                                    // twice
          ++processedFiles;
        }
        // --totalEnqueuedFiles;

      } // end of for every AbstractFile
      logger.log(Level.INFO, "IngestManager: Finished processing files");
      return null;
    }
예제 #21
0
  @Override
  public void actionPerformed(ActionEvent e) {
    JFileChooser fc = new JFileChooser();
    fc.setFileFilter(ImportAction.getFileFilter());
    fc.setCurrentDirectory(
        new File(Settings.get().get(Settings.DIRECTORY, Settings.DIRECTORY_DEFAULT)));
    fc.setMultiSelectionEnabled(true);

    if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
      for (final File file : fc.getSelectedFiles()) {
        File dir = file;
        if (!dir.isDirectory()) {
          dir = dir.getParentFile();
        }

        Settings.get().put(Settings.DIRECTORY, dir.getAbsolutePath());
        try {
          final FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.READ);
          final ProgressHandle handle =
              ProgressHandleFactory.createHandle("Opening file " + file.getName());
          handle.start(WORKUNITS);
          final long startTime = System.currentTimeMillis();
          final long start = channel.size();
          ParseMonitor monitor =
              new ParseMonitor() {
                @Override
                public void updateProgress() {
                  try {
                    int prog = (int) (WORKUNITS * (double) channel.position() / (double) start);
                    handle.progress(prog);
                  } catch (IOException ex) {
                  }
                }

                @Override
                public void setState(String state) {
                  updateProgress();
                  handle.progress(state);
                }
              };
          final GraphParser parser;
          final OutlineTopComponent component = OutlineTopComponent.findInstance();
          if (file.getName().endsWith(".xml")) {
            parser = new Parser(channel, monitor, null);
          } else if (file.getName().endsWith(".bgv")) {
            parser = new BinaryParser(channel, monitor, component.getDocument(), null);
          } else {
            parser = null;
          }
          RequestProcessor.getDefault()
              .post(
                  new Runnable() {
                    @Override
                    public void run() {
                      try {
                        final GraphDocument document = parser.parse();
                        if (document != null) {
                          SwingUtilities.invokeLater(
                              new Runnable() {
                                @Override
                                public void run() {
                                  component.requestActive();
                                  component.getDocument().addGraphDocument(document);
                                }
                              });
                        }
                      } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                      }
                      handle.finish();
                      long stop = System.currentTimeMillis();
                      Logger.getLogger(getClass().getName())
                          .log(
                              Level.INFO,
                              "Loaded in "
                                  + file
                                  + " in "
                                  + ((stop - startTime) / 1000.0)
                                  + " seconds");
                    }
                  });
        } catch (FileNotFoundException ex) {
          Exceptions.printStackTrace(ex);
        } catch (IOException ex) {
          Exceptions.printStackTrace(ex);
        }
      }
    }
  }