I have the following problem. I have something like 300 Eclipse Plugins. Now, as part of an ant script I want to read all MANIFEST.MF files and then look for the execution environment string.
Bundle-RequiredExecutionEnvironment: J2SE-1.4
Now, this string has several possible values. I want to create a report that lists the execution environment for each plug-in. That part is not really a problem as I can use some kind of regexp to obtain it.
My problem is that I want also to create some kind of summary for tracking changes at a glance, something like:
JS2E-1.4: 50 Plugins
JS2E-1.5: 150 Plugins
JS2E-1.6: 74 Plugins
Anyone has some suggestions on how could I go around this?
EDIT: Reason for using ANT is that I want to integrate it with a nightly build script
I would definitively go for hard-coded Ant task and decompose the problem in two tasks:
the first task takes a jar file and outputs a plugin-info.xml file that contains various infos, like the environment
the second task parses all these xml files and creates an XML summary report
This will of course generate (n+1) XML files for n plugins and some will find this way too much.
The nice end effect with that approach is that you can generate either detail or aggregated reports very easily (with some XSLT magic.) or even graphs.
If i were to do it myself, i probably would just write a perl script.
If it has to be done from Ant, i would write an Ant Task to do it.
I would suggest just printing each executable environment on System.out and then post process with "|sort| uniq -c".
You can use the math task from the ant-contrib project
I had to do it, I'd probably go for some shell script or custom code
Related
I want to insert the content of a file into an xml-file (using XPath or a replacer token). This should happen during the build process using maven.
My first try was to use the maven ant task plugin and the xmltask task of ant.
<xmltask source="sourceFile.xml" dest="destinationFile.xml">
<replace path="//L7p:MapValue[2]/L7p:Mappings" withfile="xmlFileToInsert.xml" />
</xmltask>
That worked fine for a while, but now i want to insert not valid xml. This xml will be made valid in future steps - but its really required to insert invalid xml here. AFAIK, this does not work with the xmltask of ant. If you know a way to disable the validation, it would also help.
Now, I'm searching for nearly the same xmltask can do in combination with maven and ant but without the validation of xml.
What do you guys think is the best way to do this with maven?
List item
Include shell script?
Write an maven plugin?
???
Thanks for your opinion and help.
If you're already using Ant, just use the Ant replace task (https://ant.apache.org/manual/Tasks/replace.html). It replaces text by another in any file, so it doesn't care if it's not valid XML. Read the value to use as a replacement from your file, and have a marker token in your original file. You could still first use xmltask to insert the marker token via XPath to give valid XML, then do the textual replacement via replace.
So I've been making a grammar in Eclipse with ANTLR v3.4 and I've made one that works and I want to make sure when I edit it everything still works. I can go into the interpretter everytime but that seems like a huge waste of time.
Questions:
I've read about gunit but the link it gives to download gUnit:
( http://antlr.org/hudson/job/gUnit/org.antlr$gunit/lastSuccessfulBuild/ ) doesn't work. How can I get gUnit.
What is the best way to test grammars? Is it actually gUnit or should I just do java tests like jUnit tests?
The question is old, but I'm leaving a reference for completeness:
For me, the gUnit was useless. So I managed to find how test only the Lexer and then, only the parser.
I answered it here: https://stackoverflow.com/a/53884851/976948
Basically, there are links for 2 articles about how to test it:
Unit test for Lexer
Unit test for Parser
I recently completed two ANTLR3 assignments (I'm working on my Master's in Computer Science) using Eclipse. I found no single document that had a process for installing, configuring, writing, and debugging a grammar in Eclipse. So, after working through various issues, I found the easiest thing to do was to stay in Eclipse for testing.
To use the process I have come to use (outlined below) you must first have the ANTLR IDE v2.1.2 installed. Add it right from inside Eclipse Indigo: http://antlrv3ide.sourceforge.net/updates. This site also has some useful doc on using the ANTLR IDE. Once installed, the IDE has to be configured. Video tutorials are a bit out of date but helpful. See a detailed how to guide on configuring ANTLR IDE in Eclipse. The main configuration item is the java output folder. Do this in Eclipse by going to Windows, Preferences, ANTLR, Code Generator, check Project relative folder and in the Output folder name box type a folder name (mine is called "antlr-java", others use "generated").
Test/Debug Process for ANTLR in Eclipse Indigo with ANTLR IDE
After a new project is created, right-click it, select Configure, Convert to
ANTLR Project...
Create the grammar in a .g file and save it. Note: filename has to match grammar name.
If there are significant errors, debug the grammar. Eclipse shows the ANTLR error(s)
and what line(s) are affected. At first, these errors seem hard to understand but
they can be worked through by using various resources:
- The Definitive ANTLR Reference by Terence Parr the guy who wrote ANTLR
- the ANTLR Reference Manual
- google the error; many times you will end up here at stackoverflow;
in particular, Bart Kiers is both knowledgeable and helpful (Bart: thx for
the help you didn't know you gave me)
On the first save after the serious ANTLR errors are resolved, the java output folder you
configured in Eclipse will be created and a java file in that folder will also be created.
Right-click on the java output folder, select Build Path, Use As a Source Folder. This
tells Eclipse where to look for the project's java source.
There are likely to be errors in the new java file. Select it, then search through looking
for java errors. Go back to your grammar or java file(s), correct the errors, and re-save
the grammar until both grammar and java files are error free, then run it.
From this point on, it's the usual modify-run-debug cycle.
The only other Eclipse change I needed was to create a few Run Configurations for testing
command line parameters.
You can download gUnit there but I think there is no latest version...
Try Jarvana... Latest version there is 3.4: http://repo1.maven.org/maven2/org/antlr/gunit/3.4/gunit-3.4.jar
#Dave Newton is right. As of ANTLR v3.1, gUnit is included in the main ANTLR Tool jar as is stated there.
I didn't know for gUnit till now. It looks great for grammar testing, but I think that JUnit tests will do their job to...
This is the first time I heard of gUinit and read up on it. (I don't use ANTLR much.) It sounds interesting, but half useless.
My approach to validating grammars is to actually validate the the entire parser with "normal" unit tests. The thing is, you should have unit tests in place anyway and the tests that check for grammar regression you just add it there. The thing is in my experience that most errors come in semantic analysis and reduction and not the grammar.
I'm trying to learn some ant for a Struts 1.x project that I was thrown onto. Mainly I'm trying to find a good referent for the inherent variables/properties of ant...beginners tutorial. Any GOOD reference really.
A couple lines of the ant file that I've been trying to figure out just for example...
<available file=${deploy.ant.docbase.dir}/WEB-INF/sun-web.xml" property="sun.web.present"/>
and
<replace file="${temp.sun.web}">
<replacetoken><![CDATA[<!DOCTYPE]]></replacetoken>
<replacevalue<![CDATA[<!-- <!DOCTYPE]]></replacevalue> //in ant is <!-- the comment out flag?
</replace>
I did do some searching and only could find ant build examples without explanation, but if it is covered and I just didn't find it a link will suffice. No reason to make someone reexplain it....I just couldn't find it.
Your first code block refers to the "available" ant task. It sets the property sun.web.present if the given file exists.
In your second code block, "<!--" starts an XML comment ("-->" closes one). This is true for all XML, not just ant build.xml files. In this case it is using the "replace" ant task to replace "<!DOCTYPE" with "<!-- <!DOCTYPE" within the file named by temp.sun.web.
In general an ant build file has targets like "build" or "clean". These depend on each other so that "test" runs "build" first. The targets are implemented by "tasks", where each XML tag refers to a task. You can read their manual and refer to the per-task docs for how each task works.
The Ant Manual is your friend. There's a link Ant tasks on the left side of the page. Click on that link, and then the List of Tasks link. That will list all of the Ant tasks on the left and their explanation on the right. There, you'll see the available task and the replace task.
Unfortunately, the Ant manual uses Frames (bad Ant Manual! Bad Ant Manual!), so I can't supply a link that will list both the
(Shameless bid for reputation)
The example doesn't use a built-in property. Most Ant targets won't, because after properties are first set they are immutable. Instead, Ant scripts usually define their own properties. The Ant manual lists the properties that Ant predefines.
If you want to get into the guts of Ant, I recommend the Manning "Ant in Action" book.
I'm trying to write an SVN Post-Commit hook to generate javadoc on a webpage whenever someone submits any changes to relevant files.
I was new to the hook concept, but I didn't expect to run in any strange errors when generating the javadoc.
java.lang.ClassCastException: com.sun.tools.javadoc.ClassDocImpl cannot be cast to com.sun.javadoc.AnnotationTypeDoc
at com.sun.tools.javadoc.AnnotationDescImpl.annotationType(AnnotationDescImpl.java:46)
at com.sun.tools.doclets.internal.toolkit.util.Util.isDeprecated(Util.java:811)
at com.sun.tools.doclets.formats.html.AbstractIndexWriter.printComment(AbstractIndexWriter.java:186)
After a few succesful searches on StackOverFlow I discovered it had something to do with third-party-annotations. (I make use of the Play framework and that uses a number of other libraries)
So I included everything in a script:
#!/bin/sh
CLASSPATH="~/Play/play-1.1.1/;"
javadoc -d ~/svndoc/ -classpath $CLASSPATH -sourcepath ~/svntest/avon/trunk/ScoreDB/app #packages
But this generates the exact same errors. Sometimes there are 10 warnings, but most of the time there are 27 of them.
Could you guys help me out?
Thanks in advance,
Jasper
Your classpath looks wrong. First, there should be no ; in it (in Unix, the separator is :, but it is not needed at the end). Secondly, do you really have the individual class files in this directory? If there are jar files, you need to either list them individually, or put a * there (but pay attention that bash does not expand it, since you would need : instead of spaces between).
I have no idea if this would solve the problem, though.
I would like to append the output JAR filename of a Netbeans project with some version number: something like 1.0, 2.0b or even a Subversion revision number. I can't seem to find anything on this, though. I am also not sure if this would the responsibility of the build system (Ant) or if the IDE (Netbeans) can delegate the process. Is there a centralised, clean way of doing this?
IMO, this is the responsibility of the build system, not of the IDE. Let me say it in other way: don't rely on your IDE to build your project, use a build tool. Using an IDE is fine during development but being IDE dependent to build a project is not a good thing (what if you change your IDE tomorrow, what if you want to build your project on another machine/OS without that IDE, what if you want to build your project on a headless machine, what if you want to automate your build, what if someone wants to build that project and doesn't have that IDE, etc, etc). Really, this is what build systems are for.
Now, regarding your initial request, there are plenty ways to add a version number. One of them is to use the Ant's BuildNumber task:
This is a basic task that can be used to track build numbers.
It will first attempt to read a build number from a file (by default, build.number in the current directory), then set the property build.number to the value that was read in (or to 0, if no such value). It will then increment the number by one and write it back out to the file. (See the PropertyFile task if you need finer control over things such as the property name or the number format.)
Use it for example like this:
<target name="jar" depends="compile">
<property name="version.num" value="1.00"/>
<buildnumber file="build.num"/>
<jar destfile="foo-${version.num}-b${build.number}.jar"
basedir="."
includes="**/*.class"
/>
</target>
Or you could indeed add subversion revision number. An easy way to do this seems to install the SVNAnt task and use the status task:
<target name="revisionnumber">
<!-- get the svn revision number -->
<svn>
<status path="application.cfm" revisionProperty="svn.revision" />
</svn>
<echo>Sandbox Revision: ${svn.revision}</echo>
</target>
Finally, another option would be to use Maven instead of Ant which has a built-in version management feature as pointed out by cetnar.
I'm not sure if it's the best way, but we put it in MANIFEST.MF file like this:
Implementation-Version: 2.0b
We can get this value programmatically like this:
String version_num = this.getClass().getPackage().getImplementationVersion();
If you feel like using a tool to handle your builds then there are lots about, such as CruiseControl, which is ANT based and has pretty deep integration with your source code control.
I use it to automatically increment a build number and use that as the last digit in my version number for the jar, e.g. 1.4.168, where 168 is the build number. I am just about to get it to put a label into CVS just before the fetch with the build number so I know exactly what code is in the jar.
Well is done default by Maven. Even if you want name your jar file with more detailed information you can use build number plugin.
EDIT
At begining I misunderstood your question so following part relates to adding this information inside jar files.
You can do it yourself by creating manifest file. In Maven it you can tune proces of creating manifest file by additional configuration. I suppouse (I'm sure) that in Ant should be similar functionality.
you can use maven for vesion and read it from pom.
read this article:
Embedding the maven version number
at
http://happygiraffe.net/blog/2008/10/01/embedding-the-maven-version-number/