From b6feca3324b400e7abf870515ec8213715187c71 Mon Sep 17 00:00:00 2001 From: Haijian Wang Date: Tue, 26 Feb 2013 13:32:28 +0200 Subject: Fixed several problems related to @extend directive (Ticket #10976) Change-Id: I5e409856601aa514965319453c11946028b08dda --- .../com/vaadin/sass/internal/ScssStylesheet.java | 2 + .../com/vaadin/sass/internal/util/StringUtil.java | 78 +++++++++++++++++++--- .../sass/internal/visitor/ExtendNodeHandler.java | 57 ++++++++++++---- .../automatic/css/extend-in-nested-block.css | 7 ++ .../css/extend-selector-in-different-levels.css | 15 +++++ ...ding-non-exist-selector-with-same-beginning.css | 7 ++ .../automatic/css/extending-same-selector.css | 7 ++ .../css/extending-selector-with-same-beginning.css | 7 ++ .../automatic/scss/extend-in-nested-block.scss | 11 +++ .../scss/extend-selector-in-different-levels.scss | 26 ++++++++ ...ing-non-exist-selector-with-same-beginning.scss | 8 +++ .../automatic/scss/extending-same-selector.scss | 8 +++ .../extending-selector-with-same-beginning.scss | 8 +++ .../sasslang/css/19-test_control_flow_if.css | 7 ++ .../sasslang/scss/19-test_control_flow_if.scss | 10 +++ .../sasslangbroken/css/19-test_control_flow_if.css | 7 -- .../scss/19-test_control_flow_if.scss | 10 --- .../vaadin/sass/internal/util/StringUtilTest.java | 58 ++++++++++++++++ 18 files changed, 294 insertions(+), 39 deletions(-) create mode 100644 theme-compiler/tests/resources/automatic/css/extend-in-nested-block.css create mode 100644 theme-compiler/tests/resources/automatic/css/extend-selector-in-different-levels.css create mode 100644 theme-compiler/tests/resources/automatic/css/extending-non-exist-selector-with-same-beginning.css create mode 100644 theme-compiler/tests/resources/automatic/css/extending-same-selector.css create mode 100644 theme-compiler/tests/resources/automatic/css/extending-selector-with-same-beginning.css create mode 100644 theme-compiler/tests/resources/automatic/scss/extend-in-nested-block.scss create mode 100644 theme-compiler/tests/resources/automatic/scss/extend-selector-in-different-levels.scss create mode 100644 theme-compiler/tests/resources/automatic/scss/extending-non-exist-selector-with-same-beginning.scss create mode 100644 theme-compiler/tests/resources/automatic/scss/extending-same-selector.scss create mode 100644 theme-compiler/tests/resources/automatic/scss/extending-selector-with-same-beginning.scss create mode 100644 theme-compiler/tests/resources/sasslang/css/19-test_control_flow_if.css create mode 100644 theme-compiler/tests/resources/sasslang/scss/19-test_control_flow_if.scss delete mode 100644 theme-compiler/tests/resources/sasslangbroken/css/19-test_control_flow_if.css delete mode 100644 theme-compiler/tests/resources/sasslangbroken/scss/19-test_control_flow_if.scss (limited to 'theme-compiler') diff --git a/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java b/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java index 64279ad1e7..688d569dff 100644 --- a/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java +++ b/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java @@ -42,6 +42,7 @@ import com.vaadin.sass.internal.tree.MixinDefNode; import com.vaadin.sass.internal.tree.Node; import com.vaadin.sass.internal.tree.VariableNode; import com.vaadin.sass.internal.tree.controldirective.IfElseDefNode; +import com.vaadin.sass.internal.visitor.ExtendNodeHandler; import com.vaadin.sass.internal.visitor.ImportNodeHandler; public class ScssStylesheet extends Node { @@ -172,6 +173,7 @@ public class ScssStylesheet extends Node { variables.clear(); ifElseDefNodes.clear(); lastNodeAdded.clear(); + ExtendNodeHandler.clear(); importOtherFiles(this); populateDefinitions(this); traverse(this); diff --git a/theme-compiler/src/com/vaadin/sass/internal/util/StringUtil.java b/theme-compiler/src/com/vaadin/sass/internal/util/StringUtil.java index cf227fe3a3..b20e8bab61 100644 --- a/theme-compiler/src/com/vaadin/sass/internal/util/StringUtil.java +++ b/theme-compiler/src/com/vaadin/sass/internal/util/StringUtil.java @@ -17,8 +17,10 @@ package com.vaadin.sass.internal.util; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.regex.Matcher; @@ -145,14 +147,7 @@ public class StringUtil { * @return true if the text contains the SCSS variable, false if not */ public static boolean containsVariable(String text, String varName) { - StringBuilder builder = new StringBuilder(); - // (?![\\w-]) means lookahead, the next one shouldn't be a word - // character nor a dash. - builder.append("\\$").append(Pattern.quote(varName)) - .append("(?![\\w-])"); - Pattern pattern = Pattern.compile(builder.toString()); - Matcher matcher = pattern.matcher(text); - return matcher.find(); + return containsSubString(text, "$" + varName); } /** @@ -162,18 +157,81 @@ public class StringUtil { * @param text * text which contains the SCSS variable * @param varName - * SCSS variable name + * SCSS variable name (Without '$' sign) * @param value * the value of the SCSS variable * @return the String after replacing */ public static String replaceVariable(String text, String varName, String value) { + return replaceSubString(text, "$" + varName, value); + } + + /** + * Check if a String contains a sub string, using whole word match. + * + * @param text + * text to be checked + * @Param sub Sub String to be checked. + * @return true if the text contains the sub string, false if not + */ + public static boolean containsSubString(String text, String sub) { StringBuilder builder = new StringBuilder(); // (?![\\w-]) means lookahead, the next one shouldn't be a word // character nor a dash. - builder.append("\\$").append(Pattern.quote(varName)) + builder.append("(? subStrings = Arrays.asList(motherString.split(Pattern + .quote(splitter))); + LinkedHashSet uniqueSubStrings = new LinkedHashSet( + subStrings); + StringBuilder builder = new StringBuilder(); + int count = 0; + for (String uniqueSubString : uniqueSubStrings) { + count++; + builder.append(uniqueSubString); + if (count < uniqueSubStrings.size()) { + builder.append(splitter); + } + } + return builder.toString(); + } } diff --git a/theme-compiler/src/com/vaadin/sass/internal/visitor/ExtendNodeHandler.java b/theme-compiler/src/com/vaadin/sass/internal/visitor/ExtendNodeHandler.java index f7917fff6e..e4a69ea5f3 100644 --- a/theme-compiler/src/com/vaadin/sass/internal/visitor/ExtendNodeHandler.java +++ b/theme-compiler/src/com/vaadin/sass/internal/visitor/ExtendNodeHandler.java @@ -26,6 +26,7 @@ import com.vaadin.sass.internal.ScssStylesheet; import com.vaadin.sass.internal.tree.BlockNode; import com.vaadin.sass.internal.tree.ExtendNode; import com.vaadin.sass.internal.tree.Node; +import com.vaadin.sass.internal.util.StringUtil; public class ExtendNodeHandler { private static Map>> extendsMap = new HashMap>>(); @@ -35,6 +36,12 @@ public class ExtendNodeHandler { modifyTree(ScssStylesheet.get()); } + public static void clear() { + if (extendsMap != null) { + extendsMap.clear(); + } + } + private static void modifyTree(Node node) throws Exception { for (Node child : node.getChildren()) { if (child instanceof BlockNode) { @@ -51,7 +58,8 @@ public class ExtendNodeHandler { } else { for (Entry>> entry : extendsMap .entrySet()) { - if (selectorString.contains(entry.getKey())) { + if (StringUtil.containsSubString(selectorString, + entry.getKey())) { for (ArrayList sList : entry.getValue()) { ArrayList clone = (ArrayList) sList .clone(); @@ -71,22 +79,36 @@ public class ExtendNodeHandler { if (extendsMap.get(extendedString) == null) { extendsMap.put(extendedString, new ArrayList>()); } - extendsMap.get(extendedString).add( - ((BlockNode) node.getParentNode()).getSelectorList()); + // prevent a selector extends itself, e.g. .test{ @extend .test} + String parentSelectorString = ((BlockNode) node.getParentNode()) + .getSelectors(); + if (!parentSelectorString.equals(extendedString)) { + extendsMap.get(extendedString).add( + ((BlockNode) node.getParentNode()).getSelectorList()); + } } private static void addAdditionalSelectorListToBlockNode( - BlockNode blockNode, ArrayList list, String selectorString) { - if (list != null) { - for (int i = 0; i < list.size(); i++) { - if (selectorString == null) { - blockNode.getSelectorList().add(list.get(i)); + BlockNode blockNode, ArrayList extendingSelectors, + String extendedSelector) { + if (extendingSelectors != null) { + for (String extendingSelector : extendingSelectors) { + if (extendedSelector == null) { + blockNode.getSelectorList().add(extendingSelector); } else { ArrayList newTags = new ArrayList(); - for (final String existing : blockNode.getSelectorList()) { - if (existing.contains(selectorString)) { - newTags.add(existing.replace(selectorString, - list.get(i))); + for (final String selectorString : blockNode + .getSelectorList()) { + if (StringUtil.containsSubString(selectorString, + extendedSelector)) { + String newTag = generateExtendingSelectors( + selectorString, extendedSelector, + extendingSelector); + // prevent adding duplicated selector list + if (!blockNode.getSelectorList().contains(newTag) + && !newTags.contains(newTag)) { + newTags.add(newTag); + } } } blockNode.getSelectorList().addAll(newTags); @@ -94,4 +116,15 @@ public class ExtendNodeHandler { } } } + + private static String generateExtendingSelectors(String selectorString, + String extendedSelector, String extendingSelector) { + String result = StringUtil.replaceSubString(selectorString, + extendedSelector, extendingSelector); + // remove duplicated class selectors. + if (result.startsWith(".")) { + result = StringUtil.removeDuplicatedSubString(result, "."); + } + return result; + } } diff --git a/theme-compiler/tests/resources/automatic/css/extend-in-nested-block.css b/theme-compiler/tests/resources/automatic/css/extend-in-nested-block.css new file mode 100644 index 0000000000..29f1550dd7 --- /dev/null +++ b/theme-compiler/tests/resources/automatic/css/extend-in-nested-block.css @@ -0,0 +1,7 @@ +.test .error, .test .seriousError { + border: 1px #f00; + background-color: #fdd; +} +.test .seriousError { + border-width: 3px; +} \ No newline at end of file diff --git a/theme-compiler/tests/resources/automatic/css/extend-selector-in-different-levels.css b/theme-compiler/tests/resources/automatic/css/extend-selector-in-different-levels.css new file mode 100644 index 0000000000..4de05d8d82 --- /dev/null +++ b/theme-compiler/tests/resources/automatic/css/extend-selector-in-different-levels.css @@ -0,0 +1,15 @@ +.test .middle .error, .test .middle .seriousError { + border: 1px #f00; + background-color: #fdd; +} +.test .seriousError { + border-width: 3px; +} + +.test1 .error1, .test1 .middle1 .seriousError1 { + border: 1px #f00; + background-color: #fdd; +} +.test1 .middle1 .seriousError1 { + border-width: 3px; +} \ No newline at end of file diff --git a/theme-compiler/tests/resources/automatic/css/extending-non-exist-selector-with-same-beginning.css b/theme-compiler/tests/resources/automatic/css/extending-non-exist-selector-with-same-beginning.css new file mode 100644 index 0000000000..d138a79e4a --- /dev/null +++ b/theme-compiler/tests/resources/automatic/css/extending-non-exist-selector-with-same-beginning.css @@ -0,0 +1,7 @@ +.test1 { + color: blue; +} + +.test2 { + background: red; +} \ No newline at end of file diff --git a/theme-compiler/tests/resources/automatic/css/extending-same-selector.css b/theme-compiler/tests/resources/automatic/css/extending-same-selector.css new file mode 100644 index 0000000000..1a85c0c23e --- /dev/null +++ b/theme-compiler/tests/resources/automatic/css/extending-same-selector.css @@ -0,0 +1,7 @@ +.test { + color: blue; +} + +.test { + background: red; +} \ No newline at end of file diff --git a/theme-compiler/tests/resources/automatic/css/extending-selector-with-same-beginning.css b/theme-compiler/tests/resources/automatic/css/extending-selector-with-same-beginning.css new file mode 100644 index 0000000000..097d7a8655 --- /dev/null +++ b/theme-compiler/tests/resources/automatic/css/extending-selector-with-same-beginning.css @@ -0,0 +1,7 @@ +.test1, .test2 { + color: blue; +} + +.test2 { + background: red; +} \ No newline at end of file diff --git a/theme-compiler/tests/resources/automatic/scss/extend-in-nested-block.scss b/theme-compiler/tests/resources/automatic/scss/extend-in-nested-block.scss new file mode 100644 index 0000000000..d62ead937e --- /dev/null +++ b/theme-compiler/tests/resources/automatic/scss/extend-in-nested-block.scss @@ -0,0 +1,11 @@ +.test{ + .error { + border: 1px #f00; + background-color: #fdd; + } + + .seriousError { + @extend .error; + border-width: 3px; + } +} \ No newline at end of file diff --git a/theme-compiler/tests/resources/automatic/scss/extend-selector-in-different-levels.scss b/theme-compiler/tests/resources/automatic/scss/extend-selector-in-different-levels.scss new file mode 100644 index 0000000000..977ead8d62 --- /dev/null +++ b/theme-compiler/tests/resources/automatic/scss/extend-selector-in-different-levels.scss @@ -0,0 +1,26 @@ +.test{ + .middle{ + .error { + border: 1px #f00; + background-color: #fdd; + } + } + + .seriousError { + @extend .error; + border-width: 3px; + } +} + +.test1{ + .error1 { + border: 1px #f00; + background-color: #fdd; + } + .middle1{ + .seriousError1 { + @extend .error1; + border-width: 3px; + } + } +} \ No newline at end of file diff --git a/theme-compiler/tests/resources/automatic/scss/extending-non-exist-selector-with-same-beginning.scss b/theme-compiler/tests/resources/automatic/scss/extending-non-exist-selector-with-same-beginning.scss new file mode 100644 index 0000000000..538f17da1d --- /dev/null +++ b/theme-compiler/tests/resources/automatic/scss/extending-non-exist-selector-with-same-beginning.scss @@ -0,0 +1,8 @@ +.test1 { + color: blue; +} + +.test2 { + @extend .test; + background: red; +} \ No newline at end of file diff --git a/theme-compiler/tests/resources/automatic/scss/extending-same-selector.scss b/theme-compiler/tests/resources/automatic/scss/extending-same-selector.scss new file mode 100644 index 0000000000..fbfaed9b20 --- /dev/null +++ b/theme-compiler/tests/resources/automatic/scss/extending-same-selector.scss @@ -0,0 +1,8 @@ +.test { + color: blue; +} + +.test { + @extend .test; + background: red; +} \ No newline at end of file diff --git a/theme-compiler/tests/resources/automatic/scss/extending-selector-with-same-beginning.scss b/theme-compiler/tests/resources/automatic/scss/extending-selector-with-same-beginning.scss new file mode 100644 index 0000000000..c7a9e5e921 --- /dev/null +++ b/theme-compiler/tests/resources/automatic/scss/extending-selector-with-same-beginning.scss @@ -0,0 +1,8 @@ +.test1 { + color: blue; +} + +.test2 { + @extend .test1; + background: red; +} \ No newline at end of file diff --git a/theme-compiler/tests/resources/sasslang/css/19-test_control_flow_if.css b/theme-compiler/tests/resources/sasslang/css/19-test_control_flow_if.css new file mode 100644 index 0000000000..14a1c6ef3c --- /dev/null +++ b/theme-compiler/tests/resources/sasslang/css/19-test_control_flow_if.css @@ -0,0 +1,7 @@ +.true, .also-true { + color: green; +} + +.false, .also-false { + color: red; +} diff --git a/theme-compiler/tests/resources/sasslang/scss/19-test_control_flow_if.scss b/theme-compiler/tests/resources/sasslang/scss/19-test_control_flow_if.scss new file mode 100644 index 0000000000..be53e52341 --- /dev/null +++ b/theme-compiler/tests/resources/sasslang/scss/19-test_control_flow_if.scss @@ -0,0 +1,10 @@ +.true { color: green; } +.false { color: red; } +.also-true { + @if true { @extend .true; } + @else { @extend .false; } +} +.also-false { + @if false { @extend .true; } + @else { @extend .false; } +} diff --git a/theme-compiler/tests/resources/sasslangbroken/css/19-test_control_flow_if.css b/theme-compiler/tests/resources/sasslangbroken/css/19-test_control_flow_if.css deleted file mode 100644 index 14a1c6ef3c..0000000000 --- a/theme-compiler/tests/resources/sasslangbroken/css/19-test_control_flow_if.css +++ /dev/null @@ -1,7 +0,0 @@ -.true, .also-true { - color: green; -} - -.false, .also-false { - color: red; -} diff --git a/theme-compiler/tests/resources/sasslangbroken/scss/19-test_control_flow_if.scss b/theme-compiler/tests/resources/sasslangbroken/scss/19-test_control_flow_if.scss deleted file mode 100644 index be53e52341..0000000000 --- a/theme-compiler/tests/resources/sasslangbroken/scss/19-test_control_flow_if.scss +++ /dev/null @@ -1,10 +0,0 @@ -.true { color: green; } -.false { color: red; } -.also-true { - @if true { @extend .true; } - @else { @extend .false; } -} -.also-false { - @if false { @extend .true; } - @else { @extend .false; } -} diff --git a/theme-compiler/tests/src/com/vaadin/sass/internal/util/StringUtilTest.java b/theme-compiler/tests/src/com/vaadin/sass/internal/util/StringUtilTest.java index b05b0e9dcf..84d189d8ba 100644 --- a/theme-compiler/tests/src/com/vaadin/sass/internal/util/StringUtilTest.java +++ b/theme-compiler/tests/src/com/vaadin/sass/internal/util/StringUtilTest.java @@ -50,4 +50,62 @@ public class StringUtilTest { Assert.assertEquals(sentence, StringUtil.replaceVariable(sentence, word, value)); } + + @Test + public void testContainsSubString() { + String sentence = "var1 var2"; + String word = "var"; + Assert.assertFalse(StringUtil.containsSubString(sentence, word)); + + word = "var1"; + Assert.assertTrue(StringUtil.containsSubString(sentence, word)); + + String var2 = "var2"; + Assert.assertTrue(StringUtil.containsSubString(sentence, var2)); + + Assert.assertTrue(StringUtil.containsSubString(".error.intrusion", + ".error")); + + Assert.assertFalse(StringUtil.containsSubString(".foo", "oo")); + } + + @Test + public void testContainsSubStringWithDash() { + String sentence = "var- var2"; + String word = "var"; + Assert.assertFalse(StringUtil.containsSubString(sentence, word)); + } + + @Test + public void testReplaceSubString() { + String sentence = "var1 var2"; + String word = "var"; + String value = "abc"; + + word = "var1"; + Assert.assertEquals("abc var2", + StringUtil.replaceSubString(sentence, word, value)); + + String var2 = "var1 abc"; + Assert.assertEquals(sentence, + StringUtil.replaceSubString(sentence, var2, value)); + + Assert.assertEquals(".foo", + StringUtil.replaceSubString(".foo", "oo", "aa")); + } + + @Test + public void testReplaceSubStringWithDash() { + String sentence = "var- var2"; + String word = "var"; + String value = "abc"; + Assert.assertEquals(sentence, + StringUtil.replaceSubString(sentence, word, value)); + } + + @Test + public void testRemoveDuplicatedClassSelector() { + Assert.assertEquals(".seriousError", StringUtil + .removeDuplicatedSubString(".seriousError.seriousError", ".")); + } } -- cgit v1.2.3 From 4b955715413720fac82d287e42d27f2c118a88fc Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 28 Feb 2013 02:02:37 +0200 Subject: Print an error message if the test folder cannot be found (#11184) Change-Id: I0642a4a51de5f989811246003415f05688f49f4e --- .../tests/src/com/vaadin/sass/testcases/scss/SassLangTests.java | 7 ++++++- .../src/com/vaadin/sass/testcases/scss/SassLangTestsBroken.java | 8 +++++++- .../tests/src/com/vaadin/sass/testcases/scss/SassTestRunner.java | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) (limited to 'theme-compiler') diff --git a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassLangTests.java b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassLangTests.java index 7f42898fe5..4b8aada524 100644 --- a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassLangTests.java +++ b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassLangTests.java @@ -32,7 +32,12 @@ public class SassLangTests extends AbstractDirectoryScanningSassTests { } private static URL getResourceURLInternal(String path) { - return SassLangTests.class.getResource("/sasslang" + path); + URL url = SassLangTests.class.getResource("/sasslang" + path); + if (url == null) { + throw new RuntimeException( + "Could not locate /sasslang using classloader"); + } + return url; } @TestFactory diff --git a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassLangTestsBroken.java b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassLangTestsBroken.java index 897e8dc543..2a0bc8e08d 100644 --- a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassLangTestsBroken.java +++ b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassLangTestsBroken.java @@ -32,7 +32,13 @@ public class SassLangTestsBroken extends AbstractDirectoryScanningSassTests { } private static URL getResourceURLInternal(String path) { - return SassLangTestsBroken.class.getResource("/sasslangbroken" + path); + URL url = SassLangTestsBroken.class.getResource("/sasslangbroken" + + path); + if (url == null) { + throw new RuntimeException( + "Could not locate /sasslangbroken using classloader"); + } + return url; } @TestFactory diff --git a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassTestRunner.java b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassTestRunner.java index da5210b2da..147362e4c7 100644 --- a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassTestRunner.java +++ b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassTestRunner.java @@ -80,7 +80,7 @@ public class SassTestRunner extends BlockJUnit4ClassRunner { getTestClass().getJavaClass()); } catch (Throwable t) { throw new RuntimeException("Could not run test factory method " - + method.getName()); + + method.getName(), t); } // Did the factory return an array? If so, make it a list. -- cgit v1.2.3 From be759f8424beb3e4c20f3851c5c2bbea8e0df2f4 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 28 Feb 2013 02:03:48 +0200 Subject: Removed super class which caused a JUnit3 runner to be used (#11184) Change-Id: Ib5d639e8c86c19902b77ce4681554065ee9be645 --- .../sass/testcases/scss/AbstractDirectoryScanningSassTests.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'theme-compiler') diff --git a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/AbstractDirectoryScanningSassTests.java b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/AbstractDirectoryScanningSassTests.java index f990647978..47657f805c 100644 --- a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/AbstractDirectoryScanningSassTests.java +++ b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/AbstractDirectoryScanningSassTests.java @@ -27,15 +27,13 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import junit.framework.TestCase; - import org.apache.commons.io.IOUtils; import org.junit.Assert; import com.vaadin.sass.internal.ScssStylesheet; import com.vaadin.sass.testcases.scss.SassTestRunner.FactoryTest; -public abstract class AbstractDirectoryScanningSassTests extends TestCase { +public abstract class AbstractDirectoryScanningSassTests { public static Collection getScssResourceNames(URL directoryUrl) throws URISyntaxException { @@ -51,7 +49,7 @@ public abstract class AbstractDirectoryScanningSassTests extends TestCase { URL sasslangUrl = directoryUrl; File sasslangDir = new File(sasslangUrl.toURI()); File scssDir = new File(sasslangDir, "scss"); - assertTrue(scssDir.exists()); + Assert.assertTrue(scssDir.exists()); return scssDir.listFiles(new FilenameFilter() { -- cgit v1.2.3 From a2636a774d599ba0154a89c9c11744805cc06afa Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Fri, 1 Mar 2013 11:13:05 +0200 Subject: Make SassLangTestsBroken pass iff the CSS and SCSS do not match. This makes builds pass, and gives a clearer message if one of the previously broken tests have been fixed. Change-Id: I6e5b2d9771615abbcb611f28d50ebdefcaa01ae2 --- .../sass/testcases/scss/SassLangTestsBroken.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'theme-compiler') diff --git a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassLangTestsBroken.java b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassLangTestsBroken.java index 2a0bc8e08d..6b812a6940 100644 --- a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassLangTestsBroken.java +++ b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassLangTestsBroken.java @@ -19,7 +19,9 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.Collection; +import org.junit.Assert; import org.junit.runner.RunWith; +import org.w3c.css.sac.CSSException; import com.vaadin.sass.testcases.scss.SassTestRunner.TestFactory; @@ -47,4 +49,22 @@ public class SassLangTestsBroken extends AbstractDirectoryScanningSassTests { return getScssResourceNames(getResourceURLInternal("")); } + @Override + public void compareScssWithCss(String scssResourceName) throws Exception { + boolean success = false; + try { + super.compareScssWithCss(scssResourceName); + success = true; + } catch (CSSException e) { + // this is an expected outcome + } catch (AssertionError e) { + // this is an expected outcome + } + if (success) { + Assert.fail("Test " + + scssResourceName + + " from sasslangbroken that was expected to fail has been fixed. Please move the corresponding CSS and SCSS files to sasslang."); + } + } + } -- cgit v1.2.3 From b056c43954fde77c5bdf4116aa1f0a948b954037 Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Fri, 1 Mar 2013 10:41:24 +0200 Subject: Prevent NPE when a SCSS file is not found #11099 Change-Id: Id0e0fd6a31f4089228b02bf8b66086d3f3a1727b --- theme-compiler/src/com/vaadin/sass/SassCompiler.java | 7 +++++++ .../src/com/vaadin/sass/internal/ScssStylesheet.java | 12 ++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'theme-compiler') diff --git a/theme-compiler/src/com/vaadin/sass/SassCompiler.java b/theme-compiler/src/com/vaadin/sass/SassCompiler.java index 840badfc25..48b2d24c46 100644 --- a/theme-compiler/src/com/vaadin/sass/SassCompiler.java +++ b/theme-compiler/src/com/vaadin/sass/SassCompiler.java @@ -17,6 +17,7 @@ package com.vaadin.sass; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; @@ -48,6 +49,12 @@ public class SassCompiler { // ScssStylesheet.setStylesheetResolvers(new VaadinResolver()); ScssStylesheet scss = ScssStylesheet.get(input); + if(scss == null){ + System.err.println("The scss file " + input + + " could not be found."); + return; + } + scss.compile(); if (output == null) { System.out.println(scss.toString()); diff --git a/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java b/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java index 688d569dff..dbb3e571dc 100644 --- a/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java +++ b/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java @@ -78,7 +78,8 @@ public class ScssStylesheet extends Node { * ScssStylesheet tree out of it. Calling compile() on it will transform * SASS into CSS. Calling toString() will print out the SCSS/CSS. * - * @param file + * @param identifier + * The file path. If null then null is returned. * @return * @throws CSSException * @throws IOException @@ -93,7 +94,8 @@ public class ScssStylesheet extends Node { * builds up a ScssStylesheet tree out of it. Calling compile() on it will * transform SASS into CSS. Calling toString() will print out the SCSS/CSS. * - * @param file + * @param identifier + * The file path. If null then null is returned. * @param encoding * @return * @throws CSSException @@ -109,6 +111,12 @@ public class ScssStylesheet extends Node { * * @charset declaration, the default one is ASCII. */ + + if (identifier == null) { + return null; + } + + // FIXME Is this actually intended? /John 1.3.2013 File file = new File(identifier); file = file.getCanonicalFile(); -- cgit v1.2.3