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