Search in sources :

Example 1 with Maintainer

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

the class HelmConfigTest method createHelmConfig.

@Test
public void createHelmConfig() throws IOException {
    // Given
    File file = File.createTempFile("test", ".tmp");
    file.deleteOnExit();
    HelmConfig helmConfig = new HelmConfig();
    helmConfig.setVersion("version");
    helmConfig.setSecurity("security");
    helmConfig.setChart("chart");
    helmConfig.setTypes(Collections.singletonList(HelmType.KUBERNETES));
    helmConfig.setType(HelmType.KUBERNETES.name());
    helmConfig.setAdditionalFiles(Collections.singletonList(file));
    helmConfig.setChartExtension("chartExtension");
    helmConfig.setOutputDir("outputDir");
    helmConfig.setSourceDir("sourceDir");
    helmConfig.setSnapshotRepository(new HelmRepository());
    helmConfig.setStableRepository(new HelmRepository());
    helmConfig.setTarballOutputDir("tarballOutputDir");
    helmConfig.setParameterTemplates(Collections.singletonList(new Template()));
    helmConfig.setDescription("description");
    helmConfig.setHome("home");
    helmConfig.setIcon("icon");
    helmConfig.setMaintainers(Collections.singletonList(new Maintainer()));
    helmConfig.setSources(Collections.singletonList("source"));
    helmConfig.setEngine("engine");
    helmConfig.setKeywords(Collections.singletonList("keyword"));
    helmConfig.setGeneratedChartListeners(Arrays.asList((helmConfig1, type, chartFile) -> {
    }));
    // Then
    assertThat(helmConfig.getVersion()).isEqualTo("version");
    assertThat(helmConfig.getSecurity()).isEqualTo("security");
    assertThat(helmConfig.getChart()).isEqualTo("chart");
    assertThat(helmConfig.getTypes().get(0)).isEqualTo(HelmType.KUBERNETES);
    assertThat(helmConfig.getAdditionalFiles().get(0)).exists();
    assertThat(helmConfig.getChartExtension()).isEqualTo("chartExtension");
    assertThat(helmConfig.getOutputDir()).isEqualTo("outputDir");
    assertThat(helmConfig.getSourceDir()).isEqualTo("sourceDir");
    assertThat(helmConfig.getSnapshotRepository()).isNotNull();
    assertThat(helmConfig.getStableRepository()).isNotNull();
    assertThat(helmConfig.getTarballOutputDir()).isEqualTo("tarballOutputDir");
    assertThat(helmConfig.getParameterTemplates()).isNotEmpty();
    assertThat(helmConfig.getDescription()).isEqualTo("description");
    assertThat(helmConfig.getHome()).isEqualTo("home");
    assertThat(helmConfig.getIcon()).isEqualTo("icon");
    assertThat(helmConfig.getMaintainers()).isNotEmpty();
    assertThat(helmConfig.getSources().get(0)).isEqualTo("source");
    assertThat(helmConfig.getEngine()).isEqualTo("engine");
    assertThat(helmConfig.getKeywords().get(0)).isEqualTo("keyword");
}
Also used : Maintainer(org.eclipse.jkube.kit.common.Maintainer) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HelmType(org.eclipse.jkube.kit.resource.helm.HelmConfig.HelmType) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) List(java.util.List) Template(io.fabric8.openshift.api.model.Template) After(org.junit.After) ParameterBuilder(io.fabric8.openshift.api.model.ParameterBuilder) Assert.fail(org.junit.Assert.fail) Collections(java.util.Collections) Maintainer(org.eclipse.jkube.kit.common.Maintainer) Before(org.junit.Before) File(java.io.File) Template(io.fabric8.openshift.api.model.Template) Test(org.junit.Test)

Example 2 with Maintainer

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

the class HelmServiceUtil method initHelmConfig.

