diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java b/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java index 36de1fa20ee1..e3c3d0a966a4 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java @@ -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 extends S */ @Nullable protected CheckinEnvironment createCheckinEnvironment() { - return IllegalStateProxy.create(CheckinEnvironment.class); + return null; } /** @@ -180,7 +179,7 @@ public abstract class AbstractVcs extends S */ @Nullable protected RollbackEnvironment createRollbackEnvironment() { - return IllegalStateProxy.create(RollbackEnvironment.class); + return null; } /** @@ -213,7 +212,7 @@ public abstract class AbstractVcs extends S */ @Nullable protected UpdateEnvironment createUpdateEnvironment() { - return IllegalStateProxy.create(UpdateEnvironment.class); + return null; } /** @@ -584,6 +583,12 @@ public abstract class AbstractVcs extends S myRollbackEnvironment = rollbackEnvironment; } + public void setupEnvironments() { + setCheckinEnvironment(createCheckinEnvironment()); + setUpdateEnvironment(createUpdateEnvironment()); + setRollbackEnvironment(createRollbackEnvironment()); + } + public boolean reportsIgnoredDirectories() { return true; } diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/ForwardingListener.java b/platform/vcs-api/src/com/intellij/openapi/vcs/ForwardingListener.java deleted file mode 100644 index 120111989b12..000000000000 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/ForwardingListener.java +++ /dev/null @@ -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 implements Consumer>> { - private final T myT; - - public ForwardingListener(T t) { - myT = t; - } - - @Override - public void consume(Pair> vcsKeyConsumerPair) { - vcsKeyConsumerPair.getSecond().consume(myT); - } -} diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java b/platform/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java index 938021c03e55..9e64eb092089 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java @@ -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(); diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsActiveEnvironmentsProxy.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsActiveEnvironmentsProxy.java deleted file mode 100644 index c031ea0bf8b1..000000000000 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsActiveEnvironmentsProxy.java +++ /dev/null @@ -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; - } - } -} diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsEventsListenerManager.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsEventsListenerManager.java index 562625a814df..9f26db671cef 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsEventsListenerManager.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsEventsListenerManager.java @@ -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); diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/impl/IllegalStateProxy.java b/platform/vcs-api/src/com/intellij/openapi/vcs/impl/IllegalStateProxy.java deleted file mode 100644 index e4ecd49463f8..000000000000 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/impl/IllegalStateProxy.java +++ /dev/null @@ -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 create(final Class clazz) { - return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, HANDLER); - } -} diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/impl/VcsEnvironmentsProxyCreator.java b/platform/vcs-api/src/com/intellij/openapi/vcs/impl/VcsEnvironmentsProxyCreator.java deleted file mode 100644 index eea5ff2dde86..000000000000 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/impl/VcsEnvironmentsProxyCreator.java +++ /dev/null @@ -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); -} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java index fd8d46cf9da4..0737c97057f4 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java @@ -112,7 +112,6 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme private final Map myBackgroundableActionHandlerMap; private final List> myPendingOutput = new ArrayList>(); - 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(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsEP.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsEP.java index 527a1f87961b..a3f8ee79e7d2 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsEP.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsEP.java @@ -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; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsEventsListenerManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsEventsListenerManagerImpl.java deleted file mode 100644 index b60861caa698..000000000000 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsEventsListenerManagerImpl.java +++ /dev/null @@ -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 myCheckinWrapper; - private final Wrapper myUpdateWrapper; - private final Wrapper myRollbackWrapper; - - public VcsEventsListenerManagerImpl() { - myCheckinWrapper = new Wrapper(CheckinEnvironment.class); - myUpdateWrapper = new Wrapper(UpdateEnvironment.class); - myRollbackWrapper = new Wrapper(RollbackEnvironment.class); - } - - @Override - public Object addCheckin(final Consumer>> consumer) { - return myCheckinWrapper.add(consumer); - } - - @Override - public Object addUpdate(final Consumer>> consumer) { - return myUpdateWrapper.add(consumer); - } - - @Override - public Object addRollback(final Consumer>> 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 { - private final Map myListenersMap; - private final Map> myExistingMulticasters; - private final Class myClazz; - private final Object myLock; - private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.impl.VcsEventsListenerManagerImpl.Wrapper"); - - private Wrapper(final Class clazz) { - myClazz = clazz; - myListenersMap = new HashMap(); - myExistingMulticasters = Collections.synchronizedMap(new HashMap>()); - myLock = new Object(); - } - - @Nullable - public T createProxy(final VcsKey key, @Nullable final T environment) { - if (environment == null) return null; - final EventDispatcher 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>(key, new Consumer() { - @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>> consumer) { - final Object key = new Object(); - synchronized (myLock) { - EventListenerWrapper listenerWrapper = new EventListenerWrapper(consumer); - myListenersMap.put(key, listenerWrapper); - for (EventDispatcher 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 dispatcher : myExistingMulticasters.values()) { - dispatcher.removeListener(listenerWrapper); - } - } - } - } - - private interface EventListenerWrapperI extends Consumer>>, EventListener {} - - private static class EventListenerWrapper implements EventListenerWrapperI { - private final Consumer>> myConsumer; - - public EventListenerWrapper(Consumer>> consumer) { - myConsumer = consumer; - } - - @Override - public void consume(Pair> vcsKeyConsumerPair) { - myConsumer.consume(vcsKeyConsumerPair); - } - } - } -} diff --git a/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/changes/committed/VcsEventsListenerTest.java b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/changes/committed/VcsEventsListenerTest.java deleted file mode 100644 index 0a09317968bc..000000000000 --- a/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/changes/committed/VcsEventsListenerTest.java +++ /dev/null @@ -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 list = Arrays.asList(new VirtualFile[]{myWorkingCopyDir}); - final MyCheckinListener listener = new MyCheckinListener(list); - final Object key = manager.addCheckin(new ForwardingListener(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 context) throws ProcessCanceledException { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public Configurable createConfigurable(Collection files) { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public boolean validateOptions(Collection 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 changes, - List vcsExceptions, - @NotNull RollbackProgressListener listener) { - //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public void rollbackMissingFileDeletion(List files, - List exceptions, - RollbackProgressListener listener) { - //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public void rollbackModifiedWithoutCheckout(List files, - List 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 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 commit(List changes, String preparedComment) { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public List commit(List changes, - String preparedComment, - @NotNull NullableFunction parametersHolder, Set feedback) { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public List scheduleMissingFileForDeletion(List files) { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public List scheduleUnversionedFilesForAddition(List 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 myCheckList; - - public MyCheckinListener(final List checkList) { - myCheckList = checkList; - myChecked = false; - myAssertOk = true; - } - - @Override - public RefreshableOnComponent createAdditionalOptionsPanel(CheckinProjectPanel panel, - PairConsumer 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 commit(List changes, String preparedComment) { - return null; - } - - @Override - public List commit(List changes, - String preparedComment, - @NotNull NullableFunction parametersHolder, Set feedback) { - return null; - } - - @Override - public List scheduleMissingFileForDeletion(List files) { - return null; - } - - @Override - public List scheduleUnversionedFilesForAddition(List 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; - } - } -}