yGuard does not work in the simplest form possible (Hello World) - netbeans

Here is my Ant snippet:
<target name="-post-jar">
<taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="${javac.classpath}"/>
<yguard>
<inoutpair in="${dist.dir}/Valuemaze.jar" out="${dist.dir}/Valuemaze_obf.jar"/>
</yguard>
<copy file="${dist.dir}/Valuemaze.jar" tofile="${dist.dir}/Valuemaze_test.jar"/>
</target>
Classpath is ok, target runs as the second task (copy) works properly. So paths are ok.
yguard task does nothing. No any message, warning nor error is provided. Cannot configure any debug logging, yguard seems to have none.
What can be wrong?

It forced me to dig into yGuard sources.
And the answer is:
<target name="-post-jar">
<taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="${javac.classpath}"/>
<yguard>
<inoutpair in="${dist.dir}/Valuemaze.jar" out="${dist.dir}/Valuemaze_obf.jar"/>
<rename mainclass="mypackage.myclass"/>
</yguard>
</target>
You have to add subtask to make it working.
Why does not docs specify this? Because it doesn't.
Why there is no single example for newbies in docs? Because it isn't.
Why there is no debug information about task missing? Because so.
Leaving here for other begginers.

Related

When using ant in eclipse, standard input does not work?

In demo.Main.main method I do
System.in.read()
In build.xml there is the target
<target name="run">
<java classname="demo.Main" fork="false">
<classpath refid="classpath" />
</java>
</target>
When I go to Eclipse's Console and I give something in , System.in.read() does not see it.
Ant does not support System.in.read().
Use the Ant task <input> for user input instead.

Getting an error "Could not load definitions from resource net/sf/antcontrib/antcontrib.properties. It could not be found."

I am getting an error Could not load definitions from resource net/sf/antcontrib/antcontrib.properties. It could not be found. when I am trying to ant build on eclipse. So I downloaded ant-contrib-0.6.jar and kept it in my /lib location of apache ant, but it still does not resolve my issue. I have also tried by specifying the /lib location in my CLASSPATH system variable. How can I get around this error?
You can provide full path to the ant-contrib JAR explicitly using "classpath" element:
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${path-to-ant-contrib}/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
EDIT: Link contributed by Djacomo:
http://ant-contrib.sourceforge.net/
One important thing missing from this StackOverflow page is that setting the correct ANT_HOME env var is absolutely vital and important, without this setting ant keeps telling the same error, regardless of where you copy the ant-contrib-1.0b3.jar on your file systems. This missing thing has costed me a few hours. =)
However I receive this error without eclipse, in the pure ant.
I fixed that this way:
Add the JAR to the Ant runtime classpath entries.
Window>Preferences>Ant>Runtime>Classpath
Add the JAR to either Ant Home Entries or Global Entries.
It would appear that you haven't installed the ant contrib jar into the correct lib directory. This can be difficult to do if you have several installations of ANT.
My suggestion is to install your ANT plugins into the "$HOME/.ant/lib" directory. You could go one step further and automate the process as follows:
<project name="ant-contrib-tasks" default="all">
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<target name="bootstrap">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ant-contrib.jar" src="http://search.maven.org/remotecontent?filepath=ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar"/>
</target>
<target name="all">
<for param="file">
<fileset dir="." includes="*.txt"/>
<sequential>
<echo message="Found file #{file}"/>
</sequential>
</for>
</target>
</project>
Use the below mentioned code in your build xml:
<path id="ant.classpath">
<pathelement location="${ant.jarPath}/ant.jar" />
<pathelement location="${ant.jarPath}/ant-contrib-0.3.jar" />
</path>
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath refid="ant.classpath" />
</taskdef>
And in your build property file:
ant.jarPath=D:/antjars
And place ant.jar and ant-contrib-0.3.jar in directory:D:/antjars
Check you have read permissions for the ant-contrib jar file.
In our case after copying the file with another user it did not, giving the same error message.

acceleoCompiler not showing output in console output with ant

