@Test public void testImport() throws Exception { String css, output; URI resuri = testdir.toURI(); css = "\r\n\r\n.imported {\r\n\tcolor : black;\r\n}"; CopyUtil.copy(css, new FileWriter(new File(testdir, "imported.css"))); configScript.put(CSSModuleBuilder.INLINEIMPORTS_REQPARAM_NAME, configScript, Boolean.TRUE); IConfig config = new ConfigImpl(mockAggregator, tmpdir.toURI(), configScript); builder.configLoaded(config, seq++); css = "\n\r@import \"imported.css\""; output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".imported{color:black}", output); css = "\n\r@import \"./imported.css\""; output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".imported{color:black}", output); css = "\n\r@import url(\"././imported.css\")"; output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".imported{color:black}", output); css = "\n\r@import url('foo/../imported.css')"; output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".imported{color:black}", output); css = "\n\r@import url( \"./foo/bar/.././../imported.css\" )"; output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".imported{color:black}", output); css = "\n\r@import \"foo/bar/../../imported.css\""; output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".imported{color:black}", output); css = "\n\r@import (less) \"imported.css\""; output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".imported{color:black}", output); css = "\n\r@import \"foo/imported.css\""; boolean exceptionCaught = false; try { output = buildCss(new StringResource(css, resuri)); } catch (NotFoundException e) { exceptionCaught = true; } Assert.assertTrue("Expected FileNotFoundException", exceptionCaught); css = "\r\n\r\n.background-image: url( \"images/img.jpg\" );"; CopyUtil.copy(css, new FileWriter(new File(testdir, "imported.css"))); output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".background-image:url(\"images/img.jpg\");", output); File subdir = new File(testdir, "subdir"); File imported = new File(subdir, "imported.css"); subdir.mkdir(); String importedCss = "\r\n\r\n.background-image: url( \"images/img.jpg\" );"; CopyUtil.copy(importedCss, new FileWriter(imported)); css = "\n\r@import \"subdir/imported.css\""; output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".background-image:url(\"subdir/images/img.jpg\");", output); importedCss = "\r\n\r\n.background-image: url('./images/./img.jpg' );"; CopyUtil.copy(importedCss, new FileWriter(imported)); output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".background-image:url('subdir/images/img.jpg');", output); importedCss = "\r\n\r\n.background-image: url( \"./images/foo/../img.jpg\" );"; CopyUtil.copy(importedCss, new FileWriter(imported)); output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".background-image:url(\"subdir/images/img.jpg\");", output); importedCss = "\r\n\r\n.background-image: url(./images/foo/bar/../../img.jpg);"; CopyUtil.copy(importedCss, new FileWriter(imported)); output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".background-image:url(subdir/images/img.jpg);", output); importedCss = "\r\n\r\n.background-image: url( images/../images/img.jpg );"; CopyUtil.copy(importedCss, new FileWriter(imported)); output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".background-image:url(subdir/images/img.jpg);", output); importedCss = "\r\n\r\n.background-image: url( '/images/img.jpg' );"; CopyUtil.copy(importedCss, new FileWriter(imported)); output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".background-image:url('/images/img.jpg');", output); importedCss = "\r\n\r\n.background-image: url( 'http: CopyUtil.copy(importedCss, new FileWriter(imported)); output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".background-image:url('http: importedCss = "\r\n\r\n.background-image: url( '#images/img.jpg' );"; CopyUtil.copy(importedCss, new FileWriter(imported)); output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".background-image:url('#images/img.jpg');", output); requestParams.put(CSSModuleBuilder.INLINEIMPORTS_REQPARAM_NAME, new String[]{"false"}); output = buildCss(new StringResource(css, resuri)); Assert.assertEquals("@import \"subdir/imported.css\"", output); requestParams.put(CSSModuleBuilder.INLINEIMPORTS_REQPARAM_NAME, new String[]{"true"}); output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".background-image:url('#images/img.jpg');", output); requestParams.put(CSSModuleBuilder.INLINEIMPORTS_REQPARAM_NAME, new String[]{"0"}); output = buildCss(new StringResource(css, resuri)); Assert.assertEquals("@import \"subdir/imported.css\"", output); requestParams.put(CSSModuleBuilder.INLINEIMPORTS_REQPARAM_NAME, new String[]{"1"}); output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".background-image:url('#images/img.jpg');", output); requestAttributes.put(IHttpTransport.SHOWFILENAMES_REQATTRNAME, Boolean.TRUE); output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".background-image:url('#images/img.jpg');", output); mockAggregator.getOptions().setOption(IOptions.DEVELOPMENT_MODE, "true"); output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".background-image:url('#images/img.jpg');", output); requestAttributes.remove(IHttpTransport.SHOWFILENAMES_REQATTRNAME); output = buildCss(new StringResource(css, resuri)); Assert.assertEquals(".background-image:url('#images/img.jpg');", output); }
@Override public void configLoaded(IConfig conf, long sequence) { final String sourceMethod = "configLoaded"; SignalUtil.lock( configUpdatingRWL.writeLock(), sourceClass, sourceMethod); try { Object obj = conf.getProperty(SIZETHRESHOLD_CONFIGPARAM, null); imageSizeThreshold = TypeUtil.asInt(obj, SIZETHRESHOLD_DEFAULT_VALUE); obj = conf.getProperty(INLINEIMPORTS_CONFIGPARAM, null); inlineImports = TypeUtil.asBoolean(obj, INLINEIMPORTS_DEFAULT_VALUE); obj = conf.getProperty(INCLUDEAMDPATHS_CONFIGPARAM, null); includeAMDPaths = TypeUtil.asBoolean(obj, INCLUDEAMDPATHS_DEFAULT_VALUE); Collection<String> types = new ArrayList<String>(s_inlineableImageTypes); Object oImageTypes = conf.getProperty(IMAGETYPES_CONFIGPARAM, null); if (oImageTypes != IConfig.NOT_FOUND && oImageTypes != null) { if (oImageTypes instanceof String) { String[] aTypes = oImageTypes.toString().split(","); for (String type : aTypes) { types.add(type); } } else { @SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>)conf.getProperty(IMAGETYPES_CONFIGPARAM, Map.class); inlineableImageTypeMap.putAll(map); } } inlineableImageTypes = types; Collection<Pattern> list = Collections.emptyList(); Object oIncludeList = conf.getProperty(INCLUDELIST_CONFIGPARAM, null); if (oIncludeList != IConfig.NOT_FOUND && oIncludeList != null) { list = new ArrayList<Pattern>(); for (String s : oIncludeList.toString().split(",")) { list.add(toRegexp(s)); } } inlinedImageIncludeList = list; list = Collections.emptyList(); Object oExcludeList = conf.getProperty(EXCLUDELIST_CONFIGPARAM, null); if (oExcludeList != IConfig.NOT_FOUND && oExcludeList != null) { list = new ArrayList<Pattern>(); for (String s : oExcludeList.toString().split(",")) { list.add(toRegexp(s)); } } inlinedImageExcludeList = list; initPostcss(conf); } finally { configUpdatingRWL.writeLock().unlock(); } }
CSSModuleBuilder extends TextModuleBuilder implements  IExtensionInitializer, IExtensionSingleton, IShutdownListener, IConfigListener { @Override public void configLoaded(IConfig conf, long sequence) { final String sourceMethod = "configLoaded"; SignalUtil.lock( configUpdatingRWL.writeLock(), sourceClass, sourceMethod); try { Object obj = conf.getProperty(SIZETHRESHOLD_CONFIGPARAM, null); imageSizeThreshold = TypeUtil.asInt(obj, SIZETHRESHOLD_DEFAULT_VALUE); obj = conf.getProperty(INLINEIMPORTS_CONFIGPARAM, null); inlineImports = TypeUtil.asBoolean(obj, INLINEIMPORTS_DEFAULT_VALUE); obj = conf.getProperty(INCLUDEAMDPATHS_CONFIGPARAM, null); includeAMDPaths = TypeUtil.asBoolean(obj, INCLUDEAMDPATHS_DEFAULT_VALUE); Collection<String> types = new ArrayList<String>(s_inlineableImageTypes); Object oImageTypes = conf.getProperty(IMAGETYPES_CONFIGPARAM, null); if (oImageTypes != IConfig.NOT_FOUND && oImageTypes != null) { if (oImageTypes instanceof String) { String[] aTypes = oImageTypes.toString().split(","); for (String type : aTypes) { types.add(type); } } else { @SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>)conf.getProperty(IMAGETYPES_CONFIGPARAM, Map.class); inlineableImageTypeMap.putAll(map); } } inlineableImageTypes = types; Collection<Pattern> list = Collections.emptyList(); Object oIncludeList = conf.getProperty(INCLUDELIST_CONFIGPARAM, null); if (oIncludeList != IConfig.NOT_FOUND && oIncludeList != null) { list = new ArrayList<Pattern>(); for (String s : oIncludeList.toString().split(",")) { list.add(toRegexp(s)); } } inlinedImageIncludeList = list; list = Collections.emptyList(); Object oExcludeList = conf.getProperty(EXCLUDELIST_CONFIGPARAM, null); if (oExcludeList != IConfig.NOT_FOUND && oExcludeList != null) { list = new ArrayList<Pattern>(); for (String s : oExcludeList.toString().split(",")) { list.add(toRegexp(s)); } } inlinedImageExcludeList = list; initPostcss(conf); } finally { configUpdatingRWL.writeLock().unlock(); } } }
CSSModuleBuilder extends TextModuleBuilder implements  IExtensionInitializer, IExtensionSingleton, IShutdownListener, IConfigListener { @Override public void configLoaded(IConfig conf, long sequence) { final String sourceMethod = "configLoaded"; SignalUtil.lock( configUpdatingRWL.writeLock(), sourceClass, sourceMethod); try { Object obj = conf.getProperty(SIZETHRESHOLD_CONFIGPARAM, null); imageSizeThreshold = TypeUtil.asInt(obj, SIZETHRESHOLD_DEFAULT_VALUE); obj = conf.getProperty(INLINEIMPORTS_CONFIGPARAM, null); inlineImports = TypeUtil.asBoolean(obj, INLINEIMPORTS_DEFAULT_VALUE); obj = conf.getProperty(INCLUDEAMDPATHS_CONFIGPARAM, null); includeAMDPaths = TypeUtil.asBoolean(obj, INCLUDEAMDPATHS_DEFAULT_VALUE); Collection<String> types = new ArrayList<String>(s_inlineableImageTypes); Object oImageTypes = conf.getProperty(IMAGETYPES_CONFIGPARAM, null); if (oImageTypes != IConfig.NOT_FOUND && oImageTypes != null) { if (oImageTypes instanceof String) { String[] aTypes = oImageTypes.toString().split(","); for (String type : aTypes) { types.add(type); } } else { @SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>)conf.getProperty(IMAGETYPES_CONFIGPARAM, Map.class); inlineableImageTypeMap.putAll(map); } } inlineableImageTypes = types; Collection<Pattern> list = Collections.emptyList(); Object oIncludeList = conf.getProperty(INCLUDELIST_CONFIGPARAM, null); if (oIncludeList != IConfig.NOT_FOUND && oIncludeList != null) { list = new ArrayList<Pattern>(); for (String s : oIncludeList.toString().split(",")) { list.add(toRegexp(s)); } } inlinedImageIncludeList = list; list = Collections.emptyList(); Object oExcludeList = conf.getProperty(EXCLUDELIST_CONFIGPARAM, null); if (oExcludeList != IConfig.NOT_FOUND && oExcludeList != null) { list = new ArrayList<Pattern>(); for (String s : oExcludeList.toString().split(",")) { list.add(toRegexp(s)); } } inlinedImageExcludeList = list; initPostcss(conf); } finally { configUpdatingRWL.writeLock().unlock(); } } CSSModuleBuilder(); protected  CSSModuleBuilder(IAggregator aggregator, ExecutorService es, int scopePoolSize); }
CSSModuleBuilder extends TextModuleBuilder implements  IExtensionInitializer, IExtensionSingleton, IShutdownListener, IConfigListener { @Override public void configLoaded(IConfig conf, long sequence) { final String sourceMethod = "configLoaded"; SignalUtil.lock( configUpdatingRWL.writeLock(), sourceClass, sourceMethod); try { Object obj = conf.getProperty(SIZETHRESHOLD_CONFIGPARAM, null); imageSizeThreshold = TypeUtil.asInt(obj, SIZETHRESHOLD_DEFAULT_VALUE); obj = conf.getProperty(INLINEIMPORTS_CONFIGPARAM, null); inlineImports = TypeUtil.asBoolean(obj, INLINEIMPORTS_DEFAULT_VALUE); obj = conf.getProperty(INCLUDEAMDPATHS_CONFIGPARAM, null); includeAMDPaths = TypeUtil.asBoolean(obj, INCLUDEAMDPATHS_DEFAULT_VALUE); Collection<String> types = new ArrayList<String>(s_inlineableImageTypes); Object oImageTypes = conf.getProperty(IMAGETYPES_CONFIGPARAM, null); if (oImageTypes != IConfig.NOT_FOUND && oImageTypes != null) { if (oImageTypes instanceof String) { String[] aTypes = oImageTypes.toString().split(","); for (String type : aTypes) { types.add(type); } } else { @SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>)conf.getProperty(IMAGETYPES_CONFIGPARAM, Map.class); inlineableImageTypeMap.putAll(map); } } inlineableImageTypes = types; Collection<Pattern> list = Collections.emptyList(); Object oIncludeList = conf.getProperty(INCLUDELIST_CONFIGPARAM, null); if (oIncludeList != IConfig.NOT_FOUND && oIncludeList != null) { list = new ArrayList<Pattern>(); for (String s : oIncludeList.toString().split(",")) { list.add(toRegexp(s)); } } inlinedImageIncludeList = list; list = Collections.emptyList(); Object oExcludeList = conf.getProperty(EXCLUDELIST_CONFIGPARAM, null); if (oExcludeList != IConfig.NOT_FOUND && oExcludeList != null) { list = new ArrayList<Pattern>(); for (String s : oExcludeList.toString().split(",")) { list.add(toRegexp(s)); } } inlinedImageExcludeList = list; initPostcss(conf); } finally { configUpdatingRWL.writeLock().unlock(); } } CSSModuleBuilder(); protected  CSSModuleBuilder(IAggregator aggregator, ExecutorService es, int scopePoolSize); @Override List<ICacheKeyGenerator> getCacheKeyGenerators(IAggregator aggregator); @Override boolean handles(String mid, IResource resource); @Override void shutdown(IAggregator aggregator); @Override void initialize(IAggregator aggregator,
			IAggregatorExtension extension, IExtensionRegistrar registrar); @Override void configLoaded(IConfig conf, long sequence); String dequote(String in); }
