Author: julien_viet
Date: 2011-05-02 07:05:30 -0400 (Mon, 02 May 2011)
New Revision: 6434
Modified:
portal/trunk/component/common/src/main/java/conf/configuration-jboss.properties
portal/trunk/component/common/src/main/java/conf/configuration-jetty.properties
portal/trunk/component/common/src/main/java/conf/configuration-tomcat.properties
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/BaseResourceCompressorPlugin.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/ClosureCompressorPlugin.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/ResourceCompressorService.java
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/common/resource-compressor-configuration.xml
Log:
GTNPORTAL-198 : expose the resource compressor service via JMX and make the js compression
configurable for Closure via a configuration property
Modified: portal/trunk/component/common/src/main/java/conf/configuration-jboss.properties
===================================================================
---
portal/trunk/component/common/src/main/java/conf/configuration-jboss.properties 2011-05-01
21:32:42 UTC (rev 6433)
+++
portal/trunk/component/common/src/main/java/conf/configuration-jboss.properties 2011-05-02
11:05:30 UTC (rev 6434)
@@ -58,3 +58,5 @@
gatein.email.smtp.socketFactory.port=465
gatein.email.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
+# Web
+gatein.web.compressor.js.level=simple
Modified: portal/trunk/component/common/src/main/java/conf/configuration-jetty.properties
===================================================================
---
portal/trunk/component/common/src/main/java/conf/configuration-jetty.properties 2011-05-01
21:32:42 UTC (rev 6433)
+++
portal/trunk/component/common/src/main/java/conf/configuration-jetty.properties 2011-05-02
11:05:30 UTC (rev 6434)
@@ -59,4 +59,7 @@
gatein.email.smtp.starttls.enable=true
gatein.email.smtp.auth=true
gatein.email.smtp.socketFactory.port=465
-gatein.email.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
\ No newline at end of file
+gatein.email.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
+
+# Web
+gatein.web.compressor.js.level=simple
\ No newline at end of file
Modified:
portal/trunk/component/common/src/main/java/conf/configuration-tomcat.properties
===================================================================
---
portal/trunk/component/common/src/main/java/conf/configuration-tomcat.properties 2011-05-01
21:32:42 UTC (rev 6433)
+++
portal/trunk/component/common/src/main/java/conf/configuration-tomcat.properties 2011-05-02
11:05:30 UTC (rev 6434)
@@ -59,4 +59,7 @@
gatein.email.smtp.starttls.enable=true
gatein.email.smtp.auth=true
gatein.email.smtp.socketFactory.port=465
-gatein.email.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
\ No newline at end of file
+gatein.email.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
+
+# Web
+gatein.web.compressor.js.level=simple
\ No newline at end of file
Modified:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/BaseResourceCompressorPlugin.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/BaseResourceCompressorPlugin.java 2011-05-01
21:32:42 UTC (rev 6433)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/BaseResourceCompressorPlugin.java 2011-05-02
11:05:30 UTC (rev 6434)
@@ -21,15 +21,26 @@
import org.exoplatform.container.component.BaseComponentPlugin;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.ValueParam;
+import org.exoplatform.management.annotations.Managed;
+import org.exoplatform.management.annotations.ManagedDescription;
+import org.exoplatform.management.jmx.annotations.NameTemplate;
+import org.exoplatform.management.jmx.annotations.Property;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
/**
* @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
* Aug 19, 2010
*/
-
+@Managed
+@ManagedDescription("A resource compressor plugin")
+@NameTemplate({@Property(key = "service", value = "resource"),
@Property(key = "compressor", value = "{Name}")})
public abstract class BaseResourceCompressorPlugin extends BaseComponentPlugin implements
ResourceCompressorPlugin
{
+
private int priority;
+
+ protected final Logger log = LoggerFactory.getLogger(getClass());
public BaseResourceCompressorPlugin(InitParams params)
{
@@ -43,9 +54,18 @@
this.priority = -1;
}
}
-
+
+ @Managed
+ @ManagedDescription("The plugin priority")
public int getPriority()
{
return priority;
}
+
+ @Managed
+ @ManagedDescription("The plugin type")
+ public String getType()
+ {
+ return getResourceType().name();
+ }
}
Modified:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/ClosureCompressorPlugin.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/ClosureCompressorPlugin.java 2011-05-01
21:32:42 UTC (rev 6433)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/ClosureCompressorPlugin.java 2011-05-02
11:05:30 UTC (rev 6434)
@@ -18,27 +18,106 @@
*/
package org.exoplatform.portal.resource.compressor.impl;
-import com.google.javascript.jscomp.CheckLevel;
import com.google.javascript.jscomp.CompilationLevel;
import com.google.javascript.jscomp.Compiler;
import com.google.javascript.jscomp.CompilerOptions;
import com.google.javascript.jscomp.JSSourceFile;
import com.google.javascript.jscomp.WarningLevel;
import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.ValueParam;
+import org.exoplatform.management.annotations.Managed;
+import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.portal.resource.compressor.BaseResourceCompressorPlugin;
import org.exoplatform.portal.resource.compressor.ResourceCompressorException;
import org.exoplatform.portal.resource.compressor.ResourceType;
import java.io.Reader;
import java.io.Writer;
+/**
+ * A compressor based on the Google <a
href="http://code.google.com/closure/>Closure Tools</a> javascript
compiler.
+ * This plugin compresses javascript resources and provides three levels of compression,
configured
+ * via the <code>level</code> init param:
+ * <ul>
+ * <li><code>basic</code> encodes with the
<code>WHITESPACE_ONLY</code> Closure level</li>
+ * <li><code>simple</code> encodes with the
<code>SIMPLE_OPTIMIZATIONS</code> Closure level</li>
+ * <li><code>advanced</code> encodes with the
<code>ADVANCED_OPTIMIZATIONS</code> Closure level</li>
+ * </ul>
+ * The precise meaning of the Closure levels are described on
+ * <a
href="http://code.google.com/closure/compiler/docs/compilation_level...
page</a>.
+ */
public class ClosureCompressorPlugin extends BaseResourceCompressorPlugin
{
+ /** . */
+ private volatile CompilationLevel compilationLevel;
+
public ClosureCompressorPlugin(InitParams params) throws Exception
{
super(params);
+
+ //
+ ValueParam vp = params.getValueParam("level");
+ CompilationLevel level = null;
+ if (vp != null)
+ {
+ String value = vp.getValue().trim().toLowerCase();
+ log.debug("found compressor level configuration " + value);
+ setLevel(value);
+ }
+
+ //
+ if (level == null)
+ {
+ log.debug("no compressor level found, will use simple level
instead");
+ level = CompilationLevel.SIMPLE_OPTIMIZATIONS;
+ }
+
+ //
+ this.compilationLevel = level;
}
+ @Managed
+ @ManagedDescription("The compression level value among
{basic,simple,advanced}")
+ public String getLevel()
+ {
+ if (compilationLevel == CompilationLevel.WHITESPACE_ONLY)
+ {
+ return "basic";
+ }
+ else if (compilationLevel == CompilationLevel.ADVANCED_OPTIMIZATIONS)
+ {
+ return "advanced";
+ }
+ else
+ {
+ return "simple";
+ }
+ }
+
+ @Managed
+ public void setLevel(String level)
+ {
+ if (level != null)
+ {
+ level = level.trim().toLowerCase();
+ if ("basic".equals(level))
+ {
+ log.debug("configuring to basic level configuration");
+ compilationLevel = CompilationLevel.WHITESPACE_ONLY;
+ }
+ else if ("simple".equals(level))
+ {
+ log.debug("configuring to simple level configuration");
+ compilationLevel = CompilationLevel.SIMPLE_OPTIMIZATIONS;
+ }
+ else if ("advanced".equals(level))
+ {
+ log.debug("configuring to advanced level configuration");
+ compilationLevel = CompilationLevel.ADVANCED_OPTIMIZATIONS;
+ }
+ }
+ }
+
public ResourceType getResourceType()
{
return ResourceType.JAVASCRIPT;
@@ -46,12 +125,20 @@
public void compress(Reader input, Writer output) throws ResourceCompressorException
{
+ CompilationLevel level = compilationLevel;
+ if (level == null)
+ {
+ level = CompilationLevel.SIMPLE_OPTIMIZATIONS;
+ }
+
+ //
Compiler compiler = new Compiler();
CompilerOptions options = new CompilerOptions();
- CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
+ level.setOptionsForCompilationLevel(options);
WarningLevel.QUIET.setOptionsForWarningLevel(options);
JSSourceFile extern = JSSourceFile.fromCode("extern", "");
-
+
+ //
JSSourceFile jsInput;
try
{
Modified:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/ResourceCompressorService.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/ResourceCompressorService.java 2011-05-01
21:32:42 UTC (rev 6433)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/compressor/impl/ResourceCompressorService.java 2011-05-02
11:05:30 UTC (rev 6434)
@@ -28,6 +28,12 @@
import org.exoplatform.container.component.ComponentPlugin;
import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.management.ManagementAware;
+import org.exoplatform.management.ManagementContext;
+import org.exoplatform.management.annotations.Managed;
+import org.exoplatform.management.annotations.ManagedDescription;
+import org.exoplatform.management.jmx.annotations.NameTemplate;
+import org.exoplatform.management.jmx.annotations.Property;
import org.exoplatform.portal.resource.compressor.ResourceCompressor;
import org.exoplatform.portal.resource.compressor.ResourceCompressorException;
import org.exoplatform.portal.resource.compressor.ResourceCompressorPlugin;
@@ -39,14 +45,21 @@
* @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
* Aug 19, 2010
*/
-
-public class ResourceCompressorService implements ResourceCompressor
+@Managed
+@ManagedDescription("The resource compressor service")
+@NameTemplate({@Property(key = "service", value = "resource")})
+public class ResourceCompressorService implements ResourceCompressor, ManagementAware
{
+ /** . */
private Log log = ExoLogger.getLogger(ResourceCompressorService.class);
+ /** . */
private Map<ResourceType, List<ResourceCompressorPlugin>> plugins;
+ /** . */
+ private ManagementContext managementContext;
+
public ResourceCompressorService(InitParams params) throws Exception
{
@@ -133,4 +146,18 @@
return candidates.get(highestPriorityIndex);
}
+
+ public void setContext(ManagementContext context)
+ {
+ this.managementContext = context;
+
+ //
+ for (Map.Entry<ResourceType, List<ResourceCompressorPlugin>> entry :
plugins.entrySet())
+ {
+ for (ResourceCompressorPlugin plugin : entry.getValue())
+ {
+ context.register(plugin);
+ }
+ }
+ }
}
Modified:
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/common/resource-compressor-configuration.xml
===================================================================
---
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/common/resource-compressor-configuration.xml 2011-05-01
21:32:42 UTC (rev 6433)
+++
portal/trunk/web/portal/src/main/webapp/WEB-INF/conf/common/resource-compressor-configuration.xml 2011-05-02
11:05:30 UTC (rev 6434)
@@ -47,6 +47,10 @@
<name>plugin.priority</name>
<value>2</value>
</value-param>
+ <value-param>
+ <name>level</name>
+ <value>${gatein.web.compressor.js.level}</value>
+ </value-param>
</init-params>
</component-plugin>
<component-plugin>