當前位置: 首頁>>代碼示例>>Java>>正文


Java FileUtil.ensureExists方法代碼示例

本文整理匯總了Java中com.intellij.openapi.util.io.FileUtil.ensureExists方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtil.ensureExists方法的具體用法?Java FileUtil.ensureExists怎麽用?Java FileUtil.ensureExists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.openapi.util.io.FileUtil的用法示例。


在下文中一共展示了FileUtil.ensureExists方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createProjectJarSubFile

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@NotNull
protected VirtualFile createProjectJarSubFile(String relativePath, Pair<ByteSequence, String>... contentEntries) throws IOException {
  assertTrue("Use 'jar' extension for JAR files: '" + relativePath + "'", FileUtilRt.extensionEquals(relativePath, "jar"));
  File f = new File(getProjectPath(), relativePath);
  FileUtil.ensureExists(f.getParentFile());
  FileUtil.ensureCanCreateFile(f);
  final boolean created = f.createNewFile();
  if (!created) {
    throw new AssertionError("Unable to create the project sub file: " + f.getAbsolutePath());
  }

  Manifest manifest = new Manifest();
  manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
  JarOutputStream target = new JarOutputStream(new FileOutputStream(f), manifest);
  for (Pair<ByteSequence, String> contentEntry : contentEntries) {
    addJarEntry(contentEntry.first.getBytes(), contentEntry.second, target);
  }
  target.close();

  final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f);
  assertNotNull(virtualFile);
  final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(virtualFile);
  assertNotNull(jarFile);
  return jarFile;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:ExternalSystemTestCase.java

