Advertisement
aslak

Arquillian - Maven3 - Pom Resolver speed test

Jul 15th, 2010
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.02 KB | None | 0 0
  1. /*
  2.  * JBoss, Home of Professional Open Source
  3.  * Copyright 2009, Red Hat Middleware LLC, and individual contributors
  4.  * by the @authors tag. See the copyright.txt in the distribution for a
  5.  * full listing of individual contributors.
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  * http://www.apache.org/licenses/LICENSE-2.0
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jboss.shrinkwrap.maven;
  18.  
  19. import java.io.File;
  20. import java.util.Set;
  21.  
  22. import org.apache.maven.artifact.Artifact;
  23. import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
  24. import org.apache.maven.artifact.repository.MavenArtifactRepository;
  25. import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
  26. import org.apache.maven.project.DefaultProjectBuildingRequest;
  27. import org.apache.maven.project.MavenProject;
  28. import org.apache.maven.project.ProjectBuilder;
  29. import org.apache.maven.project.ProjectBuildingRequest;
  30. import org.apache.maven.project.ProjectBuildingResult;
  31. import org.codehaus.plexus.DefaultPlexusContainer;
  32. import org.codehaus.plexus.logging.console.ConsoleLoggerManager;
  33. import org.junit.Before;
  34. import org.junit.Test;
  35.  
  36. /**
  37.  * MavenIntegrationTestCase
  38.  *
  39.  * @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
  40.  * @version $Revision: $
  41.  */
  42. public class MavenIntegrationTestCase
  43. {
  44.    private DefaultPlexusContainer container;
  45.    private ProjectBuilder builder;
  46.    
  47.    @Before
  48.    public void startUp() throws Exception
  49.    {
  50.       long start = System.currentTimeMillis();
  51.       container = new DefaultPlexusContainer();
  52.       container.setLoggerManager(new ConsoleLoggerManager("ERROR"));
  53.      
  54.       builder = container.lookup(ProjectBuilder.class);
  55.      
  56.       System.out.println("[@Before] " + (System.currentTimeMillis() - start));
  57.    }
  58.    
  59.    @Test
  60.    public void readAllTestArtifacs() throws Exception
  61.    {
  62.       File[] poms = new File[]{
  63.             new File("pom.xml"),
  64.             new File("../pom.xml"),
  65.             new File("../extension-classloader/pom.xml"),
  66.             new File("../extension-vdf/pom.xml"),
  67.             new File("../extension-vfs3/pom.xml"),
  68.             new File("../extension-openejb/pom.xml"),
  69.             new File("../extension-glassfish/pom.xml"),
  70.             new File("../api/pom.xml"),
  71.             new File("../impl-base/pom.xml"),
  72.             new File("../spi/pom.xml")
  73.       };
  74.       for(int i = 0; i < 10; i++)
  75.       {
  76.          
  77.          File pom = poms[i];
  78.          
  79.          long start = System.currentTimeMillis();
  80.          int numbersResolved = requestDependencies(pom);
  81.          System.out.println("[" + numbersResolved + "] " + "[" + (System.currentTimeMillis() - start) + "] "  + pom.getPath());
  82.       }
  83.    }
  84.    
  85.    public int requestDependencies(File pom) throws Exception
  86.    {
  87.       ProjectBuildingRequest request = new DefaultProjectBuildingRequest();
  88.       request.setLocalRepository(new MavenArtifactRepository(
  89.             "local",
  90.             "file:///home/aslak/.m2/repository",
  91.             container.lookup(ArtifactRepositoryLayout.class),
  92.             new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN),
  93.             new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN)));
  94.      
  95.       request.setResolveDependencies(true);
  96.       request.setOffline(true);
  97.      
  98.       ProjectBuildingResult result = builder.build(pom, request);
  99.      
  100.       Set<Artifact> artifacts = result.getArtifactResolutionResult().getArtifacts();
  101.       return artifacts.size();
  102.    }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement