net.roboconf.core.utils.Utils.listAllFiles()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(15.7k)|赞(0)|评价(0)|浏览(177)

本文整理了Java中net.roboconf.core.utils.Utils.listAllFiles()方法的一些代码示例,展示了Utils.listAllFiles()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.listAllFiles()方法的具体详情如下:
包路径:net.roboconf.core.utils.Utils
类名称:Utils
方法名:listAllFiles

Utils.listAllFiles介绍

[英]Equivalent to listAllFiles( directory, false ).
[中]相当于listAllFiles( directory, false )

代码示例

代码示例来源:origin: roboconf/roboconf-platform

/**
 * Equivalent to <code>listAllFiles( directory, false )</code>.
 * @param directory an existing directory
 * @return a non-null list of files
 */
public static List<File> listAllFiles( File directory ) {
  return listAllFiles( directory, false );
}

代码示例来源:origin: net.roboconf/roboconf-dm

@Override
public List<String> listCommands( Application app ) {
  List<String> result = new ArrayList<> ();
  File cmdDir = new File( app.getDirectory(), Constants.PROJECT_DIR_COMMANDS );
  if( cmdDir.isDirectory()) {
    for( File f : Utils.listAllFiles( cmdDir )) {
      if( f.getName().endsWith( Constants.FILE_EXT_COMMANDS )) {
        String cmdName = f.getName().replace( Constants.FILE_EXT_COMMANDS, "" );
        result.add( cmdName );
      }
    }
  }
  return result;
}

代码示例来源:origin: roboconf/roboconf-platform

/**
   * Parses the target properties for a given component.
   * @param projectDirectory the project's directory
   * @param c a component
   * @return a non-null list of errors
   */
  public static List<ModelError> parseTargetProperties( File projectDirectory, Component c ) {

    List<ModelError> errors;
    File dir = ResourceUtils.findInstanceResourcesDirectory( projectDirectory, c );
    if( dir.isDirectory()
        && ! Utils.listAllFiles( dir, Constants.FILE_EXT_PROPERTIES ).isEmpty())
      errors = parseDirectory( dir, c );
    else
      errors = new ArrayList<>( 0 );

    return errors;
  }
}

代码示例来源:origin: net.roboconf/roboconf-agent

/**
 * Executes a script resource on a given instance.
 * @param scriptsDir the scripts directory
 * @throws IOException
 */
public static void executeScriptResources( File scriptsDir ) throws IOException {
  if( scriptsDir.isDirectory()) {
    List<File> scriptFiles = Utils.listAllFiles( scriptsDir );
    Logger logger = Logger.getLogger( AgentUtils.class.getName());
    for( File script : scriptFiles) {
      if( script.getName().contains( Constants.SCOPED_SCRIPT_AT_AGENT_SUFFIX )) {
        script.setExecutable( true );
        String[] command = { script.getAbsolutePath()};
        try {
          ProgramUtils.executeCommand( logger, command, script.getParentFile(), null, null, null );
        } catch( InterruptedException e ) {
          Utils.logException( logger, e );
        }
      }
    }
  }
}

代码示例来源:origin: net.roboconf/roboconf-dm

@Override
public File findScriptForDm( AbstractApplication app, Instance scopedInstance ) {
  File result = null;
  String targetId = findTargetId( app, InstanceHelpers.computeInstancePath( scopedInstance ));
  if( targetId != null ) {
    File targetDir = new File( findTargetDirectory( targetId ), Constants.PROJECT_SUB_DIR_SCRIPTS );
    if( targetDir.isDirectory()){
      for( File f : Utils.listAllFiles( targetDir )) {
        if( f.getName().toLowerCase().contains( Constants.SCOPED_SCRIPT_AT_DM_CONFIGURE_SUFFIX )) {
          result = f;
          break;
        }
      }
    }
  }
  return result;
}

代码示例来源:origin: net.roboconf/roboconf-dm-scheduler

