ArtifactSet artifacts, boolean onePermutation)
throws UnableToCompleteException {
if (!onePermutation) {
// The artifact to return
ArtifactSet toReturn = new ArtifactSet(artifacts);
// The temporary scss files provided from the artefacts
List<FileInfo> scssFiles = new ArrayList<FileInfo>();
// The public files are provided as inputstream, but the compiler
// needs real files, as they can contain references to other
// files. They will be stored here, with their relative paths intact
String tempFolderName = new Date().getTime() + File.separator;
File tempFolder = createTempDir(tempFolderName);
// Can't search here specifically for public resources, as the type
// is different during compilation. This means we have to loop
// through all the artifacts
for (EmittedArtifact resource : artifacts
.find(EmittedArtifact.class)) {
// Create the temporary files.
String partialPath = resource.getPartialPath();
if (partialPath.endsWith(".scss")) {
// In my opinion, the SCSS file does not need to be
// output to the web content folder, as they can't
// be used there
toReturn.remove(resource);
String fileName = partialPath;
File path = tempFolder;
int separatorIndex = fileName.lastIndexOf(File.separator);
if (-1 != separatorIndex) {
fileName = fileName.substring(separatorIndex + 1);
String filePath = partialPath.substring(0,
separatorIndex);
path = createTempDir(tempFolderName + filePath);
}
File tempfile = new File(path, fileName);
try {
boolean fileCreated = tempfile.createNewFile();
if (fileCreated) {
// write the received inputstream to the temp file
writeFromInputStream(resource.getContents(logger),
tempfile);
// Store the file info for the compilation
scssFiles.add(new FileInfo(tempfile, partialPath));
} else {
logger.log(TreeLogger.WARN, "Duplicate file "
+ tempfile.getPath());
}
} catch (IOException e) {
logger.log(TreeLogger.ERROR,
"Could not write temporary file " + fileName, e);
}
}
}
// Compile the files and store them in the artifact
logger.log(TreeLogger.INFO, "Processing " + scssFiles.size()
+ " Sass file(s)");
for (FileInfo fileInfo : scssFiles) {
logger.log(TreeLogger.INFO, " " + fileInfo.originalScssPath
+ " -> " + fileInfo.getOriginalCssPath());
try {
ScssStylesheet scss = ScssStylesheet.get(fileInfo
.getAbsolutePath());
if (!fileInfo.isMixin()) {
scss.compile();
InputStream is = new ByteArrayInputStream(scss
.printState().getBytes());
toReturn.add(this.emitInputStream(logger, is,
fileInfo.getOriginalCssPath()));
}
fileInfo.getFile().delete();
} catch (CSSException e) {