Skip to content

Commit 4078f9a

Browse files
committed
Refactored HermesActor
1 parent 5d40624 commit 4078f9a

File tree

3 files changed

+71
-26
lines changed

3 files changed

+71
-26
lines changed

src/main/scala/de/upb/cs/swt/delphi/crawler/processing/HermesActor.scala

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,22 @@
1717
package de.upb.cs.swt.delphi.crawler.processing
1818

1919
import java.net.URL
20-
import java.util.jar.JarInputStream
2120

2221
import akka.actor.{Actor, ActorLogging, ActorRef, Props}
2322
import de.upb.cs.swt.delphi.crawler.discovery.maven.MavenIdentifier
2423
import de.upb.cs.swt.delphi.crawler.preprocessing.MavenArtifact
25-
import de.upb.cs.swt.delphi.crawler.tools.ClassStreamReader
2624
import org.opalj.br.analyses.Project
27-
import org.opalj.hermes.{Feature, FeatureQuery}
2825

29-
class HermesActor(elasticActor : ActorRef) extends Actor with ActorLogging {
30-
31-
32-
def transformToFeatures(results: Iterator[(FeatureQuery, TraversableOnce[Feature[URL]])]): Map[String, Int] = {
33-
results.flatMap{ case(query, features: TraversableOnce[Feature[URL]]) => features.map { case feature => feature.id -> feature.count}} toMap
34-
}
26+
class HermesActor(elasticActor : ActorRef) extends Actor with ActorLogging with OPALFunctionality with HermesFunctionality {
3527

3628
def receive: PartialFunction[Any, Unit] = {
3729
case m : MavenArtifact => {
3830
log.info(s"Starting analysis for $m")
39-
val project: Project[URL] = reifyProject(m)
4031

32+
val project: Project[URL] = reifyProject(m)
4133
val hermesResult: HermesResults = computeHermesResult(m, project)
42-
4334
elasticActor ! hermesResult
4435
}
45-
46-
}
47-
48-
private def computeHermesResult(m: MavenArtifact, project: Project[URL]) = {
49-
val results = new HermesAnalyzer(project).analyzeProject()
50-
val featureMap = transformToFeatures(results)
51-
val hermesResult = HermesResults(m.identifier, featureMap)
52-
log.info(s"Feature map for ${hermesResult.identifier.toUniqueString} is ${hermesResult.featureMap.size}.")
53-
hermesResult
54-
}
55-
56-
private def reifyProject(m: MavenArtifact) = {
57-
val project = new ClassStreamReader {}.createProject(m.identifier.toJarLocation.toURL,
58-
new JarInputStream(m.jarFile.is))
59-
project
6036
}
6137
}
6238

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (C) 2018 The Delphi Team.
2+
// See the LICENCE file distributed with this work for additional
3+
// information regarding copyright ownership.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package de.upb.cs.swt.delphi.crawler.processing
18+
import java.net.URL
19+
20+
import de.upb.cs.swt.delphi.crawler.preprocessing.MavenArtifact
21+
import org.opalj.br.analyses.Project
22+
import org.opalj.hermes.{Feature, FeatureQuery}
23+
24+
trait HermesFunctionality {
25+
26+
def transformToFeatures(results: Iterator[(FeatureQuery, TraversableOnce[Feature[URL]])]): Map[String, Int] = {
27+
results.flatMap { case (query, features: TraversableOnce[Feature[URL]]) => features.map { case feature => feature.id -> feature.count } } toMap
28+
}
29+
30+
def computeHermesResult(m: MavenArtifact, project: Project[URL]): HermesResults = {
31+
val results = new HermesAnalyzer(project).analyzeProject()
32+
val featureMap = transformToFeatures(results)
33+
val hermesResult = HermesResults(m.identifier, featureMap)
34+
hermesResult
35+
}
36+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (C) 2018 The Delphi Team.
2+
// See the LICENCE file distributed with this work for additional
3+
// information regarding copyright ownership.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package de.upb.cs.swt.delphi.crawler.processing
18+
import java.net.URL
19+
import java.util.jar.JarInputStream
20+
21+
import de.upb.cs.swt.delphi.crawler.preprocessing.MavenArtifact
22+
import de.upb.cs.swt.delphi.crawler.tools.ClassStreamReader
23+
import org.opalj.br.analyses.Project
24+
25+
trait OPALFunctionality {
26+
27+
def reifyProject(m: MavenArtifact): Project[URL] = {
28+
val project = new ClassStreamReader {}.createProject(m.identifier.toJarLocation.toURL,
29+
new JarInputStream(m.jarFile.is))
30+
m.jarFile.is.close()
31+
project
32+
}
33+
}

0 commit comments

Comments
 (0)