Copies given resources to the build directory.

@param fileSets A list of FileSet objects that represent additional
resources to copy.
@throws MojoExecutionException In case of a resource copying error.
438792
private List<String> copyResources(File targetDirectory, List<FileSet> fileSets) throws MojoExecutionException {
        ArrayList<String> addedFiles = new ArrayList<String>();
        for (FileSet fileSet : fileSets) {
            // Get the absolute base directory for the FileSet
            File sourceDirectory = new File(fileSet.getDirectory());

            if (!sourceDirectory.isAbsolute()) {
                sourceDirectory = new File(project.getBasedir(), sourceDirectory.getPath());
            }

            if (!sourceDirectory.exists()) {
                // If the requested directory does not exist, log it and carry on
                getLog().warn("Specified source directory " + sourceDirectory.getPath() + " does not exist.");
                continue;
            }

            List<String> includedFiles = scanFileSet(sourceDirectory, fileSet);
            addedFiles.addAll(includedFiles);

            getLog().info("Copying " + includedFiles.size() + " additional resource" + (includedFiles.size() > 1 ? "s" : ""));

            for (String destination : includedFiles) {
                File source = new File(sourceDirectory, destination);
                File destinationFile = new File(targetDirectory, destination);

                // Make sure that the directory we are copying into exists
                destinationFile.getParentFile().mkdirs();

                try {
                    FileUtils.copyFile(source, destinationFile);
                    destinationFile.setExecutable(fileSet.isExecutable(),false);

                } catch (IOException e) {
                    throw new MojoExecutionException("Error copying additional resource " + source, e);
                }
            }
        }
        return addedFiles;
    }
1289837
public static void copyConfiguration(AbstractWisdomWatcherMojo mojo, MavenResourcesFiltering filtering) throws
            IOException {
        File in = new File(mojo.basedir, Constants.CONFIGURATION_SRC_DIR);
        if (in.isDirectory()) {
            File out = new File(mojo.getWisdomRootDirectory(), Constants.CONFIGURATION_DIR);
            filterAndCopy(mojo, filtering, in, out);
        } else {
            mojo.getLog().warn("No configuration directory (src/main/configuration) - use this mode at your own risk");
            mojo.getLog().warn("A fake application configuration is going to be created, " +
                    "using a fake application secret, do not use this file in production");
            // No configuration directory, generate a fake application configuration
            File conf = new File(mojo.getWisdomRootDirectory(), "conf");
            mojo.getLog().debug("Creating conf directory " + conf.mkdirs());
            File output = new File(conf, "application.conf");
            ApplicationSecretGenerator.generateFakeConfiguration(output);
        }
    }
695012
@Override
    public void execute()
            throws MojoExecutionException, MojoFailureException
    {

        // ---
        // Check configuration and get all configured jar resources
        // ---

        checkConfiguration();

        // ---
        // Prepare working directory layout
        // ---

        IOUtil ioUtil = getIoUtil();

        ioUtil.makeDirectoryIfNecessary( getWorkDirectory() );
        ioUtil.copyResources( getResourcesDirectory(), getWorkDirectory() );

        // ---
        // Resolve common jar resources
        // ---

        getLog().info( "-- Prepare commons jar resources" );
        Set<ResolvedJarResource> resolvedCommonJarResources;

        if ( CollectionUtils.isEmpty( commonJarResources ) )
        {
            resolvedCommonJarResources = Collections.emptySet();
        }
        else
        {
            resolvedCommonJarResources = resolveJarResources( commonJarResources, null );
        }

        Set<ResolvedJarResource> allResolvedJarResources = new LinkedHashSet<>();
        allResolvedJarResources.addAll( resolvedCommonJarResources );

        // ---
        // Resolved jnlpFiles
        // ---

        getLog().info( "-- Prepare jnlp files" );
        Set<ResolvedJnlpFile> resolvedJnlpFiles = new LinkedHashSet<>();

        for ( JnlpFile jnlpFile : jnlpFiles )
        {
            verboseLog( "prepare jnlp " + jnlpFile );

            // resolve jar resources of the jnpl file
            Set<ResolvedJarResource> resolvedJarResources =
                    resolveJarResources( jnlpFile.getJarResources(), resolvedCommonJarResources );

            // keep them (to generate the versions.xml file)
            allResolvedJarResources.addAll( resolvedJarResources );

            // create the resolved jnlp file
            ResolvedJnlpFile resolvedJnlpFile = new ResolvedJnlpFile( jnlpFile, resolvedJarResources );
            resolvedJnlpFiles.add( resolvedJnlpFile );
        }

        // ---
        // Process collected jars
        // ---

        signOrRenameJars();

        // ---
        // Generate jnlp files
        // ---

        for ( ResolvedJnlpFile jnlpFile : resolvedJnlpFiles )
        {
            generateJnlpFile( jnlpFile, getLibPath() );
        }

        // ---
        // Generate version xml file
        // ---

        generateVersionXml( allResolvedJarResources );

        // ---
        // Copy to final directory
        // ---

        //FIXME Should be able to configure this
        File outputDir = new File( getProject().getBuild().getDirectory(),
                                   getProject().getBuild().getFinalName() + File.separator + outputDirectoryName );

        ioUtil.copyDirectoryStructure( getWorkDirectory(), outputDir );
    }
906405
protected void createFile(File stagingDirectory) throws MojoExecutionException {
        File targetDirectory = newSubdirectory(stagingDirectory, "META-INF");
        File newEntry = new File(targetDirectory, filename);

        try (FileOutputStream out = new FileOutputStream(newEntry); PrintStream ps = new PrintStream(out);) {
            
            Iterator<ConfigEntry> iter = entries.values().iterator();
            ConfigEntry entry = null;

            for (int i = 0; i < buffer.size(); i++) {
                if (entry == null && iter.hasNext()) {
                    entry = iter.next();
                }

                if (entry != null && entry.placeholder == i) {
                    for (String line : entry.buffer) {
                        ps.println(line);
                    }

                    entry = null;
                    continue;
                }

                ps.println(buffer.get(i));
            }
        } catch (Exception e) {
            throw new MojoExecutionException("Unexpected error while creating configuration file.", e);
        }
    }
219700
@Override
	protected void setup() throws MojoExecutionException {
		if (verbose) {
			getLog().info("Rox configuration is generated");
		}
		
		// Check if the ROX configuration is available
		if (roxActive && roxConfig != null) {
			// Check the ROX configuration file
			if (!roxConfig.exists() || !roxConfig.isFile() || !roxConfig.getAbsolutePath().endsWith(".yml")) {
				getLog().warn("The " + ROX_PROPERTIES_FILENAME + " configuration seems not to be a valid file or path is incorrect. Rox will be disabled.");
				roxActive = false;
			}
			else {
				try {
					// Prepare the resource to copy
					Resource r = new Resource();
					r.setFiltering(true);
					r.setDirectory(roxConfig.getParent());
					r.setIncludes(Arrays.asList(new String[] {roxConfig.getName()}));

					// Configure the resource filtering
					MavenResourcesExecution mre = new MavenResourcesExecution(
						Arrays.asList(new Resource[] {r}), getWorkingDirectory(), project, encoding, null, null, session
					);
					
					// Filter the resources
					mavenResourcesFiltering.filterResources(mre);
				}
				catch (MavenFilteringException mfe) {
					getLog().warn("Unable to filter the " + ROX_PROPERTIES_FILENAME + " file. Rox will be disabled.", mfe);
					roxActive = false;
				}
			}
		}
		else {
			getLog().info("No rox configuration to use");
			roxActive = false;
		}		
	}
