Question about Pre-processing behavior and property file modifiactions

Hi -

I am trying to use the Pre-processing setting tab in the Artifact configuration Project setting but it is not working as I would expect.

I have two artifacts set up in my Project Settings. One is an exploded WAR, the other is a WAR which includes the exploded WAR artifact. Everything builds fine, I get a WAR and I get an exploded WAR directory when I build.

So with that building my goal became to edit a properties file which is in a src directory, src/main/java/com/foo/view/message.properties and dynamically set a property (build number in this case) in it, but I could not find a way to do this directly in the project settings.

What I decided to try was to use an ANT task to modify the properties file and call the task from the Pre-processing step of my exploded WAR artifact.

After creating this ANT task and configuring the Pre-processing step of my exploded WAR artifact to call it I am seeing that the file is properly edited and is in the correct location in the WEB-INF\classes\com\foo\view directory of the exploded WAR folder, however, the WAR file built by the WAR artifact which uses the output of the exploded WAR artifact does not included the modified file, it includes the unmodified one instead.

I assumed, based on reading the online help, that the Pre-processing step occurs prior to artifact generation. In this case it should call the ANT task to modify my properties file before generating the exploded WAR artifact. Then, because my WAR artifact is dependent on the exploded artifact it should pick up the modified file and include it in its artifact WAR.

Any thoughts on why this isn't behaving as expected? Is there a better way to accomplish what I am trying to do without using ANT or other external tool? I would like to be able to modify this properties file simply using IDEA and pure IPR settings if possible.

Thanks,

-Noah


UPDATE:

This seems to have something to do with how the project is including the exploded WAR artifact in the WAR artifact. I did the following:

0. Disabled all Pre-processing settings
1. Deleted my build\artifacts directory
2. Built the exploded WAR artifact
3. Went into the build/artifacts/exploded_artifact_folder and modified the properties file by hand
4. Built the WAR artifact
5. Opened the WAR and inspected the properties file and found it did not contain my edits

Clearly based on what I am seeing, even though my project settings say to include the exploded WAR artifact it is not including the files from the exploded WAR artifacts output directory.

Based on this I decided to try changing my ANT target to update the message.properties file that had been copied into MODULE.OUTPUT.DIR tree. Sure enough that worked. Both the exploded artifact and the WAR artifact picked up the modified file.

I was surprised to see this behavior because when you tell IDEA to auto generate the ANT files it generates an ANT file with a target for the WAR artifact that ZIPs up the contents of ARTIFACT.OUTPUT.MODULE_EXPLODED.  This points to build/artifacts/MODULE_NAME_EXPLODED not MODULE.OUTPUT.DIR, so either the ANT generation is broken or the IDEA artifact generation is broken.

UPDATE 2:

It looks like the Pre-processing settings are not reflected in the artifact target as a dependency when you tell IDEA to generate the ANT build file. I think this is a bug as well.

3 comments

Hello,

'Pre-processing' tasks are indeed executed prior to artifact generation. However IDEA decides which files need to be copied to artifact output before
starting pre-processing tasks. It's essential because IDEA shouldn't call pre/post processing tasks if artifact is up to date. So pre/post processing
tasks should be used to modify artifact output files rather than module source files.

Hi -

>

I am trying to use the Pre-processing setting tab in the Artifact configuration Project setting but it is not working as I would expect.

>

I have two artifacts set up in my Project Settings. One is an exploded WAR, the other is a WAR which includes the exploded WAR artifact. Everything builds fine, I get a WAR and I get an exploded WAR directory when I build.

>

So with that building my goal became to edit a properties file which is in a src directory, src/main/java/com/foo/view/message.properties and dynamically set a property (build number in this case) in it, but I could not find a way to do this directly in the project settings.

>

What I decided to try was to use an ANT task to modify the properties file and call the task from the Pre-processing step of my exploded WAR artifact.

>

After creating this ANT task and configuring the Pre-processing step of my exploded WAR artifact to call it I am seeing that the file is properly edited and is in the correct location in the WEB-INF\classes\com\foo\view directory of the exploded WAR folder, however, the WAR file built by the WAR artifact which uses the output of the exploded WAR artifact does not included the modified file, it includes the unmodified one instead.

>

I assumed, based on reading the online help, that the Pre-processing step occurs prior to artifact generation. In this case it should call the ANT task to modify my properties file before generating the exploded WAR artifact. Then, because my WAR artifact is dependent on the exploded artifact it should pick up the modified file and include it in its artifact WAR.

>

Any thoughts on why this isn't behaving as expected? Is there a better way to accomplish what I am trying to do without using ANT or other external tool? I would like to be able to modify this properties file simply using IDEA and pure IPR settings if possible.

>

Thanks,

>

-Noah

>

---
Original message URL: http://devnet.jetbrains.net/message/5275840#5275840



--
Nikolay Chashnikov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

0

Guest wrote:

Hello,

'Pre-processing' tasks are indeed executed prior to artifact generation. However IDEA decides which files need to be copied to artifact output before
starting pre-processing tasks. It's essential because IDEA shouldn't call pre/post processing tasks if artifact is up to date. So pre/post processing
tasks should be used to modify artifact output files rather than module source files.


Nikolay,

Thank you for your response, that makes sense. Would you be able to address the behavior I am seeing in UPDATE and UPDATE 2 of my post? Thanks,

-Noah

0

Hello,

when IDEA builds the 'war' artifact containing the 'exploded' artifact it doesn't include files from the 'exploded' artifact output to the war
archive. Instead it composes the war archive from the source files which are configured to be copied to the 'exploded' artifact. Note that it will
give the same result as the generated ant file unless you edits output of the 'exploded' artifact by hand. This behaviour is caused by the current
IDEA compiler architecture: IDEA needs to decide which files should be copied to the artifacts before it starts building.

The problem described in Update 2 is indeed a bug. Could you please create an issue for it in our tracker (http://youtrack.jetbrains.net/issues/IDEA)?

Guest wrote:
>
> Hello,
>
> 'Pre-processing' tasks are indeed executed prior to artifact generation. However IDEA decides which files need to be copied to artifact output before
> starting pre-processing tasks. It's essential because IDEA shouldn't call pre/post processing tasks if artifact is up to date. So pre/post processing
> tasks should be used to modify artifact output files rather than module source files.

>

Nikolay,

>

Thank you for your response, that makes sense. Would you be able to address the behavior I am seeing in UPDATE and UPDATE 2 of my post? Thanks,

>

-Noah

>

---
Original message URL: http://devnet.jetbrains.net/message/5275917#5275917



--
Nikolay Chashnikov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

0

Please sign in to leave a comment.