continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From car...@apache.org
Subject svn commit: r431955 - in /maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action: AddMavenOneProjectAction.java AddMavenProjectAction.java AddMavenTwoProjectAction.java
Date Wed, 16 Aug 2006 17:25:39 GMT
Author: carlos
Date: Wed Aug 16 10:25:38 2006
New Revision: 431955

URL: http://svn.apache.org/viewvc?rev=431955&view=rev
Log:
Refactor add project actions to remove duplication

Added:
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenProjectAction.java
  (with props)
Modified:
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenOneProjectAction.java
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenTwoProjectAction.java

Modified: maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenOneProjectAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenOneProjectAction.java?rev=431955&r1=431954&r2=431955&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenOneProjectAction.java
(original)
+++ maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenOneProjectAction.java
Wed Aug 16 10:25:38 2006
@@ -1,7 +1,7 @@
 package org.apache.maven.continuum.web.action;
 
 /*
- * Copyright 2004-2005 The Apache Software Foundation.
+ * Copyright 2004-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,15 +17,15 @@
  */
 
 import java.io.File;
-import java.net.MalformedURLException;
-import java.util.Iterator;
 
 import org.apache.maven.continuum.ContinuumException;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
-import org.codehaus.plexus.util.StringUtils;
 
 /**
+ * Add a Maven 1 project to continuum.
+ * 
  * @author Nick Gonzalez
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
  * @version $Id$
  *
  * @plexus.component
@@ -33,93 +33,60 @@
  *   role-hint="addMavenOneProject"
  */
 public class AddMavenOneProjectAction
-    extends ContinuumActionSupport
+    extends AddMavenProjectAction
 {
 
-    private String m1PomUrl;
-
-    private File m1PomFile;
-
-    private String m1Pom = null;
-
-    public String execute()
+    protected ContinuumProjectBuildingResult doExecute( String pomUrl )
         throws ContinuumException
     {
-        if ( !StringUtils.isEmpty( m1PomUrl ) )
-        {
-            m1Pom = m1PomUrl;
-        }
-        else
-        {
-            if ( m1PomFile != null )
-            {
-                try
-                {
-                    m1Pom = m1PomFile.toURL().toString();
-                }
-                catch ( MalformedURLException e )
-                {
-                    // if local file can't be converted to url it's an internal error
-                    throw new RuntimeException( e );
-                }
-            }
-            else
-            {
-                return INPUT;
-            }
-        }
-
-        ContinuumProjectBuildingResult result = null;
-
-        result = continuum.addMavenOneProject( m1Pom );
-
-        if ( result.hasErrors() )
-        {
-            Iterator it = result.getErrors().iterator();
-
-            while ( it.hasNext() )
-            {
-                addActionError( (String) it.next() );
-            }
-
-            return INPUT;
-        }
-
-        return SUCCESS;
-    }
-
-    public String doDefault()
-    {
-        return INPUT;
+        return continuum.addMavenTwoProject( pomUrl );
     }
 
+    /**
+     * @deprecated Use {@link #getPom()} instead
+     */
     public String getM1Pom()
     {
-        return m1Pom;
+        return getPom();
     }
 
+    /**
+     * @deprecated Use {@link #setPom(String)} instead
+     */
     public void setM1Pom( String pom )
     {
-        m1Pom = pom;
+        setPom( pom );
     }
 
+    /**
+     * @deprecated Use {@link #getPomFile()} instead
+     */
     public File getM1PomFile()
     {
-        return m1PomFile;
+        return getPomFile();
     }
 
+    /**
+     * @deprecated Use {@link #setPomFile(File)} instead
+     */
     public void setM1PomFile( File pomFile )
     {
-        m1PomFile = pomFile;
+        setPomFile( pomFile );
     }
 
+    /**
+     * @deprecated Use {@link #getPomUrl()} instead
+     */
     public String getM1PomUrl()
     {
-        return m1PomUrl;
+        return getPomUrl();
     }
 
+    /**
+     * @deprecated Use {@link #setPomUrl(String)} instead
+     */
     public void setM1PomUrl( String pomUrl )
     {
-        m1PomUrl = pomUrl;
+        setPomUrl( pomUrl );
     }
 }

