ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shawn Castrianni <Shawn.Castria...@halliburton.com>
Subject RE: IDEA Project generation from ant
Date Tue, 03 Nov 2009 14:00:26 GMT
I would advise against creating the ipr file as it is very long and nasty.  I would suggest
only generating the iml file which is the important part and points to the source code locations
and dependent jars.  I have written a macrodef to generate an IML that has been tested against
IJ 8.1.3.  This macrodef has references to other specific items in my build system so you
will not be able to use it directly without modification.  But, perhaps you can use it as
a template to write your own.  Once a user generates their IML from this, they can create
a new project in IJ and then import this IML file and they are ready to go.


		<macrodef name="generateIntelliJModule" description="Converts a dependency directory
into an IntelliJ module iml file">
			<!--Assumes source code is in src directory at root-->
			<!--Assumes thirparty jars are in jar directory at root-->
			<!--Doesn't take into account env.BUILD_DIR-->
			<!--Doesn't take into account user ivy.xml file-->
			<attribute name="moduleName"/>
			<attribute name="moduleDir"/>
			<attribute name="moduleSandbox"/>
			<attribute name="moduleDependency"/>
			<sequential>
				<!--Check for ivy module location-->
				<ac:var name="ivyModuleDir" unset="true"/>
				<ac:var name="ivyDependencySourceDir" unset="true"/>
				<condition property="ivyModuleDir" value="${@{moduleName}.sandbox.dir}" else="@{moduleDir}">
					<and>
						<istrue value="@{moduleSandbox}"/>
						<istrue value="@{moduleDependency}"/>
					</and>
				</condition>
				<!--IntelliJ likes forward slashes-->
				<at:stringutil property="ivyModuleDir" string="${ivyModuleDir}">
					<at:replace regex="\\" replacement="/"/>
				</at:stringutil>
				<at:stringutil property="ivyDependencySourceDir" string="${env.DEPENDENCIES_SOURCE_DIR}">
					<at:replace regex="\\" replacement="/"/>
				</at:stringutil>
				<!--Write generic file-->
				<echoxml file="@{moduleDir}/@{moduleName}.iml">
					<module relativePaths="false" type="JAVA_MODULE" version="4">
						<component name="NewModuleRootManager" inherit-compiler-output="true">
							<exclude-output/>
							<content url="file://${ivyModuleDir}"/>
							<orderEntry type="inheritedJdk"/>
							<orderEntry type="sourceFolder" forTests="false"/>
							<orderEntry type="module-library" exported="">
								<library name="@{moduleName}-jars">
									<CLASSES/>
									<JAVADOC/>
									<SOURCES/>
								</library>
							</orderEntry>
						</component>
					</module>
				</echoxml>
				<!--Add excludes-->
				<ac:if>
					<isset property="@{moduleName}.intellij.exclude"/>
					<ac:then>
						<!--IntelliJ likes forward slashes-->
						<at:stringutil property="@{moduleName}.intellij.exclude" string="${@{moduleName}.intellij.exclude}">
							<at:replace regex="\\" replacement="/"/>
						</at:stringutil>
						<ac:for param="intellij.excludeDir" list="${@{moduleName}.intellij.exclude}">
							<sequential>
								<xt:xmltask source="@{moduleDir}/@{moduleName}.iml" dest="@{moduleDir}/@{moduleName}.iml">
									<xt:insert path="/module/component/content" xml="&lt;excludeFolder url=&quot;file://${ivyModuleDir}/@{intellij.excludeDir}&quot;/&gt;"/>
								</xt:xmltask>
							</sequential>
						</ac:for>
					</ac:then>
				</ac:if>
				<!--Add jars-->
				<ac:if>
					<available file="${ivyModuleDir}/jar"/>
					<ac:then>
						<!--Only recurse jars if a real sandbox-->
						<ac:var name="ivyModuleRecurseJars" unset="true"/>
						<condition property="ivyModuleRecurseJars" value="true">
							<istrue value="@{moduleSandbox}"/>
						</condition>
						<ac:for param="ivyModuleDirJar">
							<fileset dir="${ivyModuleDir}/jar">
								<include name="*.jar" unless="ivyModuleRecurseJars"/>
								<include name="*.zip" unless="ivyModuleRecurseJars"/>
								<include name="**/*.jar" if="ivyModuleRecurseJars"/>
								<include name="**/*.zip" if="ivyModuleRecurseJars"/>
							</fileset>
							<sequential>
								<!--IntelliJ likes forward slashes-->
								<at:stringutil property="ivyModuleDirJar" string="@{ivyModuleDirJar}">
									<at:replace regex="\\" replacement="/"/>
								</at:stringutil>
								<xt:xmltask source="@{moduleDir}/@{moduleName}.iml" dest="@{moduleDir}/@{moduleName}.iml">
									<xt:insert path="/module/component/orderEntry/library/CLASSES" xml="&lt;root
url=&quot;jar://${ivyModuleDirJar}!/&quot;/&gt;"/>
								</xt:xmltask>
							</sequential>
						</ac:for>
					</ac:then>
				</ac:if>
				<!--Add JavaDoc URL if not sandbox dependency-->
				<ac:if>
					<isfalse value="@{moduleSandbox}"/>
					<ac:then>
						<ac:var name="ivy-module.info(revision)" unset="true"/>
						<xmlproperty file="${ivyModuleDir}/ivy/ivy.xml"/>
						<!--Strip off release spec name from revision of dependency-->
						<at:stringutil property="ivyModuleReleaseSpec" string="${ivy-module.info(revision)}">
							<at:replace regex="\..*" replacement=""/>
						</at:stringutil>
						<xt:xmltask source="@{moduleDir}/@{moduleName}.iml" dest="@{moduleDir}/@{moduleName}.iml">
							<xt:insert path="/module/component/orderEntry/library/JAVADOC" xml="&lt;root
