Skip to content

Commit

Permalink
expose jgitver-maven-plugin version
Browse files Browse the repository at this point in the history
fixes #76
  • Loading branch information
McFoggy committed Feb 2, 2018
1 parent 5b7e68e commit 48d47db
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources-filtered</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/fr/brouillard/oss/jgitver/JGitverExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ public void afterProjectsRead(MavenSession mavenSession) throws MavenExecutionEx
}

sessionHolder.session().ifPresent(jgitverSession -> {
logger.info(String.format(
"jgitver-maven-plugin [%s] (sha1: %s)",
JGitverProperties.getVersion(),
JGitverProperties.getSHA1())
);
logger.info("jgitver-maven-plugin is about to change project(s) version(s)");

jgitverSession.getProjects().forEach(
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/fr/brouillard/oss/jgitver/JGitverProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// @formatter:off
/**
* Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
*
* 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.
*/
// @formatter:on
package fr.brouillard.oss.jgitver;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class JGitverProperties {
static Properties p = new Properties();
static {
try {
InputStream is = JGitverProperties.class.getResourceAsStream("/META-INF/project.properties");
if (is != null) {
p.load(is);
}
} catch (IOException e) {
// ignore
}
}

public static String getVersion() {
return p.getProperty("version", "Unknown");
}

public static String getSHA1() {
return p.getProperty("sha1", "not git sha1");
}
}
2 changes: 2 additions & 0 deletions src/main/java/fr/brouillard/oss/jgitver/JGitverUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ public static void fillPropertiesFromMetadatas(Properties properties, GitVersion
logger.debug(EXTENSION_PREFIX + " calculated version number: " + calculatedVersion);
properties.put(EXTENSION_PREFIX + ".calculated_version", calculatedVersion);

properties.put(EXTENSION_PREFIX + ".plugin-version", JGitverProperties.getVersion());

Arrays.asList(Metadatas.values()).stream().forEach(metaData -> {
Optional<String> metaValue = gitVersionCalculator.meta(metaData);
String propertyName = EXTENSION_PREFIX + "." + metaData.name().toLowerCase(Locale.ENGLISH);
Expand Down
20 changes: 20 additions & 0 deletions src/main/resources-filtered/META-INF/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
#
# 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.
#

version=${jgitver.calculated_version}
dirty=${jgitver.dirty}
sha1=${jgitver.git_sha1_full}
branch=${jgitver.branch_name}

0 comments on commit 48d47db

Please sign in to comment.