I am using acceleoCompiler inside an ant script and when i run the ant script everything shows an output except acceleoCompiler.
For instance, [javac] and [mkdir] shows up. But nothing relating to acceleoCompiler shows up. Am i doing something wrong?
The ant script:
<eclipse.refreshLocal resource="${F_FOLDER}/bin/" depth="infinite"/>
<eclipse.refreshLocal resource="${FE_FOLDER}/bin/" depth="infinite"/>
<mkdir dir="${F_OUTPUT}"/>
<mkdir dir="${FE_OUTPUT}"/>
<javac
srcdir="${F_SRC}generator/"
destdir="${FR_OUTPUT}"
executable="${JAVA_JDK}/javac"
fork="true"
includeantruntime="false"
failonerror="false"
/>
<javac
srcdir="${FE_SRC}generator/"
destdir="${FE_OUTPUT}"
executable="${JAVA_JDK}/javac"
fork="true"
includeantruntime="false"
failonerror="false"
/>
<acceleoCompiler sourceFolder="${F_SRC}"
outputFolder="${F_OUTPUT}"
dependencies=""
binaryResource="true"
packagesToRegister="org.eclipse.emf.ecore.EcorePackage">
</acceleoCompiler>
<acceleoCompiler sourceFolder="${F_SRC}"
outputFolder="${FE_OUTPUT}"
dependencies=""
binaryResource="true"
packagesToRegister="org.eclipse.emf.ecore.EcorePackage">
</acceleoCompiler>
The absence of logging messages doesn't mean you're doing anything wrong. If you look at the source for mkdir or javac you'll see that they call the Ant Task method log() in most cases. The Acceleo Ant task however only calls log() if it finds a problem - if all is well it is silent and enigmatic.
References:
Ant mkdir task source.
AcceleoCompiler source via the Acceleo wiki FAQ.

Include/Exclude buildfiles

How do you do this? Given several build files, I only want to include the ones where the target (specified from the command line) exists. Using target::exists in does not seem to work. Thanks.
<target name="*">
<property name="curr.target" value="${target::get-current-target()}"/>
<nant target="${curr.target}">
<buildfiles>
<include name="*.build" if="${target::exists(curr.target)}"/>
<!-- avoid recursive execution of current build file-->
<exclude name="${project::get-buildfile-path()}" />
</buildfiles>
</nant>
</target>
Using robaker's solution, my final build file looks like this. It does not fail anymore if the target is not found in a certain build file (unlike my previous code).
<project>
<include buildfile="A.build"/>
<include buildfile="B.build"/>
<target name="*">
<nant target="${target::get-current-target()}"/>
</target>
</project>
Why not just use the include task to include all your child build scripts instead?

Is it possible to override nant targets from included buildfile?

I have a generic common.xml file that holds a number of generic nant targets that are re-used among multiple builds. What I want to do is 'override' some of these nant targets and include additional steps either before or after the existing target is executed.
Are nant targets used from the current file first? ie. If i create a nant target in the current buildfile with the same name as a target in an included file does that one get called and the included one ignored? If that's the case I can just do and call the included target but it would seem like then that would be a recursive call rather then to an included task.
Thoughts?
I had the same question (and found the same results), but I also found a workaround. Allow me to illustrate with an example.
You have a ProjectFile.build and a CommonFile.build. Let's say you want to overwrite a target called "Clean".
You would need to create a new file (call it CommonFile_Clean.build) which contains:
<?xml version="1.0"?>
<project>
<target name="Clean">
<echo message="Do clean stuff here" />
</target>
</project>
In CommonFile.build, you conditionally include CommonFile_Clean.build:
<?xml version="1.0"?>
<project>
<echo message="checking Clean definition..." />
<if test="${not target::exists('Clean')}">
<echo message="Clean target not defined." />
<include buildfile="CommonFile_Clean.build" />
</if>
</project>
In ProjectFile.build, you can either define the Clean target (in which case CommonFile_Clean.build will not be used) or use the default implementation as defined in CommonFile_Clean.build.
Of course, if you have a large number of targets, this will be quite a bit of work.
Hope that helps.
No, I've just tried it for you, as I have a similar set-up, in that I have all of the build targets we use in a commonFile.build and then use the following code to bring it in...
<include buildfile="../commonFile.build"/>
In my newFile.build (that includes the commonFile.build at the top of the file), I added a new target called 'build', as it exists in the commonFile, and here's the error message you get in response...
BUILD FAILED
Duplicate target named 'build'!
Nice idea, probably bourne of OO principles, but sadly it doesn't work.
Any good?