Search in sources :

Example 46 with JavaProject

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

the class JKubeProjectUtilTest method getFinalOutputArtifact_withBuildFinalNamePackagingBuildDir_returnsInferredArtifact.

@Test
public void getFinalOutputArtifact_withBuildFinalNamePackagingBuildDir_returnsInferredArtifact() throws IOException {
    // Given
    File artifactFile = new File(temporaryFolder.getRoot(), "foo-test-final.jar");
    boolean artifactFileCreated = artifactFile.createNewFile();
    JavaProject javaProject = JavaProject.builder().buildFinalName("foo-test-final").packaging("jar").buildDirectory(temporaryFolder.getRoot()).build();
    // When
    File finalOutputArtifact = JKubeProjectUtil.getFinalOutputArtifact(javaProject);
    // Then
    assertThat(artifactFileCreated).isTrue();
    assertThat(finalOutputArtifact).hasName("foo-test-final.jar");
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) File(java.io.File) Test(org.junit.Test)

Example 47 with JavaProject

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

the class JKubeProjectUtilTest method getFinalOutputArtifact_withArtifactAndBuildFinalNameAndPackaging_returnsInferredArtifact.

@Test
public void getFinalOutputArtifact_withArtifactAndBuildFinalNameAndPackaging_returnsInferredArtifact() throws IOException {
    // Given
    File artifactFile = new File(temporaryFolder.getRoot(), "foo-test-1.0.0.jar");
    File buildFinalArtifactFile = new File(temporaryFolder.getRoot(), "foo-test-final.jar");
    boolean buildFinalArtifactFileCreated = buildFinalArtifactFile.createNewFile();
    boolean artifactFileCreated = artifactFile.createNewFile();
    JavaProject javaProject = JavaProject.builder().artifact(artifactFile).buildFinalName("foo-test-final").packaging("jar").buildDirectory(temporaryFolder.getRoot()).build();
    // When
    File finalOutputArtifact = JKubeProjectUtil.getFinalOutputArtifact(javaProject);
    // Then
    assertThat(artifactFileCreated).isTrue();
    assertThat(buildFinalArtifactFileCreated).isTrue();
    assertThat(finalOutputArtifact).hasName("foo-test-final.jar");
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) File(java.io.File) Test(org.junit.Test)

Example 48 with JavaProject

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

the class JKubeProjectUtilTest method resolveArtifact_whenNoArtifactPresent_shouldThrowException.

@Test
public void resolveArtifact_whenNoArtifactPresent_shouldThrowException() {
    // Given
    JavaProject javaProject = JavaProject.builder().build();
    // When
    IllegalStateException illegalStateException = Assert.assertThrows(IllegalStateException.class, () -> JKubeProjectUtil.resolveArtifact(javaProject, "org.example", "test-artifact", "0.0.1", "jar"));
    // Then
    assertThat(illegalStateException).hasMessage("Cannot find artifact test-artifact-0.0.1.jar within the resolved resources");
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) Test(org.junit.Test)

Example 49 with JavaProject

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

the class MavenUtil method convertMavenProjectToJKubeProject.

