Example #1
0
  protected void filter(File sourceFile, File targetFile) throws MojoExecutionException {
    try {

      if (StringUtils.isEmpty(encoding)) {
        getLog()
            .warn(
                "File encoding has not been set, using platform encoding "
                    + ReaderFactory.FILE_ENCODING
                    + ", i.e. build is platform dependent!");
      }
      targetFile.getParentFile().mkdirs();

      final MavenResourcesExecution mre = new MavenResourcesExecution();
      mre.setMavenProject(project);
      mre.setMavenSession(mavenSession);
      mre.setFilters(null);
      mre.setEscapedBackslashesInFilePath(true);
      final LinkedHashSet<String> delimiters = new LinkedHashSet<>();
      delimiters.add("${*}");
      mre.setDelimiters(delimiters);

      @SuppressWarnings("rawtypes")
      List filters = mavenFileFilter.getDefaultFilterWrappers(mre);
      mavenFileFilter.copyFile(sourceFile, targetFile, true, filters, encoding, true);
    } catch (MavenFilteringException e) {
      throw new MojoExecutionException(e.getMessage(), e);
    }
  }
  private void filterResources() throws MojoExecutionException {
    try {
      MavenResourcesExecution execution =
          new MavenResourcesExecution(
              getResources(),
              getFilteredAppDirectory(),
              project,
              encoding,
              filters,
              Collections.EMPTY_LIST,
              session);
      execution.setEscapeWindowsPaths(escapeWindowsPaths);
      execution.setSupportMultiLineFiltering(supportMultiLineFiltering);
      if (nonFilteredFileExtensions != null) {
        execution.setNonFilteredFileExtensions(nonFilteredFileExtensions);
      }

      resourceFilter.filterResources(execution);
    } catch (MavenFilteringException e) {
      throw new MojoExecutionException("Error while filtering Mule config files", e);
    }
  }