You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/05/15 00:01:17 UTC
svn commit: r944497 [2/5] - in
/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin:
./ src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/
src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascrip...
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/DefaultAssemblerReader.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/DefaultAssemblerReader.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/DefaultAssemblerReader.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/DefaultAssemblerReader.java Fri May 14 22:01:15 2010
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.assembler;
+
+import java.io.File;
+import java.io.FileReader;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.assembler.io.xpp3.AssemblerXpp3Reader;
+import org.codehaus.plexus.logging.LogEnabled;
+import org.codehaus.plexus.logging.Logger;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class DefaultAssemblerReader
+ implements AssemblerReader, LogEnabled
+{
+ private Logger logger;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.codehaus.plexus.logging.LogEnabled#enableLogging(org.codehaus.plexus.logging.Logger)
+ */
+ public void enableLogging( Logger logger )
+ {
+ this.logger = logger;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.codehaus.mojo.javascript.assembler.AssemblerReader#getAssembler(java.io.File)
+ */
+ public Assembler getAssembler( File file )
+ throws Exception
+ {
+ AssemblerXpp3Reader reader = new AssemblerXpp3Reader();
+ try
+ {
+ logger.info( "Reading assembler descriptor " + file.getAbsolutePath() );
+ return reader.read( new FileReader( file ) );
+ }
+ catch ( Exception e )
+ {
+ throw new MojoExecutionException( "Failed to read the script assembler descriptor", e );
+ }
+ }
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/DefaultAssemblerReaderManager.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/DefaultAssemblerReaderManager.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/DefaultAssemblerReaderManager.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/DefaultAssemblerReaderManager.java Fri May 14 22:01:15 2010
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.assembler;
+
+import java.io.File;
+
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class DefaultAssemblerReaderManager
+ implements AssemblerReaderManager, Contextualizable
+{
+ private PlexusContainer container;
+
+ public void contextualize( Context context )
+ throws ContextException
+ {
+ container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.codehaus.mojo.javascript.assembler.AssemblerReaderManager#getAssemblerReader(java.io.File)
+ */
+ public AssemblerReader getAssemblerReader( File file )
+ throws NoSuchAssemblerReaderException
+ {
+ String ext = FileUtils.getExtension( file.getName() ).toLowerCase();
+ if ( "xml".equals( ext ) )
+ {
+ return getAssemblerReader( "default" );
+ }
+ return getAssemblerReader( ext );
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.codehaus.mojo.javascript.assembler.AssemblerReaderManager#getAssemblerReader(java.lang.String)
+ */
+ public AssemblerReader getAssemblerReader( String name )
+ throws NoSuchAssemblerReaderException
+ {
+ try
+ {
+ return (AssemblerReader) container.lookup( AssemblerReader.ROLE, name );
+ }
+ catch ( ComponentLookupException e )
+ {
+ throw new NoSuchAssemblerReaderException( name );
+ }
+ }
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/JsBuilderAssemblerReader.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/JsBuilderAssemblerReader.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/JsBuilderAssemblerReader.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/JsBuilderAssemblerReader.java Fri May 14 22:01:15 2010
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.assembler;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.commons.jxpath.JXPathContext;
+import org.codehaus.plexus.logging.LogEnabled;
+import org.codehaus.plexus.logging.Logger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class JsBuilderAssemblerReader
+ implements AssemblerReader, LogEnabled
+{
+ private Logger logger;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.codehaus.plexus.logging.LogEnabled#enableLogging(org.codehaus.plexus.logging.Logger)
+ */
+ public void enableLogging( Logger logger )
+ {
+ this.logger = logger;
+ }
+
+ private static final String OUTPUT = "$output/";
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.codehaus.mojo.javascript.assembler.AssemblerReader#getAssembler(java.io.File)
+ */
+ public Assembler getAssembler( File file )
+ throws Exception
+ {
+ logger.info( "Reading assembler descriptor " + file.getAbsolutePath() );
+ DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document dom = builder.parse( file );
+
+ Assembler assembler = new Assembler();
+ JXPathContext xpath = JXPathContext.newContext( dom );
+ xpath.setLenient( true );
+ String src = (String) xpath.getValue( "//directory/@name" );
+ List nodes = xpath.selectNodes( "//target" );
+ for ( Iterator iterator = nodes.iterator(); iterator.hasNext(); )
+ {
+ Node node = (Node) iterator.next();
+ Script script = new Script();
+ assembler.addScript( script );
+ JXPathContext nodeContext = JXPathContext.newContext( node );
+ String fileName = (String) nodeContext.getValue( "@file" );
+ fileName = fileName.replace( '\\', '/' );
+ if ( fileName.startsWith( OUTPUT ) )
+ {
+ fileName = fileName.substring( OUTPUT.length() );
+ }
+ script.setFileName( fileName );
+
+ for ( Iterator iter = nodeContext.iterate( "//include/@name" ); iter.hasNext(); )
+ {
+ String include = ( (String) iter.next() ).replace( '\\', '/' );
+ if ( src != null && src.length() > 0 )
+ {
+ include = include.substring( src.length() + 1 );
+ }
+ script.addInclude( include );
+ }
+ }
+ return assembler;
+ }
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/NoSuchAssemblerReaderException.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/NoSuchAssemblerReaderException.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/NoSuchAssemblerReaderException.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/NoSuchAssemblerReaderException.java Fri May 14 22:01:15 2010
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.assembler;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class NoSuchAssemblerReaderException
+ extends Exception
+{
+ private String assemblerName;
+
+ public NoSuchAssemblerReaderException( String name )
+ {
+ super( "No such assembler reader: '" + name + "'." );
+ this.assemblerName = name;
+ }
+
+ /**
+ * @return the assemblerName
+ */
+ public String getAssemblerName()
+ {
+ return assemblerName;
+ }
+
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/CompressionException.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/CompressionException.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/CompressionException.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/CompressionException.java Fri May 14 22:01:15 2010
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.compress;
+
+import java.io.File;
+
+/**
+ * Exception during compression of some JavaScript file
+ */
+public class CompressionException extends Exception {
+
+ /** generated */
+ private static final long serialVersionUID = 1282418066985382856L;
+
+ /** The script that cannot be compressed */
+ private File script;
+
+ public CompressionException() {
+ super();
+ }
+
+ public CompressionException( File script ) {
+ super();
+ this.script = script;
+ }
+
+ public CompressionException(String message, Throwable cause, File script) {
+ super(message, cause);
+ this.script = script;
+ }
+
+ public CompressionException(String message, File script) {
+ super(message);
+ this.script = script;
+ }
+
+ public CompressionException(Throwable cause, File script) {
+ super(cause);
+ this.script = script;
+ }
+
+ public File getScript() {
+ return script;
+ }
+
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/IsolatedClassLoader.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/IsolatedClassLoader.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/IsolatedClassLoader.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/IsolatedClassLoader.java Fri May 14 22:01:15 2010
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.compress;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class IsolatedClassLoader
+ extends URLClassLoader
+{
+
+ public IsolatedClassLoader( Artifact artifact )
+ {
+ super( getArtifactURLs( artifact ) );
+ }
+
+ public IsolatedClassLoader( Collection artifacts )
+ {
+ super( getArtifactURLs( artifacts ) );
+ }
+
+ private static URL[] getArtifactURLs( Collection artifacts )
+ {
+ URL[] urls = new URL[artifacts.size()];
+ try
+ {
+ int i = 0;
+ for ( Iterator iterator = artifacts.iterator(); iterator.hasNext(); )
+ {
+ Artifact artifact = (Artifact) iterator.next();
+ urls[i++] = artifact.getFile().toURL();
+ }
+ }
+ catch ( MalformedURLException e )
+ {
+ return null;
+ }
+ return urls;
+ }
+
+ private static URL[] getArtifactURLs( Artifact artifact )
+ {
+ URL url;
+ try
+ {
+ url = artifact.getFile().toURL();
+ return new URL[] { url };
+ }
+ catch ( MalformedURLException e )
+ {
+ return null;
+ }
+ }
+
+ public Class loadClass( String name )
+ throws ClassNotFoundException
+ {
+
+ Class c = findLoadedClass( name );
+ if ( c == null )
+ {
+ try
+ {
+ return findClass( name );
+ }
+ catch ( ClassNotFoundException e )
+ {
+ return super.loadClass( name );
+ }
+ }
+ return super.loadClass( name );
+ }
+
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/JSCompressor.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/JSCompressor.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/JSCompressor.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/JSCompressor.java Fri May 14 22:01:15 2010
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.compress;
+
+import java.io.File;
+
+/**
+ * Abstraction of a JS compression tool.
+ */
+public interface JSCompressor
+{
+
+ /**
+ * Constants for optimization level
+ */
+ int NONE = 0;
+
+ int MAX = 9;
+
+ /**
+ * Javascript language versions
+ */
+ int JAVASCRIPT_1_1 = 110;
+
+ int JAVASCRIPT_1_2 = 120;
+
+ int JAVASCRIPT_1_3 = 130;
+
+ /**
+ * Compress the input script file into the output file (may be same).
+ *
+ * @param input source to get compressed
+ * @param output compressed script
+ * @param level optimization level from 0 to 9. May have various
+ * signification dependending on the compressor, from beeing ignored to some
+ * fine tweaking the output.
+ * @param language version of javascript to be used ("130" for JS 1.3), as
+ * defined by Mozilla Rhino engine
+ * @throws CompressionException any error during compression
+ */
+ void compress( File input, File output, int level, int language )
+ throws CompressionException;
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/JSCompressorProxy.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/JSCompressorProxy.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/JSCompressorProxy.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/JSCompressorProxy.java Fri May 14 22:01:15 2010
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.compress;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+
+/**
+ * @author ndeloof
+ */
+public class JSCompressorProxy
+ implements JSCompressor
+{
+
+ private Object compressor;
+
+ private Method compress;
+
+ public JSCompressorProxy( Object compressor )
+ throws InitializationException
+ {
+ super();
+ this.compressor = compressor;
+ try
+ {
+ this.compress =
+ compressor.getClass().getMethod( "compress",
+ new Class[] { File.class, File.class, int.class, int.class } );
+ }
+ catch ( Exception e )
+ {
+ throw new InitializationException(
+ "proxied object has no method compress(File,File,int,int)" );
+ }
+ }
+
+ public void compress( File input, File output, int level, int language )
+ throws CompressionException
+ {
+ try
+ {
+ compress.invoke( compressor, new Object[] { input, output, Integer.valueOf( level ),
+ Integer.valueOf( language ) } );
+ }
+ catch ( InvocationTargetException e )
+ {
+ if ( e.getTargetException() instanceof CompressionException )
+ {
+ throw (CompressionException) e.getTargetException();
+ }
+ throw new CompressionException( "Failed to compress JS file", e, input );
+ }
+ catch ( Exception e )
+ {
+ throw new CompressionException( "Failed to compress JS file", e, input );
+ }
+ }
+
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/JSMinCompressor.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/JSMinCompressor.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/JSMinCompressor.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/JSMinCompressor.java Fri May 14 22:01:15 2010
@@ -0,0 +1,317 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.compress;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PushbackInputStream;
+
+/**
+ * Use the Java version of the JSMin algorithm to compress a set of JS files.
+ * For simplicity, the JSMin code (one class) is included in the plugin.
+ *
+ * @see http://www.crockford.com/javascript/jsmin.html
+ * @author <a href="mailto:nicolas@apache.org">nicolas De Loof</a>
+ */
+public class JSMinCompressor
+ implements JSCompressor
+{
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.codehaus.mojo.javascript.compress.JSCompressor#compress(java.io.File,
+ * java.io.File, int, int)
+ */
+ public void compress( File input, File output, int level, int language )
+ throws CompressionException
+ {
+ try
+ {
+ new JSMin( new FileInputStream( input ), new FileOutputStream( output ) ).jsmin();
+ }
+ catch ( Exception e )
+ {
+ throw new CompressionException( "Failed to create compressed file", e, input );
+ }
+ }
+
+ public static class JSMin {
+ private static final int EOF = -1;
+
+ private PushbackInputStream in;
+ private OutputStream out;
+
+ private int theA;
+ private int theB;
+
+ public JSMin(InputStream in, OutputStream out) {
+ this.in = new PushbackInputStream(in);
+ this.out = out;
+ }
+
+ /**
+ * isAlphanum -- return true if the character is a letter, digit,
+ * underscore, dollar sign, or non-ASCII character.
+ */
+ static boolean isAlphanum(int c) {
+ return ( (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
+ (c >= 'A' && c <= 'Z') || c == '_' || c == '$' || c == '\\' ||
+ c > 126);
+ }
+
+ /**
+ * get -- return the next character from stdin. Watch out for lookahead. If
+ * the character is a control character, translate it to a space or
+ * linefeed.
+ */
+ int get() throws IOException {
+ int c = in.read();
+
+ if (c >= ' ' || c == '\n' || c == EOF) {
+ return c;
+ }
+
+ if (c == '\r') {
+ return '\n';
+ }
+
+ return ' ';
+ }
+
+
+
+ /**
+ * Get the next character without getting it.
+ */
+ int peek() throws IOException {
+ int lookaheadChar = in.read();
+ in.unread(lookaheadChar);
+ return lookaheadChar;
+ }
+
+ /**
+ * next -- get the next character, excluding comments. peek() is used to see
+ * if a '/' is followed by a '/' or '*'.
+ */
+ int next() throws IOException, UnterminatedCommentException {
+ int c = get();
+ if (c == '/') {
+ switch (peek()) {
+ case '/':
+ for (;;) {
+ c = get();
+ if (c <= '\n') {
+ return c;
+ }
+ }
+
+ case '*':
+ get();
+ for (;;) {
+ switch (get()) {
+ case '*':
+ if (peek() == '/') {
+ get();
+ return ' ';
+ }
+ break;
+ case EOF:
+ throw new UnterminatedCommentException();
+ }
+ }
+
+ default:
+ return c;
+ }
+
+ }
+ return c;
+ }
+
+ /**
+ * action -- do something! What you do is determined by the argument: 1
+ * Output A. Copy B to A. Get the next B. 2 Copy B to A. Get the next B.
+ * (Delete A). 3 Get the next B. (Delete B). action treats a string as a
+ * single character. Wow! action recognizes a regular expression if it is
+ * preceded by ( or , or =.
+ */
+
+ void action(int d) throws IOException, UnterminatedRegExpLiteralException,
+ UnterminatedCommentException, UnterminatedStringLiteralException {
+ switch (d) {
+ case 1:
+ out.write(theA);
+ case 2:
+ theA = theB;
+
+ if (theA == '\'' || theA == '"') {
+ for (;;) {
+ out.write(theA);
+ theA = get();
+ if (theA == theB) {
+ break;
+ }
+ if (theA <= '\n') {
+ throw new UnterminatedStringLiteralException();
+ }
+ if (theA == '\\') {
+ out.write(theA);
+ theA = get();
+ }
+ }
+ }
+
+ case 3:
+ theB = next();
+ if (theB == '/' && (theA == '(' || theA == ',' || theA == '=' ||
+ theA == ':' || theA == '[' || theA == '!' ||
+ theA == '&' || theA == '|' || theA == '?' ||
+ theA == '{' || theA == '}' || theA == ';' ||
+ theA == '\n')) {
+ out.write(theA);
+ out.write(theB);
+ for (;;) {
+ theA = get();
+ if (theA == '/') {
+ break;
+ } else if (theA == '\\') {
+ out.write(theA);
+ theA = get();
+ } else if (theA <= '\n') {
+ throw new UnterminatedRegExpLiteralException();
+ }
+ out.write(theA);
+ }
+ theB = next();
+ }
+ }
+ }
+
+ /**
+ * jsmin -- Copy the input to the output, deleting the characters which are
+ * insignificant to JavaScript. Comments will be removed. Tabs will be
+ * replaced with spaces. Carriage returns will be replaced with linefeeds.
+ * Most spaces and linefeeds will be removed.
+ */
+ public void jsmin() throws IOException, UnterminatedRegExpLiteralException, UnterminatedCommentException, UnterminatedStringLiteralException{
+ theA = '\n';
+ action(3);
+ while (theA != EOF) {
+ switch (theA) {
+ case ' ':
+ if (isAlphanum(theB)) {
+ action(1);
+ } else {
+ action(2);
+ }
+ break;
+ case '\n':
+ switch (theB) {
+ case '{':
+ case '[':
+ case '(':
+ case '+':
+ case '-':
+ action(1);
+ break;
+ case ' ':
+ action(3);
+ break;
+ default:
+ if (isAlphanum(theB)) {
+ action(1);
+ } else {
+ action(2);
+ }
+ }
+ break;
+ default:
+ switch (theB) {
+ case ' ':
+ if (isAlphanum(theA)) {
+ action(1);
+ break;
+ }
+ action(3);
+ break;
+ case '\n':
+ switch (theA) {
+ case '}':
+ case ']':
+ case ')':
+ case '+':
+ case '-':
+ case '"':
+ case '\'':
+ action(1);
+ break;
+ default:
+ if (isAlphanum(theA)) {
+ action(1);
+ } else {
+ action(3);
+ }
+ }
+ break;
+ default:
+ action(1);
+ break;
+ }
+ }
+ }
+ out.flush();
+ }
+
+ class UnterminatedCommentException extends Exception {
+ }
+
+ class UnterminatedStringLiteralException extends Exception {
+ }
+
+ class UnterminatedRegExpLiteralException extends Exception {
+ }
+
+ public static void main(String arg[]) {
+ try {
+ JSMin jsmin = new JSMin(new FileInputStream(arg[0]), System.out);
+ jsmin.jsmin();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (ArrayIndexOutOfBoundsException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (UnterminatedRegExpLiteralException e) {
+ e.printStackTrace();
+ } catch (UnterminatedCommentException e) {
+ e.printStackTrace();
+ } catch (UnterminatedStringLiteralException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ }
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/ShrinksafeCompressor.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/ShrinksafeCompressor.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/ShrinksafeCompressor.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/ShrinksafeCompressor.java Fri May 14 22:01:15 2010
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.compress;
+
+import java.io.File;
+import java.io.PrintStream;
+
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringOutputStream;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.ContextAction;
+import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.tools.ToolErrorReporter;
+import org.mozilla.javascript.tools.shell.Global;
+import org.mozilla.javascript.tools.shell.Main;
+import org.mozilla.javascript.tools.shell.ShellContextFactory;
+
+/**
+ * A JS compressor that uses Dojo modified Rhino engine to compress the script.
+ * The resulting compressed-js is garanteed to be functionaly equivalent as this
+ * is the internal view of the rhino context.
+ *
+ * @author <a href="mailto:nicolas@apache.org">nicolas De Loof</a>
+ */
+public class ShrinksafeCompressor
+ implements JSCompressor
+{
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.compress.mojo.javascript.compress.JSCompressor#compress(java.io.File,
+ * java.io.File, int, int)
+ */
+ public void compress( final File input, File compressed, int level, int language )
+ throws CompressionException
+ {
+ PrintStream o = System.out;
+ System.setOut( new PrintStream( new StringOutputStream() ) );
+ PrintStream out = null;
+ try
+ {
+ String[] args = new String[3];
+ args[0] = "-c"; // Set Main.outputCompressed = true
+ args[1] = "-o"; // Set Main.outputFileName
+ args[2] = compressed.getAbsolutePath();
+
+ Main.processOptions( args );
+
+ final ToolErrorReporter errorReporter = new ToolErrorReporter( false, System.err );
+ errorReporter.setIsReportingWarnings( false );
+
+ final ShellContextFactory shellContextFactory = new ShellContextFactory();
+ shellContextFactory.setLanguageVersion( language );
+ shellContextFactory.setOptimizationLevel( level );
+ shellContextFactory.setErrorReporter( errorReporter );
+ shellContextFactory.setStrictMode( true );
+
+ final Global scope = new Global();
+ scope.init( shellContextFactory );
+
+ shellContextFactory.call( new ContextAction()
+ {
+ public Object run( Context context )
+ {
+ Object[] args = new Object[1];
+ scope.defineProperty( "arguments", args, ScriptableObject.DONTENUM );
+ Main.processFile( context, scope, input.getAbsolutePath() );
+ return null;
+ }
+ } );
+ }
+ catch ( Exception e )
+ {
+ throw new CompressionException( "Failed to create compressed file", e, input );
+ }
+ finally
+ {
+ System.setOut( o );
+ IOUtil.close( out );
+ }
+ }
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/YahooUICompressor.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/YahooUICompressor.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/YahooUICompressor.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/YahooUICompressor.java Fri May 14 22:01:15 2010
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.compress;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+
+import org.codehaus.plexus.util.IOUtil;
+import org.mozilla.javascript.ErrorReporter;
+import org.mozilla.javascript.EvaluatorException;
+
+import com.yahoo.platform.yui.compressor.JavaScriptCompressor;
+
+/**
+ * A JS compressor that uses Dojo modified Rhino engine to compress the script.
+ * The resulting compressed-js is garanteed to be functionaly equivalent as this
+ * is the internal view of the rhino context.
+ *
+ * @author <a href="mailto:nicolas@apache.org">nicolas De Loof</a>
+ */
+public class YahooUICompressor
+ implements JSCompressor
+{
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.compress.mojo.javascript.compress.JSCompressor#compress(java.io.File,
+ * java.io.File, int, int)
+ */
+ public void compress( final File input, File compressed, int level, int language )
+ throws CompressionException
+ {
+ FileWriter out = null;
+ try
+ {
+ JavaScriptCompressor compressor =
+ new JavaScriptCompressor( new FileReader( input ), new ErrorReporter()
+ {
+
+ public void warning( String message, String sourceName, int line,
+ String lineSource, int lineOffset )
+ {
+ if ( line < 0 )
+ {
+ System.err.println( "\n[WARNING] " + message );
+ }
+ else
+ {
+ System.err.println( "\n" + line + ':' + lineOffset + ':' + message );
+ }
+ }
+
+ public void error( String message, String sourceName, int line,
+ String lineSource, int lineOffset )
+ {
+ if ( line < 0 )
+ {
+ System.err.println( "\n[ERROR] " + message );
+ }
+ else
+ {
+ System.err.println( "\n" + line + ':' + lineOffset + ':' + message );
+ }
+ }
+
+ public EvaluatorException runtimeError( String message, String sourceName,
+ int line, String lineSource,
+ int lineOffset )
+ {
+ error( message, sourceName, line, lineSource, lineOffset );
+ return new EvaluatorException( message );
+ }
+ } );
+
+ int linebreakpos = level < 4 ? -1 : 80;
+ boolean munge = level < 3;
+ boolean preserveAllSemiColons = level < 2;
+ boolean preserveStringLiterals = level < 1;
+
+ out = new FileWriter( compressed );
+ compressor.compress( out, linebreakpos, munge, true, preserveAllSemiColons,
+ preserveStringLiterals );
+ }
+ catch ( Exception e )
+ {
+ throw new CompressionException( "Failed to create compressed file", e, input );
+ }
+ finally
+ {
+ IOUtil.close( out );
+ }
+ }
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/mdo/assembler.mdo
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/mdo/assembler.mdo?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/mdo/assembler.mdo (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/mdo/assembler.mdo Fri May 14 22:01:15 2010
@@ -0,0 +1,104 @@
+<?xml version="1.0"?>
+
+<!--
+ ~ Copyright 2006 The Apache Software Foundation.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<model xsd.namespace="http://mojo.codehaus.org/javascript-maven-plugin">
+ <id>assembler</id>
+ <name>Assembler</name>
+ <description>
+ <![CDATA[
+ <p>
+ JavaScript Maven Plugin relies on the provided assembler to describe how to
+ assemble source scripts into the packaging directory.
+ </p>
+ <p>
+ This descriptor specifies a set of target script to be created by merging
+ some source scripts in the specified order.
+ </p>
+ ]]>
+ </description>
+ <defaults>
+ <default>
+ <key>package</key>
+ <value>org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.assembler</value>
+ </default>
+ </defaults>
+ <classes>
+ <class rootElement="true" xml.tagName="assembler">
+ <name>Assembler</name>
+ <description>
+ <![CDATA[
+ An assembler defines a collection of files to be created in the
+ packaging directory based on source scripts. Many script developer use
+ fine grained scripts for development and merge them during release. The
+ assembler describe the files to get merged and the ordering.
+ ]]>
+ </description>
+ <version>1.0.0+</version>
+ <fields>
+ <field>
+ <name>scripts</name>
+ <version>1.0.0+</version>
+ <association>
+ <type>Script</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ <description>
+ <![CDATA[
+ Specifies a merge to occur on a set of source files.
+ ]]>
+ </description>
+ </field>
+ </fields>
+ </class>
+
+ <class xml.tagName="script">
+ <description>
+ <![CDATA[
+ Merge multiple source scripts into a target script.
+ ]]>
+ </description>
+ <name>Script</name>
+ <version>1.0.0+</version>
+ <fields>
+ <field>
+ <name>fileName</name>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <description>
+ The script to be created by the merge.
+ </description>
+ </field>
+ <field>
+ <name>includes</name>
+ <version>1.0.0+</version>
+ <description>
+ <![CDATA[
+ This is a list of <include/> subelements, each containing a
+ source script reference. Scripts matching these elements will be
+ merged in the target script, in the order they are configured.
+ ]]>
+ </description>
+ <association>
+ <type>String</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ </fields>
+ </class>
+ </classes>
+</model>
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/resources/META-INF/plexus/components.xml?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/resources/META-INF/plexus/components.xml (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/main/resources/META-INF/plexus/components.xml Fri May 14 22:01:15 2010
@@ -0,0 +1,113 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+-->
+<component-set>
+ <components>
+
+ <!--
+ A custom artifact handler for javascript archives (jsar).
+ This requires the plugin to be configured with <extensions> set to true
+ on any project that uses javascript depedencies.
+ -->
+ <component>
+ <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
+ <role-hint>javascript</role-hint>
+ <implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
+ <configuration>
+ <type>javascript</type>
+ <extension>jar</extension>
+ <language>javascript</language>
+ <addedToClasspath>false</addedToClasspath>
+ </configuration>
+ </component>
+
+ <!--
+ A custom lifecycle for javascript packaging
+ -->
+ <component>
+ <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
+ <role-hint>javascript</role-hint>
+ <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
+ <configuration>
+ <lifecycles>
+ <lifecycle>
+ <id>default</id>
+ <phases>
+ <process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
+ <compile>org.apache.myfaces.buildtools:myfaces-javascript-plugin:compile</compile>
+ <process-test-resources>org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
+ <test-compile>org.apache.myfaces.buildtools:myfaces-javascript-plugin:prepare-tests</test-compile>
+ <test>org.apache.myfaces.buildtools:myfaces-javascript-plugin:jsunit</test>
+ <package>org.apache.myfaces.buildtools:myfaces-javascript-plugin:package</package>
+ <install>org.apache.maven.plugins:maven-install-plugin:install</install>
+ <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
+ </phases>
+ </lifecycle>
+ </lifecycles>
+ </configuration>
+ </component>
+
+ <component>
+ <role>org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.assembler.AssemblerReader</role>
+ <role-hint>default</role-hint>
+ <implementation>org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.assembler.DefaultAssemblerReader</implementation>
+ <description></description>
+ </component>
+ <component>
+ <role>org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.assembler.AssemblerReaderManager</role>
+ <implementation>org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.assembler.DefaultAssemblerReaderManager</implementation>
+ <description></description>
+ </component>
+ <component>
+ <role>org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.assembler.AssemblerReader</role>
+ <role-hint>jsbuilder</role-hint>
+ <implementation>org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.assembler.JsBuilderAssemblerReader</implementation>
+ <description></description>
+ </component>
+ <component>
+ <role>org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.archive.JavascriptArtifactManager</role>
+ <implementation>org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.archive.JavascriptArtifactManager</implementation>
+ <description>A component to handle javascript dependencies.</description>
+ <isolated-realm>false</isolated-realm>
+ <requirements>
+ <requirement>
+ <role>org.codehaus.plexus.archiver.UnArchiver</role>
+ <role-hint>javascript</role-hint>
+ <field-name>archiver</field-name>
+ </requirement>
+ </requirements>
+ </component>
+ <component>
+ <role>org.codehaus.plexus.archiver.UnArchiver</role>
+ <role-hint>javascript</role-hint>
+ <implementation>org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.archive.JavascriptUnArchiver</implementation>
+ <description>Custom archiver for javascript dependencies, packaged as "jsar" (JavaScript
+ARchive), that are simply a jar of scripts and resources.</description>
+ <isolated-realm>false</isolated-realm>
+ </component>
+ <component>
+ <role>org.codehaus.plexus.archiver.Archiver</role>
+ <role-hint>javascript</role-hint>
+ <implementation>org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.archive.JavascriptArchiver</implementation>
+ <instantiation-strategy>per-lookup</instantiation-strategy>
+ <description>Custom archiver for javascript dependencies, packaged as "jsar" (JavaScript
+ARchive), that are simply a jar of scripts and resources.</description>
+ <isolated-realm>false</isolated-realm>
+ </component>
+ </components>
+</component-set>
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/CompileMojoTest.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/CompileMojoTest.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/CompileMojoTest.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/CompileMojoTest.java Fri May 14 22:01:15 2010
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt;
+
+import java.io.File;
+
+import org.apache.maven.plugin.Mojo;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">nicolas De Loof</a>
+ */
+public class CompileMojoTest
+ extends AbstractMojoTestCase
+{
+ public void testCompileAndAssemble()
+ throws Exception
+ {
+ File testPom = new File( getBasedir(), "src/test/resources/compile.pom" );
+ Mojo mojo = (Mojo) lookupMojo( "compile", testPom );
+ assertNotNull( "Failed to configure the plugin", mojo );
+
+ mojo.execute();
+
+ File expected = new File( "./target/test-target/compile/scriptaculous.js" );
+ assertTrue( "expected file not found " + expected.getName(), expected.exists() );
+
+ expected = new File( "./target/test-target/compile/prototype.js" );
+ assertTrue( "expected file not found " + expected.getName(), expected.exists() );
+
+ String merged = FileUtils.fileRead( expected );
+ assertTrue( "builder not merged", merged.contains( "var Builder = {" ) );
+ assertTrue( "slider not merged", merged.contains( "Slider.prototype = {" ) );
+
+ File unexpected = new File( "./target/test-target/compile/builder.js" );
+ assertTrue( "unexpected file found " + unexpected.getName(), !unexpected.exists() );
+
+ unexpected = new File( "./target/test-target/compile/slider.js" );
+ assertTrue( "unexpected file found " + unexpected.getName(), !unexpected.exists() );
+ }
+}
\ No newline at end of file
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/CompressMojoTest.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/CompressMojoTest.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/CompressMojoTest.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/CompressMojoTest.java Fri May 14 22:01:15 2010
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+import org.apache.maven.plugin.Mojo;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+public class CompressMojoTest
+ extends AbstractMojoTestCase
+{
+ public void testAttachCompressedScriptaculous()
+ throws Exception
+ {
+ File testPom = new File( getBasedir(), "src/test/resources/attach-compressed.pom" );
+ Mojo mojo = (Mojo) lookupMojo( "attach-compressed", testPom );
+ assertNotNull( "Failed to configure the plugin", mojo );
+
+ mojo.execute();
+
+ File[] js = getScripts( "./src/test/resources/scripts" );
+ long size = 0;
+ for ( int i = 0; i < js.length; i++ )
+ {
+ size += js[i].length();
+ }
+
+ File expected =
+ new File( "./target/test-target/attach-compressed/scriptaculous-1.7-compressed.jar" );
+ assertTrue( "expected file not found " + expected, expected.exists() );
+ assertTrue( "no compression occured", expected.length() < size );
+ }
+
+ public void testCompressScriptaculous()
+ throws Exception
+ {
+ File target = new File( "target/test-target/compress" );
+ target.mkdirs();
+ FileUtils.cleanDirectory( target );
+ FileUtils.copyDirectory( new File( "src/test/resources/scripts" ), target );
+
+ File testPom = new File( getBasedir(), "/target/test-classes/compress.pom" );
+ Mojo mojo = (Mojo) lookupMojo( "compress", testPom );
+ assertNotNull( "Failed to configure the plugin", mojo );
+
+ mojo.execute();
+
+ File[] js = getScripts( "./src/test/resources/scripts" );
+ for ( int i = 0; i < js.length; i++ )
+ {
+ File expected = new File( target, js[i].getName().replace( ".js", "-compressed.js" ) );
+ assertTrue( "expected file not found " + expected.getName(), expected.exists() );
+ assertTrue( "no compression occured on " + expected.getName(),
+ expected.length() < js[i].length() );
+ }
+ }
+
+ public void testZeroLengthInput()
+ throws Exception
+ {
+ File target = new File( "target/test-target/compress-zero-length" );
+ target.mkdirs();
+ FileUtils.cleanDirectory( target );
+ FileUtils.copyDirectory( new File( "src/test/resources/zero-length" ), target );
+
+ File testPom = new File( getBasedir(), "/target/test-classes/compress-zero-length.pom" );
+ Mojo mojo = (Mojo) lookupMojo( "compress", testPom );
+ assertNotNull( "Failed to configure the plugin", mojo );
+
+ mojo.execute();
+
+ File[] js = getScripts( "./src/test/resources/zero-length" );
+ for ( int i = 0; i < js.length; i++ )
+ {
+ File expected = new File( target, js[i].getName().replace( ".js", "-min.js" ) );
+ assertTrue( "expected file not found " + expected.getName(), expected.exists() );
+ }
+ }
+
+ private File[] getScripts( String path )
+ {
+ File[] js = new File( path ).listFiles( new FilenameFilter()
+ {
+ public boolean accept( File dir, String name )
+ {
+ return name.endsWith( ".js" );
+ }
+ } );
+ return js;
+ }
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/StripDebugsMojoTest.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/StripDebugsMojoTest.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/StripDebugsMojoTest.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/StripDebugsMojoTest.java Fri May 14 22:01:15 2010
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt;
+
+import java.io.File;
+
+import org.apache.maven.plugin.Mojo;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.codehaus.plexus.util.FileUtils;
+
+public class StripDebugsMojoTest
+ extends AbstractMojoTestCase
+{
+ public void testStripDebugs()
+ throws Exception
+ {
+ File target = new File( "target/test-target/strip-debugs" );
+ target.mkdirs();
+ FileUtils.cleanDirectory( target );
+ FileUtils.copyFileToDirectory( new File( "src/test/resources/with-debug/debugs.js" ),
+ target );
+
+ File testPom = new File( getBasedir(), "src/test/resources/strip-debugs.pom" );
+ Mojo mojo = (Mojo) lookupMojo( "compress", testPom );
+ assertNotNull( "Failed to configure the plugin", mojo );
+
+ mojo.execute();
+
+ File expected = new File( "./target/test-target/strip-debugs/debugs.js" );
+
+ assertTrue( "Expected the stripped file to have non-zero length.", expected.length() > 0 );
+
+ String source = FileUtils.fileRead( expected );
+ assertTrue( source.indexOf( "logger" ) < 0 );
+ }
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/WarPackageMojoTest.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/WarPackageMojoTest.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/WarPackageMojoTest.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/WarPackageMojoTest.java Fri May 14 22:01:15 2010
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt;
+
+import java.io.File;
+
+import org.apache.maven.plugin.Mojo;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+
+public class WarPackageMojoTest
+ extends AbstractMojoTestCase
+{
+ public void testCopyJsSources()
+ throws Exception
+ {
+ File testPom = new File( getBasedir(), "src/test/resources/war-package.pom" );
+ Mojo mojo = (Mojo) lookupMojo( "war-package", testPom );
+ assertNotNull( "Failed to configure the plugin", mojo );
+
+ mojo.execute();
+
+ assertTrue( new File( "./target/test-target/war-package/scripts/lib/prototype.js" ).exists() );
+ assertTrue( new File( "./target/test-target/war-package/scripts/builder.js" ).exists() );
+ assertTrue( new File( "./target/test-target/war-package/scripts/controls.js" ).exists() );
+ }
+}
\ No newline at end of file
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/JsBuilderAssemblerReaderTest.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/JsBuilderAssemblerReaderTest.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/JsBuilderAssemblerReaderTest.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/assembler/JsBuilderAssemblerReaderTest.java Fri May 14 22:01:15 2010
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.assembler;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.plugin.testing.SilentLog;
+
+public class JsBuilderAssemblerReaderTest
+ extends TestCase
+{
+ public void testReadJsBuilderAssembler()
+ throws Exception
+ {
+ JsBuilderAssemblerReader reader = new JsBuilderAssemblerReader();
+ reader.enableLogging( new SilentLog() );
+ Assembler assembler = reader.getAssembler( new File( "src/test/resources/assembler.jsb" ) );
+ assertEquals( 2, assembler.getScripts().size() );
+ Script script = (Script) assembler.getScripts().get( 0 );
+ assertEquals( "test.js", script.getFileName() );
+ assertEquals( 3, script.getIncludes().size() );
+ assertEquals( "builder.js", script.getIncludes().get( 0 ).toString() );
+ }
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/IsolatedClassLoaderTest.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/IsolatedClassLoaderTest.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/IsolatedClassLoaderTest.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/IsolatedClassLoaderTest.java Fri May 14 22:01:15 2010
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.compress;
+
+import java.io.File;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.codehaus.plexus.PlexusTestCase;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
+ */
+public class IsolatedClassLoaderTest
+ extends PlexusTestCase
+{
+
+ private ArtifactFactory artifactFactory;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.class.getName() );
+ }
+
+ /**
+ * Ensure a class can be loaded in isolation based on an artifact
+ */
+ public void testLoadClassInIsolation()
+ throws Exception
+ {
+ // Create an artifact for junit.jar
+ Artifact artifact =
+ artifactFactory.createArtifact( "junit", "junit", "3.8.2", DefaultArtifact.SCOPE_TEST,
+ "jar" );
+ // locate junit.jar based on current loader class
+ URL url = getClass().getClassLoader().getResource( "junit/framework/TestCase.class" );
+ String path = url.toString();
+ assertTrue( "junit TestCase class is not loaded from a jar", path.startsWith( "jar:" ) );
+ int i = path.indexOf( '!' );
+ url = new URL( path.substring( 4, i ) );
+
+ // setup the isolated classloader
+ artifact.setFile( new File( url.getFile() ) );
+ ClassLoader cl = new IsolatedClassLoader( artifact );
+
+ Class isolated = cl.loadClass( "junit.framework.TestCase" );
+ assertNotNull( "failed to load TestCase class in isolation", isolated );
+ assertTrue( "TestCase loaded, but not in isolation", isolated != TestCase.class );
+ }
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/YahooUICompressorTest.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/YahooUICompressorTest.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/YahooUICompressorTest.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/compress/YahooUICompressorTest.java Fri May 14 22:01:15 2010
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.compress;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">nicolas De Loof</a>
+ */
+public class YahooUICompressorTest
+ extends TestCase
+{
+ private JSCompressor compressor = new YahooUICompressor();
+
+ /**
+ * Check the compressor is invoked as expected.
+ *
+ * @throws Exception
+ */
+ public void testCompress()
+ throws Exception
+ {
+ File input = new File( "src/test/resources/test.js" );
+ File output = new File( "target/test-out.js" );
+
+ compressor.compress( input, output, JSCompressor.MAX, JSCompressor.JAVASCRIPT_1_3 );
+
+ assertTrue( "exepected file not found", output.exists() );
+ assertTrue( "no compression occured", output.length() < input.length() );
+ }
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/stub/ArtifactStub.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/stub/ArtifactStub.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/stub/ArtifactStub.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/stub/ArtifactStub.java Fri May 14 22:01:15 2010
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.stub;
+
+import org.apache.maven.artifact.versioning.VersionRange;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">nicolas De Loof</a>
+ */
+public class ArtifactStub
+ extends org.apache.maven.plugin.testing.stubs.ArtifactStub
+{
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.maven.plugin.testing.stubs.ArtifactStub#getVersionRange()
+ */
+ public VersionRange getVersionRange()
+ {
+ return VersionRange.createFromVersion( getVersion() );
+ }
+}
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/stub/MavenProjectStub.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/stub/MavenProjectStub.java?rev=944497&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/stub/MavenProjectStub.java (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-javascript-plugin/src/test/java/org/apache/myfaces/buildtools/maven2/plugin/javascript/jmt/stub/MavenProjectStub.java Fri May 14 22:01:15 2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.stub;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.plugin.testing.stubs.ArtifactStub;
+import org.apache.myfaces.buildtools.maven2.plugin.javascript.jmt.archive.Types;
+
+/**
+ * @author <a href="mailto:nicolas@apache.org">nicolas De Loof</a>
+ */
+public class MavenProjectStub
+ extends org.apache.maven.plugin.testing.stubs.MavenProjectStub
+{
+ private ArtifactStub artifact;
+ {
+ artifact = new ArtifactStub();
+ artifact.setGroupId( "org.prototypejs" );
+ artifact.setArtifactId( "prototype" );
+ artifact.setVersion( "1.5.1.1" );
+ artifact.setType( Types.JAVASCRIPT_TYPE );
+ artifact.setScope( DefaultArtifact.SCOPE_RUNTIME );
+ artifact.setFile( new File( "src/test/resources/prototype-1.5.1.1.jar" ) );
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getArtifacts()
+ */
+ public Set getArtifacts()
+ {
+ Set artifacts = new HashSet();
+ artifacts.add( artifact );
+ return artifacts;
+ }
+}