From fd775d7ef30055c9cde14cfc2a9ff2cd479e3c76 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 12 Dec 2014 17:56:49 +0100 Subject: [PATCH] cleanup --- .../library/RepositoryAttachHandler.java | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryAttachHandler.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryAttachHandler.java index 81e63c3d51cb..4407feb4ccca 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryAttachHandler.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/RepositoryAttachHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -38,11 +38,14 @@ import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.util.PairProcessor; import com.intellij.util.Processor; import com.intellij.util.SmartList; +import gnu.trove.THashMap; +import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.maven.execution.SoutMavenConsole; @@ -159,7 +162,7 @@ public class RepositoryAttachHandler { } } // search for jar file first otherwise lib root won't be found! - manager.refreshAndFindFileByUrl(VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(toFile.getPath()))); + manager.refreshAndFindFileByUrl(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(toFile.getPath()))); final String url = VfsUtil.getUrlForLibraryRoot(toFile); final VirtualFile file = manager.refreshAndFindFileByUrl(url); if (file != null) { @@ -211,9 +214,12 @@ public class RepositoryAttachHandler { final List artifacts; artifacts = MavenRepositoryServicesManager.findArtifacts(template, serviceUrl); if (!artifacts.isEmpty()) { - if (!proceedFlag.get()) break; - final List repositories = MavenRepositoryServicesManager.getRepositories(serviceUrl); - final HashMap map = new HashMap(); + if (!proceedFlag.get()) { + break; + } + + List repositories = MavenRepositoryServicesManager.getRepositories(serviceUrl); + Map map = new THashMap(); for (MavenRepositoryInfo repository : repositories) { map.put(repository.getId(), repository); } @@ -310,7 +316,7 @@ public class RepositoryAttachHandler { Collection repositories, final Processor> resultProcessor, ProgressIndicator indicator) { - doResolveInner(project, Collections.singletonList(mavenId), extraTypes, repositories, resultProcessor, indicator); + doResolveInner(project, Collections.singletonList(mavenId), extraTypes, repositories, resultProcessor, indicator); } public static void doResolveInner(Project project, @@ -330,16 +336,17 @@ public class RepositoryAttachHandler { for (MavenId id : mavenIds) { artifacts.add(new MavenArtifactInfo(id, "jar", null)); } - final List firstResult = embedder.resolveTransitively(artifacts, remoteRepositories); + List firstResult = embedder.resolveTransitively(artifacts, remoteRepositories); for (MavenArtifact artifact : firstResult) { - if (!artifact.isResolved()) continue; - if (MavenConstants.SCOPE_TEST.equals(artifact.getScope())) continue; + if (!artifact.isResolved() || MavenConstants.SCOPE_TEST.equals(artifact.getScope())) { + continue; + } result.add(artifact); } // download docs & sources if (!extraTypes.isEmpty()) { - final HashSet allowedClassifiers = new HashSet(); - final Collection resolve = new LinkedHashSet(); + Set allowedClassifiers = new THashSet(); + Collection resolve = new LinkedHashSet(); for (MavenExtraArtifactType extraType : extraTypes) { allowedClassifiers.add(extraType.getDefaultClassifier()); for (MavenId id : mavenIds) { @@ -347,12 +354,10 @@ public class RepositoryAttachHandler { } // skip sources/javadoc for dependencies } - final List secondResult = - embedder.resolveTransitively(new ArrayList(resolve), remoteRepositories); - for (MavenArtifact artifact : secondResult) { - if (!artifact.isResolved()) continue; - if (MavenConstants.SCOPE_TEST.equals(artifact.getScope())) continue; - if (!allowedClassifiers.contains(artifact.getClassifier())) continue; + for (MavenArtifact artifact : embedder.resolveTransitively(new ArrayList(resolve), remoteRepositories)) { + if (!artifact.isResolved() || MavenConstants.SCOPE_TEST.equals(artifact.getScope()) || !allowedClassifiers.contains(artifact.getClassifier())) { + continue; + } result.add(artifact); } } @@ -382,7 +387,7 @@ public class RepositoryAttachHandler { return result; } - public static MavenId getMavenId(final String coord) { + public static MavenId getMavenId(@NotNull String coord) { final String[] parts = coord.split(":"); return new MavenId(parts.length > 0 ? parts[0] : null, parts.length > 1 ? parts[1] : null,