I have read this post:
Ant antcall a target that defines a property
This question is talking about properties. I would like to know how can I make <taskdef> on inner target that could be used for all project.
I don't want to define it on my main target, since it could be long and ugly. That's why i like to split it to inner targets.
The error i get is:
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
You want to call a target which defines a property, and use that property in the caller-scope, right?
You should take a look at ant contrib's RunTarget: http://ant-contrib.sourceforge.net/tasks/tasks/runtarget.html.
Related
I've got an Xcode project with three different targets (say soccer, baseball, basketball) resulting in three different apps. Most of the code is the same, but sometimes it's target-specific.
What's the best way to implement methods which are specific to a target? I'd like to avoid
if ([AppDelegate isSoccerTarget] {
...
} else if () {
...
} else if () {
...
}
I was thinking about using categories which only exist in one of the three targets, but then I can't use a default implementation. And I'd like to avoid inheritance as some classes are already in a class hierarchy and I'd like to keep that simple (avoid person => player, manager resulting in soccerPlayer, basketballPlayer etc.).
What's your way of doing this?
The way I handle it is I place anything that is similar in a super class that is added to all targets, and then I create a new class (for your example "Player") that is different for each target.
So in the source directory I would have subdirectories and files:
basketball/Player.m
baseball/Player.m
...
And then I would select the "Target Membership" for basketball/Player.m to be the "Basketball" target.
This way I only have to instantiate a Player class once and depending on what my target is, it will automatically create the proper class. Hope this helps.
You would make your targets in the Xcode project pane (the file at the very top), and then, in one of the tabs in each target (I forget which one) add some values in the preprocessor macros (might be pre compiler macros). Then, in your code, you can do this: say your preprocessor macro for the baseball target was called BASEBALL and soccer was SOCCER. Your code would look like this:
...blablablaothercode...
#ifdef BASEBALL
NSLog(#"Baseball!");
#endif
#ifdef SOCCER
NSLog(#"Soccer!");
#endif
...blablablaothercode...
These can be used anywhere normal code could be used. Think of it as a 'switch' statement that the compiler can use to see what code to use for each target.
can i change the value of parameter in called target and then retrieve it in the calling target in ant.Probably By refid if there is any other way that is appreciated.
Normally you cannot modify an ant property in ant once it's set, but as oers pointed out in a comment, you can use the Variable task in ant-contrib. You can even override an existing property with a Variable. According to the documentation, you should still use properties in most cases, and only use variables in the cases where you really need to be able to modify a value.
Another workaround is to set additional properties and call the other targets using those properties.
i have two ant files
mainBuild.xml
subBuild.xml
subBuild.xml is imported in the mainBuild.xml. One of target from mainBuild depends on subBuild. I need to pass the argument to the dependent ant target. I dont want to use the <antcall> or the <ant> tags, as i need the some properties from the
You can define the arguments in the property files, and then read that property in ant like this.
<property file="build.start.properties"/>
All properties in the property file will be imported in ant, and will be available as ant properties, which you can use in both mainBuild.xml and subBuild.xml.
refer this for further reference
Macros are one way to have re-usable code in ant. You can call them with different argument. Re-using of targets (using property ) may not be desirable as the properties are immutable.
Almost all of the Delphi code I have read has all the class type definitions in the units interface section, but I have seen occasional use of type definitions within the implementation section.
What exactly is the difference between these, and why would I use this?
It's pretty simple: types defined in implementation only are only visible within the implementation, so they cannot be used as types of arguments or return values in the interface. So, position your type definitions (like anything else;-) based on whether those types are only an implementation detail, or something you want to make visible externally, i.e., through the interface!
Scope. Interface declarations are public and availabe to other units when that unit is include in the Uses clause. Implementation declarations are private and only available within that specific Unit.
There is a general difference between code changes in interface and the code changes implementation during compilation. If you add a class to or change an existing class in the interface section then every unit that references the changed unit will need to be recompiled. However a change in the implementation section (a new subclass or code changes) will only required the recompilation of that unit and the IDE will link the previously compiled DCU plus the new one together to create the EXE file.
Overall the major benefit, is that it allows you to design you code to hide implementation details - define the parent class in the interface and any subclasses in the implementation. Or define classes in the implementation if they are solely needed to implement the behavious of a class/method available in the interface section.
Generally speaking, any ant task which accepts a <mapper> will also accept several tags designating particular mappers: <identitymapper>, <regexmapper>, etc.
But if you're writing your own task, you are supposed to supply a method for each possible tag that may exist inside your task. You don't want to add separate addConfiguredMapper(), addConfiguredIdentityMapper(), addConfiguredRegexMapper(), etc. methods. How do you easily set up a custom ant Task to take any arbitrary Mapper, specified by either the general <mapper> tag or the tag for each particular instance?
These are the two methods you will need to supply:
public Mapper createMapper() throws BuildException;
public void add(FileNameMapper fileNameMapper);
Take a look at the Copy task in the ant source distribution to see how these are implemented.