mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
jarRepository settings ui
This commit is contained in:
@@ -100,7 +100,7 @@ public class JarRepositoryManager {
|
||||
final String copyTo = dialog.getDirectoryPath();
|
||||
|
||||
final NewLibraryConfiguration config = resolveAndDownload(
|
||||
project, coord, attachSources, attachJavaDoc, copyTo, RemoteRepositoryDescription.DEFAULT_REPOSITORIES
|
||||
project, coord, attachSources, attachJavaDoc, copyTo, RemoteRepositoriesConfiguration.getInstance(project).getRepositories()
|
||||
);
|
||||
if (config == null) {
|
||||
Messages.showErrorDialog(parentComponent, "No files were downloaded for " + coord, CommonBundle.getErrorTitle());
|
||||
@@ -184,7 +184,7 @@ public class JarRepositoryManager {
|
||||
final JpsMavenRepositoryLibraryDescriptor libDescriptor = new JpsMavenRepositoryLibraryDescriptor(libraryProps.getGroupId(), libraryProps.getArtifactId(), libraryProps.getVersion());
|
||||
if (libDescriptor.getMavenId() != null) {
|
||||
if (repositories == null || repositories.isEmpty()) {
|
||||
repositories = RepositoryLibraryDescription.findDescription(libDescriptor).getRemoteRepositories();
|
||||
repositories = RemoteRepositoriesConfiguration.getInstance(project).getRepositories();
|
||||
}
|
||||
if (!repositories.isEmpty()) {
|
||||
final EnumSet<ArtifactKind> kinds = EnumSet.of(ArtifactKind.ARTIFACT);
|
||||
@@ -235,7 +235,7 @@ public class JarRepositoryManager {
|
||||
|
||||
public static void loadDependenciesAsync(Project project, JpsMavenRepositoryLibraryDescriptor desc, final Set<ArtifactKind> artifactKinds, @Nullable List<RemoteRepositoryDescription> repos, @Nullable String copyTo, Consumer<Collection<OrderRoot>> resultProcessor) {
|
||||
if (repos == null || repos.isEmpty()) {
|
||||
repos = RepositoryLibraryDescription.findDescription(desc).getRemoteRepositories();
|
||||
repos = RemoteRepositoriesConfiguration.getInstance(project).getRepositories();
|
||||
}
|
||||
submitBackgroundJob(
|
||||
project, "Resolving Maven dependencies...", newOrderRootResolveJob(desc, artifactKinds, repos, copyTo).andThen(
|
||||
@@ -247,7 +247,7 @@ public class JarRepositoryManager {
|
||||
}
|
||||
|
||||
public static void getAvailableVersionsAsync(Project project, RepositoryLibraryDescription libraryDescription, Consumer<Collection<String>> resultProcessor) {
|
||||
final List<RemoteRepositoryDescription> repos = libraryDescription.getRemoteRepositories();
|
||||
final List<RemoteRepositoryDescription> repos = RemoteRepositoriesConfiguration.getInstance(project).getRepositories();
|
||||
submitBackgroundJob(project, "Looking up available versions for " + libraryDescription.getDisplayName(), new VersionResolveJob(libraryDescription, repos)
|
||||
.andThen(
|
||||
versions -> {
|
||||
@@ -259,7 +259,7 @@ public class JarRepositoryManager {
|
||||
|
||||
@NotNull
|
||||
public static Future<Collection<String>> getAvailableVersions(Project project, RepositoryLibraryDescription libraryDescription) {
|
||||
final List<RemoteRepositoryDescription> repos = libraryDescription.getRemoteRepositories();
|
||||
final List<RemoteRepositoryDescription> repos = RemoteRepositoriesConfiguration.getInstance(project).getRepositories();
|
||||
return submitBackgroundJob(project, "Looking up available versions for " + libraryDescription.getDisplayName(), new VersionResolveJob(libraryDescription, repos));
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ public class JarRepositoryManager {
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
final List<Pair<RepositoryArtifactDescription, RemoteRepositoryDescription>> resultList = new ArrayList<>();
|
||||
try {
|
||||
for (String serviceUrl : MavenRepositoryServicesManager.getServiceUrls()) {
|
||||
for (String serviceUrl : MavenRepositoryServicesManager.getServiceUrls(project)) {
|
||||
try {
|
||||
final List<RepositoryArtifactDescription> artifacts = MavenRepositoryServicesManager.findArtifacts(template, serviceUrl);
|
||||
if (!artifacts.isEmpty()) {
|
||||
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.jarRepository.settings.RemoteRepositoriesConfigurable">
|
||||
<grid id="27dc6" binding="myMainPanel" default-binding="true" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="557" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="c4b8f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="true"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<clientProperties>
|
||||
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithoutIndent"/>
|
||||
</clientProperties>
|
||||
<border type="none" title="Maven Jar Repositories"/>
|
||||
<children>
|
||||
<scrollpane id="73c10" class="com.intellij.ui.components.JBScrollPane">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="be502" class="com.intellij.ui.components.JBList" binding="myJarRepositoryList">
|
||||
<constraints/>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<grid id="2b266" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<vspacer id="66c31">
|
||||
<constraints>
|
||||
<grid row="3" 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>
|
||||
<component id="f4162" class="javax.swing.JButton" binding="myAddRepoButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<focusable value="false"/>
|
||||
<text value="A&dd"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="924c4" class="javax.swing.JButton" binding="myEditRepoButton">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Edit"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d12de" class="javax.swing.JButton" binding="myRemoveRepoButton">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Remove"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9dabf" class="javax.swing.JButton" binding="myResetToDefaultReposButton">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Reset Defaults"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="408c" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<clientProperties>
|
||||
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithoutIndent"/>
|
||||
</clientProperties>
|
||||
<border type="none" title="Artifactory or Nexus Service URLs:"/>
|
||||
<children>
|
||||
<scrollpane id="3bdae" class="com.intellij.ui.components.JBScrollPane">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="4" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="406" height="128"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="652af" class="com.intellij.ui.components.JBList" binding="myServiceList">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<layoutOrientation value="0"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<grid id="b0065" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<vspacer id="5094e">
|
||||
<constraints>
|
||||
<grid row="4" 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>
|
||||
<component id="15737" class="javax.swing.JButton" binding="myAddServiceButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<focusable value="false"/>
|
||||
<text value="&Add"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="51b" class="javax.swing.JButton" binding="myRemoveServiceButton">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Remove"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d96a1" class="javax.swing.JButton" binding="myTestServiceButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Test"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ca06e" class="javax.swing.JButton" binding="myEditServiceButton">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Edit"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="24fc3" class="javax.swing.JButton" binding="myResetToDefaultServicesButton">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Reset Defaults"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
+253
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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 com.intellij.jarRepository.settings;
|
||||
|
||||
import com.intellij.jarRepository.JarRepositoryManager;
|
||||
import com.intellij.jarRepository.RemoteRepositoriesConfiguration;
|
||||
import com.intellij.jarRepository.RemoteRepositoryDescription;
|
||||
import com.intellij.jarRepository.services.MavenRepositoryServicesManager;
|
||||
import com.intellij.openapi.options.BaseConfigurable;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.InputValidator;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.CollectionListModel;
|
||||
import com.intellij.ui.ListUtil;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
public class RemoteRepositoriesConfigurable extends BaseConfigurable implements SearchableConfigurable, Configurable.NoScroll {
|
||||
|
||||
private JPanel myMainPanel;
|
||||
|
||||
private JBList<String> myServiceList;
|
||||
private JButton myAddServiceButton;
|
||||
private JButton myEditServiceButton;
|
||||
private JButton myRemoveServiceButton;
|
||||
private JButton myTestServiceButton;
|
||||
|
||||
private JBList<String> myJarRepositoryList;
|
||||
private JButton myAddRepoButton;
|
||||
private JButton myEditRepoButton;
|
||||
private JButton myRemoveRepoButton;
|
||||
private JButton myResetToDefaultReposButton;
|
||||
private JButton myResetToDefaultServicesButton;
|
||||
|
||||
private final Project myProject;
|
||||
private final CollectionListModel<String> myServicesModel = new CollectionListModel<>();
|
||||
private final CollectionListModel<String> myReposModel = new CollectionListModel<>();
|
||||
|
||||
public RemoteRepositoriesConfigurable(Project project) {
|
||||
myProject = project;
|
||||
configControls();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return isServiceListModified() || isRepoListModified();
|
||||
}
|
||||
|
||||
private boolean isServiceListModified() {
|
||||
return !myServicesModel.getItems().equals(MavenRepositoryServicesManager.getInstance(myProject).getUrls());
|
||||
}
|
||||
|
||||
private boolean isRepoListModified() {
|
||||
final List<String> urls = new SmartList<>();
|
||||
for (RemoteRepositoryDescription repository : RemoteRepositoriesConfiguration.getInstance(myProject).getRepositories()) {
|
||||
urls.add(repository.getUrl());
|
||||
}
|
||||
return !myReposModel.getItems().equals(urls);
|
||||
}
|
||||
|
||||
private void configControls() {
|
||||
setupListControls(
|
||||
myServiceList, myServicesModel, myAddServiceButton, myEditServiceButton, myRemoveServiceButton,
|
||||
"Artifactory or Nexus Service URL", "Service URL", "No services"
|
||||
);
|
||||
setupListControls(
|
||||
myJarRepositoryList, myReposModel, myAddRepoButton, myEditRepoButton, myRemoveRepoButton,
|
||||
"Maven Repository URL", "maven Repository URL", "No remote repositories"
|
||||
);
|
||||
|
||||
ListUtil.disableWhenNoSelection(myTestServiceButton, myServiceList);
|
||||
myTestServiceButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final String value = myServiceList.getSelectedValue();
|
||||
if (!StringUtil.isEmpty(value)) {
|
||||
myTestServiceButton.setEnabled(false);
|
||||
JarRepositoryManager.searchRepositories(myProject, Collections.singletonList(value), infos -> {
|
||||
myTestServiceButton.setEnabled(true);
|
||||
if (infos.isEmpty()) {
|
||||
Messages.showMessageDialog("No repositories found", "Service Connection Failed", Messages.getWarningIcon());
|
||||
}
|
||||
else {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(infos.size()).append(infos.size() == 1 ? "repository" : " repositories").append(" found");
|
||||
//for (MavenRepositoryInfo info : infos) {
|
||||
// sb.append("\n ");
|
||||
// sb.append(info.getId()).append(" (").append(info.getName()).append(")").append(": ").append(info.getUrl());
|
||||
//}
|
||||
Messages.showMessageDialog(sb.toString(), "Service Connection Successful", Messages.getInformationIcon());
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
myResetToDefaultReposButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
resetReposModel(RemoteRepositoryDescription.DEFAULT_REPOSITORIES);
|
||||
}
|
||||
});
|
||||
myResetToDefaultServicesButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
resetServicesModel(MavenRepositoryServicesManager.DEFAULT_SERVICES);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void setupListControls(final JBList<String> list,
|
||||
final CollectionListModel<String> model,
|
||||
final JButton addButton,
|
||||
final JButton editButton,
|
||||
final JButton removeButton,
|
||||
final String modificationDialogTitle,
|
||||
final String modificationDialogHint,
|
||||
final String emptyListHint) {
|
||||
list.setModel(model);
|
||||
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
addButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final String value = list.getSelectedValue();
|
||||
final String text = Messages.showInputDialog(
|
||||
modificationDialogTitle, "Add" + " " + modificationDialogHint, Messages.getQuestionIcon(), value == null ? "https://" : value, new URLInputVaslidator()
|
||||
);
|
||||
if (StringUtil.isNotEmpty(text)) {
|
||||
model.add(text);
|
||||
list.setSelectedValue(text, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
editButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final int index = list.getSelectedIndex();
|
||||
final String text = Messages.showInputDialog(
|
||||
modificationDialogTitle, "Edit" + " " + modificationDialogHint, Messages.getQuestionIcon(), model.getElementAt(index), new URLInputVaslidator()
|
||||
);
|
||||
if (StringUtil.isNotEmpty(text)) {
|
||||
model.setElementAt(text, index);
|
||||
}
|
||||
}
|
||||
});
|
||||
ListUtil.addRemoveListener(removeButton, list);
|
||||
ListUtil.disableWhenNoSelection(editButton, list);
|
||||
list.getEmptyText().setText(emptyListHint);
|
||||
}
|
||||
|
||||
|
||||
public String getDisplayName() {
|
||||
return "Remote Jar Repositories";
|
||||
}
|
||||
|
||||
public String getHelpTopic() {
|
||||
return ""; // todo
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getId() {
|
||||
return getClass().getName();
|
||||
}
|
||||
|
||||
public JComponent createComponent() {
|
||||
return myMainPanel;
|
||||
}
|
||||
|
||||
public void apply() throws ConfigurationException {
|
||||
MavenRepositoryServicesManager.getInstance(myProject).setUrls(myServicesModel.getItems());
|
||||
|
||||
final Map<String, RemoteRepositoryDescription> defaultRepos = new HashMap<>();
|
||||
for (RemoteRepositoryDescription repository : RemoteRepositoryDescription.DEFAULT_REPOSITORIES) {
|
||||
defaultRepos.put(repository.getUrl(), repository);
|
||||
}
|
||||
final List<RemoteRepositoryDescription> descriptions = new SmartList<>();
|
||||
for (String url : myReposModel.getItems()) {
|
||||
final RemoteRepositoryDescription def = defaultRepos.get(url);
|
||||
if (def != null) {
|
||||
descriptions.add(def);
|
||||
}
|
||||
else {
|
||||
final UUID uuid = UUID.randomUUID();
|
||||
descriptions.add(new RemoteRepositoryDescription(uuid.toString(), uuid.toString(), url));
|
||||
}
|
||||
}
|
||||
RemoteRepositoriesConfiguration.getInstance(myProject).setRepositories(descriptions);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
resetServicesModel(MavenRepositoryServicesManager.getInstance(myProject).getUrls());
|
||||
resetReposModel(RemoteRepositoriesConfiguration.getInstance(myProject).getRepositories());
|
||||
}
|
||||
|
||||
private void resetServicesModel(final List<String> urls) {
|
||||
myServicesModel.removeAll();
|
||||
myServicesModel.add(urls);
|
||||
}
|
||||
|
||||
private void resetReposModel(final List<RemoteRepositoryDescription> repositories) {
|
||||
myReposModel.removeAll();
|
||||
final List<String> repos = new SmartList<>();
|
||||
for (RemoteRepositoryDescription description : repositories) {
|
||||
repos.add(description.getUrl());
|
||||
}
|
||||
myReposModel.add(repos);
|
||||
}
|
||||
|
||||
public void disposeUIResources() {
|
||||
}
|
||||
|
||||
private static final class URLInputVaslidator implements InputValidator {
|
||||
@Override
|
||||
public boolean checkInput(String inputString) {
|
||||
try {
|
||||
return StringUtil.isNotEmpty(new URL(inputString).getHost());
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canClose(String inputString) {
|
||||
return checkInput(inputString);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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 com.intellij.jarRepository;
|
||||
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.xmlb.annotations.AbstractCollection;
|
||||
import com.intellij.util.xmlb.annotations.Property;
|
||||
import com.intellij.util.xmlb.annotations.Tag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: 24-Apr-17
|
||||
*/
|
||||
@State(name = "RemoteRepositoriesConfiguration", storages = @Storage("jarRepositories.xml"))
|
||||
public class RemoteRepositoriesConfiguration implements PersistentStateComponent<RemoteRepositoriesConfiguration.State> {
|
||||
private final List<RemoteRepositoryDescription> myRepositories = new SmartList<>();
|
||||
|
||||
public RemoteRepositoriesConfiguration() {
|
||||
this(RemoteRepositoryDescription.DEFAULT_REPOSITORIES);
|
||||
}
|
||||
|
||||
public RemoteRepositoriesConfiguration(Collection<RemoteRepositoryDescription> repos) {
|
||||
myRepositories.addAll(repos);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static RemoteRepositoriesConfiguration getInstance(Project project) {
|
||||
return ServiceManager.getService(project, RemoteRepositoriesConfiguration.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<RemoteRepositoryDescription> getRepositories() {
|
||||
return Collections.unmodifiableList(myRepositories);
|
||||
}
|
||||
|
||||
public void resetToDefault() {
|
||||
setRepositories(Collections.emptyList());
|
||||
}
|
||||
|
||||
public void setRepositories(@NotNull List<RemoteRepositoryDescription> repos) {
|
||||
myRepositories.clear();
|
||||
myRepositories.addAll(repos.isEmpty()? RemoteRepositoryDescription.DEFAULT_REPOSITORIES : repos);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public RemoteRepositoriesConfiguration.State getState() {
|
||||
return new State(myRepositories);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(RemoteRepositoriesConfiguration.State state) {
|
||||
final List<RemoteRepositoryDescription> loaded = new SmartList<>();
|
||||
if (state.data != null) {
|
||||
for (State.Repo repo : state.data) {
|
||||
loaded.add(new RemoteRepositoryDescription(repo.id, repo.name, repo.url));
|
||||
}
|
||||
}
|
||||
setRepositories(loaded);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
RemoteRepositoriesConfiguration that = (RemoteRepositoriesConfiguration)o;
|
||||
|
||||
if (!myRepositories.equals(that.myRepositories)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myRepositories.hashCode();
|
||||
}
|
||||
|
||||
static class State {
|
||||
@Tag("remote-repository")
|
||||
static class Repo{
|
||||
public String id;
|
||||
public String name;
|
||||
public String url;
|
||||
|
||||
public Repo() {
|
||||
}
|
||||
|
||||
public Repo(String id, String name, String url) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Repo repo = (Repo)o;
|
||||
|
||||
if (id != null ? !id.equals(repo.id) : repo.id != null) return false;
|
||||
if (name != null ? !name.equals(repo.name) : repo.name != null) return false;
|
||||
if (url != null ? !url.equals(repo.url) : repo.url != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = id != null ? id.hashCode() : 0;
|
||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||
result = 31 * result + (url != null ? url.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Property(surroundWithTag = false)
|
||||
@AbstractCollection(surroundWithTag = false, elementTypes = Repo.class)
|
||||
public final List<Repo> data = new SmartList<>();
|
||||
|
||||
public State() {
|
||||
this(RemoteRepositoryDescription.DEFAULT_REPOSITORIES);
|
||||
}
|
||||
|
||||
public State(List<RemoteRepositoryDescription> repos) {
|
||||
for (RemoteRepositoryDescription repository : repos) {
|
||||
data.add(new Repo(repository.getId(), repository.getName(), repository.getUrl()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
State state = (State)o;
|
||||
|
||||
if (!data.equals(state.data)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return data.hashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-7
@@ -24,6 +24,7 @@ import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.xmlb.annotations.AbstractCollection;
|
||||
@@ -32,6 +33,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -45,15 +48,21 @@ public class MavenRepositoryServicesManager implements PersistentStateComponent<
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.repository.services.MavenRepositoryServicesManager");
|
||||
private final List<String> myUrls = new ArrayList<>();
|
||||
|
||||
public static final List<String> DEFAULT_SERVICES = Collections.unmodifiableList(Arrays.asList(
|
||||
"https://oss.sonatype.org/service/local/",
|
||||
"http://repo.jfrog.org/artifactory/api/",
|
||||
"https://repository.jboss.org/nexus/service/local/"
|
||||
));
|
||||
|
||||
public MavenRepositoryServicesManager() {
|
||||
myUrls.add("https://oss.sonatype.org/service/local/");
|
||||
myUrls.add("http://repo.jfrog.org/artifactory/api/");
|
||||
myUrls.add("https://repository.jboss.org/nexus/service/local/");
|
||||
for (String s : DEFAULT_SERVICES) {
|
||||
myUrls.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static MavenRepositoryServicesManager getInstance() {
|
||||
return ServiceManager.getService(MavenRepositoryServicesManager.class);
|
||||
public static MavenRepositoryServicesManager getInstance(Project project) {
|
||||
return ServiceManager.getService(project, MavenRepositoryServicesManager.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -61,8 +70,8 @@ public class MavenRepositoryServicesManager implements PersistentStateComponent<
|
||||
return new MavenRepositoryService[]{new NexusRepositoryService(), new ArtifactoryRepositoryService()};
|
||||
}
|
||||
|
||||
public static String[] getServiceUrls() {
|
||||
return ArrayUtil.toStringArray(getInstance().getUrls());
|
||||
public static String[] getServiceUrls(final Project project) {
|
||||
return ArrayUtil.toStringArray(getInstance(project).getUrls());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
-7
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.jetbrains.idea.maven.utils.library;
|
||||
|
||||
import com.intellij.jarRepository.RemoteRepositoryDescription;
|
||||
import com.intellij.jarRepository.RepositoryLibraryDefinition;
|
||||
import com.intellij.openapi.roots.DependencyScope;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
@@ -26,7 +25,6 @@ import org.jetbrains.jps.model.library.JpsMavenRepositoryLibraryDescriptor;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class RepositoryLibraryDescription {
|
||||
@@ -107,11 +105,6 @@ public class RepositoryLibraryDescription {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<RemoteRepositoryDescription> getRemoteRepositories() {
|
||||
return RemoteRepositoryDescription.DEFAULT_REPOSITORIES;
|
||||
}
|
||||
|
||||
// One library could have more then one description - for ex. in different plugins
|
||||
// In this case heaviest description will be used
|
||||
public int getWeight() {
|
||||
|
||||
+11
-1
@@ -18,10 +18,12 @@ package org.jetbrains.jps.incremental.dependencies;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.SmartHashSet;
|
||||
import gnu.trove.THashMap;
|
||||
import gnu.trove.THashSet;
|
||||
import org.eclipse.aether.repository.RemoteRepository;
|
||||
import org.eclipse.aether.transfer.TransferCancelledException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.maven.aether.ArtifactRepositoryManager;
|
||||
@@ -35,6 +37,8 @@ import org.jetbrains.jps.incremental.messages.BuildMessage;
|
||||
import org.jetbrains.jps.incremental.messages.CompilerMessage;
|
||||
import org.jetbrains.jps.incremental.messages.ProgressMessage;
|
||||
import org.jetbrains.jps.model.JpsSimpleElement;
|
||||
import org.jetbrains.jps.model.jarRepository.JpsRemoteRepositoryDescription;
|
||||
import org.jetbrains.jps.model.jarRepository.JpsRemoteRepositoryService;
|
||||
import org.jetbrains.jps.model.library.*;
|
||||
import org.jetbrains.jps.model.module.JpsDependencyElement;
|
||||
import org.jetbrains.jps.model.module.JpsLibraryDependency;
|
||||
@@ -244,7 +248,13 @@ public class DependencyResolvingBuilder extends ModuleLevelBuilder{
|
||||
private static ArtifactRepositoryManager getRepositoryManager(final CompileContext context) {
|
||||
ArtifactRepositoryManager manager = MANAGER_KEY.get(context);
|
||||
if (manager == null) {
|
||||
manager = new ArtifactRepositoryManager(getLocalRepoDir(context), new ProgressConsumer() {
|
||||
|
||||
final List<RemoteRepository> repositories = new SmartList<>();
|
||||
for (JpsRemoteRepositoryDescription repo : JpsRemoteRepositoryService.getInstance().getOrCreateRemoteRepositoriesConfiguration(context.getProjectDescriptor().getProject())
|
||||
.getRepositories()) {
|
||||
repositories.add(ArtifactRepositoryManager.createRemoteRepository(repo.getId(), repo.getUrl()));
|
||||
}
|
||||
manager = new ArtifactRepositoryManager(getLocalRepoDir(context), repositories, new ProgressConsumer() {
|
||||
public void consume(String message) {
|
||||
context.processMessage(new ProgressMessage(message));
|
||||
}
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.jps.model.jarRepository;
|
||||
|
||||
import org.jetbrains.jps.model.JpsElement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: 25-Apr-17
|
||||
*/
|
||||
public interface JpsRemoteRepositoriesConfiguration extends JpsElement {
|
||||
List<JpsRemoteRepositoryDescription> getRepositories();
|
||||
void setRepositories(List<JpsRemoteRepositoryDescription> repositories);
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.jps.model.jarRepository;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: 25-Apr-17
|
||||
*/
|
||||
public class JpsRemoteRepositoryDescription {
|
||||
private final String myId;
|
||||
private final String myName;
|
||||
private final String myUrl;
|
||||
|
||||
public JpsRemoteRepositoryDescription(String id, String name, String url) {
|
||||
myId = id;
|
||||
myName = name;
|
||||
myUrl = url;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return myId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return myUrl;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.jps.model.jarRepository;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.JpsProject;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: 25-Apr-17
|
||||
*/
|
||||
public abstract class JpsRemoteRepositoryService {
|
||||
public static JpsRemoteRepositoryService getInstance() {
|
||||
return JpsServiceManager.getInstance().getService(JpsRemoteRepositoryService.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract JpsRemoteRepositoriesConfiguration getRemoteRepositoriesConfiguration(@NotNull JpsProject project);
|
||||
|
||||
@NotNull
|
||||
public abstract JpsRemoteRepositoriesConfiguration getOrCreateRemoteRepositoriesConfiguration(@NotNull JpsProject project);
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
#
|
||||
# Copyright 2000-2017 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.
|
||||
#
|
||||
org.jetbrains.jps.model.jarRepository.impl.JpsRemoteRepositoryServiceImpl
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.jps.model.jarRepository.impl;
|
||||
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.JpsElementChildRole;
|
||||
import org.jetbrains.jps.model.ex.JpsElementBase;
|
||||
import org.jetbrains.jps.model.ex.JpsElementChildRoleBase;
|
||||
import org.jetbrains.jps.model.jarRepository.JpsRemoteRepositoriesConfiguration;
|
||||
import org.jetbrains.jps.model.jarRepository.JpsRemoteRepositoryDescription;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: 25-Apr-17
|
||||
*/
|
||||
public class JpsRemoteRepositoriesConfigurationImpl extends JpsElementBase<JpsRemoteRepositoriesConfigurationImpl> implements JpsRemoteRepositoriesConfiguration{
|
||||
public static final JpsElementChildRole<JpsRemoteRepositoriesConfiguration> ROLE = JpsElementChildRoleBase.create("remote repositories configuration");
|
||||
|
||||
private final List<JpsRemoteRepositoryDescription> myRepositories = new SmartList<>();
|
||||
|
||||
public JpsRemoteRepositoriesConfigurationImpl() {
|
||||
this(Arrays.asList( // defaults
|
||||
new JpsRemoteRepositoryDescription("central", "Maven Central repository", "https://repo1.maven.org/maven2"),
|
||||
new JpsRemoteRepositoryDescription("jboss.community", "JBoss Community repository", "https://repository.jboss.org/nexus/content/repositories/public/")
|
||||
));
|
||||
}
|
||||
|
||||
public JpsRemoteRepositoriesConfigurationImpl(List<JpsRemoteRepositoryDescription> repositories) {
|
||||
myRepositories.addAll(repositories);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsRemoteRepositoriesConfigurationImpl createCopy() {
|
||||
return new JpsRemoteRepositoriesConfigurationImpl(myRepositories);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyChanges(@NotNull JpsRemoteRepositoriesConfigurationImpl modified) {
|
||||
setRepositories(modified.getRepositories());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JpsRemoteRepositoryDescription> getRepositories() {
|
||||
return Collections.unmodifiableList(myRepositories);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRepositories(List<JpsRemoteRepositoryDescription> repositories) {
|
||||
myRepositories.clear();
|
||||
myRepositories.addAll(repositories);
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.jps.model.jarRepository.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.JpsProject;
|
||||
import org.jetbrains.jps.model.jarRepository.JpsRemoteRepositoriesConfiguration;
|
||||
import org.jetbrains.jps.model.jarRepository.JpsRemoteRepositoryService;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: 25-Apr-17
|
||||
*/
|
||||
public class JpsRemoteRepositoryServiceImpl extends JpsRemoteRepositoryService {
|
||||
@Nullable
|
||||
@Override
|
||||
public JpsRemoteRepositoriesConfiguration getRemoteRepositoriesConfiguration(@NotNull JpsProject project) {
|
||||
return project.getContainer().getChild(JpsRemoteRepositoriesConfigurationImpl.ROLE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JpsRemoteRepositoriesConfiguration getOrCreateRemoteRepositoriesConfiguration(@NotNull JpsProject project) {
|
||||
JpsRemoteRepositoriesConfiguration config = getRemoteRepositoriesConfiguration(project);
|
||||
if (config == null) {
|
||||
config = project.getContainer().setChild(JpsRemoteRepositoriesConfigurationImpl.ROLE, new JpsRemoteRepositoriesConfigurationImpl());
|
||||
}
|
||||
return config;
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,2 +1,3 @@
|
||||
org.jetbrains.jps.model.serialization.java.JpsJavaModelSerializerExtension
|
||||
org.jetbrains.jps.model.serialization.JpsEncodingModelSerializerExtension
|
||||
org.jetbrains.jps.model.serialization.JpsEncodingModelSerializerExtension
|
||||
org.jetbrains.jps.model.serialization.jarRepository.JpsRemoteRepositoriesModelSerializerExtension
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.jps.model.serialization.jarRepository;
|
||||
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.JpsProject;
|
||||
import org.jetbrains.jps.model.jarRepository.JpsRemoteRepositoriesConfiguration;
|
||||
import org.jetbrains.jps.model.jarRepository.JpsRemoteRepositoryDescription;
|
||||
import org.jetbrains.jps.model.jarRepository.JpsRemoteRepositoryService;
|
||||
import org.jetbrains.jps.model.serialization.JpsProjectExtensionSerializer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: 25-Apr-17
|
||||
*/
|
||||
public class JpsRemoteRepositoriesConfigurationSerializer extends JpsProjectExtensionSerializer {
|
||||
private static final String ELEMENT_TAG = "remote-repository";
|
||||
private static final String OPTION_TAG = "option";
|
||||
private static final String ID_PROPERTY = "id";
|
||||
private static final String NAME_PROPERTY = "name";
|
||||
private static final String URL_PROPERTY = "url";
|
||||
|
||||
public JpsRemoteRepositoriesConfigurationSerializer() {
|
||||
super("jarRepositories.xml", "RemoteRepositoriesConfiguration");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadExtension(@NotNull JpsProject project, @NotNull Element componentTag) {
|
||||
final List<JpsRemoteRepositoryDescription> result = new SmartList<>();
|
||||
final List<Element> children = componentTag.getChildren(ELEMENT_TAG);
|
||||
for (Element repoElement : children) {
|
||||
String id = null;
|
||||
String name = null;
|
||||
String url = null;
|
||||
for (Element element : repoElement.getChildren(OPTION_TAG)) {
|
||||
final String option = element.getAttributeValue("name");
|
||||
final String optionValue = element.getAttributeValue("value");
|
||||
if (ID_PROPERTY.equals(option)) {
|
||||
id = optionValue;
|
||||
}
|
||||
else if (NAME_PROPERTY.equals(option)) {
|
||||
name = optionValue == null? "" : optionValue;
|
||||
}
|
||||
else if (URL_PROPERTY.equals(option)) {
|
||||
url = optionValue;
|
||||
}
|
||||
}
|
||||
if (id != null && url != null) {
|
||||
result.add(new JpsRemoteRepositoryDescription(id, name, url));
|
||||
}
|
||||
}
|
||||
final JpsRemoteRepositoriesConfiguration config = JpsRemoteRepositoryService.getInstance().getOrCreateRemoteRepositoriesConfiguration(project);
|
||||
if (!result.isEmpty()) {
|
||||
config.setRepositories(result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveExtension(@NotNull JpsProject project, @NotNull Element componentTag) {
|
||||
// not supported
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.jps.model.serialization.jarRepository;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension;
|
||||
import org.jetbrains.jps.model.serialization.JpsProjectExtensionSerializer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: 26-Apr-17
|
||||
*/
|
||||
public class JpsRemoteRepositoriesModelSerializerExtension extends JpsModelSerializerExtension{
|
||||
private static final JpsRemoteRepositoriesConfigurationSerializer SERIALIZER_IMPL = new JpsRemoteRepositoriesConfigurationSerializer();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends JpsProjectExtensionSerializer> getProjectExtensionSerializers() {
|
||||
return Collections.singletonList(SERIALIZER_IMPL);
|
||||
}
|
||||
}
|
||||
+2
-80
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.idea.maven.indices.MavenRepositoriesConfigurable">
|
||||
<grid id="27dc6" binding="myMainPanel" default-binding="true" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="myMainPanel" default-binding="true" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
<xy x="20" y="20" width="519" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@@ -58,84 +58,6 @@
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="408c" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<clientProperties>
|
||||
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithoutIndent"/>
|
||||
</clientProperties>
|
||||
<border type="none" title="Artifactory or Nexus Service URLs:"/>
|
||||
<children>
|
||||
<scrollpane id="3bdae" class="com.intellij.ui.components.JBScrollPane">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="4" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="406" height="128"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="652af" class="com.intellij.ui.components.JBList" binding="myServiceList">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<layoutOrientation value="0"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<grid id="b0065" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<vspacer id="5094e">
|
||||
<constraints>
|
||||
<grid row="4" 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>
|
||||
<component id="15737" class="javax.swing.JButton" binding="myAddButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<focusable value="false"/>
|
||||
<text value="&Add"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="51b" class="javax.swing.JButton" binding="myRemoveButton">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Remove"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d96a1" class="javax.swing.JButton" binding="myTestButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Test"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ca06e" class="javax.swing.JButton" binding="myEditButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Edit"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
+1
-101
@@ -16,21 +16,13 @@
|
||||
package org.jetbrains.idea.maven.indices;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.jarRepository.JarRepositoryManager;
|
||||
import com.intellij.jarRepository.services.MavenRepositoryServicesManager;
|
||||
import com.intellij.openapi.options.BaseConfigurable;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.InputValidator;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.CollectionListModel;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.ListUtil;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
import com.intellij.util.text.DateFormatUtil;
|
||||
import com.intellij.util.ui.AnimatedIcon;
|
||||
@@ -48,10 +40,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class MavenRepositoriesConfigurable extends BaseConfigurable implements SearchableConfigurable, Configurable.NoScroll {
|
||||
@@ -60,68 +49,22 @@ public class MavenRepositoriesConfigurable extends BaseConfigurable implements S
|
||||
private JPanel myMainPanel;
|
||||
private JBTable myIndicesTable;
|
||||
private JButton myUpdateButton;
|
||||
private JButton myRemoveButton;
|
||||
private JButton myAddButton;
|
||||
private JBList myServiceList;
|
||||
private JButton myTestButton;
|
||||
private JButton myEditButton;
|
||||
|
||||
private AnimatedIcon myUpdatingIcon;
|
||||
private Timer myRepaintTimer;
|
||||
private ActionListener myTimerListener;
|
||||
private final Project myProject;
|
||||
private final CollectionListModel<String> myModel = new CollectionListModel<>();
|
||||
|
||||
public MavenRepositoriesConfigurable(Project project) {
|
||||
myProject = project;
|
||||
myManager = MavenProjectIndicesManager.getInstance(project);
|
||||
configControls();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return !myModel.getItems().equals(MavenRepositoryServicesManager.getInstance().getUrls());
|
||||
return false;
|
||||
}
|
||||
|
||||
private void configControls() {
|
||||
myServiceList.setModel(myModel);
|
||||
myServiceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
myAddButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final String value = (String)myServiceList.getSelectedValue();
|
||||
final String text = Messages.showInputDialog("Artifactory or Nexus Service URL", "Add Service URL", Messages.getQuestionIcon(),
|
||||
value == null ? "http://" : value, new URLInputVaslidator());
|
||||
if (StringUtil.isNotEmpty(text)) {
|
||||
myModel.add(text);
|
||||
myServiceList.setSelectedValue(text, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
myEditButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final int index = myServiceList.getSelectedIndex();
|
||||
final String text = Messages.showInputDialog("Artifactory or Nexus Service URL", "Edit Service URL", Messages.getQuestionIcon(),
|
||||
myModel.getElementAt(index), new URLInputVaslidator());
|
||||
if (StringUtil.isNotEmpty(text)) {
|
||||
myModel.setElementAt(text, index);
|
||||
}
|
||||
}
|
||||
});
|
||||
ListUtil.addRemoveListener(myRemoveButton, myServiceList);
|
||||
ListUtil.disableWhenNoSelection(myTestButton, myServiceList);
|
||||
ListUtil.disableWhenNoSelection(myEditButton, myServiceList);
|
||||
myTestButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final String value = (String)myServiceList.getSelectedValue();
|
||||
if (value != null) {
|
||||
testServiceConnection(value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
myUpdateButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
doUpdateIndex();
|
||||
@@ -149,32 +92,11 @@ public class MavenRepositoriesConfigurable extends BaseConfigurable implements S
|
||||
myIndicesTable.setDefaultRenderer(MavenIndicesManager.IndexUpdatingState.class,
|
||||
new MyIconCellRenderer());
|
||||
|
||||
myServiceList.getEmptyText().setText("No services");
|
||||
myIndicesTable.getEmptyText().setText("No remote repositories");
|
||||
|
||||
updateButtonsState();
|
||||
}
|
||||
|
||||
private void testServiceConnection(String url) {
|
||||
myTestButton.setEnabled(false);
|
||||
JarRepositoryManager.searchRepositories(myProject, Collections.singletonList(url), infos -> {
|
||||
myTestButton.setEnabled(true);
|
||||
if (infos.isEmpty()) {
|
||||
Messages.showMessageDialog("No repositories found", "Service Connection Failed", Messages.getWarningIcon());
|
||||
}
|
||||
else {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(infos.size()).append(infos.size() == 1 ? "repository" : " repositories").append(" found");
|
||||
//for (MavenRepositoryInfo info : infos) {
|
||||
// sb.append("\n ");
|
||||
// sb.append(info.getId()).append(" (").append(info.getName()).append(")").append(": ").append(info.getUrl());
|
||||
//}
|
||||
Messages.showMessageDialog(sb.toString(), "Service Connection Successful", Messages.getInformationIcon());
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private void updateButtonsState() {
|
||||
boolean hasSelection = !myIndicesTable.getSelectionModel().isSelectionEmpty();
|
||||
myUpdateButton.setEnabled(hasSelection);
|
||||
@@ -226,13 +148,9 @@ public class MavenRepositoriesConfigurable extends BaseConfigurable implements S
|
||||
}
|
||||
|
||||
public void apply() throws ConfigurationException {
|
||||
MavenRepositoryServicesManager.getInstance().setUrls(myModel.getItems());
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
myModel.removeAll();
|
||||
myModel.add(MavenRepositoryServicesManager.getInstance().getUrls());
|
||||
|
||||
myIndicesTable.setModel(new MyTableModel(myManager.getIndices()));
|
||||
myIndicesTable.getColumnModel().getColumn(0).setPreferredWidth(400);
|
||||
myIndicesTable.getColumnModel().getColumn(1).setPreferredWidth(50);
|
||||
@@ -368,22 +286,4 @@ public class MavenRepositoriesConfigurable extends BaseConfigurable implements S
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class URLInputVaslidator implements InputValidator {
|
||||
@Override
|
||||
public boolean checkInput(String inputString) {
|
||||
try {
|
||||
final URL url = new URL(inputString);
|
||||
return StringUtil.isNotEmpty(url.getHost());
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canClose(String inputString) {
|
||||
return checkInput(inputString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1945,8 +1945,10 @@
|
||||
|
||||
<library.type implementation="com.intellij.jarRepository.RepositoryLibraryType"/>
|
||||
<library.dependencyScopeSuggester implementation="com.intellij.jarRepository.RepositoryLibraryDependencyScopeSuggester"/>
|
||||
<applicationService serviceImplementation="com.intellij.jarRepository.services.MavenRepositoryServicesManager"/>
|
||||
<projectService serviceImplementation="com.intellij.jarRepository.services.MavenRepositoryServicesManager"/>
|
||||
<projectService serviceImplementation="com.intellij.jarRepository.RemoteRepositoriesConfiguration"/>
|
||||
<postStartupActivity implementation="com.intellij.jarRepository.RepositoryLibrarySynchronizer"/>
|
||||
<projectConfigurable groupId="build" groupWeight="120" instance="com.intellij.jarRepository.settings.RemoteRepositoriesConfigurable" order="last"/>
|
||||
|
||||
<longLineInspectionPolicy implementation="com.intellij.codeInspection.JavaLongLineInspectionPolicy"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user