Skip to content
This repository was archived by the owner on Mar 11, 2019. It is now read-only.

Commit 4a40844

Browse files
committed
chore(build.sbt): update libraries + add a common build object to download bluecove
refactoring(libraries): extract unmanaged dependencies inside a root folder Use a root folder to store external dependencies. Fix a bug with sigar (closes #75).
1 parent 8b1d1d1 commit 4a40844

File tree

133 files changed

+244
-174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+244
-174
lines changed

.gitignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,5 @@ target/
3434
.worksheet
3535

3636
#bluecove
37-
*/*/bluecove*
37+
*bluecove*
3838

39-
#tokens
40-
secrets.tar

README.md

+7-7

build.sbt

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
name := "powerapi"
22

3-
version in ThisBuild := "3.4"
4-
5-
scalaVersion in ThisBuild := "2.11.6"
6-
7-
scalacOptions in ThisBuild ++= Seq(
8-
"-language:reflectiveCalls",
9-
"-language:implicitConversions",
10-
"-feature",
11-
"-deprecation"
12-
)
13-
143
// Logging
154
libraryDependencies in ThisBuild ++= Seq(
16-
"org.apache.logging.log4j" % "log4j-api" % "2.3",
17-
"org.apache.logging.log4j" % "log4j-core" % "2.3"
5+
"org.apache.logging.log4j" % "log4j-api" % "2.5",
6+
"org.apache.logging.log4j" % "log4j-core" % "2.5"
187
)
19-
20-
parallelExecution in (ThisBuild, Test) := false
File renamed without changes.
File renamed without changes.

powerapi-cli/build.sbt

+17-26
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
name := "powerapi-cli"
22

3-
lazy val downloadBluecoveApp = taskKey[File]("download-bluecove-app")
4-
lazy val downloadBluecoveGplApp = taskKey[File]("download-bluecove-gpl-app")
5-
6-
downloadBluecoveApp := {
7-
val locationBluecove = baseDirectory.value / "lib" / "bluecove-2.1.0.jar"
8-
if(!locationBluecove.getParentFile.exists()) locationBluecove.getParentFile.mkdirs()
9-
if(!locationBluecove.exists()) IO.download(url("https://bluecove.googlecode.com/files/bluecove-2.1.0.jar"), locationBluecove)
10-
locationBluecove
11-
}
12-
13-
downloadBluecoveGplApp := {
14-
val locationBluecoveGpl = baseDirectory.value / "lib" / "bluecove-gpl-2.1.0.jar"
15-
if(!locationBluecoveGpl.getParentFile.exists()) locationBluecoveGpl.getParentFile.mkdirs()
16-
if(!locationBluecoveGpl.exists()) IO.download(url("https://bluecove.googlecode.com/files/bluecove-gpl-2.1.0.jar"), locationBluecoveGpl)
17-
locationBluecoveGpl
18-
}
3+
mappings in Universal += downloadBluecove.value -> s"lib/${downloadBluecove.value.name}"
194

20-
mappings in Universal += downloadBluecoveApp.value -> s"lib/${downloadBluecoveApp.value.name}"
5+
mappings in Universal += downloadBluecoveGpl.value -> s"lib/${downloadBluecoveGpl.value.name}"
216

22-
mappings in Universal += downloadBluecoveGplApp.value -> s"lib/${downloadBluecoveGplApp.value.name}"
7+
mappings in Universal ++= {
8+
val dir = baseDirectory.value.getParentFile
9+
10+
(for {
11+
(file, relativePath) <- (dir * "README*" --- dir) pair relativeTo (dir)
12+
} yield file -> s"$relativePath") ++
13+
(for {
14+
(file, relativePath) <- (dir * "LICENSE*" --- dir) pair relativeTo (dir)
15+
} yield file -> s"$relativePath")
16+
}
2317

2418
mappings in Universal ++= {
25-
((file("../") * "README*").get map {
26-
readmeFile: File =>
27-
readmeFile -> readmeFile.getName
28-
}) ++
29-
((file("../") * "LICENSE*").get map {
30-
licenseFile: File =>
31-
licenseFile -> licenseFile.getName
32-
})
19+
val dir = baseDirectory.value.getParentFile / "external-libs" / "sigar-bin"
20+
21+
for {
22+
(file, relativePath) <- (dir.*** --- dir) pair relativeTo(dir)
23+
} yield file -> s"/lib/sigar-bin/$relativePath"
3324
}
3425

3526
scriptClasspath ++= Seq("../conf", "../scripts")

powerapi-core/build.sbt

+6-18
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ resolvers ++= Seq(
99

1010
// App
1111
libraryDependencies ++= Seq(
12-
"com.typesafe.akka" %% "akka-actor" % "2.3.11",
12+
"com.typesafe.akka" %% "akka-actor" % "2.3.14",
1313
"com.typesafe" % "config" % "1.2.1",
1414
"fr.inria.powerspy" % "powerspy-core_2.11" % "1.2",
1515
"com.nativelibs4java" % "bridj" % "0.7.0",
1616
"com.github.scala-incubator.io" %% "scala-io-core" % "0.4.3",
1717
"com.github.scala-incubator.io" %% "scala-io-file" % "0.4.3",
1818
"org.jfree" % "jfreechart" % "1.0.19",
19-
"org.scala-saddle" %% "saddle-core" % "1.3.3",
19+
"org.scala-saddle" %% "saddle-core" % "1.3.4",
2020
"org.hyperic" % "sigar" % "1.6.5.132",
2121
"io.spray" %% "spray-can" % "1.3.3",
2222
"io.spray" %% "spray-client" % "1.3.3",
2323
"io.spray" %% "spray-routing" % "1.3.3",
2424
"io.spray" %% "spray-json" % "1.3.2",
25-
"com.github.nscala-time" %% "nscala-time" % "2.0.0",
26-
"net.java.dev.jna" % "jna" % "4.1.0",
27-
"com.github.docker-java" % "docker-java" % "2.1.1"
25+
"com.github.nscala-time" %% "nscala-time" % "2.8.0",
26+
"net.java.dev.jna" % "jna" % "4.2.1",
27+
"com.github.docker-java" % "docker-java" % "2.1.4"
2828
)
2929

3030
// Tests
3131
libraryDependencies ++= Seq(
32-
"com.typesafe.akka" %% "akka-testkit" % "2.3.11" % "test",
32+
"com.typesafe.akka" %% "akka-testkit" % "2.3.14" % "test",
3333
"org.scalatest" %% "scalatest" % "2.2.5" % "test",
3434
"org.scalamock" %% "scalamock-scalatest-support" % "3.2.2" % "test",
3535
"io.spray" %% "spray-testkit" % "1.3.3" % "test"
@@ -75,15 +75,3 @@ publishTo := {
7575
else
7676
Some("releases" at nexus + "service/local/staging/deploy/maven2")
7777
}
78-
79-
val downloadBluecoveLibs = taskKey[Seq[File]]("download-bluecove")
80-
81-
downloadBluecoveLibs := {
82-
val locationBluecove = baseDirectory.value / "lib" / "bluecove-2.1.0.jar"
83-
val locationBluecoveGpl = baseDirectory.value / "lib" / "bluecove-gpl-2.1.0.jar"
84-
if(!locationBluecove.getParentFile.exists()) locationBluecove.getParentFile.mkdirs()
85-
if(!locationBluecoveGpl.getParentFile.exists()) locationBluecoveGpl.getParentFile.mkdirs()
86-
if(!locationBluecove.exists()) IO.download(url("https://bluecove.googlecode.com/files/bluecove-2.1.0.jar"), locationBluecove)
87-
if(!locationBluecoveGpl.exists()) IO.download(url("https://bluecove.googlecode.com/files/bluecove-gpl-2.1.0.jar"), locationBluecoveGpl)
88-
Seq(locationBluecove, locationBluecoveGpl)
89-
}

powerapi-core/src/main/scala/org/powerapi/core/OSHelper.scala

+13-19
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import com.typesafe.config.Config
2626
import java.io.{IOException, File}
2727
import java.util.UUID
2828
import org.apache.logging.log4j.LogManager
29-
import org.hyperic.sigar.{Sigar, SigarException, SigarProxyCache}
29+
import org.hyperic.sigar.{SigarProxy, Sigar, SigarException, SigarProxyCache}
3030
import org.hyperic.sigar.ptql.ProcessFinder
3131
import org.powerapi.core.FileHelper.using
3232
import org.powerapi.core.target.{All, Application, Container, Process, Target, TargetUsageRatio}
@@ -402,34 +402,28 @@ class LinuxHelper extends Configuration(None) with OSHelper {
402402
}
403403
}
404404

405+
trait SigarHelperConfiguration extends Configuration {
406+
/**
407+
* Sigar native libraries
408+
*/
409+
lazy val libNativePath = load { _.getString("powerapi.sigar.native-path") } match {
410+
case ConfigValue(p) => p
411+
case _ => "./lib/sigar-bin"
412+
}
413+
}
414+
405415
/**
406416
* SIGAR special helper.
407417
*
408418
* @author <a href="mailto:[email protected]">Loïc Huertas</a>
409419
*/
410-
class SigarHelper extends Configuration(None) with OSHelper {
420+
class SigarHelper(sigar: SigarProxy) extends OSHelper {
411421
private val log = LogManager.getLogger
412422

413-
/**
414-
* Sigar native libraries
415-
*/
416-
lazy val libNativePath = load { _.getString("powerapi.sigar.native-path") } match {
417-
case ConfigValue(p) => p
418-
case _ => "./lib"
419-
}
420-
421-
/**
422-
* SIGAR's proxy instance.
423-
*/
424-
lazy val sigar = {
425-
System.setProperty("java.library.path", libNativePath)
426-
SigarProxyCache.newInstance(new Sigar(), 100)
427-
}
428-
429423
/**
430424
* CPU cores number.
431425
*/
432-
lazy val cores = sigar.getCpuInfoList()(0).getTotalCores()
426+
lazy val cores = sigar.getCpuInfoList()(0).getTotalCores
433427

434428
def getCPUFrequencies: Set[Long] = throw new SigarException("sigar cannot be able to get CPU frequencies")
435429

powerapi-core/src/main/scala/org/powerapi/module/cpu/simple/CpuSimpleModule.scala

+9-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
*/
2323
package org.powerapi.module.cpu.simple
2424

25+
import org.hyperic.sigar.{Sigar, SigarProxyCache}
2526
import org.powerapi.PowerModule
26-
import org.powerapi.core.{SigarHelper, LinuxHelper, OSHelper}
27+
import org.powerapi.core.{SigarHelperConfiguration, SigarHelper, LinuxHelper, OSHelper}
2728

2829
class CpuSimpleModule(osHelper: OSHelper, tdp: Double, tdpFactor: Double) extends PowerModule {
2930
lazy val underlyingSensorsClasses = Seq((classOf[CpuSensor], Seq(osHelper)))
@@ -38,9 +39,14 @@ object ProcFSCpuSimpleModule extends CpuFormulaConfiguration {
3839
}
3940
}
4041

41-
object SigarCpuSimpleModule extends CpuFormulaConfiguration {
42+
object SigarCpuSimpleModule extends CpuFormulaConfiguration with SigarHelperConfiguration {
43+
val sigar = {
44+
System.setProperty("java.library.path", libNativePath)
45+
SigarProxyCache.newInstance(new Sigar(), 100)
46+
}
47+
4248
def apply(): CpuSimpleModule = {
43-
val sigarHelper = new SigarHelper
49+
val sigarHelper = new SigarHelper(sigar)
4450

4551
new CpuSimpleModule(sigarHelper, tdp, tdpFactor)
4652
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
~ This software is licensed under the GNU Affero General Public License, quoted below.
4+
~
5+
~ This file is a part of PowerAPI.
6+
~
7+
~ Copyright (C) 2011-2016 Inria, University of Lille 1.
8+
~
9+
~ PowerAPI is free software: you can redistribute it and/or modify
10+
~ it under the terms of the GNU Affero General Public License as
11+
~ published by the Free Software Foundation, either version 3 of
12+
~ the License, or (at your option) any later version.
13+
~
14+
~ PowerAPI is distributed in the hope that it will be useful,
15+
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
~ GNU Affero General Public License for more details.
18+
~
19+
~ You should have received a copy of the GNU Affero General Public License
20+
~ along with PowerAPI.
21+
~
22+
~ If not, please consult http://www.gnu.org/licenses/agpl-3.0.html.
23+
-->
24+
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
25+
26+
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
27+
<appender name="console" class="org.apache.log4j.ConsoleAppender">
28+
<param name="Target" value="System.out"/>
29+
<layout class="org.apache.log4j.PatternLayout">
30+
<param name="ConversionPattern" value="[%level] [%d{MM/dd/yyyy HH:mm:ss.SSS}] [%t] [%logger{36}] - %msg%n"/>
31+
</layout>
32+
</appender>
33+
34+
<root>
35+
<priority value="error" />
36+
<appender-ref ref="console" />
37+
</root>
38+
</log4j:configuration>

powerapi-core/src/test/scala/org/powerapi/core/OSHelperSuite.scala

+9-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import java.util.UUID
2626
import akka.actor.ActorSystem
2727
import akka.testkit.TestKit
2828
import akka.util.Timeout
29-
import org.hyperic.sigar.SigarException
29+
import org.hyperic.sigar.{Sigar, SigarProxyCache, SigarException}
3030
import org.powerapi.UnitTest
3131
import org.powerapi.core.target.{All, Application, Container, Process, intToProcess, stringToApplication, TargetUsageRatio}
3232
import org.powerapi.module.CacheKey
@@ -250,17 +250,19 @@ class OSHelperSuite(system: ActorSystem) extends UnitTest(system) {
250250
(timesLeft - timesRight) should equal(TimeInStates(Map(1l -> 9l, 2l -> 18l, 3l -> 27l, 4l -> 15l)))
251251
}
252252

253-
"The SigarHelper" should "be able to read configuration parameters" in {
254-
val sigarHelper = new SigarHelper
253+
"The SigarHelperConfiguration" should "be able to read configuration parameters" in {
254+
val sigarHelper = new SigarHelperConfiguration {}
255255

256256
sigarHelper.libNativePath should equal("p2")
257257
}
258258

259-
"The SigarHelper methods" should "return correct values" in {
260-
val helper = new SigarHelper {
261-
override lazy val libNativePath = "./powerapi-core/lib"
259+
"The SigarHelper methods" should "return correct values" ignore {
260+
val sigar = {
261+
System.setProperty("java.library.path", s"./../external-libs/sigar-bin")
262+
SigarProxyCache.newInstance(new Sigar(), 100)
262263
}
263-
264+
265+
val helper = new SigarHelper(sigar)
264266
val pid = Process(java.lang.management.ManagementFactory.getRuntimeMXBean.getName.split("@")(0).toInt)
265267

266268
intercept[SigarException] { helper.getCPUFrequencies }

powerapi-core/src/test/scala/org/powerapi/module/cpu/simple/CpuSimpleModulesSuite.scala

-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ class CpuSimpleModulesSuite(system: ActorSystem) extends UnitTest(system) {
9494
module.underlyingSensorsClasses(0)._1 should equal(classOf[CpuSensor])
9595
module.underlyingSensorsClasses(0)._2.size should equal(1)
9696
module.underlyingSensorsClasses(0)._2(0).getClass should equal(classOf[SigarHelper])
97-
module.underlyingSensorsClasses(0)._2(0).asInstanceOf[SigarHelper].libNativePath should equal("p2")
9897

9998
module.underlyingFormulaeClasses.size should equal(1)
10099
module.underlyingFormulaeClasses(0)._1 should equal(classOf[CpuFormula])

powerapi-daemon/build.sbt

+16-28
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,32 @@
1-
enablePlugins(JavaServerAppPackaging)
2-
31
name := "powerapi-daemon"
42

53
libraryDependencies ++= Seq(
64
"commons-daemon" % "commons-daemon" % "1.0.15"
75
)
86

9-
lazy val downloadBluecoveDaemon = taskKey[File]("download-bluecove-daemon")
10-
lazy val downloadBluecoveGplDaemon = taskKey[File]("download-bluecove-gpl-daemon")
7+
mappings in Universal += downloadBluecove.value -> s"lib/${downloadBluecove.value.name}"
118

12-
downloadBluecoveDaemon := {
13-
val locationBluecove = baseDirectory.value / "lib" / "bluecove-2.1.0.jar"
14-
if(!locationBluecove.getParentFile.exists()) locationBluecove.getParentFile.mkdirs()
15-
if(!locationBluecove.exists()) IO.download(url("https://bluecove.googlecode.com/files/bluecove-2.1.0.jar"), locationBluecove)
16-
locationBluecove
17-
}
9+
mappings in Universal += downloadBluecoveGpl.value -> s"lib/${downloadBluecoveGpl.value.name}"
1810

19-
downloadBluecoveGplDaemon := {
20-
val locationBluecoveGpl = baseDirectory.value / "lib" / "bluecove-gpl-2.1.0.jar"
21-
if(!locationBluecoveGpl.getParentFile.exists()) locationBluecoveGpl.getParentFile.mkdirs()
22-
if(!locationBluecoveGpl.exists()) IO.download(url("https://bluecove.googlecode.com/files/bluecove-gpl-2.1.0.jar"), locationBluecoveGpl)
23-
locationBluecoveGpl
11+
mappings in Universal ++= {
12+
val dir = baseDirectory.value.getParentFile
13+
14+
(for {
15+
(file, relativePath) <- (dir * "README*" --- dir) pair relativeTo (dir)
16+
} yield file -> s"$relativePath") ++
17+
(for {
18+
(file, relativePath) <- (dir * "LICENSE*" --- dir) pair relativeTo (dir)
19+
} yield file -> s"$relativePath")
2420
}
2521

26-
mappings in Universal += downloadBluecoveDaemon.value -> s"lib/${downloadBluecoveDaemon.value.name}"
27-
28-
mappings in Universal += downloadBluecoveGplDaemon.value -> s"lib/${downloadBluecoveGplDaemon.value.name}"
29-
3022
mappings in Universal ++= {
31-
((file("../") * "README*").get map {
32-
readmeFile: File =>
33-
readmeFile -> readmeFile.getName
34-
}) ++
35-
((file("../") * "LICENSE*").get map {
36-
licenseFile: File =>
37-
licenseFile -> licenseFile.getName
38-
})
23+
val dir = baseDirectory.value.getParentFile / "external-libs" / "sigar-bin"
24+
25+
for {
26+
(file, relativePath) <- (dir.*** --- dir) pair relativeTo(dir)
27+
} yield file -> s"/lib/sigar-bin/$relativePath"
3928
}
4029

4130
scriptClasspath ++= Seq("../conf", "../scripts")
4231

4332
NativePackagerKeys.executableScriptName := "powerapid"
44-

0 commit comments

Comments
 (0)