Search in sources :

Example 1 with ManipulationSession

use of org.commonjava.maven.ext.core.ManipulationSession in project pom-manipulation-ext by release-engineering.

the class VersioningCalculatorTest method setupSession.

private VersioningState setupSession(final Properties properties, final Map<ProjectRef, String[]> versionMap) throws Exception {
    final ArtifactRepository ar = new MavenArtifactRepository("test", "http://repo.maven.apache.org/maven2", new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy());
    final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties(properties).setRemoteRepositories(Arrays.asList(ar));
    final PlexusContainer container = new DefaultPlexusContainer();
    final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult());
    session = new ManipulationSession();
    session.setMavenSession(mavenSession);
    final VersioningState state = new VersioningState(properties);
    session.setState(state);
    final Map<String, byte[]> dataMap = new HashMap<>();
    if (versionMap != null && !versionMap.isEmpty()) {
        for (final Map.Entry<ProjectRef, String[]> entry : versionMap.entrySet()) {
            final String path = toMetadataPath(entry.getKey());
            final byte[] data = setupMetadataVersions(entry.getValue());
            dataMap.put(path, data);
        }
    }
    final Location mdLoc = MavenLocationExpander.EXPANSION_TARGET;
    final Transport mdTrans = new StubTransport(dataMap);
    modder = new TestVersionCalculator(new ManipulationSession(), mdLoc, mdTrans, temp.newFolder("galley-cache"));
    return state;
}
Also used : DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) PlexusContainer(org.codehaus.plexus.PlexusContainer) HashMap(java.util.HashMap) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) StubTransport(org.commonjava.maven.ext.core.fixture.StubTransport) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) MavenSession(org.apache.maven.execution.MavenSession) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) VersioningState(org.commonjava.maven.ext.core.state.VersioningState) SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) Transport(org.commonjava.maven.galley.spi.transport.Transport) StubTransport(org.commonjava.maven.ext.core.fixture.StubTransport) HashMap(java.util.HashMap) Map(java.util.Map) Location(org.commonjava.maven.galley.model.Location)

Example 2 with ManipulationSession

use of org.commonjava.maven.ext.core.ManipulationSession in project pom-manipulation-ext by release-engineering.

the class ModelResolverTest method resolveArtifactTest.

@Test(expected = ManipulationException.class)
@BMRule(name = "retrieve-first-null", targetClass = "ArtifactManagerImpl", targetMethod = "retrieveFirst(List<? extends Location> locations, ArtifactRef ref)", targetLocation = "AT ENTRY", action = "RETURN null")
public void resolveArtifactTest() throws Exception {
    final ManipulationSession session = new ManipulationSession();
    final GalleyInfrastructure galleyInfra = new GalleyInfrastructure(session.getTargetDir(), session.getRemoteRepositories(), session.getLocalRepository(), session.getSettings(), session.getActiveProfiles(), null, null, null, temp.newFolder("cache-dir"));
    final GalleyAPIWrapper wrapper = new GalleyAPIWrapper(galleyInfra);
    final ModelIO model = new ModelIO();
    FieldUtils.writeField(model, "galleyWrapper", wrapper, true);
    model.resolveRawModel(SimpleProjectVersionRef.parse("org.commonjava:commonjava:5"));
}
Also used : GalleyInfrastructure(org.commonjava.maven.ext.io.resolver.GalleyInfrastructure) ModelIO(org.commonjava.maven.ext.io.ModelIO) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) GalleyAPIWrapper(org.commonjava.maven.ext.io.resolver.GalleyAPIWrapper) BMRule(org.jboss.byteman.contrib.bmunit.BMRule) Test(org.junit.Test)

Example 3 with ManipulationSession

use of org.commonjava.maven.ext.core.ManipulationSession in project pom-manipulation-ext by release-engineering.

the class PropertiesUtilsTest method testUpdateNestedProperties.

@Test
public void testUpdateNestedProperties() throws Exception {
    Project pP = getProject();
    ManipulationSession session = createUpdateSession();
    assertTrue(updateProperties(session, pP, false, "version.hibernate.core", "5.0.4.Final-redhat-1") == PropertiesUtils.PropertyUpdate.FOUND);
    assertTrue(updateProperties(session, pP, false, "version.scala", "2.11.7.redhat-1") == PropertiesUtils.PropertyUpdate.FOUND);
    try {
        updateProperties(session, pP, false, "version.scala", "3.11.7-redhat-1");
    } catch (ManipulationException e) {
    // Pass.
    }
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) Test(org.junit.Test)

