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