mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -3,6 +3,9 @@ package com.intellij.tasks.jira;
|
||||
import com.intellij.tasks.LocalTask;
|
||||
import com.intellij.tasks.Task;
|
||||
import com.intellij.tasks.TaskState;
|
||||
import com.intellij.tasks.jira.rest.api2.JiraRestApi2;
|
||||
import com.intellij.tasks.jira.rest.api20alpha1.JiraRestApi20Alpha1;
|
||||
import com.intellij.tasks.jira.soap.JiraSoapApi;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -20,13 +23,6 @@ public abstract class JiraRemoteApi {
|
||||
myRepository = repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to clone original repository in {@link TaskRepositoryConfigurable}
|
||||
* @param repository new repository for which copy should be created
|
||||
* @return new instance of this {@link JiraRemoteApi}
|
||||
*/
|
||||
public abstract JiraRemoteApi cloneFor(@NotNull JiraRepository repository);
|
||||
|
||||
@NotNull
|
||||
public abstract List<Task> findTasks(String jql, int max) throws Exception;
|
||||
|
||||
@@ -38,13 +34,52 @@ public abstract class JiraRemoteApi {
|
||||
public abstract void updateTimeSpend(LocalTask task, String timeSpent, String comment) throws Exception;
|
||||
|
||||
@NotNull
|
||||
public abstract String getVersionName();
|
||||
public final String getVersionName() {
|
||||
return getType().getVersionName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
return "JiraRemoteApi(" + getType().getVersionName() + ")";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract ApiType getType();
|
||||
|
||||
public enum ApiType {
|
||||
SOAP,
|
||||
REST
|
||||
SOAP("SOAP") {
|
||||
@NotNull
|
||||
@Override
|
||||
public JiraSoapApi createApi(@NotNull JiraRepository repository) {
|
||||
return new JiraSoapApi(repository);
|
||||
}
|
||||
},
|
||||
REST_2_0("REST 2.0") {
|
||||
@NotNull
|
||||
@Override
|
||||
public JiraRestApi2 createApi(@NotNull JiraRepository repository) {
|
||||
return new JiraRestApi2(repository);
|
||||
}
|
||||
},
|
||||
REST_2_0_ALPHA("REST 2.0.alpha1") {
|
||||
@NotNull
|
||||
@Override
|
||||
public JiraRestApi20Alpha1 createApi(@NotNull JiraRepository repository) {
|
||||
return new JiraRestApi20Alpha1(repository);
|
||||
}
|
||||
};
|
||||
|
||||
ApiType(String versionName) {
|
||||
myVersionName = versionName;
|
||||
}
|
||||
private String myVersionName;
|
||||
@NotNull
|
||||
public abstract JiraRemoteApi createApi(@NotNull JiraRepository repository);
|
||||
|
||||
@NotNull
|
||||
public String getVersionName() {
|
||||
return myVersionName;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class JiraRepository extends BaseRepositoryImpl {
|
||||
super(other);
|
||||
mySearchQuery = other.mySearchQuery;
|
||||
if (other.myApiVersion != null) {
|
||||
myApiVersion = other.myApiVersion.cloneFor(this);
|
||||
myApiVersion = other.myApiVersion.getType().createApi(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class JiraRepository extends BaseRepositoryImpl {
|
||||
ensureApiVersionDiscovered();
|
||||
String jqlQuery = mySearchQuery;
|
||||
if (StringUtil.isNotEmpty(mySearchQuery) && StringUtil.isNotEmpty(query)) {
|
||||
jqlQuery += String.format(" and summary ~ '%s'", query);
|
||||
jqlQuery = String.format("summary ~ '%s' and ", query) + mySearchQuery;
|
||||
}
|
||||
else if (StringUtil.isNotEmpty(query)) {
|
||||
jqlQuery = String.format("summary ~ '%s'", query);
|
||||
@@ -120,7 +120,7 @@ public class JiraRepository extends BaseRepositoryImpl {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JiraRemoteApi discoverRestApiVersion() throws Exception {
|
||||
public JiraRemoteApi discoverApiVersion() throws Exception {
|
||||
String responseBody;
|
||||
GetMethod method = new GetMethod(getRestUrl("serverInfo"));
|
||||
try {
|
||||
@@ -149,7 +149,7 @@ public class JiraRepository extends BaseRepositoryImpl {
|
||||
|
||||
private void ensureApiVersionDiscovered() throws Exception {
|
||||
if (myApiVersion == null) {
|
||||
myApiVersion = discoverRestApiVersion();
|
||||
myApiVersion = discoverApiVersion();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ public class JiraRepository extends BaseRepositoryImpl {
|
||||
@Override
|
||||
protected int getFeatures() {
|
||||
int features = super.getFeatures() | TIME_MANAGEMENT;
|
||||
if (myApiVersion == null || myApiVersion.getType() != JiraRemoteApi.ApiType.REST) {
|
||||
if (myApiVersion == null || myApiVersion.getType() != JiraRemoteApi.ApiType.REST_2_0) {
|
||||
return features & ~NATIVE_SEARCH & ~STATE_UPDATING & ~TIME_MANAGEMENT;
|
||||
}
|
||||
return features;
|
||||
@@ -250,12 +250,29 @@ public class JiraRepository extends BaseRepositoryImpl {
|
||||
@Override
|
||||
public void setUrl(String url) {
|
||||
// reset remote API version, only if server URL was changed
|
||||
if (!getUrl().equals(url)) {
|
||||
if (!getUrl().equals(url)) {
|
||||
myApiVersion = null;
|
||||
super.setUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to preserve discovered API version for the next initialization.
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
@Nullable
|
||||
public JiraRemoteApi.ApiType getApiType() {
|
||||
return myApiVersion == null? null : myApiVersion.getType();
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setApiType(@Nullable JiraRemoteApi.ApiType type) {
|
||||
if (type != null) {
|
||||
myApiVersion = type.createApi(this);
|
||||
}
|
||||
}
|
||||
|
||||
public String getRestUrl(String... parts) {
|
||||
return getUrl() + REST_API_PATH + "/" + StringUtil.join(parts, "/");
|
||||
}
|
||||
|
||||
@@ -94,11 +94,6 @@ public abstract class JiraRestApi extends JiraRemoteApi {
|
||||
@Nullable
|
||||
protected abstract JiraIssue parseIssue(String response);
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("JiraRestAPI(%s)", getVersionName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTaskState(Task task, TaskState state) throws Exception {
|
||||
String requestBody = getRequestForStateTransition(state);
|
||||
@@ -111,12 +106,6 @@ public abstract class JiraRestApi extends JiraRemoteApi {
|
||||
myRepository.executeMethod(method);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public final ApiType getType() {
|
||||
return ApiType.REST;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract String getRequestForStateTransition(@NotNull TaskState state);
|
||||
|
||||
|
||||
+2
-8
@@ -5,7 +5,6 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.tasks.LocalTask;
|
||||
import com.intellij.tasks.TaskState;
|
||||
import com.intellij.tasks.jira.JiraRemoteApi;
|
||||
import com.intellij.tasks.jira.JiraRepository;
|
||||
import com.intellij.tasks.jira.rest.JiraRestApi;
|
||||
import com.intellij.tasks.jira.rest.api2.model.JiraIssueApi2;
|
||||
@@ -34,11 +33,6 @@ public class JiraRestApi2 extends JiraRestApi {
|
||||
super(repository);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JiraRemoteApi cloneFor(@NotNull JiraRepository repository) {
|
||||
return new JiraRestApi2(repository);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected GetMethod getMultipleIssuesSearchMethod(String jql, int max) {
|
||||
@@ -102,7 +96,7 @@ public class JiraRestApi2 extends JiraRestApi {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getVersionName() {
|
||||
return "2.0";
|
||||
public ApiType getType() {
|
||||
return ApiType.REST_2_0;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-8
@@ -4,7 +4,6 @@ import com.google.gson.reflect.TypeToken;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.tasks.LocalTask;
|
||||
import com.intellij.tasks.TaskState;
|
||||
import com.intellij.tasks.jira.JiraRemoteApi;
|
||||
import com.intellij.tasks.jira.JiraRepository;
|
||||
import com.intellij.tasks.jira.rest.JiraRestApi;
|
||||
import com.intellij.tasks.jira.rest.JiraRestTask;
|
||||
@@ -30,11 +29,6 @@ public class JiraRestApi20Alpha1 extends JiraRestApi {
|
||||
super(repository);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JiraRemoteApi cloneFor(@NotNull JiraRepository repository) {
|
||||
return new JiraRestApi20Alpha1(repository);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JiraIssue parseIssue(String response) {
|
||||
return JiraRepository.GSON.fromJson(response, JiraIssueApi20Alpha1.class);
|
||||
@@ -83,7 +77,7 @@ public class JiraRestApi20Alpha1 extends JiraRestApi {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getVersionName() {
|
||||
return "2.0.alpha1";
|
||||
public ApiType getType() {
|
||||
return ApiType.REST_2_0_ALPHA;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,11 +45,6 @@ public class JiraSoapApi extends JiraRemoteApi {
|
||||
super(repository);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JiraRemoteApi cloneFor(@NotNull JiraRepository repository) {
|
||||
return new JiraSoapApi(repository);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<Task> findTasks(String query, int max) throws Exception {
|
||||
@@ -174,12 +169,6 @@ public class JiraSoapApi extends JiraRemoteApi {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getVersionName() {
|
||||
return "SOAP";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public final ApiType getType() {
|
||||
|
||||
+9
-2
@@ -32,6 +32,9 @@ import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static com.intellij.tasks.jira.JiraRemoteApi.ApiType.REST_2_0;
|
||||
import static com.intellij.tasks.jira.JiraRemoteApi.ApiType.REST_2_0_ALPHA;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 1/15/13
|
||||
@@ -69,14 +72,18 @@ public class JiraIntegrationTest extends TaskManagerTestCase {
|
||||
|
||||
public void testVersionDiscovery() throws Exception {
|
||||
myRepository.setUrl(JIRA_5_TEST_SERVER_URL);
|
||||
assertEquals("2.0", myRepository.discoverRestApiVersion().getVersionName());
|
||||
assertEquals(REST_2_0, myRepository.discoverApiVersion().getType());
|
||||
myRepository.setUrl(JIRA_4_TEST_SERVER_URL);
|
||||
assertEquals("2.0.alpha1", myRepository.discoverRestApiVersion().getVersionName());
|
||||
assertEquals(REST_2_0_ALPHA, myRepository.discoverApiVersion().getType());
|
||||
}
|
||||
|
||||
public void testJqlQuery() throws Exception {
|
||||
myRepository.setSearchQuery("assignee = currentUser() AND (summary ~ 'foo' or resolution = Fixed)");
|
||||
assertEquals(2, myRepository.getIssues("", 50, 0).length);
|
||||
|
||||
// test that user part of query is prepended to existing one
|
||||
myRepository.setSearchQuery("assignee = currentUser() order by updated");
|
||||
assertEquals(1, myRepository.getIssues("foo", 50, 0).length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user