1   package org.apache.maven.artifact.resolver;
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.util.Collections;
23  
24  import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.artifact.resolver.DefaultArtifactResolver.DaemonThreadCreator;
27  
28  public class DefaultArtifactResolverTest
29      extends AbstractArtifactComponentTestCase
30  {
31      private DefaultArtifactResolver artifactResolver;
32  
33      private Artifact projectArtifact;
34  
35      @Override
36      protected void setUp()
37          throws Exception
38      {
39          super.setUp();
40  
41          artifactResolver = (DefaultArtifactResolver) lookup( ArtifactResolver.class );
42  
43          projectArtifact = createLocalArtifact( "project", "3.0" );
44      }
45  
46      @Override
47      protected void tearDown()
48          throws Exception
49      {
50          artifactFactory = null;
51          projectArtifact = null;
52          super.tearDown();
53      }
54  
55      @Override
56      protected String component()
57      {
58          return "resolver";
59      }
60  
61      public void testMNG4738()
62          throws Exception
63      {
64          Artifact g = createLocalArtifact( "g", "1.0" );
65          createLocalArtifact( "h", "1.0" );
66          artifactResolver.resolveTransitively( Collections.singleton( g ), projectArtifact, remoteRepositories(),
67                                                localRepository(), null );
68  
69          // we want to see all top-level thread groups
70          ThreadGroup tg = Thread.currentThread().getThreadGroup();
71          while ( !( tg.getParent() != null ) )
72          {
73              tg = tg.getParent();
74          }
75  
76          ThreadGroup[] tgList = new ThreadGroup[tg.activeGroupCount()];
77          tg.enumerate( tgList );
78  
79          boolean seen = false;
80  
81          for ( int i = 0; i < tgList.length; i++ )
82          {
83              if ( !tgList[i].getName().equals( DaemonThreadCreator.THREADGROUP_NAME ) )
84              {
85                  continue;
86              }
87  
88              seen = true;
89  
90              tg = tgList[i];
91              Thread[] ts = new Thread[tg.activeCount()];
92              tg.enumerate( ts );
93  
94              for ( Thread active : ts )
95              {
96                  String name = active.getName();
97                  boolean daemon = active.isDaemon();
98                  assertTrue( name + " is no daemon Thread.", daemon );
99              }
100 
101         }
102 
103         assertTrue( "Could not find ThreadGroup: " + DaemonThreadCreator.THREADGROUP_NAME, seen );
104     }
105 
106     public void testLookup()
107         throws Exception
108     {
109         ArtifactResolver resolver = lookup( ArtifactResolver.class, "default" );
110     }
111 }