You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2014/08/04 08:32:33 UTC

svn commit: r1615490 - in /oodt/trunk/protocol/api/src/main: java/org/apache/oodt/cas/protocol/cli/action/DeleteEmptyDirectoriesCliAction.java resources/policy/cmd-line-actions.xml resources/policy/cmd-line-options.xml

Author: bfoster
Date: Mon Aug  4 06:32:32 2014
New Revision: 1615490

URL: http://svn.apache.org/r1615490
Log:
- Add new action for deleting empty directories from sites.

---------
OODT-730

Added:
    oodt/trunk/protocol/api/src/main/java/org/apache/oodt/cas/protocol/cli/action/DeleteEmptyDirectoriesCliAction.java   (with props)
Modified:
    oodt/trunk/protocol/api/src/main/resources/policy/cmd-line-actions.xml
    oodt/trunk/protocol/api/src/main/resources/policy/cmd-line-options.xml

Added: oodt/trunk/protocol/api/src/main/java/org/apache/oodt/cas/protocol/cli/action/DeleteEmptyDirectoriesCliAction.java
URL: http://svn.apache.org/viewvc/oodt/trunk/protocol/api/src/main/java/org/apache/oodt/cas/protocol/cli/action/DeleteEmptyDirectoriesCliAction.java?rev=1615490&view=auto
==============================================================================
--- oodt/trunk/protocol/api/src/main/java/org/apache/oodt/cas/protocol/cli/action/DeleteEmptyDirectoriesCliAction.java (added)
+++ oodt/trunk/protocol/api/src/main/java/org/apache/oodt/cas/protocol/cli/action/DeleteEmptyDirectoriesCliAction.java Mon Aug  4 06:32:32 2014
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+package org.apache.oodt.cas.protocol.cli.action;
+
+// JDK imports
+import java.util.List;
+import java.util.regex.Pattern;
+
+// OODT imports
+import org.apache.oodt.cas.cli.exception.CmdLineActionException;
+import org.apache.oodt.cas.protocol.Protocol;
+import org.apache.oodt.cas.protocol.ProtocolFile;
+
+/**
+ * {@link ProtocolAction} for deleting empty files from site.
+ * 
+ * @author bfoster (Brian Foster)
+ */
+public class DeleteEmptyDirectoriesCliAction extends ProtocolCliAction {
+
+  private String directoryRegex = ".+";
+
+  @Override
+  public void execute(ActionMessagePrinter arg0) throws CmdLineActionException {
+    try {
+      Protocol protocol = getProtocolManager().getProtocolBySite(getSite(), getAuthentication(), null);
+      List<ProtocolFile> files = protocol.ls();
+      for (ProtocolFile file : files) {
+        if (file.isDir() && Pattern.matches(directoryRegex, file.getName())) {
+          protocol.delete(file);
+        }
+      }
+    } catch (Exception e) {
+      throw new CmdLineActionException("Failed to delete directories", e);
+    }
+  }
+
+  public void setDirectoryRegex(String directoryRegex) {
+    this.directoryRegex = directoryRegex;
+  }
+}

Propchange: oodt/trunk/protocol/api/src/main/java/org/apache/oodt/cas/protocol/cli/action/DeleteEmptyDirectoriesCliAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: oodt/trunk/protocol/api/src/main/resources/policy/cmd-line-actions.xml
URL: http://svn.apache.org/viewvc/oodt/trunk/protocol/api/src/main/resources/policy/cmd-line-actions.xml?rev=1615490&r1=1615489&r2=1615490&view=diff
==============================================================================
--- oodt/trunk/protocol/api/src/main/resources/policy/cmd-line-actions.xml (original)
+++ oodt/trunk/protocol/api/src/main/resources/policy/cmd-line-actions.xml Mon Aug  4 06:32:32 2014
@@ -23,16 +23,20 @@
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
 	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 
-	<bean id="download" class="org.apache.oodt.cas.protocol.cli.action.DownloadCliAction">
+	<bean id="Download" class="org.apache.oodt.cas.protocol.cli.action.DownloadCliAction">
 		<property name="description" value="Downloads a file" />
 	</bean>
-	<bean id="getSupportedFactories" class="org.apache.oodt.cas.protocol.cli.action.GetSupportedFactoriesCliAction">
+	<bean id="GetSupportedFactories" class="org.apache.oodt.cas.protocol.cli.action.GetSupportedFactoriesCliAction">
 		<property name="description" value="Prints out list of supported ProtocolFactory(s)" />
 	</bean>
-	<bean id="crossProtocolTransfer" class="org.apache.oodt.cas.protocol.cli.action.CrossProtocolTransferCliAction">
+	<bean id="CrossProtocolTransfer" class="org.apache.oodt.cas.protocol.cli.action.CrossProtocolTransferCliAction">
 		<property name="description" value="Transfers a file across 2 different protocols" />
 		<property name="verifierFactory" ref="BasicVerifier" />
 	</bean>
