diff --git a/plugins/tasks/tasks-core/src/META-INF/plugin.xml b/plugins/tasks/tasks-core/src/META-INF/plugin.xml index eabaf827f203..97448e864503 100644 --- a/plugins/tasks/tasks-core/src/META-INF/plugin.xml +++ b/plugins/tasks/tasks-core/src/META-INF/plugin.xml @@ -106,6 +106,8 @@ + + diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/trac/TracRepository.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/trac/TracRepository.java new file mode 100644 index 000000000000..5ad4d095ae65 --- /dev/null +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/trac/TracRepository.java @@ -0,0 +1,106 @@ +/* + * Copyright 2000-2011 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.trac; + +import com.intellij.tasks.Task; +import com.intellij.tasks.impl.BaseRepository; +import com.intellij.tasks.impl.BaseRepositoryImpl; +import com.intellij.tasks.impl.LocalTaskImpl; +import com.intellij.util.NullableFunction; +import com.intellij.util.containers.ContainerUtil; +import org.apache.xmlrpc.*; +import org.jetbrains.annotations.Nullable; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Arrays; +import java.util.List; +import java.util.Vector; + +/** + * @author Dmitry Avdeev + */ +public class TracRepository extends BaseRepositoryImpl implements XmlRpcTransportFactory { + + @Override + public Task[] getIssues(@Nullable String query, int max, long since) throws Exception { + final XmlRpcClient client = getRpcClient(); + Object[] result = (Object[])client.execute("ticket.query", new Vector(Arrays.asList(query == null ? "" : query))); + + if (result == null) throw new Exception("Cannot connect to " + getUrl()); + + List tasks = ContainerUtil.mapNotNull(result, new NullableFunction() { + @Override + public Task fun(Object o) { + try { + return getTask((Integer)o, client); + } + catch (Exception e) { + return null; + } + } + }); + return tasks.toArray(new Task[tasks.size()]); + } + + private XmlRpcClient getRpcClient() throws MalformedURLException { + return new XmlRpcClient(new URL(getUrl()), this); + } + + @Override + public Task findTask(String id) throws Exception { + return getTask(Integer.parseInt(id), getRpcClient()); + } + + private static Task getTask(int id, XmlRpcClient client) throws IOException, XmlRpcException { + Object response = client.execute("ticket.get", new Vector(Arrays.asList(id))); + LocalTaskImpl task = new LocalTaskImpl(); + return task; + } + + @Override + public void testConnection() throws Exception { + getIssues("", 0, 0); + } + + @Override + public BaseRepository clone() { + return new TracRepository(this); + } + + public TracRepository(TracRepositoryType repositoryType) { + super(repositoryType); + } + + private TracRepository(TracRepository other) { + super(other); + } + + @Override + public XmlRpcTransport createTransport() throws XmlRpcClientException { + try { + return new CommonsXmlRpcTransport(new URL(getUrl()), getHttpClient()); + } + catch (MalformedURLException e) { + throw new XmlRpcClientException(e.getMessage(), e); + } + } + + @Override + public void setProperty(String propertyName, Object value) { + } +} diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/trac/TracRepositoryType.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/trac/TracRepositoryType.java new file mode 100644 index 000000000000..9e3eb7152dbf --- /dev/null +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/trac/TracRepositoryType.java @@ -0,0 +1,53 @@ +/* + * Copyright 2000-2011 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.trac; + +import com.intellij.openapi.util.IconLoader; +import com.intellij.tasks.TaskRepository; +import com.intellij.tasks.impl.BaseRepositoryType; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +/** + * @author Dmitry Avdeev + */ +public class TracRepositoryType extends BaseRepositoryType { + + private static final Icon ICON = IconLoader.getIcon("/com/intellij/tasks/trac/trac.png"); + + @NotNull + @Override + public String getName() { + return "Trac"; + } + + @Override + public Icon getIcon() { + return ICON; + } + + @NotNull + @Override + public TaskRepository createRepository() { + return new TracRepository(this); + } + + @Override + public Class getRepositoryClass() { + return TracRepository.class; + } +} diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/trac/trac.png b/plugins/tasks/tasks-core/src/com/intellij/tasks/trac/trac.png new file mode 100644 index 000000000000..a2102e7c0d6e Binary files /dev/null and b/plugins/tasks/tasks-core/src/com/intellij/tasks/trac/trac.png differ diff --git a/plugins/tasks/tasks-core/tasks-core.iml b/plugins/tasks/tasks-core/tasks-core.iml index 1bbf0e271917..56bea5403583 100644 --- a/plugins/tasks/tasks-core/tasks-core.iml +++ b/plugins/tasks/tasks-core/tasks-core.iml @@ -27,6 +27,7 @@ +