in maven2-plugins/myfaces-faces-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/faces/GenerateMasterFacesConfigMojo.java [48:168]
public void execute() throws MojoExecutionException
{
try
{
addResourceRoot(project, targetDirectory.getCanonicalPath());
// Scan for .xrts sources
String [] xmlFiles;
if (inheritedDirectory != null)
{
HashSet set = new HashSet();
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(new File(sourceDirectory, sourcePath));
scanner.addDefaultExcludes();
scanner.setIncludes(new String[] { "**/*.xml" });
if (excludes != null)
{
scanner.setExcludes(excludes);
}
scanner.scan();
String [] sourceFiles = scanner.getIncludedFiles();
for (int i = 0; i < sourceFiles.length;i++)
{
set.add(sourceFiles[i]);
}
scanner.setBasedir(new File(inheritedDirectory,sourcePath));
scanner.scan();
sourceFiles = scanner.getIncludedFiles();
for (int i = 0; i < sourceFiles.length;i++)
{
set.add(sourceFiles[i]);
}
Object [] result = set.toArray();
xmlFiles = new String[result.length];
for (int i = 0; i < result.length; i++)
{
xmlFiles[i] = (String) result[i];
}
}
else
{
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(new File(sourceDirectory, sourcePath));
scanner.addDefaultExcludes();
scanner.setIncludes(new String[] { "**/*.xml" });
if (excludes != null)
{
scanner.setExcludes(excludes);
}
scanner.scan();
xmlFiles = scanner.getIncludedFiles();
}
long lastModified = 0L;
for (int i=0; i < xmlFiles.length; i++)
{
lastModified = Math.max(lastModified,
new File(xmlFiles[i]).lastModified());
}
File targetFile = new File(targetDirectory, targetPath);
if (!force && targetFile.lastModified() > lastModified)
{
getLog().info("Nothing to generate - " + targetPath + " is up to date");
}
else
{
getLog().info("Generating " + targetPath);
targetFile.delete();
targetFile.getParentFile().mkdirs();
OutputStream out = new BufferedOutputStream(new FileOutputStream(targetFile));
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(out);
writer.writeStartDocument("1.0");
writer.writeCharacters("\n");
writer.writeStartElement("faces-config");
writer.writeDefaultNamespace("http://java.sun.com/xml/ns/javaee");
writer.writeNamespace("xi", "http://www.w3.org/2001/XInclude");
writer.writeCharacters("\n");
for (int i=0; i < xmlFiles.length; i++)
{
String xmlFile = xmlFiles[i];
if (File.separatorChar == '\\')
{
xmlFile = xmlFile.replaceAll("\\\\", "/");
}
writer.writeCharacters(" ");
writer.writeStartElement("http://www.w3.org/2001/XInclude", "include");
writer.writeAttribute("href", xmlFile);
writer.writeAttribute("xpointer", "/faces-config/*");
writer.writeEndElement();
writer.writeCharacters("\n");
}
writer.writeEndDocument();
writer.close();
targetFile.setReadOnly();
}
}
catch (XMLStreamException e)
{
throw new MojoExecutionException("Error during generation", e);
}
catch (IOException e)
{
throw new MojoExecutionException("Error during generation", e);
}
}