Skip to content

Commit

Permalink
enable plugin for standard project (non multi modules), prepare for 0…
Browse files Browse the repository at this point in the history
….0.1 release
  • Loading branch information
McFoggy committed Apr 27, 2016
1 parent 4011deb commit 6761ccd
Show file tree
Hide file tree
Showing 8 changed files with 299 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
target/
.classpath
.project
.checkstyle
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ cat > pom.xml << EOF
<version>0</version>
<packaging>pom</packaging>
<build>
<extensions>
<extension>
<plugins>
<plugin>
<groupId>fr.brouillard.oss</groupId>
<artifactId>jgitver-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
</extension>
</extensions>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
EOF
Expand All @@ -31,7 +32,6 @@ git add content
git commit -m "initial commit"
echo B > content && git add -u && git commit -m "added B data"
git tag 1.0 -m "release 1.0"
git tag 2.0
echo C > content && git add -u && git commit -m "added C data"
git checkout -b cool-feature
echo D > content && git add -u && git commit -m "added D data"
Expand Down
109 changes: 104 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<groupId>fr.brouillard.oss</groupId>
<artifactId>jgitver-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1</version>
<packaging>maven-plugin</packaging>

<name>jgitver Maven Plugin</name>
Expand Down Expand Up @@ -119,7 +119,7 @@
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>1.5.5</version>
<version>1.6</version>
<executions>
<execution>
<goals>
Expand All @@ -133,7 +133,8 @@
<artifactId>maven-plugin-plugin</artifactId>
<version>3.4</version>
<configuration>
<goalPrefix>jgitver-maven-plugin</goalPrefix>
<goalPrefix>jgitver</goalPrefix>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -233,7 +234,6 @@
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<checkstyle.suppressions.file></checkstyle.suppressions.file>
</configuration>
<goals>
<goal>check</goal>
Expand Down Expand Up @@ -302,7 +302,6 @@
<profile>
<id>run-its</id>
<build>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -336,5 +335,105 @@
</plugins>
</build>
</profile>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-no-snapshots</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireReleaseDeps />
<requireReleaseVersion />
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>oss</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<!-- instructions from https://maven.apache.org/plugins/maven-gpg-plugin/usage.html -->
<keyname>${gpg.keyname}</keyname>
<passphraseServerId>${gpg.keyname}</passphraseServerId>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
</profiles>
</project>
62 changes: 51 additions & 11 deletions src/main/java/fr/brouillard/oss/jgitver/GAV.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,60 @@

import org.apache.maven.project.MavenProject;

public class GAV {
/**
* Wrapper for a maven project/dependency identified by a groupId/artifactId/version.
*/
public class GAV { // SUPPRESS CHECKSTYLE AbbreviationAsWordInName
private String groupId;
private String artifactId;
private String version;

/**
* Builds an immutable GAV object.
*
* @param groupId the groupId of the maven object
* @param artifactId the artifactId of the maven object
* @param version the version of the maven object
*/
public GAV(String groupId, String artifactId, String version) {
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
}

/**
* Retrieves the groupId.
*
* @return the groupId
*/
public String getGroupId() {
return groupId;
}

/**
* Retrieves the artifactId.
*
* @return the artifactId
*/
public String getArtifactId() {
return artifactId;
}

/**
* Retrieves the version.
*
* @return the version
*/
public String getVersion() {
return version;
}


/**
* Builds a GAV object from the given MavenProject object.
*
* @param project the project to extract info from
* @return a new GAV object
*/
public static GAV from(MavenProject project) {
return new GAV(project.getGroupId(), project.getArtifactId(), project.getVersion());
}
Expand All @@ -56,28 +87,37 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
GAV other = (GAV) obj;
if (artifactId == null) {
if (other.artifactId != null)
if (other.artifactId != null) {
return false;
} else if (!artifactId.equals(other.artifactId))
}
} else if (!artifactId.equals(other.artifactId)) {
return false;
}
if (groupId == null) {
if (other.groupId != null)
if (other.groupId != null) {
return false;
} else if (!groupId.equals(other.groupId))
}
} else if (!groupId.equals(other.groupId)) {
return false;
}
if (version == null) {
if (other.version != null)
if (other.version != null) {
return false;
} else if (!version.equals(other.version))
}
} else if (!version.equals(other.version)) {
return false;
}
return true;
}
}
40 changes: 27 additions & 13 deletions src/main/java/fr/brouillard/oss/jgitver/JGitverExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,56 @@
import org.apache.maven.AbstractMavenLifecycleParticipant;
import org.apache.maven.MavenExecutionException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.xml.Xpp3Dom;

@Component( role = AbstractMavenLifecycleParticipant.class, hint = "jgitver" )
@Component(role = AbstractMavenLifecycleParticipant.class, hint = "jgitver")
public class JGitverExtension extends AbstractMavenLifecycleParticipant {
@Requirement
private Logger logger;


@Requirement
private PlexusContainer container;

@Override
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
logger.info("jgitver-maven-plugin is about to change project version");

MavenProject rootProject = session.getTopLevelProject();

String newVersion = calculateVersionForProject(rootProject);
rootProject.setVersion(newVersion);
}

private String calculateVersionForProject(MavenProject rootProject) {
private String calculateVersionForProject(MavenProject rootProject) throws MavenExecutionException {
GitVersionCalculator gvc = null;

try {
gvc = GitVersionCalculator.location(rootProject.getBasedir());
return gvc.setAutoIncrementPatch(true)
.setUseDistance(true)
.setUseGitCommitId(false)
.getVersion();
gvc = GitVersionCalculator.location(rootProject.getBasedir());

Plugin plugin = rootProject.getPlugin("fr.brouillard.oss:jgitver-maven-plugin");
Xpp3Dom pluginConfigNode = (Xpp3Dom) plugin.getConfiguration();
JGitverPluginConfiguration pluginConfig = new JGitverPluginConfiguration(pluginConfigNode);

gvc.setAutoIncrementPatch(pluginConfig.autoIncrementPatch())
.setUseDistance(pluginConfig.useCommitDistance())
.setUseGitCommitId(pluginConfig.useGitCommitId())
.setGitCommitIdLength(pluginConfig.gitCommitIdLength())
.setNonQualifierBranches(pluginConfig.nonQualifierBranches());

return gvc.getVersion();
} finally {
if (gvc != null) {
try {
gvc.close();
} catch (Exception e) {
} catch (Exception ex) {
logger.warn("could not close jgitver delegate properly");
logger.debug("GitVersionCalculator#close() sent an error", e);
logger.debug("GitVersionCalculator#close() sent an error", ex);
}
}
}
Expand Down
Loading

0 comments on commit 6761ccd

Please sign in to comment.