@Override
public List<ScheduledJob> listJobs() {
  this.logger.fine( "Roboconf's scheduler is listing jobs..." );
  List<ScheduledJob> result = new ArrayList<> ();
  for( File f : Utils.listAllFiles( getSchedulerDirectory(), Constants.FILE_EXT_PROPERTIES )) {
    Properties props = Utils.readPropertiesFileQuietly( f, this.logger );
    if( props.isEmpty())
      continue;
    // Inject the ID in the properties
    props.put( JOB_ID, Utils.removeFileExtension( f.getName()));
    ScheduledJob job = from( props );
    result.add( job );
  }
  Collections.sort( result );
  return result;
}

代码示例来源:origin: roboconf/roboconf-platform

/**
 * Validates a component associated with the Puppet installer.
 * @param applicationFilesDirectory the application's directory
 * @param component the component
 * @return a non-null list of errors
 */
private static List<ModelError> validateScriptComponent( File applicationFilesDirectory, Component component ) {
  List<ModelError> result = new ArrayList<> ();
  // There must be a "scripts" directory
  File directory = ResourceUtils.findInstanceResourcesDirectory( applicationFilesDirectory, component );
  List<File> subDirs = Utils.listAllFiles( directory );
  if( !subDirs.isEmpty()) {
    File scriptsDir = new File( directory, SCRIPTS_DIR_NAME );
    if( ! scriptsDir.exists())
      result.add( new ModelError( ErrorCode.REC_SCRIPT_NO_SCRIPTS_DIR, component, component( component )));
  }
  return result;
}

代码示例来源:origin: net.roboconf/roboconf-dm-scheduler

@Override
public void loadJobs() {
  this.logger.fine( "Roboconf's scheduler is loading jobs..." );
  for( File f : Utils.listAllFiles( getSchedulerDirectory(), Constants.FILE_EXT_PROPERTIES )) {
    try {
      Properties props = Utils.readPropertiesFileQuietly( f, this.logger );
      // Inject the ID in the properties
      props.setProperty( JOB_ID, Utils.removeFileExtension( f.getName()));
      // Validate and reload
      if( validProperties( props ))
        scheduleJob( props );
      else
        this.logger.warning( "Skipped schedule for a job. There are invalid or missing job properties in " + f.getName());
    } catch( Exception e ) {
      // Catch ALL the exceptions. #start() cannot fail.
      this.logger.warning( "Failed to load a scheduled job from " + f.getName());
      Utils.logException( this.logger, e );
    }
  }
}

代码示例来源:origin: roboconf/roboconf-platform

@Test( expected = IllegalArgumentException.class )
public void testListAllFiles_inexistingFile() throws Exception {
  Utils.listAllFiles( new File( "not/existing/file" ));
}

代码示例来源:origin: roboconf/roboconf-platform

/**
 * Copies a directory.
 * <p>
 * This method copies the content of the source directory
 * into the a target directory. This latter is created if necessary.
 * </p>
 *
 * @param source the directory to copy
 * @param target the target directory
 * @throws IOException if a problem occurred during the copy
 */
public static void copyDirectory( File source, File target ) throws IOException {
  Utils.createDirectory( target );
  for( File sourceFile : listAllFiles( source, false )) {
    String path = computeFileRelativeLocation( source, sourceFile );
    File targetFile = new File( target, path );
    Utils.createDirectory( targetFile.getParentFile());
    copyStream( sourceFile, targetFile );
  }
}

代码示例来源:origin: roboconf/roboconf-platform

