Example #1
1
  public void doRFileEvaluate(final IScope scope, final IContainer param) {
    int size = param.length(scope);
    // if ( size == 0 ) { throw GamaRuntimeException.error("Missing Parameter Exception", scope); }

    final String RFile = getPath();
    try {
      // Call R
      RCaller caller = new RCaller();

      String RPath = GamaPreferences.LIB_R.value(scope).getPath();
      caller.setRscriptExecutable(RPath);

      double[] vectorParam = new double[param.length(scope)];

      int k = 0;
      for (Object o : param.iterable(scope)) {
        vectorParam[k++] = Cast.asFloat(scope, o);
      }

      RCode c = new RCode();
      // Adding the parameters
      c.addDoubleArray("vectorParam", vectorParam);

      // Adding the codes in file
      List<String> R_statements = new ArrayList<String>();

      // tmthai.begin----------------------------------------------------------------------------
      String fullPath = FileUtils.constructAbsoluteFilePath(scope, RFile, true);
      if (DEBUG) {
        GuiUtils.debug("Stats.R_compute_param.RScript:" + RPath);
        GuiUtils.debug("Stats.R_compute_param.Param:" + vectorParam.toString());
        GuiUtils.debug("Stats.R_compute_param.RFile:" + RFile);
        GuiUtils.debug("Stats.R_compute_param.fullPath:" + fullPath);
      }

      // FileReader fr = new FileReader(RFile);
      FileReader fr = new FileReader(fullPath);
      // tmthai.end----------------------------------------------------------------------------

      BufferedReader br = new BufferedReader(fr);
      String statement;

      while ((statement = br.readLine()) != null) {
        c.addRCode(statement);
        R_statements.add(statement);
        // java.lang.System.out.println(statement);
      }
      br.close();
      fr.close();
      caller.setRCode(c);

      GamaMap<String, IList> result = GamaMapFactory.create(Types.STRING, Types.LIST);

      String var = computeVariable(R_statements.get(R_statements.size() - 1).toString());
      caller.runAndReturnResult(var);

      // DEBUG:
      // java.lang.System.out.println("Name: '" + R_statements.length(scope) + "'");
      if (DEBUG) {
        GuiUtils.debug("Stats.R_compute_param.R_statements.length: '" + R_statements.size() + "'");
      }

      for (String name : caller.getParser().getNames()) {
        String[] results = null;
        results = caller.getParser().getAsStringArray(name);
        // java.lang.System.out.println("Name: '" + name + "'");
        if (DEBUG) {
          GuiUtils.debug(
              "Stats.R_compute_param.caller.Name: '"
                  + name
                  + "' length: "
                  + results.length
                  + " - Value: "
                  + results.toString());
        }

        result.put(name, GamaListFactory.create(scope, Types.NO_TYPE, results));
      }

      if (DEBUG) {
        GuiUtils.debug("Stats.R_compute_param.return:" + result.serialize(false));
      }

      setBuffer(result);

    } catch (Exception ex) {

      throw GamaRuntimeException.error("RCallerExecutionException " + ex.getMessage(), scope);
    }
  }
Example #2
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.ecf.core.IContainerListener#handleEvent(org.eclipse.ecf
  * .core.events.IContainerEvent)
  */
 public void handleEvent(IContainerEvent event) {
   final IContainerManager containerManager =
       (IContainerManager) ContainerFactory.getDefault();
   if (containerManager == null) return;
   IContainer container = containerManager.getContainer(event.getLocalContainerID());
   if (container == null) return;
   if (event instanceof IContainerConnectedEvent
       || event instanceof IContainerDisconnectedEvent) {
     // connected
     IChannelContainerAdapter cca =
         (IChannelContainerAdapter) container.getAdapter(IChannelContainerAdapter.class);
     if (cca == null) return;
     ID containerID = container.getID();
     if (event instanceof IContainerConnectedEvent) {
       try {
         if (!TeamSynchronization.contains(containerID)) {
           TeamSynchronization.put(containerID, new WorkbenchAwareRemoteShare(cca));
         }
       } catch (ECFException e) {
         TeamSynchronization.log(
             "RemoteShare could not be added or created", e); // $NON-NLS-1$
       }
     } else if (event instanceof IContainerDisconnectedEvent) {
       // disconnected
       TeamSynchronization.removeShare(containerID);
     }
   } else if (event instanceof IContainerDisposeEvent) {
     containerManager.removeListener(containerManagerListener);
     container.removeListener(containerListener);
   }
 }
