|
1 | 1 | package net.servicestack.idea;
|
2 | 2 |
|
| 3 | +import com.google.gson.JsonElement; |
| 4 | +import com.google.gson.JsonParser; |
3 | 5 | import com.intellij.ide.util.PackageChooserDialog;
|
4 | 6 | import com.intellij.openapi.module.Module;
|
5 | 7 | import com.intellij.openapi.project.Project;
|
|
16 | 18 | import javax.swing.event.DocumentListener;
|
17 | 19 | import java.awt.*;
|
18 | 20 | import java.awt.event.*;
|
| 21 | +import java.io.BufferedReader; |
| 22 | +import java.io.IOException; |
| 23 | +import java.io.InputStreamReader; |
| 24 | +import java.net.MalformedURLException; |
19 | 25 | import java.net.URL;
|
| 26 | +import java.net.URLConnection; |
| 27 | +import java.util.*; |
20 | 28 |
|
21 | 29 | public class AddRef extends JDialog {
|
22 | 30 | private JPanel contentPane;
|
@@ -45,6 +53,8 @@ public AddRef(@NotNull Module module) {
|
45 | 53 |
|
46 | 54 | buttonOK.setEnabled(false);
|
47 | 55 |
|
| 56 | + |
| 57 | + |
48 | 58 | addressUrlTextField.setInputVerifier(new InputVerifier() {
|
49 | 59 | @Override
|
50 | 60 | public boolean verify(JComponent input) {
|
@@ -186,6 +196,33 @@ private void processOK() {
|
186 | 196 | errorMessage = null;
|
187 | 197 | errorTextPane.setVisible(false);
|
188 | 198 |
|
| 199 | + URL serviceUrl; |
| 200 | + try { |
| 201 | + serviceUrl = new URL("https://api.github.com/repos/ServiceStack/ServiceStack.Java/tags"); |
| 202 | + URLConnection javaResponseConnection = serviceUrl.openConnection(); |
| 203 | + StringBuilder builder = new StringBuilder(); |
| 204 | + BufferedReader javaResponseReader = new BufferedReader( |
| 205 | + new InputStreamReader( |
| 206 | + javaResponseConnection.getInputStream())); |
| 207 | + String metadataInputLine; |
| 208 | + |
| 209 | + while ((metadataInputLine = javaResponseReader.readLine()) != null) |
| 210 | + builder.append(metadataInputLine); |
| 211 | + |
| 212 | + |
| 213 | + JsonElement jElement = new JsonParser().parse(builder.toString()); |
| 214 | + if(jElement.getAsJsonArray().size() > 0) { |
| 215 | + String latestTag = jElement.getAsJsonArray().get(0).getAsJsonObject().get("name").getAsJsonPrimitive().getAsString(); |
| 216 | + AddServiceStackRefHandler.setDependencyVersion(latestTag.substring(1)); |
| 217 | + } |
| 218 | + |
| 219 | + } catch (MalformedURLException e) { |
| 220 | + e.printStackTrace(); |
| 221 | + } catch (IOException e) { |
| 222 | + e.printStackTrace(); |
| 223 | + } |
| 224 | + |
| 225 | + |
189 | 226 | Runnable r = new Runnable() {
|
190 | 227 | public void run() {
|
191 | 228 | try {
|
|
0 commit comments