@Test
public void testListAllFiles_withFileExtension() throws Exception {
  File dir = this.folder.newFolder();
  Assert.assertTrue( new File( dir, "f1.txt" ).createNewFile());
  Assert.assertTrue( new File( dir, "f2.jpg" ).createNewFile());
  Assert.assertTrue( new File( dir, "f3.txt" ).createNewFile());
  Assert.assertTrue( new File( dir, "f4.JPG" ).createNewFile());
  Assert.assertTrue( new File( dir, "f5.zip" ).createNewFile());
  Assert.assertEquals( 2, Utils.listAllFiles( dir, "jpg" ).size());
  Assert.assertEquals( 2, Utils.listAllFiles( dir, ".jpg" ).size());
  Assert.assertEquals( 2, Utils.listAllFiles( dir, "jPg" ).size());
  Assert.assertEquals( 2, Utils.listAllFiles( dir, "txt" ).size());
  Assert.assertEquals( 1, Utils.listAllFiles( dir, ".zip" ).size());
  Assert.assertEquals( 5, Utils.listAllFiles( dir, null ).size());
}

代码示例来源:origin: roboconf/roboconf-platform

@Test
public void testListAllFilesAndDirectories() throws Exception {
  final File tempDir = this.folder.newFolder( "roboconf_test" );
  String[] paths = new String[] { "dir1", "dir2", "dir1/dir3", "dir4" };
  for( String path : paths ) {
    if( ! new File( tempDir, path ).mkdir())
      throw new IOException( "Failed to create " + path );
  }
  paths = new String[] { "dir1/toto.txt", "dir2/script.sh", "dir1/dir3/smart.png" };
  for( String path : paths ) {
    if( ! new File( tempDir, path ).createNewFile())
      throw new IOException( "Failed to create " + path );
  }
  List<File> files = Utils.listAllFiles( tempDir, true );
  // 7 files and directories, mentioned previously, plus the root directory.
  Assert.assertEquals( 8, files.size());
  for( String path : paths )
    Assert.assertTrue( path, files.contains( new File( tempDir, path )));
}

代码示例来源:origin: roboconf/roboconf-platform

@Test
public void testListAllFiles() throws Exception {
  final File tempDir = this.folder.newFolder( "roboconf_test" );
  String[] paths = new String[] { "dir1", "dir2", "dir1/dir3" };
  for( String path : paths ) {
    if( ! new File( tempDir, path ).mkdir())
      throw new IOException( "Failed to create " + path );
  }
  paths = new String[] { "dir1/toto.txt", "dir2/script.sh", "dir1/dir3/smart.png" };
  for( String path : paths ) {
    if( ! new File( tempDir, path ).createNewFile())
      throw new IOException( "Failed to create " + path );
  }
  List<File> files = Utils.listAllFiles( tempDir );
  Assert.assertEquals( 3, files.size());
  for( String path : paths )
    Assert.assertTrue( path, files.contains( new File( tempDir, path )));
}

代码示例来源:origin: roboconf/roboconf-platform

@Test( expected = IllegalArgumentException.class )
public void testListAllFiles_invalidParameter() throws Exception {
  Utils.listAllFiles( this.folder.newFile( "roboconf.txt" ));
}

代码示例来源:origin: roboconf/roboconf-platform

@Test
public void testCopyDirectory_existingTarget() throws Exception {
  // Create a source
  File source = this.folder.newFolder();
  File dir1 = new File( source, "lol/whatever/sub" );
  Assert.assertTrue( dir1.mkdirs());
  File dir2 = new File( source, "sub" );
  Assert.assertTrue( dir2.mkdirs());
  Utils.copyStream( new ByteArrayInputStream( ",kklmsdff sdfl sdfkkl".getBytes( "UTF-8" )), new File( dir1, "f1" ));
  Utils.copyStream( new ByteArrayInputStream( "".getBytes( "UTF-8" )), new File( dir1, "f2" ));
  Utils.copyStream( new ByteArrayInputStream( "sd".getBytes( "UTF-8" )), new File( dir1, "f3" ));
  Utils.copyStream( new ByteArrayInputStream( "sd\ndsfg".getBytes( "UTF-8" )), new File( source, "f" ));
  Utils.copyStream( new ByteArrayInputStream( "sd\ndsfg".getBytes( "UTF-8" )), new File( dir2, "f1" ));
  Utils.copyStream( new ByteArrayInputStream( "sdf df fg".getBytes( "UTF-8" )), new File( dir2, "f45678" ));
  // Copy
  File target = this.folder.newFolder();
  Assert.assertEquals( 0, Utils.listAllFiles( target ).size());
  Utils.copyDirectory( source, target );
  Assert.assertEquals( 6, Utils.listAllFiles( target ).size());
}

