Example #1
0
 /**
  * Returns the file representing the Git repository directory for the given file path or any of
  * its parent in the filesystem. If the file doesn't exits, is not a Git repository or an error
  * occurred while transforming the given path into a store <code>null</code> is returned.
  *
  * @param path expected format /file/{Workspace}/{projectName}[/{path}]
  * @return the .git folder if found or <code>null</code> the give path cannot be resolved to a
  *     file or it's not under control of a git repository
  * @throws CoreException
  */
 public static File getGitDir(IPath path) throws CoreException {
   Map<IPath, File> gitDirs = GitUtils.getGitDirs(path, Traverse.GO_UP);
   if (gitDirs == null) return null;
   Collection<File> values = gitDirs.values();
   if (values.isEmpty()) return null;
   return values.toArray(new File[] {})[0];
 }
Example #2
0
  private static void copyCollection(
      Object target,
      String[] effectiveProperties,
      String[] ignoreProperties,
      Boolean nullBeCopied,
      PropertyDescriptor targetPd,
      Object sourceValue,
      Method writeMethod)
      throws IllegalAccessException, InvocationTargetException, UtilException,
          ClassNotFoundException, InstantiationException, NoSuchFieldException {
    Method targetReadMethod = targetPd.getReadMethod();
    Collection targetValue = (Collection) targetReadMethod.invoke(target, null);
    List tempList = new ArrayList();
    if (sourceValue == null) {
      writeMethod.invoke(target, sourceValue);
      return;
    }
    if (targetValue == null) {
      if (Set.class.isAssignableFrom(targetPd.getPropertyType())) {
        targetValue = new HashSet();
      } else if (List.class.isAssignableFrom(targetPd.getPropertyType())) {
        targetValue = new ArrayList();
      } else {
        return;
      }
    }
    Object[] sourceArray = ((Collection) sourceValue).toArray();
    Object[] targetArray = targetValue.toArray();
    for (int i = 0; i < sourceArray.length; i++) {
      if (targetValue.contains(sourceArray[i])) {
        for (int j = 0; j < targetArray.length; j++) {
          if (sourceArray[i].equals(targetArray[j])) {
            copyProperties(
                sourceArray[i],
                targetArray[j],
                effectiveProperties,
                ignoreProperties,
                nullBeCopied);
            tempList.add(targetArray[j]);
            break;
          }
        }
      } else {
        Object tempTarget = Class.forName(sourceArray[i].getClass().getName()).newInstance();
        // 基本类型直接赋值
        if (sourceArray[i].getClass().isPrimitive() || sourceArray[i] instanceof String) {
          tempTarget = sourceArray[i];
        } else {
          copyProperties(
              sourceArray[i], tempTarget, effectiveProperties, ignoreProperties, nullBeCopied);
        }

        tempList.add(tempTarget);
      }
    }
    targetValue.clear();
    targetValue.addAll(tempList);
    return;
  }
  @Override
  public AbstractFile[] ls() throws IOException, UnsupportedFileOperationException {
    List<GuestFileInfo> fileInfos = new ArrayList<GuestFileInfo>();
    int index = 0;
    VsphereConnHandler connHandler = null;
    try {

      connHandler = getConnHandler();

      ManagedObjectReference fileManager = getFileManager(connHandler);
      boolean haveRemaining;
      do {
        GuestListFileInfo res =
            connHandler
                .getClient()
                .getVimPort()
                .listFilesInGuest(fileManager, vm, credentials, getPathInVm(), index, null, null);
        haveRemaining = (res.getRemaining() != 0);

        fileInfos.addAll(res.getFiles());
        index = fileInfos.size();
      } while (haveRemaining);

      String parentPath = PathUtils.removeTrailingSeparator(fileURL.getPath()) + SEPARATOR;

      Collection<AbstractFile> res = new ArrayList<AbstractFile>();
      for (GuestFileInfo f : fileInfos) {
        final String name = getFileName(f.getPath());
        if (name.equals(".") || name.equals("..")) {
          continue;
        }

        FileURL childURL = (FileURL) fileURL.clone();
        childURL.setPath(parentPath + name);

        AbstractFile newFile = new VSphereFile(childURL, this, f);
        res.add(newFile);
      }
      return res.toArray(new AbstractFile[0]);
    } catch (FileFaultFaultMsg e) {
      translateandLogException(e);
    } catch (GuestOperationsFaultFaultMsg e) {
      translateandLogException(e);
    } catch (InvalidStateFaultMsg e) {
      translateandLogException(e);
    } catch (RuntimeFaultFaultMsg e) {
      translateandLogException(e);
    } catch (TaskInProgressFaultMsg e) {
      translateandLogException(e);
    } catch (InvalidPropertyFaultMsg e) {
      translateandLogException(e);
    } catch (URISyntaxException e) {
      translateandLogException(e);
    } finally {
      releaseConnHandler(connHandler);
    }
    // we never get here..
    return null;
  }
