Package jp.sf.amateras.stepcounter.format

Examples of jp.sf.amateras.stepcounter.format.ResultFormatter


   * �X�e�b�v����������s���܂��B
   *
   * @see org.apache.tools.ant.Task#execute()
   */
  public void execute() throws BuildException {
      ResultFormatter formatter = FormatterFactory.getFormatter(format);

      if (encoding != null) Util.setFileEncoding(encoding);

      OutputStream out = null;
      try {
        if (output != null) {
          try {
          out = new BufferedOutputStream(new FileOutputStream(output));
        } catch (FileNotFoundException e) {
          throw new BuildException("One of tofile or todir must be set.", e);
        }
        } else {
          out = System.out;
        }

        Map<FileSet, ResourceCollection> fsList = new LinkedHashMap<FileSet, ResourceCollection>();
        for (ResourceCollection rc : rcs) {
          if (rc instanceof FileList && rc.isFilesystemOnly()) {
            FileList fl = (FileList)rc;

            FileSet fs = new FileSet();
            fs.setDir(fl.getDir(getProject()));
             fs.appendIncludes(fl.getFiles(getProject()));
            fsList.put(fs, rc);
          } else if (rc instanceof FileSet && rc.isFilesystemOnly()) {
            fsList.put((FileSet)rc, rc);
          } else {
            throw new BuildException("Only FileSystem resources are supported.");
          }
        }

        List<CountResult> results = new ArrayList<CountResult>();
        for (Map.Entry<FileSet, ResourceCollection> entry : fsList.entrySet()) {
          FileSet fs = entry.getKey();
          fs.setDefaultexcludes(defaultExcludes);

          DirectoryScanner ds = null;
                try {
                    ds = fs.getDirectoryScanner(getProject());
                } catch (BuildException e) {
                    if (failonerror || !getMessage(e).endsWith(DirectoryScanner.DOES_NOT_EXIST_POSTFIX)) {
                        throw e;
                    } else {
                        log("Warning: " + getMessage(e), Project.MSG_ERR);
                        continue;
                    }
                }

                File baseDir = fs.getDir(getProject());
                if (!baseDir.exists()) {
                  throw new BuildException("basedir \"" + baseDir.getPath() + "\" does not exist!");
                }

                String basePath;
        try {
          basePath = baseDir.getCanonicalPath();
        } catch (IOException e) {
          throw new BuildException("I/O Error: " + baseDir, e);
        }

            for (String name : ds.getIncludedFiles()) {
              File file = new File(baseDir, name);
              try {
                CountResult result = count(file);
                if (showDirectory) {
                  name = file.getCanonicalPath();
                  if (name.startsWith(basePath)) {
                    name = name.substring(basePath.length());
                  }
                  name = name.replace('\\', '/');
                  result.setFileName(name);
                }
                if (directoryAsCategory) {
                  result.setCategory(baseDir.getName());
                }
              results.add(result);
              } catch (IOException e) {
                        if (failonerror) {
                          throw new BuildException("I/O Error: " + file, e);
                        } else {
                          log("Warning: " + getMessage(e), Project.MSG_ERR);
                          continue;
                        }
              }
            }
        }

        log("" + fsList.size() + " �N�_�f�B���N�g�� / " + results.size() + " �t�@�C��");

        out.write(formatter.format(results.toArray(new CountResult[results.size()])));
        out.flush();

        if (output != null) {
          log(output.getAbsolutePath() + " �ɃJ�E���g���ʂ��o�͂��܂����B");
        }
View Full Code Here

TOP

Related Classes of jp.sf.amateras.stepcounter.format.ResultFormatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.