mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Feature-branches: VcsTaskHandler
This commit is contained in:
@@ -48,6 +48,10 @@ public class ExtensionPointName<T> {
|
||||
return Extensions.getExtensions(this);
|
||||
}
|
||||
|
||||
public T[] getExtensions(AreaInstance areaInstance) {
|
||||
return Extensions.getExtensions(this, areaInstance);
|
||||
}
|
||||
|
||||
public <V extends T> V findExtension(Class<V> instanceOf) {
|
||||
return ContainerUtil.findInstance(getExtensions(), instanceOf);
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
<extensionPoint name="vcsAnnotationGutterActionProvider" interface="com.intellij.openapi.vcs.annotate.AnnotationGutterActionProvider"/>
|
||||
<extensionPoint name="vcschangedetails" interface="com.intellij.openapi.vcs.changes.VcsChangeDetailsProvider" area="IDEA_PROJECT"/>
|
||||
|
||||
<extensionPoint name="vcs.taskHandler" interface="com.intellij.openapi.vcs.VcsTaskHandler" area="IDEA_PROJECT"/>
|
||||
|
||||
</extensionPoints>
|
||||
</idea-plugin>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.project.Project;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 16.07.13
|
||||
*/
|
||||
public abstract class VcsTaskHandler {
|
||||
|
||||
public static VcsTaskHandler[] getAllHandlers(Project project) {
|
||||
return EXTENSION_POINT_NAME.getExtensions(project);
|
||||
}
|
||||
|
||||
private static final ExtensionPointName<VcsTaskHandler> EXTENSION_POINT_NAME = ExtensionPointName.create("com.intellij.vcs.taskHandler");
|
||||
|
||||
public abstract void startNewTask(String name);
|
||||
|
||||
public abstract void switchTask(String to);
|
||||
|
||||
public abstract void closeTask(String name);
|
||||
}
|
||||
@@ -61,7 +61,7 @@
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="library" scope="TEST" name="Groovy" level="project" />
|
||||
<orderEntry type="module" module-name="dvcs" />
|
||||
<orderEntry type="module" module-name="dvcs" exported="" />
|
||||
<orderEntry type="library" scope="TEST" name="cucumber-jvm" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="cucumber-java" level="project" />
|
||||
<orderEntry type="library" name="JSch" level="project" />
|
||||
|
||||
@@ -166,6 +166,7 @@
|
||||
|
||||
<ComponentRoamingType component="Git.Settings" type="DISABLED"/>
|
||||
<fileTypeFactory implementation="git4idea.vfs.GitFileTypeFactory"/>
|
||||
<vcs.taskHandler implementation="git4idea.GitTaskHandler"/>
|
||||
</extensions>
|
||||
|
||||
<extensionPoints>
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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 git4idea;
|
||||
|
||||
import com.intellij.openapi.vcs.VcsTaskHandler;
|
||||
import git4idea.branch.GitBrancher;
|
||||
import git4idea.repo.GitRepository;
|
||||
import git4idea.repo.GitRepositoryManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 17.07.13
|
||||
*/
|
||||
public class GitTaskHandler extends VcsTaskHandler {
|
||||
|
||||
private final GitBrancher myBrancher;
|
||||
private final GitRepositoryManager myRepositoryManager;
|
||||
|
||||
public GitTaskHandler(GitBrancher brancher, GitRepositoryManager repositoryManager) {
|
||||
myBrancher = brancher;
|
||||
myRepositoryManager = repositoryManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startNewTask(String name) {
|
||||
List<GitRepository> repositories = myRepositoryManager.getRepositories();
|
||||
myBrancher.checkoutNewBranch(name, repositories);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void switchTask(String name) {
|
||||
myBrancher.checkout(name, myRepositoryManager.getRepositories(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeTask(String name) {
|
||||
myBrancher.merge(name, GitBrancher.DeleteOnMergeOption.DELETE, myRepositoryManager.getRepositories());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.tasks;
|
||||
|
||||
import com.intellij.util.xmlb.annotations.Attribute;
|
||||
import com.intellij.util.xmlb.annotations.Tag;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 18.07.13
|
||||
*/
|
||||
@Tag("branch")
|
||||
public class BranchInfo {
|
||||
|
||||
@Attribute("name")
|
||||
public String name;
|
||||
|
||||
@Attribute("repository")
|
||||
public String repository;
|
||||
}
|
||||
@@ -44,6 +44,8 @@ public abstract class LocalTask extends Task {
|
||||
return false;
|
||||
}
|
||||
|
||||
// VCS interface
|
||||
|
||||
@NotNull
|
||||
public abstract List<ChangeListInfo> getChangeLists();
|
||||
|
||||
@@ -51,6 +53,15 @@ public abstract class LocalTask extends Task {
|
||||
|
||||
public abstract void removeChangelist(final ChangeListInfo info);
|
||||
|
||||
@NotNull
|
||||
public abstract List<BranchInfo> getBranches();
|
||||
|
||||
public abstract void addBranch(BranchInfo info);
|
||||
|
||||
public abstract void removeBranch(final BranchInfo info);
|
||||
|
||||
// time tracking interface
|
||||
|
||||
public abstract long getTotalTimeSpent();
|
||||
|
||||
public abstract boolean isRunning();
|
||||
|
||||
@@ -99,7 +99,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="55d4e" class="com.intellij.ui.components.JBRadioButton" binding="myCreateBranch">
|
||||
<component id="55d4e" class="com.intellij.ui.components.JBRadioButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
@@ -107,7 +107,7 @@
|
||||
<text value="Create dedicated &branch"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b1f13" class="com.intellij.ui.components.JBRadioButton" binding="myCreateNewChangelist">
|
||||
<component id="b1f13" class="com.intellij.ui.components.JBRadioButton">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
@@ -115,7 +115,7 @@
|
||||
<text value="Create new change&list"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c4150" class="com.intellij.ui.components.JBRadioButton" binding="myDoNothing">
|
||||
<component id="c4150" class="com.intellij.ui.components.JBRadioButton">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.intellij.tasks.*;
|
||||
import com.intellij.tasks.impl.TaskManagerImpl;
|
||||
import com.intellij.tasks.impl.TaskUtil;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.components.JBRadioButton;
|
||||
import com.intellij.util.ui.RadioButtonEnumModel;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -47,9 +46,6 @@ public class SimpleOpenTaskDialog extends DialogWrapper {
|
||||
private JCheckBox myCreateChangelist;
|
||||
private JCheckBox myMarkAsInProgressBox;
|
||||
private JLabel myTaskNameLabel;
|
||||
private JBRadioButton myCreateBranch;
|
||||
private JBRadioButton myCreateNewChangelist;
|
||||
private JBRadioButton myDoNothing;
|
||||
private JPanel myVcsPanel;
|
||||
private JPanel myDistributedVcsPanel;
|
||||
private ButtonGroup myVcsGroup;
|
||||
|
||||
@@ -62,6 +62,7 @@ public class LocalTaskImpl extends LocalTask {
|
||||
private boolean myRunning = false;
|
||||
private List<WorkItem> myWorkItems = new ArrayList<WorkItem>();
|
||||
private Date myLastPost;
|
||||
private List<BranchInfo> myBranches = new ArrayList<BranchInfo>();
|
||||
|
||||
|
||||
/** for serialization */
|
||||
@@ -215,6 +216,22 @@ public class LocalTaskImpl extends LocalTask {
|
||||
myChangeLists.remove(info);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<BranchInfo> getBranches() {
|
||||
return myBranches;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBranch(BranchInfo info) {
|
||||
myBranches.add(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeBranch(BranchInfo info) {
|
||||
myBranches.add(info);
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
return myClosed;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.AbstractVcs;
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import com.intellij.openapi.vcs.VcsTaskHandler;
|
||||
import com.intellij.openapi.vcs.VcsType;
|
||||
import com.intellij.openapi.vcs.changes.*;
|
||||
import com.intellij.tasks.*;
|
||||
@@ -372,11 +373,17 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
|
||||
|
||||
@Override
|
||||
public void performVcsOperation(LocalTask task, VcsOperation operation) {
|
||||
String name = getChangelistName(task);
|
||||
if (operation == VcsOperation.CREATE_CHANGELIST) {
|
||||
String name = getChangelistName(task);
|
||||
String comment = TaskUtil.getChangeListComment(task);
|
||||
createChangeList(task, name, comment);
|
||||
}
|
||||
else if (operation == VcsOperation.CREATE_BRANCH) {
|
||||
VcsTaskHandler[] handlers = VcsTaskHandler.getAllHandlers(myProject);
|
||||
for (VcsTaskHandler handler : handlers) {
|
||||
handler.startNewTask(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void saveActiveTask() {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<orderEntry type="module" module-name="spellchecker" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="xslt-debugger" />
|
||||
<orderEntry type="module" module-name="xdebugger-impl" scope="TEST" />
|
||||
<orderEntry type="module" module-name="git4idea" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
class TestRepository extends BaseRepository {
|
||||
public class TestRepository extends BaseRepository {
|
||||
private Task[] myTasks;
|
||||
|
||||
public TestRepository(Task... tasks) {
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.tasks.vcs;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vcs.VcsTaskHandler;
|
||||
import com.intellij.tasks.TaskManagerTestCase;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import git4idea.GitLocalBranch;
|
||||
import git4idea.branch.GitBranchesCollection;
|
||||
import git4idea.repo.GitRepository;
|
||||
import git4idea.test.GitTestUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 18.07.13
|
||||
*/
|
||||
public class TaskBranchesTest extends TaskManagerTestCase {
|
||||
|
||||
public void testGitTaskHandler() throws Exception {
|
||||
|
||||
List<GitRepository> repositories = initRepositories("community", "idea");
|
||||
GitRepository repository = repositories.get(0);
|
||||
|
||||
VcsTaskHandler[] handlers = VcsTaskHandler.getAllHandlers(getProject());
|
||||
assertEquals(1, handlers.length);
|
||||
VcsTaskHandler handler = handlers[0];
|
||||
handler.startNewTask("first");
|
||||
Collection<GitLocalBranch> localBranches = repository.getBranches().getLocalBranches();
|
||||
assertEquals(2, localBranches.size());
|
||||
GitLocalBranch currentBranch = repository.getCurrentBranch();
|
||||
assertNotNull(currentBranch);
|
||||
assertEquals("first", currentBranch.getName());
|
||||
}
|
||||
|
||||
private List<GitRepository> initRepositories(String... names) {
|
||||
return ContainerUtil.map(names, new Function<String, GitRepository>() {
|
||||
@Override
|
||||
public GitRepository fun(String s) {
|
||||
return initRepository(s);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private GitRepository initRepository(String name) {
|
||||
String tempDirectory = FileUtil.getTempDirectory();
|
||||
String root = tempDirectory + "/" + name;
|
||||
assertTrue(new File(root).mkdirs());
|
||||
GitRepository repository = GitTestUtil.createRepository(getProject(), root);
|
||||
GitBranchesCollection branches = repository.getBranches();
|
||||
assertEquals(1, branches.getLocalBranches().size());
|
||||
return repository;
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.tasks;
|
||||
package com.intellij.tasks.vcs;
|
||||
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
@@ -22,6 +22,7 @@ import com.intellij.openapi.vcs.changes.*;
|
||||
import com.intellij.openapi.vcs.changes.committed.MockAbstractVcs;
|
||||
import com.intellij.openapi.vcs.changes.ui.CommitChangeListDialog;
|
||||
import com.intellij.openapi.vcs.impl.projectlevelman.AllVcses;
|
||||
import com.intellij.tasks.*;
|
||||
import com.intellij.tasks.impl.LocalTaskImpl;
|
||||
import com.intellij.tasks.impl.TaskChangelistSupport;
|
||||
import com.intellij.tasks.impl.TaskManagerImpl;
|
||||
@@ -29,6 +30,7 @@ import com.intellij.testFramework.IdeaTestCase;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import icons.TasksIcons;
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -61,7 +63,7 @@ public class TaskVcsTest extends CodeInsightFixtureTestCase {
|
||||
|
||||
assertEquals(defaultTask, myTaskManager.getAssociatedTask(myChangeListManager.getChangeListsCopy().get(0)));
|
||||
assertEquals(defaultTask.getChangeLists().get(0).id, myChangeListManager.getChangeListsCopy().get(0).getId());
|
||||
assertEquals(defaultTask.getChangeLists().get(0), new ChangeListInfo(myChangeListManager.getChangeListsCopy().get(0)));
|
||||
Assert.assertEquals(defaultTask.getChangeLists().get(0), new ChangeListInfo(myChangeListManager.getChangeListsCopy().get(0)));
|
||||
}
|
||||
|
||||
public void testSwitchingTasks() throws Exception {
|
||||
Reference in New Issue
Block a user