Added: maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenProjectAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenProjectAction.java?rev=431955&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenProjectAction.java
(added)
+++ maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenProjectAction.java
Wed Aug 16 10:25:38 2006
@@ -0,0 +1,134 @@
+package org.apache.maven.continuum.web.action;
+
+/*
+ * Copyright 2004-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.net.MalformedURLException;
+import java.util.Iterator;
+
+import org.apache.maven.continuum.ContinuumException;
+import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Action to add a Maven project to Continuum, either Maven 1 or Maven 2.
+ * 
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public abstract class AddMavenProjectAction
+    extends ContinuumActionSupport
+{
+
+    private static final long serialVersionUID = -3965565189557706469L;
+
+    private String pomUrl;
+
+    private File pomFile;
+
+    private String pom = null;
+
+    public String execute()
+        throws ContinuumException
+    {
+        if ( !StringUtils.isEmpty( pomUrl ) )
+        {
+            pom = pomUrl;
+        }
+        else
+        {
+            if ( pomFile != null )
+            {
+                try
+                {
+                    pom = pomFile.toURL().toString();
+                }
+                catch ( MalformedURLException e )
+                {
+                    // if local file can't be converted to url it's an internal error
+                    throw new RuntimeException( e );
+                }
+            }
+            else
+            {
+                // no url or file was filled
+                addActionError( "add.project.field.required.error" );
+                return INPUT;
+            }
+        }
+
+        ContinuumProjectBuildingResult result = doExecute( pom );
+
+        if ( result.hasErrors() )
+        {
+            Iterator it = result.getErrors().iterator();
+
+            while ( it.hasNext() )
+            {
+                addActionError( (String) it.next() );
+            }
+
+            return INPUT;
+        }
+
+        return SUCCESS;
+    }
+
+    /**
+     * Subclasses must implement this method calling the appropiate operation on the continuum
service.
+     * 
+     * @param pomUrl url of the pom specified by the user
+     * @return result of adding the pom to continuum
+     */
+    protected abstract ContinuumProjectBuildingResult doExecute( String pomUrl )
+        throws ContinuumException;
+
+    public String doDefault()
+    {
+        return INPUT;
+    }
+
+    public String getPom()
+    {
+        return pom;
+    }
+
+    public void setPom( String pom )
+    {
+        this.pom = pom;
+    }
+
+    public File getPomFile()
+    {
+        return pomFile;
+    }
+
+    public void setPomFile( File pomFile )
+    {
+        this.pomFile = pomFile;
+    }
+
+    public String getPomUrl()
+    {
+        return pomUrl;
+    }
+
+    public void setPomUrl( String pomUrl )
+    {
+        this.pomUrl = pomUrl;
+    }
+}

Propchange: maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenProjectAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenProjectAction.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenTwoProjectAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenTwoProjectAction.java?rev=431955&r1=431954&r2=431955&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenTwoProjectAction.java
(original)
+++ maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddMavenTwoProjectAction.java
Wed Aug 16 10:25:38 2006
@@ -1,7 +1,7 @@
 package org.apache.maven.continuum.web.action;
 
 /*
- * Copyright 2004-2005 The Apache Software Foundation.
+ * Copyright 2004-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,16 +16,16 @@
  * limitations under the License.
  */
 
+import java.io.File;
+
 import org.apache.maven.continuum.ContinuumException;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
-import org.codehaus.plexus.util.StringUtils;
-
-import java.io.File;
-import java.net.MalformedURLException;
-import java.util.Iterator;
 
 /**
+ * Add a Maven 2 project to continuum.
+ * 
  * @author Nick Gonzalez
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
  * @version $Id$
  *
  * @plexus.component
@@ -33,61 +33,13 @@
  *   role-hint="addMavenTwoProject"
  */
 public class AddMavenTwoProjectAction
-    extends ContinuumActionSupport
-{    
-
-    private String m2PomUrl;
+    extends AddMavenProjectAction
+{
 
-    private File m2PomFile;
-
-    private String m2Pom = null;
-
-    public String execute()
+    protected ContinuumProjectBuildingResult doExecute( String pomUrl )
         throws ContinuumException
     {
-        if ( !StringUtils.isEmpty( m2PomUrl ) )
-        {
-            m2Pom = m2PomUrl;
-        }
-        else
-        {
-            if ( m2PomFile != null )
-            {
-                try
-                {
-                    m2Pom = m2PomFile.toURL().toString();
-                }
-                catch ( MalformedURLException e )
-                {
-                    // if local file can't be converted to url it's an internal error
-                    throw new RuntimeException( e );
-                }
-            }
-            else
-            {
-                // no url or file was filled
-                // TODO add action error, one must be filled in
-                return INPUT;
-            }
-        }
-
-        ContinuumProjectBuildingResult result = null;
-
-        result = continuum.addMavenTwoProject( m2Pom );
-
-        if ( result.hasErrors() )
-        {
-            Iterator it = result.getErrors().iterator();
-
-            while ( it.hasNext() )
-            {
-                addActionError( (String) it.next() );
-            }
-
-            return INPUT;
-        }
-
-        return SUCCESS;
+        return continuum.addMavenTwoProject( pomUrl );
     }
 
     public String doDefault()
@@ -95,23 +47,35 @@
         return INPUT;
     }
 
+    /**
+     * @deprecated Use {@link #getPomFile()} instead
+     */
     public File getM2PomFile()
     {
-        return m2PomFile;
+        return getPomFile();
     }
 
+    /**
+     * @deprecated Use {@link #setPomFile(File)} instead
+     */
     public void setM2PomFile( File pomFile )
     {
-        m2PomFile = pomFile;
+        setPomFile( pomFile );
     }
 
+    /**
+     * @deprecated Use {@link #getPomUrl()} instead
+     */
     public String getM2PomUrl()
     {
-        return m2PomUrl;
+        return getPomUrl();
     }
 
+    /**
+     * @deprecated Use {@link #setPomUrl(String)} instead
+     */
     public void setM2PomUrl( String pomUrl )
     {
-        m2PomUrl = pomUrl;
+        setPomUrl( pomUrl );
     }
 }



Mime
View raw message