]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1398],[MRM-1401],[MRM-1403]
authorMaria Odea B. Ching <oching@apache.org>
Sun, 8 Aug 2010 05:19:33 +0000 (05:19 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Sun, 8 Aug 2010 05:19:33 +0000 (05:19 +0000)
submitted by Patti Arachchige Eshan Sudharaka
o fixed repositories page
o do not merge snapshot artifacts
o fixed problem when merging artifacts with classifier

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-MRM-980@983343 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/MergeAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/mergeExcludeConflicts.jsp
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp
archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java

index 0b9d439a77c6af7ae96898d5ab8112d778da262d..ff252a151958a2c70fc3198278c1c62955ab8a8b 100644 (file)
@@ -41,7 +41,8 @@ import java.util.Iterator;
 /**
  * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="mergeAction" instantiation-strategy="per-lookup"
  */
-public class MergeAction
+public class
+    MergeAction
     extends PlexusActionSupport
     implements Validateable, Preparable, Auditable
 
@@ -52,9 +53,9 @@ public class MergeAction
     private Maven2RepositoryMerger repositoryMerger;
 
     /**
-     * @plexus.requirement role-hint="default"
+     * @plexus.requirement
      */
-    private ArchivaConfiguration configuration;
+    protected ArchivaConfiguration archivaConfiguration;
 
     /**
      * @plexus.requirement role-hint="default"
@@ -74,8 +75,6 @@ public class MergeAction
 
     private final String action = "merge";
 
-    private final String noConflicts = "NO CONFLICTS";
-
     private final String hasConflicts = "CONFLICTS";
 
     private List<ArtifactMetadata> conflictSourceArtifacts;
@@ -85,7 +84,7 @@ public class MergeAction
     public String getConflicts()
     {
         sourceRepoId = repoid + "-stage";
-        Configuration config = configuration.getConfiguration();
+        Configuration config = archivaConfiguration.getConfiguration();
         ManagedRepositoryConfiguration targetRepoConfig = config.findManagedRepositoryById( sourceRepoId );
 
         if ( targetRepoConfig != null )
@@ -105,20 +104,29 @@ public class MergeAction
         try
         {
             List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( sourceRepoId );
-            repositoryMerger.merge( sourceRepoId, repoid );
-            scheduler.scanRepository();
 
-            for ( ArtifactMetadata metadata : sourceArtifacts )
+            if ( repository.isReleases() && !repository.isSnapshots() )
             {
-                triggerAuditEvent( repoid, metadata.getId(), AuditEvent.MERGING_REPOSITORIES );
+                mergeWithOutSnapshots( sourceArtifacts, sourceRepoId, repoid );
             }
+            else
+            {
+                repositoryMerger.merge( sourceRepoId, repoid );
+
+                for ( ArtifactMetadata metadata : sourceArtifacts )
+                {
+                    triggerAuditEvent( repoid, metadata.getId(), AuditEvent.MERGING_REPOSITORIES );
+                }
 
+            }
+            scheduler.scanRepository();
             addActionMessage( "Repository '" + sourceRepoId + "' successfully merged to '" + repoid + "'." );
-            
+
             return SUCCESS;
         }
         catch ( Exception ex )
         {
+            ex.printStackTrace();
             addActionError( "Error occurred while merging the repositories." );
             return ERROR;
         }
@@ -130,22 +138,30 @@ public class MergeAction
         {
             List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( sourceRepoId );
             sourceArtifacts.removeAll( conflictSourceArtifacts );
-            Filter<ArtifactMetadata> artifactsWithOutConflicts =
-                new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
-            repositoryMerger.merge( sourceRepoId, repoid, artifactsWithOutConflicts );
-            scheduler.scanRepository();
 
-            for ( ArtifactMetadata metadata : sourceArtifacts )
+            if ( repository.isReleases() && !repository.isSnapshots() )
             {
-                triggerAuditEvent( repoid, metadata.getId(), AuditEvent.MERGING_REPOSITORIES );
+                mergeWithOutSnapshots( sourceArtifacts, sourceRepoId, repoid );
             }
+            else
+            {
 
+                Filter<ArtifactMetadata> artifactsWithOutConflicts =
+                    new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
+                repositoryMerger.merge( sourceRepoId, repoid, artifactsWithOutConflicts );
+                for ( ArtifactMetadata metadata : sourceArtifacts )
+                {
+                    triggerAuditEvent( repoid, metadata.getId(), AuditEvent.MERGING_REPOSITORIES );
+                }
+            }
+            scheduler.scanRepository();
             addActionMessage( "Repository '" + sourceRepoId + "' successfully merged to '" + repoid + "'." );
 
             return SUCCESS;
         }
         catch ( Exception ex )
         {
+            ex.printStackTrace();
             addActionError( "Error occurred while merging the repositories." );
             return ERROR;
         }
@@ -167,7 +183,7 @@ public class MergeAction
         }
 
         addActionMessage( "Repository '" + sourceRepoId + "' successfully merged to '" + repoid + "'." );
-        
+
         return SUCCESS;
     }
 
@@ -187,7 +203,9 @@ public class MergeAction
         sourceRepoId = repoid + "-stage";
         conflictSourceArtifacts = repositoryMerger.getConflictsartifacts( sourceRepoId, repoid );
         this.scheduler.setRepoid( repoid );
-        this.repository = new ManagedRepositoryConfiguration();
+        
+        Configuration config = archivaConfiguration.getConfiguration();
+        this.repository = config.findManagedRepositoryById( repoid );
         setConflictSourceArtifactsToBeDisplayed( conflictSourceArtifacts );
     }
 
@@ -221,7 +239,7 @@ public class MergeAction
         this.conflictSourceArtifacts = conflictSourceArtifacts;
     }
 
-      public  List<ArtifactMetadata> getConflictSourceArtifactsToBeDisplayed()
+    public List<ArtifactMetadata> getConflictSourceArtifactsToBeDisplayed()
     {
         return conflictSourceArtifactsToBeDisplayed;
     }
@@ -233,15 +251,39 @@ public class MergeAction
         HashMap<String, ArtifactMetadata> map = new HashMap<String, ArtifactMetadata>();
         for ( ArtifactMetadata metadata : conflictSourceArtifacts )
         {
-                String metadataId = metadata.getNamespace() + metadata.getProject() + metadata.getProjectVersion() + metadata.getVersion();
-                map.put( metadataId, metadata );
+            String metadataId =
+                metadata.getNamespace() + metadata.getProject() + metadata.getProjectVersion() + metadata.getVersion();
+            map.put( metadataId, metadata );
         }
         Iterator iterator = map.keySet().iterator();
 
         while ( iterator.hasNext() )
         {
-            conflictSourceArtifactsToBeDisplayed.add( map.get(iterator.next() ));
+            conflictSourceArtifactsToBeDisplayed.add( map.get( iterator.next() ) );
         }
     }
+
+    private void mergeWithOutSnapshots( List<ArtifactMetadata> sourceArtifacts, String sourceRepoId, String repoid )
+        throws Exception
+    {
+        List<ArtifactMetadata> artifactsWithOutSnapshots = new ArrayList<ArtifactMetadata>();
+        for ( ArtifactMetadata metadata : sourceArtifacts )
+        {
+
+            if ( metadata.getProjectVersion().contains( "SNAPSHOT" ) )
+            {
+                artifactsWithOutSnapshots.add( metadata );
+            }
+            else
+            {
+                triggerAuditEvent( repoid, metadata.getId(), AuditEvent.MERGING_REPOSITORIES );
+            }
+
+        }
+        sourceArtifacts.removeAll( artifactsWithOutSnapshots );
+
+        Filter<ArtifactMetadata> artifactListWithOutSnapShots = new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
+        repositoryMerger.merge( sourceRepoId, repoid, artifactListWithOutSnapShots );
+    }
 }
 
index 371368423ed16fa507012386049c196d6e2febf1..8ccbfda683228d3c3ce228a4a74077548fdc34da 100644 (file)
     <c:choose>
       <c:when test="${empty (conflictSourceArtifacts)}">
         <h1>No conflicting artifacts</h1>
+
+        <c:if test="${!repository.snapshots and repository.releases}">
+          <div class="warningbox">
+            <p>
+              <strong>WARNING:  Repository  "${repoid}" does not allow to merge snapshots</strong>
+            </p>
+          </div>
+        </c:if>
+
         <s:form method="post" action="merge" namespace="/admin" validate="false" theme="simple">
           <s:hidden name="repoid"/>
           <div class="buttons">
       </c:when>
       <c:otherwise>
         <div class="warningbox">
+          <c:if test="${!repository.snapshots and repository.releases}">
+            <p>
+              <strong>WARNING:  Repository "${repoid}" does not allow to merge snapshots</strong>
+            </p>
+          </c:if>
           <p>
             <strong>WARNING: The following are the artifacts in conflict.</strong>
           </p>
@@ -85,7 +99,6 @@
                           </td>
                         </tr>
                       </table>
-
                     </td>
                   </tr>
                 </table>
index 7721cac1e24d0984445910948884b48a88c2ba21..5c84137f8ff0ff8e931e0111355b2ed01315c193 100644 (file)
@@ -22,7 +22,7 @@
 <%@ taglib prefix="s" uri="/struts-tags" %>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 <%@ taglib prefix="redback" uri="http://plexus.codehaus.org/redback/taglib-1.0" %>
-<%@ taglib prefix="archiva" uri="/WEB-INF/taglib.tld" %>
+<%@ taglib prefix="archiva"   uri="/WEB-INF/taglib.tld" %>
 
 <html>
 <head>
   <s:head/>
   <script type="text/javascript" src="<c:url value='/js/jquery-1.3.2.min.js'/>"></script>
   <script type="text/javascript">
-    $(document).ready(function()
-    {
+  $(document).ready(function(){
 
-      $(".pom").hide();
-      $("a.expand").click(function( event )
-      {
-        event.preventDefault();
-        $(this).siblings("pre").toggle("slow");
-      });
+ $(".pom").hide();
+ $("a.expand").click(function(event){
+   event.preventDefault();
+   $(this).siblings("pre").toggle("slow");
+ });
 
-    });
+  });
   </script>
 </head>
 
   </redback:ifAnyAuthorized>
   <c:url var="rssFeedIconUrl" value="/images/icons/rss-feed.png"/>
   <a href="/archiva/feeds/${repository.id}">
-    <img src="${rssFeedIconUrl}"/>
+       <img src="${rssFeedIconUrl}" />
   </a>
 </div>
 
 <h3 class="repository">${repository.name}</h3>
 
 <table class="infoTable">
+<tr>
+  <th>Identifier</th>
+  <td>
+    <code>${repository.id}</code>
+  </td>
+</tr>
+<tr>
+  <th>Name</th>
+  <td>
+    <code>${repository.name}</code>
+  </td>
+</tr>
+<tr>
+  <th>Directory</th>
+  <td>${repository.location}</td>
+</tr>
+<c:if test="${!empty (repository.indexDir)}">
+       <tr>
+         <th>Index Directory</th>
+         <td>${repository.indexDir}</td>
+       </tr>
+</c:if>
+<tr>
+  <th>WebDAV URL</th>
+  <td><a href="${baseUrl}/${repository.id}/">${baseUrl}/${repository.id}/</a></td>
+</tr>
+<tr>
+  <th>Type</th>
+    <%-- TODO: can probably just use layout appended to a key prefix in i18n to simplify this --%>
+  <td>
+    <c:choose>
+      <c:when test="${repository.layout == 'default'}">
+        Maven 2.x Repository
+      </c:when>
+      <c:otherwise>
+        Maven 1.x Repository
+      </c:otherwise>
+    </c:choose>
+  </td>
+</tr>
+<c:if test="${!empty (repositoryToGroupMap[repository.id])}">
   <tr>
     <th>Groups</th>
     <td>
       </c:forEach>
     </td>
   </tr>
+</c:if>
+<tr>
+  <th>Releases Included</th>
+  <td class="${repository.releases ? 'donemark' : 'errormark'} booleanIcon"> </td>
+</tr>
+<tr>
+  <th>Snapshots Included</th>
+  <td class="${repository.snapshots ? 'donemark' : 'errormark'} booleanIcon"> </td>
+</tr>
+<c:if test="${repository.snapshots}">
   <tr>
     <th>Delete Released Snapshots</th>
-    <td class="${repository.deleteReleasedSnapshots ? 'donemark' : 'errormark'} booleanIcon"></td>
-  </tr>    
+    <td class="${repository.deleteReleasedSnapshots ? 'donemark' : 'errormark'} booleanIcon"> </td>
+  </tr>
   <tr>
     <th>Repository Purge By Days Older Than</th>
     <td>${repository.daysOlder}</td>
     <th>Repository Purge By Retention Count</th>
     <td>${repository.retentionCount}</td>
   </tr>
+</c:if>
+<tr>
+  <th>Scanned</th>
+  <td class="${repository.scanned ? 'donemark' : 'errormark'} booleanIcon"> </td>
+</tr>
+<c:if test="${repository.scanned}">
   <tr>
     <th>Scanning Cron</th>
     <td>${repository.refreshCronExpression}</td>
       Actions
     </th>
     <td>
+      <redback:ifAuthorized permission="archiva-run-indexer">
+        <s:form action="indexRepository" theme="simple">
+        <s:hidden name="repoid" value="%{#attr.repository.id}"/>
+        <table>
+          <tr>
+            <td><s:checkbox name="scanAll" value="scanAll"/>Process All Artifacts</td>
+          </tr>
+          <tr>
+            <td><s:submit value="Scan Repository Now"/></td>
+          </tr>
+        </table>
+        </s:form>
+      </redback:ifAuthorized>
+    </td>
+  </tr>
+  <tr>
+    <th>Stats</th>
+    <td>
+      <c:set var="stats" value="${repositoryStatistics[repository.id]}"/>
       <c:choose>
         <c:when test="${empty (stats)}">
           No Statistics Available.
       </c:choose>
     </td>
   </tr>
-  <c:if test="${!empty (repositoryToGroupMap[repository.id])}">
-    <tr>
-      <th>Groups</th>
-      <td>
-        <c:forEach items="${repositoryToGroupMap[repository.id]}" varStatus="i" var="group">
-          ${group}<c:if test="${!i.last}">,</c:if>
-        </c:forEach>
-      </td>
-    </tr>
-  </c:if>
-  <tr>
-    <th>Releases Included</th>
-    <td class="${repository.releases ? 'donemark' : 'errormark'} booleanIcon"></td>
-  </tr>
-  <tr>
-    <th>Snapshots Included</th>
-    <td class="${repository.snapshots ? 'donemark' : 'errormark'} booleanIcon"></td>
-  </tr>
-  <c:if test="${repository.snapshots}">
-    <tr>
-      <th>Delete Released Snapshots</th>
-      <td class="${repository.deleteReleasedSnapshots ? 'donemark' : 'errormark'} booleanIcon"></td>
-    </tr>
-    <tr>
-      <th>Repository Purge By Days Older Than</th>
-      <td>${repository.daysOlder}</td>
-    </tr>
-    <tr>
-      <th>Repository Purge By Retention Count</th>
-      <td>${repository.retentionCount}</td>
-    </tr>
-  </c:if>
-  <tr>
-    <th>Scanned</th>
-    <td class="${repository.scanned ? 'donemark' : 'errormark'} booleanIcon"></td>
-  </tr>
-  <c:if test="${repository.scanned}">
-    <tr>
-      <th>Scanning Cron</th>
-      <td>${repository.refreshCronExpression}</td>
-    </tr>
-    <tr>
-      <th>
-        Actions
-      </th>
-      <td>
-        <redback:ifAuthorized permission="archiva-run-indexer">
-          <s:form action="indexRepository" theme="simple">
-            <s:hidden name="repoid" value="%{#attr.repository.id}"/>
-            <table>
-              <tr>
-                <td><s:checkbox name="scanAll" value="scanAll"/>Process All Artifacts</td>
-              </tr>
-              <tr>
-                <td><s:submit value="Scan Repository Now"/></td>
-              </tr>
-            </table>
-          </s:form>
-        </redback:ifAuthorized>
-      </td>
-    </tr>
-    <tr>
-      <th>Stats</th>
-      <td>
-        <c:set var="stats" value="${repositoryStatistics[repository.id]}"/>
-        <c:choose>
-          <c:when test="${empty (stats)}">
-            No Statistics Available.
-          </c:when>
-          <c:otherwise>
-            <table>
-              <tr>
-                <th>Last Scanned</th>
-                <td>${stats.scanStartTime}</td>
-              </tr>
-              <tr>
-                <th>Duration</th>
-                <td>${stats.duration} ms</td>
-              </tr>
-              <tr>
-                <th>Total File Count</th>
-                <td>${stats.totalFileCount}
-              </tr>
-              <tr>
-                <th>New Files Found</th>
-                <td>${stats.newFileCount}
-              </tr>
-            </table>
-          </c:otherwise>
-        </c:choose>
-      </td>
-    </tr>
-  </c:if>
-  <tr>
-    <th>POM Snippet</th>
-    <td>
-      <archiva:copy-paste-snippet object="${repository}" wrapper="toggle"/>
-    </td>
-
-  </tr>
+</c:if>
+<tr>
+  <th>POM Snippet</th>
+  <td>
+    <archiva:copy-paste-snippet object="${repository}" wrapper="toggle" />
+  </td>
+</tr>
 
 
   <c:set var="str" value="${repository.id}" />
   </c:if>
 
 
+
 </table>
 
 </div>
index 7b8fe7b866416a8f87ae3c02741b7eadde95fcc0..943b667d62ed99d6ef0a5057eb2f5c7fb7bb4b67 100644 (file)
@@ -173,7 +173,7 @@ public class Maven2RepositoryMerger
         File targetPomFile = new File( targetRepoPath, artifactPath.substring( 0, lastIndex ) + "/" +
             artifactPath.substring( lastIndex + 1 ).substring( 0, last ) + ".pom" );
 
-        if ( !targetPomFile.exists() )
+        if ( !targetPomFile.exists() && sourcePomFile.exists() )
         {
             copyFile( sourcePomFile, targetPomFile );
         }
@@ -358,15 +358,12 @@ public class Maven2RepositoryMerger
 
         if ( ( sourceArtifact.getNamespace().equals( targetArtifact.getNamespace() ) ) &&
             ( sourceArtifact.getProject().equals( targetArtifact.getProject() ) ) &&
-            ( sourceArtifact.getVersion().equals( targetArtifact.getVersion() ) ) &&
             ( sourceArtifact.getId().equals( targetArtifact.getId() ) ) &&
             ( sourceArtifact.getProjectVersion().equals( targetArtifact.getProjectVersion() ) ) )
 
         {
-            if ( sourceArtifact.getId().equals( targetArtifact.getId() ) )
-            {
-                isSame = true;
-            }
+            isSame = true;
+
         }
 
         return isSame;