Example #3
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
   */
  public void stop(final BundleContext context) throws Exception {
    // TODO-mkuppe here we should do something like a deregisterAll(), but see ungetService(...);
    if (serviceRegistration != null && serviceFactory.isActive()) {
      ServiceReference reference = serviceRegistration.getReference();
      IDiscoveryLocator aLocator = (IDiscoveryLocator) context.getService(reference);

      serviceRegistration.unregister();

      IContainer container = (IContainer) aLocator.getAdapter(IContainer.class);
      container.disconnect();
      container.dispose();

      serviceRegistration = null;
    }
    plugin = null;
    bundleContext = null;
    if (advertiserSt != null) {
      advertiserSt.close();
      advertiserSt = null;
    }
    if (locatorSt != null) {
      locatorSt.close();
      locatorSt = null;
    }
  }
Example #4
0
  /**
   * Final check before the actual refactoring
   *
   * @return status
   * @throws OperationCanceledException
   */
  public RefactoringStatus checkFinalConditions() throws OperationCanceledException {
    RefactoringStatus status = new RefactoringStatus();
    IContainer destination = fProcessor.getDestination();
    IProject sourceProject = fProcessor.getSourceSelection()[0].getProject();
    IProject destinationProject = destination.getProject();
    if (sourceProject != destinationProject)
      status.merge(MoveUtils.checkMove(phpFiles, sourceProject, destination));

    // Checks if one of the resources already exists with the same name in
    // the destination
    IPath dest = fProcessor.getDestination().getFullPath();
    IResource[] sourceResources = fProcessor.getSourceSelection();

    for (IResource element : sourceResources) {
      String newFilePath = dest.toOSString() + File.separatorChar + element.getName();
      IResource resource =
          ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(newFilePath));
      if (resource != null && resource.exists()) {
        status.merge(
            RefactoringStatus.createFatalErrorStatus(
                NLS.bind(
                    PhpRefactoringCoreMessages.getString("MoveDelegate.6"),
                    element.getName(),
                    dest.toOSString()))); // $NON-NLS-1$
      }
    }
    return status;
  }
  /** Ensures that controls are correctly set. */
  private void dialogChanged() {
    IResource resource =
        ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getContainerName()));
    if (resource == null) {
      updateStatus("File container must be specified");
      return;
    }
    IContainer container = (IContainer) resource;
    String fileName = getFileName();
    String author = getAuthor();
    String titleName = getModelName();

    final IFile modelfile = container.getFile(new Path("models/" + fileName));
    final IFile htmlfile = container.getFile(new Path("doc/" + titleName + ".html"));

    if (getContainerName().length() == 0) {
      updateStatus("File container must be specified");
      return;
    }
    if ((resource.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
      updateStatus("File container must exist");
      return;
    }
    if (!resource.isAccessible()) {
      updateStatus("Project must be writable");
      return;
    }
    if (fileName.length() == 0) {
      updateStatus("File name must be specified");
      return;
    }
    if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
      updateStatus("File name must be valid");
      return;
    }
    if (!fileName.endsWith(".gaml")) {
      updateStatus("File extension must be \".gaml\"");
      return;
    }
    if (author.length() == 0) {
      updateStatus("Author name must be specified");
      return;
    }
    if (modelfile.exists()) {
      updateStatus("File already exists");
      return;
    }
    if (htmlfile.exists()) {
      updateStatus("Model name already defined");
      return;
    }

    if (titleName.length() == 0) {
      updateStatus("Model name must be specified");
      return;
    }
    updateStatus(null);
  }
 private void updateReadOnlyPackageFragmentsForCopy(
     IContainer sourceFolder, PackageFragmentRoot root, String[] newFragName) {
   IContainer parentFolder = (IContainer) root.resource();
   for (int i = 0, length = newFragName.length; i < length; i++) {
     String subFolderName = newFragName[i];
     parentFolder = parentFolder.getFolder(new Path(subFolderName));
     sourceFolder = sourceFolder.getFolder(new Path(subFolderName));
     if (sourceFolder.exists() && Util.isReadOnly(sourceFolder)) {
       Util.setReadOnly(parentFolder, true);
     }
   }
 }
