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");
}
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");
}
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");
}
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();
}
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());
}
Aggregations