1167435
protected void installChecksums( Collection metadataFiles )
            throws MojoExecutionException
    {
        for ( Iterator it = metadataFiles.iterator(); it.hasNext(); )
        {
            File metadataFile = (File) it.next();
            installChecksums( metadataFile );
        }
    }
806887
public void setFileSystems(java.util.Collection<FileSystem> fileSystems) {
        if (fileSystems == null) {
            this.fileSystems = null;
            return;
        }

        this.fileSystems = new java.util.ArrayList<FileSystem>(fileSystems);
    }
133259
@Override
	protected void cleanup() throws MojoExecutionException {
		if (verbose) {
			getLog().info("Clean the rox configuration files");
		}
		
		if (roxActive) {
			// Cleanup the rox configuration files
			useCleanPlugin(
				element("filesets", 
					element("fileset",
						element("directory", getWorkingDirectory().getAbsolutePath()),
						element("followSymlinks", "false"),
						element("includes",
							element("include", ROX_PROPERTIES_FILENAME) // Clean ROX configuration file
						)
					)
				)
			);
		}
	}
131015
protected Collection<ResourceFile> getAllResourceFiles()
        throws MojoExecutionException
    {
        try
        {
            Set<ResourceFile> sourcesAndResources = new HashSet<ResourceFile>();
            Set<String> sourcesAndResourcesPath = new HashSet<String>();
            sourcesAndResourcesPath.addAll( getProject().getCompileSourceRoots() );
            for ( Resource resource : getProject().getResources() )
            {
                sourcesAndResourcesPath.add( resource.getDirectory() );
            }

            for ( String name : getModules() )
            {
                GwtModule module = readModule( name );

                sourcesAndResources.add( getDescriptor( module, sourcesAndResourcesPath ) );
                int count = 1;

                for ( String source : module.getSources() )
                {
                    getLog().debug( "GWT sources from " + name + '.' + source );
                    Collection<ResourceFile> files = getAsResources( module, source, sourcesAndResourcesPath,
                                                                     "**/*.java" );
                    sourcesAndResources.addAll( files );
                    count += files.size();

                    Collection<ResourceFile> uifiles = getAsResources( module, source, sourcesAndResourcesPath,
                            "**/*.ui.xml" );
                    sourcesAndResources.addAll( uifiles );
                    count += uifiles.size();
                }
                for ( String source : module.getSuperSources() )
                {
                    getLog().debug( "GWT super-sources from " + name + '.' + source );
                    Collection<ResourceFile> files = getAsResources( module, source, sourcesAndResourcesPath,
                                                                     "**/*.java" );
                    sourcesAndResources.addAll( files );
                    count += files.size();

                    Collection<ResourceFile> uifiles = getAsResources( module, source, sourcesAndResourcesPath,
                            "**/*.ui.xml" );
                    sourcesAndResources.addAll( uifiles );
                    count += uifiles.size();
                }
                getLog().info( count + " source files from GWT module " + name );
            }
            return sourcesAndResources;
        }
        catch ( GwtModuleReaderException e )
        {
            throw new MojoExecutionException( e.getMessage(), e );
        }
    }
684518
private void copyResources(File outputDirectory) throws IOException
    {
        copyClasspathResource(outputDirectory, "reportng.css", "reportng.css");
        copyClasspathResource(outputDirectory, "reportng.js", "reportng.js");
        // If there is a custom stylesheet, copy that.
        File customStylesheet = META.getStylesheetPath();

        if (customStylesheet != null)
        {
            if (customStylesheet.exists())
            {
                copyFile(outputDirectory, customStylesheet, CUSTOM_STYLE_FILE);
            }
            else
            {
                // If not found, try to read the file as a resource on the classpath
                // useful when reportng is called by a jarred up library
                InputStream stream = ClassLoader.getSystemClassLoader().getResourceAsStream(customStylesheet.getPath());
                if (stream != null)
                {
                    copyStream(outputDirectory, stream, CUSTOM_STYLE_FILE);
                }
            }
        }
    }