Example #7
0
    /*
     * @see org.gamegineer.table.core.AbstractContainerLayout#getComponentOffsetAt(org.gamegineer.table.core.IContainer, int)
     */
    @Override
    protected Dimension getComponentOffsetAt(final IContainer container, final int index) {
      assertArgumentLegal(
          index >= 0,
          "index",
          NonNlsMessages
              .ContainerLayouts_NullContainerLayout_getComponentOffsetAt_index_negative); //$NON-NLS-1$

      final Point containerOrigin = container.getOrigin();
      final Point componentLocation = container.getComponent(index).getLocation();
      return new Dimension(
          componentLocation.x - containerOrigin.x, componentLocation.y - containerOrigin.y);
    }
 private void copyFile(final String from, final IContainer container, final String fileName)
     throws CoreException {
   IPath path = new Path(fileName);
   IFile file = container.getFile(path);
   if (!file.exists()) {
     file.create(getFileStream(from), true, null);
   }
 }
 private void updateReadOnlyPackageFragmentsForMove(
     IContainer sourceFolder,
     PackageFragmentRoot root,
     String[] newFragName,
     boolean sourceFolderIsReadOnly) {
   IContainer parentFolder = (IContainer) root.resource();
   for (int i = 0, length = newFragName.length; i < length; i++) {
     String subFolderName = newFragName[i];
     parentFolder = parentFolder.getFolder(new Path(subFolderName));
     sourceFolder = sourceFolder.getFolder(new Path(subFolderName));
     if ((sourceFolder.exists() && Util.isReadOnly(sourceFolder))
         || (i == length - 1 && sourceFolderIsReadOnly)) {
       Util.setReadOnly(parentFolder, true);
       // the source folder will be deleted anyway (move operation)
       Util.setReadOnly(sourceFolder, false);
     }
   }
 }
 public void createWebInf() throws CoreException {
   if (webInfDir == null) {
     IPath webInfPath = new Path(WEB_INF_PATH);
     webInfDir = rootFolder.getFolder(webInfPath);
     if (!webInfDir.exists()) {
       webInfDir.create(true, false, null);
       refreshWebInf();
     }
   }
 }
 private void handleContainerSelection(final Object object) {
   IContainer container = (IContainer) object;
   try {
     if (container.isAccessible()) {
       IResource[] resources = container.members();
       for (int i = 0; i < resources.length; i++) {
         IResource resource = resources[i];
         String resourceName = resource.getName();
         boolean hasWarProductExtension =
             resourceName.endsWith("." + WARProductConstants.FILE_EXTENSION); // $NON-NLS-1$
         if (resource instanceof IFile && hasWarProductExtension) {
           IFile file = (IFile) resource;
           loadProductFromFile(file);
         }
       }
     }
   } catch (final CoreException e) {
     MessageDialog.openError(getShell(), Messages.LoadWARProductError, e.getMessage());
   }
 }
 /** Tests if the current workbench selection is a suitable container to use. */
 private void initialize() {
   if (selection != null
       && selection.isEmpty() == false
       && selection instanceof IStructuredSelection) {
     IStructuredSelection ssel = (IStructuredSelection) selection;
     if (ssel.size() > 1) {
       return;
     }
     Object obj = ssel.getFirstElement();
     if (obj instanceof IResource) {
       IContainer container;
       if (obj instanceof IContainer) {
         container = (IContainer) obj;
       } else {
         container = ((IResource) obj).getParent();
       }
       containerText.setText(container.getFullPath().toString());
     }
   }
   fileText.setText("new.gaml");
 }
 /**
  * Creates any destination package fragment(s) which do not exists yet. Return true if a read-only
  * package fragment has been found among package fragments, false otherwise
  */
 private boolean createNeededPackageFragments(
     IContainer sourceFolder, PackageFragmentRoot root, String[] newFragName, boolean moveFolder)
     throws JavaModelException {
   boolean containsReadOnlyPackageFragment = false;
   IContainer parentFolder = (IContainer) root.resource();
   JavaElementDelta projectDelta = null;
   String[] sideEffectPackageName = null;
   char[][] inclusionPatterns = root.fullInclusionPatternChars();
   char[][] exclusionPatterns = root.fullExclusionPatternChars();
   for (int i = 0; i < newFragName.length; i++) {
     String subFolderName = newFragName[i];
     sideEffectPackageName = Util.arrayConcat(sideEffectPackageName, subFolderName);
     IResource subFolder = parentFolder.findMember(subFolderName);
     if (subFolder == null) {
       // create deepest folder only if not a move (folder will be moved in
       // processPackageFragmentResource)
       if (!(moveFolder && i == newFragName.length - 1)) {
         createFolder(parentFolder, subFolderName, this.force);
       }
       parentFolder = parentFolder.getFolder(new Path(subFolderName));
       sourceFolder = sourceFolder.getFolder(new Path(subFolderName));
       if (Util.isReadOnly(sourceFolder)) {
         containsReadOnlyPackageFragment = true;
       }
       IPackageFragment sideEffectPackage = root.getPackageFragment(sideEffectPackageName);
       if (i < newFragName.length - 1 // all but the last one are side effect packages
           && !Util.isExcluded(parentFolder, inclusionPatterns, exclusionPatterns)) {
         if (projectDelta == null) {
           projectDelta = getDeltaFor(root.getJavaProject());
         }
         projectDelta.added(sideEffectPackage);
       }
       this.createdElements.add(sideEffectPackage);
     } else {
       parentFolder = (IContainer) subFolder;
     }
   }
   return containsReadOnlyPackageFragment;
 }
