ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject AW: AW: AW: AW: Prepend licence information to every source file
Date Fri, 17 Sep 2004 14:54:40 GMT
yep

<project default="addlicense">
    <target name="addlicense">
        <taskdef resource="net/sf/antcontrib/antcontrib.properties" />
        <loadfile srcfile="license-java.txt" property="license"/>
        <propertyregex property="license.1stLine"
                       input="${license}"
                       regexp="(.*)${line.separator}.*"
                       select="\1"
                       casesensitive="false" />
        <replaceregexp flags="s" match="(.*)" replace="${license}\1">
            <fileset dir="src" includes="**/*.java">
                <not>
                    <contains text="${license.1stLine}"/>
                </not>
            </fileset>
        </replaceregexp>
    </target>
</project>


Jan


> -----Ursprüngliche Nachricht-----
> Von: Jan.Materne@rzf.fin-nrw.de [mailto:Jan.Materne@rzf.fin-nrw.de]
> Gesendet am: Freitag, 17. September 2004 16:41
> An: user@ant.apache.org
> Betreff: AW: AW: AW: AW: Prepend licence information to every source
> file
> 
> Should be possible to get the first line of the file via regexp.
> Something like
>   (.*)${line.separator}.*  --> $1
> or so ...
> 
> Jan
> 
> > -----Ursprüngliche Nachricht-----
> > Von: Peter Reilly [mailto:peterreilly@apache.org]
> > Gesendet am: Freitag, 17. September 2004 16:24
> > An: Ant Users List
> > Betreff: Re: AW: AW: AW: Prepend licence information to every source
> > file
> > 
> > yes that works too (slaps head!).
> > 
> >   <target name="addlicense">
> >     <loadfile srcfile="license-java.txt" property="license"/>
> >     <replaceregexp flags="s" match="(.*)" replace="${license}\1">
> >       <fileset dir="src" includes="**/*.java">
> >         <not>
> >           <contains text="you may not use this file except in 
> > compliance 
> > with the License"/>
> >         </not>
> >       </fileset>
> >     </replaceregexp>
> >   </target>
> > 
> > 
> > Note that the <contains> file selector only works
> > on one line at a time, so it cannot use <contains 
> text="${license}"/>
> > 
> > Also, be careful with the contents of the license file,
> > special characters like \ will cause problems (like \0) with
> > the regexp replace string.
> > 
> > Peter
> > 
> > Jan.Materne@rzf.fin-nrw.de wrote:
> > 
> > >just another idea:
> > >- use selectors (contains,...) to get a fileset with files 
> > without the
> > >header (like
> > >  Peter wrote)
> > >- use regexps for inline editing (<replaceregexp> task)
> > >  match:   (.*)
> > >  replace: ${header}\1
> > >  flags:   s
> > >
> > >Jan
> > >
> > >  
> > >
> > >>-----Ursprüngliche Nachricht-----
> > >>Von: Peter Reilly [mailto:peterreilly@apache.org]
> > >>Gesendet am: Freitag, 17. September 2004 15:42
> > >>An: Ant Users List
> > >>Betreff: Re: AW: AW: Prepend licence information to every 
> > source file
> > >>
> > >>There is no in-place prepend task (I think), but one can do this
> > >>by
> > >>  1) getting a fileset that contain the files the need the 
> > license to
> > >>     be added
> > >>  2) iterate over the the files added the license by
> > >>         a) adding the licence to a file making a new file
> > >>         b) move that new file to overwrite the original file
> > >>
> > >>one can use the ant-contrib <for> task to do the iteration:
> > >>
> > >><project default="addlicense" xmlns:ac="antlib:net.sf.antcontrib">
> > >>  <target name="addlicense">
> > >>    <ac:for param="file">
> > >>      <fileset id="missing" dir="src" includes="**/*.java">
> > >>        <not>
> > >>          <contains text="you may not use this file except in 
> > >>compliance 
> > >>with the License"/>
> > >>        </not>
> > >>      </fileset>
> > >>      <sequential>
> > >>        <copy file="@{file}" tofile="@{file}.withlicense">
> > >>          <filterchain>
> > >>            <concatfilter prepend="license-java.txt"/>
> > >>          </filterchain>
> > >>        </copy>
> > >>        <move file="@{file}.withlicense" tofile="@{file}"/>
> > >>      </sequential>
> > >>    </ac:for>
> > >>  </target>
> > >></project>
> > >>
> > >>Peter
> > >>Kannan V wrote:
> > >>
> > >>    
> > >>
> > >>>Hi Jan,
> > >>>
> > >>> Thanks for the help. So that means that if my source files 
> > >>>      
> > >>>
> > >>doesn't have header info, then 
> > >>    
> > >>
> > >>>I have to copy them to a temp location for adding the 
> > >>>      
> > >>>
> > >>licence text. I was trying to avoid that 
> > >>    
> > >>
> > >>>copying to temp location part so that I can run the task on 
> > >>>      
> > >>>
> > >>my src folder directly.
> > >>    
> > >>
> > >>>thannks and regards,
> > >>>
> > >>>-- Kannan.
> > >>> 
> > >>>
> > >>>      
> > >>>
> > >>------------------------------------------------------------
> > ---------
> > >>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > >>For additional commands, e-mail: user-help@ant.apache.org
> > >>
> > >>    
> > >>
> > >
> > >  
> > >
> > 
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> > 
> 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message