Пример #1
0
  public static String getLicense(final String licenseName) {
    URL url = resourceManager.getUrl("licenses/" + licenseName + ".txt");
    if (url == null) {
      throw new IllegalArgumentException("Could not find license file for license: " + licenseName);
    }
    BufferedReader reader = null;
    try {
      reader =
          new BufferedReader(new InputStreamReader(url.openStream(), FileHelper.UTF_8_ENCODING));
      final StringBuilder sb = new StringBuilder();
      for (String line = reader.readLine(); line != null; line = reader.readLine()) {
        if (sb.length() != 0) {
          sb.append('\n');
        }
        sb.append(line);
      }

      return sb.toString();
    } catch (Exception e) {
      throw new IllegalStateException(
          "Error occurred while reading license file: " + licenseName, e);
    } finally {
      if (reader != null) {
        try {
          reader.close();
        } catch (IOException e) {
          // do nothing
        }
      }
    }
  }
Пример #2
0
  public static List<LicensedProject> getLicensedProjects() {
    final List<LicensedProject> result = new ArrayList<AboutDialog.LicensedProject>();
    final URL url = resourceManager.getUrl("licenses/dependency-licenses.csv");
    if (url == null) {
      throw new IllegalStateException("Could not find dependencies file");
    }
    try {
      DataContext dc = DataContextFactory.createCsvDataContext(url.openStream(), ',', '"');
      Table table = dc.getDefaultSchema().getTables()[0];
      Column projectColumn = table.getColumnByName("Project");
      Column websiteColumn = table.getColumnByName("Website");
      Column licenseColumn = table.getColumnByName("License");
      Query q =
          dc.query().from(table).select(table.getColumns()).orderBy(projectColumn).asc().toQuery();
      DataSet ds = dc.executeQuery(q);
      while (ds.next()) {
        final LicensedProject licensedProject = new LicensedProject();
        final Row row = ds.getRow();
        final String licenseName = row.getValue(licenseColumn).toString();

        licensedProject.name = row.getValue(projectColumn).toString();
        licensedProject.websiteUrl = row.getValue(websiteColumn).toString();
        licensedProject.license = getLicense(licenseName);

        result.add(licensedProject);
      }

    } catch (IOException e) {
      throw new IllegalStateException("Error occurred while reading dependencies file", e);
    }

    return result;
  }