CSSModuleBuilder extends TextModuleBuilder implements  IExtensionInitializer, IExtensionSingleton, IShutdownListener, IConfigListener { @Override public void configLoaded(IConfig conf, long sequence) { final String sourceMethod = "configLoaded"; SignalUtil.lock( configUpdatingRWL.writeLock(), sourceClass, sourceMethod); try { Object obj = conf.getProperty(SIZETHRESHOLD_CONFIGPARAM, null); imageSizeThreshold = TypeUtil.asInt(obj, SIZETHRESHOLD_DEFAULT_VALUE); obj = conf.getProperty(INLINEIMPORTS_CONFIGPARAM, null); inlineImports = TypeUtil.asBoolean(obj, INLINEIMPORTS_DEFAULT_VALUE); obj = conf.getProperty(INCLUDEAMDPATHS_CONFIGPARAM, null); includeAMDPaths = TypeUtil.asBoolean(obj, INCLUDEAMDPATHS_DEFAULT_VALUE); Collection<String> types = new ArrayList<String>(s_inlineableImageTypes); Object oImageTypes = conf.getProperty(IMAGETYPES_CONFIGPARAM, null); if (oImageTypes != IConfig.NOT_FOUND && oImageTypes != null) { if (oImageTypes instanceof String) { String[] aTypes = oImageTypes.toString().split(","); for (String type : aTypes) { types.add(type); } } else { @SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>)conf.getProperty(IMAGETYPES_CONFIGPARAM, Map.class); inlineableImageTypeMap.putAll(map); } } inlineableImageTypes = types; Collection<Pattern> list = Collections.emptyList(); Object oIncludeList = conf.getProperty(INCLUDELIST_CONFIGPARAM, null); if (oIncludeList != IConfig.NOT_FOUND && oIncludeList != null) { list = new ArrayList<Pattern>(); for (String s : oIncludeList.toString().split(",")) { list.add(toRegexp(s)); } } inlinedImageIncludeList = list; list = Collections.emptyList(); Object oExcludeList = conf.getProperty(EXCLUDELIST_CONFIGPARAM, null); if (oExcludeList != IConfig.NOT_FOUND && oExcludeList != null) { list = new ArrayList<Pattern>(); for (String s : oExcludeList.toString().split(",")) { list.add(toRegexp(s)); } } inlinedImageExcludeList = list; initPostcss(conf); } finally { configUpdatingRWL.writeLock().unlock(); } } CSSModuleBuilder(); protected  CSSModuleBuilder(IAggregator aggregator, ExecutorService es, int scopePoolSize); @Override List<ICacheKeyGenerator> getCacheKeyGenerators(IAggregator aggregator); @Override boolean handles(String mid, IResource resource); @Override void shutdown(IAggregator aggregator); @Override void initialize(IAggregator aggregator,
			IAggregatorExtension extension, IExtensionRegistrar registrar); @Override void configLoaded(IConfig conf, long sequence); String dequote(String in); static final String INLINEIMPORTS_CONFIGPARAM; static final String INCLUDELIST_CONFIGPARAM; static final String EXCLUDELIST_CONFIGPARAM; static final String IMAGETYPES_CONFIGPARAM; static final String SIZETHRESHOLD_CONFIGPARAM; static final String INCLUDEAMDPATHS_CONFIGPARAM; static final String POSTCSSPLUGINS_CONFIGPARAM; static final String SCOPEPOOLSIZE_CONFIGPARAM; static final String POSTCSS_CONFIGPARAM; static final boolean INLINEIMPORTS_DEFAULT_VALUE; static final boolean INCLUDEAMDPATHS_DEFAULT_VALUE; static final int SIZETHRESHOLD_DEFAULT_VALUE; static final String INLINEIMPORTS_REQPARAM_NAME; static final String INLINEIMAGES_REQPARAM_NAME; static final String PREAMBLE; static final String BLANK; static final String UTF8_CHARSET; static final String POSTCSS_RES_NAME; static final String MINIFYER_RES_NAME; static final String POSTCSS; static final String PROCESS; static final String PLUGINS; static final String POSTCSS_INSTANCE; static final String MODULE; static final String EXPORTS; static final String AMD_DEFINE_SHIM_JS; static final String MINIFIER_INITIALIZATION_VAR; static final String MINIFIER_INITIALIZATION_JS; static final Map<String, Boolean> POSTCSS_OPTIONS; static final int INITIALIZER_THREAD_POOL_SIZE; static final int DEFAULT_SCOPE_POOL_SIZE; static final int SCOPE_POOL_TIMEOUT_SECONDS; public int imageSizeThreshold; public boolean inlineImports; public boolean includeAMDPaths; public Collection<Pattern> inlinedImageExcludeList; }