コード例 #1
1
  public void testMaliciousGetIcons() {
    Iterable<WWIcon> icons = createExampleIterable();

    IconLayer layer = new IconLayer();
    layer.addIcons(icons);

    Iterable<WWIcon> layerIcons = layer.getIcons();

    // Test that the returned list cannot be modified.
    try {
      if (layerIcons instanceof java.util.Collection) {
        java.util.Collection<WWIcon> collection = (java.util.Collection<WWIcon>) layerIcons;
        collection.clear();
      } else {
        java.util.Iterator<WWIcon> iter = layerIcons.iterator();
        while (iter.hasNext()) {
          iter.next();
          iter.remove();
        }
      }
    } catch (UnsupportedOperationException e) {
      e.printStackTrace();
    }

    // Test that the layer contents do not change, even if the returned list can be modified.
    assertEquals("", icons, layerIcons);
  }
コード例 #2
0
ファイル: KILtoSMTLib.java プロジェクト: kszr/k
  /**
   * Translates the equalities of the given symbolic constraint into SMTLib format. Ignores the
   * substitution of the symbolic constraint.
   */
  @Override
  public ASTNode transform(SymbolicConstraint constraint) {
    if (constraint.data.equalities.isEmpty()) {
      return new SMTLibTerm("true");
    }

    StringBuilder sb = new StringBuilder();
    sb.append("(and");
    boolean isEmptyAdd = true;
    for (SymbolicConstraint.Equality equality : constraint.data.equalities) {
      try {
        String left = ((SMTLibTerm) equality.leftHandSide().accept(this)).expression();
        String right = ((SMTLibTerm) equality.rightHandSide().accept(this)).expression();
        sb.append(" (= ");
        sb.append(left);
        sb.append(" ");
        sb.append(right);
        sb.append(")");
        isEmptyAdd = false;
      } catch (UnsupportedOperationException e) {
        // TODO(AndreiS): fix this translation and the exceptions
        if (skipEqualities) {
          /* it is sound to skip the equalities that cannot be translated */
          e.printStackTrace();
        } else {
          throw e;
        }
      }
    }
    if (isEmptyAdd) {
      sb.append(" true");
    }
    sb.append(")");
    return new SMTLibTerm(sb.toString());
  }
コード例 #3
0
ファイル: Main.java プロジェクト: sebkur/montemedia
 private static void test(File file, Format format) throws IOException {
   testWriting(file, format);
   try {
     testReading(file);
   } catch (UnsupportedOperationException e) {
     e.printStackTrace();
   }
 }
コード例 #4
0
 public void printVegetarianMenu() {
   Iterator iterator = allMenus.createIterator();
   System.out.println("\nVEGETARIAN MENU\n-----");
   while (iterator.hasNext()) {
     MenuComponent menuComponent = (MenuComponent) iterator.next();
     try {
       if (menuComponent.isVegetarian()) {
         menuComponent.print();
       }
     } catch (UnsupportedOperationException e) {
       e.printStackTrace();
     }
   }
 }
コード例 #5
0
  /** Make sure we can actually fetch a MAC address. */
  @Test
  public void verifyMac() {
    byte[] mac;
    try {
      mac = MacUtils.macAddress();
    } catch (UnsupportedOperationException e) {
      // hmm... maybe we have no valid MAC's?
      e.printStackTrace();
      System.setProperty(MacUtils.OVERRIDE_MAC_PROP, "00:DE:AD:BE:EF:00");
      mac = MacUtils.macAddress();
    }

    Assert.assertNotNull("Could not retrieve MAC", mac);
    Assert.assertTrue("Invalid MAC address", mac.length == 6);
  }
