Search in sources :

Example 1 with PropertiesBasedValueSource

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

the class AssemblyInterpolatorTest method testShouldResolveContextValueBeforeModelPropertyOrModelGroupIdInAssemblyId.

public void testShouldResolveContextValueBeforeModelPropertyOrModelGroupIdInAssemblyId() 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 Assembly assembly = new Assembly();
    assembly.setId("assembly.${groupId}");
    final EasyMockSupport mm = new EasyMockSupport();
    final MavenSession session = mm.createMock(MavenSession.class);
    final Properties execProps = new Properties();
    execProps.setProperty("groupId", "still.another.id");
    expect(session.getExecutionProperties()).andReturn(execProps).anyTimes();
    expect(session.getUserProperties()).andReturn(new Properties()).anyTimes();
    final PojoConfigSource cs = new PojoConfigSource();
    final ArtifactRepository lr = mm.createMock(ArtifactRepository.class);
    cs.setLocalRepository(lr);
    cs.setMavenSession(session);
    cs.setRootInterpolator(FixedStringSearchInterpolator.create());
    cs.setEnvironmentInterpolator(FixedStringSearchInterpolator.create(new PropertiesBasedValueSource(execProps)));
    cs.setEnvInterpolator(FixedStringSearchInterpolator.empty());
    expect(lr.getBasedir()).andReturn("/path/to/local/repo").anyTimes();
    mm.replayAll();
    final MavenProject project = new MavenProject(model);
    cs.setMavenProject(project);
    final Assembly result = roundTripInterpolation(assembly, cs);
    assertEquals("assembly.still.another.id", result.getId());
    mm.verifyAll();
    mm.resetAll();
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) EasyMockSupport(org.easymock.classextension.EasyMockSupport) MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) PojoConfigSource(org.apache.maven.plugins.assembly.testutils.PojoConfigSource) Properties(java.util.Properties) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.fixed.PropertiesBasedValueSource) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 2 with PropertiesBasedValueSource

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

the class AbstractAssemblyMojo method createCommandLinePropertiesInterpolator.

private FixedStringSearchInterpolator createCommandLinePropertiesInterpolator() {
    Properties commandLineProperties = System.getProperties();
    final MavenSession session = getMavenSession();
    if (session != null) {
        commandLineProperties = new Properties();
        commandLineProperties.putAll(session.getSystemProperties());
        commandLineProperties.putAll(session.getUserProperties());
    }
    PropertiesBasedValueSource cliProps = new PropertiesBasedValueSource(commandLineProperties);
    return FixedStringSearchInterpolator.create(cliProps);
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) Properties(java.util.Properties) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.fixed.PropertiesBasedValueSource)

Example 3 with PropertiesBasedValueSource

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

the class AssemblyExpressionEvaluatorTest method testShouldResolveContextValueBeforeModelPropertyOrModelGroupIdInAssemblyId.

public void testShouldResolveContextValueBeforeModelPropertyOrModelGroupIdInAssemblyId() throws ExpressionEvaluationException {
    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 EasyMockSupport mm = new EasyMockSupport();
    MavenSession session = mm.createControl().createMock(MavenSession.class);
    final Properties execProps = new Properties();
    execProps.setProperty("groupId", "still.another.id");
    PropertiesBasedValueSource cliProps = new PropertiesBasedValueSource(execProps);
    expect(session.getExecutionProperties()).andReturn(execProps).anyTimes();
    expect(session.getUserProperties()).andReturn(new Properties()).anyTimes();
    AssemblerConfigurationSource cs = mm.createControl().createMock(AssemblerConfigurationSource.class);
    expect(cs.getCommandLinePropsInterpolator()).andReturn(FixedStringSearchInterpolator.create(cliProps)).anyTimes();
    expect(cs.getRepositoryInterpolator()).andReturn(FixedStringSearchInterpolator.create()).anyTimes();
    expect(cs.getEnvInterpolator()).andReturn(FixedStringSearchInterpolator.create()).anyTimes();
    expect(cs.getMavenSession()).andReturn(session).anyTimes();
    expect(cs.getProject()).andReturn(new MavenProject(model));
    final IMocksControl lrCtl = mm.createControl();
    final ArtifactRepository lr = lrCtl.createMock(ArtifactRepository.class);
    expect(lr.getBasedir()).andReturn("/path/to/local/repo").anyTimes();
    expect(cs.getLocalRepository()).andReturn(lr).anyTimes();
    mm.replayAll();
    final Object result = new AssemblyExpressionEvaluator(cs).evaluate("assembly.${groupId}");
    assertEquals("assembly.still.another.id", result);
    mm.verifyAll();
}
Also used : IMocksControl(org.easymock.classextension.IMocksControl) MavenSession(org.apache.maven.execution.MavenSession) EasyMockSupport(org.easymock.classextension.EasyMockSupport) MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) AssemblerConfigurationSource(org.apache.maven.plugins.assembly.AssemblerConfigurationSource) Properties(java.util.Properties) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.fixed.PropertiesBasedValueSource)

Example 4 with PropertiesBasedValueSource

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

the class AbstractAssemblyMojo method createRepositoryInterpolator.

private FixedStringSearchInterpolator createRepositoryInterpolator() {
    final Properties settingsProperties = new Properties();
    final MavenSession session = getMavenSession();
    if (getLocalRepository() != null) {
        settingsProperties.setProperty("localRepository", getLocalRepository().getBasedir());
        settingsProperties.setProperty("settings.localRepository", getLocalRepository().getBasedir());
    } else if (session != null && session.getSettings() != null) {
        settingsProperties.setProperty("localRepository", session.getSettings().getLocalRepository());
        settingsProperties.setProperty("settings.localRepository", getLocalRepository().getBasedir());
    }
    return FixedStringSearchInterpolator.create(new PropertiesBasedValueSource(settingsProperties));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) Properties(java.util.Properties) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.fixed.PropertiesBasedValueSource)

Example 5 with PropertiesBasedValueSource

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

the class AssemblyFormatUtils method classifierRules.

@Nonnull
public static FixedStringSearchInterpolator classifierRules(final Artifact artifact) {
    final Properties specialRules = new Properties();
    final String classifier = ProjectUtils.getClassifier(artifact);
    if (classifier != null) {
        specialRules.setProperty("dashClassifier?", "-" + classifier);
        specialRules.setProperty("dashClassifier", "-" + classifier);
    } else {
        specialRules.setProperty("dashClassifier?", "");
        specialRules.setProperty("dashClassifier", "");
    }
    return FixedStringSearchInterpolator.create(new PropertiesBasedValueSource(specialRules));
}
Also used : Properties(java.util.Properties) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.fixed.PropertiesBasedValueSource) Nonnull(javax.annotation.Nonnull)

Aggregations

Properties (java.util.Properties)8 PropertiesBasedValueSource (org.codehaus.plexus.interpolation.fixed.PropertiesBasedValueSource)8 MavenSession (org.apache.maven.execution.MavenSession)6 Nonnull (javax.annotation.Nonnull)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 Model (org.apache.maven.model.Model)2 MavenProject (org.apache.maven.project.MavenProject)2 EasyMockSupport (org.easymock.classextension.EasyMockSupport)2 AssemblerConfigurationSource (org.apache.maven.plugins.assembly.AssemblerConfigurationSource)1 Assembly (org.apache.maven.plugins.assembly.model.Assembly)1 PojoConfigSource (org.apache.maven.plugins.assembly.testutils.PojoConfigSource)1 IMocksControl (org.easymock.classextension.IMocksControl)1