获取解压后的代码对应的doc-root目录

@param codeSourceFile 当前代码所处的文件
@return 解压后的代码对应的doc-root目录
512316
private static File getExplodedWarFileDocumentRoot(File codeSourceFile) {
        log.debug("Code archive: " + codeSourceFile);
        if (codeSourceFile != null && codeSourceFile.exists()) {
            String path = codeSourceFile.getAbsolutePath();
            int webInfPathIndex = path.indexOf(File.separatorChar + "WEB-INF" + File.separatorChar);
            if (webInfPathIndex >= 0) {
                path = path.substring(0, webInfPathIndex);
                return new File(path);
            }
        }
        return null;
    }
350009
public JavaFileObject useSource(JavaFileObject file) {
        JavaFileObject prev = (source == null ? null : source.getFile());
        source = getSource(file);
        return prev;
    }
181500
public com.google.protobuf.ByteString
      getDocumentationRootUrlBytes() {
    java.lang.Object ref = documentationRootUrl_;
    if (ref instanceof java.lang.String) {
      com.google.protobuf.ByteString b = 
          com.google.protobuf.ByteString.copyFromUtf8(
              (java.lang.String) ref);
      documentationRootUrl_ = b;
      return b;
    } else {
      return (com.google.protobuf.ByteString) ref;
    }
  }
50092
@Nonnull
  public static FileIOError renameFile (@Nonnull final Path aSourceFile, @Nonnull final Path aTargetFile)
  {
    ValueEnforcer.notNull (aSourceFile, "SourceFile");
    ValueEnforcer.notNull (aTargetFile, "TargetFile");

    final Path aRealSourceFile = _getUnifiedPath (aSourceFile);
    final Path aRealTargetFile = _getUnifiedPath (aTargetFile);

    // Does the source file exist?
    if (!aRealSourceFile.toFile ().isFile ())
      return EFileIOErrorCode.SOURCE_DOES_NOT_EXIST.getAsIOError (EFileIOOperation.RENAME_FILE, aRealSourceFile);

    // Are source and target different?
    if (EqualsHelper.equals (aRealSourceFile, aRealTargetFile))
      return EFileIOErrorCode.SOURCE_EQUALS_TARGET.getAsIOError (EFileIOOperation.RENAME_FILE, aRealSourceFile);

    // Does the target file already exist?
    if (aRealTargetFile.toFile ().exists ())
      return EFileIOErrorCode.TARGET_ALREADY_EXISTS.getAsIOError (EFileIOOperation.RENAME_FILE, aRealTargetFile);

    // Is the source parent directory writable?
    final Path aSourceParentDir = aRealSourceFile.getParent ();
    if (aSourceParentDir != null && !Files.isWritable (aSourceParentDir))
      return EFileIOErrorCode.SOURCE_PARENT_NOT_WRITABLE.getAsIOError (EFileIOOperation.RENAME_FILE, aRealSourceFile);

    // Is the target parent directory writable?
    final Path aTargetParentDir = aRealTargetFile.getParent ();
    if (aTargetParentDir != null && aTargetParentDir.toFile ().exists () && !Files.isWritable (aTargetParentDir))
      return EFileIOErrorCode.TARGET_PARENT_NOT_WRITABLE.getAsIOError (EFileIOOperation.RENAME_FILE, aRealTargetFile);

    // Ensure parent of target directory is present
    PathHelper.ensureParentDirectoryIsPresent (aRealTargetFile);

    return _perform (EFileIOOperation.RENAME_FILE, PathOperations::_atomicMove, aRealSourceFile, aRealTargetFile);
  }
313976
public static GosuPathEntry createPathEntryForModuleFile(IFile moduleFile) {
    try {
      InputStream is = moduleFile.openInputStream();
      try {
        SimpleXmlNode moduleNode = SimpleXmlNode.parse(is);
        IDirectory rootDir = moduleFile.getParent();

        List<IDirectory> sourceDirs = new ArrayList<IDirectory>();
        for (String child : new String[] { "gsrc", "gtest" }) {
          IDirectory dir = rootDir.dir(child);
          if (dir.exists()) {
            sourceDirs.add(dir);
          }
        }
        return new GosuPathEntry(rootDir, sourceDirs);
      } finally {
        is.close();
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
69078
public String codeFile(@javax.annotation.Nonnull File file) throws IOException {
    Path path = pathToCodeFile(file);
    if (null != getAbsoluteUrl()) {
      try {
        return new URI(getAbsoluteUrl()).resolve(path.normalize().toString().replaceAll("\\\\", "/")).normalize().toString();
      } catch (URISyntaxException e) {
        throw new RuntimeException(e);
      }
    }
    else {
      return path.normalize().toString().replaceAll("\\\\", "/");
    }
  }
20151
public static void generateSource(InputStream is, File sourceOutputPath) throws IOException {
        ProtoFile protoFile = ProtoSchemaParser.parseUtf8(DEFAULT_FILE_NAME, is);
        List<CodeDependent> cds = new ArrayList<CodeDependent>();
        doCreate(protoFile, true, false, null, true, sourceOutputPath, cds, new HashMap<String, String>(), false);
    }
868383
public static TomcatServiceBuilder forClassPath(Class<?> clazz, String docBaseOrJarRoot) {
        requireNonNull(clazz, "clazz");
        requireNonNull(docBaseOrJarRoot, "docBaseOrJarRoot");

        final ProtectionDomain pd = clazz.getProtectionDomain();
        if (pd == null) {
            throw new IllegalArgumentException(clazz + " does not have a protection domain.");
        }
        final CodeSource cs = pd.getCodeSource();
        if (cs == null) {
            throw new IllegalArgumentException(clazz + " does not have a code source.");
        }
        final URL url = cs.getLocation();
        if (url == null) {
            throw new IllegalArgumentException(clazz + " does not have a location.");
        }

        if (!"file".equalsIgnoreCase(url.getProtocol())) {
            throw new IllegalArgumentException(clazz + " is not on a file system: " + url);
        }

        File f;
        try {
            f = new File(url.toURI());
        } catch (URISyntaxException ignored) {
            f = new File(url.getPath());
        }

        if (TomcatUtil.isZip(f.toPath())) {
            return new TomcatServiceBuilder(f.toPath(), docBaseOrJarRoot);
        }

        f = fileSystemDocBase(f, docBaseOrJarRoot);

        if (!f.isDirectory()) {
            throw new IllegalArgumentException(f + " is not a directory.");
        }

        return forFileSystem(f.toPath());
    }
1240567
@Override
  public String toSource() {
    return runInCompilerThread(
        () -> {
          Tracer tracer = newTracer("toSource");
          try {
            CodeBuilder cb = new CodeBuilder();
            if (jsRoot != null) {
              int i = 0;
              if (options.shouldPrintExterns()) {
                for (Node scriptNode = externsRoot.getFirstChild();
                    scriptNode != null;
                    scriptNode = scriptNode.getNext()) {
                  toSource(cb, i++, scriptNode);
                }
              }
              for (Node scriptNode = jsRoot.getFirstChild();
                  scriptNode != null;
                  scriptNode = scriptNode.getNext()) {
                toSource(cb, i++, scriptNode);
              }
            }
            return cb.toString();
          } finally {
            stopTracer(tracer, "toSource");
          }
        });
  }
28227
function getSourceCode(filepath) {
      // The current folder
      var dir = filepath.substring(0, filepath.lastIndexOf("/") + 1);

      // Regex for file import
      var fileRegex = /(?:["'])<!=\s*(.+)\b\s*!>(?:["'])?;?/;
      // Regex for file extension
      var fileExtRegex = /\..+$/;

      // Read the file and check if anything should be imported into it; loop through them
      return grunt.file.read(filepath).replace(new RegExp(fileRegex.source, "g"), function(match) {
        // Log the number of imports we did
        files += 1;

        // Get the filename
        var file = match.match(fileRegex)[1];

        // Check if it has an extension
        if(file.match(fileExtRegex) === null) {
          file += options.defaultExtension; // Add it
        }

        var source = "";

        // Loop through files
        glob.sync(dir + file).forEach(function(filename) {
          // Read file
          var src = grunt.file.read(filename);

          // Check if it has imports too
          source += (function() {
                return fileRegex.test(src) ? getSourceCode(filename) : src;
              })() + options.separator; // Add separator
        });
        return source;
      });
    }
1262285
function getSource() {
  var node = this.node;
  if (node.end) {
    return this.hub.file.code.slice(node.start, node.end);
  } else {
    return "";
  }
}
830585
function astFromFile(options, file, cb) {
  function convertSourceFile(file, packageName, packagePath) {
    fs.readFile(file, 'utf-8', function (err, source) {
      if (err) {
        return cb(err);
      }
      var extension = path.extname(file);
      if (extension[0] === '.') {
        extension = extension.substr(1);
      }
      astFromSource(options, source, extension, function (err, ast) {
        if (err) {
          err.file = file;
          return cb(err);
        }
        if (packageName) {
          ast.package = {name: packageName, path: packagePath};
          if (packagePath[0] !== '/') {
            ast.package.path = path.join(process.cwd(), packagePath);
          }
          ast.package.originalPath = packagePath;
        }
        ast.originalPath = file;
        if (file[0] === '/') {
          ast.path = file;
        } else {
          ast.path = path.join(process.cwd(), file);
        }
        return cb(null, ast);
      });
    });
  }

  function convertPackage() {
    if (path.basename(file) === 'package.json') {
      fs.readFile(file, 'utf-8', function (err, pkgString) {
        try {
          var pkg = JSON.parse(pkgString);
          if (!pkg.main) {
            return cb(new Error(file + " has no main modules."));
          }
          var main = path.join(path.dirname(file), pkg.main);
          if (!main.match(/\.js$/)) {
            main = main + '.js';
          }
          convertSourceFile(main, pkg.name, file);
        } catch (packageParseError) {
          packageParseError.message = 'Error parsing ' + file + ' - ' + packageParseError.message;
          return cb(packageParseError);
        }
      });
    } else {
      convertSourceFile(file, null);
    }
  }

  convertPackage();
}
257560
NameWithINode getSourceFile(String parity, String prefix) throws IOException {
    if (isHarFile(parity)) {
      return null;
    }
    // remove the prefix
    String src = parity.substring(prefix.length());
    byte[][] components = INodeDirectory.getPathComponents(src);
    INode inode = namesystem.dir.getINode(components);
    return new NameWithINode(src, inode);
  }
1235030
public static void readSourceFileAndWriteDestFile(final String srcfile, final String destFile)
		throws IOException
	{
		try (FileInputStream fis = new FileInputStream(srcfile);
			FileOutputStream fos = new FileOutputStream(destFile);
			BufferedInputStream bis = new BufferedInputStream(fis);
			BufferedOutputStream bos = new BufferedOutputStream(fos);)
		{
			final int availableLength = bis.available();
			final byte[] totalBytes = new byte[availableLength];
			bis.read(totalBytes, 0, availableLength);
			bos.write(totalBytes, 0, availableLength);
		}
	}
1295768
function listFile(docRoot) {

    return function (req, res, next) {
        //var folder = path.join(docRoot, req.baseUrl);
        var folder = path.join(docRoot, req.originalUrl);
        if (!fs.existsSync(folder)) {
            res.status(404).send('folder ' + folder + ' doesn\'t exist');
            return;
        }
        // TODO: decide if it is a file or folder
        var stat = fs.statSync(folder);
        if (!stat.isDirectory()) {
            folder = path.dirname(folder);
        }

        var markdown = {content: '', toc: ''};
        var dir = folderUtil.readDir(folder);

        if (stat.isDirectory() && dir.readMe) {
            markdown = render.withToc(fs.readFileSync(dir.readMe, {encoding: 'UTF-8'}));
        }

        res.locals.dir = dir.files;
        res.locals.markdown = markdown;


        next();
    };
}
1163085
public Root parseRootDoc(RootDoc rootDoc) {
		Root rootNode = objectFactory.createRoot();

		for (ClassDoc classDoc : rootDoc.classes()) {
			PackageDoc packageDoc = classDoc.containingPackage();

			Package packageNode = packages.get(packageDoc.name());
			if (packageNode == null) {
				packageNode = parsePackage(packageDoc);
				packages.put(packageDoc.name(), packageNode);
				rootNode.getPackage().add(packageNode);
			}

			if (classDoc instanceof AnnotationTypeDoc) {
				packageNode.getAnnotation().add(parseAnnotationTypeDoc((AnnotationTypeDoc) classDoc));
			} else if (classDoc.isEnum()) {
				packageNode.getEnum().add(parseEnum(classDoc));
			} else if (classDoc.isInterface()) {
				packageNode.getInterface().add(parseInterface(classDoc));
			} else {
				packageNode.getClazz().add(parseClass(classDoc));
			}
		}

		return rootNode;
	}
1074893
function getHeaderCodeAsScriptTags(root) {
    var ret = "";
    headerSources.forEach(function (src) {
        if (root) {
            src = path.join(root, src);
        }
        src = path.resolve(src);
        ret += "<script src=\"" + src + "\"></script>";
    });
    return ret;
}