Search in sources :

Example 1 with DefaultRepositorySystemSession

use of org.sonatype.aether.util.DefaultRepositorySystemSession in project sonatype-aether by sonatype.

the class AsyncHandlerExceptionTest method testIt.

@Test
public void testIt() throws Exception {
    HttpServer server = new HttpServer();
    server.addResources("/", baseDir.getAbsolutePath());
    server.start();
    try {
        RemoteRepository repo = new RemoteRepository("id", "default", server.getHttpUrl() + "/repo");
        RepositorySystemSession session = new DefaultRepositorySystemSession();
        AsyncRepositoryConnector connector = new AsyncRepositoryConnector(repo, session, new TestFileProcessor(), new SysoutLogger());
        try {
            StubArtifact artifact = new StubArtifact("gid:aid:1.0");
            for (int i = 0; i < 16; i++) {
                System.out.println("RUN #" + i);
                TestFileUtils.delete(baseDir);
                ArtifactDownload download = new ArtifactDownload(artifact, "project", new File(baseDir, "a.jar"), "ignore");
                System.out.println("GET");
                connector.get(Arrays.asList(download), null);
                assertTrue(String.valueOf(download.getException()), download.getException() instanceof ArtifactNotFoundException);
                ArtifactUpload upload = new ArtifactUpload(artifact, new File("pom.xml"));
                System.out.println("PUT");
                connector.put(Arrays.asList(upload), null);
                if (upload.getException() != null) {
                    upload.getException().printStackTrace();
                }
                assertNull(String.valueOf(upload.getException()), upload.getException());
            }
        } finally {
            connector.close();
        }
    } finally {
        server.stop();
    }
}
Also used : RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) SysoutLogger(org.sonatype.aether.test.impl.SysoutLogger) ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) TestFileProcessor(org.sonatype.aether.test.impl.TestFileProcessor) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) File(java.io.File) ArtifactNotFoundException(org.sonatype.aether.transfer.ArtifactNotFoundException) Test(org.junit.Test)

Example 2 with DefaultRepositorySystemSession

use of org.sonatype.aether.util.DefaultRepositorySystemSession in project gradle by gradle.

the class MavenProjectsCreator method createNow.

private Set<MavenProject> createNow(Settings settings, File pomFile) throws PlexusContainerException, PlexusConfigurationException, ComponentLookupException, MavenExecutionRequestPopulationException, ProjectBuildingException {
    ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration().setClassWorld(new ClassWorld("plexus.core", ClassWorld.class.getClassLoader())).setName("mavenCore");
    DefaultPlexusContainer container = new DefaultPlexusContainer(containerConfiguration);
    ProjectBuilder builder = container.lookup(ProjectBuilder.class);
    MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
    final Properties properties = new Properties();
    properties.putAll(SystemProperties.getInstance().asMap());
    executionRequest.setSystemProperties(properties);
    MavenExecutionRequestPopulator populator = container.lookup(MavenExecutionRequestPopulator.class);
    populator.populateFromSettings(executionRequest, settings);
    populator.populateDefaults(executionRequest);
    ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
    buildingRequest.setProcessPlugins(false);
    MavenProject mavenProject = builder.build(pomFile, buildingRequest).getProject();
    Set<MavenProject> reactorProjects = new LinkedHashSet<MavenProject>();
    //TODO adding the parent project first because the converter needs it this way ATM. This is oversimplified.
    //the converter should not depend on the order of reactor projects.
    //we should add coverage for nested multi-project builds with multiple parents.
    reactorProjects.add(mavenProject);
    List<ProjectBuildingResult> allProjects = builder.build(ImmutableList.of(pomFile), true, buildingRequest);
    CollectionUtils.collect(allProjects, reactorProjects, new Transformer<MavenProject, ProjectBuildingResult>() {

        public MavenProject transform(ProjectBuildingResult original) {
            return original.getProject();
        }
    });
    MavenExecutionResult result = new DefaultMavenExecutionResult();
    result.setProject(mavenProject);
    RepositorySystemSession repoSession = new DefaultRepositorySystemSession();
    MavenSession session = new MavenSession(container, repoSession, executionRequest, result);
    session.setCurrentProject(mavenProject);
    return reactorProjects;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) ClassWorld(org.codehaus.plexus.classworlds.ClassWorld) Properties(java.util.Properties) SystemProperties(org.gradle.internal.SystemProperties) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) ContainerConfiguration(org.codehaus.plexus.ContainerConfiguration) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession)

Example 3 with DefaultRepositorySystemSession

use of org.sonatype.aether.util.DefaultRepositorySystemSession in project karaf by apache.

the class Dependency30Helper method getDependencyTree.

