本文整理汇总了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;
}
示例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();
}
}
示例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();
}
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
}
示例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();
}
}
示例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;
}