Search in sources :

Example 31 with JavaProject

use of org.eclipse.jkube.kit.common.JavaProject in project jkube by eclipse.

the class BaseGenerator method addSchemaLabels.

protected void addSchemaLabels(BuildConfiguration.BuildConfigurationBuilder buildBuilder, PrefixedLogger log) {
    final JavaProject project = getProject();
    String docURL = project.getDocumentationUrl();
    Map<String, String> labels = new HashMap<>();
    labels.put(BuildLabelAnnotations.BUILD_DATE.value(), LocalDateTime.now().toString());
    labels.put(BuildLabelAnnotations.NAME.value(), project.getName());
    labels.put(BuildLabelAnnotations.DESCRIPTION.value(), project.getDescription());
    if (docURL != null) {
        labels.put(BuildLabelAnnotations.USAGE.value(), docURL);
    }
    if (project.getSite() != null) {
        labels.put(BuildLabelAnnotations.URL.value(), project.getSite());
    }
    if (project.getOrganizationName() != null && !project.getOrganizationName().isEmpty()) {
        labels.put(BuildLabelAnnotations.VENDOR.value(), project.getOrganizationName());
    }
    labels.put(BuildLabelAnnotations.VERSION.value(), project.getVersion());
    labels.put(BuildLabelAnnotations.SCHEMA_VERSION.value(), LABEL_SCHEMA_VERSION);
    try {
        Repository repository = GitUtil.getGitRepository(project.getBaseDirectory());
        if (repository != null) {
            String commitID = GitUtil.getGitCommitId(repository);
            labels.put(BuildLabelAnnotations.VCS_REF.value(), commitID);
            String gitRemoteUrl = repository.getConfig().getString("remote", GIT_REMOTE, "url");
            if (gitRemoteUrl != null) {
                labels.put(BuildLabelAnnotations.VCS_URL.value(), gitRemoteUrl);
            } else {
                log.verbose("Could not detect any git remote");
            }
        }
    } catch (IOException | GitAPIException | NullPointerException e) {
        log.error("Cannot extract Git information: " + e, e);
    } finally {
        buildBuilder.labels(labels);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) JavaProject(org.eclipse.jkube.kit.common.JavaProject) Repository(org.eclipse.jgit.lib.Repository) HashMap(java.util.HashMap) IOException(java.io.IOException)

Example 32 with JavaProject

use of org.eclipse.jkube.kit.common.JavaProject in project jkube by eclipse.

the class GradleUtilTest method extractProperties_shouldContainSystemProperties.

@Test
public void extractProperties_shouldContainSystemProperties() {
    // Given
    System.setProperty("foo.property", "somevalue");
    when(project.getProperties()).thenReturn(Collections.emptyMap());
    // When
    final JavaProject result = convertGradleProject(project);
    // Then
    assertThat(result.getProperties()).hasFieldOrPropertyWithValue("foo.property", null).hasEntrySatisfying("foo.property", e -> assertThat(e).isEqualTo("somevalue"));
    System.clearProperty("foo.property");
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) Test(org.junit.Test)

Example 33 with JavaProject

use of org.eclipse.jkube.kit.common.JavaProject in project jkube by eclipse.

the class GradleUtilTest method findClassesOutputDirectory_withValidSourceSet_shouldReturnFromSourceSet.

@Test
public void findClassesOutputDirectory_withValidSourceSet_shouldReturnFromSourceSet() {
    // Given
    when(javaPlugin.getSourceSets().getByName("main").getJava().getDestinationDirectory().getAsFile()).thenReturn(new DefaultProvider<>(() -> new File("classes")));
    // When
    final JavaProject result = convertGradleProject(project);
    // Then
    assertThat(result.getOutputDirectory()).isEqualTo(new File("classes"));
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) File(java.io.File) Test(org.junit.Test)

Example 34 with JavaProject

use of org.eclipse.jkube.kit.common.JavaProject in project jkube by eclipse.

the class GradleUtilTest method findClassesOutputDirectory_withNoSourceSets_shouldReturnDefault.

@Test
public void findClassesOutputDirectory_withNoSourceSets_shouldReturnDefault() {
    // Given
    when(javaPlugin.getSourceSets()).thenReturn(null);
    // When
    final JavaProject result = convertGradleProject(project);
    // Then
    assertThat(result.getOutputDirectory()).isEqualTo(folder.getRoot().toPath().resolve("build").resolve("classes").resolve("java").resolve("main").toFile());
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) Test(org.junit.Test)

Example 35 with JavaProject

use of org.eclipse.jkube.kit.common.JavaProject in project jkube by eclipse.

the class MavenScmEnricherTest method testMavenScmOnlyUrl.

@Test
public void testMavenScmOnlyUrl() {
    final JavaProject project = JavaProject.builder().scmUrl("scm:git:git://github.com/jkubeio/kubernetes-maven-plugin.git").build();
    // Setup mock behaviour
    new Expectations() {

        {
            {
                context.getProject();
                result = project;
            }
        }
    };
    MavenScmEnricher mavenScmEnricher = new MavenScmEnricher(context);
    KubernetesListBuilder builder = new KubernetesListBuilder().withItems(new DeploymentBuilder().withNewMetadata().withName("foo").endMetadata().build());
    mavenScmEnricher.create(PlatformMode.kubernetes, builder);
    Map<String, String> scmAnnotations = builder.buildFirstItem().getMetadata().getAnnotations();
    assertNotNull(scmAnnotations);
    Assert.assertEquals(1, scmAnnotations.size());
    Assert.assertFalse(scmAnnotations.containsKey(JKubeAnnotations.SCM_TAG.value()));
    Assert.assertEquals("scm:git:git://github.com/jkubeio/kubernetes-maven-plugin.git", scmAnnotations.get(JKubeAnnotations.SCM_URL.value()));
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) JavaProject(org.eclipse.jkube.kit.common.JavaProject) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.Test)

Aggregations

JavaProject (org.eclipse.jkube.kit.common.JavaProject)52 Test (org.junit.Test)43 File (java.io.File)16 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)9 DeploymentBuilder (io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)9 Expectations (mockit.Expectations)9 HashMap (java.util.HashMap)7 Properties (java.util.Properties)6 Configuration (org.gradle.api.artifacts.Configuration)6 DeprecatableConfiguration (org.gradle.internal.deprecation.DeprecatableConfiguration)6 IOException (java.io.IOException)5 Collections (java.util.Collections)4 List (java.util.List)4 MavenProject (org.apache.maven.project.MavenProject)4 Plugin (org.eclipse.jkube.kit.common.Plugin)4 JKubeEnricherContext (org.eclipse.jkube.kit.enricher.api.JKubeEnricherContext)4 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 StringUtils (org.apache.commons.lang3.StringUtils)3