private DependencyNode getDependencyTree(Artifact artifact) throws MojoExecutionException {
    try {
        CollectRequest collectRequest = new CollectRequest(new Dependency(artifact, "compile"), null, projectRepositories);
        DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession);
        session.setDependencySelector(new AndDependencySelector(new OptionalDependencySelector(), new ScopeDependencySelector1(), new ExclusionDependencySelector()));
        DependencyGraphTransformer transformer = new ChainedDependencyGraphTransformer(new ConflictMarker(), new JavaEffectiveScopeCalculator(), new JavaDependencyContextRefiner());
        session.setDependencyGraphTransformer(transformer);
        CollectResult result = repositorySystem.collectDependencies(session, collectRequest);
        return result.getRoot();
    } catch (DependencyCollectionException e) {
        throw new MojoExecutionException("Cannot build project dependency tree", e);
    }
}
Also used : JavaDependencyContextRefiner(org.sonatype.aether.util.graph.transformer.JavaDependencyContextRefiner) DependencyCollectionException(org.sonatype.aether.collection.DependencyCollectionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) CollectResult(org.sonatype.aether.collection.CollectResult) AndDependencySelector(org.sonatype.aether.util.graph.selector.AndDependencySelector) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) ChainedDependencyGraphTransformer(org.sonatype.aether.util.graph.transformer.ChainedDependencyGraphTransformer) OptionalDependencySelector(org.sonatype.aether.util.graph.selector.OptionalDependencySelector) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) JavaEffectiveScopeCalculator(org.sonatype.aether.util.graph.transformer.JavaEffectiveScopeCalculator) DependencyGraphTransformer(org.sonatype.aether.collection.DependencyGraphTransformer) ChainedDependencyGraphTransformer(org.sonatype.aether.util.graph.transformer.ChainedDependencyGraphTransformer) ConflictMarker(org.sonatype.aether.util.graph.transformer.ConflictMarker) ExclusionDependencySelector(org.sonatype.aether.util.graph.selector.ExclusionDependencySelector)

Example 4 with DefaultRepositorySystemSession

use of org.sonatype.aether.util.DefaultRepositorySystemSession in project maven-plugins by apache.

the class TestIncludeExcludeUnpackMojo method setUp.

protected void setUp() throws Exception {
    // required for mojo lookups to work
    super.setUp("unpack", true, false);
    File testPom = new File(getBasedir(), "target/test-classes/unit/unpack-test/plugin-config.xml");
    mojo = (UnpackMojo) lookupMojo("unpack", testPom);
    mojo.setOutputDirectory(new File(this.testDir, "outputDirectory"));
    // mojo.silent = true;
    // it needs to get the archivermanager
    //stubFactory.setUnpackableFile( mojo.getArchiverManager() );
    // i'm using one file repeatedly to archive so I can test the name
    // programmatically.
    stubFactory.setSrcFile(new File(getBasedir() + File.separatorChar + PACKED_FILE_PATH));
    Artifact artifact = stubFactory.createArtifact("test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null);
    ArtifactItem item = stubFactory.getArtifactItem(artifact);
    List<ArtifactItem> list = new ArrayList<ArtifactItem>(1);
    list.add(item);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    mojo.setArchiverManager((ArchiverManager) lookup(ArchiverManager.ROLE));
    mojo.setMarkersDirectory(new File(this.testDir, "markers"));
    mojo.setArtifactItems(list);
    MavenSession session = newMavenSession(mojo.getProject());
    setVariableValueToObject(mojo, "session", session);
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) ArrayList(java.util.ArrayList) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 5 with DefaultRepositorySystemSession

use of org.sonatype.aether.util.DefaultRepositorySystemSession in project maven-plugins by apache.

the class TestClassifierTypeTranslator method setUp.

protected void setUp() throws Exception {
    super.setUp("classifiertype-translator", false);
    artifactHandlerManager = new DefaultArtifactHandlerManager();
    this.setVariableValueToObject(artifactHandlerManager, "artifactHandlers", new HashMap());
    artifactFactory = new DefaultArtifactFactory();
    this.setVariableValueToObject(artifactFactory, "artifactHandlerManager", artifactHandlerManager);
    artifactRepository = new StubArtifactRepository(null);
    DependencyArtifactStubFactory factory = new DependencyArtifactStubFactory(null, false);
    artifacts = factory.getMixedArtifacts();
    repoManager = lookup(RepositoryManager.class);
    MavenSession session = newMavenSession(new MavenProjectStub());
    buildingRequest = session.getProjectBuildingRequest();
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) DefaultArtifactFactory(org.apache.maven.artifact.factory.DefaultArtifactFactory) MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) HashMap(java.util.HashMap) StubArtifactRepository(org.apache.maven.plugin.testing.stubs.StubArtifactRepository) RepositoryManager(org.apache.maven.shared.repository.RepositoryManager) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) DefaultArtifactHandlerManager(org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager) DependencyArtifactStubFactory(org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory)

Aggregations

DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)17 File (java.io.File)13 MavenSession (org.apache.maven.execution.MavenSession)11 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)10 Artifact (org.apache.maven.artifact.Artifact)6 MavenProject (org.apache.maven.project.MavenProject)4 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)3 ArtifactHandlerManager (org.apache.maven.artifact.handler.manager.ArtifactHandlerManager)2 LegacySupport (org.apache.maven.plugin.LegacySupport)2 MavenProjectStub (org.apache.maven.plugin.testing.stubs.MavenProjectStub)2 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)2 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)2 Dependency (org.sonatype.aether.graph.Dependency)2 EnhancedLocalRepositoryManager (org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager)2 THashSet (gnu.trove.THashSet)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 RemoteException (java.rmi.RemoteException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1