Search in sources :

Example 1 with MavenBinary

use of org.guvnor.ala.build.maven.model.MavenBinary in project kie-wb-common by kiegroup.

the class ContextAwareWildflyRuntimeExecConfig method setContext.

@Override
public void setContext(final Map<String, ?> context) {
    this.context = context;
    MavenBinary binary = (MavenBinary) context.get("binary");
    if (binary != null) {
        this.warPath = binary.getPath().toString();
    }
    WildflyProvider provider = (WildflyProvider) context.get("wildfly-provider");
    this.providerId = provider;
}
Also used : MavenBinary(org.guvnor.ala.build.maven.model.MavenBinary) WildflyProvider(org.guvnor.ala.wildfly.model.WildflyProvider)

Example 2 with MavenBinary

use of org.guvnor.ala.build.maven.model.MavenBinary in project kie-wb-common by kiegroup.

the class ContextAwareWildflyRuntimeExecConfigTest method testContextUsingMavenBinary.

@Test
public void testContextUsingMavenBinary() {
    final ContextAwareWildflyRuntimeExecConfig config = new ContextAwareWildflyRuntimeExecConfig();
    final Map<String, Object> context = new HashMap<>();
    final WildflyProvider provider = mock(WildflyProvider.class);
    context.put("wildfly-provider", provider);
    final MavenBinary binary = mock(MavenBinary.class);
    final Path path = mock(Path.class);
    when(binary.getPath()).thenReturn(path);
    when(path.toString()).thenReturn(FILE_PATH);
    context.put("binary", binary);
    config.setContext(context);
    assertEquals(provider, config.getProviderId());
    assertEquals(FILE_PATH, config.getWarPath());
    final WildflyRuntimeExecConfig configClone = config.asNewClone(config);
    assertEquals(provider, configClone.getProviderId());
    assertEquals(FILE_PATH, configClone.getWarPath());
}
Also used : Path(org.uberfire.java.nio.file.Path) HashMap(java.util.HashMap) ContextAwareWildflyRuntimeExecConfig(org.guvnor.ala.wildfly.config.impl.ContextAwareWildflyRuntimeExecConfig) WildflyRuntimeExecConfig(org.guvnor.ala.wildfly.config.WildflyRuntimeExecConfig) ContextAwareWildflyRuntimeExecConfig(org.guvnor.ala.wildfly.config.impl.ContextAwareWildflyRuntimeExecConfig) MavenBinary(org.guvnor.ala.build.maven.model.MavenBinary) WildflyProvider(org.guvnor.ala.wildfly.model.WildflyProvider) Test(org.junit.Test)

Example 3 with MavenBinary

use of org.guvnor.ala.build.maven.model.MavenBinary in project kie-wb-common by kiegroup.

the class MavenDependencyConfigExecutorTest method testMavenDependencyAPI.

@Test
public void testMavenDependencyAPI() throws Exception {
    final String groupId = "org.guvnor.ala";
    final String artifactId = "maven-ala-artifact-test";
    final String version = "1";
    final String artifactPath = "/org/guvnor/ala/maven-ala-artifact-test/1/maven-ala-artifact-test-1.pom";
    final String oldSettingsXmlPath = System.getProperty(CUSTOM_SETTINGS_PROPERTY);
    try {
        final Path settingsXmlPath = generateSettingsXml();
        System.setProperty(CUSTOM_SETTINGS_PROPERTY, settingsXmlPath.toString());
        MavenSettings.reinitSettings();
        installArtifactLocally(groupId, artifactId, version);
        final BuildRegistry buildRegistry = new InMemoryBuildRegistry();
        final Pipeline pipe = PipelineFactory.newBuilder().addConfigStage("Maven Artifact", new MavenDependencyConfigImpl()).buildAs("my pipe");
        final PipelineExecutor executor = new PipelineExecutor(singletonList(new MavenDependencyConfigExecutor(buildRegistry)));
        executor.execute(new Input() {

            {
                put("artifact", groupId + ":" + artifactId + ":pom:" + version);
            }
        }, pipe, System.out::println);
        final List<Binary> allBinaries = buildRegistry.getAllBinaries();
        assertNotNull(allBinaries);
        assertEquals(1, allBinaries.size());
        assertTrue(allBinaries.get(0) instanceof MavenBinary);
        final MavenBinary binary = (MavenBinary) allBinaries.get(0);
        assertEquals("Maven", binary.getType());
        assertEquals(artifactId, binary.getName());
        assertEquals(groupId, binary.getGroupId());
        assertEquals(artifactId, binary.getArtifactId());
        assertEquals(version, binary.getVersion());
        assertEquals(Paths.get(m2Folder.getPath(), artifactPath).toString(), binary.getPath().toString());
    } finally {
        if (oldSettingsXmlPath == null) {
            System.clearProperty(CUSTOM_SETTINGS_PROPERTY);
        } else {
            System.setProperty(CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath);
        }
        MavenSettings.reinitSettings();
    }
}
Also used : Path(java.nio.file.Path) InMemoryBuildRegistry(org.guvnor.ala.registry.inmemory.InMemoryBuildRegistry) MavenDependencyConfigImpl(org.guvnor.ala.build.maven.config.impl.MavenDependencyConfigImpl) MavenBinary(org.guvnor.ala.build.maven.model.MavenBinary) PipelineExecutor(org.guvnor.ala.pipeline.execution.PipelineExecutor) Pipeline(org.guvnor.ala.pipeline.Pipeline) Input(org.guvnor.ala.pipeline.Input) BuildRegistry(org.guvnor.ala.registry.BuildRegistry) InMemoryBuildRegistry(org.guvnor.ala.registry.inmemory.InMemoryBuildRegistry) Binary(org.guvnor.ala.build.Binary) MavenBinary(org.guvnor.ala.build.maven.model.MavenBinary) Test(org.junit.Test)

