Author: rfeng
Date: Mon Dec 10 13:35:17 2007
New Revision: 603058
URL: http://svn.apache.org/viewvc?rev=603058&view=rev
Log:
Integrate with maven scm status to check for changes
Added:
incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/AbstractScmMojo.java
(with props)
Modified:
incubator/tuscany/java/sca/tools/maven/maven-incremental-build/pom.xml
incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/IncrementalBuildMojo.java
Modified: incubator/tuscany/java/sca/tools/maven/maven-incremental-build/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tools/maven/maven-incremental-build/pom.xml?rev=603058&r1=603057&r2=603058&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tools/maven/maven-incremental-build/pom.xml
(original)
+++ incubator/tuscany/java/sca/tools/maven/maven-incremental-build/pom.xml Mon
Dec 10 13:35:17 2007
@@ -1,21 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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>
<modelVersion>4.0.0</modelVersion>
@@ -35,42 +35,60 @@
<artifactId>maven-plugin-api</artifactId>
<version>2.0.5</version>
</dependency>
-
+
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0.5</version>
</dependency>
-
+
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings</artifactId>
<version>2.0.5</version>
</dependency>
-
+
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0.5</version>
</dependency>
-
+
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>2.0.5</version>
</dependency>
-
+
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.0.5</version>
</dependency>
-
+
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>2.0.5</version>
</dependency>
-
+
+ <dependency>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-manager-plexus</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-provider-svnexe</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-provider-local</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+
+
</dependencies>
</project>
Added:
incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/AbstractScmMojo.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/AbstractScmMojo.java?rev=603058&view=auto
==============================================================================
---
incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/AbstractScmMojo.java
(added)
+++
incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/AbstractScmMojo.java
Mon Dec 10 13:35:17 2007
@@ -0,0 +1,388 @@
+package org.apache.tuscany.sca.tools.incremental.build.plugin;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.scm.ScmBranch;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmResult;
+import org.apache.maven.scm.ScmRevision;
+import org.apache.maven.scm.ScmTag;
+import org.apache.maven.scm.ScmVersion;
+import org.apache.maven.scm.manager.ScmManager;
+import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost;
+import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.maven.scm.repository.ScmRepositoryException;
+import org.apache.maven.settings.Server;
+import org.apache.maven.settings.Settings;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * @version $Id: AbstractScmMojo.java 540597 2007-05-22 14:32:28Z evenisse $
+ */
+public abstract class AbstractScmMojo extends AbstractMojo {
+ /**
+ * The SCM connection URL.
+ *
+ * @parameter expression="${connectionUrl}"
default-value="${project.scm.connection}"
+ */
+ private String connectionUrl;
+
+ /**
+ * The SCM connection URL for developers.
+ *
+ * @parameter expression="${connectionUrl}"
default-value="${project.scm.developerConnection}"
+ */
+ private String developerConnectionUrl;
+
+ /**
+ * The type of connection to use (connection or developerConnection).
+ *
+ * @parameter expression="${connectionType}" default-value="connection"
+ */
+ private String connectionType;
+
+ /**
+ * The working directory.
+ *
+ * @parameter expression="${workingDirectory}"
+ */
+ private File workingDirectory;
+
+ /**
+ * The user name (used by svn and starteam protocol).
+ *
+ * @parameter expression="${username}"
+ */
+ private String username;
+
+ /**
+ * The user password (used by svn and starteam protocol).
+ *
+ * @parameter expression="${password}"
+ */
+ private String password;
+
+ /**
+ * The private key (used by java svn).
+ *
+ * @parameter expression="${privateKey}"
+ */
+ private String privateKey;
+
+ /**
+ * The passphrase (used by java svn).
+ *
+ * @parameter expression="${passphrase}"
+ */
+ private String passphrase;
+
+ /**
+ * The url of tags base directory (used by svn protocol). It is not
+ * necessary to set it if you use the standard svn layout
+ * (branches/tags/trunk).
+ *
+ * @parameter expression="${tagBase}"
+ */
+ private String tagBase;
+
+ /**
+ * Comma separated list of includes file pattern.
+ *
+ * @parameter expression="${includes}"
+ */
+ private String includes;
+
+ /**
+ * Comma separated list of excludes file pattern.
+ *
+ * @parameter expression="${excludes}"
+ */
+ private String excludes;
+
+ /**
+ * @parameter
expression="${component.org.apache.maven.scm.manager.ScmManager}"
+ * @required
+ * @readonly
+ */
+ private ScmManager manager;
+
+ /**
+ * The base directory.
+ *
+ * @parameter expression="${basedir}"
+ * @required
+ */
+ private File basedir;
+
+ /**
+ * @parameter expression="${settings}"
+ * @required
+ * @readonly
+ */
+ protected Settings settings;
+
+ /**
+ * List of System properties to pass to the JUnit tests.
+ *
+ * @parameter
+ */
+ private Properties systemProperties;
+
+ /**
+ * List of provider implementations.
+ *
+ * @parameter
+ */
+ private Map providerImplementations;
+
+ public void execute() throws MojoExecutionException {
+ if (systemProperties != null) {
+ // Add all system properties configured by the user
+ Iterator iter = systemProperties.keySet().iterator();
+
+ while (iter.hasNext()) {
+ String key = (String)iter.next();
+
+ String value = systemProperties.getProperty(key);
+
+ System.setProperty(key, value);
+ }
+ }
+
+ if (providerImplementations != null) {
+ for (Iterator i = providerImplementations.keySet().iterator();
i.hasNext();) {
+ String providerType = (String)i.next();
+ String providerImplementation =
(String)providerImplementations.get(providerType);
+ getLog().info("Change the default '" + providerType
+ + "' provider implementation to '"
+ + providerImplementation
+ + "'.");
+ getScmManager().setScmProviderImplementation(providerType,
providerImplementation);
+ }
+ }
+ }
+
+ protected void setConnectionType(String connectionType) {
+ this.connectionType = connectionType;
+ }
+
+ public String getConnectionUrl() {
+ boolean requireDeveloperConnection =
!"connection".equals(connectionType.toLowerCase());
+ if (StringUtils.isNotEmpty(connectionUrl) &&
!requireDeveloperConnection) {
+ return connectionUrl;
+ } else if (StringUtils.isNotEmpty(developerConnectionUrl)) {
+ return developerConnectionUrl;
+ }
+ if (requireDeveloperConnection) {
+ throw new NullPointerException("You need to define a
developerConnectionUrl parameter");
+ } else {
+ throw new NullPointerException("You need to define a connectionUrl
parameter");
+ }
+ }
+
+ public void setConnectionUrl(String connectionUrl) {
+ this.connectionUrl = connectionUrl;
+ }
+
+ public File getWorkingDirectory() {
+ if (workingDirectory == null) {
+ return basedir;
+ }
+
+ return workingDirectory;
+ }
+
+ public void setWorkingDirectory(File workingDirectory) {
+ this.workingDirectory = workingDirectory;
+ }
+
+ public ScmManager getScmManager() {
+ return manager;
+ }
+
+ public ScmFileSet getFileSet() throws IOException {
+ if (includes != null || excludes != null) {
+ return new ScmFileSet(getWorkingDirectory(), includes, excludes);
+ } else {
+ return new ScmFileSet(getWorkingDirectory());
+ }
+ }
+
+ public ScmRepository getScmRepository() throws ScmException {
+ ScmRepository repository;
+
+ try {
+ repository = getScmManager().makeScmRepository(getConnectionUrl());
+
+ ScmProviderRepository providerRepo =
repository.getProviderRepository();
+
+ if (!StringUtils.isEmpty(username)) {
+ providerRepo.setUser(username);
+ }
+
+ if (!StringUtils.isEmpty(password)) {
+ providerRepo.setPassword(password);
+ }
+
+ if (repository.getProviderRepository() instanceof
ScmProviderRepositoryWithHost) {
+ ScmProviderRepositoryWithHost repo =
(ScmProviderRepositoryWithHost)repository.getProviderRepository();
+
+ loadInfosFromSettings(repo);
+
+ if (!StringUtils.isEmpty(username)) {
+ repo.setUser(username);
+ }
+
+ if (!StringUtils.isEmpty(password)) {
+ repo.setPassword(password);
+ }
+
+ if (!StringUtils.isEmpty(privateKey)) {
+ repo.setPrivateKey(privateKey);
+ }
+
+ if (!StringUtils.isEmpty(passphrase)) {
+ repo.setPassphrase(passphrase);
+ }
+ }
+
+ if (!StringUtils.isEmpty(tagBase) &&
repository.getProvider().equals("svn")) {
+ SvnScmProviderRepository svnRepo =
(SvnScmProviderRepository)repository.getProviderRepository();
+
+ svnRepo.setTagBase(tagBase);
+ }
+ } catch (ScmRepositoryException e) {
+ if (!e.getValidationMessages().isEmpty()) {
+ for (Iterator i = e.getValidationMessages().iterator();
i.hasNext();) {
+ String message = (String)i.next();
+ getLog().error(message);
+ }
+ }
+
+ throw new ScmException("Can't load the scm provider.", e);
+ } catch (Exception e) {
+ throw new ScmException("Can't load the scm provider.", e);
+ }
+
+ return repository;
+ }
+
+ /**
+ * Load username password from settings if user has not set them in JVM
properties
+ *
+ * @param repo
+ */
+ private void loadInfosFromSettings(ScmProviderRepositoryWithHost repo) {
+ if (username == null || password == null) {
+ String host = repo.getHost();
+
+ int port = repo.getPort();
+
+ if (port > 0) {
+ host += ":" + port;
+ }
+
+ Server server = this.settings.getServer(host);
+
+ if (server != null) {
+ if (username == null) {
+ username = this.settings.getServer(host).getUsername();
+ }
+
+ if (password == null) {
+ password = this.settings.getServer(host).getPassword();
+ }
+
+ if (privateKey == null) {
+ privateKey = this.settings.getServer(host).getPrivateKey();
+ }
+
+ if (passphrase == null) {
+ passphrase = this.settings.getServer(host).getPassphrase();
+ }
+ }
+ }
+ }
+
+ public void checkResult(ScmResult result) throws MojoExecutionException {
+ if (!result.isSuccess()) {
+ getLog().error("Provider message:");
+
+ getLog().error(result.getProviderMessage() == null ? "" :
result.getProviderMessage());
+
+ getLog().error("Command output:");
+
+ getLog().error(result.getCommandOutput() == null ? "" :
result.getCommandOutput());
+
+ throw new MojoExecutionException("Command failed." +
StringUtils.defaultString(result.getProviderMessage()));
+ }
+ }
+
+ public String getIncludes() {
+ return includes;
+ }
+
+ public void setIncludes(String includes) {
+ this.includes = includes;
+ }
+
+ public String getExcludes() {
+ return excludes;
+ }
+
+ public void setExcludes(String excludes) {
+ this.excludes = excludes;
+ }
+
+ public ScmVersion getScmVersion(String versionType, String version) throws
MojoExecutionException {
+ if (StringUtils.isEmpty(versionType) &&
StringUtils.isNotEmpty(version)) {
+ throw new MojoExecutionException("You must specify the version
type.");
+ }
+
+ if (StringUtils.isEmpty(version)) {
+ return null;
+ }
+
+ if ("branch".equals(versionType)) {
+ return new ScmBranch(version);
+ }
+
+ if ("tag".equals(versionType)) {
+ return new ScmTag(version);
+ }
+
+ if ("revision".equals(versionType)) {
+ return new ScmRevision(version);
+ }
+
+ throw new MojoExecutionException("Unknown '" + versionType + "'
version type.");
+ }
+}
Propchange:
incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/AbstractScmMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/AbstractScmMojo.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/IncrementalBuildMojo.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/IncrementalBuildMojo.java?rev=603058&r1=603057&r2=603058&view=diff
==============================================================================
---
incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/IncrementalBuildMojo.java
(original)
+++
incubator/tuscany/java/sca/tools/maven/maven-incremental-build/src/main/java/org/apache/tuscany/sca/tools/incremental/build/plugin/IncrementalBuildMojo.java
Mon Dec 10 13:35:17 2007
@@ -19,22 +19,27 @@
package org.apache.tuscany.sca.tools.incremental.build.plugin;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
-import org.apache.maven.settings.Settings;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.command.status.StatusScmResult;
+import org.apache.maven.scm.repository.ScmRepository;
import org.apache.maven.shared.invoker.DefaultInvocationRequest;
import org.apache.maven.shared.invoker.InvocationRequest;
import org.apache.maven.shared.invoker.InvocationResult;
import org.apache.maven.shared.invoker.Invoker;
import org.apache.maven.shared.invoker.MavenInvocationException;
+import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.cli.CommandLineException;
/**
@@ -44,7 +49,7 @@
* @requiresDependencyResolution test
* @description Incrementally build project modules that depend on modified
modules.
*/
-public class IncrementalBuildMojo extends AbstractMojo {
+public class IncrementalBuildMojo extends AbstractScmMojo {
/**
* The project to create a build for.
*
@@ -68,8 +73,7 @@
* @required
* @readonly
*/
- private Settings settings;
-
+ // private Settings settings;
/**
* Used to invoke Maven builds.
*
@@ -78,6 +82,11 @@
private Invoker invoker;
/**
+ * @parameter expression="${scm}" default-value=true
+ */
+ private boolean scm;
+
+ /**
* Keep track of modified projects.
*/
private static Set<String> modifiedProjectIDs = new HashSet<String>();
@@ -90,7 +99,7 @@
private static String id(MavenProject p) {
return p.getGroupId() + ':' + p.getArtifactId();
}
-
+
/**
* Returns the qualified id of an artifact .
* @param p a Maven artifact
@@ -99,17 +108,30 @@
private static String id(Artifact a) {
return a.getGroupId() + ':' + a.getArtifactId();
}
-
+
public void execute() throws MojoExecutionException {
+ getLog().info("Building " + project.getName() + " [" + project.getId()
+ "]");
+ String type = project.getArtifact().getType();
+ if ("pom".equals(type)) {
+ // project.getModules();
+ // throw new MojoExecutionException("The incremental build cannot
run with a pom module");
+ return;
+ }
String projectID = id(project);
+ boolean changed = false;
// Determine if the project has been modified
- // For now look for a .modified marker file but eventually we
- // should use "svn st" to detect modifications
- String marker = project.getBasedir().getPath()+ "/.modified";
+ String marker = project.getBasedir().getPath() + "/.modified";
if (new File(marker).exists()) {
getLog().info("Project: " + projectID + " has been modified.");
+ changed = true;
modifiedProjectIDs.add(projectID);
+ } else if (scm) {
+ if (!getStatus().getChangedFiles().isEmpty()) {
+ getLog().info("Project: " + projectID + " has been modified.");
+ changed = true;
+ modifiedProjectIDs.add(projectID);
+ }
}
// Check if a project has compile dependencies on the modified projects
@@ -117,57 +139,122 @@
// on the modified projects and needs to be retested
List<String> goals = new ArrayList<String>();
- for (Artifact artifact: (List<Artifact>)project.getCompileArtifacts())
{
- String artifactID = id(artifact);
- if (modifiedProjectIDs.contains(artifactID)) {
- getLog().info("Project " + projectID + " depends on modified
project " + artifactID + " and will be recompiled.");
- goals.add("clean");
- goals.add("install");
- break;
- }
- }
-
- if (goals.isEmpty()) {
- List<Artifact> artifacts = new ArrayList<Artifact>();
- artifacts.addAll(project.getRuntimeArtifacts());
- artifacts.addAll(project.getTestArtifacts());
- for (Artifact artifact: artifacts) {
+ if (changed) {
+ goals.add("clean");
+ goals.add("install");
+ } else {
+ for (Artifact artifact :
(List<Artifact>)project.getCompileArtifacts()) {
String artifactID = id(artifact);
if (modifiedProjectIDs.contains(artifactID)) {
- getLog().info("Project " + projectID + " depends on
modified project " + artifactID + " and will be retested.");
- goals.add("test");
+ getLog().info("Project " + projectID
+ + " depends on modified project "
+ + artifactID
+ + " and will be recompiled.");
+ goals.add("clean");
+ goals.add("install");
break;
}
}
+
+ if (goals.isEmpty()) {
+ List<Artifact> artifacts = new ArrayList<Artifact>();
+ artifacts.addAll(project.getRuntimeArtifacts());
+ artifacts.addAll(project.getTestArtifacts());
+ for (Artifact artifact : artifacts) {
+ String artifactID = id(artifact);
+ if (modifiedProjectIDs.contains(artifactID)) {
+ getLog().info("Project " + projectID
+ + " depends on modified project "
+ + artifactID
+ + " and will be retested.");
+ goals.add("test");
+ break;
+ }
+ }
+ }
}
// Invoke Maven with the necessary goals
if (!goals.isEmpty()) {
InvocationRequest request = new DefaultInvocationRequest();
request.setGoals(goals);
- request.setLocalRepositoryDirectory(new
File(localRepository.getBasedir()));
+ // FIXME: The maven invoker doesn't handle the directory names
with spaces
+ // request.setLocalRepositoryDirectory(new
File(localRepository.getBasedir()));
request.setInteractive(false);
- request.setShowErrors(false);
+ request.setShowErrors(true);
+ // request.setDebug(true);
request.setOffline(settings.isOffline());
request.setBaseDirectory(project.getBasedir());
request.setPomFile(new File(project.getBasedir().getPath() +
"/pom.xml"));
-
+
try {
InvocationResult result = invoker.execute(request);
-
+
CommandLineException cle = result.getExecutionException();
if (cle != null) {
throw new MojoExecutionException(cle.getMessage(), cle);
}
-
+
int ec = result.getExitCode();
if (ec != 0) {
throw new MojoExecutionException("Maven invocation exit
code: " + ec);
}
} catch (MavenInvocationException e) {
+ e.printStackTrace();
throw new MojoExecutionException(e.getMessage(), e);
}
}
}
-}
\ No newline at end of file
+ protected StatusScmResult getStatus() throws MojoExecutionException {
+ try {
+ ScmRepository repository = getScmRepository();
+
+ StatusScmResult result = getScmManager().status(repository,
getFileSet());
+
+ checkResult(result);
+
+ File baseDir = getFileSet().getBasedir();
+
+ // Determine the maximum length of the status column
+ int maxLen = 0;
+
+ for (Iterator iter = result.getChangedFiles().iterator();
iter.hasNext();) {
+ ScmFile file = (ScmFile)iter.next();
+ maxLen = Math.max(maxLen,
file.getStatus().toString().length());
+ }
+
+ for (Iterator iter = result.getChangedFiles().iterator();
iter.hasNext();) {
+ ScmFile file = (ScmFile)iter.next();
+
+ // right align all of the statuses
+ getLog().info(StringUtils.leftPad(file.getStatus().toString(),
maxLen) + " status for "
+ + getRelativePath(baseDir, file.getPath()));
+ }
+ return result;
+ } catch (IOException e) {
+ throw new MojoExecutionException("Cannot run status command : ",
e);
+ } catch (ScmException e) {
+ throw new MojoExecutionException("Cannot run status command : ",
e);
+ }
+ }
+
+ /**
+ * Formats the filename so that it is a relative directory from the base.
+ *
+ * @param baseDir
+ * @param path
+ * @return The relative path
+ */
+ protected String getRelativePath(File baseDir, String path) {
+ if (path.equals(baseDir.getAbsolutePath())) {
+ return ".";
+ } else if (path.indexOf(baseDir.getAbsolutePath()) == 0) {
+ // the + 1 gets rid of a leading file separator
+ return path.substring(baseDir.getAbsolutePath().length() + 1);
+ } else {
+ return path;
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]