Skip to content

Commit

Permalink
provide xml-schema for jgitver maven configuration file, fixes #37
Browse files Browse the repository at this point in the history
  • Loading branch information
McFoggy committed Dec 2, 2016
1 parent 06b6902 commit de0ace3
Show file tree
Hide file tree
Showing 18 changed files with 529 additions and 43 deletions.
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,25 @@ __via curl__

from the root directory of your project, run:

`sh -c "$(curl -fsSL https://raw.githubusercontent.com/jgitver/jgitver-maven-plugin/master/src/doc/scripts/install.sh)"`
``` shell
sh -c "$(curl -fsSL https://raw.githubusercontent.com/jgitver/jgitver-maven-plugin/master/src/doc/scripts/install.sh)"
```

__via wget__

from the root directory of your project, run:

`sh -c "$(wget https://raw.githubusercontent.com/jgitver/jgitver-maven-plugin/master/src/doc/scripts/install.sh -O -)"`
``` shell
sh -c "$(wget https://raw.githubusercontent.com/jgitver/jgitver-maven-plugin/master/src/doc/scripts/install.sh -O -)"
```

__manually__

1. Create a directory `.mvn` under the root directory of your project.
1. Create file `.mvn/extensions.xml`
1. Put the following content to `.mvn/extensions.xml` (adapt to [latest version](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22fr.brouillard.oss%22%20a%3A%22jgitver-maven-plugin%22)).

```
``` xml
<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>
Expand All @@ -55,10 +59,15 @@ __manually__
### Configuration

In order to control [jgitver-maven-plugin](#jgitver-maven-plugin) behavior, you can provide a configuration
file under `$rootProjectDir/.mvn/jgitver.config.xml` having the following format:
file under `$rootProjectDir/.mvn/jgitver.config.xml`.
The configuration file must be compliant with the [xml-schemas](https://jgitver.github.io) supported.

```
<configuration>
Here is an example configuration file:

``` xml
<configuration xmlns="http://jgitver.github.io/maven/configuration/1.0.0-beta"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jgitver.github.io/maven/configuration/1.0.0-beta https://jgitver.github.io/maven/configuration/jgitver-configuration-v1_0_0-beta.xsd ">
<mavenLike>true/false</mavenLike>
<autoIncrementPatch>true/false</autoIncrementPatch>
<useCommitDistance>true/false</useCommitDistance>
Expand All @@ -75,7 +84,7 @@ file under `$rootProjectDir/.mvn/jgitver.config.xml` having the following format
<pattern>pattern</pattern> <!-- regex pattern -->
<!-- list of transformations to apply, if empty, defaults to REPLACE_UNEXPECTED_CHARS_UNDERSCORE, LOWERCASE_EN -->
<transformations>
<transformation>NAME</transformation> <!-- transformation name, one of jgitver#fr.brouillard.oss.jgitver.metadata.Metadatas -->
<transformation>NAME</transformation> <!-- transformation name, one of jgitver#fr.brouillard.oss.jgitver.BranchingPolicy#BranchNameTransformations -->
...
</transformations>
</branchPolicy>
Expand All @@ -93,7 +102,7 @@ Those are available under the following properties name: "jgitver.meta" where `m

You can then use them as standard maven properties in your build:

```
``` xml
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
Expand All @@ -104,7 +113,6 @@ You can then use them as standard maven properties in your build:
</goals>
<configuration>
<tasks>
<echo>version calculated: ${jgitver.calculated_version}</echo>
<echo>dirty: ${jgitver.dirty}</echo>
<echo>head_committer_name: ${jgitver.head_committer_name}</echo>
Expand Down Expand Up @@ -250,7 +258,7 @@ In this context, when executing tests, maven will try to activate extensions sta

To avoid such behavior, you need to tell `jgitver-maven-plugin` to ignore some directories. If you do not have already a jgitver configuration file, create one under `.mvn/jgitver.config.xml` and declare some exclusions (see [configuration](#configuration)):

```
``` xml
<configuration>
<exclusions>
<exclusion>target/local-repo</exclusion>
Expand Down
25 changes: 25 additions & 0 deletions src/it/xml-schemas/invalid-schema-1.0.0/.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>
22 changes: 22 additions & 0 deletions src/it/xml-schemas/invalid-schema-1.0.0/.mvn/jgitver.config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
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.
-->
<configuration xmlns="http://jgitver.github.io/maven/configuration/1.0.0-beta"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jgitver.github.io/maven/configuration/1.0.0-beta https://jgitver.github.io/maven/configuration/jgitver-configuration-v1_0_0-beta.xsd">
<doesNotExist></doesNotExist>
</configuration>
2 changes: 2 additions & 0 deletions src/it/xml-schemas/invalid-schema-1.0.0/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.buildResult = failure
invoker.goals = -X install
32 changes: 32 additions & 0 deletions src/it/xml-schemas/invalid-schema-1.0.0/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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.xml-schemas</groupId>
<artifactId>invalid-1_0_0</artifactId>
<version>0</version>
<packaging>pom</packaging>

<description>Verify dirty state is part of project name</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
50 changes: 50 additions & 0 deletions src/it/xml-schemas/invalid-schema-1.0.0/prebuild.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* 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",
"echo A > content",
"git add .",
"git commit --message=initial_commit",
"git tag -a 1.0.0 --message=release_1.0.0",
"echo B > content",
"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
46 changes: 46 additions & 0 deletions src/it/xml-schemas/invalid-schema-1.0.0/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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 )

[
"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 saxException = buildLog.findAll { it =~ /org.xml.sax.SAXParseException.*Invalid content was found starting with element 'doesNotExist'/ }
log.println( "saxException: " + saxException )
assert 0 < saxException.size()

log.println( "Verify completed at: " + new Date() )
log.close()
return true
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void calculateVersionIfNecessary() throws Exception {
.setUseDefaultBranchingPolicy(cfg.useDefaultBranchingPolicy)
.setNonQualifierBranches(cfg.nonQualifierBranches);

if (cfg.branchPolicies != null) {
if (cfg.branchPolicies != null && !cfg.branchPolicies.isEmpty()) {
List<BranchingPolicy> policies = cfg.branchPolicies.stream()
.map(bp -> new BranchingPolicy(bp.pattern, bp.transformations))
.collect(Collectors.toList());
Expand All @@ -135,6 +135,7 @@ private Model provisionModel(Model model, Map<String, ?> options) throws IOExcep
try {
calculateVersionIfNecessary();
} catch (Exception ex) {
logger.error("failure while calculating version", ex);
throw new IOException("cannot build a Model object using jgitver", ex);
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/fr/brouillard/oss/jgitver/cfg/BranchPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class BranchPolicy {
@XmlElement(name = "transformation")
public List<String> transformations = new LinkedList<>(
Arrays.asList(
BranchNameTransformations.REPLACE_UNEXPECTED_CHARS_UNDERSCORE.name(),
BranchNameTransformations.LOWERCASE_EN.name()));
BranchNameTransformations.REPLACE_UNEXPECTED_CHARS_UNDERSCORE.name()
, BranchNameTransformations.LOWERCASE_EN.name())
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ public class Configuration {
public List<String> exclusions = new LinkedList<>();
@XmlElementWrapper(name = "branchPolicies")
@XmlElement(name = "branchPolicy")
public List<BranchPolicy> branchPolicies;
public List<BranchPolicy> branchPolicies = new LinkedList<>();
}
Loading

0 comments on commit de0ace3

Please sign in to comment.