Package flex2.compiler.util

Examples of flex2.compiler.util.Benchmark$BenchmarkText


      {
        Class retType = info.getGetterMethod().getReturnType();

        if (VirtualFile.class.isAssignableFrom(retType))
        {
          VirtualFile file = (VirtualFile) info.getGetterMethod().invoke(targetConfig, (Object[])null);
          if (file != null)
          {
            if (info.doChecksum())
              compile_checksum.append(file.getName());
            link_checksum.append(file.getName());
          }
          continue;
        }
        else if (retType.isArray() && VirtualFile.class.isAssignableFrom(retType.getComponentType()))
        {
          VirtualFile[] files = (VirtualFile[]) info.getGetterMethod().invoke(targetConfig, (Object[])null);
          for (int j = 0; files != null && j < files.length; j++)
          {
            if (files[j] != null)
            {
              if (info.doChecksum())
                compile_checksum.append(files[j].getName());
              link_checksum.append(files[j].getName());
            }
          }
          continue;
        }
      }

      if (args[i] instanceof Object[])
      {
        Object[] a = (Object[]) args[i];
        for (int j = 0; j < a.length; j++)
        {
          if (info.doChecksum())
            compile_checksum.append(a[j]);
          link_checksum.append(a[j]);
        }
      }
      else if (args[i] instanceof List)
      {
        List l = (List) args[i];
        for (int j = 0; j < l.size(); j++)
        {
          if (info.doChecksum())
            compile_checksum.append(l.get(j));
          link_checksum.append(l.get(j));
        }
      }
      else
      {
        if (info.doChecksum())
          compile_checksum.append(args[i]);
        link_checksum.append(args[i]);
      }
    }

    if (info.getGetterMethod() == null)
    {
      // C: need to make sure that all the VirtualFile-based config values should have getters.
      return;
    }

    Class retType = info.getGetterMethod().getReturnType();

    if (VirtualFile.class.isAssignableFrom(retType))
    {
      VirtualFile file = (VirtualFile) info.getGetterMethod().invoke(targetConfig, (Object[])null);
      if (file != null && !file.isDirectory())
      {
        if (info.doChecksum())
          compile_checksum_ts.append(file.getLastModified());
        link_checksum_ts.append(file.getLastModified());
      }
    }
    else if (retType.isArray() && VirtualFile.class.isAssignableFrom(retType.getComponentType()))
    {
      VirtualFile[] files = (VirtualFile[]) info.getGetterMethod().invoke(targetConfig, (Object[])null);
View Full Code Here


    /**
     * Create virtual file for given file and throw configuration exception if not possible
     */
    public static VirtualFile getVirtualFile(String path, boolean reportError) throws ConfigurationException
    {
        VirtualFile result = null;
        File file = new File(path);

        if (file != null && file.exists())
        {
            try
View Full Code Here

    {
            // No need to check to see if the appPath is supported again.
      if ((appPath != null && files[i].getName().equals(appPath.getName())) || isSupported(files[i]))
      {
        String name = files[i].getName();
        VirtualFile pathRoot = calculatePathRoot(files[i]);
        if (pathRoot != null)
        {
                    String relativePath = calculateRelativePath(name);
                    String namespaceURI = relativePath.replace('/', '.');
                    String localPart = calculateLocalPart(name);
View Full Code Here

        standardDefs.set(defs);
    }

    public static StandardDefs getStandardDefs()
    {
        StandardDefs defs = standardDefs.get();
        if (defs == null)
        {
            defs = StandardDefs.getStandardDefs("halo");
            setStandardDefs(defs);
        }
View Full Code Here

    }

    public static void mxmlc(String[] args)
    {
        Transcoder[] transcoders = null;
        Benchmark benchmark = null;

        try
        {
            CompilerAPI.useAS3();

            // setup the path resolver
            CompilerAPI.usePathResolver();

            // set up for localizing messages
            LocalizationManager l10n = new LocalizationManager();
            l10n.addLocalizer( new XLRLocalizer() );
            l10n.addLocalizer( new ResourceBundleLocalizer() );
            ThreadLocalToolkit.setLocalizationManager(l10n);

            // setup the console logger. the configuration parser needs a logger.
            CompilerAPI.useConsoleLogger();

            // process configuration
            ConfigurationBuffer cfgbuf = new ConfigurationBuffer(CommandLineConfiguration.class, Configuration.getAliases());

            // Do not set this.  The file-specs should be included in the configuration buffer
            // checksum so changes to the class list can be detected during incremental builds.
            //cfgbuf.setDefaultVar(FILE_SPECS);
            DefaultsConfigurator.loadDefaults( cfgbuf );
            CommandLineConfiguration configuration = (CommandLineConfiguration) processConfiguration(
                l10n, "mxmlc", args, cfgbuf, CommandLineConfiguration.class, FILE_SPECS);

            // well, setup the logger again now that we know configuration.getWarnings()???
            CompilerAPI.useConsoleLogger(true, true, configuration.getWarnings(), true);
            CompilerAPI.setupHeadless(configuration);

            if (configuration.benchmark())
            {
                benchmark = CompilerAPI.runBenchmark();
                benchmark.startTime(Benchmark.PRECOMPILE);
            }
            else
            {
                CompilerAPI.disableBenchmark();
            }

            // make sure targetFile abstract pathname is an absolute path...
            VirtualFile targetFile = CompilerAPI.getVirtualFile(configuration.getTargetFile());
            WebTierAPI.checkSupportedTargetMimeType(targetFile);

            // mxmlc only wants to take one file.
            List<String> fileList = configuration.getFileList();
            if (fileList == null || fileList.size() != 1)
            {
                throw new ConfigurationException.OnlyOneSource( "filespec", null, -1);
            }

            List<VirtualFile> virtualFileList = CompilerAPI.getVirtualFileList(fileList);

            CompilerConfiguration compilerConfig = configuration.getCompilerConfiguration();
            NameMappings mappings = CompilerAPI.getNameMappings(configuration);

            // create a FileSpec... can reuse based on targetFile, debug settings, etc...
            FileSpec fileSpec = new FileSpec(Collections.<VirtualFile>emptyList(), WebTierAPI.getFileSpecMimeTypes());

            // create a SourcePath...
            VirtualFile[] asClasspath = compilerConfig.getSourcePath();
            SourceList sourceList = new SourceList(virtualFileList,
                                                   asClasspath,
                                                   targetFile,
                                                   WebTierAPI.getSourcePathMimeTypes());
            SourcePath sourcePath = new SourcePath(asClasspath,
                                                   targetFile,
                                                   WebTierAPI.getSourcePathMimeTypes(),
                                                   compilerConfig.allowSourcePathOverlap());

            ResourceContainer resources = new ResourceContainer();
            ResourceBundlePath bundlePath = new ResourceBundlePath(configuration.getCompilerConfiguration(), targetFile);

            ArrayList<Source> sources = new ArrayList<Source>();
            List<CompilationUnit> units = new ArrayList<CompilationUnit>();

            if (benchmark != null)
            {
                benchmark.benchmark(l10n.getLocalizedTextString(new InitialSetup()));
            }

            // load SWCs
            CompilerSwcContext swcContext = new CompilerSwcContext();
            SwcCache cache = new SwcCache();
           
            // lazy read should only be set by mxmlc/compc
            cache.setLazyRead(true);

            swcContext.load( compilerConfig.getLibraryPath(),
                             Configuration.getAllExcludedLibraries(compilerConfig, configuration),
                             compilerConfig.getThemeFiles(),
                             compilerConfig.getIncludeLibraries(),
                             mappings,
                             I18nUtils.getTranslationFormat(compilerConfig),
                             cache );
            configuration.addExterns( swcContext.getExterns() );
            configuration.addIncludes( swcContext.getIncludes() );
            configuration.getCompilerConfiguration().addThemeCssFiles( swcContext.getThemeStyleSheets() );

            // Figure out the name of the output file.
            File outputFile = getOutputFile(configuration, targetFile);

            // Checksums to figure out if incremental compile can be done.
            String incrementalFileName = null;
            SwcChecksums swcChecksums = null;

            // Should we attempt to build incrementally using the incremental file?
            boolean recompile = true;

            // If incremental compilation is enabled and the output file exists,
            // use the persisted store to figure out if a compile/link is necessary.
            // link without a compile is not supported without changes to the
            // persistantStore since units for Sources of type isSwcScriptOwner()
            // aren't stored/restored properly. units contains null entries for those
            // type of Source.  To force a rebuild, with -incremental specified, delete the
            // incremental file.
            if (configuration.getCompilerConfiguration().getIncremental())
            {
                swcChecksums = new SwcChecksums(swcContext, cfgbuf, configuration);

                // If incremental compilation is enabled, read the cached
                // compilation units...  Do not include the checksum in the file name so that
                // cache files don't pile up as the configuration changes.  There needs
                // to be a 1-to-1 mapping between the swc file and the cache file.
                incrementalFileName = outputFile.getPath() + ".cache";

                // If the output file doesn't exist don't bother loading the
                // cache since a recompile is needed.
                if (outputFile.exists())
                {
                    RandomAccessFile incrementalFile = null;
                    try
                    {
                        incrementalFile = new RandomAccessFile(incrementalFileName, "r");

                        // For loadCompilationUnits, loadedChecksums[1] must match
                        // the cached value else IOException is thrown.
                        int[] loadedChecksums = swcChecksums.copy();

                        CompilerAPI.loadCompilationUnits(configuration, fileSpec, sourceList, sourcePath, resources, bundlePath, null, /* sources */
                        null, /*units */
                        loadedChecksums, swcChecksums.getSwcDefSignatureChecksums(), swcChecksums.getSwcFileChecksums(), null, /* archiveFiles */
                        incrementalFile, incrementalFileName, null /* font manager */);

                        if (!(swcChecksums.isRecompilationNeeded(loadedChecksums) && !swcChecksums.isRelinkNeeded(loadedChecksums)))
                        {
                            recompile = false;
                        }
                    }
                    catch (FileNotFoundException ex)
                    {
                            // the incremental file doesn't exist
                            ThreadLocalToolkit.logDebug(ex.getLocalizedMessage());
                    }
                    catch (IOException ex)
                    {
                        // error loading the incremental file - most likely checksum
                        // mismatch or format mismatch
                        ThreadLocalToolkit.logInfo(ex.getLocalizedMessage());
                    }
                    finally
                    {
                        if (incrementalFile != null)
                        {
                            try
                            {
                                incrementalFile.close();
                            }
                            catch (IOException ex)
                            {
                            }
                            // If the load failed, or recompilation is needed, reset
                            // all the variables to their original state.
                            if (recompile)
                            {
                                fileSpec = new FileSpec(Collections.<VirtualFile>emptyList(), WebTierAPI.getFileSpecMimeTypes());
                                sourceList = new SourceList(virtualFileList,
                                                            asClasspath,
                                                            targetFile,
                                                            WebTierAPI.getSourcePathMimeTypes());
                                sourcePath = new SourcePath(asClasspath,
                                                            targetFile,
                                                            WebTierAPI.getSourcePathMimeTypes(),
                                                            compilerConfig.allowSourcePathOverlap());
                                resources = new ResourceContainer();
                                bundlePath = new ResourceBundlePath(configuration.getCompilerConfiguration(), targetFile);
                            }
                        }
                    }
                }
            }

            VirtualFile projector = configuration.getProjector();
            boolean createProjector = (projector != null && projector.getName().endsWith("avmplus.exe"));

            // Validate CompilationUnits in FileSpec and SourcePath.  If
            // count > 0 something changed.
            int count = CompilerAPI.validateCompilationUnits(
                    fileSpec, sourceList, sourcePath, bundlePath, resources,
                    swcContext,
                    null    /* perCompileData */,
                    configuration);
            recompile = recompile || (count > 0);

            if (recompile)
            {
                // Get standard bundle of compilers, transcoders.
                transcoders = WebTierAPI.getTranscoders( configuration );
                SubCompiler[] compilers = WebTierAPI.getCompilers(compilerConfig, mappings, transcoders);

                if (benchmark != null)
                {
                    benchmark.stopTime(Benchmark.PRECOMPILE, false);
                }

                units = CompilerAPI.compile(fileSpec, sourceList,
                                            null, /* classes */
                                            sourcePath, resources, bundlePath, swcContext,
                                            mappings, configuration, compilers,
                                            createProjector ? null : new PreLink(),
                                            configuration.getLicensesConfiguration().getLicenseMap(),
                                            sources);

                if (benchmark != null)
                {
                    benchmark.startTime(Benchmark.POSTCOMPILE);
                }

                OutputStream swfOut = new BufferedOutputStream(new FileOutputStream(outputFile));
                PostLink postLink = null;

                if (configuration.optimize() && !configuration.debug())
                {
                    postLink = new PostLink(configuration);
                }

                // link
                if (createProjector)
                {
                    ConsoleApplication app = LinkerAPI.linkConsole(units, postLink, configuration);
                   
                    createProjector(configuration, projector, app, swfOut);
                }
                else
                {
                    Movie movie = LinkerAPI.link(units, postLink, configuration);
                   
                    if (projector != null)
                    {
                        createProjector(configuration, projector, movie, swfOut);
                    }
                    else
                    {
                        CompilerAPI.encode(configuration, movie, swfOut);
                    }
                }

                swfOut.flush();
                swfOut.close();

                // If incremental compilation is enabled, save the compilation units.
                if (configuration.getCompilerConfiguration().getIncremental())
                {
                    // Make sure the checksums are all current.
                    swcChecksums.saveChecksums(units);

                    RandomAccessFile incrementalFile = null;
                    try
                    {
                        incrementalFile = new RandomAccessFile(incrementalFileName, "rw");

                        // In case we're reusing the file, clear it.
                        incrementalFile.setLength(0);

                        CompilerAPI.persistCompilationUnits(
                                configuration, fileSpec, sourceList, sourcePath,
                                resources, bundlePath,
                                sources,   /* sources */
                                units,   /* units */
                                swcChecksums.getChecksums(),
                                swcChecksums.getSwcDefSignatureChecksums(),
                                swcChecksums.getSwcFileChecksums(),
                                null,   /* archiveFiles */
                                "", incrementalFile);
                    }
                    catch (IOException ex)
                    {
                        ThreadLocalToolkit.logInfo(ex.getLocalizedMessage());

                        // Get rid of the cache file since the write failed.
                        new File(incrementalFileName).deleteOnExit();
                    }
                    finally
                    {
                        if (incrementalFile != null)
                        {
                            try
                            {
                                incrementalFile.close();
                            }
                            catch (IOException ex)
                            {
                            }
                        }
                    }
                }

                ThreadLocalToolkit.log(new OutputMessage(FileUtil.getCanonicalPath(outputFile),
                        Long.toString(outputFile.length())));
            }
            else
            {
                if (benchmark != null)
                {
                    benchmark.stopTime(Benchmark.PRECOMPILE, false);
                    benchmark.startTime(Benchmark.POSTCOMPILE);
                }

                // swf is already up-to-date so no need to compile/link or rewrite file
                ThreadLocalToolkit.log(new NoUpdateMessage(FileUtil.getCanonicalPath(outputFile)));
            }
           
            Set<IMxmlcExtension> extensions = ExtensionManager.getMxmlcExtensions( configuration.getCompilerConfiguration().getExtensionsConfiguration().getExtensionMappings() );
            for ( IMxmlcExtension extension : extensions )
            {
                if(ThreadLocalToolkit.errorCount() == 0) {
                    extension.run( args );
                }
            }       
       
        }
        catch (ConfigurationException ex)
        {
          ThreadLocalToolkit.logInfo( getStartMessage( "mxmlc" ) );
            processConfigurationException(ex, "mxmlc");
        }
        catch (CompilerException ex)
        {
            assert ThreadLocalToolkit.errorCount() > 0;
        }
        catch (LinkerException ex)
        {
            assert ThreadLocalToolkit.errorCount() > 0;
        }
        catch (SwcException ex)
        {
            assert ThreadLocalToolkit.errorCount() > 0;
        }
        catch (Throwable t) // IOException, Throwable
        {
            ThreadLocalToolkit.logError(t.getLocalizedMessage());

            if (Trace.error)
            {
                t.printStackTrace();
            }
        }
        finally
        {
            if (benchmark != null)
            {
                if ((ThreadLocalToolkit.errorCount() == 0) &&
                    benchmark.hasStarted(Benchmark.POSTCOMPILE))
                {
                    benchmark.stopTime(Benchmark.POSTCOMPILE, false);
                }
                benchmark.totalTime();
                benchmark.peakMemoryUsage(true);
            }

            if (transcoders != null)
            {
                for (Transcoder element : transcoders)
View Full Code Here

    }

    private static void compile_compc(SwcTarget s)
    {
        LocalizationManager l10n = ThreadLocalToolkit.getLocalizationManager();
        Benchmark benchmark = null;

        try
        {
            // setup the path resolver
            CompilerAPI.usePathResolver();

            // process configuration
            ConfigurationBuffer cfgbuf = new ConfigurationBuffer(CompcConfiguration.class, CompcConfiguration.getAliases());
            cfgbuf.setDefaultVar("include-classes");
            DefaultsConfigurator.loadCompcDefaults( cfgbuf );
            CompcConfiguration configuration = (CompcConfiguration) Mxmlc.processConfiguration(
                ThreadLocalToolkit.getLocalizationManager(), "compc", s.args, cfgbuf, CompcConfiguration.class, "include-classes");

            CompilerAPI.setupHeadless(configuration);

            if (configuration.benchmark())
            {
                benchmark = CompilerAPI.runBenchmark();
                benchmark.startTime(Benchmark.PRECOMPILE);
            }
            else
            {
                CompilerAPI.disableBenchmark();
            }

            s.sourcePath.clearCache();
            s.bundlePath.clearCache();
            s.resources.refresh();

            // C: We don't really need to parse the manifest files again.
            CompilerConfiguration compilerConfig = configuration.getCompilerConfiguration();
            // note: if Configuration is ever shared with other parts of the system, then this part will need
            // to change, since we're setting a compc-specific setting below
            compilerConfig.setMetadataExport(true);

            NameMappings mappings = CompilerAPI.getNameMappings(configuration);

            Transcoder[] transcoders = WebTierAPI.getTranscoders( configuration );
            SubCompiler[] compilers = WebTierAPI.getCompilers(compilerConfig, mappings, transcoders);

            if (benchmark != null)
            {
                benchmark.benchmark(l10n.getLocalizedTextString(new InitialSetup()));
            }

            // load SWCs
            CompilerSwcContext swcContext = new CompilerSwcContext(true);
            // for compc the theme and include-libraries values have been purposely not passed in below.
            // This is done because the theme attribute doesn't make sense and the include-libraries value
            // actually causes issues when the default value is used with external libraries.
            // FIXME: why don't we just get rid of these values from the configurator for compc?  That's a problem
            // for include-libraries at least, since this value appears in flex-config.xml
            swcContext.load( compilerConfig.getLibraryPath(),
                             compilerConfig.getExternalLibraryPath(),
                             null,
                             null,
                             mappings,
                             I18nUtils.getTranslationFormat(compilerConfig),
                             s.swcCache );
            configuration.addExterns( swcContext.getExterns() );

            // recompile or incrementally compile...
            boolean recompile = false;
            int newChecksum = cfgbuf.checksum_ts() + swcContext.checksum();

            if (newChecksum != s.checksum)
            {
                ThreadLocalToolkit.logInfo(l10n.getLocalizedTextString(new DetectConfigurationChange()));
                s.checksum = newChecksum;
                s.resources = new ResourceContainer();
                recompile = true;
            }

            // validate CompilationUnits in FileSpec and SourcePath
            if (recompile || CompilerAPI.validateCompilationUnits(s.fileSpec, s.sourceList, s.sourcePath, s.bundlePath, s.resources,
                                                                  swcContext, s.classes, s.perCompileData, configuration) > 0)
            {
                Map licenseMap = configuration.getLicensesConfiguration().getLicenseMap();

                // create a symbol table
                SymbolTable symbolTable = new SymbolTable(configuration, s.perCompileData);
                s.configuration = configuration;

                Map<String, Source> classes = new HashMap<String, Source>();
                s.nsComponents = SwcAPI.setupNamespaceComponents(configuration, mappings, s.sourcePath, s.sourceList, classes);
                SwcAPI.setupClasses(configuration, s.sourcePath, s.sourceList, classes);
                // Only updated the SwcTarget's classes if
                // setupNamespaceComponents() and setupClasses() are
                // successful.
                s.classes = classes;

                Map<String, VirtualFile> rbFiles = new HashMap<String, VirtualFile>();

                if (benchmark != null)
                {
                    benchmark.stopTime(Benchmark.PRECOMPILE, false);
                }

                List<CompilationUnit> units = CompilerAPI.compile(s.fileSpec, s.sourceList, s.classes.values(),
                                                                  s.sourcePath, s.resources, s.bundlePath, swcContext,
                                                                  symbolTable, mappings, configuration, compilers,
                                                                  new CompcPreLink(rbFiles, configuration.getIncludeResourceBundles(),
                                                                      false),
                                                                  licenseMap, new ArrayList<Source>());

                if (benchmark != null)
                {
                    benchmark.startTime(Benchmark.POSTCOMPILE);
                }

                s.units = units;
                s.rbFiles = rbFiles;
                s.sourcePath.clearCache();
                s.bundlePath.clearCache();
                s.resources.refresh();
            }
            else
            {
                ThreadLocalToolkit.logInfo(l10n.getLocalizedTextString(new NoChange()));
            }
        }
        catch (ConfigurationException ex)
        {
            Compc.displayStartMessage();
            Mxmlc.processConfigurationException(ex, "compc");
        }
        catch (CompilerException ex)
        {
            assert ThreadLocalToolkit.errorCount() > 0;
        }
        catch (SwcException ex)
        {
            assert ThreadLocalToolkit.errorCount() > 0;
        }
        catch (Throwable t) // IOException, Throwable
        {
            ThreadLocalToolkit.logError(t.getMessage());
            if (Trace.error)
            {
                t.printStackTrace();
            }
        }
        finally
        {
            if (benchmark != null)
            {
                if ((ThreadLocalToolkit.errorCount() == 0) &&
                    benchmark.hasStarted(Benchmark.POSTCOMPILE))
                {
                    benchmark.stopTime(Benchmark.POSTCOMPILE, false);
                }
                benchmark.totalTime();
                benchmark.peakMemoryUsage(true);
            }

            CompilerAPI.removePathResolver();
        }
    }
View Full Code Here

    }

    private static void compile_mxmlc(Target s)
    {
        LocalizationManager l10n = ThreadLocalToolkit.getLocalizationManager();
        Benchmark benchmark = null;

        try
        {
            // setup the path resolver
            CompilerAPI.usePathResolver();

            // process configuration
            ConfigurationBuffer cfgbuf = new ConfigurationBuffer(CommandLineConfiguration.class, Configuration.getAliases());
            cfgbuf.setDefaultVar(Mxmlc.FILE_SPECS);
            DefaultsConfigurator.loadDefaults( cfgbuf );
            CommandLineConfiguration configuration = (CommandLineConfiguration) Mxmlc.processConfiguration(
                ThreadLocalToolkit.getLocalizationManager(), "mxmlc", s.args, cfgbuf, CommandLineConfiguration.class, Mxmlc.FILE_SPECS);

            CompilerAPI.setupHeadless(configuration);

            if (configuration.benchmark())
            {
                benchmark = CompilerAPI.runBenchmark();
                benchmark.startTime(Benchmark.PRECOMPILE);
            }
            else
            {
                CompilerAPI.disableBenchmark();
            }

            s.sourcePath.clearCache();
            s.bundlePath.clearCache();
            s.resources.refresh();

            // C: We don't really need to parse the manifest files again.
            CompilerConfiguration compilerConfig = configuration.getCompilerConfiguration();
            NameMappings mappings = CompilerAPI.getNameMappings(configuration);

            Transcoder[] transcoders = WebTierAPI.getTranscoders( configuration );
            SubCompiler[] compilers = WebTierAPI.getCompilers(compilerConfig, mappings, transcoders);

            if (benchmark != null)
            {
                benchmark.benchmark(l10n.getLocalizedTextString(new InitialSetup()));
            }

            CompilerSwcContext swcContext = new CompilerSwcContext(true);
            swcContext.load( compilerConfig.getLibraryPath(),
                             Configuration.getAllExcludedLibraries(compilerConfig, configuration),
                             compilerConfig.getThemeFiles(),
                             compilerConfig.getIncludeLibraries(),
                             mappings,
                             I18nUtils.getTranslationFormat(compilerConfig),
                             s.swcCache );
            configuration.addExterns( swcContext.getExterns() );
            configuration.addIncludes( swcContext.getIncludes() );
            configuration.getCompilerConfiguration().addThemeCssFiles( swcContext.getThemeStyleSheets() );

            // recompile or incrementally compile...
            boolean recompile = false;
            int newChecksum = cfgbuf.checksum_ts() + swcContext.checksum();

            if (newChecksum != s.checksum)
            {
                ThreadLocalToolkit.logInfo(l10n.getLocalizedTextString(new DetectConfigurationChange()));
                s.checksum = newChecksum;
                s.resources = new ResourceContainer();
                recompile = true;
            }

            // validate CompilationUnits in FileSpec and SourcePath
            if (recompile || CompilerAPI.validateCompilationUnits(s.fileSpec, s.sourceList, s.sourcePath, s.bundlePath, s.resources,
                                                                  swcContext, s.perCompileData,
                                                                  configuration) > 0)
            {
                Map licenseMap = configuration.getLicensesConfiguration().getLicenseMap();

                // create a symbol table
                SymbolTable symbolTable = new SymbolTable(configuration, s.perCompileData);
                s.configuration = configuration;

                VirtualFile projector = configuration.getProjector();

                if (benchmark != null)
                {
                    benchmark.stopTime(Benchmark.PRECOMPILE, false);
                }

                if (projector != null && projector.getName().endsWith("avmplus.exe"))
                {
                    s.units = CompilerAPI.compile(s.fileSpec, s.sourceList, null, s.sourcePath, s.resources, s.bundlePath,
                                                  swcContext, symbolTable, mappings, configuration, compilers,
                                                  null, licenseMap, new ArrayList<Source>());
                }
                else
                {
                    s.units = CompilerAPI.compile(s.fileSpec, s.sourceList, null, s.sourcePath, s.resources, s.bundlePath,
                                                  swcContext, symbolTable, mappings, configuration, compilers,
                                                  new PreLink(), licenseMap, new ArrayList<Source>());
                }

                if (benchmark != null)
                {
                    benchmark.startTime(Benchmark.POSTCOMPILE);
                }

                s.sourcePath.clearCache();
                s.bundlePath.clearCache();
                s.resources.refresh();
            }
            else
            {
                ThreadLocalToolkit.logInfo(l10n.getLocalizedTextString(new NoChange()));
            }
        }
        catch (ConfigurationException ex)
        {
            Mxmlc.processConfigurationException(ex, "mxmlc");
        }
        catch (CompilerException ex)
        {
            assert ThreadLocalToolkit.errorCount() > 0;
        }
        catch (SwcException ex)
        {
            assert ThreadLocalToolkit.errorCount() > 0;
        }
        catch (Throwable t) // IOException, Throwable
        {
            ThreadLocalToolkit.logError(t.getMessage());
            if (Trace.error)
            {
                t.printStackTrace();
            }
        }
        finally
        {
            if (benchmark != null)
            {
                if ((ThreadLocalToolkit.errorCount() == 0) &&
                    benchmark.hasStarted(Benchmark.POSTCOMPILE))
                {
                    benchmark.stopTime(Benchmark.POSTCOMPILE, false);
                }
                benchmark.totalTime();
                benchmark.peakMemoryUsage(true);
            }

            CompilerAPI.removePathResolver();
        }
    }
View Full Code Here

                t.printStackTrace();
            }
        }
        finally
        {
            Benchmark benchmark = ThreadLocalToolkit.getBenchmark();
            if (benchmark != null)
            {
                benchmark.totalTime();
                benchmark.peakMemoryUsage(true);
            }

            CompilerAPI.removePathResolver();
        }
    }
View Full Code Here

                t.printStackTrace();
            }
        }
        finally
        {
            Benchmark benchmark = ThreadLocalToolkit.getBenchmark();
            if (benchmark != null)
            {
                benchmark.totalTime();
                benchmark.peakMemoryUsage(true);
            }

            if (swfOut != null) { try { swfOut.close(); } catch (IOException ioe) {} }
        }
    }
