Search in sources :

Example 11 with MavenRepositorySystemSession

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

the class DeployMojoTest method testUpdateReleaseParamSetToTrue.

public void testUpdateReleaseParamSetToTrue() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-pom/plugin-config.xml");
    mojo = (DeployMojo) lookupMojo("deploy", testPom);
    MockitoAnnotations.initMocks(this);
    assertNotNull(mojo);
    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(LOCAL_REPO));
    when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
    boolean updateReleaseInfo = (Boolean) getVariableValueFromObject(mojo, "updateReleaseInfo");
    assertTrue(updateReleaseInfo);
    MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
    setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
    artifact = (DeployArtifactStub) project.getArtifact();
    artifact.setFile(testPom);
    ArtifactRepositoryStub repo = getRepoStub(mojo);
    repo.setAppendToUrl("basic-deploy-updateReleaseParam");
    mojo.execute();
    assertTrue(artifact.isRelease());
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenProject(org.apache.maven.project.MavenProject) ArtifactRepositoryStub(org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) File(java.io.File)

Example 12 with MavenRepositorySystemSession

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

the class DeployFileMojoTest method testDeployIfClassifierIsSet.

public void testDeployIfClassifierIsSet() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/deploy-file-classifier/plugin-config.xml");
    mojo = (DeployFileMojo) lookupMojo("deploy-file", testPom);
    MockitoAnnotations.initMocks(this);
    assertNotNull(mojo);
    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(LOCAL_REPO));
    when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
    String classifier = (String) getVariableValueFromObject(mojo, "classifier");
    String groupId = (String) getVariableValueFromObject(mojo, "groupId");
    String artifactId = (String) getVariableValueFromObject(mojo, "artifactId");
    String version = (String) getVariableValueFromObject(mojo, "version");
    assertEquals("bin", classifier);
    mojo.execute();
    File deployedArtifact = new File(remoteRepo, "deploy-file-classifier/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "-" + classifier + ".jar");
    assertTrue(deployedArtifact.exists());
    mojo.setClassifier("prod");
    assertEquals("prod", mojo.getClassifier());
    mojo.execute();
    File prodDeployedArtifact = new File(remoteRepo, "deploy-file-classifier/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "-" + mojo.getClassifier() + ".jar");
    assertTrue(prodDeployedArtifact.exists());
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) File(java.io.File)

Example 13 with MavenRepositorySystemSession

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

the class JavadocReportTest method testTagletArtifacts.

/**
     * Method to test the <code>&lt;tagletArtifacts/&gt;</code> parameter.
     *
     * @throws Exception if any
     */
public void testTagletArtifacts() throws Exception {
    File testPom = new File(unit, "tagletArtifacts-test/tagletArtifacts-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, "session", session);
    mojo.execute();
    File optionsFile = new File(mojo.getOutputDirectory(), "options");
    assertTrue(optionsFile.exists());
    String options = readFile(optionsFile);
    // count -taglet
    assertEquals(20, StringUtils.countMatches(options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet"));
    assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusConfigurationTaglet"));
    assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusRequirementTaglet"));
    assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusComponentTaglet"));
}
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 14 with MavenRepositorySystemSession

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

the class JavadocReportTest method testDoclets.

/**
     * Method to test the doclet artifact configuration
     *
     * @throws Exception if any
     */
public void testDoclets() throws Exception {
    // ----------------------------------------------------------------------
    // doclet-test: check if the file generated by UmlGraph exists and if
    // doclet path contains the UmlGraph artifact
    // ----------------------------------------------------------------------
    File testPom = new File(unit, "doclet-test/doclet-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, "session", session);
    mojo.execute();
    File generatedFile = new File(getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot");
    assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
    File optionsFile = new File(mojo.getOutputDirectory(), "options");
    assertTrue(optionsFile.exists());
    String options = readFile(optionsFile);
    assertTrue(options.contains("/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar"));
    // ----------------------------------------------------------------------
    // doclet-path: check if the file generated by UmlGraph exists and if
    // doclet path contains the twice UmlGraph artifacts
    // ----------------------------------------------------------------------
    testPom = new File(unit, "doclet-path-test/doclet-path-test-plugin-config.xml");
    mojo = lookupMojo(testPom);
    setVariableValueToObject(mojo, "session", session);
    mojo.execute();
    generatedFile = new File(getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot");
    assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
    optionsFile = new File(mojo.getOutputDirectory(), "options");
    assertTrue(optionsFile.exists());
    options = readFile(optionsFile);
    assertTrue(options.contains("/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar"));
    assertTrue(options.contains("/target/local-repo/umlgraph/UMLGraph-bis/2.1/UMLGraph-bis-2.1.jar"));
}
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 15 with MavenRepositorySystemSession

use of org.apache.maven.repository.internal.MavenRepositorySystemSession 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)

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