Search in sources :

Example 76 with MavenProject

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

the class DefaultAssemblyReader method readAssembly.

public Assembly readAssembly(Reader reader, final String locationDescription, final File assemblyDir, final AssemblerConfigurationSource configSource) throws AssemblyReadException, InvalidAssemblerConfigurationException {
    Assembly assembly;
    final MavenProject project = configSource.getProject();
    try {
        InterpolationState is = new InterpolationState();
        final RecursionInterceptor interceptor = new PrefixAwareRecursionInterceptor(InterpolationConstants.PROJECT_PREFIXES, true);
        is.setRecursionInterceptor(interceptor);
        FixedStringSearchInterpolator interpolator = AssemblyInterpolator.fullInterpolator(project, createProjectInterpolator(project), configSource);
        AssemblyXpp3Reader.ContentTransformer transformer = AssemblyInterpolator.assemblyInterpolator(interpolator, is, getLogger());
        final AssemblyXpp3Reader r = new AssemblyXpp3Reader(transformer);
        assembly = r.read(reader);
        ComponentXpp3Reader.ContentTransformer ctrans = AssemblyInterpolator.componentInterpolator(interpolator, is, getLogger());
        mergeComponentsWithMainAssembly(assembly, assemblyDir, configSource, ctrans);
        debugPrintAssembly("After assembly is interpolated:", assembly);
        AssemblyInterpolator.checkErrors(AssemblyId.createAssemblyId(assembly), is, getLogger());
        reader.close();
        reader = null;
    } catch (final IOException e) {
        throw new AssemblyReadException("Error reading descriptor: " + locationDescription + ": " + e.getMessage(), e);
    } catch (final XmlPullParserException e) {
        throw new AssemblyReadException("Error reading descriptor: " + locationDescription + ": " + e.getMessage(), e);
    } finally {
        IOUtil.close(reader);
    }
    if (assembly.isIncludeSiteDirectory()) {
        includeSiteInAssembly(assembly, configSource);
    }
    return assembly;
}
Also used : FixedStringSearchInterpolator(org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator) AssemblyXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Reader) IOException(java.io.IOException) MavenProject(org.apache.maven.project.MavenProject) ComponentXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader) PrefixAwareRecursionInterceptor(org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor) RecursionInterceptor(org.codehaus.plexus.interpolation.RecursionInterceptor) InterpolationState(org.codehaus.plexus.interpolation.fixed.InterpolationState) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) PrefixAwareRecursionInterceptor(org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 77 with MavenProject

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

the class DependencySetAssemblyPhaseTest method testExecute_ShouldAddOneDependencyFromProject.

public void testExecute_ShouldAddOneDependencyFromProject() throws AssemblyFormattingException, ArchiveCreationException, IOException, InvalidAssemblerConfigurationException, DependencyResolutionException {
    final String outputLocation = "/out";
    final MavenProject project = newMavenProject("group", "project", "0");
    final ArtifactMock projectArtifactMock = new ArtifactMock(mm, "group", "project", "0", "jar", false);
    project.setArtifact(projectArtifactMock.getArtifact());
    final DependencySet ds = new DependencySet();
    ds.setUseProjectArtifact(false);
    ds.setOutputDirectory(outputLocation);
    ds.setOutputFileNameMapping("${artifact.artifactId}");
    ds.setUnpack(false);
    ds.setScope(Artifact.SCOPE_COMPILE);
    ds.setFileMode(Integer.toString(10, 8));
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    assembly.setIncludeBaseDirectory(false);
    assembly.addDependencySet(ds);
    final MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(mm, project);
    final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "dep", "1", "jar", false);
    System.out.println("On test setup, hashcode for dependency artifact: " + artifactMock.getArtifact().hashCode());
    macTask.expectCSGetRepositories(null, null);
    macTask.expectGetDestFile(new File("junk"));
    //        macTask.expectAddFile( artifactFile, "out/dep", 10 );
    project.setArtifacts(Collections.singleton(artifactMock.getArtifact()));
    macTask.expectCSGetFinalName("final-name");
    final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
    final MavenProject depProject = newMavenProject("group", "dep", "1");
    macTask.expectBuildFromRepository(depProject);
    macTask.expectResolveDependencySets();
    mm.replayAll();
    createPhase(macTask, logger, macTask.dependencyResolver).execute(assembly, macTask.archiver, macTask.configSource);
    mm.verifyAll();
}
Also used : MockAndControlForAddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Logger(org.codehaus.plexus.logging.Logger) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 78 with MavenProject

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

the class DependencySetAssemblyPhaseTest method newMavenProject.

