[maven] IDEA-91662 doesn't take into account mirror repositories as Indexed Maven...
[idea/community.git] / plugins / maven / maven2-server-impl / src / org / jetbrains / idea / maven / server / embedder / Maven2ModelConverter.java
index 278c48b17f1f29a6e11a2ed2164c3895875f69df..b6336240fcd99f276fd68f974662715de62f2dbe 100644 (file)
@@ -5,6 +5,8 @@ import com.intellij.util.ReflectionUtilRt;
 import org.apache.maven.archetype.catalog.Archetype;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
 import org.apache.maven.model.*;
 import org.apache.maven.shared.dependency.tree.DependencyNode;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
@@ -125,6 +127,27 @@ public final class Maven2ModelConverter {
     return result;
   }
 
+  public static List<MavenRemoteRepository> convertRemoteRepositories(List<? extends ArtifactRepository> repositories) {
+    if (repositories == null) return new ArrayList<MavenRemoteRepository>();
+
+    List<MavenRemoteRepository> result = new ArrayList<MavenRemoteRepository>(repositories.size());
+    for (ArtifactRepository each : repositories) {
+      result.add(new MavenRemoteRepository(each.getId(),
+                                           each.getId(),
+                                           each.getUrl(),
+                                           "default",
+                                           convertPolicy(each.getReleases()),
+                                           convertPolicy(each.getSnapshots())));
+    }
+    return result;
+  }
+
+  private static MavenRemoteRepository.Policy convertPolicy(ArtifactRepositoryPolicy policy) {
+    return policy != null
+           ? new MavenRemoteRepository.Policy(policy.isEnabled(), policy.getUpdatePolicy(), policy.getChecksumPolicy())
+           : null;
+  }
+
   private static MavenRemoteRepository.Policy convertPolicy(RepositoryPolicy policy) {
     return policy != null
            ? new MavenRemoteRepository.Policy(policy.isEnabled(), policy.getUpdatePolicy(), policy.getChecksumPolicy())