View Javadoc
1   package org.apache.maven.shared.artifact.install.internal;
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  import java.util.Arrays;
24  import java.util.Collection;
25  
26  import org.apache.maven.artifact.Artifact;
27  import org.apache.maven.artifact.DefaultArtifact;
28  import org.apache.maven.artifact.handler.DefaultArtifactHandler;
29  import org.apache.maven.project.DefaultProjectBuildingRequest;
30  import org.apache.maven.repository.internal.MavenRepositorySystemSession;
31  import org.apache.maven.shared.artifact.install.ArtifactInstaller;
32  import org.codehaus.plexus.PlexusTestCase;
33  import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
34  
35  public class Maven30ArtifactInstallerTest extends PlexusTestCase
36  {
37      private final File localRepo = new File( "target/tests/local-repo" );
38      
39      private Maven30ArtifactInstaller installer;
40  
41      @Override
42      public void setUp() throws Exception
43      {
44          super.setUp();
45          installer = (Maven30ArtifactInstaller) super.lookup( ArtifactInstaller.class, "maven3" );
46      }
47  
48      public void testInstall() throws Exception
49      {
50          DefaultProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
51          MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
52          repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
53          buildingRequest.setRepositorySession( repositorySession );
54          
55          DefaultArtifactHandler artifactHandler = new DefaultArtifactHandler();
56          artifactHandler.setExtension( "EXTENSION" );
57  
58          File artifactsDirectory = new File( "target/tests/artifacts" );
59          artifactsDirectory.mkdirs();
60          File tmpFile = File.createTempFile( "test-install", ".jar", artifactsDirectory );
61          
62          DefaultArtifact artifact = new DefaultArtifact( "GROUPID", "ARTIFACTID", "VERSION", "compile", "jar", null, artifactHandler );
63          artifact.setFile( tmpFile );
64          DefaultArtifact artifactWithClassifier = new DefaultArtifact( "GROUPID", "ARTIFACTID", "VERSION", "compile", "jar", "CLASSIFIER", artifactHandler );
65          artifactWithClassifier.setFile( tmpFile );
66          
67          Collection<Artifact> mavenArtifacts = Arrays.<Artifact>asList( artifact, artifactWithClassifier );
68          
69          installer.install( buildingRequest, mavenArtifacts );
70          
71          assertTrue( new File( localRepo, "GROUPID/ARTIFACTID/VERSION/ARTIFACTID-VERSION.EXTENSION" ).exists() );
72          assertTrue( new File( localRepo, "GROUPID/ARTIFACTID/VERSION/ARTIFACTID-VERSION-CLASSIFIER.EXTENSION" ).exists() );
73          assertTrue( new File( localRepo, "GROUPID/ARTIFACTID/maven-metadata-local.xml" ).exists() ); //??
74      }
75  }