当前位置: 首页>>代码示例>>Java>>正文


Java FileUtil类代码示例

本文整理汇总了Java中jetbrains.buildServer.util.FileUtil的典型用法代码示例。如果您正苦于以下问题:Java FileUtil类的具体用法?Java FileUtil怎么用?Java FileUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileUtil类属于jetbrains.buildServer.util包,在下文中一共展示了FileUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeToTempFile

import jetbrains.buildServer.util.FileUtil; //导入依赖的package包/类
@NotNull
private File writeToTempFile(@NotNull final File buildTempDir,
                             @NotNull final String text,
                             @NotNull final  Map<String, String> runnerParameters) throws RunBuildException {
  Closeable handle = null;
  File file;
  try {
    file = FileUtil.createTempFile(buildTempDir, "powershell", ".ps1", true);
    OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(file), "utf-8");
    handle = w;
    if (PowerShellExecutionMode.PS1 == PowerShellExecutionMode.fromString(runnerParameters.get(RUNNER_EXECUTION_MODE))) {
      w.write(BOM);
    }
    w.write(text);
    return file;
  } catch (IOException e) {
    LOG.error("Error occurred while processing file for PowerShell script", e);
    throw new RunBuildException("Failed to generate temporary resulting PowerShell script due to exception", e);
  } finally {
    FileUtil.close(handle);
  }
}
 
开发者ID:JetBrains,项目名称:teamcity-powershell,代码行数:23,代码来源:ScriptGenerator.java

示例2: should_run_simple_command_file_ps1

import jetbrains.buildServer.util.FileUtil; //导入依赖的package包/类
@Test(dataProvider = "supportedBitnessProvider")
@TestFor(issues = "TW-29803")
public void should_run_simple_command_file_ps1(@NotNull final PowerShellBitness bits) throws Throwable {
  final File dir = createTempDir();
  final File code = new File(dir, "code.ps1");
  FileUtil.writeFileAndReportErrors(code, "echo works");

  setRunnerParameter(PowerShellConstants.RUNNER_EXECUTION_MODE, PowerShellExecutionMode.PS1.getValue());
  setRunnerParameter(PowerShellConstants.RUNNER_SCRIPT_MODE, PowerShellScriptMode.FILE.getValue());
  setRunnerParameter(PowerShellConstants.RUNNER_SCRIPT_FILE, code.getPath());
  setRunnerParameter(PowerShellConstants.RUNNER_BITNESS, bits.getValue());

  final SFinishedBuild build = doTest(null);
  dumpBuildLogLocally(build);
  Assert.assertTrue(build.getBuildStatus().isSuccessful());

  Assert.assertTrue(getBuildLog(build).contains("works"));
}
 
开发者ID:JetBrains,项目名称:teamcity-powershell,代码行数:19,代码来源:PowerShellIntegrationTests.java

示例3: testOutputIsWrittenFromScriptInFile

import jetbrains.buildServer.util.FileUtil; //导入依赖的package包/类
@Test(dataProvider = "supportedBitnessProvider")
@TestFor(issues = "TW-34775")
public void testOutputIsWrittenFromScriptInFile(@NotNull final PowerShellBitness bits) throws Throwable {
  final File dir = createTempDir();
  final File code = new File(dir, "code.ps1");
  FileUtil.writeFileAndReportErrors(code,
      "param ([string]$PowerShellParam = \"value\",)\n" +
          "Write-Host \"String from Write-Host\"\n" +
          "Write-Output \"String from Write-Output\"\n" +
          "Write-Host \"Function call from Write-Host $((Get-Date -Year 2000 -Month 12 -Day 31).DayOfYear)\"\n" +
          "Write-Output \"Function call from Write-Output $((Get-Date -Year 2000 -Month 12 -Day 31).DayOfYear)\"\n"
  );

  setRunnerParameter(PowerShellConstants.RUNNER_EXECUTION_MODE, PowerShellExecutionMode.STDIN.getValue());
  setRunnerParameter(PowerShellConstants.RUNNER_SCRIPT_MODE, PowerShellScriptMode.FILE.getValue());
  setRunnerParameter(PowerShellConstants.RUNNER_SCRIPT_FILE, code.getPath());
  setRunnerParameter(PowerShellConstants.RUNNER_BITNESS, bits.getValue());

  final SFinishedBuild build = doTest(null);
  dumpBuildLogLocally(build);
  Assert.assertTrue(build.getBuildStatus().isSuccessful());
  Assert.assertTrue(getBuildLog(build).contains("String from Write-Host"));
  Assert.assertTrue(getBuildLog(build).contains("String from Write-Output"));
  Assert.assertTrue(getBuildLog(build).contains("Function call from Write-Host 366"));
  Assert.assertTrue(getBuildLog(build).contains("Function call from Write-Output 366"));
}
 
