View Javadoc
1   package org.apache.maven.it;
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.maven.it.util.ResourceExtractor;
23  import org.apache.maven.shared.utils.io.FileUtils;
24  import org.codehaus.plexus.util.xml.Xpp3Dom;
25  import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
26  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
27  
28  import java.io.File;
29  import java.io.FileReader;
30  import java.io.IOException;
31  
32  /**
33   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-3441">MNG-3441</a>.
34   *
35   *
36   */
37  public class MavenITmng3441MetadataUpdatedFromDeploymentRepositoryTest
38      extends AbstractMavenIntegrationTestCase
39  {
40      public MavenITmng3441MetadataUpdatedFromDeploymentRepositoryTest()
41      {
42          super( "(2.0.8,)" );
43      }
44  
45      public void testitMNG3441()
46          throws Exception
47      {
48          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3441" );
49  
50          File targetRepository = new File( testDir, "target-repo" );
51          FileUtils.deleteDirectory( targetRepository );
52          FileUtils.copyDirectoryStructure( new File( testDir, "deploy-repo" ), targetRepository );
53  
54          Verifier verifier;
55  
56          verifier = newVerifier( testDir.getAbsolutePath(), "remote" );
57  
58          verifier.addCliOption( "-s" );
59          verifier.addCliOption( "settings.xml" );
60          verifier.executeGoal( "deploy" );
61  
62          verifier.verifyErrorFreeLog();
63  
64          Xpp3Dom dom = readDom( new File( targetRepository,
65                                           "org/apache/maven/its/mng3441/test-artifact/1.0-SNAPSHOT/maven-metadata.xml"
66          ) );
67          assertEquals( "2", dom.getChild( "versioning" ).getChild( "snapshot" ).getChild( "buildNumber" ).getValue() );
68  
69          dom = readDom( new File( targetRepository, "org/apache/maven/its/mng3441/maven-metadata.xml" ) );
70          Xpp3Dom[] plugins = dom.getChild( "plugins" ).getChildren();
71          assertEquals( "other-plugin", plugins[0].getChild( "prefix" ).getValue() );
72          assertEquals( "test-artifact", plugins[1].getChild( "prefix" ).getValue() );
73  
74          verifier.resetStreams();
75      }
76  
77      private Xpp3Dom readDom( File file )
78          throws XmlPullParserException, IOException
79      {
80          try ( FileReader reader = new FileReader( file ) )
81          {
82              return Xpp3DomBuilder.build( reader );
83          }
84      }
85  }