Example #14
0
 /**
  * The worker method. It will find the container, create the file if missing or just replace its
  * contents, and open the editor on the newly created file.
  */
 private void doFinish(String containerName, String fileName, IProgressMonitor monitor)
     throws CoreException {
   // create a sample file
   monitor.beginTask("Creating " + fileName, 2);
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   IResource resource = root.findMember(new Path(containerName));
   if (!resource.exists() || !(resource instanceof IContainer)) {
     throwCoreException("Container \"" + containerName + "\" does not exist.");
   }
   IContainer container = (IContainer) resource;
   final IFile file = container.getFile(new Path(fileName));
   try {
     InputStream stream = openContentStream();
     if (file.exists()) {
       file.setContents(stream, true, true, monitor);
     } else {
       file.create(stream, true, monitor);
     }
     stream.close();
   } catch (IOException e) {
   }
   monitor.worked(1);
   monitor.setTaskName("Opening file for editing...");
   getShell()
       .getDisplay()
       .asyncExec(
           new Runnable() {
             public void run() {
               IWorkbenchPage page =
                   PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
               try {
                 IDE.openEditor(page, file, true);
               } catch (PartInitException e) {
               }
             }
           });
   monitor.worked(1);
 }
 protected void removeClassFile(IPath typePath, IContainer outputFolder) throws CoreException {
   if (typePath.lastSegment().indexOf('$') == -1) { // is not a nested type
     this.newState.removeQualifiedTypeName(typePath.toString());
     // add dependents even when the type thinks it does not exist to be on the safe side
     if (JavaBuilder.DEBUG) System.out.println("Found removed type " + typePath); // $NON-NLS-1$
     addDependentsOf(
         typePath,
         true); // when member types are removed, their enclosing type is structurally changed
   }
   IFile classFile =
       outputFolder.getFile(typePath.addFileExtension(SuffixConstants.EXTENSION_class));
   if (classFile.exists()) {
     if (JavaBuilder.DEBUG)
       System.out.println("Deleting class file of removed type " + typePath); // $NON-NLS-1$
     classFile.delete(IResource.FORCE, null);
   }
 }