代码示例来源:origin: roboconf/roboconf-platform

@Test
public void testCopyDirectory_inexistingTarget() throws Exception {
  // Create a source
  File source = this.folder.newFolder();
  File dir1 = new File( source, "lol/whatever/sub/many/more/" );
  Assert.assertTrue( dir1.mkdirs());
  File dir2 = new File( source, "sub" );
  Assert.assertTrue( dir2.mkdirs());
  Utils.copyStream( new ByteArrayInputStream( ",kklmsdff sdfl sdfkkl".getBytes( "UTF-8" )), new File( dir1, "f1" ));
  Utils.copyStream( new ByteArrayInputStream( "".getBytes( "UTF-8" )), new File( dir1, "f2" ));
  Utils.copyStream( new ByteArrayInputStream( "sd".getBytes( "UTF-8" )), new File( dir1, "f3" ));
  Utils.copyStream( new ByteArrayInputStream( "sd\ndsfg".getBytes( "UTF-8" )), new File( source, "f" ));
  Utils.copyStream( new ByteArrayInputStream( "sd\ndsfg".getBytes( "UTF-8" )), new File( dir2, "f1" ));
  Utils.copyStream( new ByteArrayInputStream( "".getBytes( "UTF-8" )), new File( dir2, "f4" ));
  Utils.copyStream( new ByteArrayInputStream( "sdf df fg".getBytes( "UTF-8" )), new File( dir2, "f45678" ));
  // Copy
  File target = new File( this.folder.newFolder(), "some" );
  Assert.assertFalse( target.exists());
  Utils.copyDirectory( source, target );
  Assert.assertTrue( target.exists());
  Assert.assertEquals( 7, Utils.listAllFiles( target ).size());
}

代码示例来源:origin: roboconf/roboconf-platform

@Test
public void testExtractZipArchive() throws Exception {
  // Prepare the original ZIP
  File zipFile = this.folder.newFile( "roboconf_test.zip" );
  Map<String,String> entryToContent = TestUtils.buildZipContent();
  TestUtils.createZipFile( entryToContent, zipFile );
  TestUtils.compareZipContent( zipFile, entryToContent );
  // Prepare the output directory
  File existingDirectory = this.folder.newFolder( "roboconf_test" );
  Assert.assertTrue( existingDirectory.exists());
  Assert.assertEquals( 0, Utils.listAllFiles( existingDirectory ).size());
  // Extract
  Utils.extractZipArchive( zipFile, existingDirectory );
  // And compare
  Assert.assertNotSame( 0, Utils.listAllFiles( existingDirectory ).size());
  Map<String,String> fileToContent = Utils.storeDirectoryResourcesAsString( existingDirectory );
  for( Map.Entry<String,String> entry : fileToContent.entrySet()) {
    Assert.assertTrue( entryToContent.containsKey( entry.getKey()));
    String value = entryToContent.remove( entry.getKey());
    Assert.assertEquals( entry.getValue(), value );
  }
  // Only directories should remain
  for( Map.Entry<String,String> entry : entryToContent.entrySet()) {
    Assert.assertNull( entry.getKey(), entry.getValue());
  }
}

代码示例来源:origin: roboconf/roboconf-platform