开发者ID:JetBrains,项目名称:teamcity-powershell,代码行数:27,代码来源:PowerShellIntegrationTests.java

示例4: patch

import jetbrains.buildServer.util.FileUtil; //导入依赖的package包/类
public void patch(File symbolsFile, BuildProgressLogger buildLogger) throws Exception {
  final Collection<File> sourceFiles = mySrcToolExe.getReferencedSourceFiles(symbolsFile);
  final String symbolsFileCanonicalPath = symbolsFile.getCanonicalPath();
  if(sourceFiles.isEmpty()){
    final String message = "No source information found in pdb file " + symbolsFileCanonicalPath;
    buildLogger.warning(message);
    LOG.debug(message);
    return;
  }
  final File tmpFile = FileUtil.createTempFile(myWorkingDir, "pdb-", ".patch", false);
  int processedFilesCount = mySrcSrvStreamBuilder.dumpStreamToFile(tmpFile, sourceFiles);
  if(processedFilesCount == 0){
    buildLogger.warning(String.format("Sources appeared in file %s weren't actually indexed. Looks like related binary file wasn't built during current build.", symbolsFileCanonicalPath));
  } else {
    buildLogger.message(String.format("Information about %d source files was updated", processedFilesCount));
  }
  myPdbStrExe.doCommand(PdbStrExeCommands.WRITE, symbolsFile, tmpFile, PdbStrExe.SRCSRV_STREAM_NAME);
}
 
开发者ID:JetBrains,项目名称:teamcity-symbol-server,代码行数:19,代码来源:PdbFilePatcher.java

示例5: assertCollectionsTransferred

import jetbrains.buildServer.util.FileUtil; //导入依赖的package包/类
public static void assertCollectionsTransferred(File remoteBase, List<ArtifactsCollection> artifactsCollections) throws IOException {

    for (ArtifactsCollection artifactsCollection : artifactsCollections) {
      for (Map.Entry<File, String> fileStringEntry : artifactsCollection.getFilePathMap().entrySet()) {
        final File source = fileStringEntry.getKey();
        final String relativePath = fileStringEntry.getValue();
        final String targetPath = relativePath + (StringUtil.isNotEmpty(relativePath) ? File.separator : "") + source.getName();
        final File target;
        if (new File(targetPath).isAbsolute()) {
          target = new File(targetPath);
        } else {
          target = new File(remoteBase, targetPath);
        }
        assertTrue(target.exists(), "Destination file [" + targetPath + "] does not exist");
        assertEquals(FileUtil.readText(target), FileUtil.readText(source), "wrong content");
      }
    }
  }
 
开发者ID:JetBrains,项目名称:teamcity-deployer-plugin,代码行数:19,代码来源:DeployTestUtils.java

示例6: getCustomScriptExecutable

import jetbrains.buildServer.util.FileUtil; //导入依赖的package包/类
private String getCustomScriptExecutable(AnsibleRunConfig config) throws RunBuildException {
    String content = null;
    File scriptFile = null;
    if (config.getSourceCode() != null) {
        content = config.getSourceCode().replace("\r\n", "\n").replace("\r", "\n");
    }
    if (StringUtil.isEmptyOrSpaces(content)) {
        throw new RunBuildException("Custom script source code cannot be empty");
    }
    try {
        scriptFile = File.createTempFile("ansible_custom_exe", null, getBuildTempDirectory());
        FileUtil.writeFileAndReportErrors(scriptFile, content);
    } catch (IOException e) {
        throw new RunBuildException("Failed to create a tmp file for custom ansible execution script");
    }
    boolean executable = scriptFile.setExecutable(true, true);
    if (!executable) {
        throw new RunBuildException("Failed to set executable permissions to " + scriptFile.getAbsolutePath());
    }
    return scriptFile.getAbsolutePath();
}
 
开发者ID:andreizhuk,项目名称:tc-ansible-runner,代码行数:22,代码来源:AnsibleRunService.java

示例7: save

