vcs: Refactoring - removed unused VcsEventsListenerManager and related logic

Note: part of the api is still left and marked deprecated as it is used in some versions of TeamCity plugin (in internal action that is already removed from newer TeamCity plugin versions)
This commit is contained in:
Konstantin Kolosovsky
2015-09-16 15:58:04 +03:00
parent be14de8fb8
commit 4473b6255c
11 changed files with 20 additions and 762 deletions
@@ -30,7 +30,6 @@ import com.intellij.openapi.vcs.diff.RevisionSelector;
import com.intellij.openapi.vcs.history.VcsAnnotationCachedProxy;
import com.intellij.openapi.vcs.history.VcsHistoryProvider;
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
import com.intellij.openapi.vcs.impl.IllegalStateProxy;
import com.intellij.openapi.vcs.merge.MergeProvider;
import com.intellij.openapi.vcs.rollback.RollbackEnvironment;
import com.intellij.openapi.vcs.update.UpdateEnvironment;
@@ -159,7 +158,7 @@ public abstract class AbstractVcs<ComList extends CommittedChangeList> extends S
*/
@Nullable
protected CheckinEnvironment createCheckinEnvironment() {
return IllegalStateProxy.create(CheckinEnvironment.class);
return null;
}
/**
@@ -180,7 +179,7 @@ public abstract class AbstractVcs<ComList extends CommittedChangeList> extends S
*/
@Nullable
protected RollbackEnvironment createRollbackEnvironment() {
return IllegalStateProxy.create(RollbackEnvironment.class);
return null;
}
/**
@@ -213,7 +212,7 @@ public abstract class AbstractVcs<ComList extends CommittedChangeList> extends S
*/
@Nullable
protected UpdateEnvironment createUpdateEnvironment() {
return IllegalStateProxy.create(UpdateEnvironment.class);
return null;
}
/**
@@ -584,6 +583,12 @@ public abstract class AbstractVcs<ComList extends CommittedChangeList> extends S
myRollbackEnvironment = rollbackEnvironment;
}
public void setupEnvironments() {
setCheckinEnvironment(createCheckinEnvironment());
setUpdateEnvironment(createUpdateEnvironment());
setRollbackEnvironment(createRollbackEnvironment());
}
public boolean reportsIgnoredDirectories() {
return true;
}
@@ -1,37 +0,0 @@
/*
* Copyright 2000-2010 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs;
import com.intellij.openapi.util.Pair;
import com.intellij.util.Consumer;
/**
* @author irengrig
* Date: 12/21/10
* Time: 2:15 PM
*/
public class ForwardingListener<T> implements Consumer<Pair<VcsKey, Consumer<T>>> {
private final T myT;
public ForwardingListener(T t) {
myT = t;
}
@Override
public void consume(Pair<VcsKey, Consumer<T>> vcsKeyConsumerPair) {
vcsKeyConsumerPair.getSecond().consume(myT);
}
}
@@ -25,7 +25,6 @@ import com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener;
import com.intellij.openapi.vcs.history.VcsHistoryCache;
import com.intellij.openapi.vcs.impl.ContentRevisionCache;
import com.intellij.openapi.vcs.impl.VcsDescriptor;
import com.intellij.openapi.vcs.impl.VcsEnvironmentsProxyCreator;
import com.intellij.openapi.vcs.update.UpdatedFiles;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Processor;
@@ -267,8 +266,10 @@ public abstract class ProjectLevelVcsManager {
public abstract CheckoutProvider.Listener getCompositeCheckoutListener();
// TODO: To be removed in IDEA 16.
@Deprecated
@Nullable
public abstract VcsEventsListenerManager getVcsEventsListenerManager();
protected abstract VcsEnvironmentsProxyCreator getProxyCreator();
public abstract VcsHistoryCache getVcsHistoryCache();
public abstract ContentRevisionCache getContentRevisionCache();
@@ -1,57 +0,0 @@
/*
* Copyright 2000-2010 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs;
import com.intellij.openapi.vcs.checkin.CheckinEnvironment;
import com.intellij.openapi.vcs.impl.IllegalStateProxy;
import com.intellij.openapi.vcs.impl.VcsEnvironmentsProxyCreator;
import com.intellij.openapi.vcs.rollback.RollbackEnvironment;
import com.intellij.openapi.vcs.update.UpdateEnvironment;
/**
* @author irengrig
* Date: 12/17/10
* Time: 12:46 PM
*/
public class VcsActiveEnvironmentsProxy {
private VcsActiveEnvironmentsProxy() {
}
public static AbstractVcs proxyVcs(final AbstractVcs vcs) {
final ProjectLevelVcsManager manager = ProjectLevelVcsManager.getInstance(vcs.getProject());
final VcsEnvironmentsProxyCreator proxyCreator = manager.getProxyCreator();
if (proxyCreator == null) return vcs;
final VcsKey key = vcs.getKeyInstanceMethod();
final CheckinEnvironment checkinEnvironment = vcs.createCheckinEnvironment();
final UpdateEnvironment updateEnvironment = vcs.createUpdateEnvironment();
final RollbackEnvironment rollbackEnvironment = vcs.createRollbackEnvironment();
if (checkinEnvironment != null && checkinEnvironment.equals(IllegalStateProxy.IDENTITY) ||
updateEnvironment != null && updateEnvironment.equals(IllegalStateProxy.IDENTITY) ||
rollbackEnvironment != null && rollbackEnvironment.equals(IllegalStateProxy.IDENTITY)) {
return vcs;
} else {
final CheckinEnvironment proxedCheckin = proxyCreator.proxyCheckin(key, checkinEnvironment);
final UpdateEnvironment proxedUpdate = proxyCreator.proxyUpdate(key, updateEnvironment);
final RollbackEnvironment proxedRollback = proxyCreator.proxyRollback(key, rollbackEnvironment);
vcs.setCheckinEnvironment(proxedCheckin);
vcs.setUpdateEnvironment(proxedUpdate);
vcs.setRollbackEnvironment(proxedRollback);
return vcs;
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 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.
@@ -22,10 +22,12 @@ import com.intellij.openapi.vcs.update.UpdateEnvironment;
import com.intellij.util.Consumer;
/**
* TODO: To be removed in IDEA 16.
* @author irengrig
* Date: 12/15/10
* Time: 5:42 PM
*/
@Deprecated
public interface VcsEventsListenerManager {
void removeCheckin(final Object key);
void removeUpdate(final Object key);
@@ -1,46 +0,0 @@
/*
* Copyright 2000-2010 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.impl;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* @author irengrig
* Date: 12/17/10
* Time: 2:21 PM
*/
public class IllegalStateProxy {
public static final Object IDENTITY = new Object();
private static final InvocationHandler HANDLER = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if ("equals".equals(method.getName())) {
return IDENTITY.equals(args[0]);
}
throw new IllegalStateException();
}
};
private IllegalStateProxy() {
}
public static<T> T create(final Class<T> clazz) {
return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, HANDLER);
}
}
@@ -1,38 +0,0 @@
/*
* Copyright 2000-2010 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.impl;
import com.intellij.openapi.vcs.VcsKey;
import com.intellij.openapi.vcs.checkin.CheckinEnvironment;
import com.intellij.openapi.vcs.rollback.RollbackEnvironment;
import com.intellij.openapi.vcs.update.UpdateEnvironment;
import org.jetbrains.annotations.Nullable;
/**
* @author irengrig
* Date: 12/17/10
* Time: 5:34 PM
*/
public interface VcsEnvironmentsProxyCreator {
@Nullable
CheckinEnvironment proxyCheckin(VcsKey key, CheckinEnvironment environment);
@Nullable
UpdateEnvironment proxyUpdate(VcsKey key, UpdateEnvironment environment);
@Nullable
RollbackEnvironment proxyRollback(VcsKey key, RollbackEnvironment environment);
}
@@ -112,7 +112,6 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
private final Map<VcsBackgroundableActions, BackgroundableActionEnabledHandler> myBackgroundableActionHandlerMap;
private final List<Pair<String, TextAttributes>> myPendingOutput = new ArrayList<Pair<String, TextAttributes>>();
private VcsEventsListenerManagerImpl myVcsEventListenerManager;
private final VcsHistoryCache myVcsHistoryCache;
private final ContentRevisionCache myContentRevisionCache;
@@ -135,10 +134,6 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
myMappings = new NewMappings(myProject, myMessageBus, this, manager);
myMappingsToRoots = new MappingsToRoots(myMappings, myProject);
if (!myProject.isDefault()) {
myVcsEventListenerManager = new VcsEventsListenerManagerImpl();
}
myVcsHistoryCache = new VcsHistoryCache();
myContentRevisionCache = new ContentRevisionCache();
myConnect = myMessageBus.connect();
@@ -807,8 +802,9 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
}
@Override
@Nullable
public VcsEventsListenerManager getVcsEventsListenerManager() {
return myVcsEventListenerManager;
return null;
}
@Override
@@ -823,11 +819,6 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
return myMappings.haveDefaultMapping();
}
@Override
protected VcsEnvironmentsProxyCreator getProxyCreator() {
return myVcsEventListenerManager;
}
public BackgroundableActionEnabledHandler getBackgroundableActionHandler(final VcsBackgroundableActions action) {
ApplicationManager.getApplication().assertIsDispatchThread();
@@ -24,7 +24,6 @@ import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vcs.VcsActiveEnvironmentsProxy;
import com.intellij.util.xmlb.annotations.Attribute;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -61,8 +60,9 @@ public class VcsEP extends AbstractExtensionPointBean {
}
AbstractVcs vcs = getInstance(project, vcsClass);
synchronized (LOCK) {
if (myVcs == null) {
myVcs = VcsActiveEnvironmentsProxy.proxyVcs(vcs);
if (myVcs == null && vcs != null) {
vcs.setupEnvironments();
myVcs = vcs;
}
return myVcs;
}
@@ -1,197 +0,0 @@
/*
* Copyright 2000-2010 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.impl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vcs.VcsEventsListenerManager;
import com.intellij.openapi.vcs.VcsKey;
import com.intellij.openapi.vcs.checkin.CheckinEnvironment;
import com.intellij.openapi.vcs.rollback.RollbackEnvironment;
import com.intellij.openapi.vcs.update.UpdateEnvironment;
import com.intellij.util.Consumer;
import com.intellij.util.EventDispatcher;
import org.jetbrains.annotations.Nullable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Collections;
import java.util.EventListener;
import java.util.HashMap;
import java.util.Map;
/**
* @author irengrig
* Date: 12/15/10
* Time: 5:50 PM
*/
public class VcsEventsListenerManagerImpl implements VcsEventsListenerManager, VcsEnvironmentsProxyCreator {
private final Wrapper<CheckinEnvironment> myCheckinWrapper;
private final Wrapper<UpdateEnvironment> myUpdateWrapper;
private final Wrapper<RollbackEnvironment> myRollbackWrapper;
public VcsEventsListenerManagerImpl() {
myCheckinWrapper = new Wrapper<CheckinEnvironment>(CheckinEnvironment.class);
myUpdateWrapper = new Wrapper<UpdateEnvironment>(UpdateEnvironment.class);
myRollbackWrapper = new Wrapper<RollbackEnvironment>(RollbackEnvironment.class);
}
@Override
public Object addCheckin(final Consumer<Pair<VcsKey, Consumer<CheckinEnvironment>>> consumer) {
return myCheckinWrapper.add(consumer);
}
@Override
public Object addUpdate(final Consumer<Pair<VcsKey, Consumer<UpdateEnvironment>>> consumer) {
return myUpdateWrapper.add(consumer);
}
@Override
public Object addRollback(final Consumer<Pair<VcsKey, Consumer<RollbackEnvironment>>> consumer) {
return myRollbackWrapper.add(consumer);
}
@Override
public void removeCheckin(Object key) {
myCheckinWrapper.remove(key);
}
@Override
public void removeUpdate(Object key) {
myUpdateWrapper.remove(key);
}
@Override
public void removeRollback(Object key) {
myRollbackWrapper.remove(key);
}
@Nullable
@Override
public CheckinEnvironment proxyCheckin(final VcsKey key, final CheckinEnvironment environment) {
return myCheckinWrapper.createProxy(key, environment);
}
@Nullable
@Override
public UpdateEnvironment proxyUpdate(final VcsKey key, final UpdateEnvironment environment) {
return myUpdateWrapper.createProxy(key, environment);
}
@Nullable
@Override
public RollbackEnvironment proxyRollback(final VcsKey key, final RollbackEnvironment environment) {
return myRollbackWrapper.createProxy(key, environment);
}
private static class Wrapper<T> {
private final Map<Object, EventListenerWrapperI> myListenersMap;
private final Map<VcsKey, EventDispatcher<EventListenerWrapperI>> myExistingMulticasters;
private final Class<T> myClazz;
private final Object myLock;
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.impl.VcsEventsListenerManagerImpl.Wrapper");
private Wrapper(final Class<T> clazz) {
myClazz = clazz;
myListenersMap = new HashMap<Object, EventListenerWrapperI>();
myExistingMulticasters = Collections.synchronizedMap(new HashMap<VcsKey, EventDispatcher<EventListenerWrapperI>>());
myLock = new Object();
}
@Nullable
public T createProxy(final VcsKey key, @Nullable final T environment) {
if (environment == null) return null;
final EventDispatcher<EventListenerWrapperI> eventDispatcher;
synchronized (myLock) {
assert ! myExistingMulticasters.containsKey(key);
eventDispatcher = EventDispatcher.create(EventListenerWrapperI.class);
myExistingMulticasters.put(key, eventDispatcher);
for (EventListenerWrapperI wrapper : myListenersMap.values()) {
eventDispatcher.addListener(wrapper);
}
}
final T proxy = (T) Proxy.newProxyInstance(myClazz.getClassLoader(),
new Class[]{myClazz},
new InvocationHandler() {
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
method.setAccessible(true);
synchronized (myLock) {
eventDispatcher.getMulticaster().consume(
new Pair<VcsKey, Consumer<T>>(key, new Consumer<T>() {
@Override
public void consume(T t) {
try {
method.invoke(t, args);
}
catch (IllegalAccessException e) {
LOG.info(e);
}
catch (InvocationTargetException e) {
LOG.info(e);
}
}
}));
}
return method.invoke(environment, args);
}
});
return proxy;
}
public Object add(final Consumer<Pair<VcsKey,Consumer<T>>> consumer) {
final Object key = new Object();
synchronized (myLock) {
EventListenerWrapper<T> listenerWrapper = new EventListenerWrapper<T>(consumer);
myListenersMap.put(key, listenerWrapper);
for (EventDispatcher<EventListenerWrapperI> eventDispatcher : myExistingMulticasters.values()) {
eventDispatcher.addListener(listenerWrapper);
}
}
return key;
}
public void remove(Object key) {
synchronized (myLock) {
final EventListenerWrapperI listenerWrapper = myListenersMap.remove(key);
if (listenerWrapper != null) {
for (EventDispatcher<EventListenerWrapperI> dispatcher : myExistingMulticasters.values()) {
dispatcher.removeListener(listenerWrapper);
}
}
}
}
private interface EventListenerWrapperI<T> extends Consumer<Pair<VcsKey, Consumer<T>>>, EventListener {}
private static class EventListenerWrapper<T> implements EventListenerWrapperI<T> {
private final Consumer<Pair<VcsKey, Consumer<T>>> myConsumer;
public EventListenerWrapper(Consumer<Pair<VcsKey, Consumer<T>>> consumer) {
myConsumer = consumer;
}
@Override
public void consume(Pair<VcsKey, Consumer<T>> vcsKeyConsumerPair) {
myConsumer.consume(vcsKeyConsumerPair);
}
}
}
}
@@ -1,366 +0,0 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.changes.committed;
import com.intellij.ide.startup.impl.StartupManagerImpl;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vcs.*;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vcs.changes.ChangeList;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.checkin.CheckinEnvironment;
import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl;
import com.intellij.openapi.vcs.rollback.RollbackEnvironment;
import com.intellij.openapi.vcs.rollback.RollbackProgressListener;
import com.intellij.openapi.vcs.ui.RefreshableOnComponent;
import com.intellij.openapi.vcs.update.SequentialUpdatesContext;
import com.intellij.openapi.vcs.update.UpdateEnvironment;
import com.intellij.openapi.vcs.update.UpdateSession;
import com.intellij.openapi.vcs.update.UpdatedFiles;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
import com.intellij.testFramework.fixtures.TempDirTestFixture;
import com.intellij.testFramework.vcs.AbstractJunitVcsTestCase;
import com.intellij.util.NullableFunction;
import com.intellij.util.PairConsumer;
import com.intellij.util.ui.UIUtil;
import junit.framework.Assert;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
* @author irengrig
* Date: 12/21/10
* Time: 2:03 PM
*/
public class VcsEventsListenerTest extends AbstractJunitVcsTestCase {
private AbstractVcs myVcs;
private ProjectLevelVcsManagerImpl myVcsManager;
private ChangeListManager myChangeListManager;
private TempDirTestFixture myTempDirFixture;
private File myClientRoot;
@Before
public void setUp() {
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
try {
final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory();
myTempDirFixture = fixtureFactory.createTempDirTestFixture();
myTempDirFixture.setUp();
myClientRoot = new File(myTempDirFixture.getTempDirPath(), "clientroot");
myClientRoot.mkdir();
initProject(myClientRoot, VcsEventsListenerTest.this.getTestName());
((StartupManagerImpl)StartupManager.getInstance(myProject)).runPostStartupActivities();
myChangeListManager = ChangeListManager.getInstance(myProject);
myVcs = VcsActiveEnvironmentsProxy.proxyVcs(new MyVcs(myProject, "mock"));
myVcsManager = (ProjectLevelVcsManagerImpl)ProjectLevelVcsManager.getInstance(myProject);
myVcsManager.registerVcs(myVcs);
myVcsManager.setDirectoryMapping(myWorkingCopyDir.getPath(), myVcs.getName());
}
catch (Exception e) {
tearDown();
throw new RuntimeException(e);
}
}
});
}
@After
public void tearDown() {
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
try {
if (myVcsManager != null && myVcs != null) {
myVcsManager.unregisterVcs(myVcs);
}
tearDownProject();
if (myTempDirFixture != null) {
myTempDirFixture.tearDown();
myTempDirFixture = null;
}
FileUtil.delete(myClientRoot);
}
catch (Exception e) {
throw new RuntimeException(e);
}
finally {
try {
UsefulTestCase.clearFields(this);
}
catch (IllegalAccessException e) {
//noinspection ThrowFromFinallyBlock
throw new RuntimeException(e);
}
}
}
});
}
@Test
public void testSimpleListeningWithProxy() throws Exception {
final VcsEventsListenerManager manager = myVcsManager.getVcsEventsListenerManager();
final List<VirtualFile> list = Arrays.asList(new VirtualFile[]{myWorkingCopyDir});
final MyCheckinListener listener = new MyCheckinListener(list);
final Object key = manager.addCheckin(new ForwardingListener<CheckinEnvironment>(listener));
myVcs.getCheckinEnvironment().scheduleUnversionedFilesForAddition(list);
Assert.assertTrue(listener.isChecked());
listener.assertCheckOk();
listener.reset();
manager.removeCheckin(key);
listener.reset();
myVcs.getCheckinEnvironment().scheduleUnversionedFilesForAddition(list);
Assert.assertFalse(listener.isChecked());
}
@Test
public void testSimpleListeningWithoutProxy() throws Exception {
myVcsManager.setDirectoryMapping(myWorkingCopyDir.getPath(), "svn");
testSimpleListeningWithProxy();
}
private static class MyVcs extends MockAbstractVcs {
private MyVcs(Project project, String name) {
super(project, name);
}
@Override
protected UpdateEnvironment createUpdateEnvironment() {
return new UpdateEnvironment() {
@Override
public void fillGroups(UpdatedFiles updatedFiles) {
//To change body of implemented methods use File | Settings | File Templates.
}
@NotNull
@Override
public UpdateSession updateDirectories(@NotNull FilePath[] contentRoots,
UpdatedFiles updatedFiles,
ProgressIndicator progressIndicator,
@NotNull Ref<SequentialUpdatesContext> context) throws ProcessCanceledException {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public Configurable createConfigurable(Collection<FilePath> files) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public boolean validateOptions(Collection<FilePath> roots) {
return false; //To change body of implemented methods use File | Settings | File Templates.
}
};
}
@Override
protected RollbackEnvironment createRollbackEnvironment() {
return new RollbackEnvironment() {
@Override
public String getRollbackOperationName() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void rollbackChanges(List<Change> changes,
List<VcsException> vcsExceptions,
@NotNull RollbackProgressListener listener) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void rollbackMissingFileDeletion(List<FilePath> files,
List<VcsException> exceptions,
RollbackProgressListener listener) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void rollbackModifiedWithoutCheckout(List<VirtualFile> files,
List<VcsException> exceptions,
RollbackProgressListener listener) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void rollbackIfUnchanged(VirtualFile file) {
//To change body of implemented methods use File | Settings | File Templates.
}
};
}
@Override
protected CheckinEnvironment createCheckinEnvironment() {
return new CheckinEnvironment() {
@Override
public RefreshableOnComponent createAdditionalOptionsPanel(CheckinProjectPanel panel,
PairConsumer<Object, Object> additionalDataConsumer) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public String getDefaultMessageFor(FilePath[] filesToCheckin) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public String getHelpId() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public String getCheckinOperationName() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public List<VcsException> commit(List<Change> changes, String preparedComment) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public List<VcsException> commit(List<Change> changes,
String preparedComment,
@NotNull NullableFunction<Object, Object> parametersHolder, Set<String> feedback) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public List<VcsException> scheduleMissingFileForDeletion(List<FilePath> files) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public List<VcsException> scheduleUnversionedFilesForAddition(List<VirtualFile> files) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public boolean keepChangeListAfterCommit(ChangeList changeList) {
return false; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public boolean isRefreshAfterCommitNeeded() {
return true;
}
};
}
}
private static class MyCheckinListener implements CheckinEnvironment {
private boolean myChecked;
private boolean myAssertOk;
private final List<VirtualFile> myCheckList;
public MyCheckinListener(final List<VirtualFile> checkList) {
myCheckList = checkList;
myChecked = false;
myAssertOk = true;
}
@Override
public RefreshableOnComponent createAdditionalOptionsPanel(CheckinProjectPanel panel,
PairConsumer<Object, Object> additionalDataConsumer) {
return null;
}
@Override
public String getDefaultMessageFor(FilePath[] filesToCheckin) {
return null;
}
@Override
public String getHelpId() {
return null;
}
@Override
public String getCheckinOperationName() {
return null;
}
@Override
public List<VcsException> commit(List<Change> changes, String preparedComment) {
return null;
}
@Override
public List<VcsException> commit(List<Change> changes,
String preparedComment,
@NotNull NullableFunction<Object, Object> parametersHolder, Set<String> feedback) {
return null;
}
@Override
public List<VcsException> scheduleMissingFileForDeletion(List<FilePath> files) {
return null;
}
@Override
public List<VcsException> scheduleUnversionedFilesForAddition(List<VirtualFile> files) {
myChecked = true;
myAssertOk = myCheckList.equals(files);
return null;
}
@Override
public boolean keepChangeListAfterCommit(ChangeList changeList) {
return false;
}
@Override
public boolean isRefreshAfterCommitNeeded() {
return true;
}
public boolean isChecked() {
return myChecked;
}
public void assertCheckOk() {
Assert.assertTrue(myAssertOk);
}
public void reset() {
myAssertOk = true;
myChecked = false;
}
}
}