public void run ( File outputFolder , File templateLocationFolder , String templateType ) throws Exception { if ( ! outputFolder . canWrite ( ) ) { throw new Exception ( "Output folder is not writeable!" ) ; } File [ ] contents = outputFolder . listFiles ( ) ; boolean safe = true ; if ( contents != null ) { for ( File content : contents ) { if ( content . isDirectory ( ) ) { if ( content . getName ( ) . equalsIgnoreCase ( config . getTemplateFolderName ( ) ) ) { safe = false ; } if ( content . getName ( ) . equalsIgnoreCase ( config . getContentFolderName ( ) ) ) { safe = false ; } if ( content . getName ( ) . equalsIgnoreCase ( config . getAssetFolderName ( ) ) ) { safe = false ; } } } } if ( ! safe ) { throw new Exception ( String . format ( "Output folder '%s' already contains structure!" , outputFolder . getAbsolutePath ( ) ) ) ; } if ( config . getExampleProjectByType ( templateType ) != null ) { File templateFile = new File ( templateLocationFolder , config . getExampleProjectByType ( templateType ) ) ; if ( ! templateFile . exists ( ) ) { throw new Exception ( "Cannot find example project file: " + templateFile . getPath ( ) ) ; } ZipUtil . extract ( new FileInputStream ( templateFile ) , outputFolder ) ; } else { throw new Exception ( "Cannot locate example project type: " + templateType ) ; } }
Performs checks on output folder before extracting template file