Permalink
Browse files

[build] Updating asset compilation to utilize antrun.

CHANGELOG
=========
* Updated `bin/installer.bash` to remove requirejs building.
* Updated `pom.xml`
  * Removed requirejs plugin
  * Added antrun and antrun call.
* Updated a number of JavaScripts to improve compatibility with the
  closure compiler.
* Updated `docs/WEBUI.md` to reflect new asset compilation setup.
  • Loading branch information...
1 parent 7944018 commit b71885617fe2eedf5d6c7a517059c51820f8b4fe @andykram andykram committed Mar 15, 2013
View
@@ -54,8 +54,6 @@ function install_chronos {
sed -i '' -e "s/$DEFAULT_MESOS_JAR_STRING/$mesos_version_string/g" "$BIN_DIRECTORY/../pom.xml"
popd
pushd "$BIN_DIRECTORY" ; cd ..
- echo "Building chronos assets"
- mvn requirejs:optimize -P requirejs
echo "Installing chronos"
mvn package
popd
View
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<project name="chronos">
+
+ <!-- Inspired by: https://gist.github.com/millermedeiros/825117 -->
+ <target name="-optimize" description="Combine and minify files.">
+ <java classname="org.mozilla.javascript.tools.shell.Main">
+ <classpath path="${compile_classpath}" />
+ <arg value="${requirejs.optimizer.script}"/>
+ <arg value="-o"/>
+ <arg value="${requirejs.optimizer.settings}"/>
+ </java>
+ <echo message="optimized ${requirejs.optimizer.settings}" />
+ </target>
+
+ <target name="assets.exists" depends="buildDir.check" if="buildDir.exists">
+ <echo>${buildDir} exists, skipping asset compilation.</echo>
+ </target>
+
+ <target name="buildDir.check">
+ <condition property="buildDir.exists">
+ <available file="${buildDir}" type="dir"/>
+ </condition>
+ </target>
+
+ <target name="generateAssets" depends="assets.exists" unless="buildDir.exists">
+ <echo message="Combining and minifying JS files." />
+ <antcall target="-optimize">
+ <param name="requirejs.optimizer.script" value="${optimizerFile}" />
+ <param name="requirejs.optimizer.settings" value="${configFile}" />
+ </antcall>
+ </target>
+</project>
View
@@ -1,37 +1,17 @@
# Chronos Web UI
-Compiling assets for the web ui is simple and done on demand, in order to speed the main build process.
-
-You *must* have built assets before packaging.
-
* [Compiling Assets](#compiling-assets)
* [Modifying Assets](#modifying-assets)
-* [Assets and Order of Operations](#assets-and-order-of-operations)
-* [Rebuild Assets by Default](#rebuild-assets-by-default)
## Compiling Assets
-To compile assets simply run:
-`mvn requirejs:optimize -P requirejs`
+Assets are automatically compiled when running `mvn package`. If you change assets, and want them updated in your jar, you must either `rm -rf src/main/resources/assets/build` or `mvn clean`.
+
## Modifying Assets
To modify assets and have changes reflected on the fly, you will need to start Chronos with a specially configured YAML file. The configuration is quite simple and is documented at [dropwizard-configurable-assets-bundle](https://github.com/bazaarvoice/dropwizard-configurable-assets-bundle/blob/master/README.md).
There are also two included example YAML files that make use of this configuration:
* [config/local_scheduler.yml](/airbnb/chronos/blob/master/config/local_scheduler.yml#L4)
-* [config/local_scheduler_nozk.yml](/airbnb/chronos/blob/master/config/local_scheduler_nozk.yml#L7)
-
-## Assets and Order of Operations
-
-If you wish to deploy, or otherwise run, a production build of Chronos with full Web UI, you must ensure that you have [built assets](#compiling-assets) before running `mvn package`.
-
-## Rebuild Assets by Default
-
-If you don't want to worry about which order you build Chronos in, you can modify `pom.xml` and switch the requirejs profile's activation from
-
-`<activeByDefault>false</activeByDefault>`
-
-to
-
-`<activeByDefault>true</activeByDefault>`
+* [config/local_scheduler_nozk.yml](/airbnb/chronos/blob/master/config/local_scheduler_nozk.yml#L7)
View
102 pom.xml
@@ -188,6 +188,19 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mozilla</groupId>
+ <artifactId>rhino</artifactId>
+ <version>1.7R4</version>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>com.google.javascript</groupId>
+ <artifactId>closure-compiler</artifactId>
+ <version>r2388</version>
+ <type>jar</type>
+ </dependency>
+
<!-- Maven scope -->
<dependency>
@@ -288,6 +301,12 @@
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<configuration>
+ <artifactSet>
+ <excludes>
+ <exclude>org.mozilla:rhino</exclude>
+ <exclude>com.google.javascript:closure-compiler</exclude>
+ </excludes>
+ </artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
@@ -385,6 +404,49 @@
</execution>
</executions>
</plugin>
+
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>2.5</version>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>src/main/resources/assets</directory>
+ <includes>
+ <include>build/**</include>
+ <include>build</include>
+ </includes>
+ <followSymlinks>false</followSymlinks>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>1.7</version>
+ <executions>
+ <execution>
+ <id>ant-run-requirejs</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target>
+ <property name="compile_classpath" refid="maven.compile.classpath"/>
+ <property name="configFile" value="${assetsdir}/app.build.js"/>
+ <property name="optimizerFile" value="${assetsdir}/r.js"/>
+ <property name="buildDir" value="${assetsdir}/build"/>
+ <ant antfile="${basedir}/build.xml">
+ <target name="generateAssets"/>
+ </ant>
+ </target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
<profiles>
@@ -420,46 +482,6 @@
</pluginManagement>
</build>
</profile>
- <profile>
- <id>requirejs</id>
- <activation>
- <activeByDefault>false</activeByDefault>
- </activation>
- <build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>com.github.mcheely</groupId>
- <artifactId>requirejs-maven-plugin</artifactId>
- <version>1.1.0</version>
- <executions>
- <execution>
- <goals>
- <goal>optimize</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <!-- path to optimizer json config file -->
- <configFile>
- ${assetsdir}/app.build.js
- </configFile>
- <!-- optional path to optimizer executable -->
- <optimizerFile>
- ${assetsdir}/r.js
- </optimizerFile>
- <filterConfig>
- false
- </filterConfig>
- <skip>
- false
- </skip>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
- </profile>
</profiles>
<reporting>
<plugins>
@@ -19,12 +19,17 @@
loggingLevel: 'WARNING'
},
fileExclusionRegExp: /^\.|spec/,
+ generateSourceMaps: true,
+ preserveLicenseComments: false,
modules: [
{
name: "main",
include: [
"jquery",
"styles"
+ ],
+ excludeShallow: [
+ 'spec_runner'
]
},
{
@@ -1,108 +0,0 @@
-/**
- * CreateClass.js
- *
- */
-define([
- 'underscore',
- 'backbone',
- 'vendor/benchmark'
-],
-function(_, Backbone, Benchmark) {
- var CreateClass;
-
- CreateClass = function CreateClass(name, _instanceMethods, _classMethods) {
- var _class, instanceMethods, classMethods, fnsToMap;
-
- if (_.isEmpty(name) || !_.isString(name)) {
- throw new Error("Name must be a non-empty string");
- }
-
- fnsToMap = function(fns) { return _.reduce((fns || []), function(memo, fn) {
- memo[fn.name] = fn;
- return memo;
- }, {}); };
-
- instanceMethods = fnsToMap(_instanceMethods);
- classMethods = fnsToMap(_classMethods);
-
- _class = eval.call(null, [
- '(function() { function ', name, '() { ',
- ' this._constructor.apply(this, Array.prototype.slice.call(arguments));',
- '}; return ', name, '; }())'
- ].join(''));
-
- _.extend(_class.prototype, {
- constructor: function() {}
- }, instanceMethods, {
- _constructor: function() {
- this.constructor.apply(this, Array.prototype.slice.call(arguments));
- }
- })
-
- _.extend(_class, {
- extend: Backbone.Model.extend
- }, classMethods);
-
- return _class;
- };
-
- var Generic = function Generic() {};
- Generic.extend = Backbone.Model.extend;
-
- CreateClass.Benchmark = function(opts) {
-
- var suite = new Benchmark.Suite('Class Benchmarks'),
- CreateGenericClass, CreateNamedClass,
- AnonymousClass, NamedClass;
-
- CreateGenericClass = function() {
- return Generic.extend({
- sayHello: function () {
- console.log('hello');
- return 'hello';
- }
- }, {
- makeMe: function () {
- return new TestKlass;
- }
- });
- };
-
- CreateNamedClass = function() {
- return CreateClass('TestKlass', [
- function sayHello() {
- console.log('hello');
- return 'hello';
- }
- ], [
- function makeMe() {
- return new TestKlass;
- }
- ]);
- };
-
- AnonymousClass = CreateGenericClass();
- NamedClass = CreateNamedClass();
-
- suite.add('CC creation', function() {
- var TestKlass = CreateNamedClass();
- });
-
- suite.add('extend creation', function() {
- var TestKlass = CreateGenericClass();
- });
-
- suite.add('CC instantiation', function() {
- var testInstance = new AnonymousClass();
- });
-
- suite.add('extend instantiation', function() {
- var testInstance = new NamedClass();
- });
-
- return suite;
-
- };
-
- return CreateClass;
-});
@@ -60,13 +60,15 @@ function(_) {
}
function RemoveOne(model) {
- var views = get(this, 'views'),
- view = views[model.cid];
+ var _views = get(this, 'views'),
+ view = views[model.cid],
+ views;
if (!view) { return; }
- views[model.cid] = null;
- delete[views[model.cid]];
+ _views[model.cid] = null;
+ views = _.omit(_views, model.cid);
+ set(this, 'views', views);
if (_.isFunction(view.terminate)) {
return view.terminate();
@@ -27,7 +27,6 @@ require.config({
'propertyParser' : 'vendor/requirejs-plugins/src/propertyParser',
'font' : 'vendor/requirejs-plugins/src/font',
'mousetrap' : 'vendor/mousetrap',
- 'benchmark' : 'vendor/benchmark',
'mocha' : 'vendor/tests/mocha',
'chai' : 'vendor/tests/chai',
'chai-jquery' : 'vendor/tests/chai-jquery',
@@ -66,10 +65,6 @@ require.config({
deps: ['jquery'],
exports: 'jQuery.fn.select2'
},
- 'benchmark': {
- deps: [],
- exports: 'Benchmark'
- },
'jquery/fastLiveFilter': {
deps: ['jquery'],
exports: 'jQuery.fn.fastLiveFilter'
@@ -108,7 +103,7 @@ require.config({
deps: ['backbone', 'underscore'],
exports: 'Backbone.Validations.Model'
}
- },
+ }
});
require(['styles', 'fonts'], function(){});
Oops, something went wrong.

0 comments on commit b718856

Please sign in to comment.