Search in sources :

Example 16 with MavenRepositorySystemSession

use of org.apache.maven.repository.internal.MavenRepositorySystemSession in project maven-plugins by apache.

the class JavadocReportTest method testStylesheetfile.

/**
     * Method to test the <code>&lt;stylesheetfile/&gt;</code> parameter.
     *
     * @throws Exception if any
     */
public void testStylesheetfile() throws Exception {
    File testPom = new File(unit, "stylesheetfile-test/pom.xml");
    JavadocReport mojo = lookupMojo(testPom);
    assertNotNull(mojo);
    MavenSession session = spy(newMavenSession(mojo.project));
    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    when(buildingRequest.getRemoteRepositories()).thenReturn(mojo.project.getRemoteArtifactRepositories());
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepo));
    when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
    when(session.getRepositorySession()).thenReturn(repositorySession);
    LegacySupport legacySupport = lookup(LegacySupport.class);
    legacySupport.setSession(session);
    setVariableValueToObject(mojo, "session", session);
    File apidocs = new File(getBasedir(), "target/test/unit/stylesheetfile-test/target/site/apidocs");
    File stylesheetfile = new File(apidocs, "stylesheet.css");
    File options = new File(apidocs, "options");
    // stylesheet == maven OR java
    setVariableValueToObject(mojo, "stylesheet", "javamaven");
    try {
        mojo.execute();
        assertTrue(false);
    } catch (Exception e) {
        assertTrue(true);
    }
    // stylesheet == java
    setVariableValueToObject(mojo, "stylesheet", "java");
    mojo.execute();
    String content = readFile(stylesheetfile);
    assertTrue(content.contains("/* Javadoc style sheet */"));
    String optionsContent = readFile(options);
    assertFalse(optionsContent.contains("-stylesheetfile"));
    // stylesheet == maven
    setVariableValueToObject(mojo, "stylesheet", "maven");
    mojo.execute();
    content = readFile(stylesheetfile);
    assertTrue(content.contains("/* Javadoc style sheet */") && content.contains("Licensed to the Apache Software Foundation (ASF) under one"));
    optionsContent = readFile(options);
    assertTrue(optionsContent.contains("-stylesheetfile"));
    assertTrue(optionsContent.contains("'" + stylesheetfile.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
    // stylesheetfile defined as a project resource
    setVariableValueToObject(mojo, "stylesheet", null);
    setVariableValueToObject(mojo, "stylesheetfile", "com/mycompany/app/javadoc/css/stylesheet.css");
    mojo.execute();
    content = readFile(stylesheetfile);
    assertTrue(content.contains("/* Custom Javadoc style sheet in project */"));
    optionsContent = readFile(options);
    assertTrue(optionsContent.contains("-stylesheetfile"));
    File stylesheetResource = new File(unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css/stylesheet.css");
    assertTrue(optionsContent.contains("'" + stylesheetResource.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
    // stylesheetfile defined in a javadoc plugin dependency
    setVariableValueToObject(mojo, "stylesheetfile", "com/mycompany/app/javadoc/css2/stylesheet.css");
    mojo.execute();
    content = readFile(stylesheetfile);
    assertTrue(content.contains("/* Custom Javadoc style sheet in artefact */"));
    optionsContent = readFile(options);
    assertTrue(optionsContent.contains("-stylesheetfile"));
    assertTrue(optionsContent.contains("'" + stylesheetfile.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
    // stylesheetfile defined as file
    File css = new File(unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css");
    setVariableValueToObject(mojo, "stylesheetfile", css.getAbsolutePath());
    mojo.execute();
    content = readFile(stylesheetfile);
    assertTrue(content.contains("/* Custom Javadoc style sheet as file */"));
    optionsContent = readFile(options);
    assertTrue(optionsContent.contains("-stylesheetfile"));
    stylesheetResource = new File(unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css");
    assertTrue(optionsContent.contains("'" + stylesheetResource.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) LegacySupport(org.apache.maven.plugin.LegacySupport) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) File(java.io.File) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 17 with MavenRepositorySystemSession

use of org.apache.maven.repository.internal.MavenRepositorySystemSession in project maven-plugins by apache.

the class JavadocReportTest method testHelpfile.

/**
     * Method to test the <code>&lt;helpfile/&gt;</code> parameter.
     *
     * @throws Exception if any
     */
public void testHelpfile() throws Exception {
    File testPom = new File(unit, "helpfile-test/pom.xml");
    JavadocReport mojo = lookupMojo(testPom);
    assertNotNull(mojo);
    MavenSession session = spy(newMavenSession(mojo.project));
    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    when(buildingRequest.getRemoteRepositories()).thenReturn(mojo.project.getRemoteArtifactRepositories());
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepo));
    when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
    when(session.getRepositorySession()).thenReturn(repositorySession);
    LegacySupport legacySupport = lookup(LegacySupport.class);
    legacySupport.setSession(session);
    setVariableValueToObject(mojo, "session", session);
    File apidocs = new File(getBasedir(), "target/test/unit/helpfile-test/target/site/apidocs");
    File helpfile = new File(apidocs, "help-doc.html");
    File options = new File(apidocs, "options");
    // helpfile by default
    mojo.execute();
    String content = readFile(helpfile);
    assertTrue(content.contains("<!-- Generated by javadoc"));
    String optionsContent = readFile(options);
    assertFalse(optionsContent.contains("-helpfile"));
    // helpfile defined in a javadoc plugin dependency
    setVariableValueToObject(mojo, "helpfile", "com/mycompany/app/javadoc/helpfile/help-doc.html");
    setVariableValueToObject(mojo, "session", session);
    mojo.execute();
    content = readFile(helpfile);
    assertTrue(content.contains("<!--  Help file from artefact -->"));
    optionsContent = readFile(options);
    assertTrue(optionsContent.contains("-helpfile"));
    File help = new File(apidocs, "help-doc.html");
    assertTrue(optionsContent.contains("'" + help.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
    // helpfile defined as a project resource
    setVariableValueToObject(mojo, "helpfile", "com/mycompany/app/javadoc/helpfile2/help-doc.html");
    mojo.execute();
    content = readFile(helpfile);
    assertTrue(content.contains("<!--  Help file from file -->"));
    optionsContent = readFile(options);
    assertTrue(optionsContent.contains("-helpfile"));
    help = new File(unit, "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html");
    assertTrue(optionsContent.contains("'" + help.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
    // helpfile defined as file
    help = new File(unit, "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html");
    setVariableValueToObject(mojo, "helpfile", help.getAbsolutePath());
    mojo.execute();
    content = readFile(helpfile);
    assertTrue(content.contains("<!--  Help file from file -->"));
    optionsContent = readFile(options);
    assertTrue(optionsContent.contains("-helpfile"));
    assertTrue(optionsContent.contains("'" + help.getAbsolutePath().replaceAll("\\\\", "/") + "'"));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) LegacySupport(org.apache.maven.plugin.LegacySupport) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) File(java.io.File)

Example 18 with MavenRepositorySystemSession

use of org.apache.maven.repository.internal.MavenRepositorySystemSession in project maven-plugins by apache.

the class DefaultDependencyResolverTest method newMavenSession.

protected MavenSession newMavenSession(MavenProject project) {
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    MavenExecutionResult result = new DefaultMavenExecutionResult();
    MavenRepositorySystemSession repoSession = new MavenRepositorySystemSession();
    repoSession.setLocalRepositoryManager(LegacyLocalRepositoryManager.wrap(new StubArtifactRepository("target/local-repo"), null));
    MavenSession session = new MavenSession(getContainer(), repoSession, request, result);
    session.setCurrentProject(project);
    session.setProjects(Arrays.asList(project));
    return session;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) StubArtifactRepository(org.apache.maven.plugin.testing.stubs.StubArtifactRepository) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession)

Aggregations

MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)18 File (java.io.File)14 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)13 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)13 MavenSession (org.apache.maven.execution.MavenSession)7 LegacySupport (org.apache.maven.plugin.LegacySupport)6 ArtifactRepositoryStub (org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub)4 MavenProject (org.apache.maven.project.MavenProject)4 ArrayList (java.util.ArrayList)3 LocalRepository (org.sonatype.aether.repository.LocalRepository)3 ConsoleRepositoryListener (demo.util.ConsoleRepositoryListener)1 ConsoleTransferListener (demo.util.ConsoleTransferListener)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)1 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)1 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)1 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)1 Model (org.apache.maven.model.Model)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1