avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/extension/src/java/org/apache/avalon/excalibur/extension Specification.java
Date Mon, 01 Apr 2002 12:48:50 GMT
donaldp     02/04/01 04:48:50

  Modified:    extension/src/test/org/apache/avalon/excalibur/extension/test
                        SpecificationTestCase.java
               extension/src/java/org/apache/avalon/excalibur/extension
                        Specification.java
  Added:       extension/src/test/org/apache/avalon/excalibur/extension/test
                        specification-8.mf specification-9.mf
  Log:
  Merge in specifications when multiple sections have the same spec
  
  Revision  Changes    Path
  1.2       +49 -1     jakarta-avalon-excalibur/extension/src/test/org/apache/avalon/excalibur/extension/test/SpecificationTestCase.java
  
  Index: SpecificationTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/extension/src/test/org/apache/avalon/excalibur/extension/test/SpecificationTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SpecificationTestCase.java	1 Apr 2002 11:47:43 -0000	1.1
  +++ SpecificationTestCase.java	1 Apr 2002 12:48:50 -0000	1.2
  @@ -16,7 +16,7 @@
    * TestCases for Specification.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.1 $ $Date: 2002/04/01 11:47:43 $
  + * @version $Revision: 1.2 $ $Date: 2002/04/01 12:48:50 $
    */
   public class SpecificationTestCase
       extends TestCase
  @@ -28,6 +28,13 @@
       private static final String MF1_IVENDOR = "Peter Donald";
       private static final String MF1_IVERSION = "1.0.2Alpha";
   
  +    private static final String MF2_STITLE = "org.apache.phoenix";
  +    private static final String MF2_SVERSION = "1.0.2";
  +    private static final String MF2_SVENDOR = "Apache";
  +    private static final String MF2_ITITLE = "Apache Phoenix";
  +    private static final String MF2_IVENDOR = "Apache";
  +    private static final String MF2_IVERSION = "1.0.2";
  +
       public SpecificationTestCase( String name )
       {
           super( name );
  @@ -92,6 +99,47 @@
           assertEquals( "ImpTitle", MF1_ITITLE, specifications[ 0 ].getImplementationTitle()
);
           assertEquals( "ImpVersion", MF1_IVERSION,
                         specifications[ 0 ].getImplementationVersion().toString() );
  +    }
  +
  +    public void testMultiSection()
  +        throws Exception
  +    {
  +        final Specification[] specifications = getPackageSpecifcations( "specification-8.mf"
);
  +
  +        assertEquals( "Count", 1, specifications.length );
  +        assertEquals( "Name", MF1_STITLE, specifications[ 0 ].getSpecificationTitle() );
  +        assertEquals( "SpecVendor", MF1_SVENDOR, specifications[ 0 ].getSpecificationVendor()
);
  +        assertEquals( "SpecVersion", MF1_SVERSION,
  +                      specifications[ 0 ].getSpecificationVersion().toString() );
  +        assertEquals( "ImpVendor", MF1_IVENDOR, specifications[ 0 ].getImplementationVendor()
);
  +        assertEquals( "ImpTitle", MF1_ITITLE, specifications[ 0 ].getImplementationTitle()
);
  +        assertEquals( "ImpVersion", MF1_IVERSION,
  +                      specifications[ 0 ].getImplementationVersion().toString() );
  +    }
  +
  +    public void testMultiSectionMultiSpec()
  +        throws Exception
  +    {
  +        final Specification[] specifications = getPackageSpecifcations( "specification-9.mf"
);
  +
  +        assertEquals( "Count", 2, specifications.length );
  +        assertEquals( "Name", MF1_STITLE, specifications[ 0 ].getSpecificationTitle() );
  +        assertEquals( "SpecVendor", MF1_SVENDOR, specifications[ 0 ].getSpecificationVendor()
);
  +        assertEquals( "SpecVersion", MF1_SVERSION,
  +                      specifications[ 0 ].getSpecificationVersion().toString() );
  +        assertEquals( "ImpVendor", MF1_IVENDOR, specifications[ 0 ].getImplementationVendor()
);
  +        assertEquals( "ImpTitle", MF1_ITITLE, specifications[ 0 ].getImplementationTitle()
);
  +        assertEquals( "ImpVersion", MF1_IVERSION,
  +                      specifications[ 0 ].getImplementationVersion().toString() );
  +
  +        assertEquals( "Name", MF2_STITLE, specifications[ 1 ].getSpecificationTitle() );
  +        assertEquals( "SpecVendor", MF2_SVENDOR, specifications[ 1 ].getSpecificationVendor()
);
  +        assertEquals( "SpecVersion", MF2_SVERSION,
  +                      specifications[ 1 ].getSpecificationVersion().toString() );
  +        assertEquals( "ImpVendor", MF2_IVENDOR, specifications[ 1 ].getImplementationVendor()
);
  +        assertEquals( "ImpTitle", MF2_ITITLE, specifications[ 1 ].getImplementationTitle()
);
  +        assertEquals( "ImpVersion", MF2_IVERSION,
  +                      specifications[ 1 ].getImplementationVersion().toString() );
       }
   
       public void testMissingSPecVersion()
  
  
  
  1.1                  jakarta-avalon-excalibur/extension/src/test/org/apache/avalon/excalibur/extension/test/specification-8.mf
  
  Index: specification-8.mf
  ===================================================================
  Manifest-Version: 1.0
  
  Name: org/realityforge/dve
  Specification-Title: org.realityforge.dve
  Specification-Version: 1.0.2
  Specification-Vendor: Peter Donald
  Implementation-Title: DVE vi OS3P
  Implementation-Vendor: Peter Donald
  Implementation-Version: 1.0.2Alpha
  
  Name: org/realityforge/dve/gui
  Specification-Title: org.realityforge.dve
  Specification-Version: 1.0.2
  Specification-Vendor: Peter Donald
  Implementation-Title: DVE vi OS3P
  Implementation-Vendor: Peter Donald
  Implementation-Version: 1.0.2Alpha
  
  Name: org/realityforge/dve/3d
  Specification-Title: org.realityforge.dve
  Specification-Version: 1.0.2
  Specification-Vendor: Peter Donald
  Implementation-Title: DVE vi OS3P
  Implementation-Vendor: Peter Donald
  Implementation-Version: 1.0.2Alpha
  
  
  
  1.1                  jakarta-avalon-excalibur/extension/src/test/org/apache/avalon/excalibur/extension/test/specification-9.mf
  
  Index: specification-9.mf
  ===================================================================
  Manifest-Version: 1.0
  
  Name: org/realityforge/dve
  Specification-Title: org.realityforge.dve
  Specification-Version: 1.0.2
  Specification-Vendor: Peter Donald
  Implementation-Title: DVE vi OS3P
  Implementation-Vendor: Peter Donald
  Implementation-Version: 1.0.2Alpha
  
  Name: org/realityforge/dve/gui
  Specification-Title: org.realityforge.dve
  Specification-Version: 1.0.2
  Specification-Vendor: Peter Donald
  Implementation-Title: DVE vi OS3P
  Implementation-Vendor: Peter Donald
  Implementation-Version: 1.0.2Alpha
  
  Name: org/realityforge/dve/3d
  Specification-Title: org.realityforge.dve
  Specification-Version: 1.0.2
  Specification-Vendor: Peter Donald
  Implementation-Title: DVE vi OS3P
  Implementation-Vendor: Peter Donald
  Implementation-Version: 1.0.2Alpha
  
  Name: org/apache/phoenix
  Specification-Title: org.apache.phoenix
  Specification-Version: 1.0.2
  Specification-Vendor: Apache
  Implementation-Title: Apache Phoenix
  Implementation-Vendor: Apache
  Implementation-Version: 1.0.2
  
  
  
  1.2       +164 -7    jakarta-avalon-excalibur/extension/src/java/org/apache/avalon/excalibur/extension/Specification.java
  
  Index: Specification.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/extension/src/java/org/apache/avalon/excalibur/extension/Specification.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Specification.java	1 Apr 2002 10:32:40 -0000	1.1
  +++ Specification.java	1 Apr 2002 12:48:50 -0000	1.2
  @@ -9,6 +9,7 @@
   
   import java.text.ParseException;
   import java.util.ArrayList;
  +import java.util.Arrays;
   import java.util.Iterator;
   import java.util.Map;
   import java.util.jar.Attributes;
  @@ -25,7 +26,7 @@
    * <code>guide/extensions/versioning.html</code>.</p>
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.1 $ $Date: 2002/04/01 10:32:40 $
  + * @version $Revision: 1.2 $ $Date: 2002/04/01 12:48:50 $
    */
   public final class Specification
   {
  @@ -137,6 +138,11 @@
       private String m_implementationVersion;
   
       /**
  +     * The sections of jar that the specification applies to.
  +     */
  +    private String[] m_sections;
  +
  +    /**
        * Return an array of <code>Package Specification</code> objects.
        * If there are no such optional packages, a zero-length array is returned.
        *
  @@ -159,14 +165,15 @@
           {
               final String key = (String)keys.next();
               final Attributes attributes = (Attributes)entries.get( key );
  -            final Specification specification = getSpecification( attributes );
  +            final Specification specification = getSpecification( key, attributes );
               if( null != specification )
               {
                   results.add( specification );
               }
           }
   
  -        return (Specification[])results.toArray( new Specification[ 0 ] );
  +        final ArrayList trimmedResults = removeDuplicates( results );
  +        return (Specification[])trimmedResults.toArray( new Specification[ 0 ] );
       }
   
       /**
  @@ -188,6 +195,32 @@
                             final String implementationVersion,
                             final String implementationVendor )
       {
  +        this( specificationTitle, specificationVersion, specificationVendor,
  +              implementationTitle, implementationVersion, implementationVendor,
  +              null );
  +    }
  +
  +    /**
  +     * The constructor to create Package Specification object.
  +     * Note that every component is allowed to be specified
  +     * but only the specificationTitle is mandatory.
  +     *
  +     * @param specificationTitle the name of specification.
  +     * @param specificationVersion the specification Version.
  +     * @param specificationVendor the specification Vendor.
  +     * @param implementationTitle the title of implementation.
  +     * @param implementationVersion the implementation Version.
  +     * @param implementationVendor the implementation Vendor.
  +     * @param sections the sections/packages that Specification applies to.
  +     */
  +    public Specification( final String specificationTitle,
  +                          final String specificationVersion,
  +                          final String specificationVendor,
  +                          final String implementationTitle,
  +                          final String implementationVersion,
  +                          final String implementationVendor,
  +                          final String[] sections )
  +    {
           m_specificationTitle = specificationTitle;
           m_specificationVendor = specificationVendor;
   
  @@ -213,6 +246,14 @@
           {
               throw new NullPointerException( "specificationTitle" );
           }
  +
  +        String[] copy = null;
  +        if( null != sections )
  +        {
  +            copy = new String[ sections.length ];
  +            System.arraycopy( sections, 0, copy, 0, sections.length );
  +        }
  +        m_sections = copy;
       }
   
       /**
  @@ -276,6 +317,27 @@
       }
   
       /**
  +     * Return an array containing sections to which specification applies
  +     * or null if relevent to no sections.
  +     *
  +     * @return an array containing sections to which specification applies
  +     *         or null if relevent to no sections.
  +     */
  +    public String[] getSections()
  +    {
  +        if( null == m_sections )
  +        {
  +            return null;
  +        }
  +        else
  +        {
  +            final String[] sections = new String[ m_sections.length ];
  +            System.arraycopy( m_sections, 0, sections, 0, m_sections.length );
  +            return sections;
  +        }
  +    }
  +
  +    /**
        * Return a Compatibility enum indicating the relationship of this
        * <code>Package Specification</code> with the specified <code>Extension</code>.
        *
  @@ -412,6 +474,100 @@
       }
   
       /**
  +     * Combine all specifications objects that are identical except
  +     * for the sections.
  +     *
  +     * <p>Note this is very inefficent and should probably be fixed
  +     * in the future.</p>
  +     *
  +     * @param list the array of results to trim
  +     * @return an array list with all duplicates removed
  +     */
  +    private static ArrayList removeDuplicates( final ArrayList list )
  +    {
  +        final ArrayList results = new ArrayList();
  +        final ArrayList sections = new ArrayList();
  +        while( list.size() > 0 )
  +        {
  +            final Specification specification = (Specification)list.remove( 0 );
  +            final Iterator iterator = list.iterator();
  +            while( iterator.hasNext() )
  +            {
  +                final Specification other = (Specification)iterator.next();
  +                if( isEqual( specification, other ) )
  +                {
  +                    final String[] otherSections = other.getSections();
  +                    if( null != sections )
  +                    {
  +                        sections.addAll( Arrays.asList( otherSections ) );
  +                    }
  +                    iterator.remove();
  +                }
  +            }
  +
  +            final Specification merged =
  +                mergeInSections( specification, sections );
  +            results.add( merged );
  +            //Reset list of sections
  +            sections.clear();
  +        }
  +
  +        return results;
  +    }
  +
  +    /**
  +     * Test if two specifications are equal except for their sections.
  +     *
  +     * @param specification one specificaiton
  +     * @param other the ohter specification
  +     * @return true if two specifications are equal except for their
  +     *         sections, else false
  +     */
  +    private static boolean isEqual( final Specification specification,
  +                                    final Specification other )
  +    {
  +        return
  +            specification.getSpecificationTitle().equals( other.getSpecificationTitle()
) &&
  +            specification.getSpecificationVersion().isEqual( other.getSpecificationVersion()
) &&
  +            specification.getSpecificationVendor().equals( other.getSpecificationVendor()
) &&
  +            specification.getImplementationTitle().equals( other.getImplementationTitle()
) &&
  +            specification.getImplementationVersion().equals( other.getImplementationVersion()
) &&
  +            specification.getImplementationVendor().equals( other.getImplementationVendor()
);
  +    }
  +
  +    /**
  +     * Merge the specified sections into specified section and return result.
  +     * If no sections to be added then just return original specification.
  +     *
  +     * @param specification the specification
  +     * @param sectionsToAdd the list of sections to merge
  +     * @return the merged specification
  +     */
  +    private static Specification mergeInSections( final Specification specification,
  +                                                  final ArrayList sectionsToAdd )
  +    {
  +        if( 0 == sectionsToAdd.size() )
  +        {
  +            return specification;
  +        }
  +        else
  +        {
  +            sectionsToAdd.addAll( Arrays.asList( specification.getSections() ) );
  +
  +            final String[] sections =
  +                (String[])sectionsToAdd.toArray( new String[ sectionsToAdd.size() ] );
  +
  +            return new Specification( specification.getSpecificationTitle(),
  +                                      specification.getSpecificationVersion().toString(),
  +                                      specification.getSpecificationVendor(),
  +                                      specification.getImplementationTitle(),
  +                                      specification.getImplementationVersion(),
  +                                      specification.getImplementationVendor(),
  +                                      sections );
  +        }
  +    }
  +
  +    /**
        * Trim the supplied string if the string is non-null
        *
        * @param value the string to trim or null
  @@ -435,8 +591,9 @@
        * @param attributes Attributes to searched
        * @return the new Specification object, or null
        */
  -    private static Specification getSpecification( final Attributes attributes )
  -    throws ParseException
  +    private static Specification getSpecification( final String section,
  +                                                   final Attributes attributes )
  +        throws ParseException
       {
           //WARNING: We trim the values of all the attributes because
           //Some extension declarations are badly defined (ie have spaces
  @@ -447,7 +604,6 @@
               return null;
           }
   
  -
           final String specVendor = getTrimmedString( attributes.getValue( SPECIFICATION_VENDOR
) );
           if( null == specVendor )
           {
  @@ -479,6 +635,7 @@
           }
   
           return new Specification( name, specVersion, specVendor,
  -                                  impTitle, impVersion, impVendor );
  +                                  impTitle, impVersion, impVendor,
  +                                  new String[]{section} );
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message