maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1206629 - in /maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker: ./ github/ patching/ patching/github/
Date Sat, 26 Nov 2011 22:51:20 GMT
Author: olamy
Date: Sat Nov 26 22:51:18 2011
New Revision: 1206629

URL: http://svn.apache.org/viewvc?rev=1206629&view=rev
Log:
refactor to be able to support more patch system providers: reviewboard github is not the
only system in our world

Added:
    maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/
    maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepository.java
  (with props)
    maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryException.java
  (with props)
    maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryRequest.java
  (with props)
    maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryResult.java
  (with props)
    maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/github/
    maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/github/GitHubPatchRepository.java
  (contents, props changed)
      - copied, changed from r1206628, maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/github/PullRequest.java
    maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/github/GithubPatchRepositoryResult.java
  (with props)
Removed:
    maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/github/PullRequest.java
Modified:
    maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/AbstractPatchMojo.java
    maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/PullRequestToJiraMojo.java

Modified: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/AbstractPatchMojo.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/AbstractPatchMojo.java?rev=1206629&r1=1206628&r2=1206629&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/AbstractPatchMojo.java
(original)
+++ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/AbstractPatchMojo.java
Sat Nov 26 22:51:18 2011
@@ -21,6 +21,7 @@ package org.apache.maven.plugins.patchtr
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.patchtracker.patching.PatchRepository;
 import org.apache.maven.plugins.patchtracker.tracking.PatchTracker;
 import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerRequest;
 import org.apache.maven.project.MavenProject;
@@ -110,9 +111,14 @@ public abstract class AbstractPatchMojo
     protected String password;
 
     /**
-     * @parameter expression="${patch.system}" default-value=""
+     * @parameter expression="${patch.issueSystem}" default-value=""
      */
-    protected String system;
+    protected String issueSystem;
+
+    /**
+     * @parameter expression="${patch.patchSystem}" default-value="${project.patchManagement.system}"
+     */
+    protected String patchSystem;
 
     /**
      * @parameter expression="${patch.summary}" default-value=""
@@ -321,9 +327,9 @@ public abstract class AbstractPatchMojo
         String value = project.getIssueManagement() == null ? "" : project.getIssueManagement().getSystem();
 
         // cli must win !
-        if ( StringUtils.isNotEmpty( system ) )
+        if ( StringUtils.isNotEmpty( issueSystem ) )
         {
-            value = system;
+            value = issueSystem;
         }
 
         try
@@ -337,6 +343,28 @@ public abstract class AbstractPatchMojo
         }
     }
 
+    protected String getPatchRepositorySystem()
+        throws MojoExecutionException
+    {
+        String value = project.getProperties().getProperty( "project.patchManagement.system"
);
+
+        // cli must win !
+        if ( StringUtils.isNotEmpty( patchSystem ) )
+        {
+            value = patchSystem;
+        }
+
+        try
+        {
+            return getValue( value, "path repository system id ?", Arrays.asList( "github"
), true,
+                             "you must configure a patch system or at least use interactive
mode", "github", false );
+        }
+        catch ( PrompterException e )
+        {
+            throw new MojoExecutionException( e.getMessage(), e );
+        }
+    }
+
     protected String getValue( String currentValue, String message, List<String> possibleValues,
boolean mandatory,
                                String errorMessage, String defaultValue, boolean passwordPrompt
)
         throws PrompterException, MojoExecutionException
@@ -421,6 +449,16 @@ public abstract class AbstractPatchMojo
         return (PatchTracker) plexusContainer.lookup( PatchTracker.class.getName(), system
);
     }
 
+    protected PatchRepository getPatchRepository()
+        throws MojoExecutionException, ComponentLookupException
+    {
+        String system = getPatchRepositorySystem();
+
+        getLog().debug( "patch repository system:" + system );
+
+        return (PatchRepository) plexusContainer.lookup( PatchRepository.class.getName(),
system );
+    }
+
     public void contextualize( Context context )
         throws ContextException
     {

Modified: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/PullRequestToJiraMojo.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/PullRequestToJiraMojo.java?rev=1206629&r1=1206628&r2=1206629&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/PullRequestToJiraMojo.java
(original)
+++ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/PullRequestToJiraMojo.java
Sat Nov 26 22:51:18 2011
@@ -18,24 +18,19 @@ package org.apache.maven.plugins.patchtr
  * under the License.
  */
 
