View Javadoc
1   package org.apache.maven.shared.test.plugin;
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 java.io.File;
23  
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.artifact.factory.ArtifactFactory;
26  import org.apache.maven.project.MavenProject;
27  import org.apache.maven.project.artifact.ProjectArtifactMetadata;
28  import org.apache.maven.shared.tools.easymock.TestFileManager;
29  import org.codehaus.plexus.ContainerConfiguration;
30  import org.codehaus.plexus.PlexusConstants;
31  import org.codehaus.plexus.PlexusTestCase;
32  
33  /**
34   * @version $Id$
35   */
36  public class RepositoryToolTest
37      extends PlexusTestCase
38  {
39      private TestFileManager fileManager;
40  
41      public void setUp()
42          throws Exception
43      {
44          super.setUp();
45  
46          fileManager = new TestFileManager( "RepositoryToolTest.", "" );
47      }
48  
49      public void tearDown()
50          throws Exception
51      {
52          super.tearDown();
53  
54          fileManager.cleanUp();
55      }
56  
57      public void testCreateLocalRepositoryFromPlugin_ShouldWriteJarAndPom()
58          throws Exception
59      {
60          RepositoryTool repoTool = (RepositoryTool) lookup( RepositoryTool.ROLE, "default" );
61  
62          File tempDir = fileManager.createTempDir();
63  
64          String pomContent = "<project><modelVersion>4.0.0</modelVersion></project>";
65          String jarContent = "This is a test";
66  
67          File pom = fileManager.createFile( tempDir, "pom.xml", pomContent );
68          File jar = fileManager.createFile( tempDir, "artifact-test.jar", jarContent );
69  
70          MavenProject pluginProject = new MavenProject();
71  
72          ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
73  
74          Artifact pluginArtifact = artifactFactory.createArtifact( "group", "artifact", "test", null, "jar" );
75          pluginArtifact.setFile( jar );
76          pluginArtifact.addMetadata( new ProjectArtifactMetadata( pluginArtifact, pom ) );
77  
78          pluginProject.setArtifact( pluginArtifact );
79          pluginProject.setFile( pom );
80  
81          File targetLocalRepoBasedir = fileManager.createTempDir();
82  
83          repoTool.createLocalRepositoryFromComponentProject( pluginProject, pom, targetLocalRepoBasedir );
84  
85          fileManager.assertFileExistence( targetLocalRepoBasedir, "group/artifact/test/artifact-test.pom", true );
86          fileManager.assertFileContents( targetLocalRepoBasedir, "group/artifact/test/artifact-test.jar", jarContent );
87  
88      }
89      
90      @Override
91      protected void customizeContainerConfiguration(ContainerConfiguration configuration) 
92      {
93          configuration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
94          configuration.setAutoWiring( true );      
95      }    
96  }