Skip to content

Commit

Permalink
Add outputArtifactDir to JavaProject
Browse files Browse the repository at this point in the history
Gradle's build directory doesn't contain jar files unlike maven.
Adding an additional field outputArtifactDir which will store parent
directory of artifact file.

JavaExecGenerator would make use of outputArtifactDir field in order to
look for fat jars and creating AssemblyFileSets

Related to #850

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
  • Loading branch information
rohanKanojia authored and manusa committed Sep 1, 2021
1 parent d7f58d6 commit 85f507e
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ public static JavaProject convertMavenProjectToJKubeProject(MavenProject mavenPr
.ifPresent(mavenBuild -> builder
.outputDirectory(new File(mavenBuild.getOutputDirectory()))
.buildFinalName(mavenBuild.getFinalName())
.buildDirectory(new File(mavenBuild.getDirectory())));
.buildDirectory(new File(mavenBuild.getDirectory()))
.buildPackageDirectory(new File(mavenBuild.getDirectory())));

if (mavenProject.getIssueManagement() != null) {
builder.issueManagementSystem(mavenProject.getIssueManagement().getSystem());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ public class JavaProject implements Serializable {
* @return The build directory for the project.
*/
private File buildDirectory;

/**
* Directory where build packages or artifacts (jar/war/ear) are output.
* This can be <code>target</code> in case of Maven and <code>build/libs</code> in case of Gradle.
*
* <p>
* This directory is used by generators and other build related tools to locate the
* files and packages to be included in the Container Image.
*
* <p>
* Please note that it's different from buildDirectory or outputDirectory which may point to directory
* used by build tool or generated classes.
*
* @param buildPackageDirectory directory where the project artifacts and packages are output
* @return the directory where the project artifacts and packages are output
*/
private File buildPackageDirectory;

/**
* Project configuration properties to be used in generators and enrichers
*
Expand Down Expand Up @@ -212,7 +230,7 @@ public class JavaProject implements Serializable {
@Builder
public JavaProject(
String name, String groupId, String artifactId, String version,
File outputDirectory, File baseDirectory, File buildDirectory,
File outputDirectory, File baseDirectory, File buildDirectory, File buildPackageDirectory,
Properties properties, @Singular List<String> compileClassPathElements, @Singular List<Dependency> dependencies,
List<Dependency> dependenciesWithTransitive, @Singular List<Plugin> plugins,
String site, String description, String organizationName, String documentationUrl,
Expand Down Expand Up @@ -243,6 +261,7 @@ public JavaProject(
this.issueManagementUrl = issueManagementUrl;
this.scmUrl = scmUrl;
this.scmTag = scmTag;
this.buildPackageDirectory = buildPackageDirectory;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public JavaExecGenerator(GeneratorContext context) {

protected JavaExecGenerator(GeneratorContext context, String name) {
super(context, name, new FromSelector.Default(context, "java"));
fatJarDetector = new FatJarDetector(getProject().getBuildDirectory());
fatJarDetector = new FatJarDetector(getProject().getBuildPackageDirectory());
mainClassDetector = new MainClassDetector(getConfig(Config.MAIN_CLASS),
getProject().getOutputDirectory(), context.getLogger());
}
Expand Down Expand Up @@ -200,7 +200,7 @@ protected List<AssemblyFileSet> addAdditionalFiles() {
}

private static AssemblyFileSet getOutputDirectoryFileSet(FatJarDetector.Result fatJar, JavaProject project) {
final File buildDirectory = project.getBuildDirectory();
final File buildDirectory = project.getBuildPackageDirectory();
return AssemblyFileSet.builder()
.directory(getRelativePath(project.getBaseDirectory(), buildDirectory))
.include(getRelativePath(buildDirectory, fatJar.getArchiveFile()).getPath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public void setUp() {
// @formatter:off
new Expectations() {{
project.getVersion(); result = "1.33.7-SNAPSHOT";
project.getBuildDirectory(); result = "/the/directory";
project.getOutputDirectory(); result = "/the/output/directory";
}};
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void createAssemblyWithFatJarShouldAddDefaultFileSetsAndFatJar(
// Given
// @formatter:off
new Expectations() {{
generatorContext.getProject().getBuildDirectory(); result = new File("");
generatorContext.getProject().getBuildPackageDirectory(); result = new File("");
generatorContext.getProject().getBaseDirectory(); result = new File("");
fjResult.getArchiveFile(); result = new File("fat.jar");
fatJarDetector.scan(); result = fjResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public void setUp() throws Exception {
project.getBaseDirectory(); result = "basedirectory"; minTimes = 0;

String tempDir = Files.createTempDirectory("openliberty-test-project").toFile().getAbsolutePath();
project.getBuildDirectory(); result = tempDir;
project.getOutputDirectory(); result = tempDir; minTimes = 0;
project.getVersion(); result = "1.0.0"; minTimes = 0;
}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void setUp() throws IOException {
new Expectations() {{
project.getVersion(); result = "0.0.1-SNAPSHOT"; minTimes = 0;
project.getBaseDirectory(); result = baseDir; minTimes = 0;
project.getBuildDirectory(); result = baseDir.getAbsolutePath();
project.getBuildDirectory(); result = baseDir.getAbsolutePath(); minTimes = 0;
project.getProperties(); result = projectProps;
project.getCompileClassPathElements(); result = Collections.emptyList(); minTimes = 0;
project.getOutputDirectory(); result = baseDir;
Expand Down Expand Up @@ -477,4 +477,4 @@ private void createFakeNativeImage (boolean fastJAR) throws IOException {
runnerExec.createNewFile();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ private GeneratorContext createGeneratorContext() throws IOException {
String tempDir = Files.createTempDirectory("springboot-test-project").toFile().getAbsolutePath();

// TODO: Prepare more relastic test setup
project.getBuildDirectory(); result = tempDir;
project.getOutputDirectory(); result = tempDir;
project.getPlugins(); result = Collections.EMPTY_LIST; minTimes = 0;
project.getVersion(); result = "1.0.0"; minTimes = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public void testDefaultOptions() {
// Given
// @formatter:off
new Expectations() {{
project.getBuildDirectory(); result = new File("target/tmp").getAbsolutePath();
project.getOutputDirectory(); result = new File("target/tmp/target").getAbsolutePath();
}};
// @formatter:on
Expand All @@ -128,8 +127,6 @@ public void testWithMetrics() {
// Given
// @formatter:off
new Expectations() {{
project.getBuildDirectory(); result = new File("target/tmp").getAbsolutePath();
project.getOutputDirectory(); result = new File("target/tmp/target").getAbsolutePath();
project.getDependencies(); result = Arrays.asList(dropwizard, core);
}};
// @formatter:on
Expand All @@ -148,7 +145,6 @@ public void testWithInfinispanClusterManager() {
// Given
// @formatter:off
new Expectations() {{
project.getBuildDirectory(); result = new File("target/tmp").getAbsolutePath();
project.getOutputDirectory(); result = new File("target/tmp/target").getAbsolutePath();
project.getDependencies(); result = Arrays.asList(infinispan, core);
}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ private GeneratorContext createGeneratorContext() throws IOException {
new Expectations() {{
context.getProject(); result = project;
String tempDir = Files.createTempDirectory("wildfly-jar-test-project").toFile().getAbsolutePath();
project.getBuildDirectory(); result = tempDir;
project.getOutputDirectory(); result = tempDir;
project.getPlugins(); result = Collections.EMPTY_LIST; minTimes = 0;
project.getVersion(); result = "1.0.0"; minTimes = 0;
Expand Down

0 comments on commit 85f507e

Please sign in to comment.