Load Maven version from search.maven.org
This commit is contained in:
@@ -42,6 +42,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.maven.dom.MavenDomUtil;
|
||||
import org.jetbrains.idea.maven.dom.model.*;
|
||||
import org.jetbrains.idea.maven.project.MavenProjectsManager;
|
||||
import org.jetbrains.jet.cli.common.KotlinVersion;
|
||||
import org.jetbrains.jet.plugin.JetPluginUtil;
|
||||
import org.jetbrains.jet.plugin.framework.KotlinFrameworkDetector;
|
||||
import org.jetbrains.jet.plugin.framework.ui.ConfigureDialogWithModulesAndVersion;
|
||||
@@ -49,7 +50,7 @@ import org.jetbrains.jet.plugin.framework.ui.ConfigureDialogWithModulesAndVersio
|
||||
import java.util.List;
|
||||
|
||||
public class KotlinMavenConfigurator implements KotlinProjectConfigurator {
|
||||
private static final String[] KOTLIN_VERSIONS = {"0.6.594", "0.1-SNAPSHOT"};
|
||||
private static final String[] KOTLIN_VERSIONS = {KotlinVersion.VERSION};
|
||||
|
||||
public static final String NAME = "maven";
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ import java.util.List;
|
||||
import static org.jetbrains.jet.plugin.configuration.ConfigureKotlinInProjectUtils.showInfoNotification;
|
||||
|
||||
public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfigurator {
|
||||
private static final String[] KOTLIN_VERSIONS = {"0.6.+", "0.1-SNAPSHOT"};
|
||||
private static final String[] KOTLIN_VERSIONS = {"0.6.+"};
|
||||
|
||||
protected static final String VERSION_TEMPLATE = "$VERSION$";
|
||||
|
||||
|
||||
+13
-1
@@ -13,7 +13,7 @@
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<grid id="46726" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="46726" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="10" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
@@ -35,6 +35,18 @@
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<grid id="78943" binding="infoPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="20" height="-1"/>
|
||||
<preferred-size width="20" height="-1"/>
|
||||
<maximum-size width="20" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="f8666" binding="chooseModulesPanelPlace" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
|
||||
+134
-4
@@ -16,27 +16,52 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.framework.ui;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.util.net.HttpConfigurable;
|
||||
import com.intellij.util.ui.AsyncProcessIcon;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ConfigureDialogWithModulesAndVersion extends DialogWrapper {
|
||||
private static final String VERSIONS_LIST_URL =
|
||||
"http://search.maven.org/solrsearch/select?q=g:%22org.jetbrains.kotlin%22+AND+a:%22kotlin-runtime%22&core=gav&rows=20&wt=json";
|
||||
|
||||
private final ChooseModulePanel chooseModulePanel;
|
||||
|
||||
private JPanel contentPane;
|
||||
private JPanel chooseModulesPanelPlace;
|
||||
private JComboBox kotlinVersionComboBox;
|
||||
private JPanel infoPanel;
|
||||
|
||||
private final AsyncProcessIcon processIcon = new AsyncProcessIcon("loader");
|
||||
|
||||
public ConfigureDialogWithModulesAndVersion(
|
||||
@NotNull Project project,
|
||||
@NotNull List<Module> modules,
|
||||
@NotNull String[] kotlinVersions
|
||||
@NotNull final String[] kotlinVersions
|
||||
) {
|
||||
super(project);
|
||||
|
||||
@@ -44,12 +69,30 @@ public class ConfigureDialogWithModulesAndVersion extends DialogWrapper {
|
||||
|
||||
init();
|
||||
|
||||
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Find Kotlin Maven plugin versions", false) {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
setVersions(kotlinVersions);
|
||||
}
|
||||
});
|
||||
|
||||
kotlinVersionComboBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull ActionEvent e) {
|
||||
updateComponents();
|
||||
}
|
||||
});
|
||||
|
||||
kotlinVersionComboBox.addItem("loading...");
|
||||
kotlinVersionComboBox.setEnabled(false);
|
||||
|
||||
processIcon.resume();
|
||||
infoPanel.add(processIcon, BorderLayout.CENTER);
|
||||
|
||||
chooseModulePanel = new ChooseModulePanel(project, modules);
|
||||
chooseModulesPanelPlace.add(chooseModulePanel.getContentPane(), BorderLayout.CENTER);
|
||||
|
||||
for (String version : kotlinVersions) {
|
||||
kotlinVersionComboBox.addItem(version);
|
||||
}
|
||||
updateComponents();
|
||||
}
|
||||
|
||||
public List<Module> getModulesToConfigure() {
|
||||
@@ -65,4 +108,91 @@ public class ConfigureDialogWithModulesAndVersion extends DialogWrapper {
|
||||
protected JComponent createCenterPanel() {
|
||||
return contentPane;
|
||||
}
|
||||
|
||||
private void setVersions(@NotNull String[] kotlinVersions) {
|
||||
Collection<String> items;
|
||||
try {
|
||||
items = loadVersions();
|
||||
hideLoader();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
items = Arrays.asList(kotlinVersions);
|
||||
showWarning();
|
||||
}
|
||||
updateVersions(items);
|
||||
}
|
||||
|
||||
private void hideLoader() {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
infoPanel.setVisible(false);
|
||||
infoPanel.updateUI();
|
||||
}
|
||||
}, ModalityState.stateForComponent(infoPanel));
|
||||
}
|
||||
|
||||
private void showWarning() {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
infoPanel.remove(processIcon);
|
||||
infoPanel.add(new JLabel(UIUtil.getBalloonWarningIcon()), BorderLayout.CENTER);
|
||||
infoPanel.setToolTipText("Couldn't load versions list from search.maven.org");
|
||||
infoPanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
infoPanel.updateUI();
|
||||
}
|
||||
}, ModalityState.stateForComponent(infoPanel));
|
||||
}
|
||||
|
||||
private void updateVersions(@NotNull final Collection<String> newItems) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
kotlinVersionComboBox.removeAllItems();
|
||||
kotlinVersionComboBox.setEnabled(true);
|
||||
kotlinVersionComboBox.addItem("0.1-SNAPSHOT");
|
||||
for (String newItem : newItems) {
|
||||
kotlinVersionComboBox.addItem(newItem);
|
||||
}
|
||||
kotlinVersionComboBox.setSelectedIndex(1);
|
||||
}
|
||||
}, ModalityState.stateForComponent(kotlinVersionComboBox));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static Collection<String> loadVersions() throws Exception {
|
||||
List<String> versions = Lists.newArrayList();
|
||||
|
||||
HttpURLConnection urlConnection = HttpConfigurable.getInstance().openHttpConnection(VERSIONS_LIST_URL);
|
||||
try {
|
||||
int timeout = (int) TimeUnit.SECONDS.toMillis(30);
|
||||
urlConnection.setConnectTimeout(timeout);
|
||||
urlConnection.setReadTimeout(timeout);
|
||||
|
||||
urlConnection.connect();
|
||||
|
||||
InputStreamReader streamReader = new InputStreamReader(urlConnection.getInputStream());
|
||||
try {
|
||||
JsonElement rootElement = new JsonParser().parse(streamReader);
|
||||
JsonArray docsElements = rootElement.getAsJsonObject().get("response").getAsJsonObject().get("docs").getAsJsonArray();
|
||||
|
||||
for (JsonElement element : docsElements) {
|
||||
versions.add(element.getAsJsonObject().get("v").getAsString());
|
||||
}
|
||||
}
|
||||
finally {
|
||||
streamReader.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
urlConnection.disconnect();
|
||||
}
|
||||
|
||||
return versions;
|
||||
}
|
||||
|
||||
private void updateComponents() {
|
||||
setOKActionEnabled(kotlinVersionComboBox.isEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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 org.jetbrains.jet.plugin.framework.ui;
|
||||
|
||||
import com.intellij.testFramework.LightIdeaTestCase;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class LoadVersionsFromMavenTest extends LightIdeaTestCase {
|
||||
public void testDownload() throws Exception {
|
||||
Collection<String> versions = ConfigureDialogWithModulesAndVersion.loadVersions();
|
||||
assert versions.size() > 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user