[jboss-cvs] jboss-seam/src/gen/org/jboss/seam/tool ...

Peter Muir peter at bleepbleep.org.uk
Sun Nov 18 15:00:55 EST 2007


  User: pmuir   
  Date: 07/11/18 15:00:55

  Added:       src/gen/org/jboss/seam/tool  EclipseClasspathTask.java
  Log:
  Move eclipse classpath generation to java class and support attaching of sources from maven repo
  
  Revision  Changes    Path
  1.1      date: 2007/11/18 20:00:55;  author: pmuir;  state: Exp;jboss-seam/src/gen/org/jboss/seam/tool/EclipseClasspathTask.java
  
  Index: EclipseClasspathTask.java
  ===================================================================
  package org.jboss.seam.tool;
  
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.File;
  import java.io.FileReader;
  import java.io.FileWriter;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.types.Path;
  
  /**
   * @author Pete Muir
   * 
   */
  public class EclipseClasspathTask extends Task
  {
     private String file;
     private String toFile;
     private String filterProperty;
  
     private List<Path> paths = new ArrayList<Path>();
  
     @Override
     public void execute() throws BuildException
     {
        Path uberPath = new Path(getProject());
        for (Path path : paths)
        {
           uberPath.add(path);
        }
        String eclipsepaths = "";
        
        for (String path : uberPath.list())
        {
           // avoid placing modules on classpath
           if (!path.contains("jboss-seam"))
           {
              String sourcePath = path.substring(0, path.lastIndexOf(".jar")) + "-sources.jar";
              String javadocPath = path.substring(0, path.lastIndexOf(".jar")) + "-javadoc.jar";
              String eclipsepath = "\t<classpathentry kind=\"lib\" path=\""
                    + path + "\"";
              if (new File(sourcePath).exists())
              {
                 eclipsepath += " sourcepath=\"" + sourcePath + "\"";
              }
              
              if (new File(javadocPath).exists())
              {
                 eclipsepath += "\t\t<attributes>\n";
                 eclipsepath += "\t\t\t<attribute name=\"javadoc_location\" value=\"" + javadocPath + "!/\"/>\n";
                 eclipsepath += "\t\t</attributes>\n";
                 eclipsepath += "\t</classpathentry>\n";
              }
              else
              {
                 eclipsepath += "/>\r\n";
              }
              eclipsepaths += eclipsepath;
           }
        }
        try
        {
           BufferedReader reader = new BufferedReader(new FileReader(new File(
                 file)));
           BufferedWriter writer = new BufferedWriter(new FileWriter(new File(
                 toFile)));
           while (reader.ready())
           {
              String line = reader.readLine();
              if (line.contains(filterProperty))
              {
                 line = line.replaceFirst("@" + filterProperty + "@", eclipsepaths);
              }
              writer.write(line + "\r\n");
           }
           writer.flush();
           writer.close();
        } catch (IOException e)
        {
           throw new BuildException(e);
        }
     }
  
     /**
      * @param file the file to set
      */
     public void setFile(String file)
     {
        this.file = file;
     }
  
     /**
      * @param toFile the toFile to set
      */
     public void setToFile(String toFile)
     {
        this.toFile = toFile;
     }
  
     /**
      * @param filterProperty the filterProperty to set
      */
     public void setFilterProperty(String filterProperty)
     {
        this.filterProperty = filterProperty;
     }
  
     public void addPath(Path path)
     {
        paths.add(path);
     }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list