判断并生成最新的版本目录
@param getDir
2705
function existDir(getDir) {
        fs.exists(getDir, (exists) => {
            if (exists) {
                existDir(`${dir}/${getVersion()}`);
            } else {
                callBack(_baseVersion.join('.'));
            }
        });
    }
581437
protected function createVersionDirectory($versionDirectory)
    {
        if (! $this->filesystem->isDirectory($versionDirectory)) {
            $this->filesystem->makeDirectory($versionDirectory, 0755, true);

            return true;
        }

        return false;
    }
1137314
private function cloneToBuildDir($buildDir)
    {
        $gitRoot = $this->gitHelper->getRoot($this->appRoot, true);
        $ref = $this->gitHelper->execute(['rev-parse', 'HEAD'], $gitRoot, true);

        $cloneArgs = ['--recursive', '--shared'];
        $tmpRepo = $buildDir . '-repo';
        if (file_exists($tmpRepo)) {
            $this->fsHelper->remove($tmpRepo, true);
        }
        $this->gitHelper->cloneRepo($gitRoot, $tmpRepo, $cloneArgs, true);
        $this->gitHelper->checkOut($ref, $tmpRepo, true, true);
        $this->fsHelper->remove($tmpRepo . '/.git');

        $appDir = $tmpRepo . '/' . substr($this->appRoot, strlen($gitRoot));
        if (!rename($appDir, $buildDir)) {
            throw new \RuntimeException(sprintf('Failed to move app from %s to %s', $appDir, $buildDir));
        }
        $this->fsHelper->remove($tmpRepo);
    }
120136
protected static void checkDirectory(boolean generateSouceOnly, File sourceOutputDir) {
        if (generateSouceOnly) {
            if (sourceOutputDir == null) {
                throw new RuntimeException("param 'sourceOutputDir' is null.");
            }

            if (!sourceOutputDir.isDirectory()) {
                throw new RuntimeException("param 'sourceOutputDir' should be a exist file directory.");
            }
        }
    }
361398
@VisibleForTesting
  static File getFile(String[] localDirs, int subDirsPerLocalDir, String filename) {
    int hash = JavaUtils.nonNegativeHash(filename);
    String localDir = localDirs[hash % localDirs.length];
    int subDirId = (hash / localDirs.length) % subDirsPerLocalDir;
    return new File(createNormalizedInternedPathname(
        localDir, String.format("%02x", subDirId), filename));
  }
1064421
@Override
    public DirectoryStream<Path> newDirectoryStream(final Path dir, final Filter<? super Path> filter)
        throws IOException {
        final FileSystem fs = dir.getFileSystem();
        if (!(fs instanceof ShrinkWrapFileSystem)) {
            throw new IllegalArgumentException("Expected ShrinkWrap File System for Path: " + dir.toString());
        }
        return new ShrinkWrapDirectoryStream(dir, (ShrinkWrapFileSystem) fs, filter);
    }
69415
public static String generateCacheFileFullPath(String url, File cacheDir) {
		String fileName = md5(url);
		File cacheFile = new File(cacheDir, fileName);
		return cacheFile.getPath();
	}
301875
public static boolean checkVersionDirName(File versionDir) {
        return (versionDir.isDirectory() && versionDir.getName().contains("version-") && !versionDir.getName()
                                                                                                    .endsWith(".bak"));
    }
1156861
public static void createDirectory(final String directory) {
        if (directory == null) return;
        final File f = new File(directory);
        if (!f.isDirectory()) {
            if (!f.mkdir()) throw new RuntimeException("couldn't create "
                    + directory);
        }
    }
267257
def _prepare_workdir(self):
    """"""
    pants_jar_base_dir = os.path.join(self.versioned_workdir, 'cache')
    safe_mkdir(pants_jar_base_dir)
    return pants_jar_base_dir
368731
public static function getCachingClient($cacheDir = null)
	{
		$client = new Cached(self::getClient());
		$client->cacheDir = (isset($cacheDir)) ? $cacheDir : sys_get_temp_dir();

		return $client;
	}
1246319
function(filesArr) {
		// 读取package.json，将里面内容生成头信息
		var data = fs.readFileSync('./package.json', 'utf8');
		var packageObj = JSON.parse( data );

		var headerStr = '/** \r\n';
			headerStr += ' * ' + packageObj.name + ' v' + packageObj.version + '\r\n';
			headerStr += ' * ' + packageObj.description + '\r\n';
			headerStr += ' * author : ' + packageObj.author + '\r\n';
			headerStr += ' * homepage : ' + packageObj.homepage + '\r\n';
			headerStr += ' * bugs : ' + packageObj.bugs.url + '\r\n';
			headerStr += ' **/ \r\n';


		for (var i = 0; i < filesArr.length; i++){
			var filePath = filesArr[i]
			var data = fs.readFileSync(filePath, 'utf8');
			data = headerStr  + data;
			fs.writeFileSync(filePath, data);
		}
	}
79873
public static boolean createOrCleanDirectory(String directory) {
    // if the directory does not exist, create it.
    if (!FileUtils.isDirectoryExists(directory)) {
      LOG.fine("The directory does not exist; creating it.");
      if (!FileUtils.createDirectory(directory)) {
        LOG.severe("Failed to create directory: " + directory);
        return false;
      }
    }

    // Cleanup the directory
    if (!FileUtils.cleanDir(directory)) {
      LOG.severe("Failed to clean directory: " + directory);
      return false;
    }

    return true;
  }