コード例 #6
0
ファイル: SMTOperations.java プロジェクト: gitter-badger/k-1
 /** Checks if {@code left => right}, or {@code left /\ !right} is unsat. */
 public boolean impliesSMT(
     ConjunctiveFormula left, ConjunctiveFormula right, Set<Variable> rightOnlyVariables) {
   if (smtOptions.smt == SMTSolver.Z3) {
     try {
       return z3.isUnsat(
           KILtoSMTLib.translateImplication(left, right, rightOnlyVariables),
           smtOptions.z3ImplTimeout);
     } catch (UnsupportedOperationException e) {
       e.printStackTrace();
     } catch (SMTTranslationFailure e) {
       e.printStackTrace();
     }
   }
   return false;
 }
 public void bad(HttpServletRequest request, HttpServletResponse response) throws Throwable {
   switch (7) {
     case 7:
       try {
         throw new UnsupportedOperationException();
       } catch (UnsupportedOperationException exceptUnsupportedOperation) {
         exceptUnsupportedOperation.printStackTrace(
             response.getWriter()); /* FLAW: Print stack trace in response on error */
       }
       break;
     default:
       /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
       IO.writeLine("Benign, fixed string");
       break;
   }
 }
コード例 #8
0
  private void getImageIntents() {
    /*
     * if (getIntent().hasExtra("trio")) { _trio = true; _groupId =
     * getIntent().getStringExtra("groupId"); _planner =
     * getIntent().getBooleanExtra("planner", false); } else { _trio =
     * false; _planner = false; _groupId = ""; }
     */
    if (getIntent().getStringExtra("type").equals("gallery")) {
      Intent intent = new Intent();
      intent.setType("image/*");
      intent.setAction(Intent.ACTION_GET_CONTENT);
      this.startActivityForResult(intent, GALLERY);

      mIsCamera = false;

    } else {
      try {
        startCamera();
        mIsCamera = true;
      } catch (UnsupportedOperationException ex) {
        ex.printStackTrace();
        Toast.makeText(getBaseContext(), "UnsupportedOperationException", Toast.LENGTH_SHORT)
            .show();
      }
    }
    if (getIntent().getBooleanExtra("profile", false) == true) {
      mForProfile = true;
    } else {
      mForProfile = false;
    }
    if (getIntent().getBooleanExtra("createGroup", false) == true) {
      mForGroup = true;
    } else {
      mForGroup = false;
    }
    if (getIntent().getBooleanExtra("groupUpdate", false) == true) {
      mForGroupUpdate = true;
    } else {
      mForGroupUpdate = false;
    }
  }
コード例 #9
0
ファイル: SMTOperations.java プロジェクト: gitter-badger/k-1
  public boolean checkUnsat(ConjunctiveFormula constraint) {
    if (smtOptions.smt != SMTSolver.Z3) {
      return false;
    }

    if (constraint.isSubstitution()) {
      return false;
    }

    boolean result = false;
    try {
      String query = KILtoSMTLib.translateConstraint(constraint);
      result = z3.isUnsat(query, smtOptions.z3CnstrTimeout);
      if (result && RuleAuditing.isAuditBegun()) {
        System.err.println("SMT query returned unsat: " + query);
      }
    } catch (UnsupportedOperationException e) {
      e.printStackTrace();
    }
    return result;
  }
