[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[virgo-dev] Build System and .classpath files

Hi,
 We had the same issues here but we modified the then "spring-build" to
include a "eclipse" target which uses ant/ivy to resolve the
dependencies and update the .classpath files for eclipse. At the our
root level build (build-all) we can iterate all the sub-bundles and
update the .classpath files.

It did mean adding a new "task" into the ivy.jar that was present in the
spring-build/lib directory. This was un-jar'd, goto the folder
org/apache/ivy/ant, new class added, antlib.xml updated to reflect the
new EclipseClasspath class, and re-jar'd again.

I would have to look for the java file for the EclipseClasspath but in
the meantime, I have attached the decompiled version of it.
(EclipseClasspath.jad). It was build agains't the ivy jar we had so
there was not much problems getting it to a class file.

The antlib.xml file in the ivy.jar was updated to include this :

       <taskdef name="eclipse"
classname="org.apache.ivy.ant.EclipseClasspath"/>


Then some slight modification in the spring-build/common/common.xml to
add a new target:

        <!-- Generate Eclipse .classpath file from ivy dependencies -->
        <target name="eclipse" description="Updates eclipse classpath."
depends="ivy.init">
                <ivy:resolve  conf="test" />
                <ivy:eclipse  conf="test" />
        </target>

At this point you can add this as a "depends" to other more complex
targets. So for us this works quite well, the developers are used to
"ant clean eclipse jar" and so into the GUIs they go. Of course,
everywhere you see spring-build start to think virgo-build.

Hope it helps,

~Patsy



> It's even worse than that: we also index into the ivy cache in Eclipse
> .classpath files and in some tests, for example
> org.eclipse.virgo.web.test.SpringWebFlowWarTests in Virgo web.
>


// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   EclipseClasspath.java

package org.apache.ivy.ant;

import java.io.*;
import java.util.*;
import java.util.regex.Pattern;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.ivy.core.module.descriptor.Artifact;
import org.apache.ivy.core.report.ArtifactDownloadReport;
import org.apache.ivy.util.Message;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.DOMElementWriter;
import org.apache.tools.ant.util.FileUtils;
import org.w3c.dom.*;

// Referenced classes of package org.apache.ivy.ant:
//            IvyCacheTask

public class EclipseClasspath extends IvyCacheTask
{

    public EclipseClasspath()
    {
        sourceType = "sources";
        classpathFile = ".classpath";
    }

    public void doExecute()
        throws BuildException
    {
        FileWriter filewriter;
        prepareAndCheck();
        filewriter = null;
        try
        {
            HashMap hashmap = new HashMap();
            HashMap hashmap1 = new HashMap();
            ArtifactDownloadReport artifactdownloadreport;
            String s;
            for(Iterator iterator = getArtifactReports().iterator(); iterator.hasNext(); Message.verbose((new StringBuilder()).append("Artifact ").append(s).append(": ").append(artifactdownloadreport.getLocalFile()).toString()))
            {
                artifactdownloadreport = (ArtifactDownloadReport)iterator.next();
                s = artifactdownloadreport.getArtifact().getName();
                if(artifactdownloadreport.getType().equals(sourceType))
                    hashmap1.put(s, artifactdownloadreport.getLocalFile());
                else
                    hashmap.put(s, artifactdownloadreport.getLocalFile());
            }

            File file = new File(classpathFile);
            DocumentBuilderFactory documentbuilderfactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder documentbuilder = documentbuilderfactory.newDocumentBuilder();
            Document document = documentbuilder.parse(file);
            Element element = document.getDocumentElement();
            for(Node node = element.getFirstChild(); node != null;)
                if((node instanceof Element) && ((Element)node).getTagName().equals("classpathentry") && Boolean.parseBoolean(((Element)node).getAttribute("ivygen")))
                {
                    Node node1 = node;
                    node = node.getNextSibling();
                    element.removeChild(node1);
                } else
                if((node instanceof Text) && Pattern.matches("\\s+", node.getTextContent()))
                {
                    Node node2 = node;
                    node = node.getNextSibling();
                    element.removeChild(node2);
                } else
                {
                    node = node.getNextSibling();
                }

            Element element1;
            for(Iterator iterator1 = hashmap.entrySet().iterator(); iterator1.hasNext(); element.appendChild(element1))
            {
                java.util.Map.Entry entry = (java.util.Map.Entry)iterator1.next();
                String s1 = (String)entry.getKey();
                element1 = document.createElement("classpathentry");
                element1.setAttribute("ivygen", "true");
                element1.setAttribute("kind", "lib");
                element1.setAttribute("path", ((File)entry.getValue()).getAbsolutePath());
                File file2 = (File)hashmap1.get(s1);
                if(file2 != null)
                    element1.setAttribute("sourcepath", file2.getAbsolutePath());
            }

            FileUtils fileutils = FileUtils.newFileUtils();
            File file1 = fileutils.createTempFile("ivygen-", ".classpath", getProject().getBaseDir());
            filewriter = new FileWriter(file1);
            DOMElementWriter domelementwriter = new DOMElementWriter();
            filewriter.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
            domelementwriter.write(element, filewriter, 0, "\t");
            fileutils.copyFile(file1, file);
            file1.delete();
        }
        catch(Exception exception)
        {
            throw new BuildException("Unable to generate Eclipse classpath:", exception);
        }
        try
        {
            if(filewriter != null)
                filewriter.close();
        }
        catch(IOException ioexception) { }
        break MISSING_BLOCK_LABEL_606;
        Exception exception1;
        exception1;
        try
        {
            if(filewriter != null)
                filewriter.close();
        }
        catch(IOException ioexception1) { }
        throw exception1;
    }

    protected void prepareAndCheck()
    {
        super.prepareAndCheck();
        classpathFile = (new StringBuilder()).append(getProject().getBaseDir()).append("/").append(classpathFile).toString();
    }

    public String getSourceType()
    {
        return sourceType;
    }

    public void setSourceType(String s)
    {
        sourceType = s;
    }

    public String getClasspathFile()
    {
        return classpathFile;
    }

    public void setClasspathFile(String s)
    {
        classpathFile = s;
    }

    private static final String ATTR_IVYGEN = "ivygen";
    private static final String TAG_CLASSPATH_ENTRY = "classpathentry";
    private String sourceType;
    private String classpathFile;
}