[kepler-code] r28771 - in trunk/modules/build-area: src/org/kepler/build/ide target

crawl at ecoinformatics.org crawl at ecoinformatics.org
Fri Oct 7 12:00:12 PDT 2011


Author: crawl
Date: 2011-10-07 12:00:12 -0700 (Fri, 07 Oct 2011)
New Revision: 28771

Modified:
   trunk/modules/build-area/src/org/kepler/build/ide/Eclipse.java
   trunk/modules/build-area/target/kepler-tasks.jar
Log:
use settings/ptolemy-excludes for eclipse exclusion list
exporting $PTII/lib jars so duplicates do not have to be in ptolemy/lib
do not use BuidClassPath/BuildProject to make build-area .project & .classpath


Modified: trunk/modules/build-area/src/org/kepler/build/ide/Eclipse.java
===================================================================
--- trunk/modules/build-area/src/org/kepler/build/ide/Eclipse.java	2011-10-07 18:46:05 UTC (rev 28770)
+++ trunk/modules/build-area/src/org/kepler/build/ide/Eclipse.java	2011-10-07 19:00:12 UTC (rev 28771)
@@ -31,11 +31,17 @@
 import org.kepler.build.project.LibPath;
 import org.kepler.build.project.ProjectLocator;
 
+import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * Clean generated eclipse files
@@ -45,19 +51,8 @@
  */
 public class Eclipse extends Ide
 {
-    private File eclipseDir;
 
     /**
-     * init the task
-     */
-    public void init()
-    {
-        super.init();
-        eclipseDir = new File(getProject().getBaseDir(),
-                "build-area/resources/eclipse");
-    }
-
-    /**
      * run the task
      */
     public void run() throws Exception
@@ -71,48 +66,29 @@
             makeProjectFile(module);
             makeClasspathFile(module);
         }