private MavenProject newMavenProject(final String groupId, final String artifactId, final String version) {
    final Model model = new Model();
    model.setGroupId(groupId);
    model.setArtifactId(artifactId);
    model.setVersion(version);
    return new MavenProject(model);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model)

Example 79 with MavenProject

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

the class FileItemAssemblyPhaseTest method testExecute_ShouldAddRelativeFileNoFilterNoLineEndingConversion.

public void testExecute_ShouldAddRelativeFileNoFilterNoLineEndingConversion() throws ArchiveCreationException, AssemblyFormattingException, IOException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForConfigSource macCS = new MockAndControlForConfigSource(mm);
    final File basedir = fileManager.createTempDir();
    final File file = fileManager.createFile(basedir, "file.txt", "This is a test file.");
    macCS.expectGetBasedir(basedir);
    macCS.expectGetProject(new MavenProject(new Model()));
    macCS.expectGetFinalName("final-name");
    macCS.expectInterpolators();
    final MockAndControlForLogger macLogger = new MockAndControlForLogger(mm);
    final MockAndControlForArchiver macArchiver = new MockAndControlForArchiver(mm);
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    final FileItem fi = new FileItem();
    fi.setSource("file.txt");
    fi.setFiltered(false);
    fi.setLineEnding("keep");
    fi.setFileMode("777");
    macArchiver.expectAddFile(file, "file.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    assembly.addFile(fi);
    mm.replayAll();
    createPhase(macLogger.logger).execute(assembly, macArchiver.archiver, macCS.configSource);
    mm.verifyAll();
}
Also used : FileItem(org.apache.maven.plugins.assembly.model.FileItem) EasyMockSupport(org.easymock.classextension.EasyMockSupport) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Model(org.apache.maven.model.Model) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 80 with MavenProject

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

the class FileItemAssemblyPhaseTest method testExecute_WithOutputDirectory.

public void testExecute_WithOutputDirectory() throws Exception {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForConfigSource macCS = new MockAndControlForConfigSource(mm);
    final File basedir = fileManager.createTempDir();
    final File readmeFile = fileManager.createFile(basedir, "README.txt", "This is a test file for README.txt.");
    final File licenseFile = fileManager.createFile(basedir, "LICENSE.txt", "This is a test file for LICENSE.txt.");
    final File configFile = fileManager.createFile(basedir, "config/config.txt", "This is a test file for config/config.txt");
    macCS.expectGetBasedir(basedir);
    macCS.expectGetProject(new MavenProject(new Model()));
    macCS.expectGetFinalName("final-name");
    macCS.expectInterpolators();
    final MockAndControlForLogger macLogger = new MockAndControlForLogger(mm);
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        macLogger.logger.error("OS=Windows and the assembly descriptor contains a *nix-specific " + "root-relative-reference (starting with slash) /");
    } else {
        macLogger.logger.warn((String) anyObject());
    }
    final MockAndControlForArchiver macArchiver = new MockAndControlForArchiver(mm);
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    assembly.setIncludeBaseDirectory(true);
    final FileItem readmeFileItem = new FileItem();
    readmeFileItem.setSource("README.txt");
    readmeFileItem.setOutputDirectory("");
    readmeFileItem.setFiltered(false);
    readmeFileItem.setLineEnding("keep");
    readmeFileItem.setFileMode("777");
    final FileItem licenseFileItem = new FileItem();
    licenseFileItem.setSource("LICENSE.txt");
    licenseFileItem.setOutputDirectory("/");
    licenseFileItem.setFiltered(false);
    licenseFileItem.setLineEnding("keep");
    licenseFileItem.setFileMode("777");
    final FileItem configFileItem = new FileItem();
    configFileItem.setSource("config/config.txt");
    configFileItem.setOutputDirectory("config");
    configFileItem.setFiltered(false);
    configFileItem.setLineEnding("keep");
    configFileItem.setFileMode("777");
    macArchiver.expectAddFile(readmeFile, "README.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    macArchiver.expectAddFile(licenseFile, "LICENSE.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    macArchiver.expectAddFile(configFile, "config/config.txt", TypeConversionUtils.modeToInt("777", new ConsoleLogger(Logger.LEVEL_DEBUG, "test")));
    assembly.addFile(readmeFileItem);
    assembly.addFile(licenseFileItem);
    assembly.addFile(configFileItem);
    mm.replayAll();
    createPhase(macLogger.logger).execute(assembly, macArchiver.archiver, macCS.configSource);
    mm.verifyAll();
}
Also used : FileItem(org.apache.maven.plugins.assembly.model.FileItem) EasyMockSupport(org.easymock.classextension.EasyMockSupport) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Model(org.apache.maven.model.Model) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

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