summaryrefslogtreecommitdiffstats
path: root/theme-compiler
diff options
context:
space:
mode:
Diffstat (limited to 'theme-compiler')
-rw-r--r--theme-compiler/build.xml38
-rw-r--r--theme-compiler/ivy.xml45
-rw-r--r--theme-compiler/ivymodule/smartsprites-ivy-0.2.3-itmill.xml38
-rw-r--r--theme-compiler/src/com/vaadin/buildhelpers/CompileTheme.java114
4 files changed, 235 insertions, 0 deletions
diff --git a/theme-compiler/build.xml b/theme-compiler/build.xml
new file mode 100644
index 0000000000..300f2718aa
--- /dev/null
+++ b/theme-compiler/build.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+
+<project name="vaadin-theme-compiler" basedir="." default="publish-local" xmlns:ivy="antlib:org.apache.ivy.ant">
+ <description>
+ Compiles build helpers used when building other modules.
+ </description>
+ <include file="../common.xml" as="common" />
+ <include file="../build.xml" as="vaadin" />
+
+ <!-- global properties -->
+ <property name="module.name" value="vaadin-theme-compiler" />
+ <property name="result.dir" value="result" />
+ <path id="classpath.compile.custom" />
+ <path id="classpath.tests.custom" />
+
+ <!--<property name="classes.exclude" value="com/vaadin/buildhelpers/**" />-->
+
+ <target name="jar">
+ <antcall target="common.jar">
+ <reference torefid="extra.jar.includes" refid="empty.reference" />
+ </antcall>
+ </target>
+ <target name="publish-local" depends="jar">
+ <antcall target="common.sources.jar" />
+ <antcall target="common.javadoc.jar" />
+
+ <antcall target="common.publish-local" />
+ </target>
+
+ <target name="clean">
+ <antcall target="common.clean" />
+ </target>
+
+ <target name="tests">
+ <antcall target="common.tests.run" />
+ </target>
+
+</project> \ No newline at end of file
diff --git a/theme-compiler/ivy.xml b/theme-compiler/ivy.xml
new file mode 100644
index 0000000000..2a0e814c07
--- /dev/null
+++ b/theme-compiler/ivy.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ivy-module version="2.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"
+ xmlns:m="http://ant.apache.org/ivy/maven">
+
+ <info organisation="com.vaadin" module="vaadin-theme-compiler"
+ revision="${vaadin.version}" />
+
+ <configurations>
+ <conf name="build" />
+ <conf name="build-provided" />
+ <conf name="ide" visibility="private" />
+ <conf name="tests" />
+ </configurations>
+ <publications>
+ <artifact type="jar" ext="jar" />
+ <artifact type="pom" ext="pom" />
+ <artifact type="source" ext="jar" m:classifier="sources" />
+ <artifact type="javadoc" ext="jar" m:classifier="javadoc" />
+ </publications>
+ <dependencies defaultconf="*->default">
+ <!-- LIBRARY DEPENDENCIES (compile time) -->
+ <!-- Project modules -->
+ <dependency org="com.vaadin" name="vaadin-shared"
+ rev="${vaadin.version}" conf="build,tests" />
+
+
+ <dependency org="org.w3c.css" name="sac" rev="1.3" />
+ <dependency org="milyn" name="flute" rev="1.3" conf="*->default" />
+ <dependency org="javax.servlet" name="servlet-api"
+ rev="2.5" />
+ <dependency org="com.carrotsearch" name="smartsprites"
+ rev="0.2.3-itmill" />
+ <dependency org="com.vaadin" name="vaadin-buildhelpers"
+ rev="${vaadin.version}" conf="build"></dependency>
+ <dependency org="junit" name="junit" rev="4.5"
+ conf="tests -> default" />
+ <dependency org="net.sourceforge.cssparser" name="cssparser"
+ rev="0.9.5" conf="tests,ide->default" />
+ <dependency org="commons-cli" name="commons-cli" rev="1.2"
+ conf="build,ide -> default" />
+ </dependencies>
+
+</ivy-module>
diff --git a/theme-compiler/ivymodule/smartsprites-ivy-0.2.3-itmill.xml b/theme-compiler/ivymodule/smartsprites-ivy-0.2.3-itmill.xml
new file mode 100644
index 0000000000..495b6d00c9
--- /dev/null
+++ b/theme-compiler/ivymodule/smartsprites-ivy-0.2.3-itmill.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
+ <info organisation="com.carrotsearch"
+ module="smartsprites"
+ revision="0.2.3-itmill"
+ status="release"
+ publication="20111130000000">
+ <license name="BSD license" url="http://csssprites.org/smartsprites.LICENSE" />
+ <description homepage="http://csssprites.org">
+ CSS Sprites Generator Done Right. SmartSprites maintains CSS sprites in your designs,
+ fully automatically. No tedious copying and pasting to your CSS when adding or changing
+ sprited images.
+ </description>
+ </info>
+ <configurations>
+ <conf name="default" visibility="public" description="runtime dependencies and master artifact can be used with this conf" extends="runtime,master"/>
+ <conf name="master" visibility="public" description="contains only the artifact published by this module itself, with no transitive dependencies"/>
+ <conf name="compile" visibility="public" description="this is the default scope, used if none is specified. Compile dependencies are available in all classpaths."/>
+ <conf name="provided" visibility="public" description="this is much like compile, but indicates you expect the JDK or a container to provide it. It is only available on the compilation classpath, and is not transitive."/>
+ <conf name="runtime" visibility="public" description="this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath." extends="compile"/>
+ <conf name="test" visibility="private" description="this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases." extends="runtime"/>
+ <conf name="system" visibility="public" description="this scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository."/>
+ <conf name="sources" visibility="public" description="this configuration contains the source artifact of this module, if any."/>
+ <conf name="javadoc" visibility="public" description="this configuration contains the javadoc artifact of this module, if any."/>
+ <conf name="optional" visibility="public" description="contains all optional dependencies"/>
+ </configurations>
+ <publications>
+ <artifact name="smartsprites" type="jar" ext="jar" conf="master"/>
+ </publications>
+ <dependencies>
+ <dependency org="com.google.collections" name="google-collections" rev="0.9" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
+ <dependency org="args4j" name="args4j" rev="2.0.9" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
+ <dependency org="commons-math" name="commons-math" rev="1.1" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
+ <dependency org="commons-io" name="commons-io" rev="1.4" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
+ <dependency org="commons-lang" name="commons-lang" rev="2.3" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
+ <dependency org="junit" name="junit" rev="4.4" force="true" conf="test->runtime(*),master(*)"/>
+ </dependencies>
+</ivy-module>
diff --git a/theme-compiler/src/com/vaadin/buildhelpers/CompileTheme.java b/theme-compiler/src/com/vaadin/buildhelpers/CompileTheme.java
new file mode 100644
index 0000000000..c0bfb9aa7f
--- /dev/null
+++ b/theme-compiler/src/com/vaadin/buildhelpers/CompileTheme.java
@@ -0,0 +1,114 @@
+package com.vaadin.buildhelpers;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+
+import com.vaadin.sass.ScssStylesheet;
+import com.vaadin.shared.Version;
+
+/**
+ * Helper to combine css divided into separate per component dirs into one to
+ * optimize http requests.
+ */
+public class CompileTheme {
+
+ /**
+ * @param args
+ * @throws IOException
+ * @throws ParseException
+ */
+ public static void main(String[] args) throws IOException, ParseException {
+ Options options = new Options();
+ options.addOption("t", "theme", true, "the theme to compile");
+ options.addOption("f", "theme-folder", true,
+ "the folder containing the theme");
+ options.addOption("s", "sprites", true, "use smartsprites");
+ CommandLineParser parser = new PosixParser();
+ CommandLine params = parser.parse(options, args);
+ if (!params.hasOption("theme") || !params.hasOption("theme-folder")) {
+ // automatically generate the help statement
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp(CompileTheme.class.getName(), options);
+ return;
+ }
+ String themeName = params.getOptionValue("theme");
+ String themeFolder = params.getOptionValue("theme-folder");
+ boolean useSprites = params.hasOption("sprites");
+
+ String version = Version.getFullVersion();
+ try {
+ processSassTheme(themeFolder, themeName, useSprites, version);
+ System.out.println("Compiling theme " + themeName + " successful");
+ } catch (Exception e) {
+ System.err.println("Compiling theme " + themeName + " failed");
+ e.printStackTrace();
+ }
+ }
+
+ private static void processSassTheme(String themeFolder, String themeName,
+ boolean useSmartSprites, String version) throws Exception {
+
+ StringBuffer cssHeader = new StringBuffer();
+
+ version = version.replaceAll("\\.", "_");
+ cssHeader.append(".v-theme-version:after {content:\"" + version
+ + "\";}\n");
+ cssHeader.append(".v-theme-version-" + version + " {display: none;}\n");
+
+ String stylesCssDir = themeFolder + File.separator + themeName
+ + File.separator;
+ String stylesCssName = stylesCssDir + "styles.css";
+
+ // Process as SASS file
+ String sassFile = stylesCssDir + "styles.scss";
+ ScssStylesheet scss = ScssStylesheet.get(sassFile);
+ if (scss == null) {
+ throw new IllegalArgumentException("SASS file: " + sassFile
+ + " not found");
+ }
+ scss.compile();
+
+ BufferedWriter out = new BufferedWriter(new FileWriter(stylesCssName));
+ out.write(cssHeader.toString());
+ out.write(scss.toString());
+ out.close();
+
+ System.out.println("Compiled CSS to " + stylesCssName + " ("
+ + scss.toString().length() + " bytes)");
+
+ if (useSmartSprites) {
+ createSprites(themeFolder, themeName);
+ System.out.println("Used SmartSprites to create sprites");
+ File oldCss = new File(stylesCssName);
+ oldCss.delete();
+
+ File newCss = new File(stylesCssDir + "styles-sprite.css");
+ boolean ok = newCss.renameTo(oldCss);
+ if (!ok) {
+ System.out.println("Rename " + newCss + " -> " + oldCss
+ + " failed");
+ }
+ }
+ }
+
+ private static void createSprites(String themeFolder, String themeName)
+ throws FileNotFoundException, IOException {
+ String[] parameters = new String[] { "--sprite-png-depth", "AUTO",
+ "--css-file-suffix", "-sprite", "--css-file-encoding", "UTF-8",
+ "--root-dir-path", themeFolder + File.separator + themeName,
+ "--log-level", "WARN" };
+
+ org.carrot2.labs.smartsprites.SmartSprites.main(parameters);
+
+ }
+}