use of com.helger.commons.io.file.FileSystemRecursiveIterator in project ph-css by phax.
the class AbstractFuncTestCSSReader method testReadBadButRecoverable.
protected final void testReadBadButRecoverable(@Nonnull final String sBaseDir) {
final File aBaseDir = new File(sBaseDir);
if (!aBaseDir.exists())
throw new IllegalArgumentException("BaseDir " + sBaseDir + " does not exist!");
for (final File aFile : new FileSystemRecursiveIterator(aBaseDir).withFilter(IFileFilter.filenameEndsWith(".css"))) {
final String sKey = aFile.getAbsolutePath();
if (m_bDebug)
m_aLogger.info(sKey);
// Handle each error as a fatal error!
final CollectingCSSParseErrorHandler aErrorHdl = new CollectingCSSParseErrorHandler();
m_aReaderSettings.setCustomErrorHandler(aErrorHdl.and(new LoggingCSSParseErrorHandler()));
final CascadingStyleSheet aCSS = CSSReader.readFromFile(aFile, m_aReaderSettings);
assertNotNull(sKey, aCSS);
assertTrue(sKey, aErrorHdl.hasParseErrors());
assertTrue(sKey, aErrorHdl.getParseErrorCount() > 0);
if (m_bDebug)
m_aLogger.info(aErrorHdl.getAllParseErrors().toString());
// Write optimized version and re-read it
final String sCSS = new CSSWriter(m_aWriterSettings.setOptimizedOutput(true)).getCSSAsString(aCSS);
assertNotNull(sKey, sCSS);
if (m_bDebug)
m_aLogger.info(sCSS);
final CascadingStyleSheet aCSSReRead = CSSReader.readFromStringReader(sCSS, m_aReaderSettings);
assertNotNull("Failed to parse:\n" + sCSS, aCSSReRead);
assertEquals(sKey, aCSS, aCSSReRead);
}
}
use of com.helger.commons.io.file.FileSystemRecursiveIterator in project ph-css by phax.
the class AbstractFuncTestCSSReader method testReadBad.
protected final void testReadBad(@Nonnull final String sBaseDir) {
final File aBaseDir = new File(sBaseDir);
if (!aBaseDir.exists())
throw new IllegalArgumentException("BaseDir " + sBaseDir + " does not exist!");
for (final File aFile : new FileSystemRecursiveIterator(aBaseDir).withFilter(IFileFilter.filenameEndsWith(".css"))) {
final String sKey = aFile.getAbsolutePath();
if (m_bDebug)
m_aLogger.info(sKey);
// Handle each error as a fatal error!
final CascadingStyleSheet aCSS = CSSReader.readFromFile(aFile, m_aReaderSettings);
assertNull(sKey, aCSS);
}
}
use of com.helger.commons.io.file.FileSystemRecursiveIterator in project ph-css by phax.
the class CSSVisitor30FuncTest method testVisitContent30.
@Test
public void testVisitContent30() {
for (final File aFile : new FileSystemRecursiveIterator(new File("src/test/resources/testfiles/css30/good")).withFilter(IFileFilter.filenameEndsWith(".css"))) {
final String sKey = aFile.getAbsolutePath();
if (true)
s_aLogger.info(sKey);
final CascadingStyleSheet aCSS = CSSReader.readFromFile(aFile, new CSSReaderSettings().setFallbackCharset(StandardCharsets.UTF_8).setCSSVersion(ECSSVersion.CSS30).setCustomErrorHandler(new LoggingCSSParseErrorHandler()).setBrowserCompliantMode(true));
assertNotNull(sKey, aCSS);
CSSVisitor.visitCSSUrl(aCSS, new MockUrlVisitor(sKey));
}
}
use of com.helger.commons.io.file.FileSystemRecursiveIterator in project ph-schematron by phax.
the class SchematronTestHelper method _readDI.
@Nonnull
private static ICommonsList<SchematronTestFile> _readDI(@Nonnull final IReadableResource aRes) {
if (false)
ClassPathHelper.getAllClassPathEntries().forEach(x -> {
System.out.println(x);
if (new File(x).isDirectory()) {
final FileSystemRecursiveIterator it = new FileSystemRecursiveIterator(new File(x));
it.forEach(y -> System.out.println(StringHelper.getRepeated(" ", it.getLevel()) + y));
}
});
ValueEnforcer.notNull(aRes, "Resource");
ValueEnforcer.isTrue(aRes.exists(), () -> "Resource " + aRes + " does not exist!");
final ICommonsList<SchematronTestFile> ret = new CommonsArrayList<>();
final IMicroDocument aDoc = MicroReader.readMicroXML(aRes);
if (aDoc == null)
throw new IllegalArgumentException("Failed to open/parse " + aRes + " as XML");
String sLastParentDirBaseName = null;
for (final IMicroElement eItem : aDoc.getDocumentElement().getAllChildElements()) if (eItem.getTagName().equals("directory"))
sLastParentDirBaseName = eItem.getAttributeValue("basename");
else if (eItem.getTagName().equals("file"))
ret.add(new SchematronTestFile(sLastParentDirBaseName, new ClassPathResource(eItem.getAttributeValue("name")), eItem.getAttributeValue("basename")));
else
throw new IllegalArgumentException("Cannot handle " + eItem);
return ret;
}
use of com.helger.commons.io.file.FileSystemRecursiveIterator in project ph-css by phax.
the class AbstractFuncTestCSSReader method testReadGood.
protected final void testReadGood(@Nonnull final String sBaseDir) {
final File aBaseDir = new File(sBaseDir);
if (!aBaseDir.exists())
throw new IllegalArgumentException("BaseDir " + sBaseDir + " does not exist!");
for (final File aFile : new FileSystemRecursiveIterator(aBaseDir).withFilter(IFileFilter.filenameEndsWith(".css"))) {
final String sKey = aFile.getAbsolutePath();
if (m_bDebug)
m_aLogger.info("Filename: " + sKey);
final CollectingCSSParseErrorHandler aErrorHdl = new CollectingCSSParseErrorHandler();
m_aReaderSettings.setCustomErrorHandler(aErrorHdl.and(new LoggingCSSParseErrorHandler()));
final CascadingStyleSheet aCSS = CSSReader.readFromFile(aFile, m_aReaderSettings);
assertNotNull(sKey, aCSS);
// May have errors or not
if (m_bDebug)
m_aLogger.info("Parse errors: " + aErrorHdl.getAllParseErrors().toString());
CommonsTestHelper.testDefaultSerialization(aCSS);
// Write optimized version and compare it
String sCSS = new CSSWriter(m_aWriterSettings.setOptimizedOutput(true)).getCSSAsString(aCSS);
assertNotNull(sKey, sCSS);
if (m_bDebug)
m_aLogger.info("Created CSS: " + sCSS);
final CascadingStyleSheet aCSSReRead = CSSReader.readFromStringReader(sCSS, m_aReaderSettings);
assertNotNull("Failed to parse " + sKey + ":\n" + sCSS, aCSSReRead);
assertEquals(sKey + "\n" + sCSS, aCSS, aCSSReRead);
// Write non-optimized version and compare it
sCSS = new CSSWriter(m_aWriterSettings.setOptimizedOutput(false)).getCSSAsString(aCSS);
assertNotNull(sKey, sCSS);
if (m_bDebug)
m_aLogger.info("Read and re-created CSS: " + sCSS);
assertEquals(sKey, aCSS, CSSReader.readFromStringReader(sCSS, m_aReaderSettings));
// Write non-optimized and code-removed version and ensure it is not
// null
sCSS = new CSSWriter(m_aWriterSettings.setOptimizedOutput(false).setRemoveUnnecessaryCode(true)).getCSSAsString(aCSS);
assertNotNull(sKey, sCSS);
assertNotNull(sKey, CSSReader.readFromStringReader(sCSS, m_aReaderSettings));
// Restore value :)
m_aWriterSettings.setRemoveUnnecessaryCode(false);
}
}
Aggregations