public static HelmConfig.HelmConfigBuilder initHelmConfig(HelmConfig.HelmType defaultHelmType, JavaProject project, File manifest, File template, HelmConfig original) throws IOException {
    if (original == null) {
        original = new HelmConfig();
    }
    original.setChart(resolveFromPropertyOrDefault(PROPERTY_CHART, project, original::getChart, project.getArtifactId()));
    original.setChartExtension(resolveFromPropertyOrDefault(PROPERTY_CHART_EXTENSION, project, original::getChartExtension, DEFAULT_CHART_EXTENSION));
    original.setVersion(resolveFromPropertyOrDefault(PROPERTY_VERSION, project, original::getVersion, project.getVersion()));
    original.setDescription(resolveFromPropertyOrDefault(PROPERTY_DESCRIPTION, project, original::getDescription, project.getDescription()));
    original.setHome(resolveFromPropertyOrDefault(PROPERTY_HOME, project, original::getHome, project.getUrl()));
    if (original.getSources() == null) {
        original.setSources(project.getScmUrl() != null ? Collections.singletonList(project.getScmUrl()) : Collections.emptyList());
    }
    if (original.getMaintainers() == null && project.getMaintainers() != null) {
        original.setMaintainers(project.getMaintainers().stream().filter(m -> StringUtils.isNotBlank(m.getName()) || StringUtils.isNotBlank(m.getEmail())).map(m -> new Maintainer(m.getName(), m.getEmail())).collect(Collectors.toList()));
    }
    original.setIcon(resolveFromPropertyOrDefault(PROPERTY_ICON, project, original::getIcon, findIconURL(manifest)));
    original.setAdditionalFiles(getAdditionalFiles(original, project));
    if (original.getParameterTemplates() == null) {
        original.setParameterTemplates(findTemplates(template));
    }
    original.setTypes(resolveHelmTypes(defaultHelmType, project));
    original.setSourceDir(resolveFromPropertyOrDefault(PROPERTY_SOURCE_DIR, project, original::getSourceDir, String.format("%s/META-INF/jkube/", project.getOutputDirectory())));
    original.setOutputDir(resolveFromPropertyOrDefault(PROPERTY_OUTPUT_DIR, project, original::getOutputDir, String.format("%s/jkube/helm/%s", project.getBuildDirectory(), original.getChart())));
    original.setTarballOutputDir(resolveFromPropertyOrDefault(PROPERTY_TARBALL_OUTPUT_DIR, project, original::getTarballOutputDir, project.getBuildDirectory().getAbsolutePath()));
    return original.toBuilder();
}
Also used : ResourceUtil(org.eclipse.jkube.kit.common.util.ResourceUtil) FilenameFilter(java.io.FilenameFilter) JKubeProjectUtil.getProperty(org.eclipse.jkube.kit.common.util.JKubeProjectUtil.getProperty) UnaryOperator(java.util.function.UnaryOperator) StringUtils(org.apache.commons.lang3.StringUtils) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) RegistryServerConfiguration(org.eclipse.jkube.kit.common.RegistryServerConfiguration) Locale(java.util.Locale) JavaProject(org.eclipse.jkube.kit.common.JavaProject) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) KubernetesHelper(org.eclipse.jkube.kit.common.util.KubernetesHelper) IOException(java.io.IOException) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) File(java.io.File) Objects(java.util.Objects) KitLogger(org.eclipse.jkube.kit.common.KitLogger) Template(io.fabric8.openshift.api.model.Template) List(java.util.List) Stream(java.util.stream.Stream) KubernetesResource(io.fabric8.kubernetes.api.model.KubernetesResource) Optional(java.util.Optional) Collections(java.util.Collections) Maintainer(org.eclipse.jkube.kit.common.Maintainer) Maintainer(org.eclipse.jkube.kit.common.Maintainer)

Example 3 with Maintainer

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

the class HelmConfigTest method deserialize.