118619
private void initOutputDir(File outputDir) {

        if (!outputDir.exists()) {
            if (!outputDir.mkdirs()) {
                throw new IllegalArgumentException("Output Directory "+outputDir+" could not be created");
            }
        }
        if (!outputDir.isDirectory() || (!outputDir.canWrite())) {
            throw new IllegalArgumentException("Output Directory "+outputDir+" is not a directory or cannot be written to.");
        }
    }
76646
static Resource getFile(Resource rootDir, String strDir, String defaultDir, Resource configDir, short type, ConfigImpl config) {
	strDir = replacePlaceholder(strDir, config);
	if (!StringUtil.isEmpty(strDir, true)) {
	    Resource res;
	    if (strDir.indexOf("://") != -1) { // TODO better impl.
		res = getFile(config.getResource(strDir), type);
		if (res != null) return res;
	    }
	    res = rootDir == null ? null : getFile(rootDir.getRealResource(strDir), type);
	    if (res != null) return res;

	    res = getFile(config.getResource(strDir), type);
	    if (res != null) return res;
	}
	if (defaultDir == null) return null;
	Resource file = getFile(configDir.getRealResource(defaultDir), type);
	return file;
    }
55408
public void setOutputDirectory( String outputDirectory ) {

		// Update the configuration
		this.logger.fine( "Output directory is now... " + outputDirectory );
		this.outputDIR = Utils.isEmptyOrWhitespaces( outputDirectory ) ? null : new File( outputDirectory );

		// Generate the files
		if( this.outputDIR != null && this.dm != null ) {
			for( ManagedApplication ma : this.dm.applicationMngr().getManagedApplications())
				application( ma.getApplication(), EventType.CHANGED );
		}
	}


	/**
	 * Binds the DM.
	 * @param dm
	 */
	public void bindManager( Manager dm ) {

		synchronized( this.generationLock ) {
			this.logger.fine( "The DM is now available in the templating manager." );
			this.dm = dm;
		}
	}


	/**
	 * Unbinds the DM.
	 * @param dm
	 */
	public void unbindManager( Manager dm ) {

		synchronized( this.generationLock ) {
			this.logger.fine( "The DM is NOT available anymore in the templating manager." );
			this.dm = null;
		}
	}


	// iPojo life cycle


	/**
	 * Starts the templating manager (invoked by iPojo).
	 */
	public void start() {

		synchronized( this.watcherLock ) {
			this.logger.config( "The templating manager is starting..." );
			resetWatcher();
		}
	}


	/**
	 * Stops the templating manager (invoked by iPojo).
	 */
	public void stop() {

		synchronized( this.watcherLock ) {
			this.logger.config( "The templating manager is stopping..." );
			stopWatcher();
		}
	}


	// Inherited methods


	/*
	 * (non-Javadoc)
	 * @see net.roboconf.dm.management.events.IDmListener#getId()
	 */
	@Override
	public String getId() {
		return ID;
	}


	/* (non-Javadoc)
	 * @see net.roboconf.dm.management.events.IDmListener
	 * #application(net.roboconf.core.model.beans.Application, net.roboconf.dm.management.events.EventType)
	 */
	@Override
	public void application( Application application, EventType eventType ) {

		if( this.outputDIR == null ) {
			this.logger.warning( "Generation from templates is skipped. Invalid output directory." );

		} else if( eventType == EventType.DELETED ) {
			synchronized( this.generationLock ) {
				TemplateUtils.deleteGeneratedFiles( application, this.outputDIR );
			}

		} else {
			generate( application );
		}
	}


	/* (non-Javadoc)
	 * @see net.roboconf.dm.management.events.IDmListener
	 * #applicationTemplate(net.roboconf.core.model.beans.ApplicationTemplate, net.roboconf.dm.management.events.EventType)
	 */
	@Override
	public void applicationTemplate( ApplicationTemplate tpl, EventType eventType ) {
		// nothing
	}


	/*
	 * (non-Javadoc)
	 * @see net.roboconf.dm.management.events.IDmListener
	 * #instance(net.roboconf.core.model.beans.Instance, net.roboconf.core.model.beans.Application, net.roboconf.dm.management.events.EventType)
	 */
	@Override
	public void instance( Instance instance, Application application, EventType eventType ) {
		application( application, EventType.CHANGED );
	}


	/* (non-Javadoc)
	 * @see net.roboconf.dm.management.events.IDmListener
	 * #raw(java.lang.String, java.lang.Object[])
	 */
	@Override
	public void raw( String message, Object... data ) {
		// nothing
	}


	/*
	 * (non-Javadoc)
	 * @see net.roboconf.dm.management.events.IDmListener
	 * #enableNotifications()
	 */
	@Override
	public void enableNotifications() {
		// nothing
	}


	/*
	 * (non-Javadoc)
	 * @see net.roboconf.dm.management.events.IDmListener
	 * #disableNotifications()
	 */
	@Override
	public void disableNotifications() {
		// nothing
	}
876140
public static void mkdirs(File directory) throws CreateDirectoryException {
    if (directory.exists()) {
      // file exists and *is* a directory
      if (directory.isDirectory()) {
        return;
      }

      // file exists, but is not a directory - delete it
      if (!directory.delete()) {
        throw new CreateDirectoryException(
            directory.getAbsolutePath(),
            new FileDeleteException(directory.getAbsolutePath()));
      }
    }

    // doesn't exist. Create one
    if (!directory.mkdirs() && !directory.isDirectory()) {
      throw new CreateDirectoryException(directory.getAbsolutePath());
    }
  }