View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.artifact.resolver;
20  
21  import java.util.Collections;
22  
23  import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.artifact.resolver.DefaultArtifactResolver.DaemonThreadCreator;
26  
27  public class DefaultArtifactResolverTest extends AbstractArtifactComponentTestCase {
28      private DefaultArtifactResolver artifactResolver;
29  
30      private Artifact projectArtifact;
31  
32      @Override
33      protected void setUp() throws Exception {
34          super.setUp();
35  
36          artifactResolver = (DefaultArtifactResolver) lookup(ArtifactResolver.class);
37  
38          projectArtifact = createLocalArtifact("project", "3.0");
39      }
40  
41      @Override
42      protected void tearDown() throws Exception {
43          artifactFactory = null;
44          projectArtifact = null;
45          super.tearDown();
46      }
47  
48      @Override
49      protected String component() {
50          return "resolver";
51      }
52  
53      public void testMNG4738() throws Exception {
54          Artifact g = createLocalArtifact("g", "1.0");
55          createLocalArtifact("h", "1.0");
56          artifactResolver.resolveTransitively(
57                  Collections.singleton(g), projectArtifact, remoteRepositories(), localRepository(), null);
58  
59          // we want to see all top-level thread groups
60          ThreadGroup tg = Thread.currentThread().getThreadGroup();
61          while (tg.getParent() == null) {
62              tg = tg.getParent();
63          }
64  
65          ThreadGroup[] tgList = new ThreadGroup[tg.activeGroupCount()];
66          tg.enumerate(tgList);
67  
68          boolean seen = false;
69  
70          for (ThreadGroup aTgList : tgList) {
71              if (!aTgList.getName().equals(DaemonThreadCreator.THREADGROUP_NAME)) {
72                  continue;
73              }
74  
75              seen = true;
76  
77              tg = aTgList;
78              Thread[] ts = new Thread[tg.activeCount()];
79              tg.enumerate(ts);
80  
81              for (Thread active : ts) {
82                  String name = active.getName();
83                  boolean daemon = active.isDaemon();
84                  assertTrue(name + " is no daemon Thread.", daemon);
85              }
86          }
87  
88          assertTrue("Could not find ThreadGroup: " + DaemonThreadCreator.THREADGROUP_NAME, seen);
89      }
90  
91      public void testLookup() throws Exception {
92          ArtifactResolver resolver = lookup(ArtifactResolver.class, "default");
93      }
94  }