1 package org.kuali.maven.plugins.spring.config; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import org.apache.maven.plugin.AbstractMojo; 7 import org.apache.maven.project.MavenProject; 8 import org.kuali.common.util.PropertyUtils; 9 import org.kuali.maven.plugins.spring.LoadMojo; 10 import org.kuali.maven.plugins.spring.MojoRunner; 11 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.context.annotation.Bean; 13 import org.springframework.context.annotation.Configuration; 14 import org.springframework.context.annotation.Import; 15 16 import edu.calpoly.records.spring.ThreadsafeTestConfig; 17 18 @Configuration 19 @Import(BaseMojoTestConfig.class) 20 public class LoadMojoTestConfig { 21 22 @Autowired 23 BaseMojoTestConfig baseConfig; 24 25 @Bean 26 public AbstractMojo mojo() { 27 MavenProject project = baseConfig.mavenProject(); 28 29 List<Thread> threads = new ArrayList<Thread>(); 30 ThreadGroup group = new ThreadGroup("threads"); 31 for (int i = 0; i < 8; i++) { 32 33 LoadMojo mojo = new LoadMojo(); 34 mojo.setProject(project); 35 mojo.setProperties(PropertyUtils.EMPTY); 36 mojo.setAnnotatedClass(ThreadsafeTestConfig.class.getName()); 37 38 Runnable target = new MojoRunner(mojo); 39 Thread thread = new Thread(group, target, "mojo-runner-" + i); 40 threads.add(thread); 41 } 42 start(threads); 43 wait(threads); 44 return null; 45 } 46 47 protected void start(List<Thread> threads) { 48 for (Thread thread : threads) { 49 thread.start(); 50 } 51 } 52 53 protected void wait(List<Thread> threads) { 54 for (Thread thread : threads) { 55 try { 56 thread.join(); 57 } catch (InterruptedException e) { 58 throw new IllegalStateException(e); 59 } 60 } 61 } 62 }