public void execute() throws MojoExecutionException {
    getLog()
        .info("Invoking xgettext for Java files in '" + sourceDirectory.getAbsolutePath() + "'.");

    Commandline cl = new Commandline();
    cl.setExecutable(xgettextCmd);
    cl.createArg().setValue("--from-code=" + encoding);
    cl.createArg().setValue("--output=" + new File(poDirectory, keysFile).getAbsolutePath());
    cl.createArg().setValue("--language=Java");
    cl.createArg().setValue("--sort-output");
    // cl.createArg().setValue("--join-existing");
    cl.createArg().setLine(keywords);
    cl.setWorkingDirectory(sourceDirectory.getAbsolutePath());

    DirectoryScanner ds = new DirectoryScanner();
    ds.setBasedir(sourceDirectory);
    ds.setIncludes(new String[] {"**/*.java"});
    ds.scan();
    String[] files = ds.getIncludedFiles();
    List<String> fileNameList = Collections.emptyList();
    if (extraSourceFiles != null && extraSourceFiles.getDirectory() != null) {
      try {
        fileNameList =
            FileUtils.getFileNames(
                new File(extraSourceFiles.getDirectory()),
                StringUtils.join(extraSourceFiles.getIncludes().iterator(), ","),
                StringUtils.join(extraSourceFiles.getExcludes().iterator(), ","),
                false);
      } catch (IOException e) {
        throw new MojoExecutionException("error finding extra source files", e);
      }
    }

    File file = createListFile(files, fileNameList);
    if (file != null) {
      cl.createArg().setValue("--files-from=" + file.getAbsolutePath());
    } else {
      for (String file1 : files) {
        cl.createArg().setValue(getAbsolutePath(file1));
      }
    }

    getLog().debug("Executing: " + cl.toString());
    StreamConsumer out = new LoggerStreamConsumer(getLog(), LoggerStreamConsumer.INFO);
    StreamConsumer err = new LoggerStreamConsumer(getLog(), LoggerStreamConsumer.WARN);
    try {
      CommandLineUtils.executeCommandLine(cl, out, err);
    } catch (CommandLineException e) {
      throw new MojoExecutionException("Could not execute " + xgettextCmd + ".", e);
    }
  }
示例#2
0
  private DirectoryScanner scan(FileSet fileSet) {
    File basedir = new File(fileSet.getDirectory());

    if (!basedir.exists() || !basedir.isDirectory()) {
      return null;
    }

    DirectoryScanner scanner = new DirectoryScanner();

    List<String> includesList = fileSet.getIncludes();
    List<String> excludesList = fileSet.getExcludes();

    if (includesList.size() > 0) {
      scanner.setIncludes(includesList.toArray(new String[0]));
    }

    if (excludesList.size() > 0) {
      scanner.setExcludes(excludesList.toArray(new String[0]));
    }

    if (true) // fileSet.isUseDefaultExcludes() )
    {
      scanner.addDefaultExcludes();
    }

    scanner.setBasedir(basedir);
    scanner.setFollowSymlinks(true); // fileSet.isFollowSymlinks() );

    scanner.scan();

    return scanner;
  }
 private File readDirectory(org.apache.maven.model.FileSet mavenFs) {
   if (StringUtils.isBlank(mavenFs.getDirectory())) {
     return pomFileDir;
   }
   return new File(pomFileDir, mavenFs.getDirectory());
 }