1 package org.apache.maven.archiva.web.action;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import com.opensymphony.xwork2.Validateable;
23 import com.opensymphony.xwork2.Preparable;
24 import org.apache.archiva.audit.Auditable;
25 import org.apache.archiva.audit.AuditEvent;
26 import org.apache.archiva.stagerepository.merge.Maven2RepositoryMerger;
27 import org.apache.archiva.metadata.model.ArtifactMetadata;
28 import org.apache.archiva.metadata.repository.filter.Filter;
29 import org.apache.archiva.metadata.repository.filter.IncludesFilter;
30 import org.apache.archiva.metadata.repository.MetadataRepository;
31 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
32 import org.apache.maven.archiva.configuration.Configuration;
33 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
35 import java.util.List;
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.Iterator;
41 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="mergeAction" instantiation-strategy="per-lookup"
43 public class MergeAction
44 extends PlexusActionSupport
45 implements Validateable, Preparable, Auditable
49 * @plexus.requirement role="org.apache.archiva.stagerepository.merge.RepositoryMerger" role-hint="maven2"
51 private Maven2RepositoryMerger repositoryMerger;
54 * @plexus.requirement role-hint="default"
56 private ArchivaConfiguration configuration;
59 * @plexus.requirement role-hint="default"
61 private MetadataRepository metadataRepository;
63 private ManagedRepositoryConfiguration repository;
65 private String repoid;
67 private String sourceRepoId;
69 private final String action = "merge";
71 private final String noConflicts = "NO CONFLICTS";
73 private final String hasConflicts = "CONFLICTS";
75 private List<ArtifactMetadata> conflictSourceArtifacts;
77 private List<ArtifactMetadata> conflictSourceArtifactsToBeDisplayed;
79 public String getConflicts()
81 sourceRepoId = repoid + "-stage";
82 Configuration config = configuration.getConfiguration();
83 ManagedRepositoryConfiguration targetRepoConfig = config.findManagedRepositoryById( sourceRepoId );
85 if ( targetRepoConfig != null )
96 public String doMerge()
101 List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( sourceRepoId );
102 repositoryMerger.merge( sourceRepoId, repoid );
103 triggerAuditEvent( sourceRepoId, "file-eshan", AuditEvent.MERGING_REPOSITORIES );
105 for ( ArtifactMetadata metadata : sourceArtifacts )
107 triggerAuditEvent( repoid, metadata.getId(), AuditEvent.MERGING_REPOSITORIES );
110 addActionMessage( "Repository '" + sourceRepoId + "' successfully merged to '" + repoid + "'." );
114 catch ( Exception ex )
116 addActionError( "Error occurred while merging the repositories." );
121 public String mergeBySkippingConflicts()
125 List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( sourceRepoId );
126 sourceArtifacts.removeAll( conflictSourceArtifacts );
127 Filter<ArtifactMetadata> artifactsWithOutConflicts =
128 new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
129 repositoryMerger.merge( sourceRepoId, repoid, artifactsWithOutConflicts );
131 for ( ArtifactMetadata metadata : sourceArtifacts )
133 triggerAuditEvent( repoid, metadata.getId(), AuditEvent.MERGING_REPOSITORIES );
136 addActionMessage( "Repository '" + sourceRepoId + "' successfully merged to '" + repoid + "'." );
140 catch ( Exception ex )
142 addActionError( "Error occurred while merging the repositories." );
147 public String mergeWithOutConlficts()
150 sourceRepoId = repoid + "-stage";
154 conflictSourceArtifacts = repositoryMerger.getConflictsartifacts( sourceRepoId, repoid );
156 catch ( Exception e )
158 addActionError( "Error occurred while merging the repositories." );
162 addActionMessage( "Repository '" + sourceRepoId + "' successfully merged to '" + repoid + "'." );
167 public ManagedRepositoryConfiguration getRepository()
172 public void setRepository( ManagedRepositoryConfiguration repository )
174 this.repository = repository;
177 public void prepare()
180 sourceRepoId = repoid + "-stage";
181 conflictSourceArtifacts = repositoryMerger.getConflictsartifacts( sourceRepoId, repoid );
182 this.repository = new ManagedRepositoryConfiguration();
183 setConflictSourceArtifactsToBeDisplayed( conflictSourceArtifacts );
186 public String getSourceRepoId()
191 public void setSourceRepoId( String sourceRepoId )
193 this.sourceRepoId = sourceRepoId;
196 public String getRepoid()
201 public void setRepoid( String repoid )
203 this.repoid = repoid;
206 public List<ArtifactMetadata> getConflictSourceArtifacts()
208 return conflictSourceArtifacts;
211 public void setConflictSourceArtifacts( List<ArtifactMetadata> conflictSourceArtifacts )
213 this.conflictSourceArtifacts = conflictSourceArtifacts;
216 public List<ArtifactMetadata> getConflictSourceArtifactsToBeDisplayed()
218 return conflictSourceArtifactsToBeDisplayed;
221 public void setConflictSourceArtifactsToBeDisplayed( List<ArtifactMetadata> conflictSourceArtifacts )
224 this.conflictSourceArtifactsToBeDisplayed = new ArrayList<ArtifactMetadata>();
225 HashMap<String, ArtifactMetadata> map = new HashMap<String, ArtifactMetadata>();
226 for ( ArtifactMetadata metadata : conflictSourceArtifacts )
228 String metadataId = metadata.getNamespace() + metadata.getProject() + metadata.getProjectVersion() + metadata.getVersion();
229 map.put( metadataId, metadata );
231 Iterator iterator = map.keySet().iterator();
233 while ( iterator.hasNext() )
235 conflictSourceArtifactsToBeDisplayed.add( map.get(iterator.next() ));