Inheritance: FanObj
Beispiel #1
0
        internal ZipOutputStream m_zipOut; // write only

        #endregion Fields

        #region Constructors

        private Zip(File f)
        {
            try
              {
            // only support local files
            if (!(f is LocalFile))
              throw IOErr.make("Only local files supported: " + f).val;

            // open the file
            this.m_file = (LocalFile)f;
            this.m_zipFile = new ZipFile(m_file.m_file.FullName);
              }
              catch (System.Exception e)
              {
            // NOTE: use ctor instead of make() to force type == IOErr
            throw new IOErr(e).val;
              }
        }
Beispiel #2
0
        static Map readDef(Pod pod, Uri uri)
        {
            uri = Uri.fromStr(pod.uri() + "/" + uri);
            Fan.Sys.File f   = (Fan.Sys.File)pod.file(uri, false);
            Map          map = Sys.m_emptyStrStrMap;

            try
            {
                if (f != null)
                {
                    map = (Map)f.readProps().toImmutable();
                }
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine("ERROR: Cannot load props " + pod + "::" + uri);
                System.Console.WriteLine("  " + e);
            }
            return(map);
        }
Beispiel #3
0
        //////////////////////////////////////////////////////////////////////////
        // Public
        //////////////////////////////////////////////////////////////////////////
        public Type compile(File file, Map options)
        {
            // normalize the file path as our cache key
              file = file.normalize();

              // unless force=true, check the cache
              if (!getOption(options, m_strForce, false))
              {
            CachedScript c = getCache(file);

            // if cached, try to lookup type (it might have been GCed)
            if (c != null)
            {
              Type t1 = Type.find(c.typeName, false);
              if (t1 != null) return t1;
            }
              }

              // generate a unique pod name
              string podName = generatePodName(file);

              // compile the script
              Pod pod = compile(podName, file, options);

              // get the primary type
              List types = pod.types();
              Type t = null;
              for (int i=0; i<types.sz(); ++i)
              {
            t = (Type)types.get(i);
            if (t.isPublic()) break;
              }
              if (t == null)
            throw Err.make("Script file defines no public classes: " +  file).val;

              // put it into the cache
              putCache(file, t);

              return t;
        }
Beispiel #4
0
 string cacheKey(File f)
 {
     return f.toStr();
 }
Beispiel #5
0
        void putCache(File file, Type t)
        {
            CachedScript c = new CachedScript();
              c.modified = file.modified();
              c.size     = file.size();
              c.typeName = t.qname();

              lock (m_cache) { m_cache[cacheKey(file)] = c; }
        }
Beispiel #6
0
        //////////////////////////////////////////////////////////////////////////
        // CachedScript
        //////////////////////////////////////////////////////////////////////////
        CachedScript getCache(File file)
        {
            lock (m_cache)
              {
            // check cache
            string key = cacheKey(file);
            CachedScript c = (CachedScript)m_cache[key];
            if (c == null) return null;

            // check that timestamp and size still the same
            if (OpUtil.compareEQ(c.modified, file.modified()) &&
            OpUtil.compareEQ(c.size, file.size()))
              return c;

            // nuke from cache
            m_cache.Remove(key);
            return null;
              }
        }
Beispiel #7
0
 public override File moveTo(File to)
 {
     throw IOErr.make("ZipEntryFile is readonly").val;
 }
Beispiel #8
0
        public override File moveTo(File to)
        {
            if (isDir() != to.isDir())
              {
            if (isDir())
              throw ArgErr.make("moveTo must be dir `" + to + "`").val;
            else
              throw ArgErr.make("moveTo must not be dir `" + to + "`").val;
              }

              if (!(to is LocalFile))
            throw IOErr.make("Cannot move LocalFile to " + to.@typeof()).val;
              LocalFile dest = (LocalFile)to;

              if (dest.exists())
            throw IOErr.make("moveTo already exists: " + to).val;

              try
              {
            if (m_file is FileInfo)
              (m_file as FileInfo).MoveTo((dest.m_file as FileInfo).FullName);
            else
              (m_file as DirectoryInfo).MoveTo((dest.m_file as DirectoryInfo).FullName);
              }
              catch (System.IO.IOException)
              {
            throw IOErr.make("moveTo failed: " + to).val;
              }

              return to;
        }
Beispiel #9
0
 public virtual Type compileScript(File file, Map options)
 {
     return m_scripts.compile(file, options);
 }
Beispiel #10
0
 public static Process make(List command, File dir)
 {
     return new Process(command, dir);
 }
Beispiel #11
0
 private Process(List command, File dir)
 {
     this.command(command);
       this.dir(dir);
 }
Beispiel #12
0
 public void dir(File v)
 {
     checkRun();
       if (v != null && (!v.exists() || !v.isDir()))
     throw ArgErr.make("Invalid working directory: " + v).val;
       this.m_dir = v;
 }
Beispiel #13
0
 //////////////////////////////////////////////////////////////////////////
 // Construction
 //////////////////////////////////////////////////////////////////////////
 public static Zip open(File file)
 {
     return new Zip(file);
 }
Beispiel #14
0
 private Pod compile(string podName, File f, Map options)
 {
     // use Fantom reflection to run compiler::Main.compileScript(File)
       Method m = Slot.findMethod("compiler::Main.compileScript", true);
       return (Pod)m.call(podName, f, options);
 }
Beispiel #15
0
Datei: Test.cs Projekt: xored/f4
 //////////////////////////////////////////////////////////////////////////
 // Utils
 //////////////////////////////////////////////////////////////////////////
 public File tempDir()
 {
     if (m_tempDir == null)
       {
     m_tempDir = Env.cur().tempDir().plus(Uri.fromStr("test/"), false);
     m_tempDir.delete();
     m_tempDir.create();
       }
       return m_tempDir;
 }
Beispiel #16
0
 //////////////////////////////////////////////////////////////////////////
 // Utils
 //////////////////////////////////////////////////////////////////////////
 private string generatePodName(File f)
 {
     string bse = f.basename();
       StringBuilder s = new StringBuilder(bse.Length+6);
       for (int i=0; i<bse.Length; ++i)
       {
     int c = bse[i];
     if ('a' <= c && c <= 'z') { s.Append((char)c); continue; }
     if ('A' <= c && c <= 'Z') { s.Append((char)c); continue; }
     if (i > 0 && '0' <= c && c <= '9') { s.Append((char)c); continue; }
       }
       lock (m_counterLock) { s.Append('_').Append(m_counter++); }
       return s.ToString();
 }
Beispiel #17
0
 //////////////////////////////////////////////////////////////////////////
 // State
 //////////////////////////////////////////////////////////////////////////
 public virtual Type compileScript(File file)
 {
     return compileScript(file, null);
 }