gianugo     2003/02/24 10:41:58

  Modified:    .        contributor.xml
  Added:       tools/eclipse classpath-tmpl.xml make-classpath.xsl project
  Log:
  Another goodie boorowed from Cocoon. Run "ant -f contributor.xml 
eclipse-project" (don't bother trying the included ant: it's missing the 
required xslt task), open Eclipse->New Project->Java->browse to the xml-xindice 
directory->Next and enjoy your automatically created Eclipse project!
  
  Revision  Changes    Path
  1.7       +80 -2     xml-xindice/contributor.xml
  
  Index: contributor.xml
  ===================================================================
  RCS file: /home/cvs/xml-xindice/contributor.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- contributor.xml   15 Feb 2003 23:00:31 -0000      1.6
  +++ contributor.xml   24 Feb 2003 18:41:57 -0000      1.7
  @@ -30,6 +30,8 @@
       <property name="root.dir" value="java"/>
       <property name="jar.dir" value="${root.dir}/lib"/>
       <property name="src.dir" value="${root.dir}/src"/>
  +    <property name="scratchpad.src.dir" value="${root.dir}/scratchpad/src"/>
  +    <property name="scratchpad.jar.dir" value="${root.dir}/scratchpad/lib"/>
       <property name="test.src.dir" value="${root.dir}/tests/src"/>
       <property name="examples.dir" value="${root.dir}/examples"/>
       <property name="bin.dir" value="bin"/>
  @@ -38,6 +40,7 @@
   
       <!-- destination directories -->
       <property name="build.dir" value="build"/>
  +    <property name="build.temp" value="${build.dir}/temp"/>
       <property name="src.build.dir" value="${build.dir}/classes"/>
       <property name="test.build.dir" value="${build.dir}/classes-tests"/>
       <property name="examples.build.dir" 
value="${build.dir}/classes-examples"/>
  @@ -250,4 +253,79 @@
           </pmd>
       </target>
   
  -</project>
  \ No newline at end of file
  +  <!-- Build the Eclipse projects files -->
  +  <target name="eclipse-project" description="Generate the Eclipse project 
files">
  +    <property name="eclipse" value="tools/eclipse"/>
  +
  +    <!-- prepare the various paths that will form the project -->
  +    <path id="srcs">
  +      <!-- main source dir -->
  +      <pathelement path="${src.dir}"/>
  +      <!-- scratchpad source dir -->
  +      <pathelement path="${scratchpad.src.dir}"/>
  +      <!-- unit tests dir -->
  +      <pathelement path="${test.src.dir}"/>
  +      <!-- examples (guide) dir -->
  +      <pathelement path="${examples.dir}/guide/src"/>
  +      <!-- examples (Addressbook) dir -->
  +      <pathelement path="${examples.dir}/Addressbook/src/java"/>
  +    </path>
  +
  +    <path id="libs">
  +      <!-- main libs -->
  +      <fileset dir="${jar.dir}">
  +        <include name="*.jar"/>
  +      </fileset>
  +      <!-- scratchpad libs -->
  +      <fileset dir="${scratchpad.jar.dir}">
  +        <include name="*.jar"/>
  +      </fileset>
  +    </path>
  +
  +    <!-- convert paths to properties -->
  +    <property name="srcs" refid="srcs"/>
  +    <property name="libs" refid="libs"/>
  +
  +    <!-- expand properties in the template file -->
  +    <copy file="${eclipse}/classpath-tmpl.xml"
  +          tofile="${build.temp}/classpath-temp.xml"
  +          filtering="yes"
  +          overwrite="yes">
  +      <filterset>
  +        <filter token="SRC_DIRS" value="${srcs}"/>
  +        <filter token="LIBS" value="${libs}"/>
  +      </filterset>
  +    </copy>
  +
  +    <!-- split the path in 'item' XML elements -->
  +    <replace file="${build.temp}/classpath-temp.xml"
  +             token="${path.separator}" value="&lt;/item&gt;&#xA; 
&lt;item&gt;"/>
  +    <!-- relativize file names by removing the current directory -->
  +    <replace file="${build.temp}/classpath-temp.xml"
  +             token="${user}${file.separator}" value=""/>
  +    <!-- and in case that fails, remove the base directory -->
  +    <replace file="${build.temp}/classpath-temp.xml"
  +             token="${basedir}${file.separator}" value=""/>
  +
  +    <!-- replace platform-dependent path separator by '/' -->
  +    <replace file="${build.temp}/classpath-temp.xml"
  +             token="${file.separator}" value="/"/>
  +
  +    <!-- now build the .classpath file -->
  +    <xslt in="${build.temp}/classpath-temp.xml" out="${basedir}/.classpath"
  +          processor="trax" 
  +          style="${eclipse}/make-classpath.xsl"/>
  +
  +    <!-- copy the project file (expand version) -->
  +    <copy file="${eclipse}/project"
  +          tofile="${basedir}/.project"
  +          overwrite="yes">
  +      <filterset>
  +        <filter token="VERSION" value="${project.version}"/>
  +      </filterset>
  +    </copy>
  +
  +    <delete file="${build.temp}/classpath-temp.xml"/>
  +  </target>
  +
  +</project>
  
  
  
  1.1                  xml-xindice/tools/eclipse/classpath-tmpl.xml
  
  Index: classpath-tmpl.xml
  ===================================================================
  <?xml version="1.0"?>
  <data>
    <src-dirs><item>@SRC_DIRS@</item></src-dirs>
    <libs><item>@LIBS@</item></libs>
  </data>
  
  
  
  1.1                  xml-xindice/tools/eclipse/make-classpath.xsl
  
  Index: make-classpath.xsl
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!--
    Build the Eclipse .classpath file from a list of path items
    (see "eclipse-project" target in build.xml)
    
    @author Sylvain Wallez
    @version CVS $Id: make-classpath.xsl,v 1.1 2003/02/24 18:41:57 gianugo Exp $
  -->
  
  <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  
    <xsl:output indent="yes" method="xml"/>
  
    <xsl:strip-space elements="*"/>
  
    <xsl:template match="/data">
      <classpath>
        <!-- 1. source dirs -->
        <xsl:for-each select="src-dirs/item">
          <classpathentry kind="src" path="{.}"/>
        </xsl:for-each>
       
        <!-- 2. libraries -->
        <xsl:for-each select="libs/item">
          <classpathentry kind="lib" path="{.}"/>
        </xsl:for-each>
       
        <!-- 3. mock classes -->
        <xsl:for-each select="mock-dirs/item">
          <classpathentry kind="src" path="{.}"/>
        </xsl:for-each>
       
        <!-- 4. JRE runtime -->
        <classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" 
sourcepath="JRE_SRC"/>
       
        <!-- output directory. Build in a separate dir since Eclipse is 
confused by classes
             compiled externally by Sun's Javac -->
        <classpathentry kind="output" path="build/eclipse/classes"/>
  
      </classpath>
    </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.1                  xml-xindice/tools/eclipse/project
  
  Index: project
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <projectDescription>
        <name>Xindice @VERSION@</name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
                <buildCommand>
                        <name>org.eclipse.jdt.core.javabuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
        </buildSpec>
        <natures>
                <nature>org.eclipse.jdt.core.javanature</nature>
        </natures>
  </projectDescription>
  
  
  

Reply via email to