You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ah...@apache.org on 2005/12/05 01:53:30 UTC
svn commit: r353948 - in
/maven/maven-1/core/trunk/src/java/org/apache/maven: jelly/JellyUtils.java
plugin/PluginManager.java
Author: aheritier
Date: Sun Dec 4 16:53:22 2005
New Revision: 353948
URL: http://svn.apache.org/viewcvs?rev=353948&view=rev
Log:
Fix systemId used to parse jelly scripts. It didn't create a problem but added a lot of exceptions for nothing.
Modified:
maven/maven-1/core/trunk/src/java/org/apache/maven/jelly/JellyUtils.java
maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/PluginManager.java
Modified: maven/maven-1/core/trunk/src/java/org/apache/maven/jelly/JellyUtils.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/core/trunk/src/java/org/apache/maven/jelly/JellyUtils.java?rev=353948&r1=353947&r2=353948&view=diff
==============================================================================
--- maven/maven-1/core/trunk/src/java/org/apache/maven/jelly/JellyUtils.java (original)
+++ maven/maven-1/core/trunk/src/java/org/apache/maven/jelly/JellyUtils.java Sun Dec 4 16:53:22 2005
@@ -17,24 +17,26 @@
* ====================================================================
*/
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.Iterator;
+
+import javax.xml.parsers.SAXParserFactory;
+
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.expression.CompositeExpression;
import org.apache.commons.jelly.expression.Expression;
import org.apache.commons.jelly.parser.XMLParser;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
-import javax.xml.parsers.SAXParserFactory;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.util.Iterator;
-
/**
* Utilities for Jelly.
*
@@ -46,6 +48,11 @@
*/
public class JellyUtils
{
+ /**
+ * Logger
+ */
+ private static final Log log = LogFactory.getLog( JellyUtils.class );
+
/** Maven Expression Factory. */
private static MavenExpressionFactory mavenExpressionFactory = new MavenExpressionFactory();
@@ -59,10 +66,7 @@
* @throws Exception If an error occurs while locating, compiling or
* executing the script.
*/
- public static void runScript( InputStream scriptInputStream,
- URL rootUrl,
- JellyContext context,
- XMLOutput output )
+ public static void runScript( InputStream scriptInputStream, URL rootUrl, JellyContext context, XMLOutput output )
throws Exception
{
runScript( scriptInputStream, null, rootUrl, context, output );
@@ -79,11 +83,8 @@
* @throws Exception If an error occurs while locating, compiling or
* executing the script.
*/
- public static void runScript( InputStream scriptInputStream,
- String systemId,
- URL rootUrl,
- JellyContext context,
- XMLOutput output )
+ public static void runScript( InputStream scriptInputStream, String systemId, URL rootUrl, JellyContext context,
+ XMLOutput output )
throws Exception
{
URL oldRoot = context.getRootURL();
@@ -112,10 +113,7 @@
* @throws Exception If an error occurs while locating, compiling or
* executing the script.
*/
- public static void runScript( File scriptFile,
- URL rootUrl,
- JellyContext context,
- XMLOutput output )
+ public static void runScript( File scriptFile, URL rootUrl, JellyContext context, XMLOutput output )
throws Exception
{
if ( !scriptFile.canRead() || scriptFile.length() < 1 )
@@ -123,11 +121,7 @@
return;
}
- runScript( new FileInputStream( scriptFile ),
- scriptFile.getAbsolutePath(),
- rootUrl,
- context,
- output );
+ runScript( new FileInputStream( scriptFile ), scriptFile.toURL().toString(), rootUrl, context, output );
}
/**
@@ -139,11 +133,10 @@
* script.
* @return The compiled script.
*/
- public static Script compileScript( File scriptFile,
- JellyContext context )
+ public static Script compileScript( File scriptFile, JellyContext context )
throws Exception
{
- return compileScript( new FileInputStream( scriptFile ), scriptFile.getAbsolutePath(), context );
+ return compileScript( new FileInputStream( scriptFile ), scriptFile.toURL().toString(), context );
}
/**
@@ -155,8 +148,7 @@
* script.
* @return The compiled script.
*/
- public static Script compileScript( InputStream scriptInputStream,
- JellyContext context )
+ public static Script compileScript( InputStream scriptInputStream, JellyContext context )
throws Exception
{
return compileScript( scriptInputStream, null, context, null );
@@ -172,9 +164,7 @@
* script.
* @return The compiled script.
*/
- public static Script compileScript( InputStream scriptInputStream,
- String systemId,
- JellyContext context )
+ public static Script compileScript( InputStream scriptInputStream, String systemId, JellyContext context )
throws Exception
{
return compileScript( scriptInputStream, systemId, context, null );
@@ -192,10 +182,8 @@
* @return The compiled script.
* @todo throw something else
*/
- public static Script compileScript( InputStream scriptInputStream,
- String systemId,
- JellyContext context,
- String encoding )
+ public static Script compileScript( InputStream scriptInputStream, String systemId, JellyContext context,
+ String encoding )
throws Exception
{
// FIXME: This should all be done by Jelly.
@@ -211,14 +199,17 @@
InputSource source = null;
if ( encoding != null )
{
- source = new InputSource( new InputStreamReader( scriptInputStream, encoding ) ) ;
+ source = new InputSource( new InputStreamReader( scriptInputStream, encoding ) );
}
else
{
source = new InputSource( scriptInputStream );
}
- source.setSystemId( systemId );
+ if ( systemId != null )
+ source.setSystemId( systemId );
+ if ( log.isDebugEnabled() )
+ log.debug( "the system identifier to help resolve relative URLs : " + systemId );
script = parser.parse( source );
script = script.compile();
@@ -234,8 +225,7 @@
*
* @return The recursively evaluated Jelly expression.
*/
- public static Expression decomposeExpression( String text,
- JellyContext context )
+ public static Expression decomposeExpression( String text, JellyContext context )
{
Expression expression = null;
@@ -266,9 +256,9 @@
public static void compareContexts( MavenJellyContext ctx1, MavenJellyContext ctx2 )
{
System.out.println( "======== compare contexts ========" );
- for ( Iterator i = ctx1.getVariableNames(); i.hasNext();)
+ for ( Iterator i = ctx1.getVariableNames(); i.hasNext(); )
{
- String name = ( String ) i.next();
+ String name = (String) i.next();
if ( ctx2.getVariable( name ) == null )
{
System.out.println( name + " not in ctx2" );
@@ -278,7 +268,7 @@
if ( !ctx2.getVariable( name ).equals( ctx1.getVariable( name ) ) )
{
System.out.println( name + " doesn't match: '" + ctx1.getVariable( name ) + "' vs '"
- + ctx2.getVariable( name ) + "'" );
+ + ctx2.getVariable( name ) + "'" );
}
}
}
@@ -295,8 +285,8 @@
{
if ( sourceContext != null )
{
- if ( !"false".equals( sourceContext.getVariable( "maven.property.inheritance" ) ) &&
- ( !"false".equals( destContext.getVariable( "maven.property.inheritance" ) ) ) )
+ if ( !"false".equals( sourceContext.getVariable( "maven.property.inheritance" ) )
+ && ( !"false".equals( destContext.getVariable( "maven.property.inheritance" ) ) ) )
{
populateVariables( destContext, sourceContext.isInherit() ? sourceContext.getParent() : null );
}
@@ -305,4 +295,3 @@
destContext.setVariable( "context", destContext );
}
}
-
Modified: maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/PluginManager.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/PluginManager.java?rev=353948&r1=353947&r2=353948&view=diff
==============================================================================
--- maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/PluginManager.java (original)
+++ maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/PluginManager.java Sun Dec 4 16:53:22 2005
@@ -378,6 +378,7 @@
/**
* @param project
* @param jelly
+ * @param systemId the system identifier to help resolve relative URLs
* @return
* @throws Exception
* @deprecated get rid of this - it duplicates functionality in the housing
@@ -385,14 +386,14 @@
* @todo don't throw Exception
* @todo get rid of this - it duplicates functionality in the housing
*/
- private JellyScriptHousing createJellyScriptHousing( Project project, InputStream jelly ) throws Exception
+ private JellyScriptHousing createJellyScriptHousing( Project project, String systemId, InputStream jelly ) throws Exception
{
JellyScriptHousing jellyScriptHousing = new JellyScriptHousing();
try
{
// Now lets compile the script once so we can use it repeatedly.
- Script script = JellyUtils.compileScript( jelly, project.getContext() );
+ Script script = JellyUtils.compileScript( jelly, systemId, project.getContext() );
jellyScriptHousing.setProject( project );
jellyScriptHousing.setScript( script );
@@ -586,7 +587,7 @@
// driver.jelly
InputStream driver = getClass().getResourceAsStream( "/driver.jelly" );
- JellyScriptHousing driverHousing = createJellyScriptHousing( project, driver );
+ JellyScriptHousing driverHousing = createJellyScriptHousing( project, getClass().getResource("/driver.jelly").toString(), driver );
// TODO: stop reading all scripts 2 times
driver.close();
driver = getClass().getResourceAsStream( "/driver.jelly" );
@@ -1132,6 +1133,8 @@
try
{
+ if ( log.isDebugEnabled() )
+ log.debug( "Jelly script to parse : "+jellyScriptHousing.getSource().toURL());
Script script = JellyUtils.compileScript( jellyScriptHousing.getSource(), context );
context.setRootURL( oldRoot );