Merge remote-tracking branch 'origin/master'

This commit is contained in:
Vladimir.Orlov
2015-10-06 15:57:21 +03:00
8 changed files with 98 additions and 74 deletions
@@ -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.
@@ -231,4 +231,9 @@ public class LayeredIcon implements Icon {
layeredIcon.setIcon(foregroundIcon, 1);
return layeredIcon;
}
@Override
public String toString() {
return "Layered icon. myIcons=" + Arrays.asList(myIcons);
}
}
@@ -109,4 +109,9 @@ public class RowIcon implements Icon {
myWidth = width;
myHeight = height;
}
@Override
public String toString() {
return "Row icon. myIcons=" + Arrays.asList(myIcons);
}
}
@@ -21,7 +21,6 @@ package com.intellij.ui;
import com.intellij.ide.PowerSaveMode;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.util.ProgressIndicatorUtils;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.util.Comparing;
@@ -238,9 +237,6 @@ public class DeferredIconImpl<T> implements DeferredIcon {
try {
result = nonNull(myEvaluator.fun(myParam));
}
catch (ProcessCanceledException e) {
result = EMPTY_ICON;
}
catch (IndexNotReadyException e) {
result = EMPTY_ICON;
}
@@ -357,4 +353,9 @@ public class DeferredIconImpl<T> implements DeferredIcon {
Comparing.equal(myParam, ((DeferredIconImpl)icon).myParam) &&
equalIcons(myDelegateIcon, ((DeferredIconImpl)icon).myDelegateIcon);
}
@Override
public String toString() {
return "Deferred. Base=" + myDelegateIcon;
}
}
@@ -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.
@@ -32,7 +32,6 @@ import com.intellij.ui.tabs.impl.table.TableLayout;
import com.intellij.util.PairConsumer;
import com.intellij.util.ui.Centerizer;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -31,6 +31,7 @@ import java.util.List;
import java.util.Random;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -119,60 +120,65 @@ public class UrlClassLoaderTest extends TestCase {
final int resourceCount = 20;
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(threadCount, ConcurrencyUtil.newNamedThreadFactory("conc loading"));
final Random random = new Random();
UrlClassLoader.CachePool pool = UrlClassLoader.createCachePool();
for (int attempt = 0; attempt < attemptCount; attempt++) {
final UrlClassLoader loader = UrlClassLoader.build().urls(urls).parent(null).
useCache(pool, new UrlClassLoader.CachingCondition() {
@Override
public boolean shouldCacheData(@NotNull URL url) {
return true; // fails also without cache pool (but with cache enabled), but takes much longer
}
}).get();
//if (attempt % 10 == 0) System.out.println("Attempt " + attempt);
try {
final Random random = new Random();
UrlClassLoader.CachePool pool = UrlClassLoader.createCachePool();
for (int attempt = 0; attempt < attemptCount; attempt++) {
final UrlClassLoader loader = UrlClassLoader.build().urls(urls).parent(null).
useCache(pool, new UrlClassLoader.CachingCondition() {
@Override
public boolean shouldCacheData(@NotNull URL url) {
return true; // fails also without cache pool (but with cache enabled), but takes much longer
}
}).get();
//if (attempt % 10 == 0) System.out.println("Attempt " + attempt);
final List<String> namesToLoad = ContainerUtil.newArrayList();
for (int j = 0; j < resourceCount; j++) {
namesToLoad.add(resourceNames.get(random.nextInt(resourceNames.size())));
}
final List<String> namesToLoad = ContainerUtil.newArrayList();
for (int j = 0; j < resourceCount; j++) {
namesToLoad.add(resourceNames.get(random.nextInt(resourceNames.size())));
}
List<Future> futures = ContainerUtil.newArrayList();
for (int i = 0; i < threadCount; i++) {
futures.add(executor.submit(new Runnable() {
@Override
public void run() {
for (String name : namesToLoad) {
try {
assertNotNull(findResource(name));
}
catch (Throwable e) {
System.out.println("Failed loading " + name);
throw new RuntimeException(e);
List<Future> futures = ContainerUtil.newArrayList();
for (int i = 0; i < threadCount; i++) {
futures.add(executor.submit(new Runnable() {
@Override
public void run() {
for (String name : namesToLoad) {
try {
assertNotNull(findResource(name));
}
catch (Throwable e) {
System.out.println("Failed loading " + name);
throw new RuntimeException(e);
}
}
}
}
private final Random findResourceOrFindResourcesChooser = new Random();
private URL findResource(String name) {
if (findResourceOrFindResourcesChooser.nextBoolean()) {
try {
Enumeration<URL> resources = loader.getResources(name);
assertTrue(resources.hasMoreElements());
return resources.nextElement();
}
catch (IOException e) {
throw new RuntimeException(e);
private final Random findResourceOrFindResourcesChooser = new Random();
private URL findResource(String name) {
if (findResourceOrFindResourcesChooser.nextBoolean()) {
try {
Enumeration<URL> resources = loader.getResources(name);
assertTrue(resources.hasMoreElements());
return resources.nextElement();
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
return loader.findResource(name);
}
return loader.findResource(name);
}
}));
}
}));
}
for (Future future : futures) {
future.get();
for (Future future : futures) {
future.get();
}
}
}
finally {
executor.shutdownNow();
executor.awaitTermination(1000, TimeUnit.SECONDS);
}
}
}
@@ -80,7 +80,8 @@ public class Semaphore {
sync.acquireSharedInterruptibly(1);
}
public boolean waitFor(final long msTimeout) {
// true if semaphore became free
public boolean waitFor(final long msTimeout) {
try {
return waitForUnsafe(msTimeout);
}
@@ -89,6 +90,7 @@ public class Semaphore {
}
}
// true if semaphore became free
public boolean waitForUnsafe(long msTimeout) throws InterruptedException {
if (sync.tryAcquireShared(1) >= 0) return true;
return sync.tryAcquireSharedNanos(1, TimeUnit.MILLISECONDS.toNanos(msTimeout));
@@ -34,6 +34,7 @@ import java.util.Collections;
import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -71,6 +72,12 @@ public class BaseOutputReaderTest {
@AfterClass
public static void tearDown() {
ourExecutor.shutdown();
try {
ourExecutor.awaitTermination(1000, TimeUnit.SECONDS);
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
ourExecutor = null;
}
@@ -65,7 +65,6 @@ import javax.swing.*;
import java.io.File;
import java.util.*;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicReference;
/**
@@ -86,7 +85,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
ourUpdateAlarm.set(createChangeListExecutor());
}
private static ScheduledThreadPoolExecutor createChangeListExecutor() {
private static ScheduledExecutorService createChangeListExecutor() {
return VcsUtil.createExecutor("Change List Updater");
}
@@ -95,7 +94,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
private FileHolderComposite myComposite;
private ChangeListWorker myWorker;
private VcsException myUpdateException = null;
private VcsException myUpdateException;
private Factory<JComponent> myAdditionalInfo;
private final EventDispatcher<ChangeListListener> myListeners = EventDispatcher.create(ChangeListListener.class);
@@ -466,7 +465,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
final Iterator<FilePath> filesIterator = modifier.getDirtyFilesIterator();
while (filesIterator.hasNext()) {
final FilePath dirtyFile = filesIterator.next();
if ((dirtyFile.getVirtualFile() != null) && isIgnoredFile(dirtyFile.getVirtualFile())) {
if (dirtyFile.getVirtualFile() != null && isIgnoredFile(dirtyFile.getVirtualFile())) {
filesIterator.remove();
fileHolder.addFile(dirtyFile.getVirtualFile());
refreshFiles.add(dirtyFile.getVirtualFile());
@@ -477,7 +476,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
final Iterator<FilePath> dirIterator = modifier.getDirtyDirectoriesIterator(root);
while (dirIterator.hasNext()) {
final FilePath dir = dirIterator.next();
if ((dir.getVirtualFile() != null) && isIgnoredFile(dir.getVirtualFile())) {
if (dir.getVirtualFile() != null && isIgnoredFile(dir.getVirtualFile())) {
dirIterator.remove();
fileHolder.addFile(dir.getVirtualFile());
refreshFiles.add(dir.getVirtualFile());
@@ -531,7 +530,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
myAdditionalInfo = null;
}
}
final String scopeInString = (!LOG.isDebugEnabled()) ? "" : StringUtil.join(scopes, new Function<VcsDirtyScope, String>() {
final String scopeInString = !LOG.isDebugEnabled() ? "" : StringUtil.join(scopes, new Function<VcsDirtyScope, String>() {
@Override
public String fun(VcsDirtyScope scope) {
return scope.toString();
@@ -545,7 +544,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
iterateScopes(dataHolder, scopes, wasEverythingDirty);
final boolean takeChanges = (myUpdateException == null);
final boolean takeChanges = myUpdateException == null;
if (takeChanges) {
// update IDEA-level ignored files
updateIgnoredFiles(dataHolder.getComposite());
@@ -696,8 +695,8 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
private class DataHolder {
private final boolean myWasEverythingDirty;
final FileHolderComposite myComposite;
final ChangeListWorker myChangeListWorker;
private final FileHolderComposite myComposite;
private final ChangeListWorker myChangeListWorker;
private DataHolder(FileHolderComposite composite, ChangeListWorker changeListWorker, boolean wasEverythingDirty) {
myComposite = composite;
@@ -705,14 +704,14 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
myWasEverythingDirty = wasEverythingDirty;
}
public void notifyStart() {
private void notifyStart() {
if (myWasEverythingDirty) {
myComposite.cleanAll();
myChangeListWorker.notifyStartProcessingChanges(null);
}
}
public void notifyStartProcessingChanges(@NotNull final VcsModifiableDirtyScope scope) {
private void notifyStartProcessingChanges(@NotNull final VcsModifiableDirtyScope scope) {
if (!myWasEverythingDirty) {
myComposite.cleanAndAdjustScope(scope);
myChangeListWorker.notifyStartProcessingChanges(scope);
@@ -722,13 +721,13 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
myChangeListWorker.notifyVcsStarted(scope.getVcs());
}
public void notifyDoneProcessingChanges() {
private void notifyDoneProcessingChanges() {
if (!myWasEverythingDirty) {
myChangeListWorker.notifyDoneProcessingChanges(myDelayedNotificator.getProxyDispatcher());
}
}
public void notifyEnd() {
void notifyEnd() {
if (myWasEverythingDirty) {
myChangeListWorker.notifyDoneProcessingChanges(myDelayedNotificator.getProxyDispatcher());
}
@@ -738,7 +737,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
return myComposite;
}
public ChangeListWorker getChangeListWorker() {
ChangeListWorker getChangeListWorker() {
return myChangeListWorker;
}
}
@@ -927,7 +926,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
public Factory<JComponent> getAdditionalUpdateInfo() {
Factory<JComponent> getAdditionalUpdateInfo() {
synchronized (myDataLock) {
return myAdditionalInfo;
}
@@ -1258,7 +1257,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
});
if (exceptions.size() > 0) {
if (!exceptions.isEmpty()) {
StringBuilder message = new StringBuilder(VcsBundle.message("error.adding.files.prompt"));
for (VcsException ex : exceptions) {
message.append("\n").append(ex.getMessage());
@@ -1292,7 +1291,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
if (changesToMove.size() > 0) {
if (!changesToMove.isEmpty()) {
moveChangesTo(list, changesToMove.toArray(new Change[changesToMove.size()]));
}
}
@@ -1389,13 +1388,13 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
@Override
@SuppressWarnings({"unchecked"})
@SuppressWarnings("unchecked")
public void readExternal(Element element) throws InvalidDataException {
if (!myProject.isDefault()) {
synchronized (myDataLock) {
myIgnoredIdeaLevel.clear();
new ChangeListManagerSerialization(myIgnoredIdeaLevel, myWorker).readExternal(element);
if ((!myWorker.isEmpty()) && getDefaultChangeList() == null) {
if (!myWorker.isEmpty() && getDefaultChangeList() == null) {
setDefaultChangeList(myWorker.getListsCopy().get(0));
}
}
@@ -1442,8 +1441,8 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
private static class MyDirtyFilesScheduler {
private static final int ourPiecesLimit = 100;
final List<VirtualFile> myFiles = new ArrayList<VirtualFile>();
final List<VirtualFile> myDirs = new ArrayList<VirtualFile>();
private final List<VirtualFile> myFiles = new ArrayList<VirtualFile>();
private final List<VirtualFile> myDirs = new ArrayList<VirtualFile>();
private boolean myEveryThing;
private int myCnt;
private final Project myProject;