-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add util.BuildInformation and buildinfo command
This is a first attempt at #41. - adam-core: Add git-commit plugin to POM file. The file is generated is `adam-core/src/main/resources/git.properties` and the info is available in the object `edu.berkeley.cs.amplab.adam.core.util.BuildInformation`. - adam-cli: Add the command `buildinfo`.
- Loading branch information
Showing
6 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,6 @@ | |
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
adam-cli/src/main/scala/edu/berkeley/cs/amplab/adam/cli/BuildInformation.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2014. Sebastien Mondet <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package edu.berkeley.cs.amplab.adam.cli | ||
|
||
import scala.collection.JavaConversions._ | ||
import scala.Some | ||
import scala.collection.JavaConverters._ | ||
|
||
|
||
object BuildInformation extends AdamCommandCompanion { | ||
val commandName: String = "buildinfo" | ||
val commandDescription: String = "Display build information (use this for bug reports)" | ||
|
||
def apply(cmdLine: Array[String]): AdamCommand = { | ||
new BuildInformation() | ||
} | ||
} | ||
|
||
class BuildInformation() extends AdamCommand { | ||
val companion = BuildInformation | ||
|
||
def run() = { | ||
val properties = edu.berkeley.cs.amplab.adam.core.util.BuildInformation.asString(); | ||
println("Build information:\n" + properties); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
dependency-reduced-pom.xml | ||
src/main/resources/git.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
adam-core/src/main/scala/edu/berkeley/cs/amplab/adam/util/BuildInformation.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2014. Sebastien Mondet <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package edu.berkeley.cs.amplab.adam.core.util | ||
|
||
import scala.collection.JavaConversions._ | ||
import scala.Some | ||
import scala.collection.JavaConverters._ | ||
import java.util.Properties | ||
|
||
/** A static object that gets the resource "git.properties" and renders the | ||
* build-information in different formats. The parsing is “lazy”, it parses | ||
* the properties only the first time a function is called. */ | ||
object BuildInformation { | ||
|
||
private var properties : scala.Option[scala.collection.mutable.Map[String,String]] = None | ||
|
||
/** Return a scala mutable Map (property, value). */ | ||
def asMap(): scala.collection.mutable.Map[String,String] = { | ||
properties match { | ||
case Some(inThere) => inThere | ||
case None => { | ||
val javaProperties = new Properties; | ||
javaProperties.load(getClass().getClassLoader().getResourceAsStream("git.properties")); | ||
properties = Some(javaProperties.asScala); | ||
javaProperties.asScala | ||
} | ||
} | ||
} | ||
|
||
/** Return a formatted human-readable string. */ | ||
def asString(): String = { | ||
asMap().foldLeft(""){ | ||
case (prev_string, (key, value)) => | ||
prev_string + key + ": " + value + "\n" | ||
} | ||
} | ||
} |