-        makeBuildFiles();
+        
+        // create .project and .classpath for build-area
+        Module buildModule = Module.make("build-area");
+        makeProjectFile(buildModule);
+        makeClasspathFile(buildModule);
     }
 
     /**
-     * make build files
-     */
-    private void makeBuildFiles()
-    {
-        makeBuildProjectFile();
-        makeBuildClasspathFile();
-    }
-
-    /**
-     * make a project file for the build
-     */
-    private void makeBuildProjectFile()
-    {
-        File projectFile = new File(basedir, "build-area/.project");
-        PrintWriter pw = FileMerger.getPrintWriter(projectFile);
-        File mainProject = new File(eclipseDir, "BuildProject");
-        FileMerger.merge(mainProject, pw);
-        pw.close();
-        System.out.println("Writing " + projectFile);
-    }
-
-    /**
-     * make a classpath file for the build
-     */
-    private void makeBuildClasspathFile()
-    {
-        this.makeClasspathFile(Module.make("build-area"));
-    }
-
-    /**
      * make a project file for a module
      */
     private void makeProjectFile(Module module)
     {
+        // XXX why is build-area called something else?
+        String name = module.toString();
+        if(name.equals("build-area"))
+        {
+            name = "_kepler.build";
+        }
+        
         File projectFile = new File(module.getDir(), ".project");
         PrintWriter pw = FileMerger.getPrintWriter(projectFile);
         pw.println("<projectDescription>");
-        pw.println("  <name>" + module + "</name>");
+        pw.println("  <name>" + name + "</name>");
         pw.println("  <projects/>");
         pw.println("  <buildSpec>");
         pw.println("    <buildCommand>");
@@ -132,9 +108,10 @@
      */
     private void makeClasspathFile(Module module)
     {
+
         String moduleName = module.getName();
         String versionSuffix = "-\\d+\\.\\d+(\\.\\d+)?";
-        if (moduleName.equals(Module.PTOLEMY) || 
+        if (moduleName.equals(Module.PTOLEMY) ||
             moduleName.matches(Module.PTOLEMY+versionSuffix) ||
             moduleName.matches(Module.PTOLEMY_KEPLER+versionSuffix))
         {
@@ -147,6 +124,7 @@
             makeCommonClasspathFile(module);
             return;
         }
+
         File src = module.getSrc();
         File testsSrc = module.getTestsSrc();
         File resources = module.getResourcesDir();
@@ -279,9 +257,52 @@
     {
         File classpathFile = new File(module.getDir(), ".classpath");
         PrintWriter pw = FileMerger.getPrintWriter(classpathFile);
-        File ptolemyClasspathStart = new File(eclipseDir, "PtolemyClasspathStart");
-        FileMerger.merge(ptolemyClasspathStart, pw);
-
+   
+        // write the header
+        pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+        pw.println("<classpath>");
+        pw.println("    <classpathentry kind=\"con\" path=\"org.eclipse.jdt.launching.JRE_CONTAINER\"/>");
+        
+        
+        // add excludes
+        final File excludesFile = new File(basedir, "build-area/settings/ptolemy-excludes");
+        BufferedReader reader = null;
+        
+        try
+        {
+            reader = new BufferedReader(new FileReader(excludesFile));
+        }
+        catch(FileNotFoundException e)
+        {
+            System.err.println("Could not find ptolemy-excludes file.\n" + e.getMessage());
+        }
+        
+        if(reader != null)
+        {
+            pw.print("  <classpathentry excluding=\"**/*.c|**/*.class|**/*.htm|**/*.html" +
+                "|**/*.jnlp|**/*.tcl|**/*svn*|**/*svn-base|**/README.txt|" +
+                "**/makefile");
+            
+            // read the ptolemy-excludes file
+            try
+            {
+                String line = reader.readLine();
+                while(line != null)
+                {
+                    pw.print("|" + line.replaceAll("\n", ""));
+                    line = reader.readLine();
+                }
+                reader.close();
+            }
+            catch(IOException e)
+            {
+                System.err.println("Error reading ptolemy-excludes file: " + e.getMessage());
+            }       
+            
+            pw.println("\" including=\"com/|diva/|ptolemy/|util/|org/\" kind=\"src\" path=\"src\"/>");
+        }
+                
+        // add the jars in ptolemy/src/lib/
         File srcFile = module.getSrc();
         File srcLibFile = new File(srcFile, "lib");
         FileSet srcLibJarFileset = new FileSet();
@@ -289,16 +310,22 @@
         srcLibJarFileset.setDir(srcLibFile);
         srcLibJarFileset.setIncludes("**/*.jar");
 
-        Iterator<FileResource> i = srcLibJarFileset.iterator();
+        Iterator<?> i = srcLibJarFileset.iterator();
         while (i.hasNext())
         {
-            FileResource fr = i.next();
+            FileResource fr = (FileResource) i.next();
             String fn = fr.getFile().getName();
-            pw.println("\t<classpathentry kind=\"lib\" path=\"src/lib/" + fn + "\"/>");
+            pw.println("\t<classpathentry exported=\"true\" kind=\"lib\" path=\"src/lib/" + fn + "\"/>");
         }
+        
+        // add any jars in ptolemy/lib/
+        printJarEntries(pw, module);
+        
+        // write the footer
+        pw.println("    <classpathentry kind=\"output\" path=\"target/eclipse/classes\"/>");
+        pw.println("</classpath>");
 
-        File ptolemyClasspathEnd = new File(eclipseDir, "PtolemyClasspathEnd");
-        FileMerger.merge(ptolemyClasspathEnd, pw);
+        
         pw.close();
         System.out.println("Writing " + classpathFile);
     }
@@ -333,7 +360,20 @@
         while (i.hasNext())
         {
             File jar = i.next().getFile();
-            printJarEntry(pw, module, jar);
+            
+            // do not add swt jar to classpath since eclipse comes with its own
+            // version of swt, and adding it causes problems.
+            // XXX this may only be a problem on Mac.
+            Matcher matcher = SWT_PATTERN.matcher(jar.getName());
+            if(matcher.matches())
+            {
+                System.out.println("WARNING: not adding " + jar.getPath() + 
+                    " to class the path since it appears to be an SWT jar.");
+            }
+            else
+            {
+                printJarEntry(pw, module, jar);
+            }
         }
     }
 
@@ -434,4 +474,8 @@
         }
         return excludes.toString();
     }
+    
+    /** Regex to match swt jar. */
+    private final static Pattern SWT_PATTERN = Pattern.compile("swt.*\\.jar");
+
 }

Modified: trunk/modules/build-area/target/kepler-tasks.jar
===================================================================
(Binary files differ)



More information about the Kepler-cvs mailing list