Search in sources :

Example 71 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class DefaultAssemblyReaderTest method testReadAssembly_ShouldReadAssemblyWithSiteDirInclusionFromAssemblyWithoutComponentsOrInterpolation.

public void testReadAssembly_ShouldReadAssemblyWithSiteDirInclusionFromAssemblyWithoutComponentsOrInterpolation() throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException {
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    assembly.setIncludeSiteDirectory(true);
    final StringReader sr = writeToStringReader(assembly);
    final File siteDir = fileManager.createTempDir();
    expect(configSource.getSiteDirectory()).andReturn(siteDir).anyTimes();
    final File basedir = fileManager.createTempDir();
    expect(configSource.getBasedir()).andReturn(basedir).anyTimes();
    final Model model = new Model();
    model.setGroupId("group");
    model.setArtifactId("artifact");
    model.setVersion("version");
    final MavenProject project = new MavenProject(model);
    expect(configSource.getProject()).andReturn(project).anyTimes();
    DefaultAssemblyArchiverTest.setupInterpolators(configSource);
    mockManager.replayAll();
    final Assembly result = new DefaultAssemblyReader().readAssembly(sr, "testLocation", null, configSource);
    assertEquals(assembly.getId(), result.getId());
    final List<FileSet> fileSets = result.getFileSets();
    assertEquals(1, fileSets.size());
    assertEquals("/site", fileSets.get(0).getOutputDirectory());
    mockManager.verifyAll();
}
Also used : MavenProject(org.apache.maven.project.MavenProject) FileSet(org.apache.maven.plugins.assembly.model.FileSet) StringReader(java.io.StringReader) Model(org.apache.maven.model.Model) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 72 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class DefaultAssemblyReaderTest method testReadAssembly_ShouldReadAssemblyWithComponentWithoutSiteDirInclusionOrInterpolation.