+	<bean id="DeleteEmptyDirectories" class="org.apache.oodt.cas.protocol.cli.action.DeleteEmptyDirectoriesCliAction">
+		<property name="description" value="Deletes empty directories from a given site" />
+		<property name="verifierFactory" ref="BasicVerifier" />
+	</bean>
 
 	<bean id="BasicVerifier" class="org.apache.oodt.cas.protocol.verify.BasicProtocolVerifierFactory" />
 </beans>

Modified: oodt/trunk/protocol/api/src/main/resources/policy/cmd-line-options.xml
URL: http://svn.apache.org/viewvc/oodt/trunk/protocol/api/src/main/resources/policy/cmd-line-options.xml?rev=1615490&r1=1615489&r2=1615490&view=diff
==============================================================================
--- oodt/trunk/protocol/api/src/main/resources/policy/cmd-line-options.xml (original)
+++ oodt/trunk/protocol/api/src/main/resources/policy/cmd-line-options.xml Mon Aug  4 06:32:32 2014
@@ -29,7 +29,7 @@
     <property name="requirementRules">
       <list>
         <bean class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
-          p:actionName="download" p:relation="OPTIONAL" />
+          p:actionName="Download" p:relation="OPTIONAL" />
       </list>
     </property>
     <property name="handler">
@@ -37,7 +37,7 @@
         <property name="applyToActions">
           <list>
             <bean class="org.apache.oodt.cas.cli.option.handler.ApplyToAction"
-              p:actionName="download" />
+              p:actionName="Download" />
           </list>
         </property>
       </bean>
@@ -53,7 +53,7 @@
     <property name="requirementRules">
       <list>
         <bean class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
-          p:actionName="download" p:relation="OPTIONAL" />
+          p:actionName="Download" p:relation="OPTIONAL" />
       </list>
     </property>
     <property name="handler">
@@ -61,7 +61,7 @@
         <property name="applyToActions">
           <list>
             <bean class="org.apache.oodt.cas.cli.option.handler.ApplyToAction"
-              p:actionName="download" />
+              p:actionName="Download" />
           </list>
         </property>
       </bean>
@@ -77,7 +77,7 @@
     <property name="requirementRules">
       <list>
         <bean class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
-          p:actionName="download" p:relation="REQUIRED" />
+          p:actionName="Download" p:relation="REQUIRED" />
       </list>
     </property>
     <property name="handler">
@@ -85,7 +85,7 @@
         <property name="applyToActions">
           <list>
             <bean class="org.apache.oodt.cas.cli.option.handler.ApplyToAction"
-              p:actionName="download" />
+              p:actionName="Download" />
           </list>
         </property>
       </bean>
@@ -101,7 +101,7 @@
     <property name="requirementRules">
       <list>
         <bean class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
-          p:actionName="crossProtocolTransfer" p:relation="REQUIRED" />
+          p:actionName="CrossProtocolTransfer" p:relation="REQUIRED" />
       </list>
     </property>
     <property name="handler">
@@ -125,7 +125,7 @@
     <property name="requirementRules">
       <list>
         <bean class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
-          p:actionName="crossProtocolTransfer" p:relation="REQUIRED" />
+          p:actionName="CrossProtocolTransfer" p:relation="REQUIRED" />
       </list>
     </property>
     <property name="handler">
@@ -139,4 +139,28 @@
       </bean>
     </property>
 	</bean>
+
+	<bean id="directoriesRegex" class="org.apache.oodt.cas.cli.option.AdvancedCmdLineOption">
+		<property name="shortOption" value="dr" />
+		<property name="longOption" value="dirsRegex" />
+		<property name="description" value="Directory regex of directories to delete" />
+		<property name="hasArgs" value="true" />
+		<property name="argsDescription" value="URL" />
+	    <property name="requirementRules">
+	      <list>
+	        <bean class="org.apache.oodt.cas.cli.option.require.ActionDependencyRule"
+	          p:actionName="DeleteEmptyDirectories" p:relation="REQUIRED" />
+	      </list>
+	    </property>
+	    <property name="handler">
+	      <bean class="org.apache.oodt.cas.cli.option.handler.ApplyToActionHandler">
+	        <property name="applyToActions">
+	          <list>
+	            <bean class="org.apache.oodt.cas.cli.option.handler.ApplyToAction"
+	              p:actionName="DeleteEmptyDirectories" p:methodName="setDirectoryRegex" />
+	          </list>
+	        </property>
+	      </bean>
+	    </property>
+	</bean>
 </beans>