Search in sources :

Example 11 with Project

use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.

the class IconEnricher method getDefaultIconRef.

/**
 * Lets use the project and its classpath to try figure out what default icon to use
 *
 * @return the icon ref if we can detect one or return null
 */
private String getDefaultIconRef() {
    MavenProject project = getProject();
    EnricherContext context = getContext();
    if (hasClass(project, "io.fabric8.funktion.runtime.Main") || MavenUtil.hasDependencyOnAnyArtifactOfGroup(project, "io.fabric8.funktion")) {
        return "funktion";
    }
    if (hasClass(project, "org.apache.camel.CamelContext")) {
        return "camel";
    }
    if (hasPlugin(project, "org.springframework.boot:spring-boot-maven-plugin") || hasClass(project, "org.springframework.boot.SpringApplication")) {
        return "spring-boot";
    }
    if (hasClass(project, "org.springframework.core.Constants")) {
        return "spring";
    }
    if (hasClass(project, "org.vertx.java.core.Handler", "io.vertx.core.Handler")) {
        return "vertx";
    }
    if (hasPlugin(project, "org.wildfly.swarm:wildfly-swarm-plugin") || MavenUtil.hasDependencyOnAnyArtifactOfGroup(project, "org.wildfly.swarm")) {
        return "wildfly-swarm";
    }
    return null;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) EnricherContext(io.fabric8.maven.enricher.api.EnricherContext)

Example 12 with Project

use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.

the class DefaultControllerEnricherTest method setupExpectations.

protected void setupExpectations(final BuildImageConfiguration buildConfig, final TreeMap controllerConfig) {
    new Expectations() {

        {
            project.getArtifactId();
            result = "fmp-controller-test";
            project.getBuild().getOutputDirectory();
            result = Files.createTempDir().getAbsolutePath();
            context.getProject();
            result = project;
            context.getConfig();
            result = new ProcessorConfig(null, null, Collections.singletonMap("fmp-controller", controllerConfig));
            imageConfiguration.getBuildConfiguration();
            result = buildConfig;
            imageConfiguration.getName();
            result = "helloworld";
            context.getImages();
            result = Arrays.asList(imageConfiguration);
        }
    };
}
Also used : Expectations(mockit.Expectations) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig)

Example 13 with Project

use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.

the class MavenProjectEnricherTest method testOldStyleGeneratedResources.

@Test
public void testOldStyleGeneratedResources() {
    final Properties properties = new Properties();
    properties.setProperty("fabric8.enricher.fmp-project.useProjectLabel", "true");
    new Expectations() {

        {
            mavenProject.getProperties();
            result = properties;
        }
    };
    ProjectEnricher projectEnricher = new ProjectEnricher(context);
    KubernetesListBuilder builder = createListWithDeploymentConfig();
    projectEnricher.adapt(builder);
    KubernetesList list = builder.build();
    Map<String, String> labels = list.getItems().get(0).getMetadata().getLabels();
    assertNotNull(labels);
    assertEquals("groupId", labels.get("group"));
    assertEquals("artifactId", labels.get("project"));
    assertEquals("version", labels.get("version"));
    assertNull(labels.get("app"));
    Map<String, String> selectors = projectEnricher.getSelector(Kind.DEPLOYMENT_CONFIG);
    assertEquals("groupId", selectors.get("group"));
    assertEquals("artifactId", selectors.get("project"));
    assertNull(selectors.get("version"));
    assertNull(selectors.get("app"));
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Properties(java.util.Properties) Test(org.junit.Test)

Example 14 with Project

use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.

the class MavenProjectEnricherTest method testGeneratedResources.

@Test
public void testGeneratedResources() {
    ProjectEnricher projectEnricher = new ProjectEnricher(context);
    KubernetesListBuilder builder = createListWithDeploymentConfig();
    projectEnricher.adapt(builder);
    KubernetesList list = builder.build();
    Map<String, String> labels = list.getItems().get(0).getMetadata().getLabels();
    assertNotNull(labels);
    assertEquals("groupId", labels.get("group"));
    assertEquals("artifactId", labels.get("app"));
    assertEquals("version", labels.get("version"));
    assertNull(labels.get("project"));
    Map<String, String> selectors = projectEnricher.getSelector(Kind.DEPLOYMENT_CONFIG);
    assertEquals("groupId", selectors.get("group"));
    assertEquals("artifactId", selectors.get("app"));
    assertNull(selectors.get("version"));
    assertNull(selectors.get("project"));
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Test(org.junit.Test)

Example 15 with Project

use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.

the class ProfileUtilTest method mergeProfiles.

@Test
public void mergeProfiles() throws Exception {
    Profile profile = ProfileUtil.findProfile("merge-1", getProfileDir());
    assertFalse(profile.getEnricherConfig().use("fmp-project"));
    assertTrue(profile.getEnricherConfig().use("fmp-image"));
}
Also used : Profile(io.fabric8.maven.core.config.Profile) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)51 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)29 File (java.io.File)14 Expectations (mockit.Expectations)14 ArrayList (java.util.ArrayList)13 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)11 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)11 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)9 IOException (java.io.IOException)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)7 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)6 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)6 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)5 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)5 MojoFailureException (org.apache.maven.plugin.MojoFailureException)5 MavenProject (org.apache.maven.project.MavenProject)5 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)4 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3