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