@Test
public void deserialize() throws Exception {
    // Given
    final String serializedChart = "{" + "\"version\":\"1337\"," + "\"security\":\"NYPD\"," + "\"chart\":\"pie\"," + "\"type\":\"kUberNetes\"," + "\"chartExtension\":\"tar\"," + "\"outputDir\":\"./output\"," + "\"sourceDir\":\"./src\"," + "\"snapshotRepository\":{}," + "\"stableRepository\":{}," + "\"tarballOutputDir\":\"./tar-output\"," + "\"parameterTemplates\":[{}]," + "\"parameters\": [{\"name\":\"key\"}]," + "\"description\":\"The description\"," + "\"home\":\"e.t.\"," + "\"icon\":\"Warhol\"," + "\"maintainers\":[{}]," + "\"sources\":[\"source\"]," + "\"engine\":\"V8\"," + "\"keywords\":[\"SEO\"]," + "\"dependencies\":[{" + "\"name\": \"ngnix\"," + "\"version\": \"1.2.3\"," + "\"repository\": \"https://example.com/charts\"" + "}]" + "}";
    // When
    final HelmConfig result = objectMapper.readValue(serializedChart, HelmConfig.class);
    // Then
    assertThat(result).hasFieldOrPropertyWithValue("version", "1337").hasFieldOrPropertyWithValue("security", "NYPD").hasFieldOrPropertyWithValue("chart", "pie").hasFieldOrPropertyWithValue("types", Collections.singletonList(HelmType.KUBERNETES)).hasFieldOrPropertyWithValue("chartExtension", "tar").hasFieldOrPropertyWithValue("outputDir", "./output").hasFieldOrPropertyWithValue("sourceDir", "./src").hasFieldOrPropertyWithValue("snapshotRepository", new HelmRepository()).hasFieldOrPropertyWithValue("stableRepository", new HelmRepository()).hasFieldOrPropertyWithValue("tarballOutputDir", "./tar-output").hasFieldOrPropertyWithValue("parameterTemplates", Collections.singletonList(new Template())).hasFieldOrPropertyWithValue("parameters", Collections.singletonList(new ParameterBuilder().withName("key").build())).hasFieldOrPropertyWithValue("description", "The description").hasFieldOrPropertyWithValue("home", "e.t.").hasFieldOrPropertyWithValue("icon", "Warhol").hasFieldOrPropertyWithValue("maintainers", Collections.singletonList(new Maintainer())).hasFieldOrPropertyWithValue("sources", Collections.singletonList("source")).hasFieldOrPropertyWithValue("engine", "V8").hasFieldOrPropertyWithValue("keywords", Collections.singletonList("SEO")).hasFieldOrPropertyWithValue("dependencies", Collections.singletonList(new HelmDependency().toBuilder().name("ngnix").version("1.2.3").repository("https://example.com/charts").build()));
}
Also used : Maintainer(org.eclipse.jkube.kit.common.Maintainer) ParameterBuilder(io.fabric8.openshift.api.model.ParameterBuilder) Template(io.fabric8.openshift.api.model.Template) Test(org.junit.Test)

Example 4 with Maintainer

use of org.eclipse.jkube.kit.common.Maintainer 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)

Aggregations

Maintainer (org.eclipse.jkube.kit.common.Maintainer)4 Template (io.fabric8.openshift.api.model.Template)3 File (java.io.File)3 IOException (java.io.IOException)3 Collections (java.util.Collections)3 List (java.util.List)3 ParameterBuilder (io.fabric8.openshift.api.model.ParameterBuilder)2 ArrayList (java.util.ArrayList)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang3.StringUtils)2 JavaProject (org.eclipse.jkube.kit.common.JavaProject)2 KitLogger (org.eclipse.jkube.kit.common.KitLogger)2 RegistryServerConfiguration (org.eclipse.jkube.kit.common.RegistryServerConfiguration)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Objects (com.google.common.base.Objects)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)1 KubernetesResource (io.fabric8.kubernetes.api.model.KubernetesResource)1 FileInputStream (java.io.FileInputStream)1