Skip to content

Instantly share code, notes, and snippets.

@nickname55
Created April 14, 2025 20:34
Show Gist options
  • Save nickname55/35c4efc1c6e57ef26f8269b7b14aa7d1 to your computer and use it in GitHub Desktop.
Save nickname55/35c4efc1c6e57ef26f8269b7b14aa7d1 to your computer and use it in GitHub Desktop.
Minimal Java client for Jira plugin upload via UPM + Apache HttpClient)
package pmpshk.atlassian.upm;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
import java.io.File;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException {
uploadPlugin(new File("e:\\inspections\\target\\inspections-1.0.22-SNAPSHOT.jar"));
}
final static String baseUrl = "http://localhost";
public static JSONObject uploadPlugin(File pluginJarFile) throws IOException {
// 1. Получение upm-token
HttpGet get = new HttpGet(baseUrl + "/rest/plugins/1.0/");
get.addHeader("X-Atlassian-Token", "no-check");
get.addHeader(BasicScheme.authenticate(
new UsernamePasswordCredentials("username", "password"), "UTF-8", false));
try (CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse response = client.execute(get)) {
String upmToken = response.getFirstHeader("upm-token").getValue();
// 2. Загрузка плагина
HttpPost post = new HttpPost(baseUrl + "/rest/plugins/1.0/?token=" + upmToken);
post.addHeader("X-Atlassian-Token", "no-check");
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("plugin", pluginJarFile, ContentType.DEFAULT_BINARY, pluginJarFile.getName());
post.setEntity(builder.build());
try (CloseableHttpResponse uploadResponse = client.execute(post)) {
String result = EntityUtils.toString(uploadResponse.getEntity());
return new JSONObject(result); // Используем org.json
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment