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