View Full Code Here

    }

    private static void mxmlc(String[] args, int id)
    {
        LocalizationManager l10n = ThreadLocalToolkit.getLocalizationManager();
        Benchmark benchmark = null;
        OutputStream swfOut = null;
        Target s = new Target();
        s.id = id;

        try
        {
            // setup the path resolver
            CompilerAPI.usePathResolver();

            // process configuration
            ConfigurationBuffer cfgbuf = new ConfigurationBuffer(CommandLineConfiguration.class, Configuration.getAliases());
            cfgbuf.setDefaultVar(Mxmlc.FILE_SPECS);
            DefaultsConfigurator.loadDefaults( cfgbuf );
            CommandLineConfiguration configuration = (CommandLineConfiguration) Mxmlc.processConfiguration(
                ThreadLocalToolkit.getLocalizationManager(), "mxmlc", args, cfgbuf, CommandLineConfiguration.class, Mxmlc.FILE_SPECS);
            s.configuration = configuration;

            CompilerAPI.setupHeadless(configuration);

            if (configuration.benchmark())
            {
                benchmark = CompilerAPI.runBenchmark();
                benchmark.startTime(Benchmark.PRECOMPILE);
            }
            else
            {
                CompilerAPI.disableBenchmark();
            }

            String target = configuration.getTargetFile();
            targets.put("" + id, s);
            s.args = args;

            // make sure targetFile abstract pathname is an absolute path...
            VirtualFile targetFile = CompilerAPI.getVirtualFile(target);
            WebTierAPI.checkSupportedTargetMimeType(targetFile);
            List<VirtualFile> virtualFileList = CompilerAPI.getVirtualFileList(configuration.getFileList());

            CompilerConfiguration compilerConfig = configuration.getCompilerConfiguration();
            NameMappings mappings = CompilerAPI.getNameMappings(configuration);

            Transcoder[] transcoders = WebTierAPI.getTranscoders( configuration );
            SubCompiler[] compilers = WebTierAPI.getCompilers(compilerConfig, mappings, transcoders);

            // construct the SWF file name...
            VirtualFile projector = configuration.getProjector();

            if (projector != null && projector.getName().endsWith("avmplus.exe"))
            {
                // output .exe
                s.outputName = configuration.getOutput();
                if (s.outputName == null)
                {
                    s.outputName = targetFile.getName();
                    s.outputName = s.outputName.substring(0, s.outputName.lastIndexOf('.')) + ".exe";
                }
            }
            else
            {
                // output SWF
                s.outputName = configuration.getOutput();
                if (s.outputName == null)
                {
                    s.outputName = targetFile.getName();
                    if (projector != null)
                    {
                        s.outputName = s.outputName.substring(0, s.outputName.lastIndexOf('.')) + ".exe";
                    }
                    else
                    {
                        s.outputName = s.outputName.substring(0, s.outputName.lastIndexOf('.')) + ".swf";
                    }
                }
            }

            VirtualFile[] asClasspath = compilerConfig.getSourcePath();

            // create a FileSpec...
            s.fileSpec = new FileSpec(Collections.<VirtualFile>emptyList(), WebTierAPI.getFileSpecMimeTypes());

            // create a SourceList
            s.sourceList = new SourceList(virtualFileList, asClasspath, targetFile, WebTierAPI.getSourcePathMimeTypes());

            // create a SourcePath...
            s.sourcePath = new SourcePath(asClasspath, targetFile, WebTierAPI.getSourcePathMimeTypes(),
                                          compilerConfig.allowSourcePathOverlap());

            // create a ResourceContainer...
            s.resources = new ResourceContainer();

            // create a ResourceBundlePath...
            s.bundlePath = new ResourceBundlePath(configuration.getCompilerConfiguration(), targetFile);

            if (benchmark != null)
            {
                benchmark.benchmark(l10n.getLocalizedTextString(new InitialSetup()));
            }

            // load SWCs
            s.swcCache = new SwcCache();
           
            CompilerSwcContext swcContext = new CompilerSwcContext(true);
            swcContext.load( compilerConfig.getLibraryPath(),
                             Configuration.getAllExcludedLibraries(compilerConfig, configuration),
                             compilerConfig.getThemeFiles(),
                             compilerConfig.getIncludeLibraries(),
                             mappings,
                             I18nUtils.getTranslationFormat(compilerConfig),
                             s.swcCache );
            configuration.addExterns( swcContext.getExterns() );
            configuration.addIncludes( swcContext.getIncludes() );
            configuration.getCompilerConfiguration().addThemeCssFiles( swcContext.getThemeStyleSheets() );

               s.checksum = cfgbuf.checksum_ts() + swcContext.checksum();

            final SymbolTable symbolTable = new SymbolTable(configuration);
            s.perCompileData = symbolTable.perCompileData;

            Map licenseMap = configuration.getLicensesConfiguration().getLicenseMap();
            PostLink postLink = null;

            if (configuration.optimize() && !configuration.debug())
            {
                postLink = new PostLink(configuration);
            }

            if (projector != null && projector.getName().endsWith("avmplus.exe"))
            {
                if (benchmark != null)
                {
                    benchmark.stopTime(Benchmark.PRECOMPILE, false);
                }

                List<CompilationUnit> units = CompilerAPI.compile(s.fileSpec, s.sourceList, null, s.sourcePath, s.resources, s.bundlePath,
                                                        swcContext, symbolTable, mappings, configuration, compilers,
                                                        null, licenseMap, new ArrayList<Source>());

                if (benchmark != null)
                {
                    benchmark.startTime(Benchmark.POSTCOMPILE);
                }

                s.units = units;
                s.sourcePath.clearCache();
                s.bundlePath.clearCache();
                s.resources.refresh();

                // link
                s.app = LinkerAPI.linkConsole(units, postLink, configuration);

                // output .exe
                File file = FileUtil.openFile(s.outputName, true);
                swfOut = new BufferedOutputStream(new FileOutputStream(file));

                Mxmlc.createProjector(configuration, projector, s.app, swfOut);

                swfOut.flush();
                swfOut.close();

                ThreadLocalToolkit.log(new OutputMessage(s.outputName, Long.toString(file.length())));
            }
            else
            {
                if (benchmark != null)
                {
                    benchmark.stopTime(Benchmark.PRECOMPILE, false);
                }

                List<CompilationUnit> units = CompilerAPI.compile(s.fileSpec, s.sourceList, null, s.sourcePath, s.resources, s.bundlePath,
                                                        swcContext, symbolTable, mappings, configuration, compilers,
                                                        new PreLink(), licenseMap, new ArrayList<Source>());

                if (benchmark != null)
                {
                    benchmark.startTime(Benchmark.POSTCOMPILE);
                }

                s.units = units;
                s.sourcePath.clearCache();
                s.bundlePath.clearCache();
                s.resources.refresh();

                // link
                s.movie = LinkerAPI.link(units, postLink, configuration);

                // output SWF
                File file = FileUtil.openFile(s.outputName, true);
                swfOut = new BufferedOutputStream(new FileOutputStream(file));

                if (projector != null)
                {
                    Mxmlc.createProjector(configuration, projector, s.movie, swfOut);
                }
                else
                {
                    CompilerAPI.encode(configuration, s.movie, swfOut);
                }

                swfOut.flush();
                swfOut.close();

                ThreadLocalToolkit.log(new OutputMessage(s.outputName, Long.toString(file.length())));
            }
        }
        catch (ConfigurationException ex)
        {
            Mxmlc.processConfigurationException(ex, "mxmlc");
        }
        catch (CompilerException ex)
        {
            assert ThreadLocalToolkit.errorCount() > 0;
        }
        catch (LinkerException ex)
        {
            assert ThreadLocalToolkit.errorCount() > 0;
        }
        catch (SwcException ex)
        {
            assert ThreadLocalToolkit.errorCount() > 0;
        }
        catch (Throwable thr) // IOException, Throwable
        {
            ThreadLocalToolkit.logError(thr.getMessage());
            if (Trace.error)
            {
                thr.printStackTrace();
            }
        }
        finally
        {
            if (benchmark != null)
            {
                if ((ThreadLocalToolkit.errorCount() == 0) &&
                    benchmark.hasStarted(Benchmark.POSTCOMPILE))
                {
                    benchmark.stopTime(Benchmark.POSTCOMPILE, false);
                }
                benchmark.totalTime();
                benchmark.peakMemoryUsage(true);
            }

            CompilerAPI.removePathResolver();

            if (swfOut != null) try { swfOut.close(); } catch (IOException ioe) {}
View Full Code Here

TOP

Related Classes of flex2.compiler.util.Benchmark$BenchmarkText

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.