|
17 | 17 | package de.upb.cs.swt.delphi.crawler.discovery.maven |
18 | 18 |
|
19 | 19 | import java.net.{URI, URL} |
| 20 | +import java.util |
20 | 21 |
|
21 | 22 | import akka.NotUsed |
22 | 23 | import akka.event.LoggingAdapter |
23 | 24 | import akka.stream.scaladsl.{RestartSource, Source} |
24 | 25 | import org.apache.maven.index.reader.IndexReader |
25 | 26 | import org.slf4j.LoggerFactory |
26 | 27 |
|
27 | | -import scala.util.{Failure, Success, Try} |
28 | 28 | import scala.concurrent.duration._ |
| 29 | +import scala.util.{Failure, Success, Try} |
29 | 30 |
|
30 | 31 | trait IndexProcessing { |
31 | 32 |
|
@@ -73,15 +74,27 @@ class MavenIndexReader(base: URL) { |
73 | 74 | lazy val cr = ir.iterator().next().iterator() |
74 | 75 |
|
75 | 76 | def read(): Option[MavenIdentifier] = { |
76 | | - cr.hasNext() match { |
77 | | - case true => { |
78 | | - val kvp = cr.next() |
79 | | - val identifier = kvp.get("u").split("|".toCharArray) |
80 | 77 |
|
81 | | - val mavenId = MavenIdentifier(base.toString, identifier(0), identifier(1), identifier(2)) |
82 | | - log.debug(s"Producing $mavenId") |
83 | | - Some(mavenId) |
| 78 | + def readInternal(kvp: util.Map[String, String]) = { |
| 79 | + val kvpU = kvp.get("u") |
| 80 | + val identifierAttempt = Try(kvpU.split("|".toCharArray)) |
| 81 | + |
| 82 | + identifierAttempt match { |
| 83 | + case Success(identifier) => { |
| 84 | + val mavenId = MavenIdentifier(base.toString, identifier(0), identifier(1), identifier(2)) |
| 85 | + log.debug(s"Producing $mavenId") |
| 86 | + |
| 87 | + Some(mavenId) |
| 88 | + } |
| 89 | + case Failure(e) => { |
| 90 | + log.warn(s"While processing index we received the following u-value that we could not split $kvpU. Full kvp is $kvp. Exception was $e.") |
| 91 | + None |
| 92 | + } |
84 | 93 | } |
| 94 | + } |
| 95 | + |
| 96 | + cr.hasNext() match { |
| 97 | + case true => Iterator.continually(readInternal(cr.next())).takeWhile(result => cr.hasNext()).collectFirst[MavenIdentifier]({ case Some(x) => x}) |
85 | 98 | case false => None |
86 | 99 | } |
87 | 100 | } |
|
0 commit comments