Obsolete since replacement of Maven by Gradle build script

pull/442/head
reger24 3 years ago
parent c94b9b8197
commit d411566c45

@ -1,4 +0,0 @@
/target/
/.classpath
/.project
/.settings/

@ -1,137 +0,0 @@
<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>net.yacy</groupId>
<artifactId>maven-plugin-gitrevisionnumber</artifactId>
<version>1.1</version>
<packaging>maven-plugin</packaging>
<name>YaCy - Build Number Maven Plugin</name>
<description>This plugin gives you a Git repository release number. in the format 9000 as maven property "releaseNr" and a Git repository timestamp as Maven property "DSTAMP" in the format yyyymmdd </description>
<url>http://www.yacy.net</url>
<scm>
<connection>scm:git:https://github.com/yacy/yacy_search_server.git</connection>
<url>https://github.com/yacy/yacy_search_server</url>
</scm>
<developers>
<developer>
<name>Michael Peter Christen</name>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>1</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<shortRevisionLength>5</shortRevisionLength>
<revisionOnScmFailure>9000</revisionOnScmFailure>
<!-- creates a string e.g. 20130131-1fd45 -->
<format>{0,date,yyyyMMdd}-{1}</format>
<items>
<item>timestamp</item>
<item>scmVersion</item>
</items>
</configuration>
</plugin>
<!-- exec:exec goal to provide start YaCy by Maven (just to have it for cases were the ide not provides a run command) -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<classpathScope>runtime</classpathScope>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<!-- see http://jira.codehaus.org/browse/MNG-5346 -->
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
<!-- if you want to generate help goal -->
<!-- <execution> <id>help-goal</id> <goals> <goal>helpmojo</goal> </goals> </execution> -->
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>4.5.0.201609210915-r</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>3.0-alpha-2</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.1.1</version>
</dependency>
</dependencies>
</project>

@ -1,146 +0,0 @@
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
/**
* Maven plugin to create property with YaCy release number,
* a 4 digit number based on commits to the Git repository
*
*/
@Mojo(name = "create", defaultPhase = LifecyclePhase.INITIALIZE)
public class GitRevMavenTask extends AbstractMojo {
@Component
private MavenProject project;
/**
* Name of the buildNumber property
*
* parameter expression="${maven.buildNumber.buildNumberPropertyName}"
* default-value="releaseNr"
*/
@Parameter
private String branchPropertyName = "branch";
@Parameter
private String buildNumberPropertyName = "releaseNr";
@Parameter
private String commitDatePropertyName = "DSTAMP";
Log log = this.getLog();
public void setBuildNumberPropertyName(String revprop) {
this.buildNumberPropertyName = revprop;
}
public void setCommitDatePropertyName(String dateprop) {
this.commitDatePropertyName = dateprop;
}
@Override
public void execute() throws MojoExecutionException {
String branch = null;
String revision = null;
String lastTag = null;
String commitDate = null;
Repository repo = null;
Git git = null;
RevWalk walk = null;
try {
final File src = project.getBasedir(); // set Git root path to project root
repo = new FileRepositoryBuilder().readEnvironment()
.findGitDir(src).build();
branch = repo.getBranch();
branch = "master".equals(branch) ? "" : "_" + branch;
final ObjectId head = repo.resolve("HEAD");
git = new Git(repo);
final List<Ref> tags = git.tagList().call();
walk = new RevWalk(repo);
final RevCommit headCommit = walk.parseCommit(head);
final SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
commitDate = df.format(headCommit.getAuthorIdent().getWhen());
walk.markStart(headCommit);
int distance = 0;
/* Peel known tags */
final List<Ref> peeledTags = new ArrayList<>();
for (final Ref tag : tags) {
peeledTags.add(repo.peel(tag));
}
/* Look for the last tag commit and calculate distance with the HEAD commit */
for (final RevCommit commit : walk) {
for (final Ref tag : peeledTags) {
if (commit.equals(tag.getPeeledObjectId()) || commit.equals(tag.getObjectId())) {
lastTag = commit.getShortMessage();
break;
}
}
if (lastTag != null || distance++ > 90999) {
break;
}
}
walk.dispose();
if (lastTag == null) {
revision = "0000";
} else {
revision = Integer.toString(distance + 9000);
}
} catch (final IOException e) {
e.printStackTrace();
} catch (GitAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
/* In all cases, properly release resources */
if(walk != null) {
walk.close();
}
if(git != null) {
git.close();
}
if(repo != null) {
repo.close();
}
}
if (project != null) {
project.getProperties().put(this.branchPropertyName, branch);
log.info("GitrevMavenTask: set property " + this.branchPropertyName + "='" + branch + "'");
project.getProperties().put(this.buildNumberPropertyName, revision);
log.info("GitrevMavenTask: set property " + this.buildNumberPropertyName + "=" + revision);
project.getProperties().put(this.commitDatePropertyName, commitDate);
log.info("GitrevMavenTask: set property " + this.commitDatePropertyName + "=" + commitDate);
} else {
log.error("GitrevMavenTask: no Maven project");
System.out.println(this.branchPropertyName + "=" + branch);
System.out.println(this.buildNumberPropertyName + "=" + revision);
System.out.println(this.commitDatePropertyName + "=" + commitDate);
}
}
}
Loading…
Cancel
Save