@Test
public void testExtractZipArchive_withOptions_invalidPrefix() throws Exception {
  // Prepare the original ZIP
  File zipFile = this.folder.newFile( "roboconf_test.zip" );
  Map<String,String> entryToContent = TestUtils.buildZipContent();
  TestUtils.createZipFile( entryToContent, zipFile );
  TestUtils.compareZipContent( zipFile, entryToContent );
  // Prepare the output directory
  File existingDirectory = this.folder.newFolder( "roboconf_test" );
  Assert.assertTrue( existingDirectory.exists());
  Assert.assertEquals( 0, Utils.listAllFiles( existingDirectory ).size());
  // Extract
  final String pattern = "graph/.*";
  Utils.extractZipArchive( zipFile, existingDirectory, pattern, "invalid/" );
  // And compare
  Assert.assertEquals( 3, Utils.listAllFiles( existingDirectory ).size());
  Map<String,String> fileToContent = Utils.storeDirectoryResourcesAsString( existingDirectory );
  for( Map.Entry<String,String> entry : fileToContent.entrySet()) {
    Assert.assertTrue( entryToContent.containsKey( entry.getKey()));
    String value = entryToContent.remove( entry.getKey());
    Assert.assertEquals( entry.getValue(), value );
  }
}

代码示例来源:origin: roboconf/roboconf-platform

@Test
public void testExtractZipArchive_inexistingDirectory() throws Exception {
  // Prepare the original ZIP
  File zipFile = this.folder.newFile( "roboconf_test.zip" );
  Map<String,String> entryToContent = TestUtils.buildZipContent();
  TestUtils.createZipFile( entryToContent, zipFile );
  // Prepare the output directory
  File unexistingDirectory = this.folder.newFolder( "roboconf_test" );
  if( ! unexistingDirectory.delete())
    throw new IOException( "Failed to delete a directory." );
  Assert.assertFalse( unexistingDirectory.exists());
  // Extract
  Utils.extractZipArchive( zipFile, unexistingDirectory );
  Assert.assertTrue( unexistingDirectory.exists());
  // And compare
  Assert.assertNotSame( 0, Utils.listAllFiles( unexistingDirectory ).size());
  Map<String,String> fileToContent = Utils.storeDirectoryResourcesAsString( unexistingDirectory );
  for( Map.Entry<String,String> entry : fileToContent.entrySet()) {
    Assert.assertTrue( entryToContent.containsKey( entry.getKey()));
    String value = entryToContent.remove( entry.getKey());
    Assert.assertEquals( entry.getValue(), value );
  }
  // Only directories should remain
  for( Map.Entry<String,String> entry : entryToContent.entrySet()) {
    Assert.assertNull( entry.getKey(), entry.getValue());
  }
}

代码示例来源:origin: roboconf/roboconf-platform

@Test
public void testExtractZipArchive_withOptions() throws Exception {
  // Prepare the original ZIP
  File zipFile = this.folder.newFile( "roboconf_test.zip" );
  Map<String,String> entryToContent = TestUtils.buildZipContent();
  TestUtils.createZipFile( entryToContent, zipFile );
  TestUtils.compareZipContent( zipFile, entryToContent );
  // Prepare the output directory
  File existingDirectory = this.folder.newFolder( "roboconf_test" );
  Assert.assertTrue( existingDirectory.exists());
  Assert.assertEquals( 0, Utils.listAllFiles( existingDirectory ).size());
  // Extract
  final String pattern = "graph/.*";
  Utils.extractZipArchive( zipFile, existingDirectory, pattern, "graph/" );
  // And compare
  Assert.assertNotSame( 0, Utils.listAllFiles( existingDirectory ).size());
  Map<String,String> fileToContent = Utils.storeDirectoryResourcesAsString( existingDirectory );
  Assert.assertEquals( 3, fileToContent.size());
  for( Map.Entry<String,String> entry : fileToContent.entrySet()) {
    Assert.assertTrue( entryToContent.containsKey( "graph/" + entry.getKey()));
    String value = entryToContent.remove( "graph/" + entry.getKey());
    Assert.assertEquals( entry.getValue(), value );
  }
}

相关文章