public static JavaProject convertMavenProjectToJKubeProject(MavenProject mavenProject, MavenSession mavenSession) throws DependencyResolutionRequiredException {
    JavaProject.JavaProjectBuilder builder = JavaProject.builder();
    Properties properties = new Properties();
    if (mavenProject.getProperties() != null) {
        properties.putAll(mavenProject.getProperties());
    }
    if (mavenSession != null) {
        if (mavenSession.getUserProperties() != null) {
            properties.putAll(mavenSession.getUserProperties());
        }
        if (mavenSession.getSystemProperties() != null) {
            properties.putAll(mavenSession.getSystemProperties());
        }
        if (mavenSession.getExecutionProperties() != null) {
            properties.putAll(mavenSession.getExecutionProperties());
        }
    }
    builder.name(mavenProject.getName()).description(mavenProject.getDescription()).groupId(mavenProject.getGroupId()).artifactId(mavenProject.getArtifactId()).version(mavenProject.getVersion()).baseDirectory(mavenProject.getBasedir()).documentationUrl(getDocumentationUrl(mavenProject)).compileClassPathElements(mavenProject.getCompileClasspathElements()).properties(properties).packaging(mavenProject.getPackaging()).dependencies(getDependencies(mavenProject)).dependenciesWithTransitive(getTransitiveDependencies(mavenProject)).plugins(getPlugins(mavenProject));
    if (mavenProject.getOrganization() != null) {
        builder.site(mavenProject.getOrganization().getUrl()).organizationName(mavenProject.getOrganization().getName());
    }
    Optional.ofNullable(mavenProject.getBuild()).ifPresent(mavenBuild -> builder.outputDirectory(new File(mavenBuild.getOutputDirectory())).buildFinalName(mavenBuild.getFinalName()).buildDirectory(new File(mavenBuild.getDirectory())).buildPackageDirectory(new File(mavenBuild.getDirectory())));
    if (mavenProject.getIssueManagement() != null) {
        builder.issueManagementSystem(mavenProject.getIssueManagement().getSystem());
        builder.issueManagementUrl(mavenProject.getIssueManagement().getUrl());
    }
    if (mavenProject.getScm() != null) {
        builder.scmTag(mavenProject.getScm().getTag());
        builder.scmUrl(mavenProject.getScm().getUrl());
    }
    if (mavenProject.getArtifact() != null) {
        builder.artifact(mavenProject.getArtifact().getFile());
    }
    if (mavenProject.getUrl() != null) {
        builder.url(mavenProject.getUrl());
    }
    if (mavenProject.getDevelopers() != null) {
        builder.maintainers(Optional.of(mavenProject).map(MavenProject::getDevelopers).orElse(Collections.emptyList()).stream().filter(developer -> StringUtils.isNotBlank(developer.getName()) || StringUtils.isNotBlank(developer.getEmail())).map(developer -> new Maintainer(developer.getName(), developer.getEmail())).collect(Collectors.toList()));
    }
    return builder.build();
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) Server(org.apache.maven.settings.Server) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Settings(org.apache.maven.settings.Settings) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) JarEntry(java.util.jar.JarEntry) MavenProject(org.apache.maven.project.MavenProject) RegistryServerConfiguration(org.eclipse.jkube.kit.common.RegistryServerConfiguration) JarInputStream(java.util.jar.JarInputStream) Artifact(org.apache.maven.artifact.Artifact) Objects(com.google.common.base.Objects) ZipArchiver(org.codehaus.plexus.archiver.zip.ZipArchiver) JavaProject(org.eclipse.jkube.kit.common.JavaProject) EnvUtil.greaterOrEqualsVersion(org.eclipse.jkube.kit.common.util.EnvUtil.greaterOrEqualsVersion) BuildPluginManager(org.apache.maven.plugin.BuildPluginManager) TarArchiver(org.codehaus.plexus.archiver.tar.TarArchiver) Properties(java.util.Properties) MavenSession(org.apache.maven.execution.MavenSession) Set(java.util.Set) TarLongFileMode(org.codehaus.plexus.archiver.tar.TarLongFileMode) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) Plugin(org.eclipse.jkube.kit.common.Plugin) KitLogger(org.eclipse.jkube.kit.common.KitLogger) List(java.util.List) Dependency(org.eclipse.jkube.kit.common.Dependency) DistributionManagement(org.apache.maven.model.DistributionManagement) Site(org.apache.maven.model.Site) Optional(java.util.Optional) Collections(java.util.Collections) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) InputStream(java.io.InputStream) Maintainer(org.eclipse.jkube.kit.common.Maintainer) Maintainer(org.eclipse.jkube.kit.common.Maintainer) JavaProject(org.eclipse.jkube.kit.common.JavaProject) MavenProject(org.apache.maven.project.MavenProject) Properties(java.util.Properties) File(java.io.File)

Example 50 with JavaProject

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

the class MavenUtilTest method testLoadedPomFromFile.

@Test
public void testLoadedPomFromFile() throws Exception {
    MavenProject mavenProject = loadMavenProjectFromPom();
    JavaProject project = MavenUtil.convertMavenProjectToJKubeProject(mavenProject, getMavenSession());
    assertEquals("Eclipse JKube Maven :: Sample :: Spring Boot Web", project.getName());
    assertEquals("Minimal Example with Spring Boot", project.getDescription());
    assertEquals("jkube-maven-sample-spring-boot", project.getArtifactId());
    assertEquals("org.eclipse.jkube", project.getGroupId());
    assertEquals("0.1.1-SNAPSHOT", project.getVersion());
    List<Plugin> plugins = MavenUtil.getPlugins(mavenProject);
    assertEquals(2, plugins.size());
    assertEquals("org.springframework.boot", plugins.get(0).getGroupId());
    assertEquals("spring-boot-maven-plugin", plugins.get(0).getArtifactId());
    assertEquals("org.eclipse.jkube", plugins.get(1).getGroupId());
    assertEquals("kubernetes-maven-plugin", plugins.get(1).getArtifactId());
    assertEquals("0.1.0", plugins.get(1).getVersion());
    assertEquals(3, plugins.get(1).getExecutions().size());
    assertEquals(Arrays.asList("resource", "build", "helm"), plugins.get(1).getExecutions());
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) MavenProject(org.apache.maven.project.MavenProject) Plugin(org.eclipse.jkube.kit.common.Plugin) 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