Search in sources :

Example 6 with DefaultRepositorySystemSession

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

the class JiraUnicodeTestCase method testUnicodeReport.

public void testUnicodeReport() throws Exception {
    File pom = new File(getBasedir(), "/src/test/unit/jira-plugin-config.xml");
    assertNotNull(pom);
    assertTrue(pom.exists());
    JiraMojo mojo = (JiraMojo) lookupMojo("jira-report", pom);
    MavenProject project = new JiraUnicodeTestProjectStub();
    MavenSession session = newMavenSession(project);
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager("target/local-repo"));
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "mavenSession", session);
    InputStream testJiraXmlStream = JiraUnicodeTestCase.class.getResourceAsStream("unicode-jira-results.xml");
    String jiraXml = null;
    try {
        jiraXml = IOUtils.toString(testJiraXmlStream, "utf-8");
    } finally {
        testJiraXmlStream.close();
    }
    MockJiraDownloader mockDownloader = new MockJiraDownloader();
    mockDownloader.setJiraXml(jiraXml);
    mojo.setMockDownloader(mockDownloader);
    File outputDir = new File("target/jira-test-output");
    outputDir.mkdirs();
    mojo.setReportOutputDirectory(outputDir);
    mojo.execute();
    String reportHtml = FileUtils.readFileToString(new File(outputDir, "jira-report.html"), "utf-8");
    int turtleIndex = reportHtml.indexOf(TEST_TURTLES);
    assertTrue(turtleIndex >= 0);
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenProject(org.apache.maven.project.MavenProject) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) InputStream(java.io.InputStream) JiraMojo(org.apache.maven.plugins.jira.JiraMojo) File(java.io.File)

Example 7 with DefaultRepositorySystemSession

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

the class DefaultDependencyCollector method optimizeSession.

private RepositorySystemSession optimizeSession(RepositorySystemSession session) {
    DefaultRepositorySystemSession optimized = new DefaultRepositorySystemSession(session);
    optimized.setArtifactTypeRegistry(CachingArtifactTypeRegistry.newInstance(session));
    return optimized;
}
Also used : DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession)

Example 8 with DefaultRepositorySystemSession

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

the class Maven30ServerEmbedderImpl method doResolveProject.

@NotNull
public Collection<MavenExecutionResult> doResolveProject(@NotNull final Collection<File> files, @NotNull final List<String> activeProfiles, @NotNull final List<String> inactiveProfiles, final List<ResolutionListener> listeners) throws RemoteException {
    final File file = files.size() == 1 ? files.iterator().next() : null;
    final MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, Collections.<String>emptyList());
    request.setUpdateSnapshots(myAlwaysUpdateSnapshots);
    final Collection<MavenExecutionResult> executionResults = ContainerUtil.newArrayList();
    executeWithMavenSession(request, new Runnable() {

        @Override
        public void run() {
            try {
                RepositorySystemSession repositorySession = getComponent(LegacySupport.class).getRepositorySession();
                if (repositorySession instanceof DefaultRepositorySystemSession) {
                    ((DefaultRepositorySystemSession) repositorySession).setTransferListener(new Maven30TransferListenerAdapter(myCurrentIndicator));
                    if (myWorkspaceMap != null) {
                        ((DefaultRepositorySystemSession) repositorySession).setWorkspaceReader(new Maven30WorkspaceReader(myWorkspaceMap));
                    }
                }
                List<ProjectBuildingResult> buildingResults = getProjectBuildingResults(request, files);
                for (ProjectBuildingResult buildingResult : buildingResults) {
                    MavenProject project = buildingResult.getProject();
                    if (project == null) {
                        List<Exception> exceptions = new ArrayList<Exception>();
                        for (ModelProblem problem : buildingResult.getProblems()) {
                            exceptions.add(problem.getException());
                        }
                        MavenExecutionResult mavenExecutionResult = new MavenExecutionResult(buildingResult.getPomFile(), exceptions);
                        executionResults.add(mavenExecutionResult);
                        continue;
                    }
                    List<Exception> exceptions = new ArrayList<Exception>();
                    loadExtensions(project, exceptions);
                    //Artifact projectArtifact = project.getArtifact();
                    //Map managedVersions = project.getManagedVersionMap();
                    //ArtifactMetadataSource metadataSource = getComponent(ArtifactMetadataSource.class);
                    project.setDependencyArtifacts(project.createArtifacts(getComponent(ArtifactFactory.class), null, null));
                    if (USE_MVN2_COMPATIBLE_DEPENDENCY_RESOLVING) {
                        addMvn2CompatResults(project, exceptions, listeners, myLocalRepository, executionResults);
                    } else {
                        final DependencyResolutionResult dependencyResolutionResult = resolveDependencies(project, repositorySession);
                        final List<Dependency> dependencies = dependencyResolutionResult.getDependencies();
                        Set<Artifact> artifacts = new LinkedHashSet<Artifact>(dependencies.size());
                        for (Dependency dependency : dependencies) {
                            final Artifact artifact = RepositoryUtils.toArtifact(dependency.getArtifact());
                            artifact.setScope(dependency.getScope());
                            artifact.setOptional(dependency.isOptional());
                            artifacts.add(artifact);
                            resolveAsModule(artifact);
                        }
                        project.setArtifacts(artifacts);
                        executionResults.add(new MavenExecutionResult(project, dependencyResolutionResult, exceptions));
                    }
                }
            } catch (Exception e) {
                executionResults.add(handleException(e));
            }
        }
    });
    return executionResults;
}
Also used : DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) THashSet(gnu.trove.THashSet) MavenExecutionResult(org.jetbrains.idea.maven.server.embedder.MavenExecutionResult) Dependency(org.sonatype.aether.graph.Dependency) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) ContextException(org.codehaus.plexus.context.ContextException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) Artifact(org.apache.maven.artifact.Artifact) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) ModelProblem(org.apache.maven.model.building.ModelProblem) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with DefaultRepositorySystemSession

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

the class InstallMojoTest method createMavenSession.

private MavenSession createMavenSession() {
    MavenSession session = mock(MavenSession.class);
    DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new EnhancedLocalRepositoryManager(new File(LOCAL_REPO)));
    ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
    buildingRequest.setRepositorySession(repositorySession);
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    return session;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) EnhancedLocalRepositoryManager(org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) File(java.io.File) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Example 10 with DefaultRepositorySystemSession

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

the class InstallFileMojoTest method createMavenSession.

private MavenSession createMavenSession() {
    MavenSession session = mock(MavenSession.class);
    DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new EnhancedLocalRepositoryManager(new File(LOCAL_REPO)));
    ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
    buildingRequest.setRepositorySession(repositorySession);
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    return session;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) EnhancedLocalRepositoryManager(org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) File(java.io.File) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

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