Revision: 97
          http://mvn-infix.svn.sourceforge.net/mvn-infix/?rev=97&view=rev
Author:   bindul
Date:     2010-12-18 23:54:29 +0000 (Sat, 18 Dec 2010)

Log Message:
-----------
Progress on merging maps

Modified Paths:
--------------
    
plugins/sfnet-mvnrepo-plugin/trunk/src/main/java/com/mindtree/techworks/infix/plugins/sfnetmvnrepo/SfNetMvnMojoInfo.java
    
plugins/sfnet-mvnrepo-plugin/trunk/src/main/java/com/mindtree/techworks/infix/plugins/sfnetmvnrepo/actions/RepoMapGenAction.java
    plugins/sfnet-mvnrepo-plugin/trunk/src/main/mdo/mvn-repo-map.mdo
    
plugins/sfnet-mvnrepo-plugin/trunk/src/test/java/com/mindtree/techworks/infix/plugins/sfnetmvnrepo/SfNetMvnMojoInfoTCImpl.java

Modified: 
plugins/sfnet-mvnrepo-plugin/trunk/src/main/java/com/mindtree/techworks/infix/plugins/sfnetmvnrepo/SfNetMvnMojoInfo.java
===================================================================
--- 
plugins/sfnet-mvnrepo-plugin/trunk/src/main/java/com/mindtree/techworks/infix/plugins/sfnetmvnrepo/SfNetMvnMojoInfo.java
    2010-12-18 23:53:17 UTC (rev 96)
+++ 
plugins/sfnet-mvnrepo-plugin/trunk/src/main/java/com/mindtree/techworks/infix/plugins/sfnetmvnrepo/SfNetMvnMojoInfo.java
    2010-12-18 23:54:29 UTC (rev 97)
@@ -34,10 +34,10 @@
  */
 public interface SfNetMvnMojoInfo extends MojoInfo {
 
-       /**
-        * Returns the repository configurations configured for the run
-        * 
-        * @return The list of repository configurations or an empty list
-        */
-       public List<RepositoryConfig> getRepositoryConfigs ();
+    /**
+     * Returns the repository configurations configured for the run
+     * 
+     * @return The list of repository configurations or an empty list
+     */
+    public List<RepositoryConfig> getRepositoryConfigs ();
 }

Modified: 
plugins/sfnet-mvnrepo-plugin/trunk/src/main/java/com/mindtree/techworks/infix/plugins/sfnetmvnrepo/actions/RepoMapGenAction.java
===================================================================
--- 
plugins/sfnet-mvnrepo-plugin/trunk/src/main/java/com/mindtree/techworks/infix/plugins/sfnetmvnrepo/actions/RepoMapGenAction.java
    2010-12-18 23:53:17 UTC (rev 96)
+++ 
plugins/sfnet-mvnrepo-plugin/trunk/src/main/java/com/mindtree/techworks/infix/plugins/sfnetmvnrepo/actions/RepoMapGenAction.java
    2010-12-18 23:54:29 UTC (rev 97)
@@ -20,9 +20,14 @@
  */
 package com.mindtree.techworks.infix.plugins.sfnetmvnrepo.actions;
 
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.xml.stream.XMLStreamException;
+
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
 
@@ -33,7 +38,10 @@
 import 
com.mindtree.techworks.infix.plugins.sfnetmvnrepo.model.repoconfig.ExistingRepositoryMap;
 import 
com.mindtree.techworks.infix.plugins.sfnetmvnrepo.model.repoconfig.RepositoryConfig;
 import 
com.mindtree.techworks.infix.plugins.sfnetmvnrepo.model.repoconfig.SourceForgeFRSMapper;
+import 
com.mindtree.techworks.infix.plugins.sfnetmvnrepo.model.repomap.Directory;
+import 
com.mindtree.techworks.infix.plugins.sfnetmvnrepo.model.repomap.FileItem;
 import 