-import org.apache.commons.io.IOUtils;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.patchtracker.github.PullRequest;
+import org.apache.maven.plugins.patchtracker.patching.PatchRepository;
+import org.apache.maven.plugins.patchtracker.patching.PatchRepositoryException;
+import org.apache.maven.plugins.patchtracker.patching.PatchRepositoryRequest;
+import org.apache.maven.plugins.patchtracker.patching.PatchRepositoryResult;
 import org.apache.maven.plugins.patchtracker.tracking.PatchTracker;
 import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerException;
 import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerRequest;
 import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerResult;
-import org.codehaus.jackson.map.DeserializationConfig;
-import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 
-import java.io.IOException;
-
 
 /**
  * @author Olivier Lamy
@@ -47,7 +42,7 @@ public class PullRequestToJiraMojo
 {
 
     /**
-     * github user/organization  : github.com/apache use apache
+     * for github user/organization  : github.com/apache use apache
      *
      * @parameter expression="${patch.pullrequest.user}" default-value=""
      */
@@ -84,49 +79,36 @@ public class PullRequestToJiraMojo
         // format curl -v https://api.github.com/repos/apache/directmemory/pulls/1
         try
         {
+            PatchRepositoryRequest patchRepositoryRequest =
+                new PatchRepositoryRequest().setUrl( githubApiUrl ).setRepository( repo ).setId(
+                    pullRequestId ).setOrganization( user );
 
-            String url = githubApiUrl + "/" + user + "/" + repo + "/pulls/" + pullRequestId;
-            getLog().debug( "url" + url );
-
-            HttpGet httpGet = new HttpGet( url );
-
-            HttpResponse httpResponse = defaultHttpClient.execute( httpGet );
-
-            ObjectMapper objectMapper = new ObjectMapper();
-
-            // we don't parse all stuff
-            objectMapper.configure( DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,
false );
+            PatchRepository patchRepository = getPatchRepository();
 
-            String response = IOUtils.toString( httpResponse.getEntity().getContent() );
-
-            getLog().debug( "response:" + response );
-
-            PullRequest pullRequest = objectMapper.reader( PullRequest.class ).readValue(
response );
-
-            getLog().debug( "pullRequest:" + pullRequest.toString() );
+            PatchRepositoryResult result = patchRepository.getPatch( patchRepositoryRequest,
getLog() );
 
             PatchTrackerRequest patchTrackerRequest = buidPatchTrackerRequest( false );
 
-            patchTrackerRequest.setSummary( pullRequest.getTitle() );
+            patchTrackerRequest.setSummary( result.getTitle() );
 
-            patchTrackerRequest.setDescription( pullRequest.getBody() + ". url: " + pullRequest.getPatch_url()
);
+            patchTrackerRequest.setDescription( result.getDescription() + ". url: " + result.getPatchUrl()
);
 
-            patchTrackerRequest.setPatchContent( getPatchContent( pullRequest ) );
+            patchTrackerRequest.setPatchContent( result.getPatchContent() );
+
+            getLog().debug( "patchTrackerRequest:" + patchTrackerRequest.toString() );
 
             PatchTracker patchTracker = getPatchTracker();
 
-            PatchTrackerResult result = patchTracker.createPatch( patchTrackerRequest );
-            getLog().info( "issue created with id:" + result.getPatchId() + ", url:" + result.getPatchUrl()
);
-        }
-        catch ( ClientProtocolException e )
-        {
-            throw new MojoExecutionException( e.getMessage(), e );
+            PatchTrackerResult patchTrackerResult = patchTracker.createPatch( patchTrackerRequest
);
+            getLog().info( "issue created with id:" + patchTrackerResult.getPatchId() + ",
url:"
+                               + patchTrackerResult.getPatchUrl() );
+
         }
-        catch ( IOException e )
+        catch ( ComponentLookupException e )
         {
             throw new MojoExecutionException( e.getMessage(), e );
         }
-        catch ( ComponentLookupException e )
+        catch ( PatchRepositoryException e )
         {
             throw new MojoExecutionException( e.getMessage(), e );
         }
