Skip to content

Commit

Permalink
Add util.BuildInformation and buildinfo command
Browse files Browse the repository at this point in the history
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
smondet committed Mar 4, 2014
1 parent 6fdf373 commit 72ee24a
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 2 deletions.
1 change: 0 additions & 1 deletion adam-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ object AdamMain extends Logging {
Vcf2Adam,
FindReads,
Fasta2Adam,
PluginExecutor)
PluginExecutor,
BuildInformation)

private def printCommands() {
println("\n")
Expand Down
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);
}


}
1 change: 1 addition & 0 deletions adam-core/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dependency-reduced-pom.xml
src/main/resources/git.properties
20 changes: 20 additions & 0 deletions adam-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.1.9</version>
<executions>
<execution> <goals> <goal>revision</goal> </goals> </execution>
</executions>
<configuration>
<verbose>true</verbose>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<!-- <generateGitPropertiesFilename>adam-cli/src/main/resources/git.properties</generateGitPropertiesFilename> -->
<generateGitPropertiesFilename>src/main/resources/git.properties</generateGitPropertiesFilename>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
<excludeProperties>
<!-- Avoid email addresses and names: -->
<excludeProperty>git.commit.user.*</excludeProperty>
<excludeProperty>git.build.user.*</excludeProperty>
</excludeProperties>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
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"
}
}
}

0 comments on commit 72ee24a

Please sign in to comment.