/**
*Usage in pon.xml
* <plugin>
* <groupId>test.maven</groupId>
* <artifactId>maven-p4-plugin</artifactId>
* <executions>
* <execution>
* <goals>
* <goal>p4changes</goal>
* </goals>
* <configuration>
* <url>//depot/ABC/2/X/...</url>
* </configuration>
* </execution>
* </executions>
* </plugin>
*
* Goal which touches a timestamp file.
*
* @goal p4changes
*
* @phase process-sources
*/
public class P4RevisionMojo extends AbstractMojo {
private Process p;
private Properties prop;
private MavenProject project;
/**
* @parameter expression="${p4.url}" default-value="./..."
* @required
* @since 1.0
*/
private String suffix;
/**
* @parameter expression="${p4.port}" default-value="${env.P4PORT}"
* @optional
* @since 1.0
*/
private String p4port;
/**
* @parameter expression="${p4.client}" default-value="${env.P4CLIENT}"
* @optional
* @since 1.0
*/
private String p4client;
/**
* @parameter expression="${p4.user}" default-value="${env.P4USER}"
* @optional
* @since 1.0
*/
private String p4user;
/**
* @parameter expression="${p4.passwd}" default-value="${env.P4PASSWD}"
* @optional
* @since 1.0
*/
private String p4passwd;
public void execute() throws MojoExecutionException {
try {
String cmd = "p4 changes -m 1 " + url;
this.getLog().info("Executing P4 command: " + cmd);
p = Runtime.getRuntime().exec(cmd);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = stdInput.readLine();
String property = "p4.revision";
if (suffix != null && suffix.length() > 0) {
property = property.concat("." + suffix);
}
prop.setProperty("buildtstamp", new Date().toString());
prop.setProperty(property, "000000");
while (line != null) {
String[] line_items = line.split(" ");
if (line_items.length >= 1) {
if (line_items[0].equalsIgnoreCase("Change")) {
prop.setProperty(property, line_items[1]);
this.getLog().info("P4 Revision ${" + property + "} :::: " + prop.getProperty(property));
}
}
return;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}