Skip to content

Commit

Permalink
handle project>scm>tag in pom
Browse files Browse the repository at this point in the history
fixes #35
  • Loading branch information
McFoggy committed Nov 1, 2017
1 parent f3521c1 commit b6f7438
Show file tree
Hide file tree
Showing 16 changed files with 466 additions and 79 deletions.
2 changes: 2 additions & 0 deletions src/it/issues/issue-35.1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
prebuild.log
build.log
25 changes: 25 additions & 0 deletions src/it/issues/issue-35.1/.mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
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.
-->
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
<extension>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</extension>
</extensions>
1 change: 1 addition & 0 deletions src/it/issues/issue-35.1/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# invoker.mavenOpts = -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
38 changes: 38 additions & 0 deletions src/it/issues/issue-35.1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>fr.brouillard.oss.it</groupId>
<artifactId>issue-35.1</artifactId>
<version>0</version>
<packaging>pom</packaging>

<description>Verify SCM tag is udpated with SHA1</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<scm>
<connection>scm:git:https://github.com/jgitver/dummy.git</connection>
<developerConnection>scm:git:https://github.com/jgitver/dummy.git</developerConnection>
<tag>HEAD</tag>
</scm>
</project>
52 changes: 52 additions & 0 deletions src/it/issues/issue-35.1/prebuild.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* 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.
*/

def log = new PrintWriter( new File(basedir, "prebuild.log").newWriter("UTF-8"), true )
log.println( "Prebuild started at: " + new Date() + " in: " + basedir )

[
"git --version",
"rm -rf .git",
"git init",
"git config user.name nobody",
"git config user.email nobody@nowhere.com",
"dd if=/dev/urandom of=content bs=512 count=2",
"git add .",
"git commit --message=initial_commit",
"git tag -a 1.0.0 --message=release_1.0.0",
"dd if=/dev/urandom of=content bs=512 count=2",
"git add -u",
"git commit --message=added_B_data",
"git status",
"git log --graph --oneline"
].each{ command ->

def proc = command.execute(null, basedir)
def sout = new StringBuilder(), serr = new StringBuilder()
proc.waitForProcessOutput(sout, serr)

log.println( "cmd: " + command )
log.println( "out:" ) ; log.println( sout.toString().trim() )
log.println( "err:" ) ; log.println( serr.toString().trim() )
log.println( "ret: " + proc.exitValue() )

assert proc.exitValue() == 0

}

log.println( "Prebuild completed at: " + new Date() )
log.close()
return true
56 changes: 56 additions & 0 deletions src/it/issues/issue-35.1/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* 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.
*/

def log = new PrintWriter( new File(basedir, "verify.log").newWriter("UTF-8"), true )
log.println( "Verify started at: " + new Date() + " in: " + basedir )

[
"chmod -R 755 .git",
"rm -rf .git"
].each{ command ->

def proc = command.execute(null, basedir)
def sout = new StringBuilder(), serr = new StringBuilder()
proc.waitForProcessOutput(sout, serr)

log.println( "cmd: " + command )
log.println( "out:" ) ; log.println( sout.toString().trim() )
log.println( "err:" ) ; log.println( serr.toString().trim() )
log.println( "ret: " + proc.exitValue() )

assert proc.exitValue() == 0

}

def buildLog = new File(basedir, "build.log").readLines()

// Check the version was used by the plugin execution
def versionChanges = buildLog.findAll { it =~ /fr.brouillard.oss.it::issue-35.1::0 -> 1.0.1-SNAPSHOT/ }
log.println( "versionChanges: " + versionChanges )
assert 0 < versionChanges.size()

// Check that SCM>tag has been changed
def tagWithHead = buildLog.findAll { it =~ /<tag>HEAD<\/tag>/ }
log.println( "tagWithHead: " + tagWithHead)
assert 0 == tagWithHead.size()

def tagWithSHA1 = buildLog.findAll { it =~ /<tag>[a-zA-Z0-9]{40}<\/tag>/ }
log.println( "tagWithSHA1: " + tagWithSHA1)
assert 0 == tagWithSHA1.size()

