Skip to content

Commit fecc237

Browse files
committed
Made read operation more resilient. Closes #29.
1 parent fdb8c6d commit fecc237

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/main/scala/de/upb/cs/swt/delphi/crawler/discovery/maven/IndexProcessing.scala

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
package de.upb.cs.swt.delphi.crawler.discovery.maven
1818

1919
import java.net.{URI, URL}
20+
import java.util
2021

2122
import akka.NotUsed
2223
import akka.event.LoggingAdapter
2324
import akka.stream.scaladsl.{RestartSource, Source}
2425
import org.apache.maven.index.reader.IndexReader
2526
import org.slf4j.LoggerFactory
2627

27-
import scala.util.{Failure, Success, Try}
2828
import scala.concurrent.duration._
29+
import scala.util.{Failure, Success, Try}
2930

3031
trait IndexProcessing {
3132

@@ -73,15 +74,27 @@ class MavenIndexReader(base: URL) {
7374
lazy val cr = ir.iterator().next().iterator()
7475

7576
def read(): Option[MavenIdentifier] = {
76-
cr.hasNext() match {
77-
case true => {
78-
val kvp = cr.next()
79-
val identifier = kvp.get("u").split("|".toCharArray)
8077

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+
}
8493
}
94+
}
95+
96+
cr.hasNext() match {
97+
case true => Iterator.continually(readInternal(cr.next())).takeWhile(result => cr.hasNext()).collectFirst[MavenIdentifier]({ case Some(x) => x})
8598
case false => None
8699
}
87100
}

0 commit comments

Comments
 (0)