001 package org.apache.maven.artifact.resolver; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 import java.util.Collections; 023 024 import org.apache.maven.artifact.AbstractArtifactComponentTestCase; 025 import org.apache.maven.artifact.Artifact; 026 import org.apache.maven.artifact.resolver.DefaultArtifactResolver.DaemonThreadCreator; 027 028 public class DefaultArtifactResolverTest 029 extends AbstractArtifactComponentTestCase 030 { 031 private DefaultArtifactResolver artifactResolver; 032 033 private Artifact projectArtifact; 034 035 @Override 036 protected void setUp() 037 throws Exception 038 { 039 super.setUp(); 040 041 artifactResolver = (DefaultArtifactResolver) lookup( ArtifactResolver.class ); 042 043 projectArtifact = createLocalArtifact( "project", "3.0" ); 044 } 045 046 @Override 047 protected void tearDown() 048 throws Exception 049 { 050 artifactFactory = null; 051 projectArtifact = null; 052 super.tearDown(); 053 } 054 055 @Override 056 protected String component() 057 { 058 return "resolver"; 059 } 060 061 public void testMNG4738() 062 throws Exception 063 { 064 Artifact g = createLocalArtifact( "g", "1.0" ); 065 createLocalArtifact( "h", "1.0" ); 066 artifactResolver.resolveTransitively( Collections.singleton( g ), projectArtifact, remoteRepositories(), 067 localRepository(), null ); 068 069 // we want to see all top-level thread groups 070 ThreadGroup tg = Thread.currentThread().getThreadGroup(); 071 while ( !( tg.getParent() != null ) ) 072 { 073 tg = tg.getParent(); 074 } 075 076 ThreadGroup[] tgList = new ThreadGroup[tg.activeGroupCount()]; 077 tg.enumerate( tgList ); 078 079 boolean seen = false; 080 081 for ( int i = 0; i < tgList.length; i++ ) 082 { 083 if ( !tgList[i].getName().equals( DaemonThreadCreator.THREADGROUP_NAME ) ) 084 { 085 continue; 086 } 087 088 seen = true; 089 090 tg = tgList[i]; 091 Thread[] ts = new Thread[tg.activeCount()]; 092 tg.enumerate( ts ); 093 094 for ( Thread active : ts ) 095 { 096 String name = active.getName(); 097 boolean daemon = active.isDaemon(); 098 assertTrue( name + " is no daemon Thread.", daemon ); 099 } 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 }