com.mindtree.techworks.infix.plugins.sfnetmvnrepo.model.repomap.RepositoryMap;
+import 
com.mindtree.techworks.infix.plugins.sfnetmvnrepo.model.repomap.io.stax.RepositoryMapStaxWriter;
 
 
 /**
@@ -95,7 +103,31 @@
                }
                
                // Merge the maps!!
-               mergeMaps(parsedMaps, repositoryConfig);
+               RepositoryMap mergedMap = mergeMaps(parsedMaps, 
repositoryConfig);
+               
+               // Write the map
+               File mergedMapDestin = new File (mojoInfo.getWorkDirectory(), 
repositoryConfig.getId() + "-repomap.xml");
+               FileWriter fileWriter = null;
+               try {
+                       fileWriter = new FileWriter(mergedMapDestin);
+                       RepositoryMapStaxWriter writer = new 
RepositoryMapStaxWriter();
+                       writer.write(fileWriter, mergedMap);
+               } catch (IOException e) {
+                       mojoInfo.getLog().error("Unable to write generated map 
to : " + mergedMapDestin, e);
+                       throw new MapGenerationException("Unable to write 
generated map to : " + mergedMapDestin, e);
+               } catch (XMLStreamException e) {
+                       mojoInfo.getLog().error("Unable to write generated map 
to : " + mergedMapDestin, e);
+                       throw new MapGenerationException("Unable to write 
generated map to : " + mergedMapDestin, e);
+               } finally {
+                       if (null != fileWriter) {
+                               try {
+                                       fileWriter.close();
+                               } catch (IOException e) {
+                                       // Ignore
+                               }
+                       }
+               }
+               
        }
 
        /**
@@ -133,7 +165,7 @@
        /**
         * 
         */
-       private void mergeMaps (List<RepositoryMap> parsedMaps, 
RepositoryConfig repositoryConfig) {
+       private RepositoryMap mergeMaps (List<RepositoryMap> parsedMaps, 
RepositoryConfig repositoryConfig) {
                
                // Create the master
                RepositoryMap mergedRepoMap = new RepositoryMap();
@@ -141,15 +173,75 @@
                mergedRepoMap.setId(repositoryConfig.getId());
                mergedRepoMap.setName(repositoryConfig.getName());
                
-//             for (RepositoryMap parsedMap : parsedMaps) {
-//                     handleDirectory (parsedMap, )
-//             }
+               for (RepositoryMap parsedMap : parsedMaps) {
+                       for (Directory directory : parsedMap.getDirectories()) {
+                               handleDirectory (mergedRepoMap, directory, 
mergedRepoMap.getRedirectBase(), parsedMap.getRedirectBase());
+                       }
+               }
                
-               // TODO Auto-generated method stub
+               return mergedRepoMap;
        }
 
+       private void handleDirectory (Directory destinationParent, Directory 
sourceDir, String destinationParentUrl, String sourceParentUrl) {
+               
+               // Decide on URL
+               String destinationRedirectBase = null;
+               if (!isNullOrEmpty(sourceDir.getRedirectBase())) {
+                       String possibleDestination = 
sourceDir.getRedirectBase();
+                       if (!possibleDestination.endsWith("/")) {
+                               possibleDestination = possibleDestination + "/";
+                       }
+                       if 
(!possibleDestination.equals(computeUrl(destinationParentUrl, sourceDir))) {
+                               destinationRedirectBase = possibleDestination;
+                       }
+               } else if (!destinationParentUrl.equals(sourceParentUrl)) {
+                       destinationRedirectBase = computeUrl(sourceParentUrl, 
sourceDir);
+               }
+               
+               // Create the directory
+               Directory destination = new Directory();
+               destination.setId(sourceDir.getId());
+               destination.setName(sourceDir.getName());
+               if (null != destinationRedirectBase) {
+                       destination.setRedirectBase(destinationRedirectBase);
+               }
+               destinationParent.addDirectory(destination);
+               
+               // Handle files
+               if (null != sourceDir.getFiles()) {
+                       for (FileItem sourceFile : sourceDir.getFiles()) {
+                               destination.addFile(sourceFile);
+                       }
+               }
+               
+               // Handle directories
+               if (null != sourceDir.getDirectories() && 
!sourceDir.getDirectories().isEmpty()) {
+                       String invokeDestinationParentUrl = 
destinationRedirectBase;
+                       if (null == invokeDestinationParentUrl) {
+                               invokeDestinationParentUrl = 
computeUrl(destinationParentUrl, destination);
+                       }
+                       String invokeSourceParentUrl = 
sourceDir.getRedirectBase();
+                       if (null == invokeSourceParentUrl) {
+                               invokeSourceParentUrl = 
computeUrl(sourceParentUrl, sourceDir);
+                       }
+                       for (Directory child : sourceDir.getDirectories()) {
+                               handleDirectory(destination, child, 
invokeDestinationParentUrl, invokeSourceParentUrl);
+                       }
+               }
+       }
+       
        private boolean isNullOrEmpty (String test) {
                return ((null == test) || (test.trim().length() == 0));
        }
        
+       private String computeUrl (String parentUrl, Directory childDir) {
+               StringBuilder destin = new StringBuilder(parentUrl);
+               if (!parentUrl.endsWith("/")) {
+                       destin.append('/');
+               }
+               destin.append(childDir.getId());
+               destin.append('/');
+               return destin.toString();
+               
+       }
 }

