You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm-commits@maven.apache.org by ol...@apache.org on 2011/04/09 10:28:14 UTC
svn commit: r1090542 - in /maven/scm/trunk/maven-scm-plugin/src:
main/java/org/apache/maven/scm/plugin/
test/java/org/apache/maven/scm/plugin/ test/resources/mojos/remove/
Author: olamy
Date: Sat Apr 9 08:28:14 2011
New Revision: 1090542
URL: http://svn.apache.org/viewvc?rev=1090542&view=rev
Log:
[SCM-615] RemoveMojo to allow removing resources from version control.
Submitted by Paul Mackinlay.
Added:
maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/RemoveMojo.java (with props)
maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/RemoveMojoTest.java (with props)
maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/remove/
maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/remove/removeWithPerforce.xml (with props)
maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/remove/removeWithPerforceNoIncludes.xml (with props)
Added: maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/RemoveMojo.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/RemoveMojo.java?rev=1090542&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/RemoveMojo.java (added)
+++ maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/RemoveMojo.java Sat Apr 9 08:28:14 2011
@@ -0,0 +1,60 @@
+package org.apache.maven.scm.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.command.remove.RemoveScmResult;
+import org.apache.maven.scm.repository.ScmRepository;
+
+import java.io.IOException;
+
+/*
+ * 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.
+ */
+
+/**
+ * Mark a set of files for deletion.
+ *
+ * @author <a href="paul@webotech.co.uk">Paul Mackinlay</a>
+ * @goal remove
+ * @aggregator
+ */
+public class RemoveMojo extends AbstractScmMojo {
+
+ /**
+ * The commit message.
+ *
+ * @parameter expression="${message}"
+ */
+ private String message;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void execute() throws MojoExecutionException {
+ super.execute();
+ try {
+ ScmRepository repository = getScmRepository();
+ RemoveScmResult result = getScmManager().remove(repository, getFileSet(), message);
+ checkResult(result);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Cannot run remove command : ", e);
+ } catch (ScmException e) {
+ throw new MojoExecutionException("Cannot run remove command : ", e);
+ }
+ }
+}
Propchange: maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/RemoveMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/RemoveMojo.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/RemoveMojoTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/RemoveMojoTest.java?rev=1090542&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/RemoveMojoTest.java (added)
+++ maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/RemoveMojoTest.java Sat Apr 9 08:28:14 2011
@@ -0,0 +1,84 @@
+package org.apache.maven.scm.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 org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.File;
+
+/**
+ * @author <a href="paul@webotech.co.uk">Paul Mackinlay</a>
+ */
+public class RemoveMojoTest extends AbstractMojoTestCase {
+
+ public void testShouldInvokeP4Delete() throws Exception {
+ String testConfig = "src/test/resources/mojos/remove/removeWithPerforce.xml";
+ try {
+ RemoveMojo removeMojo = (RemoveMojo) lookupMojo("remove", getTestFile(testConfig));
+ String connectionUrl = removeMojo.getConnectionUrl();
+ connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
+ connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
+ removeMojo.setWorkingDirectory(new File(getBasedir()));
+ removeMojo.setConnectionUrl(connectionUrl);
+
+ removeMojo.execute();
+ } finally {
+ // Just to be sure unedit anything that has been marked for delete
+ UnEditMojo unEditMojo = (UnEditMojo) lookupMojo("unedit", getTestFile(testConfig));
+ String connectionUrl = unEditMojo.getConnectionUrl();
+ connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
+ connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
+ unEditMojo.setWorkingDirectory(new File(getBasedir()));
+ unEditMojo.setConnectionUrl(connectionUrl);
+ unEditMojo.execute();
+ }
+ }
+
+ public void testShouldFailToInvokeP4Delete() throws Exception {
+ String testConfig = "src/test/resources/mojos/remove/removeWithPerforceNoIncludes.xml";
+ try {
+ RemoveMojo removeMojo = (RemoveMojo) lookupMojo("remove", getTestFile(testConfig));
+ String connectionUrl = removeMojo.getConnectionUrl();
+ connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
+ connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
+ removeMojo.setWorkingDirectory(new File(getBasedir()));
+ removeMojo.setConnectionUrl(connectionUrl);
+
+ try {
+ removeMojo.execute();
+ fail("At least one file needs to be included for removal");
+ } catch (MojoExecutionException e) {
+ // we're expecting this exception
+ }
+ } finally {
+ // Just to be sure unedit anything that has been marked for delete
+ UnEditMojo unEditMojo = (UnEditMojo) lookupMojo("unedit", getTestFile(testConfig));
+ String connectionUrl = unEditMojo.getConnectionUrl();
+ connectionUrl = StringUtils.replace(connectionUrl, "${basedir}", getBasedir());
+ connectionUrl = StringUtils.replace(connectionUrl, "\\", "/");
+ unEditMojo.setWorkingDirectory(new File(getBasedir()));
+ unEditMojo.setConnectionUrl(connectionUrl);
+ unEditMojo.execute();
+ }
+ }
+
+}
Propchange: maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/RemoveMojoTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/RemoveMojoTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/remove/removeWithPerforce.xml
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/remove/removeWithPerforce.xml?rev=1090542&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/remove/removeWithPerforce.xml (added)
+++ maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/remove/removeWithPerforce.xml Sat Apr 9 08:28:14 2011
@@ -0,0 +1,34 @@
+<!--
+ ~ 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>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-scm-plugin</artifactId>
+ <configuration>
+ <settings implementation="org.apache.maven.settings.Settings"/>
+ <connectionType>connection</connectionType>
+ <connectionUrl>scm:perforce:///${basedir}/target/repository/trunk</connectionUrl>
+ <includes>pom.xml</includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Propchange: maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/remove/removeWithPerforce.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/remove/removeWithPerforce.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/remove/removeWithPerforceNoIncludes.xml
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/remove/removeWithPerforceNoIncludes.xml?rev=1090542&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/remove/removeWithPerforceNoIncludes.xml (added)
+++ maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/remove/removeWithPerforceNoIncludes.xml Sat Apr 9 08:28:14 2011
@@ -0,0 +1,33 @@
+<!--
+ ~ 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>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-scm-plugin</artifactId>
+ <configuration>
+ <settings implementation="org.apache.maven.settings.Settings"/>
+ <connectionType>connection</connectionType>
+ <connectionUrl>scm:perforce:///${basedir}/target/repository/trunk</connectionUrl>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Propchange: maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/remove/removeWithPerforceNoIncludes.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/remove/removeWithPerforceNoIncludes.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision