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;
34 import org.apache.maven.archiva.web.action.admin.SchedulerAction;
36 import java.util.List;
37 import java.util.ArrayList;
38 import java.util.HashMap;
39 import java.util.Iterator;
42 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="mergeAction" instantiation-strategy="per-lookup"
44 public class MergeAction
45 extends PlexusActionSupport
46 implements Validateable, Preparable, Auditable
50 * @plexus.requirement role="org.apache.archiva.stagerepository.merge.RepositoryMerger" role-hint="maven2"
52 private Maven2RepositoryMerger repositoryMerger;
55 * @plexus.requirement role-hint="default"
57 private ArchivaConfiguration configuration;
60 * @plexus.requirement role-hint="default"
62 private MetadataRepository metadataRepository;
65 * @plexus.requirement role="com.opensymphony.xwork2.Action" role-hint="schedulerAction"
67 private SchedulerAction scheduler;
69 private ManagedRepositoryConfiguration repository;
71 private String repoid;
73 private String sourceRepoId;
75 private final String action = "merge";
77 private final String noConflicts = "NO CONFLICTS";
79 private final String hasConflicts = "CONFLICTS";
81 private List<ArtifactMetadata> conflictSourceArtifacts;
83 private List<ArtifactMetadata> conflictSourceArtifactsToBeDisplayed;
85 public String getConflicts()
87 sourceRepoId = repoid + "-stage";
88 Configuration config = configuration.getConfiguration();
89 ManagedRepositoryConfiguration targetRepoConfig = config.findManagedRepositoryById( sourceRepoId );
91 if ( targetRepoConfig != null )
102 public String doMerge()
107 List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( sourceRepoId );
108 repositoryMerger.merge( sourceRepoId, repoid );
109 scheduler.scanRepository();
111 for ( ArtifactMetadata metadata : sourceArtifacts )
113 triggerAuditEvent( repoid, metadata.getId(), AuditEvent.MERGING_REPOSITORIES );
116 addActionMessage( "Repository '" + sourceRepoId + "' successfully merged to '" + repoid + "'." );
120 catch ( Exception ex )
122 addActionError( "Error occurred while merging the repositories." );
127 public String mergeBySkippingConflicts()
131 List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( sourceRepoId );
132 sourceArtifacts.removeAll( conflictSourceArtifacts );
133 Filter<ArtifactMetadata> artifactsWithOutConflicts =
134 new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
135 repositoryMerger.merge( sourceRepoId, repoid, artifactsWithOutConflicts );
136 scheduler.scanRepository();
138 for ( ArtifactMetadata metadata : sourceArtifacts )
140 triggerAuditEvent( repoid, metadata.getId(), AuditEvent.MERGING_REPOSITORIES );
143 addActionMessage( "Repository '" + sourceRepoId + "' successfully merged to '" + repoid + "'." );
147 catch ( Exception ex )
149 addActionError( "Error occurred while merging the repositories." );
154 public String mergeWithOutConlficts()
157 sourceRepoId = repoid + "-stage";
161 conflictSourceArtifacts = repositoryMerger.getConflictsartifacts( sourceRepoId, repoid );
163 catch ( Exception e )
165 addActionError( "Error occurred while merging the repositories." );
169 addActionMessage( "Repository '" + sourceRepoId + "' successfully merged to '" + repoid + "'." );
174 public ManagedRepositoryConfiguration getRepository()
179 public void setRepository( ManagedRepositoryConfiguration repository )
181 this.repository = repository;
184 public void prepare()
187 sourceRepoId = repoid + "-stage";
188 conflictSourceArtifacts = repositoryMerger.getConflictsartifacts( sourceRepoId, repoid );
189 this.scheduler.setRepoid( repoid );
190 this.repository = new ManagedRepositoryConfiguration();
191 setConflictSourceArtifactsToBeDisplayed( conflictSourceArtifacts );
194 public String getSourceRepoId()
199 public void setSourceRepoId( String sourceRepoId )
201 this.sourceRepoId = sourceRepoId;
204 public String getRepoid()
209 public void setRepoid( String repoid )
211 this.repoid = repoid;
214 public List<ArtifactMetadata> getConflictSourceArtifacts()
216 return conflictSourceArtifacts;
219 public void setConflictSourceArtifacts( List<ArtifactMetadata> conflictSourceArtifacts )
221 this.conflictSourceArtifacts = conflictSourceArtifacts;
224 public List<ArtifactMetadata> getConflictSourceArtifactsToBeDisplayed()
226 return conflictSourceArtifactsToBeDisplayed;
229 public void setConflictSourceArtifactsToBeDisplayed( List<ArtifactMetadata> conflictSourceArtifacts )
232 this.conflictSourceArtifactsToBeDisplayed = new ArrayList<ArtifactMetadata>();
233 HashMap<String, ArtifactMetadata> map = new HashMap<String, ArtifactMetadata>();
234 for ( ArtifactMetadata metadata : conflictSourceArtifacts )
236 String metadataId = metadata.getNamespace() + metadata.getProject() + metadata.getProjectVersion() + metadata.getVersion();
237 map.put( metadataId, metadata );
239 Iterator iterator = map.keySet().iterator();
241 while ( iterator.hasNext() )
243 conflictSourceArtifactsToBeDisplayed.add( map.get(iterator.next() ));