@@ -136,13 +118,4 @@ public class PullRequestToJiraMojo
         }
     }
 
-    protected String getPatchContent( PullRequest pullRequest )
-        throws IOException, ClientProtocolException
-    {
-        HttpGet httpGet = new HttpGet( pullRequest.getPatch_url() );
-
-        HttpResponse httpResponse = defaultHttpClient.execute( httpGet );
-
-        return IOUtils.toString( httpResponse.getEntity().getContent() );
-    }
 }

Added: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepository.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepository.java?rev=1206629&view=auto
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepository.java
(added)
+++ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepository.java
Sat Nov 26 22:51:18 2011
@@ -0,0 +1,31 @@
+package org.apache.maven.plugins.patchtracker.patching;
+/*
+ * 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.logging.Log;
+
+/**
+ * @author Olivier Lamy
+ */
+public interface PatchRepository
+{
+
+    PatchRepositoryResult getPatch( PatchRepositoryRequest patchRepositoryRequest, Log log
)
+        throws PatchRepositoryException;
+}

Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepository.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryException.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryException.java?rev=1206629&view=auto
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryException.java
(added)
+++ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryException.java
Sat Nov 26 22:51:18 2011
@@ -0,0 +1,31 @@
+package org.apache.maven.plugins.patchtracker.patching;
+/*
+ * 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.
+ */
+
+/**
+ * @author Olivier Lamy
+ */
+public class PatchRepositoryException
+    extends Exception
+{
+    public PatchRepositoryException( String message, Throwable throwable )
+    {
+        super( message, throwable );
+    }
+}

Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryRequest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryRequest.java?rev=1206629&view=auto
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryRequest.java
(added)
+++ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryRequest.java
Sat Nov 26 22:51:18 2011
@@ -0,0 +1,113 @@
+package org.apache.maven.plugins.patchtracker.patching;
+/*
+ * 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.Serializable;
+
+/**
+ * @author Olivier Lamy
+ */
+public class PatchRepositoryRequest
+    implements Serializable
+{
+    /**
+     * for github user/organization  : github.com/apache use apache
+     */
+    protected String organization;
+
+    /**
+     * for github repo  : github.com/apache/maven-3 use maven-3
+     */
+    protected String repository;
+
+    /**
+     * for github pull request id
+     *
+     * @parameter expression="${patch.pullrequest.id}" default-value=""
+     */
+    protected String id;
+
+
+    /**
+     * for github api url https://api.github.com/repos
+     */
+    protected String url;
+
+    public PatchRepositoryRequest()
+    {
+        // no op
+    }
+
+    public String getOrganization()
+    {
+        return organization;
+    }
+
+    public PatchRepositoryRequest setOrganization( String organization )
+    {
+        this.organization = organization;
+        return this;
+    }
+
+    public String getRepository()
+    {
+        return repository;
+    }
+
+    public PatchRepositoryRequest setRepository( String repository )
+    {
+        this.repository = repository;
+        return this;
+    }
+
+    public String getId()
+    {
+        return id;
+    }
+
+    public PatchRepositoryRequest setId( String id )
+    {
+        this.id = id;
+        return this;
+    }
+
+    public String getUrl()
+    {
+        return url;
+    }
+
+    public PatchRepositoryRequest setUrl( String url )
+    {
+        this.url = url;
+        return this;
+    }
+
+    @Override
+    public String toString()
+    {
+        final StringBuilder sb = new StringBuilder();
+        sb.append( "PatchRepositoryRequest" );
+        sb.append( "{organization='" ).append( organization ).append( '\'' );
+        sb.append( ", repository='" ).append( repository ).append( '\'' );
+        sb.append( ", id='" ).append( id ).append( '\'' );
+        sb.append( ", url='" ).append( url ).append( '\'' );
+        sb.append( '}' );
+        return sb.toString();
+    }
+}

Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryRequest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryResult.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryResult.java?rev=1206629&view=auto
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryResult.java
(added)
+++ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryResult.java
Sat Nov 26 22:51:18 2011
@@ -0,0 +1,112 @@
+package org.apache.maven.plugins.patchtracker.patching;
+/*
+ * 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.Serializable;
+
+/**
+ * @author Olivier Lamy
+ */
+public class PatchRepositoryResult
+    implements Serializable
+{
+    private String title;
+
+    private String htmlUrl;
+
+    private String patchUrl;
+
+    private String description;
+
+    private String patchContent;
+
+    public PatchRepositoryResult()
+    {
+        // no op
+    }
+
+    public String getTitle()
+    {
+        return title;
+    }
+
+    public PatchRepositoryResult setTitle( String title )
+    {
+        this.title = title;
+        return this;
+    }
+
+    public String getHtmlUrl()
+    {
+        return htmlUrl;
+    }
+
+    public PatchRepositoryResult setHtmlUrl( String htmlUrl )
+    {
+        this.htmlUrl = htmlUrl;
+        return this;
+    }
+
+    public String getPatchUrl()
+    {
+        return patchUrl;
+    }
+
+    public PatchRepositoryResult setPatchUrl( String patchUrl )
+    {
+        this.patchUrl = patchUrl;
+        return this;
+    }
+
+    public String getDescription()
+    {
+        return description;
+    }
+
+    public PatchRepositoryResult setDescription( String description )
+    {
+        this.description = description;
+        return this;
+    }
+
+    public String getPatchContent()
+    {
+        return patchContent;
+    }
+
+    public PatchRepositoryResult setPatchContent( String patchContent )
+    {
+        this.patchContent = patchContent;
+        return this;
+    }
+
+    @Override
+    public String toString()
+    {
+        final StringBuilder sb = new StringBuilder();
+        sb.append( "PatchRepositoryResult" );
+        sb.append( "{title='" ).append( title ).append( '\'' );
+        sb.append( ", htmlUrl='" ).append( htmlUrl ).append( '\'' );
+        sb.append( ", patchUrl='" ).append( patchUrl ).append( '\'' );
+        sb.append( ", description='" ).append( description ).append( '\'' );
+        sb.append( ", patchContent='" ).append( patchContent ).append( '\'' );
+        sb.append( '}' );
+        return sb.toString();
+    }
+}

Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryResult.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/PatchRepositoryResult.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/github/GitHubPatchRepository.java
(from r1206628, maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/github/PullRequest.java)
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/github/GitHubPatchRepository.java?p2=maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/github/GitHubPatchRepository.java&p1=maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/github/PullRequest.java&r1=1206628&r2=1206629&rev=1206629&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/github/PullRequest.java
(original)
+++ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/github/GitHubPatchRepository.java
Sat Nov 26 22:51:18 2011
@@ -1,4 +1,4 @@
-package org.apache.maven.plugins.patchtracker.github;
+package org.apache.maven.plugins.patchtracker.patching.github;
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -18,14 +18,97 @@ package org.apache.maven.plugins.patchtr
  * under the License.
  */
 