Example #16
0
  @Override
  public void dispose() {
    super.dispose();

    if (bMinus != null) {
      bMinus.dispose();
      bMinus = null;
    }
    if (bPlus != null) {
      bPlus.dispose();
      bPlus = null;
    }
    if (fNumber != null) {
      fNumber.removeListener(numberChangeListener);
      fNumber.dispose();
      fNumber = null;
    }
    if (panel != null) {
      panel.dispose();
      panel = null;
    }
  }
  /**
   * Copies/moves a compilation unit with the name <code>newCUName</code> to the destination
   * package.<br>
   * The package statement in the compilation unit is updated if necessary. The main type of the
   * compilation unit is renamed if necessary.
   *
   * @exception JavaModelException if the operation is unable to complete
   */
  private void processCompilationUnitResource(ICompilationUnit source, PackageFragment dest)
      throws JavaModelException {
    String newCUName = getNewNameFor(source);
    String destName = (newCUName != null) ? newCUName : source.getElementName();
    TextEdit edit = updateContent(source, dest, newCUName); // null if unchanged

    // TODO (frederic) remove when bug 67606 will be fixed (bug 67823)
    // store encoding (fix bug 66898)
    IFile sourceResource = (IFile) source.getResource();
    String sourceEncoding = null;
    try {
      sourceEncoding = sourceResource.getCharset(false);
    } catch (CoreException ce) {
      // no problem, use default encoding
    }
    // end todo
    // copy resource
    IContainer destFolder = (IContainer) dest.getResource(); // can be an IFolder or an IProject
    IFile destFile = destFolder.getFile(new Path(destName));
    org.eclipse.jdt.internal.core.CompilationUnit destCU =
        new org.eclipse.jdt.internal.core.CompilationUnit(
            dest, destName, DefaultWorkingCopyOwner.PRIMARY);
    if (!destFile.equals(sourceResource)) {
      try {
        if (!destCU.isWorkingCopy()) {
          if (destFile.exists()) {
            if (this.force) {
              // we can remove it
              deleteResource(destFile, IResource.KEEP_HISTORY);
              destCU.close(); // ensure the in-memory buffer for the dest CU is closed
            } else {
              // abort
              throw new JavaModelException(
                  new JavaModelStatus(
                      IJavaModelStatusConstants.NAME_COLLISION,
                      Messages.bind(
                          Messages.status_nameCollision, destFile.getFullPath().toString())));
            }
          }
          int flags = this.force ? IResource.FORCE : IResource.NONE;
          if (isMove()) {
            flags |= IResource.KEEP_HISTORY;
            sourceResource.move(destFile.getFullPath(), flags, getSubProgressMonitor(1));
          } else {
            if (edit != null) flags |= IResource.KEEP_HISTORY;
            sourceResource.copy(destFile.getFullPath(), flags, getSubProgressMonitor(1));
          }
          setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
        } else {
          destCU.getBuffer().setContents(source.getBuffer().getContents());
        }
      } catch (JavaModelException e) {
        throw e;
      } catch (CoreException e) {
        throw new JavaModelException(e);
      }

      // update new resource content
      if (edit != null) {
        boolean wasReadOnly = destFile.isReadOnly();
        try {
          saveContent(dest, destName, edit, sourceEncoding, destFile);
        } catch (CoreException e) {
          if (e instanceof JavaModelException) throw (JavaModelException) e;
          throw new JavaModelException(e);
        } finally {
          Util.setReadOnly(destFile, wasReadOnly);
        }
      }

      // register the correct change deltas
      prepareDeltas(source, destCU, isMove());
      if (newCUName != null) {
        // the main type has been renamed
        String oldName = Util.getNameWithoutJavaLikeExtension(source.getElementName());
        String newName = Util.getNameWithoutJavaLikeExtension(newCUName);
        prepareDeltas(source.getType(oldName), destCU.getType(newName), isMove());
      }
    } else {
      if (!this.force) {
        throw new JavaModelException(
            new JavaModelStatus(
                IJavaModelStatusConstants.NAME_COLLISION,
                Messages.bind(Messages.status_nameCollision, destFile.getFullPath().toString())));
      }
      // update new resource content
      // in case we do a saveas on the same resource we have to simply update the contents
      // see http://dev.eclipse.org/bugs/show_bug.cgi?id=9351
      if (edit != null) {
        saveContent(dest, destName, edit, sourceEncoding, destFile);
      }
    }
  }