Example 4 with ManipulationSession

use of org.commonjava.maven.ext.core.ManipulationSession in project pom-manipulation-ext by release-engineering.

the class PropertiesUtilsTest method testStrictWithTimeStamp.

@Test
public void testStrictWithTimeStamp() throws Exception {
    String suffix = "t-20170216-223844-555-rebuild";
    p.setProperty("version.suffix", suffix + "-1");
    ManipulationSession session = createUpdateSession();
    assertTrue(PropertiesUtils.getSuffix(session).equals(suffix));
    assertTrue(PropertiesUtils.checkStrictValue(session, "1.0.0.Final", "1.0.0.Final-t-20170216-223844-555-rebuild-1"));
    assertTrue(PropertiesUtils.checkStrictValue(session, "1.0", "1.0.0.t-20170216-223844-555-rebuild-1"));
    assertTrue(PropertiesUtils.checkStrictValue(session, "1.0-SNAPSHOT", "1.0.0.t-20170216-223844-555-rebuild-1"));
    suffix = "t20170216223844555-rebuild";
    p.setProperty("version.suffix", suffix + "-2");
    session = createUpdateSession();
    assertTrue(PropertiesUtils.getSuffix(session).equals(suffix));
    assertTrue(PropertiesUtils.checkStrictValue(session, "1.0.0.Final", "1.0.0.Final-t20170216223844555-rebuild-2"));
    assertTrue(PropertiesUtils.checkStrictValue(session, "1.0", "1.0.0.t20170216223844555-rebuild-2"));
    assertTrue(PropertiesUtils.checkStrictValue(session, "1.0-SNAPSHOT", "1.0.0.t20170216223844555-rebuild-2"));
}
Also used : ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) Test(org.junit.Test)

Example 5 with ManipulationSession

use of org.commonjava.maven.ext.core.ManipulationSession in project pom-manipulation-ext by release-engineering.

the class PropertiesUtilsTest method testResolveProperties.

@Test
public void testResolveProperties() throws Exception {
    final Model modelChild = TestUtils.resolveModelResource(RESOURCE_BASE, "inherited-properties.pom");
    final Model modelParent = TestUtils.resolveModelResource(RESOURCE_BASE, "infinispan-bom-8.2.0.Final.pom");
    ManipulationSession session = createUpdateSession();
    Project pP = new Project(modelParent);
    Project pC = new Project(modelChild);
    List<Project> al = new ArrayList<>();
    al.add(pC);
    al.add(pP);
    String result = PropertyResolver.resolveProperties(session, al, "${version.scala.major}.${version.scala.minor}");
    assertTrue(result.equals("2.11.7"));
    result = PropertyResolver.resolveProperties(session, al, "TestSTART.and.${version.scala.major}.now.${version.scala.minor}");
    assertTrue(result.equals("TestSTART.and.2.11.now.7"));
    result = PropertyResolver.resolveProperties(session, al, "${project.version}");
    assertTrue(result.equals("1"));
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) Model(org.apache.maven.model.Model) ArrayList(java.util.ArrayList) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) Test(org.junit.Test)

Aggregations

ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)23 Test (org.junit.Test)20 Project (org.commonjava.maven.ext.common.model.Project)9 File (java.io.File)8 MavenSession (org.apache.maven.execution.MavenSession)7 Model (org.apache.maven.model.Model)4 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)3 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)2 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)2 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)2 Dependency (org.apache.maven.model.Dependency)2 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)2 PlexusContainer (org.codehaus.plexus.PlexusContainer)2 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)2 VersioningState (org.commonjava.maven.ext.core.state.VersioningState)2 PomIO (org.commonjava.maven.ext.io.PomIO)2 GalleyAPIWrapper (org.commonjava.maven.ext.io.resolver.GalleyAPIWrapper)2 GalleyInfrastructure (org.commonjava.maven.ext.io.resolver.GalleyInfrastructure)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1