-import java.io.Serializable;
+import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugins.patchtracker.patching.PatchRepository;
+import org.apache.maven.plugins.patchtracker.patching.PatchRepositoryException;
+import org.apache.maven.plugins.patchtracker.patching.PatchRepositoryRequest;
+import org.apache.maven.plugins.patchtracker.patching.PatchRepositoryResult;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.Version;
+import org.codehaus.jackson.map.DeserializationConfig;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.module.SimpleModule;
+
+import java.io.IOException;
 
 /**
  * @author Olivier Lamy
+ * @plexus.component role="org.apache.maven.plugins.patchtracker.patching.PatchRepository"
role-hint="github"
  */
-public class PullRequest
-    implements Serializable
+public class GitHubPatchRepository
+    implements PatchRepository
 {
+    DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
+
+    public PatchRepositoryResult getPatch( PatchRepositoryRequest patchRepositoryRequest,
Log log )
+        throws PatchRepositoryException
+    {
+        try
+        {
+            String url = patchRepositoryRequest.getUrl() + "/" + patchRepositoryRequest.getOrganization()
+ "/"
+                + patchRepositoryRequest.getRepository() + "/pulls/" + patchRepositoryRequest.getId();
+            log.debug( "url" + url );
+
+            HttpGet httpGet = new HttpGet( url );
+
+            HttpResponse httpResponse = defaultHttpClient.execute( httpGet );
+
+            String response = IOUtils.toString( httpResponse.getEntity().getContent() );
+
+            log.debug( "response:" + response );
+
+            PatchRepositoryResult patchRepositoryResult = fromJson( response );
+
+            log.debug( "patchRepositoryResult:" + patchRepositoryResult );
+
+            patchRepositoryResult.setPatchContent( getPatchContent( patchRepositoryResult
) );
+
+            log.debug( "pullRequest:" + patchRepositoryResult.toString() );
+            return patchRepositoryResult;
+        }
+        catch ( IOException e )
+        {
+            throw new PatchRepositoryException( e.getMessage(), e );
+        }
+    }
+
+    protected String getPatchContent( PatchRepositoryResult pullRequest )
+        throws IOException, ClientProtocolException
+    {
+        HttpGet httpGet = new HttpGet( pullRequest.getPatchUrl() );
+
+        HttpResponse httpResponse = defaultHttpClient.execute( httpGet );
+
+        return IOUtils.toString( httpResponse.getEntity().getContent() );
+    }
+
+    /**
+     * parse json from gitbut see http://developer.github.com/v3/pulls/
+     *
+     * @param jsonContent
+     * @return
+     * @throws IOException
+     * @throws JsonProcessingException
+     */
+    protected PatchRepositoryResult fromJson( String jsonContent )
+        throws IOException, JsonProcessingException
+    {
+        ObjectMapper objectMapper = new ObjectMapper();
+
+        // we don't parse all stuff
+        // se json format below or documentation
+        objectMapper.configure( DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,
false );
+
+        //objectMapper.
+
+        return objectMapper.reader( GithubPatchRepositoryResult.class ).readValue( jsonContent
);
+    }
+
     /**
      * json format
      * <p/>
@@ -163,69 +246,4 @@ public class PullRequest
      * }
      */
 
-    private String title;
-
-    private String html_url;
-
-    private String patch_url;
-
-    private String body;
-
-    public PullRequest()
-    {
-        // no op
-    }
-
-    public String getTitle()
-    {
-        return title;
-    }
-
-    public void setTitle( String title )
-    {
-        this.title = title;
-    }
-
-    public String getHtml_url()
-    {
-        return html_url;
-    }
-
-    public void setHtml_url( String html_url )
-    {
-        this.html_url = html_url;
-    }
-
-    public String getPatch_url()
-    {
-        return patch_url;
-    }
-
-    public void setPatch_url( String patch_url )
-    {
-        this.patch_url = patch_url;
-    }
-
-    public String getBody()
-    {
-        return body;
-    }
-
-    public void setBody( String body )
-    {
-        this.body = body;
-    }
-
-    @Override
-    public String toString()
-    {
-        final StringBuilder sb = new StringBuilder();
-        sb.append( "PullRequest" );
-        sb.append( "{title='" ).append( title ).append( '\'' );
-        sb.append( ", html_url='" ).append( html_url ).append( '\'' );
-        sb.append( ", patch_url='" ).append( patch_url ).append( '\'' );
-        sb.append( ", body='" ).append( body ).append( '\'' );
-        sb.append( '}' );
-        return sb.toString();
-    }
 }

Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/github/GitHubPatchRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/github/GitHubPatchRepository.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/github/GithubPatchRepositoryResult.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/github/GithubPatchRepositoryResult.java?rev=1206629&view=auto
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/github/GithubPatchRepositoryResult.java
(added)
+++ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/github/GithubPatchRepositoryResult.java
Sat Nov 26 22:51:18 2011
@@ -0,0 +1,40 @@
+package org.apache.maven.plugins.patchtracker.patching.github;
+/*
+ * 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.plugins.patchtracker.patching.PatchRepositoryResult;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * use jackson annotation to map field to json attributes
+ *
+ * @author Olivier Lamy
+ */
+public class GithubPatchRepositoryResult
+    extends PatchRepositoryResult
+{
+    @JsonProperty( "html_url" )
+    private String htmlUrl;
+
+    @JsonProperty( "patch_url" )
+    private String patchUrl;
+
+    @JsonProperty( "body" )
+    private String description;
+}

Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/github/GithubPatchRepositoryResult.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/patching/github/GithubPatchRepositoryResult.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message