View Javadoc
1   package org.apache.maven;
2   
3   import org.apache.maven.artifact.Artifact;
4   import org.apache.maven.artifact.DefaultArtifact;
5   import org.apache.maven.execution.MavenExecutionRequest;
6   import org.apache.maven.execution.MavenExecutionResult;
7   import org.apache.maven.project.MavenProject;
8   import org.apache.maven.project.MavenProjectHelper;
9   
10  import java.io.File;
11  import java.nio.file.Files;
12  
13  import static java.util.Arrays.asList;
14  
15  /*
16   * Licensed to the Apache Software Foundation (ASF) under one
17   * or more contributor license agreements.  See the NOTICE file
18   * distributed with this work for additional information
19   * regarding copyright ownership.  The ASF licenses this file
20   * to you under the Apache License, Version 2.0 (the
21   * "License"); you may not use this file except in compliance
22   * with the License.  You may obtain a copy of the License at
23   *
24   *  http://www.apache.org/licenses/LICENSE-2.0
25   *
26   * Unless required by applicable law or agreed to in writing,
27   * software distributed under the License is distributed on an
28   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
29   * KIND, either express or implied.  See the License for the
30   * specific language governing permissions and limitations
31   * under the License.
32   */
33  public class DefaultMavenTest
34      extends AbstractCoreMavenComponentTestCase
35  {
36  
37      public void testThatErrorDuringProjectDependencyGraphCreationAreStored()
38              throws Exception
39      {
40          Maven maven = getContainer().lookup( Maven.class );
41          MavenExecutionRequest request = createMavenExecutionRequest( getProject( "cyclic-reference" ) ).setGoals( asList("validate") );
42  
43          MavenExecutionResult result = maven.execute( request );
44  
45          assertEquals( ProjectCycleException.class, result.getExceptions().get( 0 ).getClass() );
46      }
47  
48      @Override
49      protected String getProjectsDirectory()
50      {
51          return "src/test/projects/default-maven";
52      }
53  
54  
55      public void testMavenProjectNoDuplicateArtifacts()
56          throws Exception
57      {
58          MavenProjectHelper mavenProjectHelper = lookup( MavenProjectHelper.class );
59          MavenProject mavenProject = new MavenProject();
60          mavenProject.setArtifact( new DefaultArtifact( "g", "a", "1.0", Artifact.SCOPE_TEST, "jar", "", null ) );
61          File artifactFile = Files.createTempFile( "foo", "tmp").toFile();
62          try
63          {
64              mavenProjectHelper.attachArtifact( mavenProject, "sources", artifactFile );
65              assertEquals( 1, mavenProject.getAttachedArtifacts().size() );
66              mavenProjectHelper.attachArtifact( mavenProject, "sources", artifactFile );
67              assertEquals( 1, mavenProject.getAttachedArtifacts().size() );
68          } finally
69          {
70              Files.deleteIfExists( artifactFile.toPath() );
71          }
72      }
73  
74  }