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;
38 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="mergeAction" instantiation-strategy="per-lookup"
40 public class MergeAction
41 extends PlexusActionSupport
42 implements Validateable, Preparable, Auditable
46 * @plexus.requirement role="org.apache.archiva.stagerepository.merge.RepositoryMerger" role-hint="maven2"
48 private Maven2RepositoryMerger repositoryMerger;
51 * @plexus.requirement role-hint="default"
53 private ArchivaConfiguration configuration;
56 * @plexus.requirement role-hint="default"
58 private MetadataRepository metadataRepository;
60 private ManagedRepositoryConfiguration repository;
62 private String repoid;
64 private String targetRepoId;
66 private final String action = "merge";
68 private final String noConflicts = "NO CONFLICTS";
70 private final String hasConflicts = "CONFLICTS";
72 private List<ArtifactMetadata> conflictSourceArtifacts;
74 public String getConflicts()
76 targetRepoId = repoid + "-stage";
77 Configuration config = configuration.getConfiguration();
78 ManagedRepositoryConfiguration targetRepoConfig = config.findManagedRepositoryById( targetRepoId );
80 if ( targetRepoConfig != null )
91 public String doMerge()
96 List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( targetRepoId );
97 repositoryMerger.merge( targetRepoId, repoid );
98 triggerAuditEvent( targetRepoId, "file-eshan", AuditEvent.MERGING_REPOSITORIES );
100 for ( ArtifactMetadata metadata : sourceArtifacts )
102 triggerAuditEvent( repoid, metadata.getId(), AuditEvent.MERGING_REPOSITORIES );
106 catch ( Exception ex )
112 public String mergeBySkippingConflicts()
116 List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts( targetRepoId );
117 sourceArtifacts.removeAll( conflictSourceArtifacts );
118 Filter<ArtifactMetadata> artifactsWithOutConflicts =
119 new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
120 repositoryMerger.merge( targetRepoId, repoid, artifactsWithOutConflicts );
122 for ( ArtifactMetadata metadata : sourceArtifacts )
124 triggerAuditEvent( repoid, metadata.getId(), AuditEvent.MERGING_REPOSITORIES );
129 catch ( Exception ex )
135 public String mergeWithOutConlficts()
138 targetRepoId = repoid + "-stage";
142 conflictSourceArtifacts = repositoryMerger.getConflictsartifacts( targetRepoId, repoid );
144 catch ( Exception e )
152 public ManagedRepositoryConfiguration getRepository()
157 public void setRepository( ManagedRepositoryConfiguration repository )
159 this.repository = repository;
162 public void prepare()
165 targetRepoId = repoid + "-stage";
166 conflictSourceArtifacts = repositoryMerger.getConflictsartifacts( targetRepoId, repoid );
167 this.repository = new ManagedRepositoryConfiguration();
170 public String getTargetRepoId()
175 public void setTargetRepoId( String targetRepoId )
177 this.targetRepoId = targetRepoId;
180 public String getRepoid()
185 public void setRepoid( String repoid )
187 this.repoid = repoid;
190 public List<ArtifactMetadata> getConflictSourceArtifacts()
192 return conflictSourceArtifacts;
195 public void setConflictSourceArtifacts( List<ArtifactMetadata> conflictSourceArtifacts )
197 this.conflictSourceArtifacts = conflictSourceArtifacts;