Search in sources :

Example 41 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 42 with SimpleLocalRepositoryManager

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

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

the class TestBuildClasspathMojo method testPath.

public void testPath() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/build-classpath-test/plugin-config.xml");
    BuildClasspathMojo mojo = (BuildClasspathMojo) lookupMojo("build-classpath", testPom);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    MavenSession session = newMavenSession(mojo.getProject());
    setVariableValueToObject(mojo, "session", session);
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
    Artifact artifact = stubFactory.getReleaseArtifact();
    StringBuilder sb = new StringBuilder();
    mojo.setPrefix(null);
    mojo.setStripVersion(false);
    mojo.appendArtifactPath(artifact, sb);
    assertEquals(artifact.getFile().getPath(), sb.toString());
    mojo.setLocalRepoProperty("$M2_REPO");
    sb.setLength(0);
    mojo.appendArtifactPath(artifact, sb);
    assertEquals("$M2_REPO" + File.separator + artifact.getFile().getName(), sb.toString());
    mojo.setLocalRepoProperty("%M2_REPO%");
    sb.setLength(0);
    mojo.appendArtifactPath(artifact, sb);
    assertEquals("%M2_REPO%" + File.separator + artifact.getFile().getName(), sb.toString());
    mojo.setLocalRepoProperty("%M2_REPO%");
    sb.setLength(0);
    mojo.setPrependGroupId(true);
    mojo.appendArtifactPath(artifact, sb);
    assertEquals("If prefix is null, prependGroupId has no impact ", "%M2_REPO%" + File.separator + DependencyUtil.getFormattedFileName(artifact, false, false), sb.toString());
    mojo.setLocalRepoProperty("");
    mojo.setPrefix("prefix");
    sb.setLength(0);
    mojo.setPrependGroupId(true);
    mojo.appendArtifactPath(artifact, sb);
    assertEquals("prefix" + File.separator + DependencyUtil.getFormattedFileName(artifact, false, true), sb.toString());
    mojo.setPrependGroupId(false);
    mojo.setLocalRepoProperty("");
    mojo.setPrefix("prefix");
    sb.setLength(0);
    mojo.appendArtifactPath(artifact, sb);
    assertEquals("prefix" + File.separator + artifact.getFile().getName(), sb.toString());
    mojo.setPrefix("prefix");
    mojo.setStripVersion(true);
    sb.setLength(0);
    mojo.appendArtifactPath(artifact, sb);
    assertEquals("prefix" + File.separator + DependencyUtil.getFormattedFileName(artifact, true), sb.toString());
}
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) Artifact(org.apache.maven.artifact.Artifact)

Example 44 with SimpleLocalRepositoryManager

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

the class TestCopyDependenciesMojo2 method setUp.

protected void setUp() throws Exception {
    // required for mojo lookups to work
    super.setUp("copy-dependencies", true);
    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();
    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");
    LegacySupport legacySupport = lookup(LegacySupport.class);
    MavenSession session = newMavenSession(project);
    setVariableValueToObject(mojo, "session", session);
    legacySupport.setSession(session);
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) legacySupport.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(testDir.getAbsolutePath()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) LegacySupport(org.apache.maven.plugin.LegacySupport) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenProject(org.apache.maven.project.MavenProject) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 45 with SimpleLocalRepositoryManager

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

the class TestUnpackDependenciesMojo method setUp.

protected void setUp() throws Exception {
    // required for mojo lookups to work
    super.setUp("unpack-dependencies", true, false);
    File testPom = new File(getBasedir(), "target/test-classes/unit/unpack-dependencies-test/plugin-config.xml");
    mojo = (UnpackDependenciesMojo) lookupMojo("unpack-dependencies", testPom);
    mojo.outputDirectory = new File(this.testDir, "outputDirectory");
    mojo.setUseJvmChmod(true);
    // 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 + UNPACKABLE_FILE_PATH));
    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)

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