Spinning icon & NPE fixes

This commit is contained in:
Gregory.Shrago
2012-03-28 21:08:25 +04:00
parent 197b9ae652
commit 268416fd8d
3 changed files with 24 additions and 4 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.idea.maven.services.artifactory;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.maven.model.MavenArtifactInfo;
@@ -27,6 +28,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
@@ -53,6 +55,9 @@ public class ArtifactoryRepositoryService extends MavenRepositoryService {
}
return result;
}
catch (JsonSyntaxException e) {
return Collections.emptyList();
}
catch (Exception e) {
throw new IOException(e);
}
@@ -74,7 +79,7 @@ public class ArtifactoryRepositoryService extends MavenRepositoryService {
final String name = StringUtil.join(Arrays.asList(template.getGroupId(), template.getArtifactId(), template.getVersion()), ":");
final InputStream stream = new Endpoint.Search.Artifact(url).getArtifactSearchResultJson(name, null).getInputStream();
final ArtifactoryModel.GavcResults results = gson.fromJson(new InputStreamReader(stream), ArtifactoryModel.GavcResults.class);
final ArtifactoryModel.GavcResults results = stream == null? null : gson.fromJson(new InputStreamReader(stream), ArtifactoryModel.GavcResults.class);
if (results != null && results.results != null) {
for (ArtifactoryModel.GavcResult result : results.results) {
if (!result.uri.endsWith(packaging)) continue;
@@ -87,7 +92,7 @@ public class ArtifactoryRepositoryService extends MavenRepositoryService {
final String searchString = className.endsWith("*") || className.endsWith("?") ? className : className + ".class";
final InputStream stream = new Endpoint.Search.Archive(url).getArchiveSearchResultJson(searchString, null).getInputStream();
final ArtifactoryModel.ArchiveResults results = gson.fromJson(new InputStreamReader(stream), ArtifactoryModel.ArchiveResults.class);
final ArtifactoryModel.ArchiveResults results = stream == null? null : gson.fromJson(new InputStreamReader(stream), ArtifactoryModel.ArchiveResults.class);
if (results != null && results.results != null) {
for (ArtifactoryModel.ArchiveResult result : results.results) {
for (String uri : result.archiveUris) {
@@ -99,6 +104,9 @@ public class ArtifactoryRepositoryService extends MavenRepositoryService {
}
return artifacts;
}
catch (JsonSyntaxException e) {
return Collections.emptyList();
}
catch (Exception e) {
throw new IOException(e);
}
@@ -23,9 +23,11 @@ import org.jetbrains.idea.maven.model.MavenRepositoryInfo;
import org.jetbrains.idea.maven.services.MavenRepositoryService;
import javax.xml.bind.JAXBException;
import javax.xml.bind.UnmarshalException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
@@ -64,6 +66,9 @@ public class NexusRepositoryService extends MavenRepositoryService {
}
return result;
}
catch (UnmarshalException e) {
return Collections.emptyList();
}
catch (JAXBException e) {
throw new IOException(e);
}
@@ -74,12 +79,12 @@ public class NexusRepositoryService extends MavenRepositoryService {
public List<MavenArtifactInfo> findArtifacts(@NotNull String url, @NotNull MavenArtifactInfo template) throws IOException {
try {
final String packaging = StringUtil.notNullize(template.getPackaging());
final ArrayList<MavenArtifactInfo> result = new ArrayList<MavenArtifactInfo>();
final String name = StringUtil.join(Arrays.asList(template.getGroupId(), template.getArtifactId(), template.getVersion()), ":");
final SearchResults results = new Endpoint.DataIndex(url).getArtifactlistAsSearchResults(
name, template.getGroupId(), template.getArtifactId(), template.getVersion(), null, template.getClassNames());
boolean tooManyResults = results.isTooManyResults();
final SearchResults.Data data = results.getData();
final ArrayList<MavenArtifactInfo> result = new ArrayList<MavenArtifactInfo>();
if (data != null) {
for (ArtifactType each : data.getArtifact()) {
if (!Comparing.equal(each.packaging, packaging)) continue;
@@ -89,6 +94,9 @@ public class NexusRepositoryService extends MavenRepositoryService {
if (tooManyResults) result.add(null);
return result;
}
catch (UnmarshalException e) {
return Collections.emptyList();
}
catch (JAXBException e) {
throw new IOException(e);
}
@@ -76,6 +76,7 @@ public class RepositoryAttachDialog extends DialogWrapper {
private TextFieldWithBrowseButton myDirectoryField;
private String myFilterString;
private boolean myInUpdate;
public RepositoryAttachDialog(Project project, boolean managed, final @Nullable String initialFilter) {
super(project, true);
@@ -117,7 +118,7 @@ public class RepositoryAttachDialog extends DialogWrapper {
@Override
public void actionPerformed(ActionEvent e) {
final boolean popupVisible = myCombobox.isPopupVisible();
if (!popupVisible || myCoordinates.isEmpty()) {
if (!myInUpdate && (!popupVisible || myCoordinates.isEmpty())) {
performSearch();
}
else {
@@ -181,6 +182,8 @@ public class RepositoryAttachDialog extends DialogWrapper {
if (!force && Comparing.equal(myFilterString, prevFilter)) return;
int prevSize = myShownItems.size();
myShownItems.clear();
myInUpdate = true;
final boolean itemSelected = myCoordinates.containsKey(myFilterString) &&
Comparing.strEqual((String)myCombobox.getSelectedItem(), myFilterString, false);
final boolean filtered;
@@ -205,6 +208,7 @@ public class RepositoryAttachDialog extends DialogWrapper {
}
Collections.sort(myShownItems);
((CollectionComboBoxModel)myCombobox.getModel()).update();
myInUpdate = false;
field.setText(myFilterString);
field.setCaretPosition(caret);
updateInfoLabel();