Difference between private and public targets in ant scripts
Asked Answered
K

3

15

I've recently discovered that there are several useful templates (in Eclipse) that can be added to the script. And among them "public target" and "private target". And here the templates:

public target

    <!-- ================================= 
          target: name              
         ================================= -->
    <target name="name" depends="depends" description="description">

    </target>

private target

    <!-- - - - - - - - - - - - - - - - - - 
          target: name                      
         - - - - - - - - - - - - - - - - - -->
    <target name="name">

    </target>

And i don't get it. What is the main difference? And what does the private target mean? Is it some specific feature in ant scripts or just code beautifying?

Just interesting.

Karlotte answered 22/4, 2011 at 9:59 Comment(0)
A
19

A target which has a description is public because it appears when you execute

ant -projecthelp

The others are considered private because they don't appear by default.

Araucanian answered 22/4, 2011 at 10:4 Comment(2)
and this depends only on comment style? how interesting=)Karlotte
@Raigomaru - it's the presence of the description attribute that makes the target public, not the comments style. Additionally, you can enforce that private targets can only be called from within the script itself (i.e. in depends lists of other tasks) and not specified on the command line if you give them a name starting with a '-' character.Lampyrid
B
7

Here's an example

<project name="public_only" default="public">
    <target name="-private">
        <echo message="private" />
    </target>
    <target name="public" description="this task is public" depends="-private">
        <echo message="public" />
    </target>
</project>
Bin answered 7/12, 2012 at 15:19 Comment(1)
The accepted answer says the targe is private because of the missing description attribute, I read about the dash as first character of the name of a private target. Is it just a convention or does it have syntactical meaning?Iselaisenberg
B
0
private targets, i.e targets which could not be called by the user called in script itself

while

public can be called by user

you often want to call internal / private targets to run just a small step in the build (particularly while developing new features) – you can’t do this if the targets are private. so you end up creating a second, public, target that calls the private target … and you end up doubling the size of your build files.

Birgit answered 22/4, 2011 at 10:2 Comment(2)
Actually nothing stops the user to call the private target.Karlotte
private and public target in ant are same from the point view of ant. It is not like private and public methods in a class.Trombidiasis

© 2022 - 2024 — McMap. All rights reserved.