JBuilder.java :  » IDE » tIDE » tide » importtools » Java Open Source

Java Open Source » IDE » tIDE 
tIDE » tide » importtools » JBuilder.java
package tide.importtools;

import java.io.*;
import java.util.*;
import tide.project.ProjectSettings;
import snow.utils.storage.*;
import javax.swing.JOptionPane;

/** Imports JBuilder 2 project files.
*  Missing: libraries paths !! (??)
*/
public final class JBuilder
{
   public static String fileNameEnding = ".jpr";
   final private File base;
   private final Map<String, String> map = new HashMap<String, String>();

   public JBuilder(File projFile, ProjectSettings proj) throws Exception
   {
      this.base = projFile.getParentFile();

      FileReader fr = new FileReader(projFile);
      BufferedReader br = new BufferedReader(fr);
      String line = null;
      while((line= br.readLine())!=null)
      {

         if(line.startsWith(";"))
         {
            System.out.println(""+line);
         }
         else
         {
            int pos = line.indexOf('=');
            if(pos>0)
            {
              String key = line.substring(0,pos);
              String val = line.substring(pos+1);

              map.put(key, val);

              if(key.startsWith("sys[0]."))
              {
                 System.out.println(""+key+":: "+val);
              }
            }
            else
            {
               System.out.println("Bad syntax: "+line);
            }
         }


      }

      //System.out.println("Sources home = "+getAbsFile(map.get("sys[0].SourcePath")));

      if(proj!=null)
      {
         proj.setSources_Home( getAbsFile(map.get("sys[0].SourcePath")));
         proj.setMainSourceFile( getAbsFile(map.get("sys[0].DefaultRunnablePath")));
         proj.setRuntimeArgs( map.get( "sys[0].JavaVmParameters" ));
         proj.setClasses_Home(getAbsFile(map.get("sys[0].OutPath")));
         proj.setProjectName( projFile.getName() );

         String libs = map.get("sys[0].Libraries");
         if(libs!=null && libs.length()>0)
         {
           JOptionPane.showMessageDialog(null,"Please add the paths to the libraries\n   "+libs+"\nin the project settings");
         }
      }
   }

   private File getAbsFile(String relName)
   {
      File af = new File(base, relName);
      try
      {
         af = af.getCanonicalFile();
      }
      catch(Exception ignore) {}
      return af;
   }

/*test
   public static void main(String[] args) throws Exception
   {
      new JBuilder(new File("c:/temp/PortListener.jpr"), null);
   }*/

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.