140825
public void copyLatexSrcToTempDir( File texDirectory, File tempDirectory )
        throws MojoExecutionException
    {
        try
        {
            if ( tempDirectory.exists() )
            {
                log.info( "Deleting existing directory " + tempDirectory.getPath() );
                FileUtils.deleteDirectory( tempDirectory );
            }

            log.debug( "Copying TeX source directory (" + texDirectory.getPath() + ") to temporary directory ("
                + tempDirectory + ")" );
            FileUtils.copyDirectory( texDirectory, tempDirectory );
        }
        catch ( IOException e )
        {
            throw new MojoExecutionException( "Failure copying the TeX directory (" + texDirectory.getPath()
                + ") to a temporary directory (" + tempDirectory.getPath() + ").", e );
        }
    }
572831
static void copyFileFromResources(String sourcePath, String destPath) throws IOException {
        LOGGER.entering(new Object[] { sourcePath, destPath });

        File downloadFile = new File(destPath);

        if (!downloadFile.exists()) {
            InputStream stream = JarSpawner.class.getResourceAsStream(sourcePath);
            FileUtils.copyInputStreamToFile(stream, downloadFile);
            LOGGER.fine("File copied to " + destPath);
        }
        LOGGER.exiting();
    }
192288
public void setConfigurationSets(java.util.Collection<String> configurationSets) {
        if (configurationSets == null) {
            this.configurationSets = null;
            return;
        }

        this.configurationSets = new java.util.ArrayList<String>(configurationSets);
    }
879309
protected void extendProjectCompileRootsAndResources() throws MojoExecutionException {
		if (project != null) {
			try {
				extendCompileSourceRoots();
				extendResources(outletResDir, false);
				extendResources(outletResOnceDir, false);
				extendResources(outletResTestDir, true);
				extendResources(outletResTestOnceDir, true);
			} catch (Exception ex) {
				throw new MojoExecutionException("Could not extend the " + "projects compile paths", ex);
			}
		}
	}
1335540
public void add(ResourceCollection rc) {
    if (rc instanceof FileSet) {
      FileSet fs = (FileSet) rc;
      fs.setProject(getProject());
    }
    resources.add(rc);
  }
744917
public void execute() throws MojoExecutionException {
        getLog().debug("starting packaging");
        
        AbstractConfiguration[] configurations= (AbstractConfiguration[]) getPluginContext().get(ConfiguratorMojo.GENERATED_CONFIGURATIONS_KEY);
        
        try {
            for(AbstractConfiguration configuration : configurations) {
                if(!(configuration instanceof NodeConfiguration)) {
                    continue;
                }
                
                String classifier= configuration.className.substring(configuration.className.lastIndexOf('.') + 1);
                File jarFile= checkJarFile(classifier);
                JavaApplicationDescriptor descriptor= getDescriptor();
                descriptor.setNodeConfiguration(configuration.className);
                descriptor.setJarFile(jarFile);
                File jadFile= getJadFile(classifier);
                getDescriptor().writeDescriptor(jadFile);
                getProjectHelper().attachArtifact(getProject(), "jad", classifier, jadFile);
            }
        } catch (IOException ioe) {
            throw new MojoExecutionException("could not create .jad file", ioe);
        } catch (RuntimeException e) {
            throw new MojoExecutionException("could not create .jad file", e);
        }
        getLog().debug("finished packaging");
    }
1366981
public static void copyExternalAssets(AbstractWisdomMojo mojo, MavenResourcesFiltering filtering) throws IOException {
        File in = new File(mojo.basedir, Constants.ASSETS_SRC_DIR);
        if (!in.exists()) {
            return;
        }
        File out = new File(mojo.getWisdomRootDirectory(), Constants.ASSETS_DIR);
        filterAndCopy(mojo, filtering, in, out);
    }