Modified: plugins/sfnet-mvnrepo-plugin/trunk/src/main/mdo/mvn-repo-map.mdo
===================================================================
--- plugins/sfnet-mvnrepo-plugin/trunk/src/main/mdo/mvn-repo-map.mdo    
2010-12-18 23:53:17 UTC (rev 96)
+++ plugins/sfnet-mvnrepo-plugin/trunk/src/main/mdo/mvn-repo-map.mdo    
2010-12-18 23:54:29 UTC (rev 97)
@@ -135,6 +135,17 @@
                        <description>The root repository 
information</description>
                        <version>0.1.0+</version>
                        <superClass>Directory</superClass>
+                       <fields>
+                               <field>
+                                       <name>footerLines</name>
+                                       <version>0.1.0+</version>
+                                       <description>Footer line to add to the 
repository directory display</description>
+                                       <association>
+                                               <type>String</type>
+                                               <multiplicity>*</multiplicity>
+                                       </association>
+                               </field>
+                       </fields>
                </class>
        </classes>
 </model>
\ No newline at end of file

Modified: 
plugins/sfnet-mvnrepo-plugin/trunk/src/test/java/com/mindtree/techworks/infix/plugins/sfnetmvnrepo/SfNetMvnMojoInfoTCImpl.java
===================================================================
--- 
plugins/sfnet-mvnrepo-plugin/trunk/src/test/java/com/mindtree/techworks/infix/plugins/sfnetmvnrepo/SfNetMvnMojoInfoTCImpl.java
      2010-12-18 23:53:17 UTC (rev 96)
+++ 
plugins/sfnet-mvnrepo-plugin/trunk/src/test/java/com/mindtree/techworks/infix/plugins/sfnetmvnrepo/SfNetMvnMojoInfoTCImpl.java
      2010-12-18 23:54:29 UTC (rev 97)
@@ -32,14 +32,19 @@
  *
  */
 public class SfNetMvnMojoInfoTCImpl extends MojoInfoTCImpl implements 
SfNetMvnMojoInfo {
+       
+       private List<RepositoryConfig> repositoryConfigs;
 
        /* (non-Javadoc)
         * @see 
com.mindtree.techworks.infix.plugins.sfnetmvnrepo.SfNetMvnMojoInfo#getRepositoryConfigs()
         */
        @Override
        public List<RepositoryConfig> getRepositoryConfigs () {
-               // TODO Auto-generated method stub
-               return null;
+               return this.repositoryConfigs;
        }
+       
+       public void setRepositoryConfigs (List<RepositoryConfig> 
repositoryConfigs) {
+               this.repositoryConfigs = repositoryConfigs;
+       }
 
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
mvn-Infix-commits mailing list
mvn-Infix-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mvn-infix-commits

Reply via email to