compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCNative.java [494:649]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            zipOutputStream.flush();
            zipOutputStream.closeEntry();
            zipOutputStream.flush();
            zipOutputStream.close();
            swcFile.delete();
            File newSWCFile = new File(outputFolderName + ".new");
            newSWCFile.renameTo(swcFile);
        }
        return true;
    }

    private void processSourceMap(ByteArrayOutputStream sourceMapTemp, ByteArrayOutputStream baos, File outputClassFile, String symbol)
    {
        String sourceMapSourceRoot = project.config.getSourceMapSourceRoot();
        if(sourceMapSourceRoot != null && sourceMapSourceRoot.length() > 0)
        {
            String sourceMapContents = null;
            try
            {
                sourceMapContents = sourceMapTemp.toString("utf8");
            }
            catch(UnsupportedEncodingException e)
            {
                sourceMapContents = null;
            }
            if(sourceMapContents != null)
            {
                SourceMapConsumerV3 sourceMapConsumer = new SourceMapConsumerV3();
                try
                {
                    sourceMapConsumer.parse(sourceMapContents);
                }
                catch(SourceMapParseException e)
                {
                    sourceMapConsumer = null;
                }
                if (sourceMapConsumer != null && !sourceMapSourceRoot.equals(sourceMapConsumer.getSourceRoot()))
                {
                    SourceMapGeneratorV3 sourceMapGenerator = SourceMapUtils.sourceMapConsumerToGeneratorWithRemappedSourceRoot(sourceMapConsumer, sourceMapSourceRoot, symbol);
                    String newSourceMapContents = SourceMapUtils.sourceMapGeneratorToString(sourceMapGenerator, outputClassFile.getName());
                    try
                    {
                        IOUtils.write(newSourceMapContents, baos, Charset.forName("utf8"));
                    }
                    catch(IOException e)
                    {
                    }
                    return;
                }
            }
        }
        try
        {
            sourceMapTemp.writeTo(baos);
        }
        catch(IOException e)
        {

        }
    }

    private void writeFileToZip(ZipOutputStream zipOutputStream, String entryFilePath, ByteArrayOutputStream baos, StringBuilder fileList) throws IOException
    {
        long fileDate = System.currentTimeMillis();
        long zipFileDate = fileDate;
        String metadataDate = targetSettings.getSWFMetadataDate();
        if (metadataDate != null)
        {
            String metadataFormat = targetSettings.getSWFMetadataDateFormat();
            try {
                SimpleDateFormat sdf = new SimpleDateFormat(metadataFormat);
                Date d = sdf.parse(metadataDate);
                Calendar cal = new GregorianCalendar();
                cal.setTime(d);
                sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
                d = sdf.parse(metadataDate);
                fileDate = d.getTime();
                ZonedDateTime zdt = ZonedDateTime.of(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), 
                                        cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), 0, ZoneId.systemDefault());
                zipFileDate = zdt.toInstant().toEpochMilli();
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalArgumentException e1) {
                e1.printStackTrace();
            }
        }
        ZipEntry ze = new ZipEntry(entryFilePath);
        ze.setTime(zipFileDate);
        ze.setMethod(ZipEntry.STORED);
        
        ze.setSize(baos.size());
        ze.setCompressedSize(baos.size());
        CRC32 crc = new CRC32();
        crc.reset();
        crc.update(baos.toByteArray());
        ze.setCrc(crc.getValue());

        zipOutputStream.putNextEntry(ze);
        baos.writeTo(zipOutputStream);
        zipOutputStream.flush();
        zipOutputStream.closeEntry();
        fileList.append("        <file path=\"" + entryFilePath + "\" mod=\"" + fileDate + "\"/>\n");
    }

    @Override
    protected void setupWatcher()
    {
        if (!config.getWatch())
        {
            return;
        }
        IWatchWriter writer = new IWatchWriter()
        {
            private long startTime;

            public void rebuild(Collection<ICompilationUnit> units, Collection<ICompilerProblem> problems) throws InterruptedException, IOException
            {
                startTime = System.nanoTime();
                workspace.startBuilding();
                try
                {
                    target = project.getBackend().createTarget(project,
                            getTargetSettings(), null);
                    ((JSTarget) target).build(null, problems);
                    for (ICompilationUnit unit : units)
                    {
                        // call waitForBuildFinish() to ensure that binding data
                        // doesn't get lost when a new definition is created
                        unit.waitForBuildFinish(problems, null);
                    }
                }
                finally
                {
                    workspace.doneBuilding();
                }
            }
    
            public void write(Collection<ICompilationUnit> units) throws InterruptedException, IOException
            {
                try
                {
                    if (!writeSWC())
                    {
                        throw new IOException("Failed to write SWC file.");
                    }

                    long endTime = System.nanoTime();
                    System.out.println((endTime - startTime) / 1e9 + " seconds");
                }
                finally
                {
                    workspace.doneBuilding();
                }
            }
        };
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCRoyale.java [561:716]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            zipOutputStream.flush();
            zipOutputStream.closeEntry();
            zipOutputStream.flush();
            zipOutputStream.close();
            swcFile.delete();
            File newSWCFile = new File(outputFolderName + ".new");
            newSWCFile.renameTo(swcFile);
        }
        return true;
    }

    private void processSourceMap(ByteArrayOutputStream sourceMapTemp, ByteArrayOutputStream baos, File outputClassFile, String symbol)
    {
        String sourceMapSourceRoot = project.config.getSourceMapSourceRoot();
        if(sourceMapSourceRoot != null && sourceMapSourceRoot.length() > 0)
        {
            String sourceMapContents = null;
            try
            {
                sourceMapContents = sourceMapTemp.toString("utf8");
            }
            catch(UnsupportedEncodingException e)
            {
                sourceMapContents = null;
            }
            if(sourceMapContents != null)
            {
                SourceMapConsumerV3 sourceMapConsumer = new SourceMapConsumerV3();
                try
                {
                    sourceMapConsumer.parse(sourceMapContents);
                }
                catch(SourceMapParseException e)
                {
                    sourceMapConsumer = null;
                }
                if (sourceMapConsumer != null && !sourceMapSourceRoot.equals(sourceMapConsumer.getSourceRoot()))
                {
                    SourceMapGeneratorV3 sourceMapGenerator = SourceMapUtils.sourceMapConsumerToGeneratorWithRemappedSourceRoot(sourceMapConsumer, sourceMapSourceRoot, symbol);
                    String newSourceMapContents = SourceMapUtils.sourceMapGeneratorToString(sourceMapGenerator, outputClassFile.getName());
                    try
                    {
                        IOUtils.write(newSourceMapContents, baos, Charset.forName("utf8"));
                    }
                    catch(IOException e)
                    {
                    }
                    return;
                }
            }
        }
        try
        {
            sourceMapTemp.writeTo(baos);
        }
        catch(IOException e)
        {

        }
    }

    private void writeFileToZip(ZipOutputStream zipOutputStream, String entryFilePath, ByteArrayOutputStream baos, StringBuilder fileList) throws IOException
    {
        long fileDate = System.currentTimeMillis();
        long zipFileDate = fileDate;
        String metadataDate = targetSettings.getSWFMetadataDate();
        if (metadataDate != null)
        {
            String metadataFormat = targetSettings.getSWFMetadataDateFormat();
            try {
                SimpleDateFormat sdf = new SimpleDateFormat(metadataFormat);
                Date d = sdf.parse(metadataDate);
                Calendar cal = new GregorianCalendar();
                cal.setTime(d);
                sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
                d = sdf.parse(metadataDate);
                fileDate = d.getTime();
                ZonedDateTime zdt = ZonedDateTime.of(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), 
                                        cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), 0, ZoneId.systemDefault());
                zipFileDate = zdt.toInstant().toEpochMilli();
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalArgumentException e1) {
                e1.printStackTrace();
            }
        }
        ZipEntry ze = new ZipEntry(entryFilePath);
        ze.setTime(zipFileDate);
        ze.setMethod(ZipEntry.STORED);
        
        ze.setSize(baos.size());
        ze.setCompressedSize(baos.size());
        CRC32 crc = new CRC32();
        crc.reset();
        crc.update(baos.toByteArray());
        ze.setCrc(crc.getValue());

        zipOutputStream.putNextEntry(ze);
        baos.writeTo(zipOutputStream);
        zipOutputStream.flush();
        zipOutputStream.closeEntry();
        fileList.append("        <file path=\"" + entryFilePath + "\" mod=\"" + fileDate + "\"/>\n");
    }

    @Override
    protected void setupWatcher()
    {
        if (!config.getWatch())
        {
            return;
        }
        IWatchWriter writer = new IWatchWriter()
        {
            private long startTime;

            public void rebuild(Collection<ICompilationUnit> units, Collection<ICompilerProblem> problems) throws InterruptedException, IOException
            {
                startTime = System.nanoTime();
                workspace.startBuilding();
                try
                {
                    target = project.getBackend().createTarget(project,
                            getTargetSettings(), null);
                    ((JSTarget) target).build(null, problems);
                    for (ICompilationUnit unit : units)
                    {
                        // call waitForBuildFinish() to ensure that binding data
                        // doesn't get lost when a new definition is created
                        unit.waitForBuildFinish(problems, null);
                    }
                }
                finally
                {
                    workspace.doneBuilding();
                }
            }
    
            public void write(Collection<ICompilationUnit> units) throws InterruptedException, IOException
            {
                try
                {
                    if (!writeSWC())
                    {
                        throw new IOException("Failed to write SWC file.");
                    }

                    long endTime = System.nanoTime();
                    System.out.println((endTime - startTime) / 1e9 + " seconds");
                }
                finally
                {
                    workspace.doneBuilding();
                }
            }
        };
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



