Search in sources :

Example 26 with SimpleLocalRepositoryManager

use of org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager in project maven-plugins by apache.

the class JavadocReportTest method testProxy.

/**
     * Method to test proxy support in the javadoc
     *
     * @throws Exception if any
     */
public void testProxy() throws Exception {
    Settings settings = new Settings();
    Proxy proxy = new Proxy();
    // dummy proxy
    proxy.setActive(true);
    proxy.setHost("127.0.0.1");
    proxy.setPort(80);
    proxy.setProtocol("http");
    proxy.setUsername("toto");
    proxy.setPassword("toto");
    proxy.setNonProxyHosts("www.google.com|*.somewhere.com");
    settings.addProxy(proxy);
    File testPom = new File(getBasedir(), "src/test/resources/unit/proxy-test/proxy-test-plugin-config.xml");
    JavadocReport mojo = lookupMojo(testPom);
    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, "settings", settings);
    setVariableValueToObject(mojo, "session", session);
    mojo.execute();
    File commandLine = new File(getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/javadoc." + (SystemUtils.IS_OS_WINDOWS ? "bat" : "sh"));
    assertTrue(FileUtils.fileExists(commandLine.getAbsolutePath()));
    String readed = readFile(commandLine);
    assertTrue(readed.contains("-J-Dhttp.proxySet=true"));
    assertTrue(readed.contains("-J-Dhttp.proxyHost=127.0.0.1"));
    assertTrue(readed.contains("-J-Dhttp.proxyPort=80"));
    assertTrue(readed.contains("-J-Dhttp.proxyUser=\\\"toto\\\""));
    assertTrue(readed.contains("-J-Dhttp.proxyPassword=\\\"toto\\\""));
    assertTrue(readed.contains("-J-Dhttp.nonProxyHosts=\\\"www.google.com|*.somewhere.com\\\""));
    File options = new File(getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/options");
    assertTrue(FileUtils.fileExists(options.getAbsolutePath()));
    String optionsContent = readFile(options);
    // NO -link expected
    assertFalse(optionsContent.contains("-link"));
    // real proxy
    ProxyServer proxyServer = null;
    AuthAsyncProxyServlet proxyServlet;
    try {
        proxyServlet = new AuthAsyncProxyServlet();
        proxyServer = new ProxyServer(proxyServlet);
        proxyServer.start();
        settings = new Settings();
        proxy = new Proxy();
        proxy.setActive(true);
        proxy.setHost(proxyServer.getHostName());
        proxy.setPort(proxyServer.getPort());
        proxy.setProtocol("http");
        settings.addProxy(proxy);
        mojo = lookupMojo(testPom);
        setVariableValueToObject(mojo, "settings", settings);
        setVariableValueToObject(mojo, "session", session);
        mojo.execute();
        readed = readFile(commandLine);
        assertTrue(readed.contains("-J-Dhttp.proxySet=true"));
        assertTrue(readed.contains("-J-Dhttp.proxyHost=" + proxyServer.getHostName()));
        assertTrue(readed.contains("-J-Dhttp.proxyPort=" + proxyServer.getPort()));
        optionsContent = readFile(options);
    // -link expected
    // TODO: This got disabled for now!
    // This test fails since the last commit but I actually think it only ever worked by accident.
    // It did rely on a commons-logging-1.0.4.pom which got resolved by a test which did run previously.
    // But after updating to commons-logging.1.1.1 there is no pre-resolved artifact available in
    // target/local-repo anymore, thus the javadoc link info cannot get built and the test fails
    // I'll for now just disable this line of code, because the test as far as I can see _never_
    // did go upstream. The remoteRepository list used is always empty!.
    //
    //            assertTrue( optionsContent.contains( "-link 'http://commons.apache.org/logging/apidocs'" ) );
    } finally {
        if (proxyServer != null) {
            proxyServer.stop();
        }
    }
    // auth proxy
    Map<String, String> authentications = new HashMap<String, String>();
    authentications.put("foo", "bar");
    try {
        proxyServlet = new AuthAsyncProxyServlet(authentications);
        proxyServer = new ProxyServer(proxyServlet);
        proxyServer.start();
        settings = new Settings();
        proxy = new Proxy();
        proxy.setActive(true);
        proxy.setHost(proxyServer.getHostName());
        proxy.setPort(proxyServer.getPort());
        proxy.setProtocol("http");
        proxy.setUsername("foo");
        proxy.setPassword("bar");
        settings.addProxy(proxy);
        mojo = lookupMojo(testPom);
        setVariableValueToObject(mojo, "settings", settings);
        setVariableValueToObject(mojo, "session", session);
        mojo.execute();
        readed = readFile(commandLine);
        assertTrue(readed.contains("-J-Dhttp.proxySet=true"));
        assertTrue(readed.contains("-J-Dhttp.proxyHost=" + proxyServer.getHostName()));
        assertTrue(readed.contains("-J-Dhttp.proxyPort=" + proxyServer.getPort()));
        assertTrue(readed.contains("-J-Dhttp.proxyUser=\\\"foo\\\""));
        assertTrue(readed.contains("-J-Dhttp.proxyPassword=\\\"bar\\\""));
        optionsContent = readFile(options);
    // -link expected
    // see comment above (line 829)
    //             assertTrue( optionsContent.contains( "-link 'http://commons.apache.org/logging/apidocs'" ) );
    } finally {
        if (proxyServer != null) {
            proxyServer.stop();
        }
    }
}
Also used : LegacySupport(org.apache.maven.plugin.LegacySupport) HashMap(java.util.HashMap) AuthAsyncProxyServlet(org.apache.maven.plugin.javadoc.ProxyServer.AuthAsyncProxyServlet) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) MavenSession(org.apache.maven.execution.MavenSession) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) Proxy(org.apache.maven.settings.Proxy) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) File(java.io.File) Settings(org.apache.maven.settings.Settings)

