7 Replies Latest reply on Mar 17, 2010 3:38 AM by dgolovin

    create/extend  a builder for hbm files?

    elhanan

      hi..

       

      is there a way to ensure that when i save an hbm file eclipe will automatically add 3 properties to it? (it's a legacy kind of thing) .

        • 1. Re: create/extend  a builder for hbm files?
          maxandersen

          not directly - but you could probably write a script that would get called by a Builder to check if your hbm.xml file contains the 3 elements and if not then add them.

           

          But not sure why this wouldn't be done better by just writing a xml manipulation and call it from ant on all your hbm.xml files ? Then it would be IDE independent.

          • 2. Re: create/extend  a builder for hbm files?
            elhanan

            actually this is what's happening rigit now, we have an ant script which runs on all the hbm's through xsl copies them to a build directory, the same scripts also bothers to compile our entire source, (again after eclipse did it) load it with aspectwerkz aspects, generate spring xml files contaning references to said hbm's, and then afterwords copies the entire thing again into a jboss ear.

             

            pro's: IDE agnostic.

             

            cons: takes mintues to do , frags the disk, creates a mismatch between my hbm and the actuall build (thus i cannot run immidiate junit tests, or launching) and unusable in a j2ee prespective with dynamic web project s and ear projects, and all for what?

             

            build scripts are nice.. for CI server (if you have one), what i wanna do, is use aspectj instead of aspect werkz, just only incremental build aspects, not compile every source each time, and have eclipse append the fields i want to my actuall source, and i could use standard web projects for this, thus avoiding huge amount of needless overhead.

             

            so how would i write a script to be called from a builder? (do you mean ant scripts configured form .projects?)

            • 3. Re: create/extend  a builder for hbm files?
              dgolovin
              Actually you can add builder based on ant script. Just open project properties and look at "Builders" category. Then hit "New" and select "Ant Builder". You can change order of your builders by "Up/Down" button.
              • 4. Re: create/extend  a builder for hbm files?
                elhanan
                yes, but will it be an incremntal build ? meaning let's say i've changed 3 xml's will it be called on each of the 3 changing it? also note, that i wanna first change the actuall source, then have eclipse copy it to the bin lib. and how will i pass the file changed to the ant script?
                • 5. Re: create/extend  a builder for hbm files?
                  dgolovin

                  To make it incremental you have to inject changed files from eclipse. Just define ant property like it shown below.

                  ant-inject-files.png

                  build_files variable returns the set of absolute file system paths whose modification caused the current build.  A list of the characters, 'a' (added), 'c' (changed), 'r' (removed), 'f' (files only), 'd' (directories only), can be supplied as an argument to limit the file list to just those types of deltas.  Defaults to all deltas.

                   

                  My might be needed to define several other variables like where to copy changed files and etc.

                   

                  It is not easy, but can be done.

                   

                  If you change three files and then press Save all you'll get those three files injected in build through ${changes} ant property and build will be called once. If you save them on by one -> builder will be called tree times. But you can control it a little with "Targets" tab and configure it to be called only once for manual build for example, but in this case you'll get only one changed resource and that will be project folder.

                   

                  It could be a problem to change actual files because it could trigger ant script builder twice. First after your change files. Then after ant builder finished and modified actual sources get refreshed as it configured on Refresh tab.

                   

                  So it could work this way.

                  1. Your build iterate through ${changes} using <for> and check that changed files if they should be altered with missing attributes. If there is nothing to add it just should skip the file.

                  2. Add the ant builder to builders list and inject all required params

                   

                  When you change something it will trigger the builder with list of changed files and then required attributes should be added to sources in project.

                  Then "Refresh" happens and it triggers builder again, but it does nothing because required attributes already present.

                  Then it is in waitig state for next changes.

                   

                  Second option for you is developing plug-in with Incremental builder like it described here "Project Builders and Natures". I remember there is an template in eclipse SDK which does most of the work left for you only actual implementation of several methods.

                  1 of 1 people found this helpful
                  • 6. Re: create/extend  a builder for hbm files?
                    elhanan
                    thanks , the ant script would have almost nailed it, if it wern't for some folks skipping manual build and doing Ctrl+b   (not me), a plug-in builder is what i was going for, becouse it would help me to also anaylaze some other xml files and put problem markers in case attribubtes refer to methods which do not exist in classes (but i have no idea how to do that. getting an object model of a class in an eclipse project)
                    • 7. Re: create/extend  a builder for hbm files?
                      dgolovin

                      Elhanan wrote:

                       

                      ... getting an object model of a class in an eclipse project

                      I almost said, that it is simple It actually is, but when you get used to it. This article should give you some ideas, look at "Abstract Syntax Tree".