本文整理了Java中net.roboconf.core.utils.Utils.createDirectory()
方法的一些代码示例,展示了Utils.createDirectory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.createDirectory()
方法的具体详情如下:
包路径:net.roboconf.core.utils.Utils
类名称:Utils
方法名:createDirectory
[英]Creates a directory if it does not exist.
[中]创建一个不存在的目录。
代码示例来源:origin: net.roboconf/roboconf-doc-generator
@Override
protected File writeFileContent( String fileContent ) throws IOException {
File targetFile = new File( this.outputDirectory, "index.md" );
Utils.createDirectory( targetFile.getParentFile());
Utils.writeStringInto( fileContent.replaceAll( "\n{3,}", "\n\n" ), targetFile );
return targetFile;
}
}
代码示例来源:origin: roboconf/roboconf-platform
@Override
protected File writeFileContent( String fileContent ) throws IOException {
File targetFile = new File( this.outputDirectory, "index.md" );
Utils.createDirectory( targetFile.getParentFile());
Utils.writeStringInto( fileContent.replaceAll( "\n{3,}", "\n\n" ), targetFile );
return targetFile;
}
}
代码示例来源:origin: net.roboconf/roboconf-agent
/**
* Copies the resources of an instance on the disk.
* @param instance an instance
* @param fileNameToFileContent the files to write down (key = relative file location, value = file's content)
* @throws IOException if the copy encountered a problem
*/
public static void copyInstanceResources( Instance instance, Map<String,byte[]> fileNameToFileContent )
throws IOException {
File dir = InstanceHelpers.findInstanceDirectoryOnAgent( instance );
Utils.createDirectory( dir );
if( fileNameToFileContent != null ) {
for( Map.Entry<String,byte[]> entry : fileNameToFileContent.entrySet()) {
File f = new File( dir, entry.getKey());
Utils.createDirectory( f.getParentFile());
ByteArrayInputStream in = new ByteArrayInputStream( entry.getValue());
Utils.copyStream( in, f );
}
}
}
代码示例来源:origin: net.roboconf/roboconf-dm
/**
* Constructor.
*/
public ConfigurationMngrImpl() {
String karafData = System.getProperty( Constants.KARAF_DATA );
if( Utils.isEmptyOrWhitespaces( karafData ))
this.workingDirectory = new File( System.getProperty( "java.io.tmpdir" ), "roboconf-dm" );
else
this.workingDirectory = new File( karafData, "roboconf" );
try {
Utils.createDirectory( this.workingDirectory );
} catch( IOException e ) {
this.logger.severe( "The DM's configuration directory could not be found and/or created." );
Utils.logException( this.logger, e );
}
}
代码示例来源:origin: net.roboconf/roboconf-dm
@Override
public void createOrUpdateCommand( Application app, String commandName, String commandText ) throws IOException {
File cmdFile = findCommandFile( app, commandName );
Utils.createDirectory( cmdFile.getParentFile());
Utils.writeStringInto( commandText, cmdFile );
}
代码示例来源: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: net.roboconf/roboconf-doc-generator
@Override
protected File writeFileContent(String fileContent) throws IOException {
// Load the template
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = getClass().getResourceAsStream( "/fop.tpl" );
Utils.copyStreamSafely( in, out );
//Copy the header in outputDirectory
InputStream h = getClass().getResourceAsStream( "/roboconf.jpg" );
File imgFile = new File( this.outputDirectory, "header.jpg" );
Utils.copyStream( h, imgFile );
// Create the target directory
File targetFile = new File( this.outputDirectory, "index.fo" );
Utils.createDirectory( targetFile.getParentFile());
// Write the main file
String toWrite = out.toString( "UTF-8" )
.replace( TITLE_MARKUP, this.applicationTemplate.getName())
.replace( CONTENT_MARKUP, fileContent )
.replace( "header.jpg", this.outputDirectory.getAbsolutePath() + "/header.jpg" )
.replace( "png/", this.outputDirectory.getAbsolutePath() + "/png/" )
.replaceAll( "\n{3,}", "\n\n" );
Utils.writeStringInto( toWrite, targetFile );
return targetFile;
}
代码示例来源:origin: net.roboconf/roboconf-dm
/**
* Saves the instances into a file.
* @param app the application (not null)
* @param configurationDirectory the configuration directory
*/
public static void saveInstances( Application app ) {
File targetFile = new File( app.getDirectory(), Constants.PROJECT_DIR_INSTANCES + "/" + INSTANCES_FILE );
try {
Utils.createDirectory( targetFile.getParentFile());
RuntimeModelIo.writeInstances( targetFile, app.getRootInstances());
} catch( IOException e ) {
Logger logger = Logger.getLogger( ConfigurationUtils.class.getName());
logger.severe( "Failed to save instances. " + e.getMessage());
Utils.logException( logger, e );
}
}
代码示例来源:origin: roboconf/roboconf-platform
@Override
protected File writeFileContent(String fileContent) throws IOException {
// Load the template
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = getClass().getResourceAsStream( "/fop.tpl" );
Utils.copyStreamSafely( in, out );
//Copy the header in outputDirectory
InputStream h = getClass().getResourceAsStream( "/roboconf.jpg" );
File imgFile = new File( this.outputDirectory, "header.jpg" );
Utils.copyStream( h, imgFile );
// Create the target directory
File targetFile = new File( this.outputDirectory, "index.fo" );
Utils.createDirectory( targetFile.getParentFile());
// Write the main file
String toWrite = out.toString( "UTF-8" )
.replace( TITLE_MARKUP, this.applicationTemplate.getName())
.replace( CONTENT_MARKUP, fileContent )
.replace( "header.jpg", this.outputDirectory.getAbsolutePath() + "/header.jpg" )
.replace( "png/", this.outputDirectory.getAbsolutePath() + "/png/" )
.replaceAll( "\n{3,}", "\n\n" );
Utils.writeStringInto( toWrite, targetFile );
return targetFile;
}
代码示例来源:origin: net.roboconf/roboconf-dm
private void processMsgNotifLogs( MsgNotifLogs message ) {
StringBuilder path = new StringBuilder();
path.append( "roboconf-logs/" );
path.append( message.getApplicationName());
path.append( "/" );
path.append( DockerAndScriptUtils.cleanInstancePath( message.getScopedInstancePath()));
// Dump these messages in the temporary directory...
File dumpDir = new File( this.tmpDir, path.toString());
try {
Utils.createDirectory( dumpDir );
for( Map.Entry<String,byte[]> entry : message.getLogFiles().entrySet()) {
ByteArrayInputStream in = new ByteArrayInputStream( entry.getValue());
Utils.copyStream( in, new File( dumpDir, entry.getKey()));
}
} catch( IOException e ) {
StringBuilder sb = new StringBuilder();
sb.append( "An error occurred while dumping logs from agent " );
sb.append( message.getScopedInstancePath());
sb.append( " @ " );
sb.append( message.getApplicationName());
sb.append( ". " );
if( ! Utils.isEmptyOrWhitespaces( e.getMessage()))
sb.append( e.getMessage());
this.logger.severe( sb.toString());
Utils.logException( this.logger, e );
}
}
代码示例来源:origin: roboconf/roboconf-platform
/**
* Creates a simple project for Roboconf.
* @param targetDirectory the directory into which the Roboconf files must be copied
* @param creationBean the creation properties
* @throws IOException if something went wrong
*/
private static void createSimpleProject( File targetDirectory, CreationBean creationBean )
throws IOException {
// Create the directory structure
String[] directoriesToCreate = creationBean.isReusableRecipe() ? RR_DIRECTORIES : ALL_DIRECTORIES;
for( String s : directoriesToCreate ) {
File dir = new File( targetDirectory, s );
Utils.createDirectory( dir );
}
// Create the descriptor
InputStream in = ProjectUtils.class.getResourceAsStream( "/application-skeleton.props" );
ByteArrayOutputStream out = new ByteArrayOutputStream();
Utils.copyStreamSafely( in, out );
String tpl = out.toString( "UTF-8" )
.replace( TPL_NAME, creationBean.getProjectName())
.replace( TPL_VERSION, creationBean.getProjectVersion())
.replace( TPL_DESCRIPTION, creationBean.getProjectDescription());
// Create the rest of the project
completeProjectCreation( targetDirectory, tpl, creationBean );
}
代码示例来源:origin: roboconf/roboconf-platform
/**
* Creates the recipes directories for a Roboconf components.
* @param applicationDirectory the application directory
* @return a non-null list of the created directories
* @throws IOException if something went wrong
*/
public static List<File> createRecipeDirectories( File applicationDirectory ) throws IOException {
List<File> result = new ArrayList<> ();
ApplicationLoadResult alr = RuntimeModelIo.loadApplicationFlexibly( applicationDirectory );
if( alr.getApplicationTemplate() != null ) {
for( Component c : ComponentHelpers.findAllComponents( alr.getApplicationTemplate())) {
File directory = ResourceUtils.findInstanceResourcesDirectory( applicationDirectory, c );
if( ! directory.exists())
result.add( directory );
Utils.createDirectory( directory );
}
}
return result;
}
代码示例来源:origin: net.roboconf/roboconf-doc-generator
/**
* Generates and saves an image.
* @param comp the component to highlight in the image
* @param type the kind of relation to show in the diagram
* @param transformer a transformer for the graph generation
* @param sb the string builder to append the link to the generated image
* @throws IOException if something went wrong
*/
private void saveImage( final Component comp, DiagramType type, AbstractRoboconfTransformer transformer, StringBuilder sb )
throws IOException {
String baseName = comp.getName() + "_" + type; //$NON-NLS-1$
String relativePath = "png/" + baseName + ".png"; //$NON-NLS-1$ //$NON-NLS-2$
if( this.options.containsKey( DocConstants.OPTION_GEN_IMAGES_ONCE ))
relativePath = "../" + relativePath;
File pngFile = new File( this.outputDirectory, relativePath ).getCanonicalFile();
if( ! pngFile.exists()) {
Utils.createDirectory( pngFile.getParentFile());
GraphUtils.writeGraph(
pngFile,
comp,
transformer.getConfiguredLayout(),
transformer.getGraph(),
transformer.getEdgeShapeTransformer(),
this.options );
}
sb.append( renderImage( comp.getName(), type, relativePath ));
}
代码示例来源:origin: roboconf/roboconf-platform
/**
* Generates and saves an image.
* @param comp the component to highlight in the image
* @param type the kind of relation to show in the diagram
* @param transformer a transformer for the graph generation
* @param sb the string builder to append the link to the generated image
* @throws IOException if something went wrong
*/
private void saveImage( final Component comp, DiagramType type, AbstractRoboconfTransformer transformer, StringBuilder sb )
throws IOException {
String baseName = comp.getName() + "_" + type; //$NON-NLS-1$
String relativePath = "png/" + baseName + ".png"; //$NON-NLS-1$ //$NON-NLS-2$
if( this.options.containsKey( DocConstants.OPTION_GEN_IMAGES_ONCE ))
relativePath = "../" + relativePath;
File pngFile = new File( this.outputDirectory, relativePath ).getCanonicalFile();
if( ! pngFile.exists()) {
Utils.createDirectory( pngFile.getParentFile());
GraphUtils.writeGraph(
pngFile,
comp,
transformer.getConfiguredLayout(),
transformer.getGraph(),
transformer.getEdgeShapeTransformer(),
this.options );
}
sb.append( renderImage( comp.getName(), type, relativePath ));
}
代码示例来源:origin: roboconf/roboconf-platform
@Test( expected = IOException.class )
public void testCreateDirectory_error() throws Exception {
File dir = this.folder.newFolder();
File target = new File( dir, "toto/pom" );
Assert.assertTrue( target.getParentFile().createNewFile());
Utils.createDirectory( target );
}
代码示例来源:origin: net.roboconf/roboconf-dm
@Override
public void updateApplication( ManagedApplication ma, String newDesc ) throws IOException {
// Basic checks
this.messagingMngr.checkMessagingConfiguration();
// Update it
Application app = ma.getApplication();
app.setDescription( newDesc );
File targetDirectory = app.getDirectory();
File descFile = new File( targetDirectory, Constants.PROJECT_DIR_DESC + "/" + Constants.PROJECT_FILE_DESCRIPTOR );
Utils.createDirectory( descFile.getParentFile());
ApplicationDescriptor.save( descFile, app );
// Notify listeners
this.notificationMngr.application( ma.getApplication(), EventType.CHANGED );
this.logger.fine( "The description of application " + ma.getApplication().getName() + " was successfully updated." );
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testCreateDirectory() throws Exception {
File dir = this.folder.newFolder();
File target = new File( dir, "toto/pom" );
Utils.createDirectory( target );
Assert.assertTrue( target.exists());
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testParseTargetProperties_ok() throws Exception {
File dir = new File( this.folder.newFolder(), Constants.PROJECT_DIR_GRAPH + "/c" );
Utils.createDirectory( dir );
Utils.writeStringInto( "id: tid1\nhandler: in", new File( dir, "t1.properties" ));
List<ModelError> errors = TargetValidator.parseTargetProperties( dir.getParentFile().getParentFile(), new Component( "c" ));
Assert.assertEquals( 1, errors.size());
Assert.assertEquals( ErrorCode.REC_TARGET_NO_NAME, errors.get( 0 ).getErrorCode());
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testParseTargetProperties_noFile() throws Exception {
File dir = new File( this.folder.newFolder(), Constants.PROJECT_DIR_GRAPH + "/c" );
Utils.createDirectory( dir );
List<ModelError> errors = TargetValidator.parseTargetProperties( dir, new Component( "c" ));
Assert.assertEquals( 0, errors.size());
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testParseTargetProperties_noProperties() throws Exception {
File dir = new File( this.folder.newFolder(), Constants.PROJECT_DIR_GRAPH + "/c" );
Utils.createDirectory( dir );
Utils.writeStringInto( "id: tid1\nhandler: in", new File( dir, "t1.not-properties" ));
List<ModelError> errors = TargetValidator.parseTargetProperties( dir, new Component( "c" ));
Assert.assertEquals( 0, errors.size());
}
}
内容来源于网络,如有侵权,请联系作者删除!