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