import jetbrains.buildServer.util.FileUtil; //导入依赖的package包/类
public synchronized void save()
{
	this.myChangeObserver.runActionWithDisabledObserver(new Runnable()
	{
		public void run()
		{
			FileUtil.processXmlFile(YammerNotificationMainConfig.this.myConfigFile, new FileUtil.Processor() {
				public void process(Element rootElement) {
					rootElement.setAttribute("enabled", Boolean.toString(YammerNotificationMainConfig.this.enabled));
					rootElement.setAttribute("token", emptyIfNull(YammerNotificationMainConfig.this.token));
					rootElement.setAttribute("appKey", emptyIfNull(YammerNotificationMainConfig.this.appKey));
					rootElement.setAttribute("secretKey", emptyIfNull(YammerNotificationMainConfig.this.secretKey));
					rootElement.setAttribute("userName", emptyIfNull(YammerNotificationMainConfig.this.userName));
					rootElement.setAttribute("password", emptyIfNull(YammerNotificationMainConfig.this.password));
					rootElement.setAttribute("groupId", emptyIfNull(YammerNotificationMainConfig.this.groupId));
				}
			});
		}
	});
}
 
开发者ID:iguissouma,项目名称:teamcity-yammer-notifier,代码行数:21,代码来源:YammerNotificationMainConfig.java

示例8: VmwareCloudImage

import jetbrains.buildServer.util.FileUtil; //导入依赖的package包/类
public VmwareCloudImage(@NotNull final VMWareApiConnector apiConnector,
                        @NotNull final VmwareCloudImageDetails imageDetails,
                        @NotNull final CloudAsyncTaskExecutor asyncTaskExecutor,
                        @NotNull final File idxStorage,
                        @NotNull final CloudProfile profile) {
  super(imageDetails.getSourceId(), imageDetails.getSourceId());
  myImageDetails = imageDetails;
  myApiConnector = apiConnector;
  myAsyncTaskExecutor = asyncTaskExecutor;
  myProfile = profile;
  myActualSourceState = new AtomicReference<>();
  myIdxFile = new File(idxStorage, imageDetails.getSourceId() + ".idx");
  if (!myIdxFile.exists()){
    try {
      FileUtil.writeFileAndReportErrors(myIdxFile, "1");
    } catch (IOException e) {
      LOG.warn(String.format("Unable to write idx file '%s': %s", myIdxFile.getAbsolutePath(), e.toString()));
    }
  }
}
 
开发者ID:JetBrains,项目名称:teamcity-vmware-plugin,代码行数:21,代码来源:VmwareCloudImage.java

示例9: executeCommandLine

import jetbrains.buildServer.util.FileUtil; //导入依赖的package包/类
@NotNull
@Override
public BuildProcess executeCommandLine(@NotNull BuildRunnerContext hostContext,
                                       @NotNull Collection<String> argz,
                                       @NotNull File workingDir,
                                       @NotNull Map<String, String> additionalEnvironment) throws RunBuildException {
  final List<String> processed = new ArrayList<String>();
  for (String arg : argz) {
    processed.add(
            arg
                    .replace(home.getPath(), "!HOME!")
                    .replace(work.getPath(), "!WORK!")
                    .replace(FileUtil.getRelativePath(home, work), "!REL_WORK!")
    );
  }

  System.out.println("cmd>> " + processed);
  return cmd.executeCommandLine(hostContext, processed, workingDir, additionalEnvironment);
}
 
开发者ID:jonnyzzz,项目名称:TeamCity.Virtual,代码行数:20,代码来源:DockerTest.java

示例10: loadDescriptor

import jetbrains.buildServer.util.FileUtil; //导入依赖的package包/类
@NotNull
public SoftDescriptor loadDescriptor(@NotNull final InputStream inputStream, String name) {
  final SoftDescriptor sd = new SoftDescriptor(name);

  readXmlFile(inputStream, new FileUtil.Processor()
  {
    @Override
    public void process(Element element)
    {

      loadDescriptorContent(sd, element);

    }
  });

  return sd;
}
 
开发者ID:leo-from-spb,项目名称:teamcity-soft-installer,代码行数:18,代码来源:ModelLoader.java

示例11: readXmlFile