Example 27 with SimpleLocalRepositoryManager

use of org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager 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 28 with SimpleLocalRepositoryManager

use of org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager 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 29 with SimpleLocalRepositoryManager

use of org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager in project maven-dependency-plugin by apache.

the class TestCopyDependenciesMojo method setUp.

protected void setUp() throws Exception {
    // required for mojo lookups to work
    super.setUp("copy-dependencies", true, false);
    File testPom = new File(getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml");
    mojo = (CopyDependenciesMojo) lookupMojo("copy-dependencies", testPom);
    mojo.outputDirectory = new File(this.testDir, "outputDirectory");
    // mojo.silent = true;
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    MavenProject project = mojo.getProject();
    MavenSession session = newMavenSession(project);
    setVariableValueToObject(mojo, "session", session);
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
    Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
    Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
    artifacts.addAll(directArtifacts);
    project.setArtifacts(artifacts);
    project.setDependencyArtifacts(directArtifacts);
    mojo.markersDirectory = new File(this.testDir, "markers");
    ArtifactHandlerManager manager = lookup(ArtifactHandlerManager.class);
    setVariableValueToObject(mojo, "artifactHandlerManager", manager);
}
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) ArtifactHandlerManager(org.apache.maven.artifact.handler.manager.ArtifactHandlerManager) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 30 with SimpleLocalRepositoryManager

use of org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager in project maven-dependency-plugin by apache.

the class TestUnpackMojo method setUp.

protected void setUp() throws Exception {
    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.setMarkersDirectory(new File(this.testDir, "markers"));
    mojo.setSilent(true);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    // MavenProject project = mojo.getProject();
    // init classifier things
    // 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 + "target/test-classes/unit/unpack-dependencies-test/test.txt"));
    mojo.setUseJvmChmod(true);
    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) File(java.io.File)

Aggregations

SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)49 File (java.io.File)44 MavenSession (org.apache.maven.execution.MavenSession)30 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)29 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)28 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)20 LegacySupport (org.apache.maven.plugin.LegacySupport)16 MavenProject (org.apache.maven.project.MavenProject)16 Artifact (org.apache.maven.artifact.Artifact)11 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)9 ArchetypeGenerationRequest (org.apache.maven.archetype.ArchetypeGenerationRequest)7 ArrayList (java.util.ArrayList)6 ArchetypeManager (org.apache.maven.archetype.ArchetypeManager)6 ArchetypeCatalog (org.apache.maven.archetype.catalog.ArchetypeCatalog)6 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)6 HashMap (java.util.HashMap)5 Properties (java.util.Properties)5 ArchetypeGenerationResult (org.apache.maven.archetype.ArchetypeGenerationResult)5 Archetype (org.apache.maven.archetype.catalog.Archetype)5 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)5