コード例 #10
0
  @Override
  public GrepResults execute(List<GrepRequest> grepRequests) {
    GrepResults results = new GrepResults();
    ExecutorService executorService = null;
    StackSessionPool.getInstance().startPool();
    try {
      clock.start();
      executorService =
          Executors.newFixedThreadPool(
              maxGrepTaskThreads(this.optionsDecorator, grepRequests.size()));
      List<GrepTask> grepTasks = new ArrayList<GrepTask>();
      for (GrepRequest grepRequest : grepRequests) {
        grepTasks.add(new GrepTask(grepRequest));
      }

      List<Future<List<GrepResult>>> grepTaskFutures = executorService.invokeAll(grepTasks);
      for (Future<List<GrepResult>> future : grepTaskFutures) {
        for (GrepResult singleGrepResult : future.get()) results.add(singleGrepResult);
      }

    } catch (Exception e) {
      throw new RuntimeException("Error when executing the GrepTask", e);
    } finally {
      clock.stop();
      results.setExecutionTime(clock.getTime());
      if (executorService != null) {
        executorService.shutdownNow();
      }
      try {
        StackSessionPool.getInstance().getPool().close();
      } catch (UnsupportedOperationException e) {
        e.printStackTrace();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    return results;
  }
コード例 #11
0
  @Override
  public void onConfigure(Map<String, Object> params) {
    this.tableComponent =
        (GridComponent) params.get(IComponentFactory.FACTORY_PARAM_MVP_COMPONENT_MODEL);
    this.mainApplication =
        (IEntityContainerProvider) params.get(IComponentFactory.FACTORY_PARAM_MAIN_APP);
    this.factory = (IComponentModelFactory) params.get(IComponentFactory.VAADIN_COMPONENT_FACTORY);
    this.daoProvider = (IDAOProvider) params.get(IComponentFactory.CONTAINER_PROVIDER);
    this.entityTypeDao = (IEntityTypeDAOService) params.get(IComponentFactory.CONTAINER_PROVIDER);

    try {
      this.entityClass = this.tableComponent.getDataSource().getEntityType().getJavaType();
      this.entityContainer =
          (BeanItemContainer<?>) mainApplication.createBeanContainer(this.entityClass);
      Set<String> nestedFieldNames = this.tableComponent.getDataSource().getNestedFieldNames();
      for (String nestedFieldName : nestedFieldNames) {
        this.entityContainer.addNestedContainerProperty(nestedFieldName);
      }
    } catch (UnsupportedOperationException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
  }
コード例 #12
0
  private boolean uploadOneSubmission(
      String id, String instanceFilePath, String jrFormId, String token, String formFilePath) {
    // if the token is null fail immediately
    if (token == null) {
      mResults.put(id, oauth_fail + Collect.getInstance().getString(R.string.invalid_oauth));
      return false;
    }

    HashMap<String, String> answersToUpload = new HashMap<String, String>();
    HashMap<String, String> photosToUpload = new HashMap<String, String>();
    HashMap<String, PhotoEntry> uploadedPhotos = new HashMap<String, PhotoEntry>();

    HttpTransport h = AndroidHttp.newCompatibleTransport();
    GoogleCredential gc = new GoogleCredential();
    gc.setAccessToken(token);

    PicasaClient client = new PicasaClient(h.createRequestFactory(gc));

    // get instance file
    File instanceFile = new File(instanceFilePath);

    // first check to see how many columns we have:
    ArrayList<String> columnNames = new ArrayList<String>();
    try {
      getColumns(formFilePath, columnNames);
    } catch (FileNotFoundException e2) {
      e2.printStackTrace();
      mResults.put(id, e2.getMessage());
      return false;
    } catch (XmlPullParserException e2) {
      e2.printStackTrace();
      mResults.put(id, e2.getMessage());
      return false;
    } catch (IOException e2) {
      e2.printStackTrace();
      mResults.put(id, e2.getMessage());
      return false;
    } catch (FormException e2) {
      e2.printStackTrace();
      mResults.put(id, e2.getMessage());
      return false;
    }

    if (columnNames.size() > 255) {
      mResults.put(
          id, Collect.getInstance().getString(R.string.sheets_max_columns, columnNames.size()));
      return false;
    }

    // make sure column names are legal
    for (String n : columnNames) {
      if (!isValidGoogleSheetsString(n)) {
        mResults.put(
            id, Collect.getInstance().getString(R.string.google_sheets_invalid_column_form, n));
        return false;
      }
    }

    // parses the instance file and populates the answers and photos
    // hashmaps.
    try {
      processInstanceXML(instanceFile, answersToUpload, photosToUpload);
    } catch (XmlPullParserException e) {
      e.printStackTrace();
      mResults.put(id, form_fail + e.getMessage());
      return false;
    } catch (FormException e) {
      mResults.put(id, form_fail + Collect.getInstance().getString(R.string.google_repeat_error));
      return false;
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      mResults.put(id, form_fail + e.getMessage());
      return false;
    } catch (IOException e) {
      e.printStackTrace();
      mResults.put(id, form_fail + e.getMessage());
      return false;
    }

    try {
      Thread.sleep(GOOGLE_SLEEP_TIME);
    } catch (InterruptedException e3) {
      e3.printStackTrace();
    }

    // make sure column names in submission are legal (may be different than form)
    for (String n : answersToUpload.keySet()) {
      if (!isValidGoogleSheetsString(n)) {
        mResults.put(
            id, Collect.getInstance().getString(R.string.google_sheets_invalid_column_instance, n));
        return false;
      }
    }

    // if we have any photos to upload,
    // get the picasa album or create a new one
    // then upload the photos
    if (photosToUpload.size() > 0) {
      // First set up a picasa album to upload to:
      // maybe we should move this, because if we don't have any
      // photos we don't care...
      AlbumEntry albumToUse;
      try {
        albumToUse = getOrCreatePicasaAlbum(client, jrFormId);
      } catch (IOException e) {
        e.printStackTrace();
        GoogleAuthUtil.invalidateToken(Collect.getInstance(), token);
        mResults.put(id, picasa_fail + e.getMessage());
        return false;
      }

      try {
        uploadPhotosToPicasa(photosToUpload, uploadedPhotos, client, albumToUse, instanceFile);
      } catch (IOException e1) {
        e1.printStackTrace();
        mResults.put(id, picasa_fail + e1.getMessage());
        return false;
      }
    }

    // All photos have been sent to picasa (if there were any)
    // now upload data to Google Sheet

    String selection = InstanceColumns._ID + "=?";
    String[] selectionArgs = {id};

    Cursor cursor = null;
    String urlString = null;
    try {
      // see if the submission element was defined in the form
      cursor =
          Collect.getInstance()
              .getContentResolver()
              .query(InstanceColumns.CONTENT_URI, null, selection, selectionArgs, null);

      if (cursor.getCount() > 0) {
        cursor.moveToPosition(-1);
        while (cursor.moveToNext()) {
          int subIdx = cursor.getColumnIndex(InstanceColumns.SUBMISSION_URI);
          urlString = cursor.isNull(subIdx) ? null : cursor.getString(subIdx);

          // if we didn't find one in the content provider,
          // try to get from settings
          if (urlString == null) {
            SharedPreferences settings =
                PreferenceManager.getDefaultSharedPreferences(Collect.getInstance());
            urlString =
                settings.getString(
                    PreferencesActivity.KEY_GOOGLE_SHEETS_URL,
                    Collect.getInstance().getString(R.string.default_google_sheets_url));
          }
        }
      }
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }

    // now parse the url string if we have one
    final String googleHeader = "docs.google.com/spreadsheets/d/";
    String sheetId;
    if (urlString == null || urlString.length() < googleHeader.length()) {
      mResults.put(
          id, form_fail + Collect.getInstance().getString(R.string.invalid_sheet_id, urlString));
      return false;
    } else {
      int start = urlString.indexOf(googleHeader) + googleHeader.length();
      int end = urlString.indexOf("/", start);
      if (end == -1) {
        // if there wasn't a "/", just try to get the end
        end = urlString.length();
      }
      if (start == -1 || end == -1) {
        mResults.put(
            id, form_fail + Collect.getInstance().getString(R.string.invalid_sheet_id, urlString));
        return false;
      }
      sheetId = urlString.substring(start, end);
    }

    SpreadsheetService service = new SpreadsheetService("ODK-Collect");
    service.setAuthSubToken(token);

    // Define the URL to request.
    URL spreadsheetFeedURL = null;
    try {
      spreadsheetFeedURL =
          new URL("https://spreadsheets.google.com/feeds/worksheets/" + sheetId + "/private/full");
    } catch (MalformedURLException e) {
      e.printStackTrace();
      mResults.put(id, form_fail + e.getMessage());
      return false;
    }

    WorksheetQuery query = new WorksheetQuery(spreadsheetFeedURL);
    WorksheetFeed feed = null;
    try {
      feed = service.query(query, WorksheetFeed.class);
    } catch (IOException e) {
      e.printStackTrace();
      mResults.put(id, form_fail + e.getMessage());
      return false;
    } catch (ServiceException e) {
      e.printStackTrace();
      if (e.getLocalizedMessage().equalsIgnoreCase("forbidden")) {
        mResults.put(
            id, form_fail + Collect.getInstance().getString(R.string.google_sheets_access_denied));
      } else {
        mResults.put(id, form_fail + Html.fromHtml(e.getResponseBody()));
      }
      return false;
    }

    List<WorksheetEntry> spreadsheets = feed.getEntries();
    // get the first worksheet
    WorksheetEntry we = spreadsheets.get(0);

    // check the headers....
    URL headerFeedUrl = null;
    try {
      headerFeedUrl =
          new URI(
                  we.getCellFeedUrl().toString()
                      + "?min-row=1&max-row=1&min-col=1&max-col="
                      + we.getColCount()
                      + "&return-empty=true")
              .toURL();
    } catch (MalformedURLException e1) {
      e1.printStackTrace();
      mResults.put(id, form_fail + e1.getMessage());
      return false;
    } catch (URISyntaxException e1) {
      e1.printStackTrace();
      mResults.put(id, form_fail + e1.getMessage());
      return false;
    }

    CellFeed headerFeed = null;
    try {
      headerFeed = service.getFeed(headerFeedUrl, CellFeed.class);
    } catch (IOException e) {
      e.printStackTrace();
      mResults.put(id, form_fail + e.getMessage());
      return false;
    } catch (ServiceException e) {
      e.printStackTrace();
      mResults.put(id, form_fail + e.getMessage());
      return false;
    }

    boolean emptyheaders = true;

    // go through headers
    // if they're empty, resize and add
    for (CellEntry c : headerFeed.getEntries()) {
      if (c.getCell().getValue() != null) {
        emptyheaders = false;
        break;
      }
    }

    if (emptyheaders) {
      // if the headers were empty, resize the spreadsheet
      // and add the headers
      we.setColCount(columnNames.size());
      try {
        we.update();
      } catch (IOException e2) {
        e2.printStackTrace();
        mResults.put(id, form_fail + e2.getMessage());
        return false;
      } catch (ServiceException e2) {
        e2.printStackTrace();
        mResults.put(id, form_fail + e2.getMessage());
        return false;
      } catch (UnsupportedOperationException e) {
        e.printStackTrace();
        mResults.put(
            id, form_fail + Collect.getInstance().getString(R.string.google_sheets_update_error));
        return false;
      }

      // get the cell feed url
      URL cellFeedUrl = null;
      try {
        cellFeedUrl =
            new URI(
                    we.getCellFeedUrl().toString()
                        + "?min-row=1&max-row=1&min-col=1&max-col="
                        + columnNames.size()
                        + "&return-empty=true")
                .toURL();
      } catch (MalformedURLException e1) {
        e1.printStackTrace();
        mResults.put(id, form_fail + e1.getMessage());
        return false;
      } catch (URISyntaxException e1) {
        e1.printStackTrace();
        mResults.put(id, form_fail + e1.getMessage());
        return false;
      }

      // and the cell feed
      CellFeed cellFeed = null;
      try {
        cellFeed = service.getFeed(cellFeedUrl, CellFeed.class);
      } catch (IOException e) {
        e.printStackTrace();
        mResults.put(id, form_fail + e.getMessage());
        return false;
      } catch (ServiceException e) {
        e.printStackTrace();
        mResults.put(id, form_fail + e.getMessage());
        return false;
      }

      // write the headers
      for (int i = 0; i < cellFeed.getEntries().size(); i++) {
        CellEntry cell = cellFeed.getEntries().get(i);
        String column = columnNames.get(i);
        cell.changeInputValueLocal(column);
        try {
          cell.update();
        } catch (IOException e) {
          e.printStackTrace();
          mResults.put(id, form_fail + e.getMessage());
          return false;
        } catch (ServiceException e) {
          e.printStackTrace();
          mResults.put(id, form_fail + e.getMessage());
          return false;
        }
      }
    }

    // we may have updated the feed, so get a new one
    // update the feed
    try {
      headerFeedUrl =
          new URI(
                  we.getCellFeedUrl().toString()
                      + "?min-row=1&max-row=1&min-col=1&max-col="
                      + we.getColCount()
                      + "&return-empty=true")
              .toURL();
    } catch (MalformedURLException e3) {
      e3.printStackTrace();
      mResults.put(id, form_fail + e3.getMessage());
      return false;
    } catch (URISyntaxException e3) {
      e3.printStackTrace();
      mResults.put(id, form_fail + e3.getMessage());
      return false;
    }
    try {
      headerFeed = service.getFeed(headerFeedUrl, CellFeed.class);
    } catch (IOException e2) {
      e2.printStackTrace();
      mResults.put(id, form_fail + e2.getMessage());
      return false;
    } catch (ServiceException e2) {
      e2.printStackTrace();
      mResults.put(id, form_fail + e2.getMessage());
      return false;
    }

    // see if our columns match, now
    URL cellFeedUrl = null;
    try {
      cellFeedUrl =
          new URI(
                  we.getCellFeedUrl().toString()
                      + "?min-row=1&max-row=1&min-col=1&max-col="
                      + headerFeed.getEntries().size()
                      + "&return-empty=true")
              .toURL();
    } catch (MalformedURLException e1) {
      e1.printStackTrace();
      mResults.put(id, form_fail + e1.getMessage());
      return false;
    } catch (URISyntaxException e1) {
      e1.printStackTrace();
      mResults.put(id, form_fail + e1.getMessage());
      return false;
    }
    CellFeed cellFeed = null;
    try {
      cellFeed = service.getFeed(cellFeedUrl, CellFeed.class);
    } catch (IOException e) {
      e.printStackTrace();
      mResults.put(id, form_fail + e.getMessage());
      return false;
    } catch (ServiceException e) {
      e.printStackTrace();
      mResults.put(id, form_fail + e.getMessage());
      return false;
    }

    // first, get all the columns in the spreadsheet
    ArrayList<String> sheetCols = new ArrayList<String>();
    for (int i = 0; i < cellFeed.getEntries().size(); i++) {
      CellEntry cell = cellFeed.getEntries().get(i);
      sheetCols.add(cell.getPlainTextContent());
    }

    ArrayList<String> missingColumns = new ArrayList<String>();
    for (String col : columnNames) {
      if (!sheetCols.contains(col)) {
        missingColumns.add(col);
      }
    }

    if (missingColumns.size() > 0) {
      // we had some missing columns, so error out
      String missingString = "";
      for (int i = 0; i < missingColumns.size(); i++) {
        missingString += missingColumns.get(i);
        if (i < missingColumns.size() - 1) {
          missingString += ", ";
        }
      }
      mResults.put(
          id,
          form_fail
              + Collect.getInstance()
                  .getString(R.string.google_sheets_missing_columns, missingString));
      return false;
    }

    // if we get here.. all has matched
    // so write the values
    ListEntry row = new ListEntry();

    // add photos to answer set
    Iterator<String> photoIterator = uploadedPhotos.keySet().iterator();
    while (photoIterator.hasNext()) {
      String key = photoIterator.next();
      String url = uploadedPhotos.get(key).getImageLink();
      answersToUpload.put(key, url);
    }

    Iterator<String> answerIterator = answersToUpload.keySet().iterator();
    while (answerIterator.hasNext()) {
      String path = answerIterator.next();
      String answer = answersToUpload.get(path);
      // Check to see if answer is a location, if so, get rid of accuracy
      // and altitude
      // try to match a fairly specific pattern to determine
      // if it's a location
      // [-]#.# [-]#.# #.# #.#
      Pattern p =
          Pattern.compile(
              "^-?[0-9]+\\.[0-9]+\\s-?[0-9]+\\.[0-9]+\\s-?[0-9]+\\" + ".[0-9]+\\s[0-9]+\\.[0-9]+$");
      Matcher m = p.matcher(answer);
      if (m.matches()) {
        // get rid of everything after the second space
        int firstSpace = answer.indexOf(" ");
        int secondSpace = answer.indexOf(" ", firstSpace + 1);
        answer = answer.substring(0, secondSpace);
        answer = answer.replace(' ', ',');
      }
      row.getCustomElements().setValueLocal(TextUtils.htmlEncode(path), answer);
    }

    // Send the new row to the API for insertion.
    try {
      URL listFeedUrl = we.getListFeedUrl();
      row = service.insert(listFeedUrl, row);
    } catch (IOException e) {
      e.printStackTrace();
      mResults.put(id, form_fail + e.getMessage());
      return false;
    } catch (ServiceException e) {
      e.printStackTrace();
      if (e.getLocalizedMessage().equalsIgnoreCase("Forbidden")) {
        mResults.put(
            id, form_fail + Collect.getInstance().getString(R.string.google_sheets_access_denied));
      } else {
        mResults.put(id, form_fail + Html.fromHtml(e.getResponseBody()));
      }
      return false;
    }

    mResults.put(id, Collect.getInstance().getString(R.string.success));
    return true;
  }
コード例 #13
0
 /**
  * Prints the stack trace for this exception only (root cause not included) using the specified
  * writer.
  *
  * @param out the writer to write to
  * @since 2.1
  */
 public final void printPartialStackTrace(PrintWriter out) {
   super.printStackTrace(out);
 }
コード例 #14
0
ファイル: Game.java プロジェクト: BSteffaniak/WorkspaceOld
  public void init() {
    rot = 0;

    BufferedImage image = null;

    try {
      sprites = new SpriteSheet("res/images/sprites.png", 36, 18);
      brick = new Texture("res/images/brick.png");
      tile = new Texture("res/images/tile.png");
    } catch (IOException e) {
      e.printStackTrace();
    }

    amountX = 220;
    amountZ = 220;

    loc = 2.5f;

    world2D = new Bundle(4 * 3, 2, true, false);
    world3D = new Bundle((4 * 6 * 2) + (4 * 6 * amountX * amountZ), 3, true, false);

    world2D.beginEditingVertices();
    world2D.addVertices(GL.genRectVerts(0, 0, 100, 100));
    world2D.endEditingVertices();

    world2D.beginEditingTextures();
    world2D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
    world2D.endEditingTextures();

    world3D.beginEditingTextures();
    world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
    world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
    world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
    world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
    world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(2, 0, 1, 1)));
    world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(2, 0, 1, 1)));
    world3D.endEditingTextures();

    world3D.beginEditingVertices();
    world3D.addVertices(GL.genCubeVerts(0, loc, -10, 2, 2, 2));

    world3D.addVertices(GL.genCubeVerts(-100, -2, -100, 200, 2, 200));
    world3D.endEditingVertices();

    world3D.beginEditingTextures();
    world3D.addTextures(GL.genRectTextures(tile, 30, 30));
    world3D.addTextures(GL.genRectTextures(tile, 30, 30));
    world3D.addTextures(GL.genRectTextures(tile, 30, 30));
    world3D.addTextures(GL.genRectTextures(tile, 30, 30));
    world3D.addTextures(GL.genRectTextures(tile, 30, 30));
    world3D.addTextures(GL.genRectTextures(tile, 30, 30));

    for (int z = 0; z < amountZ; z++) {
      for (int x = 0; x < amountX; x++) {
        world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
        world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
        world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
        world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(1, 0, 1, 1)));
        world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(2, 0, 1, 1)));
        world3D.addTextures(GL.genRectTextures(sprites.getImageOffsets(2, 0, 1, 1)));
      }
    }

    world3D.endEditingTextures();

    world3D.beginEditingVertices();
    for (int z = 0; z < amountZ; z++) {
      for (int x = 0; x < amountX; x++) {
        world3D.addVertices(GL.genCubeVerts(x * 4, y, z * 4, 2, 2, 2));
      }
    }

    world3D.endEditingVertices();

    //		world3D.beginEditingColors();
    //
    //		world3D.setColors(0, GL.genRectColors(0.5f, 0.5f, 0.5f, 1));
    //
    //		for (int i = 0; i < 100000; i++)
    //		{
    //			world3D.addColors(GL.genRectColors(0.5f, 0.5f, 0.5f, 1));
    //		}
    //
    //		world3D.endEditingColors();

    font =
        new Font(
            "res/images/fonts/font.png",
            26,
            4,
            new char[] {
              'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
                  'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
              'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
                  'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_', '-', '+', '=', '~', '`', '!',
                  '@', '#', '$', '%', '^', '&', '*', '(', ')',
              '?', '>', '<', ';', ':', '\'', '"', '{', '}', '[', ']', '\\', '|', ',', '.', '/', ' ',
                  ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
            });

    actor = new Actor();
    actor.setLocation(0, 2, 0);

    flashlight = new Shader();
    flashlight.loadFile(
        new String[] {"res/shaders/vertex.vs"},
        new String[] {
          "res/shaders/vertex.fs",
          "res/shaders/flashlight.shade",
          "res/shaders/diffuseLights.shade",
        });

    try {
      frameBuffer = new FrameBuffer();
    } catch (UnsupportedOperationException e) {
      e.printStackTrace();
    }

    rising = true;
  }