log.println( "Verify completed at: " + new Date() )
log.close()
return true
2 changes: 2 additions & 0 deletions src/it/issues/issue-35.2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
prebuild.log
build.log
25 changes: 25 additions & 0 deletions src/it/issues/issue-35.2/.mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
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.
-->
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
<extension>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</extension>
</extensions>
1 change: 1 addition & 0 deletions src/it/issues/issue-35.2/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# invoker.mavenOpts = -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
38 changes: 38 additions & 0 deletions src/it/issues/issue-35.2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>fr.brouillard.oss.it</groupId>
<artifactId>issue-35.2</artifactId>
<version>0</version>
<packaging>pom</packaging>

<description>Verify SCM tag is udpated with release version</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<scm>
<connection>scm:git:https://github.com/jgitver/dummy.git</connection>
<developerConnection>scm:git:https://github.com/jgitver/dummy.git</developerConnection>
<tag>HEAD</tag>
</scm>
</project>
53 changes: 53 additions & 0 deletions src/it/issues/issue-35.2/prebuild.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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.
*/

def log = new PrintWriter( new File(basedir, "prebuild.log").newWriter("UTF-8"), true )
log.println( "Prebuild started at: " + new Date() + " in: " + basedir )

[
"git --version",
"rm -rf .git",
"git init",
"git config user.name nobody",
"git config user.email nobody@nowhere.com",
"dd if=/dev/urandom of=content bs=512 count=2",
"git add .",
"git commit --message=initial_commit",
"git tag -a 1.0.0 --message=release_1.0.0",
"dd if=/dev/urandom of=content bs=512 count=2",
"git add -u",
"git commit --message=added_B_data",
"git tag -a 2.0.0 --message=release_2.0.0",
"git status",
"git log --graph --oneline"
].each{ command ->

def proc = command.execute(null, basedir)
def sout = new StringBuilder(), serr = new StringBuilder()
proc.waitForProcessOutput(sout, serr)

log.println( "cmd: " + command )
log.println( "out:" ) ; log.println( sout.toString().trim() )
log.println( "err:" ) ; log.println( serr.toString().trim() )
log.println( "ret: " + proc.exitValue() )

assert proc.exitValue() == 0

}

log.println( "Prebuild completed at: " + new Date() )
log.close()
return true
56 changes: 56 additions & 0 deletions src/it/issues/issue-35.2/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* 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.
*/

def log = new PrintWriter( new File(basedir, "verify.log").newWriter("UTF-8"), true )
log.println( "Verify started at: " + new Date() + " in: " + basedir )

[
"chmod -R 755 .git",
"rm -rf .git"
].each{ command ->

def proc = command.execute(null, basedir)
def sout = new StringBuilder(), serr = new StringBuilder()
proc.waitForProcessOutput(sout, serr)

log.println( "cmd: " + command )
log.println( "out:" ) ; log.println( sout.toString().trim() )
log.println( "err:" ) ; log.println( serr.toString().trim() )
log.println( "ret: " + proc.exitValue() )

assert proc.exitValue() == 0

}

def buildLog = new File(basedir, "build.log").readLines()

// Check the version was used by the plugin execution
def versionChanges = buildLog.findAll { it =~ /fr.brouillard.oss.it::issue-35.2::0 -> 2.0.0/ }
log.println( "versionChanges: " + versionChanges )
assert 0 < versionChanges.size()

// Check that SCM>tag has been changed
def tagWithHead = buildLog.findAll { it =~ /<tag>HEAD<\/tag>/ }
log.println( "tagWithHead: " + tagWithHead)
assert 0 == tagWithHead.size()

def tagWithRelease = buildLog.findAll { it =~ /<tag>2.0.0<\/tag>/ }
log.println( "tagWithSHA1: " + tagWithRelease)
assert 0 == tagWithRelease.size()

log.println( "Verify completed at: " + new Date() )
log.close()
return true
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void afterSessionStart(MavenSession mavenSession) throws MavenExecutionEx
}

JGitverUtils.fillPropertiesFromMetadatas(mavenSession.getUserProperties(), gitVersionCalculator, logger);
sessionHolder.setSession(new JGitverSession(gitVersionCalculator.getVersion(), rootDirectory));
sessionHolder.setSession(new JGitverSession(gitVersionCalculator, rootDirectory));
} catch (Exception ex) {
logger.warn("cannot autoclose GitVersionCalculator object for project: " + rootDirectory, ex);
}
Expand Down
Loading

0 comments on commit b6f7438

Please sign in to comment.