Example #4
0
 private static String[] toStringArray(Collection coll) {
   Object[] objArray = coll.toArray();
   String[] strArray = new String[objArray.length];
   for (int i = 0; i < objArray.length; i++) {
     strArray[i] = (String) objArray[i];
   }
   return strArray;
 }
 /** Values.toArray contains all values */
 public void testDescendingValuesToArray() {
   ConcurrentNavigableMap map = dmap5();
   Collection v = map.values();
   Object[] ar = v.toArray();
   ArrayList s = new ArrayList(Arrays.asList(ar));
   assertEquals(5, ar.length);
   assertTrue(s.contains("A"));
   assertTrue(s.contains("B"));
   assertTrue(s.contains("C"));
   assertTrue(s.contains("D"));
   assertTrue(s.contains("E"));
 }
 private static StartOptions[] getStartOptions(int options) {
   if (options == 0) {
     return new StartOptions[0];
   }
   Collection<StartOptions> result = new ArrayList<Module.StartOptions>(2);
   if ((options & Bundle.START_TRANSIENT) != 0) {
     result.add(StartOptions.TRANSIENT);
   }
   if ((options & Bundle.START_ACTIVATION_POLICY) != 0) {
     result.add(StartOptions.USE_ACTIVATION_POLICY);
   }
   return result.toArray(new StartOptions[result.size()]);
 }
  private static String[] setgetAll(SolrDocument doc, String solrField) {
    Collection<Object> value_col = doc.getFieldValues(solrField);
    Collection<Object> isnull_col = doc.getFieldValues(solrField + IS_NULL_FIELD_SUFFIX);

    if (value_col == null || isnull_col == null) {
      // System.out.println("returing empty " + field.solrName());
      // System.out.println("valuecol " + (value_col == null));
      // System.out.println("isnull " + (isnull_col == null));

      return new String[] {};
    }

    Boolean[] isnull = isnull_col.toArray(new Boolean[] {});
    String[] values = value_col.toArray(new String[] {});

    for (int i = 0; i < values.length; i++) {
      if (isnull[i]) {
        values[i] = null;
      }
    }

    return values;
  }
Example #8
0
 /**
  * Run the given runnable, waiting until the end to perform a refresh
  *
  * @param runnable
  * @param monitor
  */
 public void run(IRunnableWithProgress runnable, IProgressMonitor monitor)
     throws InvocationTargetException, InterruptedException {
   try {
     notificationLevel++;
     runnable.run(monitor);
   } finally {
     notificationLevel = Math.max(0, notificationLevel - 1);
     if (notificationLevel == 0) {
       try {
         Collection roots = changedRepositories.values();
         broadcastRepositoriesChanged(
             (ICVSRepositoryLocation[]) roots.toArray(new ICVSRepositoryLocation[roots.size()]));
       } finally {
         changedRepositories.clear();
       }
     }
   }
 }
  public TicketTaxInfo[] getTaxLines() {

    Map<String, TicketTaxInfo> m = new HashMap<String, TicketTaxInfo>();

    TicketLineInfo oLine;
    for (Iterator<TicketLineInfo> i = m_aLines.iterator(); i.hasNext(); ) {
      oLine = i.next();

      TicketTaxInfo t = m.get(oLine.getTaxInfo().getId());
      if (t == null) {
        t = new TicketTaxInfo(oLine.getTaxInfo());
        m.put(t.getTaxInfo().getId(), t);
      }
      t.add(oLine.getSubValue());
    }

    // return dSuma;
    Collection<TicketTaxInfo> avalues = m.values();
    return avalues.toArray(new TicketTaxInfo[avalues.size()]);
  }
 public static Building[] placeBigFires(int num, Building[] b, Limits radius) {
   List remaining = new ArrayList();
   for (int i = 0; i < b.length; ++i) remaining.add(b[i]);
   Collections.shuffle(remaining);
   Collection fires = new HashSet();
   System.out.print("Placing " + num + " big fires");
   Iterator it = remaining.iterator();
   for (int i = 0; i < num; ++i) {
     Building center = (Building) it.next();
     fires.add(center);
     long r = radius.getNumber();
     long distanceSquared = r * r;
     // Check for close buildings
     for (int j = 0; j < b.length; ++j) {
       long dx = center.getX() - b[j].getX();
       long dy = center.getY() - b[j].getY();
       long distance = (dx * dx) + (dy * dy);
       if (distance <= distanceSquared) fires.add(b[j]);
     }
   }
   return (Building[]) fires.toArray(new Building[0]);
 }
 /**
  * Returns all Groovy classes loaded by this class loader.
  *
  * @return all classes loaded by this class loader
  */
 public Class[] getLoadedClasses() {
   synchronized (classCache) {
     final Collection<Class> values = classCache.values();
     return values.toArray(new Class[values.size()]);
   }
 }
