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 targetRepoId;
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 targetRepoId = repoid + "-stage";
82 Configuration config = configuration.getConfiguration();
83 ManagedRepositoryConfiguration targetRepoConfig = config.findManagedRepositoryById( targetRepoId );
85 if ( targetRepoConfig != null )
96 public String doMerge()
101 List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( targetRepoId );
102 repositoryMerger.merge( targetRepoId, repoid );
103 triggerAuditEvent( targetRepoId, "file-eshan", AuditEvent.MERGING_REPOSITORIES );
105 for ( ArtifactMetadata metadata : sourceArtifacts )
107 triggerAuditEvent( repoid, metadata.getId(), AuditEvent.MERGING_REPOSITORIES );
111 catch ( Exception ex )
117 public String mergeBySkippingConflicts()
121 List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( targetRepoId );
122 sourceArtifacts.removeAll( conflictSourceArtifacts );
123 Filter<ArtifactMetadata> artifactsWithOutConflicts =
124 new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
125 repositoryMerger.merge( targetRepoId, repoid, artifactsWithOutConflicts );
127 for ( ArtifactMetadata metadata : sourceArtifacts )
129 triggerAuditEvent( repoid, metadata.getId(), AuditEvent.MERGING_REPOSITORIES );
134 catch ( Exception ex )
140 public String mergeWithOutConlficts()
143 targetRepoId = repoid + "-stage";
147 conflictSourceArtifacts = repositoryMerger.getConflictsartifacts( targetRepoId, repoid );
149 catch ( Exception e )
157 public ManagedRepositoryConfiguration getRepository()
162 public void setRepository( ManagedRepositoryConfiguration repository )
164 this.repository = repository;
167 public void prepare()
170 targetRepoId = repoid + "-stage";
171 conflictSourceArtifacts = repositoryMerger.getConflictsartifacts( targetRepoId, repoid );
172 this.repository = new ManagedRepositoryConfiguration();
173 setConflictSourceArtifactsToBeDisplayed( conflictSourceArtifacts );
176 public String getTargetRepoId()
181 public void setTargetRepoId( String targetRepoId )
183 this.targetRepoId = targetRepoId;
186 public String getRepoid()
191 public void setRepoid( String repoid )
193 this.repoid = repoid;
196 public List<ArtifactMetadata> getConflictSourceArtifacts()
198 return conflictSourceArtifacts;
201 public void setConflictSourceArtifacts( List<ArtifactMetadata> conflictSourceArtifacts )
203 this.conflictSourceArtifacts = conflictSourceArtifacts;
206 public List<ArtifactMetadata> getConflictSourceArtifactsToBeDisplayed()
208 return conflictSourceArtifactsToBeDisplayed;
211 public void setConflictSourceArtifactsToBeDisplayed( List<ArtifactMetadata> conflictSourceArtifacts )
214 this.conflictSourceArtifactsToBeDisplayed = new ArrayList<ArtifactMetadata>();
215 HashMap<String, ArtifactMetadata> map = new HashMap<String, ArtifactMetadata>();
216 for ( ArtifactMetadata metadata : conflictSourceArtifacts )
218 String metadataId = metadata.getNamespace() + metadata.getProject() + metadata.getProjectVersion() + metadata.getVersion();
219 map.put( metadataId, metadata );
221 Iterator iterator = map.keySet().iterator();
223 while ( iterator.hasNext() )
225 conflictSourceArtifactsToBeDisplayed.add( map.get(iterator.next() ));