mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-84619 Changelist becomes dissociated with a task on commit
This commit is contained in:
@@ -66,6 +66,9 @@ public abstract class TaskManager {
|
||||
@NotNull
|
||||
public abstract LocalTask getActiveTask();
|
||||
|
||||
@Nullable
|
||||
public abstract LocalTask findTask(String id);
|
||||
|
||||
/**
|
||||
* Update issue cache asynchronously
|
||||
* @param onComplete callback to be invoked after updating
|
||||
|
||||
@@ -20,11 +20,16 @@ import com.intellij.tasks.TaskRepository;
|
||||
import com.intellij.tasks.TaskRepositoryType;
|
||||
import com.intellij.util.xmlb.annotations.Tag;
|
||||
import com.intellij.util.xmlb.annotations.Transient;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public abstract class BaseRepository extends TaskRepository {
|
||||
private static final Pattern PATTERN = Pattern.compile("[A-Z]+\\-\\d+");
|
||||
protected String myUsername = "";
|
||||
protected String myPassword = "";
|
||||
protected boolean myUseProxy;
|
||||
@@ -110,4 +115,10 @@ public abstract class BaseRepository extends TaskRepository {
|
||||
public void setUseHttpAuthentication(boolean useHttpAuthentication) {
|
||||
myUseHttpAuthentication = useHttpAuthentication;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String extractId(String taskName) {
|
||||
Matcher matcher = PATTERN.matcher(taskName);
|
||||
return matcher.find() ? matcher.group() : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Base class for HTTP-based repositories.
|
||||
@@ -26,8 +24,6 @@ public abstract class BaseRepositoryImpl extends BaseRepository {
|
||||
Protocol.registerProtocol(EASY_HTTPS, new Protocol(EASY_HTTPS, (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443));
|
||||
}
|
||||
|
||||
private static final Pattern PATTERN = Pattern.compile("[A-Z]+\\-\\d+");
|
||||
|
||||
protected BaseRepositoryImpl() {
|
||||
}
|
||||
|
||||
@@ -39,12 +35,6 @@ public abstract class BaseRepositoryImpl extends BaseRepository {
|
||||
super(other);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String extractId(String taskName) {
|
||||
Matcher matcher = PATTERN.matcher(taskName);
|
||||
return matcher.find() ? matcher.group() : null;
|
||||
}
|
||||
|
||||
protected static String encodeUrl(String s) {
|
||||
try {
|
||||
return URLEncoder.encode(s, "UTF-8");
|
||||
|
||||
@@ -69,14 +69,17 @@ public class TaskCheckinHandlerFactory extends CheckinHandlerFactory {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Task findTask(String message, TaskManager manager) {
|
||||
private static LocalTask findTask(String message, TaskManager manager) {
|
||||
TaskRepository[] repositories = manager.getAllRepositories();
|
||||
for (TaskRepository repository : repositories) {
|
||||
String id = repository.extractId(message);
|
||||
if (id == null) continue;
|
||||
LocalTask localTask = manager.findTask(id);
|
||||
if (localTask != null) return localTask;
|
||||
try {
|
||||
Task task = repository.findTask(id);
|
||||
if (task != null) {
|
||||
return task;
|
||||
return manager.addTask(task);
|
||||
}
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
|
||||
@@ -226,6 +226,11 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
|
||||
return myActiveTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalTask findTask(String id) {
|
||||
return myTasks.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Task> getIssues(String query) {
|
||||
return getIssues(query, true);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.intellij.tasks;
|
||||
|
||||
import com.intellij.tasks.impl.LocalTaskImpl;
|
||||
import com.intellij.tasks.impl.TaskManagerImpl;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
@@ -26,6 +27,10 @@ public abstract class TaskManagerTestCase extends LightCodeInsightFixtureTestCas
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
myManager.setRepositories(Collections.<TaskRepository>emptyList());
|
||||
LocalTaskImpl[] tasks = myManager.getLocalTasks();
|
||||
for (LocalTaskImpl task : tasks) {
|
||||
myManager.removeTask(task);
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,12 @@
|
||||
package com.intellij.tasks;
|
||||
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.ChangeListManager;
|
||||
import com.intellij.openapi.vcs.changes.ChangeListManagerImpl;
|
||||
import com.intellij.openapi.vcs.changes.LocalChangeList;
|
||||
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.impl.LocalTaskImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -70,6 +72,28 @@ public class TaskVcsTest extends TaskManagerTestCase {
|
||||
assertEquals("TEST-001 Summary 001 TEST", info.comment);
|
||||
}
|
||||
|
||||
public void testSaveContextOnCommit() throws Exception {
|
||||
Task task = myRepository.findTask("TEST-001");
|
||||
assertNotNull(task);
|
||||
myManager.activateTask(task, false, true);
|
||||
|
||||
assertEquals(2, myManager.getLocalTasks().length); // default + new one
|
||||
LocalTask localTask = myManager.getActiveTask();
|
||||
List<ChangeListInfo> changelists = myManager.getOpenChangelists(localTask);
|
||||
|
||||
ChangeListInfo info = changelists.get(0);
|
||||
LocalChangeList changeList = ChangeListManager.getInstance(getProject()).getChangeList(info.id);
|
||||
assertNotNull(changeList);
|
||||
assertEquals(changeList.getId(), localTask.getAssociatedChangelistId());
|
||||
|
||||
CommitChangeListDialog.commitChanges(getProject(), Collections.<Change>emptyList(), changeList, null, changeList.getName());
|
||||
|
||||
assertEquals(2, myManager.getLocalTasks().length); // no extra task created
|
||||
|
||||
LocalTask associatedTask = myManager.getAssociatedTask(changeList);
|
||||
assertNotNull(associatedTask); // association should survive
|
||||
}
|
||||
|
||||
private ChangeListInfo createChangelist(Task task) {
|
||||
clearChangeLists();
|
||||
LocalTaskImpl localTask = new LocalTaskImpl(task);
|
||||
|
||||
@@ -43,11 +43,6 @@ class TestRepository extends BaseRepository {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String extractId(String taskName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfigured() {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user