本文整理汇总了Java中org.codehaus.plexus.util.FileUtils.fileWrite方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.fileWrite方法的具体用法?Java FileUtils.fileWrite怎么用?Java FileUtils.fileWrite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.plexus.util.FileUtils
的用法示例。
在下文中一共展示了FileUtils.fileWrite方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createEnvWrapperFile
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
private File createEnvWrapperFile( File vsInstallDir, String platform )
throws IOException
{
File tmpFile = File.createTempFile( "msenv", ".bat" );
StringBuffer buffer = new StringBuffer();
buffer.append( "@echo off\r\n" );
buffer.append( "call \"" ).append( vsInstallDir ).append( "\"" ).append( "\\VC\\vcvarsall.bat " + platform
+ "\n\r" );
buffer.append( "echo " + EnvStreamConsumer.START_PARSING_INDICATOR ).append( "\r\n" );
buffer.append( "set\n\r" );
FileUtils.fileWrite( tmpFile.getAbsolutePath(), buffer.toString() );
return tmpFile;
}
示例2: insertPreWrapperConf
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
private void insertPreWrapperConf( File wrapperConf, File preWrapperConf )
throws DaemonGeneratorException
{
try
{
StringBuilder buffer = new StringBuilder();
buffer.append( FileUtils.fileRead( preWrapperConf ) );
buffer.append( "\n" );
buffer.append( FileUtils.fileRead( wrapperConf ) );
FileUtils.fileWrite( wrapperConf, buffer.toString() );
}
catch ( IOException e )
{
throw new DaemonGeneratorException( "Unable to merge pre wrapper config file." );
}
}
示例3: installSignChecksum
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
void installSignChecksum(Path pChecksumPath, Path pArchivePath, boolean pRepack) throws MojoExecutionException
{
String checksum = _calculateChecksum(pArchivePath, pRepack);
Path path = pChecksumPath.resolveSibling(pChecksumPath.getFileName() + _getPostfix());
log.debug("Installing checksum to " + path);
try
{
Files.createDirectories(path.getParent());
FileUtils.fileWrite(path.toFile(), "UTF-8", checksum);
}
catch (IOException e)
{
throw new MojoExecutionException("Failed to install checksum to " + path, e);
}
}
示例4: failLocalChangeItTest
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
@Test
@Ignore
// svn local db corrupted
public void failLocalChangeItTest()
throws Exception
{
File projDir = resources.getBasedir( "failed-local-change" );
MavenExecution mavenExec = maven.forProject( projDir );
MavenExecutionResult result = mavenExec.execute( "clean" );
result.assertErrorFreeLog();
File basedir = result.getBasedir();
File foo = new File( basedir, "foo.txt" );
FileUtils.fileWrite( foo, "hello" );
FileUtils.copyDirectory( new File( basedir, "DotSvnDir" ), new File( basedir, ".svn" ) );
result = mavenExec.execute( "verify" );
// this fail local dotSvnDir corrupted, not b/c we change local file
result.assertLogText( "BUILD FAILURE" );
}
示例5: gitBasicItMBUILDNUM66Test
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
@Test
@Ignore
// git local database corrected
public void gitBasicItMBUILDNUM66Test()
throws Exception
{
File projDir = resources.getBasedir( "git-basic-it-MBUILDNUM-66" );
MavenExecution mavenExec = maven.forProject( projDir );
MavenExecutionResult result = mavenExec.execute( "clean" );
result.assertErrorFreeLog();
File basedir = result.getBasedir();
File foo = new File( basedir, "foo.txt" );
FileUtils.fileWrite( foo, "hello" );
FileUtils.copyDirectory( new File( basedir, "dotGitDir" ), new File( basedir, ".git" ) );
result = mavenExec.execute( "verify" );
// this fail local dotSvnDir corrupted, not b/c we change local file
}
示例6: playActions
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
public void playActions() throws Exception {
for (FileSystemAction action : actions) {
if (action.kind == ENTRY_CREATE) {
FileUtils.fileWrite(action.path.toFile(), action.content);
} else if (action.kind == ENTRY_MODIFY) {
FileUtils.fileAppend(action.path.toFile().getAbsolutePath(), action.content);
action.path.toFile().setLastModified(new Date().getTime());
} else if (action.kind == ENTRY_DELETE) {
action.path.toFile().delete();
} else {
switch (action.myType) {
case WAIT:
try {
Thread.sleep(action.millis);
} catch (InterruptedException e) {
}
break;
case MKDIR:
if (!action.path.toFile().exists()) {
action.path.toFile().mkdirs();
}
break;
case COUNTABLE:
case NOOP:
break;
}
}
}
}
示例7: processToml
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
private List<String> processToml(
File tomlFile,
File templatesDirectory,
Map<String, String> env,
String encoding,
boolean mkdirs
) throws IOException {
Toml toml = new Toml().read(tomlFile);
String src = toml.getString("template.src");
String dest = toml.getString("template.dest");
List<String> keys = toml.getList("template.keys");
if (keys == null || keys.size() == 0) {
throw new IOException("Something went wrong while processing the toml file <" + tomlFile +
">: the 'keys' section must exist and contain at least one key");
}
// filter the env map according to the keys defined in the toml
HashMap<String, String> filteredEnv = new HashMap<String, String>();
for (Map.Entry<String, String> entry : env.entrySet()) {
for (String key : keys) {
if (entry.getKey().startsWith(key)) {
filteredEnv.put(entry.getKey(), entry.getValue());
}
}
}
File templateFile = new File(templatesDirectory, src);
File destFile = new File(dest);
if (mkdirs) {
destFile.getParentFile().mkdirs();
}
Parser parser = new Parser(templateFile, encoding);
String parsedTemplate = parser.parse(filteredEnv);
FileUtils.fileWrite(destFile, encoding, parsedTemplate);
return parser.getTemplateKeys();
}
示例8: writeToml
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
public static void writeToml(
File tomlFile,
TemplateConfig tc,
boolean globalForceDestToLocalFileSystemType) throws IOException {
StringWriter sw = new StringWriter();
sw.append("[template]")
.append(LINE_SEPARATOR);
sw.append("src = ")
.append(QUOTE)
.append(FileUtils.removePath(tc.getSrc().getPath()))
.append(QUOTE)
.append(LINE_SEPARATOR);
sw.append("dest = ")
.append(QUOTE)
.append(tc.getResolvedDestPath(globalForceDestToLocalFileSystemType))
.append(QUOTE)
.append(LINE_SEPARATOR);
sw.append("keys = [")
.append(LINE_SEPARATOR);
for (String key : tc.getKeys()) {
sw.append(QUOTE)
.append(key)
.append(QUOTE)
.append(',')
.append(LINE_SEPARATOR);
}
sw.append(']')
.append(LINE_SEPARATOR);
FileUtils.fileWrite(tomlFile, "UTF8", sw.toString());
}
示例9: createTestFile
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
protected File createTestFile(String[] lines) throws IOException {
StringBuilder sb = new StringBuilder();
for (String s : lines) {
sb.append(s).append('\n');
}
File f = temporaryFolder.newFile("test.dict");
FileUtils.fileWrite(f, ENCODING, sb.toString());
return f;
}
示例10: copyResource
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
private void copyResource(String source, File target, String separator, HashMap<String, String> interpolations) throws MojoExecutionException {
try {
String content = loadTextResource(getClass().getResource(source));
if( interpolations!=null ) {
content = StringUtils.interpolate(content, interpolations);
}
content = content.replaceAll("\\r?\\n", Matcher.quoteReplacement(separator));
FileUtils.fileWrite(target, content);
} catch (IOException e) {
throw new MojoExecutionException("Could create the "+target+" file", e);
}
}
示例11: createCassandraYaml
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
/**
* Generates the {@code cassandra.yaml} file.
*
* @param cassandraYaml the {@code cassandra.yaml} file.
* @param data The data directory.
* @param commitlog The commitlog directory.
* @param savedCaches The saved caches directory.
* @param listenAddress The address to listen on for storage and other cassandra servers.
* @param rpcAddress The address to listen on for clients.
* @param seeds The seeds.
* @throws IOException If something went wrong.
*/
private void createCassandraYaml( File cassandraYaml, File data, File commitlog, File savedCaches,
String listenAddress, String rpcAddress, BigInteger initialToken, String[] seeds )
throws IOException
{
String defaults = IOUtil.toString( getClass().getResourceAsStream( "/cassandra.yaml" ) );
StringBuilder config = new StringBuilder();
config.append( "data_file_directories:\n" ).append( " - " ).append( data.getAbsolutePath() ).append( "\n" );
config.append( "commitlog_directory: " ).append( commitlog ).append( "\n" );
config.append( "saved_caches_directory: " ).append( savedCaches ).append( "\n" );
config.append( "initial_token: " ).append(
initialToken == null || "null".equals( initialToken ) ? "" : initialToken.toString() ).append( "\n" );
config.append( "listen_address: " ).append( listenAddress ).append( "\n" );
config.append( "storage_port: " ).append( storagePort ).append( "\n" );
config.append( "rpc_address: " ).append( rpcAddress ).append( "\n" );
config.append( "rpc_port: " ).append( rpcPort ).append( "\n" );
config.append( "native_transport_port: " ).append( nativeTransportPort ).append( "\n" );
config.append( "start_native_transport: " ).append( startNativeTransport ).append( "\n" );
if ( seeds != null )
{
config.append( "seed_provider: " ).append( "\n" );
config.append( " - class_name: org.apache.cassandra.locator.SimpleSeedProvider" ).append( "\n" );
config.append( " parameters:" ).append( "\n" );
String sep = " - seeds: \"";
for ( int i = 0; i < seeds.length; i++ )
{
config.append( sep ).append( seeds[i] );
sep = ", ";
}
if ( sep.length() == 2 )
{
config.append( "\"" ).append( "\n" );
}
}
FileUtils.fileWrite( cassandraYaml.getAbsolutePath(),
Utils.merge( Utils.merge( defaults, yaml ), config.toString() ) );
}
示例12: fixIndirectLibraryReferences
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
/**
*
*
* @param projectDirectory
* @param dependentLibs
* @param log
* @throws Exception
*/
public void fixIndirectLibraryReferences(File projectDirectory, Collection<String> dependentLibs, Log log) throws Exception
{
File projectFile = new File(projectDirectory, ".project");
if (!projectFile.exists()) {
throw new Exception("unable to locate .project file at " + projectFile.getAbsolutePath());
}
String content = FileUtils.fileRead(projectFile);
String projectsStartTag = "<projects>";
String projectsEndTag = "</projects>";
String projectStartTag = "<project>";
String projectEndTag = "</project>";
// / just want to append the file at the right point
int insertionPoint = content.indexOf(projectsEndTag);
if (insertionPoint == -1)
{
log.info("unable to find " + projectsEndTag + " in .project file");
}
String firstPart = content.substring(0, insertionPoint);
String lastPart = content.substring(insertionPoint);
String projectsSection = content.substring(content.indexOf(projectsStartTag), insertionPoint);
boolean firstPartAppended = false;
for (String dependentLib : dependentLibs)
{
String libTagNeeded = projectStartTag + dependentLib + projectEndTag;
if (!projectsSection.contains(libTagNeeded))
{
firstPartAppended = true;
firstPart += "\t" + libTagNeeded;
log.info("adding direct project reference " + libTagNeeded + " to " + projectFile.getAbsolutePath());
}
}
if (firstPartAppended)
{
firstPart += "\n\t";
}
else
{
log.info("no dependent libraries fix needed for " + projectFile.getAbsolutePath());
}
content = firstPart + lastPart;
FileUtils.fileWrite(projectFile, content);
}
示例13: writeTargetToProjectFile
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
/**
* Write the ant target and surrounding tags to a temporary file
*
* @throws PlexusConfigurationException
*/
private File writeTargetToProjectFile()
throws IOException, PlexusConfigurationException {
// Have to use an XML writer because in Maven 2.x the PlexusConfig toString() method loses XML attributes
StringWriter writer = new StringWriter();
AntrunXmlPlexusConfigurationWriter xmlWriter = new AntrunXmlPlexusConfigurationWriter();
xmlWriter.write(target, writer);
StringBuffer antProjectConfig = writer.getBuffer();
// replace deprecated tasks tag with standard Ant target
stringReplace(antProjectConfig, "<tasks", "<target");
stringReplace(antProjectConfig, "</tasks", "</target");
antTargetName = target.getAttribute("name");
if (antTargetName == null) {
antTargetName = DEFAULT_ANT_TARGET_NAME;
stringReplace(antProjectConfig, "<target", "<target name=\"" + antTargetName + "\"");
}
String xmlns = "";
if (!customTaskPrefix.trim().equals("")) {
xmlns = "xmlns:" + customTaskPrefix + "=\"" + TASK_URI + "\"";
}
final String xmlHeader = "<?xml version=\"1.0\" encoding=\"" + UTF_8 + "\" ?>\n";
antProjectConfig.insert(0, xmlHeader);
final String projectOpen = "<project name=\"maven-antrun-\" default=\"" + antTargetName + "\" " + xmlns + " >\n";
int index = antProjectConfig.indexOf("<target");
antProjectConfig.insert(index, projectOpen);
final String projectClose = "\n</project>";
antProjectConfig.append(projectClose);
// The fileName should probably use the plugin executionId instead of the targetName
String fileName = "build-" + antTargetName + ".xml";
File file = new File(project.getBuild().getDirectory(), "/antrun/" + fileName);
file.getParentFile().mkdirs();
FileUtils.fileWrite(file.getAbsolutePath(), UTF_8, antProjectConfig.toString());
return file;
}