コード例 #15
0
  @NonNull
  @Override
  protected void retrieve(@NonNull final SCMHeadObserver observer, @NonNull TaskListener listener)
      throws IOException, InterruptedException {
    String cacheEntry = getCacheEntry();
    Lock cacheLock = getCacheLock(cacheEntry);
    cacheLock.lock();
    try {
      File cacheDir = getCacheDir(cacheEntry);
      Git git =
          Git.with(listener, new EnvVars(System.getenv()))
              .in(cacheDir)
              .using(GitTool.getDefaultInstallation().getGitExe());
      GitClient client = git.getClient();
      client.addDefaultCredentials(getCredentials());
      if (!client.hasGitRepo()) {
        listener.getLogger().println("Creating git repository in " + cacheDir);
        client.init();
      }
      String remoteName = getRemoteName();
      listener.getLogger().println("Setting " + remoteName + " to " + getRemote());
      client.setRemoteUrl(remoteName, getRemote());
      listener.getLogger().println("Fetching " + remoteName + "...");
      List<RefSpec> refSpecs = getRefSpecs();
      client.fetch(remoteName, refSpecs.toArray(new RefSpec[refSpecs.size()]));
      listener.getLogger().println("Pruning stale remotes...");
      final Repository repository = client.getRepository();
      try {
        client.prune(new RemoteConfig(repository.getConfig(), remoteName));
      } catch (UnsupportedOperationException e) {
        e.printStackTrace(listener.error("Could not prune stale remotes"));
      } catch (URISyntaxException e) {
        e.printStackTrace(listener.error("Could not prune stale remotes"));
      }
      listener.getLogger().println("Getting remote branches...");
      SCMSourceCriteria branchCriteria = getCriteria();
      RevWalk walk = new RevWalk(repository);
      try {
        walk.setRetainBody(false);
        for (Branch b : client.getRemoteBranches()) {
          if (!b.getName().startsWith(remoteName + "/")) {
            continue;
          }
          final String branchName = StringUtils.removeStart(b.getName(), remoteName + "/");
          listener.getLogger().println("Checking branch " + branchName);
          if (isExcluded(branchName)) {
            continue;
          }
          if (branchCriteria != null) {
            RevCommit commit = walk.parseCommit(b.getSHA1());
            final long lastModified = TimeUnit.SECONDS.toMillis(commit.getCommitTime());
            final RevTree tree = commit.getTree();
            SCMSourceCriteria.Probe probe =
                new SCMSourceCriteria.Probe() {
                  @Override
                  public String name() {
                    return branchName;
                  }

                  @Override
                  public long lastModified() {
                    return lastModified;
                  }

                  @Override
                  public boolean exists(@NonNull String path) throws IOException {
                    TreeWalk tw = TreeWalk.forPath(repository, path, tree);
                    try {
                      return tw != null;
                    } finally {
                      if (tw != null) {
                        tw.release();
                      }
                    }
                  }
                };
            if (branchCriteria.isHead(probe, listener)) {
              listener.getLogger().println("Met criteria");
            } else {
              listener.getLogger().println("Does not meet criteria");
              continue;
            }
          }
          SCMHead head = new SCMHead(branchName);
          SCMRevision hash = new SCMRevisionImpl(head, b.getSHA1String());
          observer.observe(head, hash);
          if (!observer.isObserving()) {
            return;
          }
        }
      } finally {
        walk.dispose();
      }

      listener.getLogger().println("Done.");
    } finally {
      cacheLock.unlock();
    }
  }