url=&quot;http://cmnas01.lgc.com/www/docs/@{moduleName}/${ivyModuleReleaseSpec}/java&quot;/&gt;"/>
						</xt:xmltask>
					</ac:then>
				</ac:if>
				<!--Add compiled source path-->
				<ac:if>
					<available file="${ivyModuleDir}/src"/>
					<ac:then>
						<xt:xmltask source="@{moduleDir}/@{moduleName}.iml" dest="@{moduleDir}/@{moduleName}.iml">
							<xt:attr path="/module/component" attr="inherit-compiler-output" value="false"/>
							<xt:insert path="/module/component/exclude-output" position="before" xml="&lt;output
url=&quot;file://$MODULE_DIR$/build/classes&quot;/&gt;"/>
							<xt:insert path="/module/component/exclude-output" position="before" xml="&lt;output-test
url=&quot;file://$MODULE_DIR$/build/testClasses&quot;/&gt;"/>
							<xt:insert path="/module/component/content" xml="&lt;sourceFolder url=&quot;file://${ivyModuleDir}/src&quot;
isTestSource=&quot;false&quot;/&gt;"/>
							<xt:insert path="/module/component/content" xml="&lt;sourceFolder url=&quot;file://${ivyModuleDir}/test&quot;
isTestSource=&quot;true&quot;/&gt;"/>
							<xt:insert path="/module/component/content" xml="&lt;content url=&quot;file://$MODULE_DIR$/build&quot;&gt;&lt;sourceFolder
url=&quot;file://$MODULE_DIR$/build/generated&quot; isTestSource=&quot;false&quot;/&gt;&lt;/content&gt;"
position="after"/>
						</xt:xmltask>
					</ac:then>
				</ac:if>
				<!--Add library source path-->
				<ac:if>
					<available file="${ivyDependencySourceDir}/@{moduleName}/src"/>
					<ac:then>
						<xt:xmltask source="@{moduleDir}/@{moduleName}.iml" dest="@{moduleDir}/@{moduleName}.iml">
							<xt:insert path="/module/component/orderEntry/library/SOURCES" xml="&lt;root
url=&quot;file://${ivyDependencySourceDir}/@{moduleName}/src&quot;/&gt;"/>
						</xt:xmltask>
					</ac:then>
				</ac:if>
				<!--Insert in dependencies-->
				<ac:var name="ivyModuleFile" unset="true"/>
				<condition property="ivyModuleFile" value="${ivyModuleDir}/ivy.xml" else="${ivyModuleDir}/ivy/ivy.xml">
					<istrue value="@{moduleSandbox}"/>
				</condition>
				<ac:var name="hasIvyDependencies" value="false"/>
				<xt:xmltask source="${ivyModuleFile}">
					<xt:call path="ivy-module/dependencies/dependency">
						<param name="ivyModuleDependencyName" path="@name"/>
						<xt:actions>
							<ac:var name="hasIvyDependencies" value="true"/>
							<xt:xmltask source="@{moduleDir}/@{moduleName}.iml" dest="@{moduleDir}/@{moduleName}.iml">
								<xt:insert path="/module/component" xml="&lt;orderEntry type=&quot;module&quot;
module-name=&quot;@{ivyModuleDependencyName}&quot; exported=&quot;&quot;/&gt;"/>
							</xt:xmltask>
						</xt:actions>
					</xt:call>
				</xt:xmltask>
				<ac:if>
					<isfalse value="${hasIvyDependencies}"/>
					<ac:then>
						<xt:xmltask source="@{moduleDir}/@{moduleName}.iml" dest="@{moduleDir}/@{moduleName}.iml">
							<xt:insert path="/module/component" xml="&lt;orderEntry type=&quot;module&quot;
module-name=&quot;lgcbuild&quot; exported=&quot;&quot;/&gt;"/>
						</xt:xmltask>
					</ac:then>
				</ac:if>
				<echo message="Created IntelliJ IML file: @{moduleDir}/@{moduleName}.iml"/>
			</sequential>
		</macrodef>

---
Shawn Castrianni

-----Original Message-----
From: Raja Nagendra Kumar [mailto:Nagendra.Raja@tejasoft.com] 
Sent: Tuesday, November 03, 2009 4:01 AM
To: user@ant.apache.org
Subject: IDEA Project generation from ant


Hi,

Are there any ant tasks available to generate intellij and/or eclipse
projects from ant target. I wish to provide the needed class and source
paths.

Regards,
Raja Nagendra  Kumar,
C.T.O
www.tejasoft.com
-- 
View this message in context: http://old.nabble.com/IDEA-Project-generation-from-ant-tp26160045p26160045.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org

----------------------------------------------------------------------
This e-mail, including any attached files, may contain confidential and privileged information
for the sole use of the intended recipient.  Any review, use, distribution, or disclosure
by others is strictly prohibited.  If you are not the intended recipient (or authorized to
receive information for the intended recipient), please contact the sender by reply e-mail
and delete all copies of this message.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message