use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class ClientPropertiesManager method checkInitDefaultManager.
private static void checkInitDefaultManager() {
synchronized (DEFAULT_MANAGER_LOCK) {
// in Upsource projectOpened can be executed concurrently for 2 projects
if (ourDefaultManager == null) {
ourDefaultManager = new ClientPropertiesManager();
try {
//noinspection HardCodedStringLiteral
final Document document = new SAXBuilder().build(ClientPropertiesManager.class.getResource("/" + COMPONENT_NAME + ".xml"));
final Element child = document.getRootElement();
ourDefaultManager.readExternal(child);
} catch (Exception e) {
LOG.error(e);
}
}
}
}
use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class YouTrackRepository method getAvailableTaskStates.
@NotNull
@Override
public Set<CustomTaskState> getAvailableTaskStates(@NotNull Task task) throws Exception {
final HttpMethod method = doREST("/rest/issue/" + task.getId() + "/execute/intellisense?command=" + encodeUrl("state: "), false);
try {
final InputStream stream = method.getResponseBodyAsStream();
final Element element = new SAXBuilder(false).build(stream).getRootElement();
return ContainerUtil.map2Set(element.getChild("suggest").getChildren("item"), element1 -> {
final String stateName = element1.getChildText("option");
return new CustomTaskState(stateName, stateName);
});
} finally {
method.releaseConnection();
}
}
use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class YouTrackRepository method checkVersion.
private void checkVersion() throws Exception {
HttpMethod method = doREST("/rest/workflow/version", false);
try {
InputStream stream = method.getResponseBodyAsStream();
Element element = new SAXBuilder(false).build(stream).getRootElement();
final boolean timeTrackingAvailable = element.getName().equals("version") && VersionComparatorUtil.compare(element.getChildText("version"), "4.1") >= 0;
if (!timeTrackingAvailable) {
throw new Exception("Time tracking is not supported in this version of Youtrack");
}
} finally {
method.releaseConnection();
}
}
use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class YouTrackRepository method doREST.
HttpMethod doREST(String request, boolean post) throws Exception {
HttpClient client = login(new PostMethod(getUrl() + "/rest/user/login"));
String uri = getUrl() + request;
HttpMethod method = post ? new PostMethod(uri) : new GetMethod(uri);
configureHttpMethod(method);
int status = client.executeMethod(method);
if (status == 400) {
InputStream string = method.getResponseBodyAsStream();
Element element = new SAXBuilder(false).build(string).getRootElement();
TaskUtil.prettyFormatXmlToLog(LOG, element);
if ("error".equals(element.getName())) {
throw new Exception(element.getText());
}
}
return method;
}
use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class PivotalTrackerRepository method setTaskState.
@Override
public void setTaskState(@NotNull Task task, @NotNull TaskState state) throws Exception {
final String realId = getRealId(task.getId());
if (realId == null)
return;
final String stateName;
switch(state) {
case IN_PROGRESS:
stateName = "started";
break;
case RESOLVED:
stateName = "finished";
break;
// may add some others in future
default:
return;
}
String url = API_URL + "/projects/" + myProjectId + "/stories/" + realId;
url += "?" + encodeUrl("story[current_state]") + "=" + encodeUrl(stateName);
LOG.info("Updating issue state by id: " + url);
final HttpMethod method = doREST(url, HTTPMethod.PUT);
final InputStream stream = method.getResponseBodyAsStream();
final Element element = new SAXBuilder(false).build(stream).getRootElement();
if (!element.getName().equals("story")) {
if (element.getName().equals("errors")) {
throw new Exception(extractErrorMessage(element));
} else {
// unknown error, probably our fault
LOG.warn("Error setting state for: " + url + ", HTTP status code: " + method.getStatusCode());
throw new Exception(String.format("Cannot set state '%s' for issue.", stateName));
}
}
}
Aggregations