import jetbrains.buildServer.util.FileUtil; //导入依赖的package包/类
public static void readXmlFile(@NotNull final File file, @NotNull final FileUtil.Processor p) {
  if (!file.exists()) throw new IllegalArgumentException("The file \""+file.getAbsolutePath()+"\" doesn't exist");

  try {
    final FileInputStream fis = new FileInputStream(file);
    try {
      readXmlFile(fis, p);
    }
    finally {
      fis.close();
    }
  }
  catch (IOException ioe) {
    throw new RuntimeException("Failed to read XML file \"" + file.getAbsolutePath() +"\": " + ioe.getMessage(), ioe);
  }
}
 
开发者ID:leo-from-spb,项目名称:teamcity-soft-installer,代码行数:17,代码来源:Xml.java

示例12: VSONotificatorConfig

import jetbrains.buildServer.util.FileUtil; //导入依赖的package包/类
public VSONotificatorConfig(@NotNull ServerPaths serverPaths) throws IOException {
  final File configDir = new File(serverPaths.getConfigDir(), FreeMarkerHelper.TEMPLATES_ROOT + "/" + Constants.NOTIFICATOR_TYPE);
  configDir.mkdirs();
  myConfigFile = new File(configDir, CONFIG_FILENAME);
  FileUtil.copyResourceIfNotExists(getClass(), "/message_templates/" + CONFIG_FILENAME, myConfigFile);
  reloadConfiguration();

  copyMessageTemplates(configDir);

  myChangeObserver = new FileWatcher(myConfigFile);
  myChangeObserver.setSleepingPeriod(10000);
  myChangeObserver.registerListener(this);
  myChangeObserver.start();

  myConfiguration = FreeMarkerHelper.getConfiguration(serverPaths);
}
 
开发者ID:JetBrains,项目名称:tc-vso-rooms,代码行数:17,代码来源:VSONotificatorConfig.java

示例13: download

import jetbrains.buildServer.util.FileUtil; //导入依赖的package包/类
protected byte[] download(final String urlString) throws IOException {
  final HttpMethod getMethod = new GetMethod(urlString);
  InputStream in = null;
  try {
    myHttpClient.executeMethod(getMethod);
    if (getMethod.getStatusCode() != HttpStatus.SC_OK) {
      throw new IOException(String.format("Problem [%d] while downloading %s: %s", getMethod.getStatusCode(), urlString, getMethod.getStatusText()));
    }
    in = getMethod.getResponseBodyAsStream();
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    StreamUtil.copyStreamContent(in, bOut);
    return bOut.toByteArray();
  } finally {
    FileUtil.close(in);
    getMethod.releaseConnection();
  }
}
 
开发者ID:JetBrains,项目名称:teamcity-torrent-plugin,代码行数:18,代码来源:TorrentTransportFactory.java

示例14: test_cleanup

import jetbrains.buildServer.util.FileUtil; //导入依赖的package包/类
public void test_cleanup() throws IOException {
  List<File> torrents = createTorrentFiles();

  File randomTorrentFile = torrents.get(torrents.size() / 2);
  mySeeder.registerSrcAndTorrentFile(createTempFile(), randomTorrentFile, true);

  myFakeAgentIdleTasks.getTask().execute(new InterruptState() {
    public boolean isInterrupted() {
      return false;
    }
  });

  Collection<File> actualTorrentFiles = FileUtil.findFiles(new FileFilter() {
    public boolean accept(File pathname) {
      return pathname.getName().endsWith(".torrent");
    }
  }, myTorrentsDir);

  assertEquals(1, actualTorrentFiles.size());
  assertTrue(actualTorrentFiles.contains(randomTorrentFile));
}
 
开发者ID:JetBrains,项目名称:teamcity-torrent-plugin,代码行数:22,代码来源:TorrentFilesFactoryTest.java

示例15: loadConfiguration

import jetbrains.buildServer.util.FileUtil; //导入依赖的package包/类
private void loadConfiguration(@NotNull File configFile) {
  Properties properties = new Properties();
  FileReader fileReader = null;
  try {
    fileReader = new FileReader(configFile);
    properties.load(fileReader);
    if (properties.get(DOWNLOAD_ENABLED) == null) {
      properties.put(DOWNLOAD_ENABLED, Boolean.FALSE.toString());
    }
    myConfiguration = properties;
  } catch (IOException e) {
    Loggers.SERVER.warn("Failed to load configuration file: " + configFile.getAbsolutePath() + ", error: " + e.toString());
  } finally {
    FileUtil.close(fileReader);
  }
}
 
开发者ID:JetBrains,项目名称:teamcity-torrent-plugin,代码行数:17,代码来源:TorrentConfigurator.java


注:本文中的jetbrains.buildServer.util.FileUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。