/** * Copies the resources defined in the 'resources' attribute */ private void copyResources() throws MojoExecutionException { try { // Right now it's not used at all, but could be used to apply resource filters/replacements MavenResourcesExecution resourcesExecution = new MavenResourcesExecution(resources, outputDirectory, project, encoding, Collections.<String>emptyList(), Collections.<String>emptyList(), session); resourcesExecution.setIncludeEmptyDirs(true); resourcesExecution.setAddDefaultExcludes(true); outputResourcesFiltering.filterResources(resourcesExecution); } catch (MavenFilteringException e) { throw new MojoExecutionException("Could not copy resources", e); } }
private static void filterAndCopy(AbstractWisdomMojo mojo, MavenResourcesFiltering filtering, File in, File out) throws IOException { Resource resource = new Resource(); resource.setDirectory(in.getAbsolutePath()); resource.setFiltering(true); resource.setTargetPath(out.getAbsolutePath()); List<String> excludedExtensions = new ArrayList<>(); excludedExtensions.addAll(filtering.getDefaultNonFilteredFileExtensions()); excludedExtensions.addAll(NON_FILTERED_EXTENSIONS); MavenResourcesExecution exec = new MavenResourcesExecution(ImmutableList.of(resource), out, mojo.project, "UTF-8", Collections.<String>emptyList(), excludedExtensions, mojo.session); exec.setEscapeString("\\"); try { filtering.filterResources(exec); } catch (MavenFilteringException e) { throw new IOException("Error while copying resources", e); } }
private void copyNbmResources() throws MojoExecutionException { try { if ( StringUtils.isEmpty( encoding ) && isFilteringEnabled( nbmResources ) ) { getLog().warn( "File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!" ); } MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution( Arrays.asList( nbmResources ), clusterDir, project, encoding, Collections.EMPTY_LIST, Collections.EMPTY_LIST, session ); mavenResourcesExecution.setEscapeWindowsPaths( true ); mavenResourcesFiltering.filterResources( mavenResourcesExecution ); } catch ( MavenFilteringException ex ) { throw new MojoExecutionException( ex.getMessage(), ex ); } }
private void copyNbmResources() throws MojoExecutionException { try { if ( StringUtils.isEmpty( encoding ) && isFilteringEnabled( nbmResources ) ) { getLog().warn( "File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!" ); } MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution( Arrays.asList( nbmResources ), clusterDir, project, encoding, Collections.EMPTY_LIST, Collections.EMPTY_LIST, session ); mavenResourcesExecution.setEscapeWindowsPaths( true ); mavenResourcesFiltering.filterResources( mavenResourcesExecution ); } catch ( MavenFilteringException ex ) { throw new MojoExecutionException( ex.getMessage(), ex ); } }
protected void doCopyPreAssembleDirectory( final String targetDirectory ) throws MojoFailureException { // Create a Resource from the configuration source directory Resource resource = new Resource(); resource.setDirectory( preAssembleDirectory.getAbsolutePath() ); resource.setFiltering( filterPreAssembleDirectory ); List<Resource> resources = new ArrayList<Resource>(); resources.add( resource ); MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution( resources, new File( targetDirectory ), mavenProject, encoding, buildFilters, Collections.<String>emptyList(), session ); mavenResourcesExecution.setEscapeString( escapeString ); // Include empty directories, to be backwards compatible mavenResourcesExecution.setIncludeEmptyDirs( true ); mavenResourcesExecution.setUseDefaultFilterWrappers( true ); try { getLog().info( "Copy pre-assemble files from " + this.preAssembleDirectory.getAbsolutePath() + " to " + targetDirectory ); // Use a MavenResourcesFiltering component to filter and copy the configuration files mavenResourcesFiltering.filterResources( mavenResourcesExecution ); } catch ( MavenFilteringException mfe ) { throw new MojoFailureException( "Failed to copy/filter the configuration files." ); } }
protected void doCopyPreAssembleDirectory( final String targetDirectory ) throws MojoFailureException { // Create a Resource from the configuration source directory Resource resource = new Resource(); resource.setDirectory( preAssembleDirectory.getAbsolutePath() ); resource.setFiltering( filterPreAssembleDirectory ); List<Resource> resources = new ArrayList<Resource>(); resources.add( resource ); MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution( resources, new File( targetDirectory ), mavenProject, encoding, buildFilters, Collections.<String>emptyList(), session ); mavenResourcesExecution.setEscapeString( escapeString ); // Include empty directories, to be backwards compatible mavenResourcesExecution.setIncludeEmptyDirs( true ); mavenResourcesExecution.setUseDefaultFilterWrappers( true ); try { getLog().info( "Copy pre-assemble files from " + this.preAssembleDirectory.getAbsolutePath() + " to " + targetDirectory ); // Use a MavenResourcesFiltering component to filter and copy the configuration files mavenResourcesFiltering.filterResources( mavenResourcesExecution ); } catch ( MavenFilteringException mfe ) { throw new MojoFailureException( "Failed to copy/filter the configuration files." ); } }
excludedExtensions.addAll(NON_FILTERED_EXTENSIONS); MavenResourcesExecution exec = new MavenResourcesExecution(ImmutableList.of(resource), dir, mojo.project, "UTF-8", Collections.<String>emptyList(), excludedExtensions, mojo.session);
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); } }
/** * @throws MojoExecutionException */ private void setDefaultWrappers() throws MojoExecutionException { final MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(); mavenResourcesExecution.setEscapeString( escapeString ); try { defaultFilterWrappers = mavenFileFilter.getDefaultFilterWrappers( project, filters, false, this.session, mavenResourcesExecution ); } catch ( MavenFilteringException e ) { getLog().error( "fail to build filering wrappers " + e.getMessage() ); throw new MojoExecutionException( e.getMessage(), e ); } }
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); } }
new MavenResourcesExecution( resources, new File( targetDirectory ), mavenProject, encoding, buildFilters, Collections.<String>emptyList(), session );
/** * @throws MojoExecutionException */ private void setDefaultWrappers() throws MojoExecutionException { final MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(); mavenResourcesExecution.setEscapeString( escapeString ); try { defaultFilterWrappers = mavenFileFilter.getDefaultFilterWrappers( project, filters, false, this.session, mavenResourcesExecution ); } catch ( MavenFilteringException e ) { getLog().error( "fail to build filering wrappers " + e.getMessage() ); throw new MojoExecutionException( e.getMessage(), e ); } }
new MavenResourcesExecution( resources, new File( targetDirectory ), mavenProject, encoding, buildFilters, Collections.<String>emptyList(), session );
MavenResourcesExecution mre = new MavenResourcesExecution( Arrays.asList(new Resource[] {r}), getWorkingDirectory(), project, encoding, null, null, session );
/** {@inheritDoc} */ @Nonnull public Reader filter( @Nonnull Reader from, boolean filtering, MavenProject mavenProject, List<String> filters, boolean escapedBackslashesInFilePath, MavenSession mavenSession ) throws MavenFilteringException { MavenResourcesExecution mre = new MavenResourcesExecution(); mre.setMavenProject( mavenProject ); mre.setFileFilters( filters ); mre.setEscapeWindowsPaths( escapedBackslashesInFilePath ); mre.setMavenSession( mavenSession ); mre.setInjectProjectBuildFilters( true ); List<FilterWrapper> filterWrappers = getDefaultFilterWrappers( mre ); return filter( from, filtering, filterWrappers ); }
@Nonnull public List<FileUtils.FilterWrapper> getDefaultFilterWrappers( final MavenProject mavenProject, List<String> filters, final boolean escapedBackslashesInFilePath, MavenSession mavenSession, MavenResourcesExecution mavenResourcesExecution ) throws MavenFilteringException { MavenResourcesExecution mre = mavenResourcesExecution == null ? new MavenResourcesExecution() : mavenResourcesExecution.copyOf(); mre.setMavenProject( mavenProject ); mre.setMavenSession( mavenSession ); mre.setFilters( filters ); mre.setEscapedBackslashesInFilePath( escapedBackslashesInFilePath ); return getDefaultFilterWrappers( mre ); }
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); } }
public void filterResource(String directory, String include, String targetPath, File outputDirectory) { Resource resource = new Resource(); resource.setDirectory(directory); resource.addInclude(include); resource.setFiltering(true); resource.setTargetPath(targetPath); MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution( Collections.singletonList(resource), outputDirectory, project, encoding, filters, defaultNonFilteredFileExtensions, session); System.out.println("mavenResourcesExecution: " + mavenResourcesExecution); mavenResourcesExecution.setInjectProjectBuildFilters(false); mavenResourcesExecution.setOverwrite(true); mavenResourcesExecution.setSupportMultiLineFiltering(true); try { mavenResourcesFiltering.filterResources(mavenResourcesExecution); } catch (MavenFilteringException e) { e.printStackTrace(); } }
/** {@inheritDoc} */ public void copyFile( File from, File to, boolean filtering, MavenProject mavenProject, List<String> filters, boolean escapedBackslashesInFilePath, String encoding, MavenSession mavenSession ) throws MavenFilteringException { MavenResourcesExecution mre = new MavenResourcesExecution(); mre.setMavenProject( mavenProject ); mre.setFileFilters( filters ); mre.setEscapeWindowsPaths( escapedBackslashesInFilePath ); mre.setMavenSession( mavenSession ); mre.setInjectProjectBuildFilters( true ); List<FileUtils.FilterWrapper> filterWrappers = getDefaultFilterWrappers( mre ); copyFile( from, to, filtering, filterWrappers, encoding ); }
/** * @return {@link MavenResourcesExecution} */ public MavenResourcesExecution copyOf() { MavenResourcesExecution mre = new MavenResourcesExecution(); mre.setAdditionalProperties( mre.getAdditionalProperties() ); mre.setEncoding( mre.getEncoding() ); mre.setEscapedBackslashesInFilePath( mre.isEscapedBackslashesInFilePath() ); mre.setEscapeString( mre.getEscapeString() ); mre.setFileFilters( copyList( mre.getFileFilters() ) ); mre.setFilterWrappers( copyList( mre.getFilterWrappers() ) ); mre.setIncludeEmptyDirs( mre.isIncludeEmptyDirs() ); mre.setInjectProjectBuildFilters( mre.isInjectProjectBuildFilters() ); mre.setMavenProject( mre.getMavenProject() ); mre.setMavenSession( mre.getMavenSession() ); mre.setNonFilteredFileExtensions( copyList( mre.getNonFilteredFileExtensions() ) ); mre.setOutputDirectory( mre.getOutputDirectory() ); mre.setOverwrite( mre.isOverwrite() ); mre.setProjectStartExpressions( copyList( mre.getProjectStartExpressions() ) ); mre.setResources( copyList( mre.getResources() ) ); mre.setResourcesBaseDirectory( mre.getResourcesBaseDirectory() ); mre.setUseDefaultFilterWrappers( mre.isUseDefaultFilterWrappers() ); mre.setAddDefaultExcludes( mre.isAddDefaultExcludes() ); mre.setSupportMultiLineFiltering( mre.isSupportMultiLineFiltering() ); return mre; }