]> source.dussan.org Git - archiva.git/blob
712f8a6f242b01a425e5dc19c17c18c4cca63f7a
[archiva.git] /
1 package org.apache.maven.archiva.converter.artifact;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
22 import org.apache.archiva.common.plexusbridge.DigesterUtils;
23 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
24 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
25 import org.apache.commons.io.FileUtils;
26 import org.apache.commons.io.IOUtils;
27 import org.apache.archiva.transaction.FileTransaction;
28 import org.apache.archiva.transaction.TransactionException;
29 import org.apache.maven.artifact.Artifact;
30 import org.apache.maven.artifact.factory.ArtifactFactory;
31 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
32 import org.apache.maven.artifact.repository.ArtifactRepository;
33 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
34 import org.apache.maven.artifact.repository.metadata.Metadata;
35 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
36 import org.apache.maven.artifact.repository.metadata.Snapshot;
37 import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
38 import org.apache.maven.artifact.repository.metadata.Versioning;
39 import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
40 import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
41 import org.apache.maven.model.DistributionManagement;
42 import org.apache.maven.model.Model;
43 import org.apache.maven.model.Relocation;
44 import org.apache.maven.model.converter.ModelConverter;
45 import org.apache.maven.model.converter.PomTranslationException;
46 import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
47 import org.codehaus.plexus.digest.Digester;
48 import org.codehaus.plexus.digest.DigesterException;
49 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
50 import org.springframework.stereotype.Service;
51
52 import javax.annotation.PostConstruct;
53 import javax.inject.Inject;
54 import java.io.File;
55 import java.io.FileNotFoundException;
56 import java.io.FileReader;
57 import java.io.IOException;
58 import java.io.StringReader;
59 import java.io.StringWriter;
60 import java.util.ArrayList;
61 import java.util.HashMap;
62 import java.util.List;
63 import java.util.Map;
64 import java.util.Properties;
65 import java.util.regex.Matcher;
66
67 /**
68  * LegacyToDefaultConverter
69  *
70  * @version $Id$
71  * @plexus.component role="org.apache.maven.archiva.converter.artifact.ArtifactConverter"
72  * role-hint="legacy-to-default"
73  */
74 @Service( "artifactConverter#legacy-to-default" )
75 public class LegacyToDefaultConverter
76     implements ArtifactConverter
77 {
78     /**
79      * {@link List}<{@link Digester}
80      * plexus.requirement role="org.codehaus.plexus.digest.Digester"
81      */
82     private List<? extends Digester> digesters;
83
84     @Inject
85     private PlexusSisuBridge plexusSisuBridge;
86
87     @Inject
88     private DigesterUtils digesterUtils;
89
90     /**
91      * plexus.requirement
92      */
93     private ModelConverter translator;
94
95     /**
96      * plexus.requirement
97      */
98     private ArtifactFactory artifactFactory;
99
100     /**
101      * plexus.requirement
102      */
103     private ArtifactHandlerManager artifactHandlerManager;
104
105     /**
106      * plexus.configuration default-value="false"
107      */
108     private boolean force;
109
110     /**
111      * plexus.configuration default-value="false"
112      */
113     private boolean dryrun;
114
115     private Map<Artifact, List<String>> warnings = new HashMap<Artifact, List<String>>();
116
117     @PostConstruct
118     public void initialize()
119         throws PlexusSisuBridgeException
120     {
121         this.digesters = digesterUtils.getAllDigesters();
122         translator = plexusSisuBridge.lookup( ModelConverter.class );
123         artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class );
124         artifactHandlerManager = plexusSisuBridge.lookup( ArtifactHandlerManager.class );
125     }
126
127     public void convert( Artifact artifact, ArtifactRepository targetRepository )
128         throws ArtifactConversionException
129     {
130         if ( artifact.getRepository().getUrl().equals( targetRepository.getUrl() ) )
131         {
132             throw new ArtifactConversionException( Messages.getString( "exception.repositories.match" ) ); //$NON-NLS-1$
133         }
134
135         if ( !validateMetadata( artifact ) )
136         {
137             addWarning( artifact, Messages.getString( "unable.to.validate.metadata" ) ); //$NON-NLS-1$
138             return;
139         }
140
141         FileTransaction transaction = new FileTransaction();
142
143         if ( !copyPom( artifact, targetRepository, transaction ) )
144         {
145             addWarning( artifact, Messages.getString( "unable.to.copy.pom" ) ); //$NON-NLS-1$
146             return;
147         }
148
149         if ( !copyArtifact( artifact, targetRepository, transaction ) )
150         {
151             addWarning( artifact, Messages.getString( "unable.to.copy.artifact" ) ); //$NON-NLS-1$
152             return;
153         }
154
155         Metadata metadata = createBaseMetadata( artifact );
156         Versioning versioning = new Versioning();
157         versioning.addVersion( artifact.getBaseVersion() );
158         metadata.setVersioning( versioning );
159         updateMetadata( new ArtifactRepositoryMetadata( artifact ), targetRepository, metadata, transaction );
160
161         metadata = createBaseMetadata( artifact );
162         metadata.setVersion( artifact.getBaseVersion() );
163         versioning = new Versioning();
164
165         Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( artifact.getVersion() );
166         if ( matcher.matches() )
167         {
168             Snapshot snapshot = new Snapshot();
169             snapshot.setBuildNumber( Integer.parseInt( matcher.group( 3 ) ) );
170             snapshot.setTimestamp( matcher.group( 2 ) );
171             versioning.setSnapshot( snapshot );
172         }
173
174         // TODO: merge latest/release/snapshot from source instead
175         metadata.setVersioning( versioning );
176         updateMetadata( new SnapshotArtifactRepositoryMetadata( artifact ), targetRepository, metadata, transaction );
177
178         if ( !dryrun )
179         {
180             try
181             {
182                 transaction.commit();
183             }
184             catch ( TransactionException e )
185             {
186                 throw new ArtifactConversionException( Messages.getString( "transaction.failure", e.getMessage() ),
187                                                        e ); //$NON-NLS-1$
188             }
189         }
190     }
191
192     @SuppressWarnings( "unchecked" )
193     private boolean copyPom( Artifact artifact, ArtifactRepository targetRepository, FileTransaction transaction )
194         throws ArtifactConversionException
195     {
196         Artifact pom = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
197                                                               artifact.getVersion() );
198         pom.setBaseVersion( artifact.getBaseVersion() );
199         ArtifactRepository repository = artifact.getRepository();
200         File file = new File( repository.getBasedir(), repository.pathOf( pom ) );
201
202         boolean result = true;
203         if ( file.exists() )
204         {
205             File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pom ) );
206
207             String contents = null;
208             boolean checksumsValid = false;
209             try
210             {
211                 if ( testChecksums( artifact, file ) )
212                 {
213                     checksumsValid = true;
214                 }
215
216                 // Even if the checksums for the POM are invalid we should still convert the POM
217                 contents = FileUtils.readFileToString( file, null );
218             }
219             catch ( IOException e )
220             {
221                 throw new ArtifactConversionException(
222                     Messages.getString( "unable.to.read.source.pom", e.getMessage() ), e ); //$NON-NLS-1$
223             }
224
225             if ( checksumsValid && contents.indexOf( "modelVersion" ) >= 0 ) //$NON-NLS-1$
226             {
227                 // v4 POM
228                 try
229                 {
230                     boolean matching = false;
231                     if ( !force && targetFile.exists() )
232                     {
233                         String targetContents = FileUtils.readFileToString( targetFile, null );
234                         matching = targetContents.equals( contents );
235                     }
236                     if ( force || !matching )
237                     {
238                         transaction.createFile( contents, targetFile, digesters );
239                     }
240                 }
241                 catch ( IOException e )
242                 {
243                     throw new ArtifactConversionException(
244                         Messages.getString( "unable.to.write.target.pom", e.getMessage() ), e ); //$NON-NLS-1$
245                 }
246             }
247             else
248             {
249                 // v3 POM
250                 StringReader stringReader = new StringReader( contents );
251                 StringWriter writer = null;
252                 try
253                 {
254                     org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader v3Reader =
255                         new org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader();
256                     org.apache.maven.model.v3_0_0.Model v3Model = v3Reader.read( stringReader );
257
258                     if ( doRelocation( artifact, v3Model, targetRepository, transaction ) )
259                     {
260                         Artifact relocatedPom =
261                             artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
262                                                                    artifact.getVersion() );
263                         targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( relocatedPom ) );
264                     }
265
266                     Model v4Model = translator.translate( v3Model );
267
268                     translator.validateV4Basics( v4Model, v3Model.getGroupId(), v3Model.getArtifactId(),
269                                                  v3Model.getVersion(), v3Model.getPackage() );
270
271                     writer = new StringWriter();
272                     MavenXpp3Writer Xpp3Writer = new MavenXpp3Writer();
273                     Xpp3Writer.write( writer, v4Model );
274
275                     transaction.createFile( writer.toString(), targetFile, digesters );
276
277                     List<String> warnings = translator.getWarnings();
278
279                     for ( String message : warnings )
280                     {
281                         addWarning( artifact, message );
282                     }
283                 }
284                 catch ( XmlPullParserException e )
285                 {
286                     addWarning( artifact, Messages.getString( "invalid.source.pom", e.getMessage() ) ); //$NON-NLS-1$
287                     result = false;
288                 }
289                 catch ( IOException e )
290                 {
291                     throw new ArtifactConversionException( Messages.getString( "unable.to.write.converted.pom" ),
292                                                            e ); //$NON-NLS-1$
293                 }
294                 catch ( PomTranslationException e )
295                 {
296                     addWarning( artifact, Messages.getString( "invalid.source.pom", e.getMessage() ) ); //$NON-NLS-1$
297                     result = false;
298                 }
299                 finally
300                 {
301                     IOUtils.closeQuietly( writer );
302                 }
303             }
304         }
305         else
306         {
307             addWarning( artifact, Messages.getString( "warning.missing.pom" ) ); //$NON-NLS-1$
308         }
309         return result;
310     }
311
312     private boolean testChecksums( Artifact artifact, File file )
313         throws IOException
314     {
315         boolean result = true;
316         for ( Digester digester : digesters )
317         {
318             result &= verifyChecksum( file, file.getName() + "." + getDigesterFileExtension( digester ), digester,
319                                       //$NON-NLS-1$
320                                       artifact,
321                                       "failure.incorrect." + getDigesterFileExtension( digester ) ); //$NON-NLS-1$
322         }
323         return result;
324     }
325
326     private boolean verifyChecksum( File file, String fileName, Digester digester, Artifact artifact, String key )
327         throws IOException
328     {
329         boolean result = true;
330
331         File checksumFile = new File( file.getParentFile(), fileName );
332         if ( checksumFile.exists() )
333         {
334             String checksum = FileUtils.readFileToString( checksumFile, null );
335             try
336             {
337                 digester.verify( file, checksum );
338             }
339             catch ( DigesterException e )
340             {
341                 addWarning( artifact, Messages.getString( key ) );
342                 result = false;
343             }
344         }
345         return result;
346     }
347
348     /**
349      * File extension for checksums
350      * TODO should be moved to plexus-digester ?
351      */
352     private String getDigesterFileExtension( Digester digester )
353     {
354         return digester.getAlgorithm().toLowerCase().replaceAll( "-", "" ); //$NON-NLS-1$ //$NON-NLS-2$
355     }
356
357     private boolean copyArtifact( Artifact artifact, ArtifactRepository targetRepository, FileTransaction transaction )
358         throws ArtifactConversionException
359     {
360         File sourceFile = artifact.getFile();
361
362         if ( sourceFile.getAbsolutePath().indexOf( "/plugins/" ) > -1 ) //$NON-NLS-1$
363         {
364             artifact.setArtifactHandler( artifactHandlerManager.getArtifactHandler( "maven-plugin" ) ); //$NON-NLS-1$
365         }
366
367         File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
368
369         boolean result = true;
370         try
371         {
372             boolean matching = false;
373             if ( !force && targetFile.exists() )
374             {
375                 matching = FileUtils.contentEquals( sourceFile, targetFile );
376                 if ( !matching )
377                 {
378                     addWarning( artifact, Messages.getString( "failure.target.already.exists" ) ); //$NON-NLS-1$
379                     result = false;
380                 }
381             }
382             if ( result )
383             {
384                 if ( force || !matching )
385                 {
386                     if ( testChecksums( artifact, sourceFile ) )
387                     {
388                         transaction.copyFile( sourceFile, targetFile, digesters );
389                     }
390                     else
391                     {
392                         result = false;
393                     }
394                 }
395             }
396         }
397         catch ( IOException e )
398         {
399             throw new ArtifactConversionException( Messages.getString( "error.copying.artifact" ), e ); //$NON-NLS-1$
400         }
401         return result;
402     }
403
404     private Metadata createBaseMetadata( Artifact artifact )
405     {
406         Metadata metadata = new Metadata();
407         metadata.setArtifactId( artifact.getArtifactId() );
408         metadata.setGroupId( artifact.getGroupId() );
409         return metadata;
410     }
411
412     private Metadata readMetadata( File file )
413         throws ArtifactConversionException
414     {
415         Metadata metadata;
416         MetadataXpp3Reader reader = new MetadataXpp3Reader();
417         FileReader fileReader = null;
418         try
419         {
420             fileReader = new FileReader( file );
421             metadata = reader.read( fileReader );
422         }
423         catch ( FileNotFoundException e )
424         {
425             throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ),
426                                                    e ); //$NON-NLS-1$
427         }
428         catch ( IOException e )
429         {
430             throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ),
431                                                    e ); //$NON-NLS-1$
432         }
433         catch ( XmlPullParserException e )
434         {
435             throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ),
436                                                    e ); //$NON-NLS-1$
437         }
438         finally
439         {
440             IOUtils.closeQuietly( fileReader );
441         }
442         return metadata;
443     }
444
445     private boolean validateMetadata( Artifact artifact )
446         throws ArtifactConversionException
447     {
448         ArtifactRepository repository = artifact.getRepository();
449
450         boolean result = true;
451
452         RepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact );
453         File file =
454             new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) );
455         if ( file.exists() )
456         {
457             Metadata metadata = readMetadata( file );
458             result = validateMetadata( metadata, repositoryMetadata, artifact );
459         }
460
461         repositoryMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
462         file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) );
463         if ( file.exists() )
464         {
465             Metadata metadata = readMetadata( file );
466             result = result && validateMetadata( metadata, repositoryMetadata, artifact );
467         }
468
469         return result;
470     }
471
472     @SuppressWarnings( "unchecked" )
473     private boolean validateMetadata( Metadata metadata, RepositoryMetadata repositoryMetadata, Artifact artifact )
474     {
475         String groupIdKey;
476         String artifactIdKey = null;
477         String snapshotKey = null;
478         String versionKey = null;
479         String versionsKey = null;
480
481         if ( repositoryMetadata.storedInGroupDirectory() )
482         {
483             groupIdKey = "failure.incorrect.groupMetadata.groupId"; //$NON-NLS-1$
484         }
485         else if ( repositoryMetadata.storedInArtifactVersionDirectory() )
486         {
487             groupIdKey = "failure.incorrect.snapshotMetadata.groupId"; //$NON-NLS-1$
488             artifactIdKey = "failure.incorrect.snapshotMetadata.artifactId"; //$NON-NLS-1$
489             versionKey = "failure.incorrect.snapshotMetadata.version"; //$NON-NLS-1$
490             snapshotKey = "failure.incorrect.snapshotMetadata.snapshot"; //$NON-NLS-1$
491         }
492         else
493         {
494             groupIdKey = "failure.incorrect.artifactMetadata.groupId"; //$NON-NLS-1$
495             artifactIdKey = "failure.incorrect.artifactMetadata.artifactId"; //$NON-NLS-1$
496             versionsKey = "failure.incorrect.artifactMetadata.versions"; //$NON-NLS-1$
497         }
498
499         boolean result = true;
500
501         if ( metadata.getGroupId() == null || !metadata.getGroupId().equals( artifact.getGroupId() ) )
502         {
503             addWarning( artifact, Messages.getString( groupIdKey ) );
504             result = false;
505         }
506         if ( !repositoryMetadata.storedInGroupDirectory() )
507         {
508             if ( metadata.getGroupId() == null || !metadata.getArtifactId().equals( artifact.getArtifactId() ) )
509             {
510                 addWarning( artifact, Messages.getString( artifactIdKey ) );
511                 result = false;
512             }
513             if ( !repositoryMetadata.storedInArtifactVersionDirectory() )
514             {
515                 // artifact metadata
516
517                 boolean foundVersion = false;
518                 if ( metadata.getVersioning() != null )
519                 {
520                     for ( String version : (List<String>) metadata.getVersioning().getVersions() )
521                     {
522                         if ( version.equals( artifact.getBaseVersion() ) )
523                         {
524                             foundVersion = true;
525                             break;
526                         }
527                     }
528                 }
529
530                 if ( !foundVersion )
531                 {
532                     addWarning( artifact, Messages.getString( versionsKey ) );
533                     result = false;
534                 }
535             }
536             else
537             {
538                 // snapshot metadata
539                 if ( !artifact.getBaseVersion().equals( metadata.getVersion() ) )
540                 {
541                     addWarning( artifact, Messages.getString( versionKey ) );
542                     result = false;
543                 }
544
545                 if ( artifact.isSnapshot() )
546                 {
547                     Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( artifact.getVersion() );
548                     if ( matcher.matches() )
549                     {
550                         boolean correct = false;
551                         if ( metadata.getVersioning() != null && metadata.getVersioning().getSnapshot() != null )
552                         {
553                             Snapshot snapshot = metadata.getVersioning().getSnapshot();
554                             int build = Integer.parseInt( matcher.group( 3 ) );
555                             String ts = matcher.group( 2 );
556                             if ( build == snapshot.getBuildNumber() && ts.equals( snapshot.getTimestamp() ) )
557                             {
558                                 correct = true;
559                             }
560                         }
561
562                         if ( !correct )
563                         {
564                             addWarning( artifact, Messages.getString( snapshotKey ) );
565                             result = false;
566                         }
567                     }
568                 }
569             }
570         }
571         return result;
572     }
573
574     private void updateMetadata( RepositoryMetadata artifactMetadata, ArtifactRepository targetRepository,
575                                  Metadata newMetadata, FileTransaction transaction )
576         throws ArtifactConversionException
577     {
578         File file = new File( targetRepository.getBasedir(),
579                               targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
580
581         Metadata metadata;
582         boolean changed;
583
584         if ( file.exists() )
585         {
586             metadata = readMetadata( file );
587             changed = metadata.merge( newMetadata );
588         }
589         else
590         {
591             changed = true;
592             metadata = newMetadata;
593         }
594
595         if ( changed )
596         {
597             StringWriter writer = null;
598             try
599             {
600                 writer = new StringWriter();
601
602                 MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer();
603
604                 mappingWriter.write( writer, metadata );
605
606                 transaction.createFile( writer.toString(), file, digesters );
607             }
608             catch ( IOException e )
609             {
610                 throw new ArtifactConversionException( Messages.getString( "error.writing.target.metadata" ),
611                                                        e ); //$NON-NLS-1$
612             }
613             finally
614             {
615                 IOUtils.closeQuietly( writer );
616             }
617         }
618     }
619
620     private boolean doRelocation( Artifact artifact, org.apache.maven.model.v3_0_0.Model v3Model,
621                                   ArtifactRepository repository, FileTransaction transaction )
622         throws IOException
623     {
624         Properties properties = v3Model.getProperties();
625         if ( properties.containsKey( "relocated.groupId" ) || properties.containsKey( "relocated.artifactId" )
626             //$NON-NLS-1$ //$NON-NLS-2$
627             || properties.containsKey( "relocated.version" ) ) //$NON-NLS-1$
628         {
629             String newGroupId = properties.getProperty( "relocated.groupId", v3Model.getGroupId() ); //$NON-NLS-1$
630             properties.remove( "relocated.groupId" ); //$NON-NLS-1$
631
632             String newArtifactId =
633                 properties.getProperty( "relocated.artifactId", v3Model.getArtifactId() ); //$NON-NLS-1$
634             properties.remove( "relocated.artifactId" ); //$NON-NLS-1$
635
636             String newVersion = properties.getProperty( "relocated.version", v3Model.getVersion() ); //$NON-NLS-1$
637             properties.remove( "relocated.version" ); //$NON-NLS-1$
638
639             String message = properties.getProperty( "relocated.message", "" ); //$NON-NLS-1$ //$NON-NLS-2$
640             properties.remove( "relocated.message" ); //$NON-NLS-1$
641
642             if ( properties.isEmpty() )
643             {
644                 v3Model.setProperties( null );
645             }
646
647             writeRelocationPom( v3Model.getGroupId(), v3Model.getArtifactId(), v3Model.getVersion(), newGroupId,
648                                 newArtifactId, newVersion, message, repository, transaction );
649
650             v3Model.setGroupId( newGroupId );
651             v3Model.setArtifactId( newArtifactId );
652             v3Model.setVersion( newVersion );
653
654             artifact.setGroupId( newGroupId );
655             artifact.setArtifactId( newArtifactId );
656             artifact.setVersion( newVersion );
657
658             return true;
659         }
660         else
661         {
662             return false;
663         }
664     }
665
666     private void writeRelocationPom( String groupId, String artifactId, String version, String newGroupId,
667                                      String newArtifactId, String newVersion, String message,
668                                      ArtifactRepository repository, FileTransaction transaction )
669         throws IOException
670     {
671         Model pom = new Model();
672         pom.setGroupId( groupId );
673         pom.setArtifactId( artifactId );
674         pom.setVersion( version );
675
676         DistributionManagement dMngt = new DistributionManagement();
677
678         Relocation relocation = new Relocation();
679         relocation.setGroupId( newGroupId );
680         relocation.setArtifactId( newArtifactId );
681         relocation.setVersion( newVersion );
682         if ( message != null && message.length() > 0 )
683         {
684             relocation.setMessage( message );
685         }
686
687         dMngt.setRelocation( relocation );
688
689         pom.setDistributionManagement( dMngt );
690
691         Artifact artifact = artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" ); //$NON-NLS-1$
692         File pomFile = new File( repository.getBasedir(), repository.pathOf( artifact ) );
693
694         StringWriter strWriter = new StringWriter();
695         MavenXpp3Writer pomWriter = new MavenXpp3Writer();
696         pomWriter.write( strWriter, pom );
697
698         transaction.createFile( strWriter.toString(), pomFile, digesters );
699     }
700
701     private void addWarning( Artifact artifact, String message )
702     {
703         List<String> messages = warnings.get( artifact );
704         if ( messages == null )
705         {
706             messages = new ArrayList<String>();
707         }
708         messages.add( message );
709         warnings.put( artifact, messages );
710     }
711
712     public void clearWarnings()
713     {
714         warnings.clear();
715     }
716
717     public Map<Artifact, List<String>> getWarnings()
718     {
719         return warnings;
720     }
721
722
723     public List<? extends Digester> getDigesters()
724     {
725         return digesters;
726     }
727
728     public void setDigesters( List<Digester> digesters )
729     {
730         this.digesters = digesters;
731     }
732
733     public ModelConverter getTranslator()
734     {
735         return translator;
736     }
737
738     public void setTranslator( ModelConverter translator )
739     {
740         this.translator = translator;
741     }
742
743     public ArtifactFactory getArtifactFactory()
744     {
745         return artifactFactory;
746     }
747
748     public void setArtifactFactory( ArtifactFactory artifactFactory )
749     {
750         this.artifactFactory = artifactFactory;
751     }
752
753     public ArtifactHandlerManager getArtifactHandlerManager()
754     {
755         return artifactHandlerManager;
756     }
757
758     public void setArtifactHandlerManager( ArtifactHandlerManager artifactHandlerManager )
759     {
760         this.artifactHandlerManager = artifactHandlerManager;
761     }
762
763     public boolean isForce()
764     {
765         return force;
766     }
767
768     public void setForce( boolean force )
769     {
770         this.force = force;
771     }
772
773     public boolean isDryrun()
774     {
775         return dryrun;
776     }
777
778     public void setDryrun( boolean dryrun )
779     {
780         this.dryrun = dryrun;
781     }
782 }