示例2: perform

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@NotNull
@Override
protected File perform(@NotNull ProgressIndicator indicator, @NotNull File destination) throws WizardException {
  indicator.setText("Installing Android SDK");
  try {
    FileUtil.ensureExists(destination);
    if (!FileUtil.filesEqual(destination.getCanonicalFile(), myRepo.getCanonicalFile())) {
      SdkMerger.mergeSdks(myRepo, destination, indicator);
      myRepoWasMerged = true;
    }
    myContext.print(String.format("Android SDK was installed to %1$s\n", destination), ConsoleViewContentType.SYSTEM_OUTPUT);
    return destination;
  }
  catch (IOException e) {
    throw new WizardException(e.getMessage(), e);
  }
  finally {
    indicator.stop();
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:21,代碼來源:InstallComponentsPath.java

示例3: createEmptyJar

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public static void createEmptyJar(@NotNull String dir, @NotNull String name) throws IOException {
  File jar = new File(dir, name);
  FileUtil.ensureExists(jar.getParentFile());
  IoTestUtil.createTestJar(jar);

  MessageDigest digest;
  try {
    digest = MessageDigest.getInstance("SHA1");
  }
  catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
  }
  digest.update(FileUtil.loadFileBytes(jar));
  byte[] sha1 = digest.digest();

  PrintWriter out = new PrintWriter(new File(dir, name + ".sha1"), "UTF-8");
  try {
    for (byte b : sha1) out.printf("%02x", b);
    out.println("  " + name);
  }
  finally {
    out.close();
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:25,代碼來源:ArtifactsDownloadingTestCase.java

示例4: ensureTempDirCreated

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private void ensureTempDirCreated() throws IOException {
  if (ourTempDir != null) return;

  ourTempDir = new File(FileUtil.getTempDirectory(), getTestsTempDir());
  FileUtil.delete(ourTempDir);
  FileUtil.ensureExists(ourTempDir);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:8,代碼來源:ExternalSystemTestCase.java

示例5: createProjectSubFile

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
protected VirtualFile createProjectSubFile(String relativePath) throws IOException {
  File f = new File(getProjectPath(), relativePath);
  FileUtil.ensureExists(f.getParentFile());
  FileUtil.ensureCanCreateFile(f);
  final boolean created = f.createNewFile();
  if(!created) {
    throw new AssertionError("Unable to create the project sub file: " + f.getAbsolutePath());
  }
  return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:11,代碼來源:ExternalSystemTestCase.java

示例6: ensureTempDirExists

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static void ensureTempDirExists() {
  // Gradle checks that the dir at "java.io.tmpdir" exists, and if it doesn't it fails (on Windows.)
  String tmpDirProperty = System.getProperty("java.io.tmpdir");
  if (!Strings.isNullOrEmpty(tmpDirProperty)) {
    File tmpDir = new File(tmpDirProperty);
    try {
      FileUtil.ensureExists(tmpDir);
    }
    catch (IOException e) {
      LOG.warn("Unable to create temp directory", e);
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:14,代碼來源:AndroidGradleTargetBuilder.java

示例7: ensureTempDirCreated

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static void ensureTempDirCreated() throws IOException {
  if (ourTempDir != null) return;

  ourTempDir = new File(FileUtil.getTempDirectory(), "gradleTests");
  FileUtil.delete(ourTempDir);
  FileUtil.ensureExists(ourTempDir);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:8,代碼來源:AbstractModelBuilderTest.java

示例8: ensureTempDirCreated

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private void ensureTempDirCreated() throws IOException {
  if (ourTempDir != null) return;

  ourTempDir = new File(FileUtil.getTempDirectory(), "mavenTests");
  FileUtil.delete(ourTempDir);
  FileUtil.ensureExists(ourTempDir);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:8,代碼來源:MavenTestCase.java

示例9: setUp

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Before
@Override
public void setUp() throws Exception {
  super.setUp();
  ensureTempDirCreated();

  myTestDir = new File(ourTempDir, getTestName(false));
  FileUtil.ensureExists(myTestDir);

  setUpFixtures();
  myProject = myTestFixture.getProject();

  edt(new Runnable() {
    @Override
    public void run() {
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        @Override
        public void run() {
          try {
            setUpInWriteAction();
          }
          catch (Throwable e) {
            try {
              tearDown();
            }
            catch (Exception e1) {
              e1.printStackTrace();
            }
            throw new RuntimeException(e);
          }
        }
      });
    }
  });

  ArrayList<String> allowedRoots = new ArrayList<String>();
  collectAllowedRoots(allowedRoots);
  registerAllowedRoots(allowedRoots, myTestRootDisposable);

  CompilerTestUtil.enableExternalCompiler();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:42,代碼來源:ExternalSystemTestCase.java

示例10: setUpInWriteAction

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
protected void setUpInWriteAction() throws Exception {
  File projectDir = new File(myTestDir, "project");
  FileUtil.ensureExists(projectDir);
  myProjectRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(projectDir);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:6,代碼來源:ExternalSystemTestCase.java

示例11: createProjectSubDir

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
protected VirtualFile createProjectSubDir(String relativePath) throws IOException {
  File f = new File(getProjectPath(), relativePath);
  FileUtil.ensureExists(f);
  return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:6,代碼來源:ExternalSystemTestCase.java

示例12: copy

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static void copy(@NotNull File src, @NotNull File dest, ConfigImportSettings settings, File oldInstallationHome) throws IOException {
  src = src.getCanonicalFile();
  dest = dest.getCanonicalFile();
  if (!src.isDirectory()) {
    throw new IOException(ApplicationBundle.message("config.import.invalid.directory.error", src.getAbsolutePath()));
  }
  if (!dest.isDirectory()) {
    throw new IOException(ApplicationBundle.message("config.import.invalid.directory.error", dest.getAbsolutePath()));
  }
  if (FileUtil.filesEqual(src, dest)) {
    return;
  }

  FileUtil.ensureExists(dest);

  File[] childFiles = src.listFiles(new FilenameFilter() {
    @Override
    public boolean accept(@NotNull File dir, @NotNull String name) {
      // Don't copy plugins just imported. They're most probably incompatible with newer idea version.
      return !StringUtil.startsWithChar(name, '.') && !name.equals(PLUGINS_PATH);
    }
  });

  if (childFiles == null || childFiles.length == 0) {
    return;
  }

  for (File from : childFiles) {
    File to = new File(dest, from.getName());
    if (from.isDirectory()) {
      FileUtil.copyDir(from, to, false);
    }
    else {
      FileUtil.copy(from, to);
    }
  }

  File plugins = new File(src, PLUGINS_PATH);
  if (!loadOldPlugins(plugins, dest) && SystemInfo.isMac) {
    File oldPluginsDir = getOldPath(oldInstallationHome, settings, PathManager.PROPERTY_PLUGINS_PATH,
                                    new Function<String, String>() {
                                      @Override
                                      public String fun(String pathSelector) {
                                        return PathManager.getDefaultPluginPathFor(pathSelector);
                                      }
                                    });
    if (oldPluginsDir == null) {
      //e.g. installation home referred to config home. Try with default selector, same as config name
      oldPluginsDir = new File(PathManager.getDefaultPluginPathFor(src.getName()));
    }
    loadOldPlugins(oldPluginsDir, dest);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:54,代碼來源:ConfigImportHelper.java

示例13: setUp

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
  assumeThat(gradleVersion, versionMatcherRule.getMatcher());

  ensureTempDirCreated();

  String methodName = name.getMethodName();
  Matcher m = TEST_METHOD_NAME_PATTERN.matcher(methodName);
  if (m.matches()) {
    methodName = m.group(1);
  }

  testDir = new File(ourTempDir, methodName);
  FileUtil.ensureExists(testDir);

  FileUtil.writeToFile(
    new File(testDir, GradleConstants.DEFAULT_SCRIPT_NAME),
    FileUtil.loadTextAndClose(getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.DEFAULT_SCRIPT_NAME))
  );

  FileUtil.writeToFile(
    new File(testDir, GradleConstants.SETTINGS_FILE_NAME),
    FileUtil.loadTextAndClose(getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.SETTINGS_FILE_NAME))
  );

  GradleConnector connector = GradleConnector.newConnector();

  final URI distributionUri = new DistributionLocator().getDistributionFor(GradleVersion.version(gradleVersion));
  connector.useDistribution(distributionUri);
  connector.forProjectDirectory(testDir);
  int daemonMaxIdleTime = 10;
  try {
    daemonMaxIdleTime = Integer.parseInt(System.getProperty("gradleDaemonMaxIdleTime", "10"));
  }
  catch (NumberFormatException ignore) {}

  ((DefaultGradleConnector)connector).daemonMaxIdleTime(daemonMaxIdleTime, TimeUnit.SECONDS);
  ProjectConnection connection = connector.connect();

  try {
    final ProjectImportAction projectImportAction = new ProjectImportAction(false);
    projectImportAction.addExtraProjectModelClasses(getModels());
    BuildActionExecuter<ProjectImportAction.AllModels> buildActionExecutor = connection.action(projectImportAction);
    File initScript = GradleExecutionHelper.generateInitScript(false, getToolingExtensionClasses());
    assertNotNull(initScript);
    String jdkHome = IdeaTestUtil.requireRealJdkHome();
    buildActionExecutor.setJavaHome(new File(jdkHome));
    buildActionExecutor.setJvmArguments("-Xmx64m", "-XX:MaxPermSize=64m");
    buildActionExecutor.withArguments("--info", "--recompile-scripts", GradleConstants.INIT_SCRIPT_CMD_OPTION, initScript.getAbsolutePath());
    allModels = buildActionExecutor.run();
    assertNotNull(allModels);
  } finally {
    connection.close();
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:56,代碼來源:AbstractModelBuilderTest.java

示例14: dumpModulesPaths

import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static File dumpModulesPaths(@NotNull Project project) throws IOException {
  ApplicationManager.getApplication().assertReadAccessAllowed();

  Properties res = new Properties();

  MavenProjectsManager manager = MavenProjectsManager.getInstance(project);

  for (Module module : ModuleManager.getInstance(project).getModules()) {
    if (manager.isMavenizedModule(module)) {
      MavenProject mavenProject = manager.findProject(module);
      if (mavenProject != null && !manager.isIgnored(mavenProject)) {
        res.setProperty(mavenProject.getMavenId().getGroupId()
                        + ':' + mavenProject.getMavenId().getArtifactId()
                        + ":pom"
                        + ':' + mavenProject.getMavenId().getVersion(),
                        mavenProject.getFile().getPath());

        res.setProperty(mavenProject.getMavenId().getGroupId()
                        + ':' + mavenProject.getMavenId().getArtifactId()
                        + ":test-jar"
                        + ':' + mavenProject.getMavenId().getVersion(),
                        mavenProject.getTestOutputDirectory());

        res.setProperty(mavenProject.getMavenId().getGroupId()
                        + ':' + mavenProject.getMavenId().getArtifactId()
                        + ':' + mavenProject.getPackaging()
                        + ':' + mavenProject.getMavenId().getVersion(),
                         mavenProject.getOutputDirectory());

      }
    }
  }

  File file = new File(PathManager.getSystemPath(), "Maven/idea-projects-state-" + project.getLocationHash() + ".properties");
  FileUtil.ensureExists(file.getParentFile());

  OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
  try {
    res.store(out, null);
  }
  finally {
    out.close();
  }

  return file;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:47,代碼來源:MavenExternalParameters.java


注:本文中的com.intellij.openapi.util.io.FileUtil.ensureExists方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。