-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Created Karaf Quickstart - Fixed problems with FileSet assembly config to include complete directories - Upgraded images to use quay.io/jkube/jkube-karaf-binary-s2i Signed-off-by: Marc Nuri <[email protected]>
- Loading branch information
Showing
20 changed files
with
961 additions
and
162 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
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
48 changes: 48 additions & 0 deletions
48
...e-kit/common/src/main/java/org/eclipse/jkube/kit/common/archive/AssemblyFileSetUtils.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,48 @@ | ||
/** | ||
* 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.AssemblyFileSet; | ||
import org.eclipse.jkube.kit.common.util.FileUtil; | ||
|
||
import java.io.File; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class AssemblyFileSetUtils { | ||
|
||
private static final String DIRECTORY_CAN_LIST_PERMISSION = "040111"; | ||
|
||
private AssemblyFileSetUtils() {} | ||
|
||
public static Map<File, String> calculateFilePermissions(File destFile, AssemblyFileSet assemblyFileSet) { | ||
final Map<File, String> ret = new HashMap<>(); | ||
if (destFile.isDirectory()) { | ||
final String directoryMode = Optional.ofNullable(assemblyFileSet.getDirectoryMode()) | ||
.orElse(DIRECTORY_CAN_LIST_PERMISSION); | ||
ret.put(destFile, directoryMode); | ||
FileUtil.listFilesAndDirsRecursivelyInDirectory(destFile).forEach(f -> { | ||
if (f.isDirectory()) { | ||
ret.put(f, directoryMode); | ||
} else if(f.isFile() && assemblyFileSet.getFileMode() != null) { | ||
ret.put(f, assemblyFileSet.getFileMode()); | ||
} | ||
}); | ||
} else if (destFile.isFile() && assemblyFileSet.getFileMode() != null) { | ||
ret.put(destFile, assemblyFileSet.getFileMode()); | ||
} | ||
return ret; | ||
} | ||
} |
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
107 changes: 107 additions & 0 deletions
107
...t/common/src/test/java/org/eclipse/jkube/kit/common/archive/AssemblyFileSetUtilsTest.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,107 @@ | ||
/** | ||
* 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 java.io.File; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.eclipse.jkube.kit.common.AssemblyFileSet; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import static org.eclipse.jkube.kit.common.archive.AssemblyFileSetUtils.calculateFilePermissions; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.empty; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.hasEntry; | ||
import static org.hamcrest.Matchers.hasSize; | ||
|
||
public class AssemblyFileSetUtilsTest { | ||
|
||
@Rule | ||
public TemporaryFolder temp = new TemporaryFolder(); | ||
|
||
@Test | ||
public void calculateFilePermissionsFileWithNoFileMode() throws Exception { | ||
// Given | ||
final AssemblyFileSet afs = AssemblyFileSet.builder().build(); | ||
final File aFile = temp.newFile("just-a-file.txt"); | ||
// When | ||
final Map<File, String> result = calculateFilePermissions(aFile, afs); | ||
// Then | ||
assertThat(result.entrySet(), empty()); | ||
} | ||
|
||
@Test | ||
public void calculateFilePermissionsFileWithFileMode() throws Exception { | ||
// Given | ||
final AssemblyFileSet afs = AssemblyFileSet.builder().fileMode("0644").build(); | ||
final File aFile = temp.newFile("just-a-file.txt"); | ||
// When | ||
final Map<File, String> result = calculateFilePermissions(aFile, afs); | ||
// Then | ||
assertThat(result.entrySet(), hasSize(1)); | ||
assertThat(result, hasEntry(aFile, "0644")); | ||
} | ||
|
||
@Test | ||
public void calculateFilePermissionsDirectoryWithNoDirectoryMode() throws Exception { | ||
// Given | ||
final AssemblyFileSet afs = AssemblyFileSet.builder().build(); | ||
final File aDirectory = temp.newFolder("just-a-directory"); | ||
// When | ||
final Map<File, String> result = calculateFilePermissions(aDirectory, afs); | ||
// Then | ||
assertThat(result.entrySet(), hasSize(1)); | ||
assertThat(result, hasEntry(aDirectory, "040111")); | ||
} | ||
|
||
@Test | ||
public void calculateFilePermissionsDirectoryWithDirectoryMode() throws Exception { | ||
// Given | ||
final AssemblyFileSet afs = AssemblyFileSet.builder().directoryMode("040755").build(); | ||
final File aDirectory = temp.newFolder("just-a-directory"); | ||
final File aSubdirectory = new File(aDirectory, "subdirectory"); | ||
FileUtils.forceMkdir(aSubdirectory); | ||
final File aFile = new File(aDirectory, "file.txt"); | ||
assertThat(aFile.createNewFile(), equalTo(true)); | ||
// When | ||
final Map<File, String> result = calculateFilePermissions(aDirectory, afs); | ||
// Then | ||
assertThat(result.entrySet(), hasSize(2)); | ||
assertThat(result, hasEntry(aDirectory, "040755")); | ||
assertThat(result, hasEntry(aSubdirectory, "040755")); | ||
} | ||
|
||
@Test | ||
public void calculateFilePermissionsDirectoryWithDirectoryAndFileMode() throws Exception { | ||
// Given | ||
final AssemblyFileSet afs = AssemblyFileSet.builder().directoryMode("040755").fileMode("0644").build(); | ||
final File aDirectory = temp.newFolder("just-a-directory"); | ||
final File aSubdirectory = new File(aDirectory, "subdirectory"); | ||
FileUtils.forceMkdir(aSubdirectory); | ||
final File aFile = new File(aDirectory, "file.txt"); | ||
assertThat(aFile.createNewFile(), equalTo(true)); | ||
// When | ||
final Map<File, String> result = calculateFilePermissions(aDirectory, afs); | ||
// Then | ||
assertThat(result.entrySet(), hasSize(3)); | ||
assertThat(result, hasEntry(aDirectory, "040755")); | ||
assertThat(result, hasEntry(aSubdirectory, "040755")); | ||
assertThat(result, hasEntry(aFile, "0644")); | ||
} | ||
} |
Oops, something went wrong.