Example #12
0
 public static URL[] toURLArray(Collection<File> files) {
   return toURLs(files.toArray(new File[files.size()]));
 }
Example #13
0
 /**
  * Creates a new section with paragraphs and appends them to the RTF document.
  *
  * @param paragraphs Paragraphs.
  * @return {@code this}-reference.
  */
 public Rtf section(Collection<RtfPara> paragraphs) {
   return section(null, paragraphs.toArray(new RtfPara[paragraphs.size()]));
 }
Example #14
0
 /**
  * 预测分布
  *
  * @param context
  * @return
  */
 public final List<Pair<String, Double>> predict(Collection<String> context) {
   return predict(context.toArray(new String[0]));
 }
Example #15
0
 /**
  * Retrieves all the available <code>Charset</code>s on the platform, among which the default
  * <code>charset</code>.
  *
  * @return an array of <code>Charset</code>s.
  */
 public static Charset[] getAvailableCharsets() {
   Collection collection = Charset.availableCharsets().values();
   return (Charset[]) collection.toArray(new Charset[collection.size()]);
 }
Example #16
0
  protected boolean executeUploadCommand(Collection commandDownloader) throws RunnerException {
    firstErrorFound = false; // haven't found any errors yet
    secondErrorFound = false;
    notFoundError = false;
    int result = 0; // pre-initialized to quiet a bogus warning from jikes

    String userdir = System.getProperty("user.dir") + File.separator;

    try {
      String[] commandArray = new String[commandDownloader.size()];
      commandDownloader.toArray(commandArray);

      String avrBasePath;

      if (Base.isLinux()) {
        avrBasePath = new String(Base.getHardwarePath() + "/tools/");
      } else {
        avrBasePath = new String(Base.getHardwarePath() + "/tools/avr/bin/");
      }

      commandArray[0] = avrBasePath + commandArray[0];

      if (verbose || Preferences.getBoolean("upload.verbose")) {
        for (int i = 0; i < commandArray.length; i++) {
          System.out.print(commandArray[i] + " ");
        }
        System.out.println();
      }
      Process process = Runtime.getRuntime().exec(commandArray);
      new MessageSiphon(process.getInputStream(), this);
      new MessageSiphon(process.getErrorStream(), this);

      // wait for the process to finish.  if interrupted
      // before waitFor returns, continue waiting
      //
      boolean compiling = true;
      while (compiling) {
        try {
          result = process.waitFor();
          compiling = false;
        } catch (InterruptedException intExc) {
        }
      }
      if (exception != null) {
        exception.hideStackTrace();
        throw exception;
      }
      if (result != 0) return false;
    } catch (Exception e) {
      String msg = e.getMessage();
      if ((msg != null)
          && (msg.indexOf("uisp: not found") != -1)
          && (msg.indexOf("avrdude: not found") != -1)) {
        // System.err.println("uisp is missing");
        // JOptionPane.showMessageDialog(editor.base,
        //                              "Could not find the compiler.\n" +
        //                              "uisp is missing from your PATH,\n" +
        //                              "see readme.txt for help.",
        //                              "Compiler error",
        //                              JOptionPane.ERROR_MESSAGE);
        return false;
      } else {
        e.printStackTrace();
        result = -1;
      }
    }
    // System.out.println("result2 is "+result);
    // if the result isn't a known, expected value it means that something
    // is fairly wrong, one possibility is that jikes has crashed.
    //
    if (exception != null) throw exception;

    if ((result != 0) && (result != 1)) {
      exception = new RunnerException(SUPER_BADNESS);
      // editor.error(exception);
      // PdeBase.openURL(BUGS_URL);
      // throw new PdeException(SUPER_BADNESS);
    }

    return (result == 0); // ? true : false;
  }