代码如下:
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.taskadapter.redmineapi.RedmineManager;
import com.taskadapter.redmineapi.bean.CustomField;
import com.taskadapter.redmineapi.bean.Issue;
import com.taskadapter.redmineapi.bean.Project;
import com.taskadapter.redmineapi.bean.Tracker;
import com.taskadapter.redmineapi.bean.User;
public class Simple {
// private static final String 98555a0d30ce752b8dcf944031373f74bd11dd1a = null;
private static Object issues;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
RedmineManager mgr = new RedmineManager("http://localhost/redmine/", "e422ba2d69f8ad49ddc376c9cab531e6e1de992d");
// RedmineManager mgr = new RedmineManager("http://localhost/redmine/", "chenaq","19820720");
try {
// tryGetIssues(mgr);
tryMakeIssue(mgr);
// Project project = mgr.getProjectByKey("1");
// System.out.println(project.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
private static void tryGetIssues(RedmineManager mgr) throws Exception {
List<Issue> issues = mgr.getIssues(null, null);
// Issue issue = mgr.getIssueById(1);
for (Issue issue : issues) {
System.out.println(issue.toString());
}
}
private static void tryMakeIssue(RedmineManager mgr) throws Exception {
// Issue is = new Issue();
// is.setSubject( "redmine-api-test");
// mgr.createIssue(null, is);
// System.out.println("create");
Date date = new Date();
Issue issue = new Issue();
Tracker tracker = new Tracker();
User user = new User();
List<CustomField> customFields = new ArrayList<CustomField>();
CustomField customField = new CustomField();
// List<String> values = new ArrayList<String>();
// values.add("TC0003");
// values.add("TC0004");
customField.setId(4);
customField.setName("缺陷ID");
customField.setValue("TC0002");
// customField.setValues(values);
customFields.add(customField);
user.setId(5);
user.setLogin("yangfei");
tracker.setId(4);
tracker.setName("缺陷");
issue.setSubject("功能缺陷障碍(TC缺陷ID:TC0001)");
issue.setDescription("柜台子系统缺陷");
issue.setAuthor(user);
user.setId(4);
user.setLogin("liulin");
issue.setAssignee(user);
issue.setTracker(tracker);
issue.setStartDate(date);
issue.setStatusId(2);
issue.setPriorityId(3);
issue.setCustomFields(customFields);
mgr.createIssue("1", issue);
System.out.println(issue.toString());
}
}
其中依赖的库下载地址:
http://mvnrepository.com/artifact/com.taskadapter/redmine-java-api
参考:
http://www.redmine.org/projects/redmine/wiki/Rest_api_with_java
其他语言的api:
http://www.redmine.org/projects/redmine/wiki/Rest_api/