You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by do...@apache.org on 2002/04/04 13:00:44 UTC

cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions ExtraAttribute.java Resources.properties JarLibManifestTask.java

donaldp     02/04/04 03:00:44

  Modified:    proposal/myrmidon/src/samples sample.ant
               proposal/myrmidon/src/java/org/apache/antlib/extensions
                        Resources.properties JarLibManifestTask.java
  Added:       proposal/myrmidon/src/java/org/apache/antlib/extensions
                        ExtraAttribute.java
  Log:
  Added support for declaring extra attributes for main section of manifest
  
  Revision  Changes    Path
  1.6       +3 -2      jakarta-ant/proposal/myrmidon/src/samples/sample.ant
  
  Index: sample.ant
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/samples/sample.ant,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- sample.ant	4 Apr 2002 10:50:40 -0000	1.5
  +++ sample.ant	4 Apr 2002 11:00:44 -0000	1.6
  @@ -341,8 +341,9 @@
               destfile="../../generated-manifest.txt"
               extension-name="org.realityforge.dve"
               specification-version="1.0"
  -            specification-vendor="Peter Donald"
  -            >
  +            specification-vendor="Peter Donald" >
  +            <attribute name="Main-class"
  +                       value="org.realityforg.dve.WorldGen"/>
               <depends dir="../../">
                   <include name="src/ant1compat/jar/*.jar"/>
               </depends>
  
  
  
  1.3       +4 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/Resources.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Resources.properties	4 Apr 2002 10:50:41 -0000	1.2
  +++ Resources.properties	4 Apr 2002 11:00:44 -0000	1.3
  @@ -4,4 +4,7 @@
   
   manifest.missing-file.error=Destfile attribute not specified.
   manifest.bad-file.error="{0}" is not a file.
  -manifest.file.notice=Generating manifest {0}.
  \ No newline at end of file
  +manifest.file.notice=Generating manifest {0}.
  +
  +param.noname.error=Missing name from parameter.
  +param.novalue.error=Missing value from parameter "{0}".
  
  
  
  1.2       +36 -0     jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/JarLibManifestTask.java
  
  Index: JarLibManifestTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/JarLibManifestTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JarLibManifestTask.java	4 Apr 2002 10:50:41 -0000	1.1
  +++ JarLibManifestTask.java	4 Apr 2002 11:00:44 -0000	1.2
  @@ -114,6 +114,12 @@
       private String m_implementationURL;
   
       /**
  +     * Extra attributes the user specifies for main section
  +     * in manifest.
  +     */
  +    private final ArrayList m_extraAttributes = new ArrayList();
  +
  +    /**
        * Set the name of extension in generated manifest.
        *
        * @param extensionName the name of extension in generated manifest
  @@ -213,6 +219,16 @@
           m_optionals.addElement( fileSet );
       }
   
  +    /**
  +     * Adds an attribute that is to be put in main section of manifest.
  +     *
  +     * @param attribute an attribute that is to be put in main section of manifest.
  +     */
  +    public void addAttribute( final ExtraAttribute attribute )
  +    {
  +        m_extraAttributes.add( attribute );
  +    }
  +
       public void execute()
           throws TaskException
       {
  @@ -224,6 +240,8 @@
           attributes.put( Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION );
           attributes.putValue( "Created-By", Constants.BUILD_DESCRIPTION );
   
  +        appendExtraAttributes( attributes );
  +
           appendExtensionData( attributes );
   
           final String extensionKey = Extension.EXTENSION_LIST.toString();
  @@ -266,6 +284,24 @@
               final String message =
                   REZ.getString( "manifest.bad-file.error", m_destfile );
               throw new TaskException( message );
  +        }
  +    }
  +
  +    /**
  +     * Add any extra attributes to the manifest.
  +     *
  +     * @param attributes the manifest section to write
  +     *        attributes to
  +     */
  +    private void appendExtraAttributes( final Attributes attributes )
  +    {
  +        final Iterator iterator = m_extraAttributes.iterator();
  +        while( iterator.hasNext() )
  +        {
  +            final ExtraAttribute attribute =
  +                (ExtraAttribute)iterator.next();
  +            attributes.putValue( attribute.getName(),
  +                                 attribute.getValue() );
           }
       }
   
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/extensions/ExtraAttribute.java
  
  Index: ExtraAttribute.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.antlib.extensions;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.myrmidon.api.TaskException;
  
  /**
   * Simple holder for extra attributes in main section of manifest.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/04 11:00:44 $
   * @todo Refactor this and all the other parameter, sysproperty,
   *   property etc into a single class in framework
   */
  public class ExtraAttribute
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( ExtraAttribute.class );
  
      private String m_name;
      private String m_value;
  
      /**
       * Set the name of the parameter.
       *
       * @param name the name of parameter
       */
      public void setName( final String name )
      {
          m_name = name;
      }
  
      /**
       * Set the value of the parameter.
       *
       * @param value the parameter value
       */
      public void setValue( final String value )
      {
          m_value = value;
      }
  
      /**
       * Retrieve name of parameter.
       *
       * @return the name of parameter.
       */
      String getName()
      {
          return m_name;
      }
  
      /**
       * Retrieve the value of parameter.
       *
       * @return the value of parameter.
       */
      String getValue()
      {
          return m_value;
      }
  
      /**
       * Make sure that neither the name or the value
       * is null.
       */
      public void validate()
          throws TaskException
      {
          if( null == m_name )
          {
              final String message = REZ.getString( "param.noname.error" );
              throw new TaskException( message );
          }
          else if( null == m_value )
          {
              final String message =
                  REZ.getString( "param.novalue.error", m_name );
              throw new TaskException( message );
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>