Search in sources :

Example 1 with InterpolationState

use of org.codehaus.plexus.interpolation.fixed.InterpolationState 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 2 with InterpolationState

use of org.codehaus.plexus.interpolation.fixed.InterpolationState in project maven-plugins by apache.

the class AssemblyExpressionEvaluator method evaluate.

@Override
public Object evaluate(String expression) throws ExpressionEvaluationException {
    InterpolationState is = new InterpolationState();
    is.setRecursionInterceptor(interceptor);
    return interpolator.interpolate(expression, is);
}
Also used : InterpolationState(org.codehaus.plexus.interpolation.fixed.InterpolationState)

Example 3 with InterpolationState

use of org.codehaus.plexus.interpolation.fixed.InterpolationState in project maven-plugins by apache.

the class DefaultAssemblyReaderTest method testMergeComponentsWithMainAssembly_ShouldAddOneFileSetToAssembly.

public void testMergeComponentsWithMainAssembly_ShouldAddOneFileSetToAssembly() throws IOException, AssemblyReadException {
    final Component component = new Component();
    final FileSet fileSet = new FileSet();
    fileSet.setDirectory("/dir");
    component.addFileSet(fileSet);
    final File componentFile = fileManager.createTempFile();
    Writer writer = null;
    try {
        writer = new OutputStreamWriter(new FileOutputStream(componentFile), "UTF-8");
        final ComponentXpp3Writer componentWriter = new ComponentXpp3Writer();
        componentWriter.write(writer, component);
        writer.close();
        writer = null;
    } finally {
        IOUtil.close(writer);
    }
    final String filename = componentFile.getName();
    final Assembly assembly = new Assembly();
    assembly.addComponentDescriptor(filename);
    final File basedir = componentFile.getParentFile();
    final MavenProject project = new MavenProject();
    expect(configSource.getProject()).andReturn(project).anyTimes();
    expect(configSource.getBasedir()).andReturn(basedir).anyTimes();
    DefaultAssemblyArchiverTest.setupInterpolators(configSource);
    InterpolationState is = new InterpolationState();
    ComponentXpp3Reader.ContentTransformer componentIp = AssemblyInterpolator.componentInterpolator(FixedStringSearchInterpolator.create(), is, new ConsoleLogger(Logger.LEVEL_DEBUG, "console"));
    mockManager.replayAll();
    new DefaultAssemblyReader().mergeComponentsWithMainAssembly(assembly, null, configSource, componentIp);
    final List<FileSet> fileSets = assembly.getFileSets();
    assertNotNull(fileSets);
    assertEquals(1, fileSets.size());
    final FileSet fs = fileSets.get(0);
    assertEquals("/dir", fs.getDirectory());
    mockManager.verifyAll();
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) MavenProject(org.apache.maven.project.MavenProject) ComponentXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader) InterpolationState(org.codehaus.plexus.interpolation.fixed.InterpolationState) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) FileOutputStream(java.io.FileOutputStream) 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)

Aggregations

InterpolationState (org.codehaus.plexus.interpolation.fixed.InterpolationState)3 Assembly (org.apache.maven.plugins.assembly.model.Assembly)2 ComponentXpp3Reader (org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader)2 MavenProject (org.apache.maven.project.MavenProject)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Component (org.apache.maven.plugins.assembly.model.Component)1 FileSet (org.apache.maven.plugins.assembly.model.FileSet)1 AssemblyXpp3Reader (org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Reader)1 AssemblyXpp3Writer (org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Writer)1 ComponentXpp3Writer (org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer)1 PrefixAwareRecursionInterceptor (org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor)1 RecursionInterceptor (org.codehaus.plexus.interpolation.RecursionInterceptor)1 FixedStringSearchInterpolator (org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator)1 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)1 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)1