diff --git a/jvm-packages/pom.xml b/jvm-packages/pom.xml index a6ed7b2f0..1476801c6 100644 --- a/jvm-packages/pom.xml +++ b/jvm-packages/pom.xml @@ -212,6 +212,12 @@ + + + src/main/resources + true + + org.scalastyle diff --git a/jvm-packages/xgboost4j-spark/src/main/scala/ml/dmlc/xgboost4j/scala/spark/XGBoost.scala b/jvm-packages/xgboost4j-spark/src/main/scala/ml/dmlc/xgboost4j/scala/spark/XGBoost.scala index 43ad1f1bd..34e59b0dd 100644 --- a/jvm-packages/xgboost4j-spark/src/main/scala/ml/dmlc/xgboost4j/scala/spark/XGBoost.scala +++ b/jvm-packages/xgboost4j-spark/src/main/scala/ml/dmlc/xgboost4j/scala/spark/XGBoost.scala @@ -18,6 +18,7 @@ package ml.dmlc.xgboost4j.scala.spark import java.io.File import java.nio.file.Files +import java.util.Properties import scala.collection.mutable.ListBuffer import scala.collection.{AbstractIterator, mutable} @@ -31,7 +32,7 @@ import org.apache.commons.io.FileUtils import org.apache.commons.logging.LogFactory import org.apache.spark.rdd.RDD -import org.apache.spark.{SparkContext, SparkParallelismTracker, TaskContext} +import org.apache.spark.{SparkContext, SparkException, SparkParallelismTracker, TaskContext} import org.apache.spark.sql.{DataFrame, SparkSession} import org.apache.spark.storage.StorageLevel @@ -386,7 +387,7 @@ object XGBoost extends Serializable { hasGroup: Boolean = false, evalSetsMap: Map[String, RDD[XGBLabeledPoint]] = Map()): (Booster, Map[String, Array[Float]]) = { - logger.info(s"XGBoost training with parameters:\n${params.mkString("\n")}") + logger.info(s"Running XGBoost ${spark.VERSION} with parameters:\n${params.mkString("\n")}") val (nWorkers, round, _, _, _, _, trackerConf, timeoutRequestWorkers, checkpointPath, checkpointInterval) = parameterFetchAndValidation(params, trainingData.sparkContext) diff --git a/jvm-packages/xgboost4j-spark/src/main/scala/ml/dmlc/xgboost4j/scala/spark/package.scala b/jvm-packages/xgboost4j-spark/src/main/scala/ml/dmlc/xgboost4j/scala/spark/package.scala new file mode 100644 index 000000000..df5e3bcc0 --- /dev/null +++ b/jvm-packages/xgboost4j-spark/src/main/scala/ml/dmlc/xgboost4j/scala/spark/package.scala @@ -0,0 +1,48 @@ +/* + Copyright (c) 2014 by Contributors + + 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 ml.dmlc.xgboost4j.scala + +import java.util.Properties + +import org.apache.spark.SparkException + +package object spark { + private def loadVersionInfo(): String = { + val versionResourceFile = Thread.currentThread().getContextClassLoader.getResourceAsStream( + "xgboost4j-version.properties") + try { + val unknownProp = "" + val props = new Properties() + props.load(versionResourceFile) + props.getProperty("version", unknownProp) + } catch { + case e: Exception => + throw new SparkException("Error loading properties from xgboost4j-version.properties", e) + } finally { + if (versionResourceFile != null) { + try { + versionResourceFile.close() + } catch { + case e: Exception => + throw new SparkException("Error closing xgboost4j version resource stream", e) + } + } + } + } + + val VERSION: String = loadVersionInfo() +} diff --git a/jvm-packages/xgboost4j/src/main/resources/xgboost4j-version.properties b/jvm-packages/xgboost4j/src/main/resources/xgboost4j-version.properties new file mode 100644 index 000000000..e5683df88 --- /dev/null +++ b/jvm-packages/xgboost4j/src/main/resources/xgboost4j-version.properties @@ -0,0 +1 @@ +version=${project.version} \ No newline at end of file