public void cfgOutput(ConfigurationValue val, String str) throws ConfigurationException { if (str != null && (str.startsWith(File.separator) || str.startsWith("/") || FileUtils.isAbsolute(new File(str)))) { output = str; } else if (val.getContext() != null) { output = FileUtils.addPathComponents(val.getContext(), str, File.separatorChar); } else { output = str; } }
// changed from private to protected to support Flash Authoring - jkamerer 2007.07.30 protected Swc getSwc(File file) { Swc swc; try { String location = FileUtils.canonicalPath(file); swc = (Swc) swcLRUCache.get(location); long fileLastModified = file.lastModified(); if (swc == null || (fileLastModified != swc.getLastModified())) { if (Trace.swc) { if (swc != null) { Trace.trace( "Reloading: location = " + location + ", fileLastModified = " + fileLastModified + ", swc.getLastModified() = " + swc.getLastModified() + ", swc = " + swc.hashCode()); } else { Trace.trace("Loading " + location); } } SwcArchive archive = file.isDirectory() ? (SwcArchive) new SwcDirectoryArchive(location) : lazyRead ? new SwcLazyReadArchive(location) : new SwcDynamicArchive(location); swc = new Swc(archive, true); swc.setLastModified(fileLastModified); if (ThreadLocalToolkit.errorCount() > 0) { swc = null; } else if (useCache) { swcLRUCache.put(location, swc); } } else if (Trace.swc) { Trace.trace("Using cached version of " + location); } } catch (Exception e) { if (Trace.error) { e.printStackTrace(); } SwcException.SwcNotLoaded ex = new SwcException.SwcNotLoaded(file.getName(), e); ThreadLocalToolkit.log(ex); throw ex; } return swc; }
// changed from private to protected to support Flash Authoring - jkamerer 2007.07.30 protected Map<String, Swc> getSwcs(String path) { Map<String, Swc> map = new LinkedHashMap<String, Swc>(); File f = new File(path); if (!f.exists()) { throw new SwcException.SwcNotFound(path); } File catalog = new File(FileUtils.addPathComponents(path, Swc.CATALOG_XML, File.separatorChar)); if (!f.isDirectory() || catalog.exists()) { Swc swc = getSwc(f); if (swc != null) { map.put(swc.getLocation(), swc); } } else { File[] files = FileUtils.listFiles(f); for (int i = 0; i < files.length; i++) { File file = files[i]; // we don't want to snarf an entire directory tree, just a single level. if ((!file.isDirectory()) && file.canRead()) { String lowerCase = file.getName().toLowerCase(); if (lowerCase.endsWith(GENSWC_EXTENSION)) // never automatically read genswcs continue; if (lowerCase.endsWith(SWC_EXTENSION)) { Swc swc = getSwc(file); if (swc != null) { map.put(swc.getLocation(), swc); } } } } } return map; }
private static void doSignatureGeneration(final CompilationUnit unit) { // debug("doSignatureGeneration(" + unit.getSource().getName() + ")"); // generate the signature final String sigString = generateSignature(unit); // computer and store the checksum of the signature { final Long checksum = computeChecksum(unit, sigString); // make sure we've never parsed this unit before -- we don't want to waste passes // TODO concern: Source.copy() means that if you recompile a copied source, this // assertion will explode. Unsure IF that can/should happen; // unless CU.resetKeepTypeInfo() or CU.reset() clears the signature // and is always called before recompiling a copied unit. // this should never, ever happen in production compiler -- and has never happened so far, to // boot. // so I've upgraded it to an assertion, to be sure that we'd catch it during development. assert !unit.hasSignatureChecksum() : "overwriting an existing checksum for " + unit; unit.setSignatureChecksum(checksum); } // dump signature to filesystem // If the siggen failed, a file won't get created. I would LIKE to // write a file saying *** FAILED *** or some such, but if the package or class // name was one of the problems, then the generated file name is unreliable // (since it is based on the package name) and could overwrite an existing, // valid, signature file if ((sigString != null) && (signatureDirectory != null)) { final ProgramNode pNode = (ProgramNode) unit.getSyntaxTree(); final PackageDefinitionNode pdn = pNode.pkgdefs.first(); final String pkgName = NodeMagic.getPackageName(pdn).replace('.', '_'); // final VirtualFile vFile = unit.getSource().getBackingFile(); // this is only kinda sketchy, but it works... all I need is the file name, not the path final String fileName = new File(unit.getSource().getNameForReporting()).getName(); // older sketchy method // URI uri; // try // { // apparently a URL is-a URI, therefore, this should never fail // except... some vFiles are in-memory, which give us a "memory://" URI, invalid // uri = new URI(vFile.getURL()); // fileName = new File(uri).getName(); // } // catch(URISyntaxException e) // { // fileName = new File(vFile.getName()).getName(); // } final String srcName = fileName.substring( 0, (fileName.length() - MimeMappings.getExtension(unit.getSource().getMimeType()).length())); final String sigName = pkgName.concat(pkgName.equals("") ? "" : "_").concat(srcName).concat(".sig"); try { // final String NL = SignatureEvaluator.NEWLINE; FileUtils.writeClassToFile( signatureDirectory, "", sigName, /* (("SOURCE: " + fileName + NL + "DIGEST: " + chksum + NL + "-------------------" + NL + NL) + */ sigString); } catch (IOException ioe) { final CompilerWarning warning = new KeepGeneratedSignatureFileWritingFailed(sigName); warning.setPath(unit.getSource().getNameForReporting()); setWarning(unit, warning); } } }