public void testReadAssembly_ShouldReadAssemblyWithComponentWithoutSiteDirInclusionOrInterpolation() throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException {
    final File componentsFile = fileManager.createTempFile();
    final File basedir = componentsFile.getParentFile();
    final String componentsFilename = componentsFile.getName();
    final Component component = new Component();
    final FileSet fs = new FileSet();
    fs.setDirectory("/dir");
    component.addFileSet(fs);
    Writer fw = null;
    try {
        fw = new OutputStreamWriter(new FileOutputStream(componentsFile), "UTF-8");
        new ComponentXpp3Writer().write(fw, component);
        fw.close();
        fw = null;
    } finally {
        IOUtil.close(fw);
    }
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    assembly.addComponentDescriptor(componentsFilename);
    final StringReader sr = writeToStringReader(assembly);
    expect(configSource.getBasedir()).andReturn(basedir).anyTimes();
    final Model model = new Model();
    model.setGroupId("group");
    model.setArtifactId("artifact");
    model.setVersion("version");
    final MavenProject project = new MavenProject(model);
    expect(configSource.getProject()).andReturn(project).anyTimes();
    DefaultAssemblyArchiverTest.setupInterpolators(configSource);
    mockManager.replayAll();
    final Assembly result = new DefaultAssemblyReader().readAssembly(sr, "testLocation", null, configSource);
    assertEquals(assembly.getId(), result.getId());
    final List<FileSet> fileSets = result.getFileSets();
    assertEquals(1, fileSets.size());
    assertEquals("/dir", fileSets.get(0).getDirectory());
    mockManager.verifyAll();
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) MavenProject(org.apache.maven.project.MavenProject) FileOutputStream(java.io.FileOutputStream) StringReader(java.io.StringReader) Model(org.apache.maven.model.Model) ComponentXpp3Writer(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer) OutputStreamWriter(java.io.OutputStreamWriter) Component(org.apache.maven.plugins.assembly.model.Component) File(java.io.File) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) AssemblyXpp3Writer(org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Writer) Writer(java.io.Writer) ComponentXpp3Writer(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 73 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class AssemblyFormatUtilsTest method createProject.

private MavenProject createProject(String groupId, String artifactId, String version, final Properties projectProperties) {
    if (artifactId == null) {
        artifactId = "artifact";
    }
    if (groupId == null) {
        groupId = "group";
    }
    if (version == null) {
        version = "version";
    }
    final Model model = new Model();
    model.setGroupId(groupId);
    model.setArtifactId(artifactId);
    model.setVersion(version);
    model.setProperties(projectProperties);
    return new MavenProject(model);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model)

Example 74 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class AssemblyInterpolatorTest method testShouldResolveModelPropertyBeforeModelGroupIdInAssemblyId.

public void testShouldResolveModelPropertyBeforeModelGroupIdInAssemblyId() throws AssemblyInterpolationException, InvalidAssemblerConfigurationException, AssemblyReadException, IOException {
    final Model model = new Model();
    model.setArtifactId("artifact-id");
    model.setGroupId("group.id");
    model.setVersion("1");
    model.setPackaging("jar");
    final Properties props = new Properties();
    props.setProperty("groupId", "other.id");
    model.setProperties(props);
    final PojoConfigSource configSourceStub = new PojoConfigSource();
    configSourceStub.setRootInterpolator(FixedStringSearchInterpolator.create());
    configSourceStub.setEnvironmentInterpolator(FixedStringSearchInterpolator.create());
    final Assembly assembly = new Assembly();
    assembly.setId("assembly.${groupId}");
    final MavenProject project = new MavenProject(model);
    configSourceStub.setMavenProject(project);
    final Assembly result = roundTripInterpolation(assembly, configSourceStub);
    assertEquals("assembly.other.id", result.getId());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model) PojoConfigSource(org.apache.maven.plugins.assembly.testutils.PojoConfigSource) Properties(java.util.Properties) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 75 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class DefaultCheckstyleExecutor method configureResourceLocator.

/**
     * Configures search paths in the resource locator.
     * This method should only be called once per execution.
     *
     * @param request executor request data.
     */
private void configureResourceLocator(final ResourceManager resourceManager, final CheckstyleExecutorRequest request, final List<Artifact> additionalArtifacts) {
    final MavenProject project = request.getProject();
    resourceManager.setOutputDirectory(new File(project.getBuild().getDirectory()));
    // Recurse up the parent hierarchy and add project directories to the search roots
    MavenProject parent = project;
    while (parent != null && parent.getFile() != null) {
        // MCHECKSTYLE-131 ( olamy ) I don't like this hack.
        // (dkulp) Me either.   It really pollutes the location stuff
        // by allowing searches of stuff outside the current module.
        File dir = parent.getFile().getParentFile();
        resourceManager.addSearchPath(FileResourceLoader.ID, dir.getAbsolutePath());
        parent = parent.getParent();
    }
    resourceManager.addSearchPath("url", "");
    // MCHECKSTYLE-225: load licenses from additional artifacts, not from classpath
    if (additionalArtifacts != null) {
        for (Artifact licenseArtifact : additionalArtifacts) {
            try {
                resourceManager.addSearchPath("jar", "jar:" + licenseArtifact.getFile().toURI().toURL());
            } catch (MalformedURLException e) {
            // noop
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) MavenProject(org.apache.maven.project.MavenProject) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

MavenProject (org.apache.maven.project.MavenProject)297 File (java.io.File)138 Artifact (org.apache.maven.artifact.Artifact)66 ArrayList (java.util.ArrayList)64 Model (org.apache.maven.model.Model)57 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)36 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)33 IOException (java.io.IOException)29 Assembly (org.apache.maven.plugins.assembly.model.Assembly)28 EasyMockSupport (org.easymock.classextension.EasyMockSupport)27 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)20 Test (org.junit.Test)17 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)16 MavenSession (org.apache.maven.execution.MavenSession)16 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)16 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)16 LinkedHashSet (java.util.LinkedHashSet)15 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)15 FileSet (org.apache.maven.plugins.assembly.model.FileSet)15