2.0<\/version>/ }.size()
35 |
36 | return true
37 |
--------------------------------------------------------------------------------
/src/it/xml-schemas/invalid-schema-1.0.0/.gitignore:
--------------------------------------------------------------------------------
1 | prebuild.log
2 | build.log
--------------------------------------------------------------------------------
/src/it/xml-schemas/invalid-schema-1.0.0/.mvn/extensions.xml:
--------------------------------------------------------------------------------
1 |
18 |
20 |
21 | @project.groupId@
22 | @project.artifactId@
23 | @project.version@
24 |
25 |
--------------------------------------------------------------------------------
/src/it/xml-schemas/invalid-schema-1.0.0/.mvn/jgitver.config.xml:
--------------------------------------------------------------------------------
1 |
18 |
21 |
22 |
--------------------------------------------------------------------------------
/src/it/xml-schemas/invalid-schema-1.0.0/invoker.properties:
--------------------------------------------------------------------------------
1 | invoker.buildResult = failure
2 | invoker.goals = -X install
3 |
--------------------------------------------------------------------------------
/src/it/xml-schemas/invalid-schema-1.0.0/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 | 4.0.0
21 |
22 | fr.brouillard.oss.it.xml-schemas
23 | invalid-1_0_0
24 | 0
25 | pom
26 |
27 | Verify dirty state is part of project name
28 |
29 |
30 | UTF-8
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/main/java/fr/brouillard/oss/jgitver/JGitverConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package fr.brouillard.oss.jgitver;
17 |
18 | import fr.brouillard.oss.jgitver.cfg.Configuration;
19 | import java.io.File;
20 | import java.io.IOException;
21 | import org.apache.maven.MavenExecutionException;
22 |
23 | public interface JGitverConfiguration {
24 | public Configuration getConfiguration() throws MavenExecutionException;
25 |
26 | boolean ignore(File pomFile) throws IOException;
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/fr/brouillard/oss/jgitver/JGitverGuiceModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package fr.brouillard.oss.jgitver;
17 |
18 | import com.google.inject.AbstractModule;
19 |
20 | /**
21 | * Guice binding for {@link fr.brouillard.oss.jgitver.JGitverConfiguration}.
22 | *
23 | * Without a guice binding looking up the ProjectBuilder on other plugins will throw an exception
24 | * trying to load {@link fr.brouillard.oss.jgitver.JGitverConfiguration} (only started on maven
25 | * 3.6.3).
26 | */
27 | public class JGitverGuiceModule extends AbstractModule {
28 | @Override
29 | protected void configure() {
30 | bind(JGitverConfiguration.class).to(JGitverConfigurationComponent.class);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/fr/brouillard/oss/jgitver/JGitverInformationProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package fr.brouillard.oss.jgitver;
17 |
18 | import fr.brouillard.oss.jgitver.metadata.MetadataProvider;
19 |
20 | public interface JGitverInformationProvider extends MetadataProvider {
21 | default String getVersion() {
22 | return getVersionObject().toString();
23 | }
24 |
25 | Version getVersionObject();
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/fr/brouillard/oss/jgitver/JGitverMavenPluginProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package fr.brouillard.oss.jgitver;
17 |
18 | import java.io.IOException;
19 | import java.io.InputStream;
20 | import java.util.Properties;
21 |
22 | public class JGitverMavenPluginProperties {
23 | static Properties p = new Properties();
24 |
25 | static {
26 | try {
27 | InputStream is =
28 | JGitverMavenPluginProperties.class.getResourceAsStream(
29 | "/META-INF/jgitver-maven-plugin-project.properties");
30 | if (is != null) {
31 | p.load(is);
32 | }
33 | } catch (IOException e) {
34 | // ignore
35 | }
36 | }
37 |
38 | public static String getVersion() {
39 | return p.getProperty("version", "Unknown");
40 | }
41 |
42 | public static String getSHA1() {
43 | return p.getProperty("sha1", "not git sha1");
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/fr/brouillard/oss/jgitver/JGitverSessionHolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package fr.brouillard.oss.jgitver;
17 |
18 | import java.util.Optional;
19 | import org.codehaus.plexus.component.annotations.Component;
20 |
21 | @Component(role = JGitverSessionHolder.class, instantiationStrategy = "singleton")
22 | public class JGitverSessionHolder {
23 | private JGitverSession session = null;
24 |
25 | public void setSession(JGitverSession session) {
26 | this.session = session;
27 | }
28 |
29 | public Optional session() {
30 | return Optional.ofNullable(session);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/fr/brouillard/oss/jgitver/Providers.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package fr.brouillard.oss.jgitver;
17 |
18 | import fr.brouillard.oss.jgitver.metadata.Metadatas;
19 | import java.util.Optional;
20 |
21 | public class Providers {
22 | private Providers() {}
23 |
24 | public static JGitverInformationProvider decorate(final GitVersionCalculator calculator) {
25 | return new JGitverInformationProvider() {
26 | @Override
27 | public Version getVersionObject() {
28 | return calculator.getVersionObject();
29 | }
30 |
31 | @Override
32 | public Optional meta(Metadatas meta) {
33 | return calculator.meta(meta);
34 | }
35 | };
36 | }
37 |
38 | public static JGitverInformationProvider fixVersion(
39 | final String version, final JGitverInformationProvider provider) {
40 | return new JGitverInformationProvider() {
41 | final Version fixed = Version.parse(version);
42 |
43 | @Override
44 | public Version getVersionObject() {
45 | return fixed;
46 | }
47 |
48 | @Override
49 | public Optional meta(Metadatas meta) {
50 | return provider.meta(meta);
51 | }
52 | };
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/fr/brouillard/oss/jgitver/cfg/BranchPolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package fr.brouillard.oss.jgitver.cfg;
17 |
18 | import fr.brouillard.oss.jgitver.BranchingPolicy.BranchNameTransformations;
19 | import java.util.Arrays;
20 | import java.util.LinkedList;
21 | import java.util.List;
22 | import javax.xml.bind.annotation.*;
23 | import org.simpleframework.xml.Root;
24 | import org.simpleframework.xml.convert.Convert;
25 |
26 | @XmlRootElement
27 | @XmlAccessorType(XmlAccessType.FIELD)
28 | @Root
29 | @Convert(SimpleBranchPolicyConverter.class)
30 | public class BranchPolicy {
31 | @XmlElement(name = "pattern")
32 | public String pattern;
33 |
34 | @XmlElementWrapper(name = "transformations")
35 | @XmlElement(name = "transformation")
36 | public List transformations =
37 | new LinkedList<>(
38 | Arrays.asList(
39 | BranchNameTransformations.REPLACE_UNEXPECTED_CHARS_UNDERSCORE.name(),
40 | BranchNameTransformations.LOWERCASE_EN.name()));
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/resources-filtered/META-INF/jgitver-maven-plugin-project.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | version=${jgitver.calculated_version}
18 | dirty=${jgitver.dirty}
19 | sha1=${jgitver.git_sha1_full}
20 | branch=${jgitver.branch_name}
--------------------------------------------------------------------------------
/src/quality/checkstyle/suppressions.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/test/java/fr/brouillard/oss/jgitver/GitVersionCalculatorProxyTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package fr.brouillard.oss.jgitver;
17 |
18 | import static org.hamcrest.CoreMatchers.is;
19 | import static org.hamcrest.CoreMatchers.not;
20 | import static org.junit.Assert.assertThat;
21 |
22 | import fr.brouillard.oss.jgitver.metadata.Metadatas;
23 | import java.io.File;
24 | import org.junit.Test;
25 |
26 | public class GitVersionCalculatorProxyTest {
27 | @Test
28 | public void can_proxy_calls() throws Exception {
29 | String expectedVersion = "1.0.0";
30 | File basedir = new File(System.getProperty("user.dir"));
31 |
32 | try (GitVersionCalculator gvc = GitVersionCalculator.location(basedir)) {
33 | JGitverInformationProvider infoProvider =
34 | Providers.fixVersion(expectedVersion, Providers.decorate(gvc));
35 | assertThat(expectedVersion, is(infoProvider.getVersion()));
36 | assertThat(expectedVersion, not(is(infoProvider.meta(Metadatas.CALCULATED_VERSION).get())));
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/test/resources/config/complex-branch.cfg.xml:
--------------------------------------------------------------------------------
1 |
2 | false
3 |
4 |
5 | (master)
6 |
7 | IGNORE
8 |
9 |
10 |
11 | (.*)
12 |
13 | REMOVE_UNEXPECTED_CHARS
14 | UPPERCASE_EN
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/test/resources/config/invalid-with-schema.xml:
--------------------------------------------------------------------------------
1 |
18 |
21 |
22 |
--------------------------------------------------------------------------------
/src/test/resources/config/simple.cfg.with.schema.xml:
--------------------------------------------------------------------------------
1 |
4 | false
5 | true
6 |
--------------------------------------------------------------------------------
/src/test/resources/config/simple.cfg.xml:
--------------------------------------------------------------------------------
1 |
2 | false
3 | true
4 |
--------------------------------------------------------------------------------
/travis-set-branch.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | #
17 |
18 | set -ev
19 |
20 | if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
21 | # this is not a pull request build
22 |
23 | # even knowing https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash
24 | # we test for existence or emptiness
25 | if [ -z "$TRAVIS_TAG"]; then
26 | # normal build on a branch
27 | echo "branch build detected, adjusting 'git checkout' local branch to git commit SHA1"
28 | git checkout $TRAVIS_BRANCH
29 | git reset --hard $TRAVIS_COMMIT
30 | else
31 | # tag build
32 | echo "tag build detected, keeping travis defaults for 'git checkout'"
33 | fi;
34 |
35 | else
36 | # this is a pull request build
37 | echo "PR build detected, adjusting 'git checkout' to a local PR branch "
38 | git checkout -b PR$TRAVIS_PULL_REQUEST
39 | fi;
40 |
41 | echo "asked to build: $TRAVIS_COMMIT"
42 | git status
43 | git log --oneline -n 1
44 |
--------------------------------------------------------------------------------