Skip to content

Commit

Permalink
Cleanup (duplicates; formatting; typos)
Browse files Browse the repository at this point in the history
  • Loading branch information
trespasserw committed Jul 27, 2015
1 parent 6de1698 commit 34c7fbc
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,11 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* created at Jan 3, 2002
* @author Jeka
*/
package com.intellij.compiler.impl;

import com.intellij.openapi.compiler.CompileContext;
Expand All @@ -38,6 +33,10 @@
import java.util.Collection;
import java.util.List;

/**
* @author Jeka
* @since Jan 3, 2002
*/
public class CompilerUtil {
private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.CompilerUtil");

Expand All @@ -49,27 +48,15 @@ public static String quotePath(String path) {
return path;
}

/**
* must not be called inside ReadAction
* @param files
*/
public static void refreshIOFiles(@NotNull final Collection<File> files) {
if (!files.isEmpty()) {
LocalFileSystem.getInstance().refreshIoFiles(files);
}
}

public static void refreshIODirectories(@NotNull final Collection<File> files) {
final LocalFileSystem lfs = LocalFileSystem.getInstance();
final List<VirtualFile> filesToRefresh = new ArrayList<VirtualFile>();
for (File file : files) {
final VirtualFile virtualFile = lfs.refreshAndFindFileByIoFile(file);
if (virtualFile != null) {
filesToRefresh.add(virtualFile);
}
}
if (!filesToRefresh.isEmpty()) {
RefreshQueue.getInstance().refresh(false, true, null, filesToRefresh);
if (!files.isEmpty()) {
LocalFileSystem.getInstance().refreshIoFiles(files, false, true, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -376,12 +376,7 @@ protected String copyToProject(String relativeSourcePath, String relativeTargetP
String fullTargetPath = getAbsolutePath(relativeTargetPath);
File target = new File(fullTargetPath);
try {
if (source.isDirectory()) {
FileUtil.copyDir(source, target);
}
else {
FileUtil.copy(source, target);
}
FileUtil.copyFileOrDir(source, target);
}
catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,17 +17,14 @@

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.util.ExceptionUtil;
import org.jetbrains.annotations.NotNull;


public class RunResult<T> extends Result<T> {

private BaseActionRunnable<T> myActionRunnable;

private Throwable myThrowable;

protected RunResult() {
}
protected RunResult() { }

public RunResult(@NotNull BaseActionRunnable<T> action) {
myActionRunnable = action;
Expand All @@ -38,18 +35,13 @@ public RunResult<T> run() {
myActionRunnable.run(this);
}
catch (ProcessCanceledException e) {
throw e; // this exception may occur from time to time and it shouldn't be catched
throw e; // this exception may occur from time to time and it shouldn't be caught
}
catch (Throwable throwable) {
myThrowable = throwable;
catch (Throwable t) {
myThrowable = t;
if (!myActionRunnable.isSilentExecution()) {
if (throwable instanceof RuntimeException) throw (RuntimeException)throwable;
if (throwable instanceof Error) {
throw (Error)throwable;
}
else {
throw new RuntimeException(myThrowable);
}
ExceptionUtil.rethrowUnchecked(t);
throw new RuntimeException(myThrowable);
}
}
finally {
Expand All @@ -65,7 +57,7 @@ public T getResultObject() {

@NotNull
public RunResult logException(Logger logger) {
if (hasException()) {
if (myThrowable != null) {
logger.error(myThrowable);
}

Expand All @@ -74,16 +66,11 @@ public RunResult logException(Logger logger) {

@NotNull
public RunResult<T> throwException() throws RuntimeException, Error {
if (hasException()) {
if (myThrowable instanceof RuntimeException) {
throw (RuntimeException)myThrowable;
}
if (myThrowable instanceof Error) {
throw (Error)myThrowable;
}

if (myThrowable != null) {
ExceptionUtil.rethrowUnchecked(myThrowable);
throw new RuntimeException(myThrowable);
}

return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,8 +23,10 @@

public abstract class WriteAction<T> extends BaseActionRunnable<T> {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.application.WriteAction");

@NotNull
@Override
@SuppressWarnings("InstanceofCatchParameter")
public RunResult<T> execute() {
final RunResult<T> result = new RunResult<T>(this);

Expand All @@ -35,7 +37,8 @@ public RunResult<T> execute() {
}

try {
if (!application.isDispatchThread() && application.isReadAccessAllowed()) {
boolean dispatchThread = application.isDispatchThread();
if (!dispatchThread && application.isReadAccessAllowed()) {
LOG.error("Must not start write action from within read action in the other thread - deadlock is coming");
}
Runnable runnable = new Runnable() {
Expand All @@ -49,7 +52,7 @@ public void run() {
});
}
};
if (application.isDispatchThread()) {
if (dispatchThread) {
runnable.run();
}
else if (application.isReadAccessAllowed()) {
Expand All @@ -68,6 +71,7 @@ else if (application.isReadAccessAllowed()) {
throw new Error(e);
}
}

return result;
}

Expand Down
12 changes: 12 additions & 0 deletions platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,18 @@ public static VirtualFile[] getChildren(@NotNull VirtualFile dir) {
return children == null ? VirtualFile.EMPTY_ARRAY : children;
}

@NotNull
public static List<VirtualFile> getChildren(@NotNull VirtualFile dir, @NotNull VirtualFileFilter filter) {
List<VirtualFile> result = null;
for (VirtualFile child : dir.getChildren()) {
if (filter.accept(child)) {
if (result == null) result = ContainerUtil.newSmartList();
result.add(child);
}
}
return result != null ? result : ContainerUtil.<VirtualFile>emptyList();
}

/**
* @param url Url for virtual file
* @return url for parent directory of virtual file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,12 +623,7 @@ public VirtualFile copyFile(Object requestor,
if (!auxCopy(file, newParent, copyName)) {
try {
File ioFile = convertToIOFile(file);
if (attributes.isDirectory()) {
FileUtil.copyDir(ioFile, ioTarget);
}
else {
FileUtil.copy(ioFile, ioTarget);
}
FileUtil.copyFileOrDir(ioFile, ioTarget, attributes.isDirectory());
}
catch (IOException e) {
FileUtil.delete(ioTarget);
Expand Down
21 changes: 14 additions & 7 deletions platform/util/src/com/intellij/openapi/util/io/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,19 @@ public static void copy(@NotNull InputStream inputStream, int maxSize, @NotNull
}
}

public static void copyFileOrDir(@NotNull File from, @NotNull File to) throws IOException {
copyFileOrDir(from, to, from.isDirectory());
}

public static void copyFileOrDir(@NotNull File from, @NotNull File to, boolean isDir) throws IOException {
if (isDir) {
copyDir(from, to);
}
else {
copy(from, to);
}
}

public static void copyDir(@NotNull File fromDir, @NotNull File toDir) throws IOException {
copyDir(fromDir, toDir, true);
}
Expand All @@ -555,13 +568,7 @@ public static void copyDir(@NotNull File fromDir, @NotNull File toDir) throws IO
public static void copyDirContent(@NotNull File fromDir, @NotNull File toDir) throws IOException {
File[] children = ObjectUtils.notNull(fromDir.listFiles(), ArrayUtil.EMPTY_FILE_ARRAY);
for (File child : children) {
File target = new File(toDir, child.getName());
if (child.isFile()) {
copy(child, target);
}
else {
copyDir(child, target, true);
}
copyFileOrDir(child, new File(toDir, child.getName()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.intellij.execution.CommandLineUtil;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ArrayUtilRt;
Expand Down Expand Up @@ -137,11 +136,7 @@ private void copyLibraries(String zipPath, File tempUnzippedArtifactOutput) thro
final String fileName = file.getName();
if (ArrayUtilRt.find(generatedItems, fileName) < 0) {
final File destination = new File(tempUnzippedArtifactOutput, fileName);
if (file.isFile()) {
FileUtil.copy(file, destination);
} else {
FileUtil.copyDir(file, destination, true);
}
FileUtil.copyFileOrDir(file, destination);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -337,7 +337,7 @@ private boolean for17move(final SvnVcs vcs, final File src, final File dst, bool
// check destination directory
if (isUnversioned(vcs, dst.getParentFile())) {
try {
copyFileOrDir(src, dst);
FileUtil.copyFileOrDir(src, dst);
}
catch (IOException e) {
throw new SvnBindException(e);
Expand Down Expand Up @@ -369,7 +369,7 @@ public boolean process(File file) {
File newFile = new File(dst, relativePath);
if (!newFile.exists()) {
try {
copyFileOrDir(src, dst);
FileUtil.copyFileOrDir(src, dst);
}
catch (IOException e) {
exc[0] = new SvnBindException(e);
Expand All @@ -385,14 +385,6 @@ public boolean process(File file) {
}
}

private static void copyFileOrDir(File src, File dst) throws IOException {
if (src.isDirectory()) {
FileUtil.copyDir(src, dst);
} else {
FileUtil.copy(src, dst);
}
}

private static boolean doUsualMove(SvnVcs vcs, File src) {
// if src is not under version control, do usual move.
Status srcStatus = getFileStatus(vcs, src);
Expand Down

0 comments on commit 34c7fbc

Please sign in to comment.