Example 4 with MavenBinary

use of org.guvnor.ala.build.maven.model.MavenBinary in project kie-wb-common by kiegroup.

the class MavenProjectConfigExecutorTest method assertMavenBinary.

private static void assertMavenBinary(final Binary binary, final Project project) {
    assertTrue(binary instanceof MavenBinary);
    final MavenBinary mavenBinary = (MavenBinary) binary;
    assertEquals("Maven", mavenBinary.getType());
    final File pom = new File(project.getTempDir(), "pom.xml");
    final MavenProject mavenProject = MavenProjectLoader.parseMavenPom(pom);
    assertEquals(mavenProject.getGroupId(), mavenBinary.getGroupId());
    assertEquals(mavenProject.getArtifactId(), mavenBinary.getArtifactId());
    assertEquals(mavenProject.getVersion(), mavenBinary.getVersion());
    assertEquals(project.getTempDir() + "/target/" + project.getExpectedBinary(), mavenBinary.getPath().toString());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MavenBinary(org.guvnor.ala.build.maven.model.MavenBinary) File(java.io.File)

Example 5 with MavenBinary

use of org.guvnor.ala.build.maven.model.MavenBinary in project kie-wb-common by kiegroup.

the class MavenDependencyConfigExecutor method apply.

@Override
public Optional<MavenBinary> apply(final MavenDependencyConfig config) {
    final String artifactId = config.getArtifact();
    checkNotEmpty("artifact parameter is mandatory", artifactId);
    LOGGER.debug("Resolving Artifact: {}", artifactId);
    final Artifact artifact = resolveArtifact(artifactId);
    if (artifact == null) {
        throw new RuntimeException("Cannot resolve Maven artifact. Look at the previous logs for more information.");
    }
    final String absolutePath = artifact.getFile().getAbsolutePath();
    LOGGER.debug("Resolved Artifact path: {}", absolutePath);
    final Path path = FileSystems.getFileSystem(URI.create("file://default")).getPath(absolutePath);
    final MavenBinary binary = new MavenBinaryImpl(path, artifact.getArtifactId(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
    buildRegistry.registerBinary(binary);
    return Optional.of(binary);
}
Also used : Path(org.uberfire.java.nio.file.Path) MavenBinaryImpl(org.guvnor.ala.build.maven.model.impl.MavenBinaryImpl) MavenBinary(org.guvnor.ala.build.maven.model.MavenBinary) Artifact(org.eclipse.aether.artifact.Artifact)

Aggregations

MavenBinary (org.guvnor.ala.build.maven.model.MavenBinary)7 Path (org.uberfire.java.nio.file.Path)3 File (java.io.File)2 MavenProject (org.apache.maven.project.MavenProject)2 Binary (org.guvnor.ala.build.Binary)2 WildflyProvider (org.guvnor.ala.wildfly.model.WildflyProvider)2 Test (org.junit.Test)2 URL (java.net.URL)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 Artifact (org.eclipse.aether.artifact.Artifact)1 Project (org.guvnor.ala.build.Project)1 MavenDependencyConfigImpl (org.guvnor.ala.build.maven.config.impl.MavenDependencyConfigImpl)1 MavenBinaryImpl (org.guvnor.ala.build.maven.model.impl.MavenBinaryImpl)1 MavenProjectBinaryImpl (org.guvnor.ala.build.maven.model.impl.MavenProjectBinaryImpl)1 Input (org.guvnor.ala.pipeline.Input)1 Pipeline (org.guvnor.ala.pipeline.Pipeline)1 PipelineExecutor (org.guvnor.ala.pipeline.execution.PipelineExecutor)1 BuildRegistry (org.guvnor.ala.registry.BuildRegistry)1