Example #18
0
  private static void computeXaXsTransitions(
      final IScope scope,
      final IAgentFilter filter,
      final GamaMatrix<Double> fuzzytransitions,
      final Double distance,
      final IContainer<Integer, IAgent> agents,
      final int nbCat,
      final Map<List<Integer>, Map<Double, Double>> XaPerTransition,
      final Map<List<Integer>, Map<Double, Double>> XsPerTransition,
      final Set<Double> Xvals) {

    IList<ILocation> locs = GamaListFactory.create(Types.POINT);
    for (IAgent ag : agents.iterable(scope)) {
      locs.add(ag.getLocation());
    }
    ILocation centralLoc = (ILocation) Stats.getMean(scope, locs);
    if (filter != null) {
      IAgent centralAg = scope.getTopology().getAgentClosestTo(scope, centralLoc, filter);
      List<IAgent> neighbors =
          distance == 0
              ? new ArrayList<IAgent>()
              : new ArrayList<IAgent>(
                  scope.getTopology().getNeighborsOf(scope, centralAg, distance, filter));
      double sizeNorm = FastMath.sqrt(centralAg.getEnvelope().getArea());

      Map<IAgent, Double> distancesCoeff = new TOrderedHashMap<IAgent, Double>();
      distancesCoeff.put(centralAg, 1.0);
      for (IAgent ag : neighbors) {
        double euclidDist = centralAg.getLocation().euclidianDistanceTo(ag.getLocation());
        double dist = 1 / (1.0 + euclidDist / sizeNorm);
        distancesCoeff.put(ag, dist);
      }

      for (int i = 0; i < nbCat; i++) {
        for (int j = 0; j < nbCat; j++) {
          for (int k = 0; k < nbCat; k++) {
            List<Integer> ca = new ArrayList();
            ca.add(i);
            ca.add(j);
            ca.add(k);
            double xa = 0;
            double xs = 0;
            for (IAgent ag : distancesCoeff.keySet()) {
              double dist = distancesCoeff.get(ag);
              double xatmp = fuzzyTransition(scope, fuzzytransitions, nbCat, i, k, i, j) * dist;
              double xstmp = fuzzyTransition(scope, fuzzytransitions, nbCat, i, j, i, k) * dist;
              if (xatmp > xa) {
                xa = xatmp;
              }
              if (xstmp > xs) {
                xs = xstmp;
              }
            }
            if (xa > 0) {

              Map<Double, Double> mapxa = XaPerTransition.get(ca);
              if (mapxa == null) {
                mapxa = new TOrderedHashMap<Double, Double>();
                mapxa.put(xa, 1.0);
                XaPerTransition.put(ca, mapxa);
              } else {
                if (mapxa.containsKey(xa)) {
                  mapxa.put(xa, mapxa.get(xa) + 1.0);
                } else {
                  mapxa.put(xa, 1.0);
                }
              }
              Xvals.add(xa);
            }
            if (xs > 0) {
              Map<Double, Double> mapxs = XsPerTransition.get(ca);
              if (mapxs == null) {
                mapxs = new TOrderedHashMap<Double, Double>();
                mapxs.put(xs, 1.0);
                XsPerTransition.put(ca, mapxs);
              } else {
                if (mapxs.containsKey(xa)) {
                  mapxs.put(xs, mapxs.get(xs) + 1.0);
                } else {
                  mapxs.put(xs, 1.0);
                }
              }
              Xvals.add(xs);
            }
          }
        }
      }
    }
  }
  @Test
  @Ignore
  public void testSeekKeyFrameCheckIndex() {
    Global.setFFmpegLoggingLevel(52);
    IContainer container = IContainer.make();

    int retval = -1;
    // final String
    // INPUT_FILE="fixtures/"+this.getClass().getName()+"-testSeekKeyFrameCheckIndex.ogg";
    //    final int NUM_STREAMS=2;
    //    final ICodec.ID VID_CODEC=ICodec.ID.CODEC_ID_THEORA;
    //    final String INPUT_FILE="fixtures/testfile_h264_mp4a_tmcd.mov";
    //    final int NUM_STREAMS=3;
    //    final ICodec.ID VID_CODEC=ICodec.ID.CODEC_ID_H264;
    final String INPUT_FILE = "fixtures/testfile.flv";
    final int NUM_STREAMS = 2;
    final ICodec.ID VID_CODEC = ICodec.ID.CODEC_ID_FLV1;

    retval = container.open(INPUT_FILE, IContainer.Type.READ, null);
    assertTrue("could not open file", retval >= 0);

    // First, let's get all the key frames
    final int numStreams = container.getNumStreams();
    assertEquals(NUM_STREAMS, numStreams);

    final int vidIndex = 0;
    final IStream vidStream = container.getStream(vidIndex);
    final IStreamCoder vidCoder = vidStream.getStreamCoder();
    assertEquals(VID_CODEC, vidCoder.getCodecID());
    vidCoder.delete();
    vidStream.delete();

    // now, loop through the entire file and record the index of EACH
    // video key frame
    final IPacket packet = IPacket.make();
    final ArrayList<Long> offsets = new ArrayList<Long>(1024);
    final ArrayList<Long> timestamps = new ArrayList<Long>(1024);
    long numPackets = 0;
    while (container.readNextPacket(packet) >= 0) {
      //      log.debug("Next: {}", container.getByteOffset());
      if (packet.isComplete()) {
        if (packet.getStreamIndex() != vidIndex) continue;
        if (!packet.isKey()) continue;
        //        log.debug("Packet: {}", packet);
        if (numPackets < 5) {
          log.debug("First Packet: {}", packet);
        }
        ++numPackets;
        assertTrue(packet.getPosition() >= 0);
        offsets.add(packet.getPosition());
        timestamps.add(packet.getDts());
      }
    }
    log.debug(
        "Num Index Entries; container: {}; test: {}",
        vidStream.getNumIndexEntries(),
        offsets.size());
    //    retval = container.close();
    //    assertTrue("got negative retval: " + IError.errorNumberToType(retval), retval >= 0);
    //    retval = container.open(INPUT_FILE, IContainer.Type.READ, null);
    //    assertTrue("got negative retval: " + IError.errorNumberToType(retval), retval >= 0);

    // move the seek head backwards
    retval =
        container.seekKeyFrame(
            -1, Long.MIN_VALUE, 0, Long.MAX_VALUE, IContainer.SEEK_FLAG_BACKWARDS);
    assertTrue("got negative retval: " + IError.errorNumberToType(retval), retval >= 0);

    // now let's walk through that index and ensure we can seek to each key frame.
    for (int i = 0; i < offsets.size(); i++) {
      long index = offsets.get(i);
      retval =
          container.seekKeyFrame(
              vidIndex,
              index,
              index,
              index,
              //          0);
              IContainer.SEEK_FLAG_BYTE);
      assertTrue("got negative retval: " + IError.errorNumberToType(retval), retval >= 0);
      retval = container.readNextPacket(packet);
      log.debug("{}", packet);
      assertTrue("got negative retval: " + IError.errorNumberToType(retval), retval >= 0);
      assertTrue(packet.isComplete());
      //      assertEquals(offsets.get(i).longValue(), packet.getPosition());
      //      assertEquals(timestamps.get(i).longValue(), packet.getDts());
      assertTrue(packet.isKey());
    }
    container.close();
  }
  protected void cleanOutputFolders(boolean copyBack) throws CoreException {
    boolean deleteAll =
        JavaCore.CLEAN.equals(
            this.javaBuilder.javaProject.getOption(
                JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, true));
    if (deleteAll) {
      if (this.javaBuilder.participants != null)
        for (int i = 0, l = this.javaBuilder.participants.length; i < l; i++)
          this.javaBuilder.participants[i].cleanStarting(this.javaBuilder.javaProject);

      ArrayList visited = new ArrayList(this.sourceLocations.length);
      for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
        this.notifier.subTask(
            Messages.bind(
                Messages.build_cleaningOutput, this.javaBuilder.currentProject.getName()));
        ClasspathMultiDirectory sourceLocation = this.sourceLocations[i];
        if (sourceLocation.hasIndependentOutputFolder) {
          IContainer outputFolder = sourceLocation.binaryFolder;
          if (!visited.contains(outputFolder)) {
            visited.add(outputFolder);
            IResource[] members = outputFolder.members();
            for (int j = 0, m = members.length; j < m; j++) {
              IResource member = members[j];
              if (!member.isDerived()) {
                member.accept(
                    new IResourceVisitor() {
                      public boolean visit(IResource resource) throws CoreException {
                        resource.setDerived(true, null);
                        return resource.getType() != IResource.FILE;
                      }
                    });
              }
              member.delete(IResource.FORCE, null);
            }
          }
          this.notifier.checkCancel();
          if (copyBack) copyExtraResourcesBack(sourceLocation, true);
        } else {
          boolean isOutputFolder = sourceLocation.sourceFolder.equals(sourceLocation.binaryFolder);
          final char[][] exclusionPatterns =
              isOutputFolder
                  ? sourceLocation.exclusionPatterns
                  : null; // ignore exclusionPatterns if output folder == another source folder...
                          // not this one
          final char[][] inclusionPatterns =
              isOutputFolder
                  ? sourceLocation.inclusionPatterns
                  : null; // ignore inclusionPatterns if output folder == another source folder...
                          // not this one
          sourceLocation.binaryFolder.accept(
              new IResourceProxyVisitor() {
                public boolean visit(IResourceProxy proxy) throws CoreException {
                  if (proxy.getType() == IResource.FILE) {
                    if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(
                        proxy.getName())) {
                      IResource resource = proxy.requestResource();
                      if (exclusionPatterns != null || inclusionPatterns != null)
                        if (Util.isExcluded(
                            resource.getFullPath(), inclusionPatterns, exclusionPatterns, false))
                          return false;
                      if (!resource.isDerived()) resource.setDerived(true, null);
                      resource.delete(IResource.FORCE, null);
                    }
                    return false;
                  }
                  if (exclusionPatterns != null
                      && inclusionPatterns
                          == null) // must walk children if inclusionPatterns != null
                  if (Util.isExcluded(proxy.requestFullPath(), null, exclusionPatterns, true))
                      return false;
                  BatchImageBuilder.this.notifier.checkCancel();
                  return true;
                }
              },
              IResource.NONE);
          this.notifier.checkCancel();
        }
        this.notifier.checkCancel();
      }
    } else if (copyBack) {
      for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
        ClasspathMultiDirectory sourceLocation = this.sourceLocations[i];
        if (sourceLocation.hasIndependentOutputFolder)
          copyExtraResourcesBack(sourceLocation, false);
        this.notifier.checkCancel();
      }
    }
    // GROOVY start
    LanguageSupportFactory.getEventHandler()
        .handle(this.javaBuilder.javaProject, "cleanOutputFolders");
    // GROOVY end
  }
Example #21
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.ecf.core.IContainerManagerListener#containerAdded(org
  * .eclipse.ecf.core.IContainer)
  */
 public void containerAdded(IContainer container) {
   IChannelContainerAdapter cca =
       (IChannelContainerAdapter) container.getAdapter(IChannelContainerAdapter.class);
   if (cca == null) return;
   container.addListener(containerListener);
 }
Example #22
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.ecf.core.IContainerManagerListener#containerRemoved(org
  * .eclipse.ecf.core.IContainer)
  */
 public void containerRemoved(IContainer container) {
   container.removeListener(containerListener);
 }