-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Watch works with complex assemblies using AssemblyFile
Signed-off-by: Marc Nuri <marc@marcnuri.com>
- Loading branch information
1 parent
7580138
commit 50332a7
Showing
8 changed files
with
157 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ | |
* to rebuild an image. | ||
* | ||
* @author roland | ||
* @since 15/06/15 | ||
*/ | ||
public class AssemblyFiles { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/archive/AssemblyFileUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.common.archive; | ||
|
||
import org.eclipse.jkube.kit.common.AssemblyConfiguration; | ||
import org.eclipse.jkube.kit.common.AssemblyFile; | ||
|
||
import java.io.File; | ||
import java.util.Objects; | ||
|
||
public class AssemblyFileUtils { | ||
|
||
private AssemblyFileUtils() {} | ||
|
||
public static File getAssemblyFileOutputDirectory( | ||
AssemblyFile assemblyFile, File outputDirectoryForRelativePaths, AssemblyConfiguration assemblyConfiguration) { | ||
final File outputDirectory; | ||
if (assemblyFile.getOutputDirectory().isAbsolute()) { | ||
outputDirectory = assemblyFile.getOutputDirectory(); | ||
} else { | ||
outputDirectory = outputDirectoryForRelativePaths.toPath() | ||
.resolve(Objects.requireNonNull(assemblyConfiguration.getName(), "Assembly Configuration name is required")) | ||
.resolve(assemblyFile.getOutputDirectory().toPath()) | ||
.toFile(); | ||
} | ||
return outputDirectory; | ||
} | ||
|
||
public static File resolveSourceFile(File baseDirectory, AssemblyFile assemblyFile) { | ||
return baseDirectory.toPath() | ||
.resolve(Objects.requireNonNull(assemblyFile.getSource(), "Assembly File source is required").toPath()) | ||
.toFile(); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...-kit/common/src/test/java/org/eclipse/jkube/kit/common/archive/AssemblyFileUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.common.archive; | ||
|
||
import org.eclipse.jkube.kit.common.AssemblyConfiguration; | ||
import org.eclipse.jkube.kit.common.AssemblyFile; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class AssemblyFileUtilsTest { | ||
|
||
@Rule | ||
public TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
||
@Test | ||
public void getAssemblyFileOutputDirectoryWithAbsoluteDirectoryShouldReturnSame() throws IOException { | ||
// Given | ||
final AssemblyFile af = AssemblyFile.builder().outputDirectory(new File("/")).build(); | ||
final File outputDirectoryForRelativePaths = temporaryFolder.newFolder("output"); | ||
final AssemblyConfiguration ac = AssemblyConfiguration.builder().build(); | ||
// When | ||
final File result = AssemblyFileUtils.getAssemblyFileOutputDirectory(af, outputDirectoryForRelativePaths, ac); | ||
// Then | ||
assertEquals("/", result.getAbsolutePath()); | ||
} | ||
|
||
@Test | ||
public void getAssemblyFileOutputDirectoryWithRelativeDirectoryShouldReturnComputedPath() throws IOException { | ||
// Given | ||
final AssemblyFile af = AssemblyFile.builder().outputDirectory(new File("target")).build(); | ||
final File outputDirectoryForRelativePaths = temporaryFolder.newFolder("output"); | ||
final AssemblyConfiguration ac = AssemblyConfiguration.builder().name("project").build(); | ||
// When | ||
final File result = AssemblyFileUtils.getAssemblyFileOutputDirectory(af, outputDirectoryForRelativePaths, ac); | ||
// Then | ||
final String expectedPath = outputDirectoryForRelativePaths.toPath().resolve("project").resolve("target") | ||
.toAbsolutePath().toString(); | ||
assertEquals(expectedPath, result.getAbsolutePath()); | ||
} | ||
|
||
@Test | ||
public void resolveSourceFileAbsoluteFileShouldReturnSame() throws IOException { | ||
// Given | ||
final File baseDirectory = temporaryFolder.newFolder("base"); | ||
final AssemblyFile af = AssemblyFile.builder().source(new File("/")).build(); | ||
// When | ||
final File result = AssemblyFileUtils.resolveSourceFile(baseDirectory, af); | ||
// Then | ||
assertEquals("/", result.getAbsolutePath()); | ||
} | ||
|
||
@Test | ||
public void resolveSourceFileRelativeSourceShouldReturnComputedPath() throws IOException { | ||
// Given | ||
final File baseDirectory = temporaryFolder.newFolder("base"); | ||
final AssemblyFile af = AssemblyFile.builder().source(new File("some-file.txt")).build(); | ||
// When | ||
final File result = AssemblyFileUtils.resolveSourceFile(baseDirectory, af); | ||
// Then | ||
final String expectedPath = baseDirectory.toPath().resolve("some-file.txt") | ||
.toAbsolutePath().toString(); | ||
assertEquals(expectedPath, result.getAbsolutePath()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters