예제 #1
1
 private CIJobStatus deleteCI(CIJob job, List<String> builds) throws PhrescoException {
   S_LOGGER.debug("Entering Method CIManagerImpl.deleteCI(CIJob job)");
   S_LOGGER.debug("Job name " + job.getName());
   cli = getCLI(job);
   String deleteType = null;
   List<String> argList = new ArrayList<String>();
   S_LOGGER.debug("job name " + job.getName());
   S_LOGGER.debug("Builds " + builds);
   if (CollectionUtils.isEmpty(builds)) { // delete job
     S_LOGGER.debug("Job deletion started");
     S_LOGGER.debug("Command " + FrameworkConstants.CI_JOB_DELETE_COMMAND);
     deleteType = DELETE_TYPE_JOB;
     argList.add(FrameworkConstants.CI_JOB_DELETE_COMMAND);
     argList.add(job.getName());
   } else { // delete Build
     S_LOGGER.debug("Build deletion started");
     deleteType = DELETE_TYPE_BUILD;
     argList.add(FrameworkConstants.CI_BUILD_DELETE_COMMAND);
     argList.add(job.getName());
     StringBuilder result = new StringBuilder();
     for (String string : builds) {
       result.append(string);
       result.append(",");
     }
     String buildNos = result.substring(0, result.length() - 1);
     argList.add(buildNos);
     S_LOGGER.debug("Command " + FrameworkConstants.CI_BUILD_DELETE_COMMAND);
     S_LOGGER.debug("Build numbers " + buildNos);
   }
   try {
     int status = cli.execute(argList);
     String message = deleteType + " deletion started in jenkins";
     if (status == FrameworkConstants.JOB_STATUS_NOTOK) {
       deleteType = deleteType.substring(0, 1).toLowerCase() + deleteType.substring(1);
       message = "Error while deleting " + deleteType + " in jenkins";
     }
     S_LOGGER.debug("Delete CI Status " + status);
     S_LOGGER.debug("Delete CI Message " + message);
     return new CIJobStatus(status, message);
   } finally {
     if (cli != null) {
       try {
         cli.close();
       } catch (IOException e) {
         if (debugEnabled) {
           S_LOGGER.error(
               "Entered into catch block of CIManagerImpl.deleteCI(CIJob job) "
                   + e.getLocalizedMessage());
         }
       } catch (InterruptedException e) {
         if (debugEnabled) {
           S_LOGGER.error(
               "Entered into catch block of CIManagerImpl.deleteCI(CIJob job) "
                   + e.getLocalizedMessage());
         }
       }
     }
   }
 }
예제 #2
0
 private void deleteJsonJobs(ApplicationInfo appInfo, List<CIJob> selectedJobs)
     throws PhrescoException {
   try {
     if (CollectionUtils.isEmpty(selectedJobs)) {
       return;
     }
     Gson gson = new Gson();
     List<CIJob> jobs = getJobs(appInfo);
     if (CollectionUtils.isEmpty(jobs)) {
       return;
     }
     // all values
     Iterator<CIJob> iterator = jobs.iterator();
     // deletable values
     for (CIJob selectedInfo : selectedJobs) {
       while (iterator.hasNext()) {
         CIJob itrCiJob = iterator.next();
         if (itrCiJob.getName().equals(selectedInfo.getName())) {
           iterator.remove();
           break;
         }
       }
     }
     writeJsonJobs(appInfo, jobs, CI_CREATE_NEW_JOBS);
   } catch (Exception e) {
     throw new PhrescoException(e);
   }
 }
예제 #3
0
 private void _deepToString(
     Object[] objsArray, StringBuilder buffer, Set<Object[]> alreadyFormatted) {
   if (objsArray == null) {
     buffer.append(NULL);
     return;
   }
   alreadyFormatted.add(objsArray);
   buffer.append('[');
   int length = objsArray.length;
   for (int i = 0; i < length; i++) {
     if (i != 0) buffer.append(", ");
     Object element = objsArray[i];
     if (element == null) {
       buffer.append(NULL);
       continue;
     }
     if (!CollectionUtils.isArray(element.getClass())) { // Objetos normales
       buffer.append(Strings.quote(element.toString()));
       continue;
     }
     // Aqui es un array pero no se sabe si es de objetos primitivos o objetos normales
     if (!CollectionUtils.isObjectsArray(element.getClass())) { // Array de objetos primitivos
       buffer.append(_formatPrimitivesArray(element));
       continue;
     }
     if (alreadyFormatted.contains(element)) {
       buffer.append("[...]");
       continue;
     }
     // Aqui seguro que es un array de objetos
     _deepToString((Object[]) element, buffer, alreadyFormatted);
   }
   buffer.append(']');
   alreadyFormatted.remove(objsArray);
 }
예제 #4
0
  /** Filters input HTML using specified policy as white list of allowed tags. */
  @SuppressWarnings("unchecked")
  private String filter(String inputHtml, String policyFileName) {
    String filteredHtml = "";
    if (!StringUtils.isBlank(inputHtml)) {
      if (policyFileName == null) {
        LOG.warn("Provided policy file name is null.");
        policyFileName = DEFAULT_ANTISAMY_POLICY_FILE;
      }

      AntiSamy htmlScanner = getHtmlScannerByPolicyFileName(policyFileName);
      if (htmlScanner != null) {
        CleanResults scanResults;
        try {
          scanResults = htmlScanner.scan(inputHtml);
          filteredHtml = scanResults.getCleanHTML();
          ArrayList<String> scannerErrors = scanResults.getErrorMessages();
          if (!CollectionUtils.isNullOrEmpty(scannerErrors)) {
            LOG.trace("HTML input contains erorrs (" + scannerErrors.size() + "):");
            int i = 1;
            for (String error : scannerErrors) {
              LOG.trace("    " + i + ") " + error);
              i++;
            }
          }
        } catch (ScanException ex) {
          throw new HtmlScannerException(ex);
        } catch (PolicyException ex) {
          throw new HtmlScannerException(ex);
        }
      }
    }

    return filteredHtml;
  }
예제 #5
0
 public String formatOpts(Collection pLongNames) {
   StringBuffer result = new StringBuffer();
   Map longnametoshortnamemap = CollectionUtils.inverseMap(mShortNameToLongNameMap);
   Iterator longnames = pLongNames.iterator();
   while (longnames.hasNext()) {
     String longname = (String) longnames.next();
     result.append("  -" + longname);
     String shortname = (String) longnametoshortnamemap.get(longname);
     if (shortname != null) {
       result.append(" (-" + shortname + ")");
     }
     String possibleValsString = "";
     if (mPossibleValues.keySet().contains(longname)) {
       possibleValsString = " " + mPossibleValues.get(longname);
     }
     result.append(possibleValsString);
     String defaultVal = (String) mDefaultValues.get(longname);
     if (defaultVal != null) {
       result.append(", default=" + defaultVal);
     }
     if (longnames.hasNext()) {
       result.append("\n");
     }
   }
   return result.toString();
 }
 /**
  * Splits the {@code delimited} string (delimited by the specified {@code separator} character)
  * and returns the delimited values as a {@code Set}.
  *
  * <p>If either argument is {@code null}, this method returns {@code null}.
  *
  * @param delimited the string to split
  * @param separator the character that delineates individual tokens to split
  * @return the delimited values as a {@code Set}.
  */
 public static Set<String> splitToSet(String delimited, String separator) {
   if (delimited == null || separator == null) {
     return null;
   }
   String[] split = split(delimited, separator.charAt(0));
   return CollectionUtils.asSet(split);
 }
예제 #7
0
파일: Main.java 프로젝트: namihira-k/java8
  public static void main(String[] args) {
    // setup
    final Path in = getPath("in.txt");
    final Path out = getPath("out.txt");

    // action
    try {
      final byte[] bytes = Files.readAllBytes(in);
      System.out.println("-->");
      System.out.println(new String(bytes));

      final byte[] reversed = CollectionUtils.reverse(bytes);
      Files.write(out, reversed);
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }

    // check
    try {
      final byte[] result = Files.readAllBytes(out);
      System.out.println("<--");
      System.out.println(new String(result));
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  }
예제 #8
0
 /**
  * Filter the stacktrace elements with only interesting one.
  *
  * @param throwable throwable
  * @return {@link Throwable} instance with interested stacktrace elements.
  */
 public static Throwable sanitize(Throwable throwable) {
   if (throwable instanceof NGrinderRuntimeException) {
     if (((NGrinderRuntimeException) throwable).isSanitized()) {
       return throwable;
     }
   }
   Throwable t = throwable;
   while (t != null) {
     // Note that this getBoolean access may well be synced...
     StackTraceElement[] trace = t.getStackTrace();
     List<StackTraceElement> newTrace = CollectionUtils.newArrayList();
     for (StackTraceElement stackTraceElement : trace) {
       if (isApplicationClass(stackTraceElement.getClassName())) {
         newTrace.add(stackTraceElement);
       }
     }
     StackTraceElement[] clean = new StackTraceElement[newTrace.size()];
     newTrace.toArray(clean);
     t.setStackTrace(clean);
     t = t.getCause();
   }
   if (throwable instanceof NGrinderRuntimeException) {
     ((NGrinderRuntimeException) throwable).setSanitized(true);
   }
   return throwable;
 }
예제 #9
0
 public static List<Vulnerabilities.Vulnerability.Finding> convertTFFindingsToSSVLFindings(
     List<Finding> tfVulnFindings) {
   List<Vulnerabilities.Vulnerability.Finding> ssvlVulnFindings = CollectionUtils.list();
   for (Finding tfFinding : tfVulnFindings) {
     ssvlVulnFindings.add(convertTFFindingToSSVLFinding(tfFinding));
   }
   return ssvlVulnFindings;
 }
예제 #10
0
  private static final String getAppleMailParam(final String subject, final String body) {
    final List<String> l = new ArrayList<String>(3);
    l.add("visible:true");
    if (subject != null) l.add(createASParam("subject", subject));
    if (body != null) l.add(createASParam("content", body));

    return CollectionUtils.join(l, ", ");
  }
예제 #11
0
  public static List<Vulnerabilities.Vulnerability> convertTFVulnsToSSVLVulns(
      List<Vulnerability> tfVulnList) {
    List<Vulnerabilities.Vulnerability> ssvlVulnList = CollectionUtils.list();
    for (Vulnerability tfVuln : tfVulnList) {
      ssvlVulnList.add(convertTFVulnToSSVLVuln(tfVuln));
    }

    return ssvlVulnList;
  }
예제 #12
0
  /**
   * Constructs an instance of the BreadthFirstIterator class wrapping the Iterator of Iterators to
   * collectively traverse the Iterators in order, left to right, top to bottom.
   *
   * @param iterators the Iterator of Iterators to encapsulate in a breadth-first traversal.
   * @throws java.lang.NullPointerException if the Iterator of Iterators reference is null.
   * @see java.util.Iterator
   */
  public BreadthFirstIterator(final Iterator<Iterator<T>> iterators) {
    Assert.notNull(iterators, "The Iterator of Iterators must not be null!");

    for (Iterator<T> iterator : CollectionUtils.iterable(iterators)) {
      if (iterator != null) {
        this.iterators.add(iterator);
      }
    }
  }
  @Test(groups = "unittest")
  public void testNotFound2() {
    Set<String> first = new HashSet<String>(Arrays.asList("one", "two", "twohalf", "three"));
    Set<String> second = new HashSet<String>(Arrays.asList("one", "two", "twohalf", "three"));

    Set<String> notFound = (Set<String>) CollectionUtils.firstNotFoundInSecond(first, second);

    Assert.assertTrue(notFound.size() == 0);
  }
예제 #14
0
 @Test
 void getOnlyElementWithEmptyCollection() {
   PreconditionViolationException exception =
       expectThrows(
           PreconditionViolationException.class,
           () -> {
             CollectionUtils.getOnlyElement(emptySet());
           });
   assertEquals("collection must contain exactly one element: []", exception.getMessage());
 }
 protected Enumeration<URL> findResources(final String name, final boolean parentHasBeenSearched)
     throws IOException {
   final Enumeration<URL> mine = new ResourceEnumeration(name);
   Enumeration<URL> base;
   if (this.parent != null && (!parentHasBeenSearched || this.parent != this.getParent())) {
     base = this.parent.getResources(name);
   } else {
     base = new CollectionUtils.EmptyEnumeration<URL>();
   }
   if (this.isParentFirst(name)) {
     return CollectionUtils.append(base, mine);
   }
   if (this.ignoreBase) {
     return (this.getRootLoader() == null)
         ? mine
         : CollectionUtils.append(mine, this.getRootLoader().getResources(name));
   }
   return CollectionUtils.append(mine, base);
 }
예제 #16
0
 @Test
 void getOnlyElementWithNullCollection() {
   PreconditionViolationException exception =
       expectThrows(
           PreconditionViolationException.class,
           () -> {
             CollectionUtils.getOnlyElement(null);
           });
   assertEquals("collection must not be null", exception.getMessage());
 }
  @Test(groups = "unittest")
  public void testNotFound() {
    Set<String> first = new HashSet<String>(Arrays.asList("one", "two", "twohalf", "three"));
    Set<String> second = new HashSet<String>(Arrays.asList("two", "three", "four"));

    Set<String> notFound = (Set<String>) CollectionUtils.firstNotFoundInSecond(first, second);

    for (String string : notFound)
      Assert.assertTrue(string.equals("one") || string.equals("twohalf"));
  }
예제 #18
0
 @Test
 void getOnlyElementWithMultiElementCollection() {
   PreconditionViolationException exception =
       expectThrows(
           PreconditionViolationException.class,
           () -> {
             CollectionUtils.getOnlyElement(asList("foo", "bar"));
           });
   assertEquals("collection must contain exactly one element: [foo, bar]", exception.getMessage());
 }
예제 #19
0
 public Set<Model> getClassModels(String jarName) {
   Set<Model> rootModels = jarPackageMap.get(jarName);
   Set<Model> classModels = new HashSet<Model>();
   if (CollectionUtils.hasElements(rootModels)) {
     for (Model model : rootModels) {
       model.listPackages(model, classModels, false);
     }
   }
   return classModels;
 }
  @Test
  public void testFilterNonNullIterableWithNullFilter() {
    // Set up
    final Iterable<String> inputs = Arrays.asList("a", "");

    // Invoke
    final List<? extends String> results = CollectionUtils.filter(inputs, null);

    // Check
    assertEquals(inputs, results);
  }
 /** {@inheritDoc} */
 public boolean removeAll(Collection<?> c) {
   if (CollectionUtils.isEmpty(c)) {
     return false;
   }
   writeLock.lock();
   try {
     return super.removeAll(c);
   } finally {
     writeLock.unlock();
   }
 }
예제 #22
0
 @Override
 public ICollectionSequence<T> asSynchronized() {
   final Collection<T> synchronizedCollection =
       CollectionUtils.synchronizedCollection(getCollection());
   return new CollectionSequence<T>() {
     @Override
     protected Collection<T> getCollection() {
       return synchronizedCollection;
     }
   };
 }
예제 #23
0
 public SampleBuilderSpec<P> blanks(Collection<BlankBuilderSpec<?>> blanks) {
   verifyMutable();
   if (this.blanks == null) {
     this.blanks = new ArrayList<BlankBuilderSpec<?>>();
   }
   if (blanks != null) {
     for (BlankBuilderSpec<?> e : blanks) {
       CollectionUtils.addItem(this.blanks, e);
     }
   }
   return this;
 }
예제 #24
0
 public SampleBuilderSpec<P> otherClasses(Collection<Class<?>> otherClasses) {
   verifyMutable();
   if (this.otherClasses == null) {
     this.otherClasses = new TreeSet<Class<?>>();
   }
   if (otherClasses != null) {
     for (Class<?> e : otherClasses) {
       CollectionUtils.addItem(this.otherClasses, e);
     }
   }
   return this;
 }
예제 #25
0
 public SampleBuilderSpec<P> keywords(Collection<String> keywords) {
   verifyMutable();
   if (this.keywords == null) {
     this.keywords = new HashSet<String>();
   }
   if (keywords != null) {
     for (String e : keywords) {
       CollectionUtils.addItem(this.keywords, e);
     }
   }
   return this;
 }
예제 #26
0
 private Set<Train> filterTrains(Filter filter, Object criteria) {
   Set<Train> foundedTrains = Collections.emptySet();
   if (CollectionUtils.isNotEmpty(trains)) {
     foundedTrains = new HashSet<Train>();
     for (Train train : trains) {
       if (filter.apply(train, criteria)) {
         foundedTrains.add(train);
       }
     }
   }
   return foundedTrains;
 }
예제 #27
0
 public SampleBuilderSpec<P> names(Collection<String> names) {
   verifyMutable();
   if (this.names == null) {
     this.names = new ArrayList<String>();
   }
   if (names != null) {
     for (String e : names) {
       CollectionUtils.addItem(this.names, e);
     }
   }
   return this;
 }
  @Test
  public void testPopulateNonNullCollectionWithNullCollection() {
    // Set up
    final Collection<Parent> collection = new ArrayList<Parent>();
    collection.add(new Parent());

    // Invoke
    final Collection<Parent> result = CollectionUtils.populate(collection, null);

    // Check
    assertEquals(0, result.size());
  }
예제 #29
0
  static {
    transforms.put("void", "V");
    transforms.put("byte", "B");
    transforms.put("char", "C");
    transforms.put("double", "D");
    transforms.put("float", "F");
    transforms.put("int", "I");
    transforms.put("long", "J");
    transforms.put("short", "S");
    transforms.put("boolean", "Z");

    CollectionUtils.reverse(transforms, rtransforms);
  }
예제 #30
0
  // see http://kb.mozillazine.org/Command_line_arguments_(Thunderbird)
  // The escape mechanism isn't specified, it turns out we can pass percent encoded strings
  private static final String getTBParam(
      final String to, final String subject, final String body, final File... attachments) {
    // "to='[email protected],[email protected]',cc='*****@*****.**',subject='dinner',body='How
    // about dinner
    // tonight?',attachment='file:///C:/cygwin/Cygwin.bat,file:///C:/cygwin/Cygwin.ico'";

    final List<String> l = new ArrayList<String>(4);
    if (to != null) l.add(createEncodedParam("to", to));
    if (subject != null) l.add(createEncodedParam("subject", subject));
    if (body != null) l.add(createEncodedParam("body", body));
    final List<String> urls = new ArrayList<String>(attachments.length);
    for (final File attachment : attachments) {
      // Thunderbird doesn't parse java URI file:/C:/
      final String rawPath = attachment.toURI().getRawPath();
      // handle UNC paths
      final String tbURL = (rawPath.startsWith("//") ? "file:///" : "file://") + rawPath;
      urls.add(tbURL);
    }
    l.add(createEncodedParam("attachment", CollectionUtils.join(urls, ",")));

    return DesktopEnvironment.getDE().quoteParamForExec(CollectionUtils.join(l, ","));
  }