Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TAP5-2708/2753: CssCompressor updates and CSS variable fixes #40

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion tapestry-webresources/NOTICE.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).

This product includes source from the YUI Compressor library, available under a BSD License.
This product includes source and test files from the YUI Compressor library, available under a BSD License.
http://yui.github.io/yuicompressor/
2 changes: 1 addition & 1 deletion tapestry-webresources/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jar.manifest {


test {
useJUnit()
useJUnitPlatform()

systemProperties("geb.build.reportsDir": "$reporting.baseDir/geb",
"tapestry.compiled-asset-cache-dir": "$buildDir/compiled-asset-cache",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.io.*;

/**
* A wrapper around YUI Compressor. This module does not have a dependency on YUICompressor;
* isntead a local copy of the YUICompressor CSS minimizer is kept (because the reset of YUICompressor
* A wrapper around a customized YUI Compressor. This module does not have a dependency on YUICompressor;
* instead a local copy of the YUICompressor CSS minimizer is kept (because the reset of YUICompressor
* is painful to mix due to how it attempts to patch Rhino).
*/
public class CSSMinimizer extends AbstractMinimizer
Expand All @@ -38,20 +38,15 @@ public CSSMinimizer(Logger logger, OperationTracker tracker, AssetChecksumGenera
@Override
protected InputStream doMinimize(StreamableResource resource) throws IOException
{
StringWriter writer = new StringWriter(1000);
Reader reader = new InputStreamReader(resource.openStream());
InputStream is = resource.openStream();

try
{
new CssCompressor(reader).compress(writer, -1);

writer.flush();

return IOUtils.toInputStream(writer.getBuffer());
String compressed = CssCompressor.compress(is);
return IOUtils.toInputStream(compressed);
} finally
{
InternalUtils.close(reader);
InternalUtils.close(writer);
InternalUtils.close(is);
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,29 +1,132 @@
package t5.webresources.tests

import geb.spock.GebReportingSpec

import org.apache.tapestry5.internal.webresources.CssCompressor
import org.apache.tapestry5.test.JettyRunner

import spock.lang.Issue;
import spock.lang.Shared
import spock.lang.Specification;

class CssCompressorSpec extends Specification {

@Issue('TAP5-2524')
def "minify CSS with keyframes "() {
setup:
given:
def css = '''@keyframes anim {
0% { opacity: 0; }
100% { opacity: 1; }
}'''
StringWriter writer = new StringWriter()
def expected = "@keyframes anim{0%{opacity:0}100%{opacity:1}}"

when:
def result = CssCompressor.compress(css)

then:
result == expected
}

@Issue('TAP5-2753')
def "preserve space for calc operators"() {
given:
def is = CssCompressorSpec.class.getResourceAsStream("/t5/webresources/css/tap5-2753.css")
def t = CssCompressorSpec.class.getResourceAsStream("/t5/webresources/css/tap5-2753.css.min").text
def expected = CssCompressorSpec.class.getResourceAsStream("/t5/webresources/css/tap5-2753.css.min").text.trim()

when:
def result = CssCompressor.compress(is)

then:
result == expected
}

def "bootstrap.css integry check"() {
given:
def is = CssCompressorSpec.class.getResourceAsStream("/t5/webresources/css/bootstrap.css")
def expected = CssCompressorSpec.class.getResourceAsStream("/t5/webresources/css/bootstrap.css.min").text.trim()

when:
def result = CssCompressor.compress(is)

then:
result == expected
}

def "yui compressor test '#rawFile'"() {
given:
def is = CssCompressorSpec.class.getResourceAsStream("/t5/webresources/css/yui/$rawFile")
def expected = CssCompressorSpec.class.getResourceAsStream("/t5/webresources/css/yui/${rawFile}.min").text.trim()

when:
new CssCompressor(new StringReader(css)).compress(writer, -1)
def result = CssCompressor.compress(is)

then:
writer.toString() == '''@keyframes anim{0%{opacity:0}100%{opacity:1}}'''
result == expected

where:
rawFile << [
"background-position.css",
"border-none.css",
"box-model-hack.css",
"bug2527974.css",
"bug2527991.css",
"bug2527998.css",
"bug2528034.css",
"bug-flex.css",
"bug-nested-pseudoclass.css",
"bug-preservetoken-calc.css",
"charset-media.css",
"color.css",
"color-keyword.css",
"color-simple.css",
"comment.css",
"concat-charset.css",
"dataurl-base64-doublequotes.css",
"dataurl-base64-eof.css",
"dataurl-base64-linebreakindata.css",
"dataurl-base64-noquotes.css",
"dataurl-base64-singlequotes.css",
"dataurl-base64-twourls.css",
"dataurl-dbquote-font.css",
"dataurl-nonbase64-doublequotes.css",
"dataurl-nonbase64-noquotes.css",
"dataurl-nonbase64-singlequotes.css",
"dataurl-noquote-multiline-font.css",
"dataurl-realdata-doublequotes.css",
"dataurl-realdata-noquotes.css",
"dataurl-realdata-singlequotes.css",
"dataurl-realdata-yuiapp.css",
"dataurl-singlequote-font.css",
"decimals.css",
"dollar-header.css",
"font-face.css",
// "hsla-issue81.css.FAIL",
"ie5mac.css",
"ie-backslash9-hack.css",
"issue151.css",
// "issue172.css.FAIL",
"issue180.css",
"issue205.css",
"issue221.css",
"issue222.css",
"issue-59.css",
"lowercasing.css",
"media-empty-class.css",
"media-multi.css",
"media-test.css",
"old-ie-filter-matrix.css",
"opacity-filter.css",
"opera-pixel-ratio.css",
"pointzeros.css",
"preserve-case.css",
"preserve-important.css",
"preserve-new-line.css",
"preserve-strings.css",
"pseudo.css",
"pseudo-first.css",
// "rgb-issue81.css.FAIL",
"special-comments.css",
"star-underscore-hacks.css",
"string-in-comment.css",
"webkit-transform.css",
"zeros.css"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package t5.webresources.tests

import geb.spock.GebReportingSpec
import geb.spock.GebSpec
import org.apache.tapestry5.test.JettyRunner
import spock.lang.Shared

class WebResourcesSpec extends GebReportingSpec {
class WebResourcesSpec extends GebSpec {

@Shared
def runner;
Expand Down
2 changes: 1 addition & 1 deletion tapestry-webresources/src/test/resources/GebConfig.groovy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import io.github.bonigarcia.wdm.FirefoxDriverManager
import io.github.bonigarcia.wdm.managers.FirefoxDriverManager

driver = "firefox"

Expand Down