maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: maven-components/maven-core/src/test/java/org/apache/maven/project/interpolation RegexBasedProjectInterpolatorTest.java
Date Wed, 23 Feb 2005 03:56:25 GMT
brett       2005/02/22 19:56:25

  Modified:    maven-core/src/main/java/org/apache/maven/project/interpolation
                        RegexBasedModelInterpolator.java
               maven-core/src/main/resources/org/apache/maven/project
                        pom-4.0.0.xml
               maven-core/src/test/java/org/apache/maven/project/interpolation
                        RegexBasedProjectInterpolatorTest.java
  Log:
  use ${..} style interpolation
  
  Revision  Changes    Path
  1.2       +16 -13    maven-components/maven-core/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java
  
  Index: RegexBasedModelInterpolator.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RegexBasedModelInterpolator.java	23 Feb 2005 03:26:59 -0000	1.1
  +++ RegexBasedModelInterpolator.java	23 Feb 2005 03:56:24 -0000	1.2
  @@ -23,6 +23,7 @@
   import org.apache.maven.util.introspection.ReflectionValueExtractor;
   import org.codehaus.plexus.logging.AbstractLogEnabled;
   import org.codehaus.plexus.logging.Logger;
  +import org.codehaus.plexus.util.StringUtils;
   
   import java.io.StringReader;
   import java.io.StringWriter;
  @@ -37,12 +38,13 @@
       implements ModelInterpolator
   {
   
  -    private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "#([A-Za-z.]+)"
);
  +    private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "\\$\\{([^}]+)\\}"
);
   
       /**
        * Added: Feb 3, 2005 by jdcasey
        */
  -    public Model interpolate( Model model ) throws ModelInterpolationException
  +    public Model interpolate( Model model )
  +        throws ModelInterpolationException
       {
           StringWriter sWriter = new StringWriter();
   
  @@ -51,10 +53,9 @@
           {
               writer.write( sWriter, model );
           }
  -        catch( Exception e )
  +        catch ( Exception e )
           {
  -            throw new ModelInterpolationException(
  -                "Cannot serialize project model for interpolation.", e );
  +            throw new ModelInterpolationException( "Cannot serialize project model for
interpolation.", e );
           }
   
           String serializedModel = sWriter.toString();
  @@ -67,7 +68,7 @@
           {
               model = modelReader.read( sReader );
           }
  -        catch( Exception e )
  +        catch ( Exception e )
           {
               throw new ModelInterpolationException(
                   "Cannot read project model from interpolating filter of serialized version.",
e );
  @@ -83,7 +84,7 @@
       {
           String result = src;
           Matcher matcher = EXPRESSION_PATTERN.matcher( result );
  -        while( matcher.find() )
  +        while ( matcher.find() )
           {
               String wholeExpr = matcher.group( 0 );
               String realExpr = matcher.group( 1 );
  @@ -93,19 +94,21 @@
               {
                   value = String.valueOf( ReflectionValueExtractor.evaluate( realExpr, model
) );
               }
  -            catch( Exception e )
  +            catch ( Exception e )
               {
                   Logger logger = getLogger();
  -                if( logger != null )
  +                if ( logger != null )
                   {
  -                    logger.debug( "POM interpolation cannot proceed with expression: "
+ wholeExpr
  -                        + ". Skipping...", e );
  +                    logger.debug( "POM interpolation cannot proceed with expression: "
+ wholeExpr + ". Skipping...", e );
                   }
               }
   
  -            if( value != null )
  +            if ( value != null )
               {
  -                result = result.replaceAll( wholeExpr, value );
  +                result = StringUtils.replace( result, wholeExpr, value );
  +                // could use:
  +                // result = matcher.replaceFirst( value );
  +                // but this could result in multiple lookups of value, and replaceAll is
not correct behaviour 
                   matcher.reset( result );
               }
           }
  
  
  
  1.5       +1 -1      maven-components/maven-core/src/main/resources/org/apache/maven/project/pom-4.0.0.xml
  
  Index: pom-4.0.0.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/resources/org/apache/maven/project/pom-4.0.0.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- pom-4.0.0.xml	23 Feb 2005 03:27:00 -0000	1.4
  +++ pom-4.0.0.xml	23 Feb 2005 03:56:25 -0000	1.5
  @@ -32,7 +32,7 @@
       <!-- This all may just fold into plugin parameters -->
       <directory>target</directory>
       <output>target/classes</output>
  -    <finalName>#artifactId-#version</finalName>
  +    <finalName>${artifactId}-${version}</finalName>
       <testOutput>target/test-classes</testOutput>
       <sourceDirectory>src/main/java</sourceDirectory>
       <unitTestSourceDirectory>src/test/java</unitTestSourceDirectory>
  
  
  
  1.3       +20 -3     maven-components/maven-core/src/test/java/org/apache/maven/project/interpolation/RegexBasedProjectInterpolatorTest.java
  
  Index: RegexBasedProjectInterpolatorTest.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/test/java/org/apache/maven/project/interpolation/RegexBasedProjectInterpolatorTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RegexBasedProjectInterpolatorTest.java	23 Feb 2005 03:27:00 -0000	1.2
  +++ RegexBasedProjectInterpolatorTest.java	23 Feb 2005 03:56:25 -0000	1.3
  @@ -37,7 +37,7 @@
           model.setVersion( "3.8.1" );
   
           Dependency dep = new Dependency();
  -        dep.setVersion( "#version" );
  +        dep.setVersion( "${version}" );
   
           model.addDependency( dep );
   
  @@ -53,13 +53,30 @@
           model.setVersion( "3.8.1" );
   
           Dependency dep = new Dependency();
  -        dep.setVersion( "#something" );
  +        dep.setVersion( "${something}" );
   
           model.addDependency( dep );
   
           Model out = new RegexBasedModelInterpolator().interpolate( model );
   
  -        assertEquals( "#something", ((Dependency) out.getDependencies().get( 0 )).getVersion()
);
  +        assertEquals( "${something}", ((Dependency) out.getDependencies().get( 0 )).getVersion()
);
  +    }
  +
  +    public void testTwoReferences()
  +        throws ModelInterpolationException
  +    {
  +        Model model = new Model();
  +        model.setVersion( "3.8.1" );
  +        model.setArtifactId( "foo" );
  +
  +        Dependency dep = new Dependency();
  +        dep.setVersion( "${artifactId}-${version}" );
  +
  +        model.addDependency( dep );
  +
  +        Model out = new RegexBasedModelInterpolator().interpolate( model );
  +
  +        assertEquals( "foo-3.8.1", ((Dependency) out.getDependencies().get( 0 )).getVersion()
);
       }
   
   }
  \ No newline at end of file
  
  
  

Mime
View raw message