diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c2cbe5492..b015881257 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ Usage: * Fix #210: WebAppGenerator\>JettyAppSeverHandler uses quay.io/jkube/jkube-jetty9-binary-s2i as base image * Fix #211: pom.xml configured runtime mode `` is considered instead of `` * Fix #209: WildFlySwarmGenerator includes required env variables + java options - +* Fix #285: fix: KarafGenerator update (Created Karaf Quickstart #188, fix FileSet problems, upgraded base images) ### 1.0.0-alpha-3 (2020-05-06) * Fix #167: Add CMD for wildfly based applications diff --git a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyConfigurationSource.java b/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyConfigurationSource.java index ab1f8a4de7..062aa6acf9 100644 --- a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyConfigurationSource.java +++ b/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyConfigurationSource.java @@ -18,7 +18,7 @@ import org.eclipse.jkube.kit.config.JKubeConfiguration; import org.eclipse.jkube.kit.common.JavaProject; -import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; /** * @author roland diff --git a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyManager.java b/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyManager.java index 302f1933fd..d81b404587 100644 --- a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyManager.java +++ b/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyManager.java @@ -21,25 +21,24 @@ import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Properties; -import org.eclipse.jkube.kit.config.JKubeConfiguration; import org.eclipse.jkube.kit.build.service.docker.helper.DockerFileUtil; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.eclipse.jkube.kit.common.AssemblyFile; import org.eclipse.jkube.kit.common.AssemblyFileSet; +import org.eclipse.jkube.kit.common.AssemblyMode; import org.eclipse.jkube.kit.common.JavaProject; import org.eclipse.jkube.kit.common.KitLogger; import org.eclipse.jkube.kit.common.archive.ArchiveCompression; import org.eclipse.jkube.kit.common.archive.JKubeTarArchiver; import org.eclipse.jkube.kit.common.util.FileUtil; import org.eclipse.jkube.kit.common.util.JKubeProjectUtil; -import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; -import org.eclipse.jkube.kit.config.image.build.AssemblyMode; +import org.eclipse.jkube.kit.config.JKubeConfiguration; import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; import org.eclipse.jkube.kit.config.image.build.DockerFileBuilder; @@ -47,13 +46,13 @@ import static org.eclipse.jkube.kit.build.core.assembly.JKubeAssemblyConfigurationUtils.getJKubeAssemblyFileSets; import static org.eclipse.jkube.kit.build.core.assembly.JKubeAssemblyConfigurationUtils.getJKubeAssemblyFileSetsExcludes; import static org.eclipse.jkube.kit.build.core.assembly.JKubeAssemblyConfigurationUtils.getJKubeAssemblyFiles; +import static org.eclipse.jkube.kit.common.archive.AssemblyFileSetUtils.processAssemblyFileSet; /** * Tool for creating a docker image tar ball including a Dockerfile for building * a docker image. * * @author roland - * @since 08.05.14 */ public class DockerAssemblyManager { @@ -404,7 +403,7 @@ private Map copyFilesToFinalTarballDirectory( final Map filesToPermissionsMap = new HashMap<>(); FileUtil.createDirectory(new File(buildDirs.getOutputDirectory(), assemblyConfiguration.getName())); for (AssemblyFileSet fileSet : getJKubeAssemblyFileSets(assemblyConfiguration)) { - filesToPermissionsMap.putAll(processJKubeProjectAssemblyFileSet(project, fileSet, buildDirs, assemblyConfiguration)); + filesToPermissionsMap.putAll(processAssemblyFileSet(project.getBaseDirectory(), buildDirs.getOutputDirectory(), fileSet, assemblyConfiguration)); } for (AssemblyFile file : getJKubeAssemblyFiles(assemblyConfiguration)) { processJKubeProjectAssemblyFile(project, file, buildDirs, assemblyConfiguration); @@ -412,48 +411,6 @@ private Map copyFilesToFinalTarballDirectory( return filesToPermissionsMap; } - private Map processJKubeProjectAssemblyFileSet(JavaProject project, - AssemblyFileSet jkubeProjectAssemblyFileSet, BuildDirs buildDirs, - AssemblyConfiguration jkubeProjectAssemblyConfiguration) throws IOException { - - final Map fileToPermissionsMap = new HashMap<>(); - - final List includes = Optional.ofNullable(jkubeProjectAssemblyFileSet.getIncludes()) - .orElse(Collections.singletonList("")); - for (String relativePathInclude : includes) { - final File sourceDirectory = project.getBaseDirectory().toPath() - .resolve(jkubeProjectAssemblyFileSet.getDirectory().toPath()) - .toFile(); - final File sourceFile = new File(sourceDirectory, FileUtil.trimWildcardCharactersFromPath(relativePathInclude)); - File destParentFile = new File(buildDirs.getOutputDirectory(), jkubeProjectAssemblyConfiguration.getName()); - if (jkubeProjectAssemblyFileSet.getOutputDirectory() != null - && !jkubeProjectAssemblyFileSet.getOutputDirectory().getName().equals(".")) { - destParentFile = buildDirs.getOutputDirectory().toPath() - .resolve(jkubeProjectAssemblyConfiguration.getName()) - .resolve(jkubeProjectAssemblyFileSet.getOutputDirectory().toPath()) - .toFile(); - } - FileUtil.createDirectory(destParentFile); - File destFile = new File(destParentFile, sourceFile.getName()); - - if (sourceFile.exists()) { - if (sourceFile.isDirectory()) { - FileUtil.copyDirectoryIfNotExists(sourceFile, destFile); - } else { - FileUtil.copy(sourceFile, destFile); - } - final String fileMode = jkubeProjectAssemblyFileSet.getFileMode(); - if (destFile.isFile()) { - fileToPermissionsMap.put(destFile, fileMode); - } else { - final int directoryCanListPermission = Integer.parseInt(fileMode, 8) + 0111; - fileToPermissionsMap.put(destFile, Integer.toOctalString(directoryCanListPermission)); - } - } - } - return fileToPermissionsMap; - } - private void processJKubeProjectAssemblyFile( JavaProject project, AssemblyFile assemblyFile, BuildDirs buildDirs, AssemblyConfiguration assemblyConfiguration) throws IOException { diff --git a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/core/assembly/JKubeAssemblyConfigurationUtils.java b/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/core/assembly/JKubeAssemblyConfigurationUtils.java index 3516bd1092..399bc5995e 100644 --- a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/core/assembly/JKubeAssemblyConfigurationUtils.java +++ b/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/core/assembly/JKubeAssemblyConfigurationUtils.java @@ -14,7 +14,7 @@ package org.eclipse.jkube.kit.build.core.assembly; import org.apache.commons.lang3.StringUtils; -import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; import org.eclipse.jkube.kit.common.AssemblyFile; import org.eclipse.jkube.kit.common.AssemblyFileSet; diff --git a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/BuildService.java b/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/BuildService.java index d8b462f53b..72847674ba 100644 --- a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/BuildService.java +++ b/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/BuildService.java @@ -36,7 +36,7 @@ import org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException; import org.eclipse.jkube.kit.common.KitLogger; import org.eclipse.jkube.kit.config.image.ImageName; -import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; import org.eclipse.jkube.kit.config.image.build.CleanupMode; diff --git a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/property/PropertyConfigHandler.java b/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/property/PropertyConfigHandler.java index 2d90cc3104..cd069bc05e 100644 --- a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/property/PropertyConfigHandler.java +++ b/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/property/PropertyConfigHandler.java @@ -28,7 +28,7 @@ import org.eclipse.jkube.kit.common.util.JKubeProjectUtil; import org.eclipse.jkube.kit.common.util.MapUtil; import org.eclipse.jkube.kit.config.image.build.Arguments; -import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; import org.eclipse.jkube.kit.config.image.build.HealthCheckConfiguration; diff --git a/jkube-kit/build/service/docker/src/test/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyConfigurationSourceTest.java b/jkube-kit/build/service/docker/src/test/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyConfigurationSourceTest.java index 72e014c17b..902cef3544 100644 --- a/jkube-kit/build/service/docker/src/test/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyConfigurationSourceTest.java +++ b/jkube-kit/build/service/docker/src/test/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyConfigurationSourceTest.java @@ -18,7 +18,7 @@ import org.eclipse.jkube.kit.config.JKubeConfiguration; import org.eclipse.jkube.kit.common.JavaProject; -import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.junit.Before; import org.junit.Rule; import org.junit.Test; diff --git a/jkube-kit/build/service/docker/src/test/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyManagerTest.java b/jkube-kit/build/service/docker/src/test/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyManagerTest.java index 6b721d5cb8..8bf372b64c 100644 --- a/jkube-kit/build/service/docker/src/test/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyManagerTest.java +++ b/jkube-kit/build/service/docker/src/test/java/org/eclipse/jkube/kit/build/core/assembly/DockerAssemblyManagerTest.java @@ -21,7 +21,7 @@ import java.util.Properties; import org.eclipse.jkube.kit.config.JKubeConfiguration; -import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; import org.eclipse.jkube.kit.common.JavaProject; import org.eclipse.jkube.kit.common.KitLogger; diff --git a/jkube-kit/build/service/docker/src/test/java/org/eclipse/jkube/kit/build/core/assembly/JKubeAssemblyConfigurationUtilsTest.java b/jkube-kit/build/service/docker/src/test/java/org/eclipse/jkube/kit/build/core/assembly/JKubeAssemblyConfigurationUtilsTest.java index 6739fb9a54..4b586b5888 100644 --- a/jkube-kit/build/service/docker/src/test/java/org/eclipse/jkube/kit/build/core/assembly/JKubeAssemblyConfigurationUtilsTest.java +++ b/jkube-kit/build/service/docker/src/test/java/org/eclipse/jkube/kit/build/core/assembly/JKubeAssemblyConfigurationUtilsTest.java @@ -21,7 +21,7 @@ import org.eclipse.jkube.kit.common.Assembly; import org.eclipse.jkube.kit.common.AssemblyFile; import org.eclipse.jkube.kit.common.AssemblyFileSet; -import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; import mockit.Expectations; diff --git a/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/build/AssemblyConfiguration.java b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/AssemblyConfiguration.java similarity index 97% rename from jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/build/AssemblyConfiguration.java rename to jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/AssemblyConfiguration.java index 4749256266..7c3f4428aa 100644 --- a/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/build/AssemblyConfiguration.java +++ b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/AssemblyConfiguration.java @@ -11,13 +11,11 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.jkube.kit.config.image.build; +package org.eclipse.jkube.kit.common; import java.io.Serializable; import java.util.Optional; -import org.eclipse.jkube.kit.common.Assembly; - import lombok.AllArgsConstructor; import lombok.Builder; import lombok.EqualsAndHashCode; diff --git a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/AssemblyFileSet.java b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/AssemblyFileSet.java index 968317c83a..2c6daa5ad6 100644 --- a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/AssemblyFileSet.java +++ b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/AssemblyFileSet.java @@ -23,7 +23,6 @@ import java.io.File; import java.io.Serializable; -import java.util.ArrayList; import java.util.List; @SuppressWarnings("JavaDoc") @@ -58,7 +57,7 @@ public class AssemblyFileSet implements Serializable { */ private boolean filtered; /** - * A set of files and directory to include. + * A set of files and directory to include. NO WILDCARDS SUPPORTED * *

If none is present, then everything is included * @@ -88,20 +87,17 @@ public class AssemblyFileSet implements Serializable { * @return The assembly fileSet file mode value. */ private String fileMode; - - public void addInclude(String item) { - if (includes == null) { - includes = new ArrayList<>(); - } - includes.add(item); - } - - public void addExclude(String item) { - if (excludes == null) { - excludes = new ArrayList<>(); - } - excludes.add(item); - } + /** + * Similar to a UNIX permission, sets the directory mode of the directories included. + * + *

Format: (User)(Group)(Other) where each component is a sum of Read = 4, Write = 2, and Execute = 1. + * + *

For example, the value 0755 translates to User read-write, Group and Other read-only. + * + * @param directoryMode New file mode value for the assembly fileSet. + * @return The assembly fileSet directory mode value. + */ + private String directoryMode; // Plexus deserialization specific setters /** diff --git a/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/build/AssemblyMode.java b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/AssemblyMode.java similarity index 94% rename from jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/build/AssemblyMode.java rename to jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/AssemblyMode.java index 504964416b..1fa53c96d0 100644 --- a/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/build/AssemblyMode.java +++ b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/AssemblyMode.java @@ -11,13 +11,12 @@ * Contributors: * Red Hat, Inc. - initial API and implementation */ -package org.eclipse.jkube.kit.config.image.build; +package org.eclipse.jkube.kit.common; /** * Various modes how to add file for the tarball for "docker:build". * * @author roland - * @since 18/05/15 */ public enum AssemblyMode { diff --git a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/archive/AssemblyFileSetUtils.java b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/archive/AssemblyFileSetUtils.java new file mode 100644 index 0000000000..2c101b951d --- /dev/null +++ b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/archive/AssemblyFileSetUtils.java @@ -0,0 +1,132 @@ +/** + * 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.apache.commons.lang3.StringUtils; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.AssemblyFileSet; +import org.eclipse.jkube.kit.common.util.FileUtil; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +public class AssemblyFileSetUtils { + + private static final String PATH_TO_SELF = "."; + private static final String DIRECTORY_CAN_LIST_PERMISSION = "040111"; + + private AssemblyFileSetUtils() {} + + public static Map calculateFilePermissions(File destFile, AssemblyFileSet assemblyFileSet) { + final Map 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; + } + + /** + * Will copy files from the provided baseDirectory into outputDirectory/assemblyConfiguration.name + * considering the inclusion and exclusion rules defined in the provided {@link AssemblyFileSet}. + * + *

NO WILDCARDS ARE SUPPORTED + * + * @param baseDirectory directory from where to source files. + * @param outputDirectory directory where files should be output. + * @param assemblyFileSet fileSet to process. + * @param assemblyConfiguration configuration for assembly. + * @return Map containing the calculated permissions. + * @throws IOException in case something goes wrong when performing File operations. + * + * @see Maven Assemblies (Spec partially compliant) + */ + public static Map processAssemblyFileSet( + File baseDirectory, File outputDirectory, AssemblyFileSet assemblyFileSet, + AssemblyConfiguration assemblyConfiguration) throws IOException { + + final Map fileToPermissionsMap = new HashMap<>(); + final File sourceDirectory = resolveSourceDirectory(baseDirectory, assemblyFileSet); + final File targetDirectory = outputDirectory.toPath() + .resolve(Objects.requireNonNull(assemblyConfiguration.getName(), "Assembly Configuration name is required")) + .toFile(); + final File destinationDirectory; + if (assemblyFileSet.getOutputDirectory() == null) { + destinationDirectory = new File(targetDirectory, sourceDirectory.getName()); + } else if (assemblyFileSet.getOutputDirectory().isAbsolute()) { + destinationDirectory = assemblyFileSet.getOutputDirectory(); + } else if (assemblyFileSet.getOutputDirectory().getPath().equals(PATH_TO_SELF)) { + destinationDirectory = targetDirectory; + } else { + destinationDirectory = targetDirectory.toPath().resolve(assemblyFileSet.getOutputDirectory().getPath()).toFile(); + } + final List includes = Optional.ofNullable(assemblyFileSet.getIncludes()) + .filter(i -> !i.isEmpty()) + .orElse(Collections.singletonList(PATH_TO_SELF)); + for (String include : includes) { + if (isSelfPath(include)) { + fileToPermissionsMap.putAll(copy(sourceDirectory, destinationDirectory, assemblyFileSet)); + } else { + final File sourceFile = new File(sourceDirectory, include); + final File destFile = destinationDirectory.toPath().resolve(sourceDirectory.toPath().relativize(sourceFile.toPath())).toFile(); + FileUtil.createDirectory(destFile.getParentFile()); + fileToPermissionsMap.putAll(copy(sourceFile, destFile, assemblyFileSet)); + } + } + return fileToPermissionsMap; + } + + + static File resolveSourceDirectory(File baseDirectory, AssemblyFileSet assemblyFileSet) { + if (Objects.requireNonNull(assemblyFileSet.getDirectory(), "Assembly FileSet directory is required").isAbsolute()) { + return assemblyFileSet.getDirectory(); + } else { + return baseDirectory.toPath() + .resolve(assemblyFileSet.getDirectory().toPath()) + .toFile(); + } + } + + private static boolean isSelfPath(String path) { + return StringUtils.isBlank(path) || path.equals(PATH_TO_SELF); + } + + private static Map copy(File source, File target, AssemblyFileSet assemblyFileSet) throws IOException { + if (source.exists()) { + if (source.isDirectory()) { + FileUtil.copyDirectoryIfNotExists(source, target); + } else { + FileUtil.copy(source, target); + } + return calculateFilePermissions(target, assemblyFileSet); + } + return Collections.emptyMap(); + } +} diff --git a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/FileUtil.java b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/FileUtil.java index 168bcec3df..b74677886d 100644 --- a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/FileUtil.java +++ b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/FileUtil.java @@ -43,7 +43,6 @@ /** * File related methods which cannot be found elsewhere * @author roland - * @since 23.05.17 */ public class FileUtil { @@ -314,6 +313,7 @@ public static void copyDirectoryIfNotExists(File sourceDir, File targetDir) thro try (Stream sourceTree = Files.walk(sourcePath)) { for (Path source : sourceTree.collect(Collectors.toList())){ Path target = targetDir.toPath().resolve(sourcePath.relativize(source)); + FileUtils.forceMkdir(target.toFile()); Files.copy(source, target, REPLACE_EXISTING); } } diff --git a/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/archive/AssemblyFileSetUtilsProcessAssemblyFileSetTest.java b/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/archive/AssemblyFileSetUtilsProcessAssemblyFileSetTest.java new file mode 100644 index 0000000000..1bdb08bc41 --- /dev/null +++ b/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/archive/AssemblyFileSetUtilsProcessAssemblyFileSetTest.java @@ -0,0 +1,344 @@ +/** + * 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.io.IOException; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.eclipse.jkube.kit.common.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.AssemblyFileSet; + +import org.apache.commons.io.FileUtils; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import static org.eclipse.jkube.kit.common.archive.AssemblyFileSetUtils.resolveSourceDirectory; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.arrayContainingInAnyOrder; +import static org.hamcrest.Matchers.arrayWithSize; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.emptyArray; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.startsWith; + +public class AssemblyFileSetUtilsProcessAssemblyFileSetTest { + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + private File baseDirectory; + private File sourceDirectory; + private File outputDirectory; + + @Before + public void setUp() throws Exception { + baseDirectory = temp.newFolder("base"); + sourceDirectory = new File(baseDirectory, "source-directory"); + final List sourceSubdirectories = Stream.of("one", "two", "three") + .map(s -> new File(sourceDirectory, s)).collect(Collectors.toList()); + for (File directory : Stream.concat(Stream.of(baseDirectory, sourceDirectory), sourceSubdirectories.stream()).collect(Collectors.toList())) { + FileUtils.forceMkdir(directory); + populateSampleFiles(directory); + } + outputDirectory = temp.newFolder("output"); + } + + @After + public void tearDown() { + outputDirectory = null; + sourceDirectory = null; + baseDirectory = null; + } + + private static void populateSampleFiles(File baseDirectory) throws IOException { + for (String fileName : new String[]{"1.txt", "3.other", "37"}) { + assertThat(new File(baseDirectory, fileName).createNewFile(), equalTo(true)); + } + } + + @Test + public void resolveSourceDirectoryIsAbsoluteShouldReturnAbsolute() throws Exception { + // Given + final File directory = temp.newFolder("absolute-path-out-of-base"); + final AssemblyFileSet afs = AssemblyFileSet.builder().directory(directory).build(); + // When + final File result = resolveSourceDirectory(baseDirectory, afs); + // Then + assertThat(result, equalTo(directory)); + final Path relativeToBase = baseDirectory.toPath().relativize(result.toPath()); + assertThat(relativeToBase.toString(), startsWith("..")); + } + + @Test + public void resolveSourceDirectoryIsRelativeShouldReturnRelative() { + // Given + final File relativeDirectory = new File("source-directory"); + final AssemblyFileSet afs = AssemblyFileSet.builder().directory(relativeDirectory).build(); + // When + final File result = resolveSourceDirectory(baseDirectory, afs); + // Then + assertThat(result, equalTo(new File(baseDirectory, "source-directory"))); + final Path relativeToBase = baseDirectory.toPath().relativize(result.toPath()); + assertThat(relativeToBase.toString(), equalTo("source-directory")); + } + + @Test + public void assemblyFileSetHasNoDirectoryShouldThrowException() { + // Given + final AssemblyFileSet afs = AssemblyFileSet.builder().build(); + final AssemblyConfiguration ac = AssemblyConfiguration.builder() + .name("deployments") + .build(); + // When + final Exception result = Assert.assertThrows(NullPointerException.class, () -> + AssemblyFileSetUtils.processAssemblyFileSet(baseDirectory, outputDirectory, afs, ac) + ); + // Then + assertThat(result.getMessage(), equalTo("Assembly FileSet directory is required")); + } + + @Test + public void assemblyConfigurationHasNoNameShouldThrowException() { + // Given + final AssemblyFileSet afs = AssemblyFileSet.builder() + .directory(sourceDirectory) + .build(); + final AssemblyConfiguration ac = AssemblyConfiguration.builder().build(); + // When + final Exception result = Assert.assertThrows(NullPointerException.class, () -> + AssemblyFileSetUtils.processAssemblyFileSet(baseDirectory, outputDirectory, afs, ac) + ); + // Then + assertThat(result.getMessage(), equalTo("Assembly Configuration name is required")); + } + + /** + * Has AssemblyFileSet#directory and AssemblyConfiguration#name options. + * + * Should copy the AssemblyFileSet#directory to the outputDirectory in a subdirectory named as the AssemblyConfiguration#name. + * + * n.b. this is the only case where the source directory and not its contents is copied. + */ + @Test + public void minimumRequiredFields() throws Exception { + // Given + final AssemblyFileSet afs = AssemblyFileSet.builder() + .directory(sourceDirectory) + .build(); + final AssemblyConfiguration ac = AssemblyConfiguration.builder() + .name("deployments") + .build(); + // When + final Map permissions = AssemblyFileSetUtils.processAssemblyFileSet(baseDirectory, outputDirectory, afs, ac); + // Then + assertThat(permissions.entrySet(), hasSize(4)); + final File deployments = new File(outputDirectory, "deployments"); + assertThat(deployments.exists(), equalTo(true)); + assertThat(deployments.listFiles(), arrayWithSize(1)); + final File outputSourceDir = Objects.requireNonNull(deployments.listFiles())[0]; + assertThat(outputSourceDir.getName(), equalTo("source-directory")); + assertThat(outputSourceDir.exists(), equalTo(true)); + assertThat(outputSourceDir.listFiles(), arrayWithSize(6)); + assertThat(outputSourceDir.list(), arrayContainingInAnyOrder("one", "two", "three", "1.txt", "3.other", "37")); + } + + /** + * Has AssemblyFileSet#directory and AssemblyConfiguration#name options. + * + * Source directory doesn't exist + * + * Should do nothing. + */ + @Test + public void sourceDoesNotExist() throws Exception { + // Given + final AssemblyFileSet afs = AssemblyFileSet.builder() + .directory(new File(sourceDirectory, "non-existent")) + .build(); + final AssemblyConfiguration ac = AssemblyConfiguration.builder() + .name("deployments") + .build(); + // When + final Map permissions = AssemblyFileSetUtils.processAssemblyFileSet(baseDirectory, outputDirectory, afs, ac); + // Then + assertThat(permissions.entrySet(), empty()); + final File deployments = new File(outputDirectory, "deployments"); + assertThat(deployments.exists(), equalTo(false)); + } + + /** + * Has AssemblyFileSet with directory and outputDirectory relative path resolving to self. + * Has AssemblyConfiguration name. + * + * Should copy contents of AssemblyFileSet#directory to the outputDirectory in a subdirectory named as the AssemblyConfiguration#name. + */ + @Test + public void fileSetDirectoryAndOutputDirectoryResolvingToSelf() throws Exception { + // Given + final AssemblyFileSet afs = AssemblyFileSet.builder() + .directory(sourceDirectory) + .outputDirectory(new File(".")) + .build(); + final AssemblyConfiguration ac = AssemblyConfiguration.builder() + .name("deployments") + .build(); + // When + final Map permissions = AssemblyFileSetUtils.processAssemblyFileSet(baseDirectory, outputDirectory, afs, ac); + // Then + assertThat(permissions.entrySet(), hasSize(4)); + final File deployments = new File(outputDirectory, "deployments"); + assertThat(deployments.exists(), equalTo(true)); + assertThat(deployments.listFiles(), arrayWithSize(6)); + assertThat(deployments.list(), arrayContainingInAnyOrder("one", "two", "three", "1.txt", "3.other", "37")); + assertThat(new File(deployments, "source-directory").exists(), equalTo(false)); + } + + /** + * Has AssemblyFileSet directory and absolute outputDirectory. + * Has AssemblyConfiguration name. + * + * Should copy contents of AssemblyFileSet#directory to the absoluteOutputDirectory. + */ + @Test + public void fileSetDirectoryAndAbsoluteOutputDirectory() throws Exception { + // Given + final File absoluteOutputDirectory = temp.newFolder("absolute-output"); + assertThat(absoluteOutputDirectory.listFiles(), emptyArray()); + final AssemblyFileSet afs = AssemblyFileSet.builder() + .directory(sourceDirectory) + .outputDirectory(absoluteOutputDirectory) + .build(); + final AssemblyConfiguration ac = AssemblyConfiguration.builder() + .name("deployments") + .build(); + // When + final Map permissions = AssemblyFileSetUtils.processAssemblyFileSet(baseDirectory, outputDirectory, afs, ac); + // Then + assertThat(permissions.entrySet(), hasSize(4)); + assertThat(new File(outputDirectory, "deployments").exists(), equalTo(false)); + assertThat(absoluteOutputDirectory.listFiles(), arrayWithSize(6)); + assertThat(absoluteOutputDirectory.list(), arrayContainingInAnyOrder("one", "two", "three", "1.txt", "3.other", "37")); + } + + /** + * No options provided except of the AssemblyFileSet#directory, relative outputDirectory and AssemblyConfiguration#name. + * + * Should copy contents of AssemblyFileSet#directory to the outputDirectory in a relative subdirectory with path + * composed of AssemblyConfiguration#name and the relative outputDirectory. + */ + @Test + public void fileSetDirectoryAndRelativeOutputDirectory() throws Exception { + // Given + final File relativeOutputDirectory = new File("relative-output"); + final AssemblyFileSet afs = AssemblyFileSet.builder() + .directory(sourceDirectory) + .outputDirectory(relativeOutputDirectory) + .build(); + final AssemblyConfiguration ac = AssemblyConfiguration.builder() + .name("deployments") + .build(); + // When + final Map permissions = AssemblyFileSetUtils.processAssemblyFileSet(baseDirectory, outputDirectory, afs, ac); + // Then + assertThat(permissions.entrySet(), hasSize(4)); + final File deployments = new File(outputDirectory, "deployments"); + assertThat(deployments.exists(), equalTo(true)); + assertThat(deployments.listFiles(), arrayWithSize(1)); + final File resultingDirectory = outputDirectory.toPath().resolve("deployments").resolve("relative-output").toFile(); + assertThat(Objects.requireNonNull(deployments.listFiles())[0], equalTo(resultingDirectory)); + assertThat(resultingDirectory.exists(), equalTo(true)); + assertThat(resultingDirectory.listFiles(), arrayWithSize(6)); + assertThat(resultingDirectory.list(), arrayContainingInAnyOrder("one", "two", "three", "1.txt", "3.other", "37")); + } + + /** + * Has AssemblyFileSet#directory and includes for files in several hierarchic levels. + * Has AssemblyConfiguration name. + * + * Should copy contents of AssemblyFileSet#directory to the outputDirectory in a subdirectory named as the AssemblyConfiguration#name. + */ + @Test + public void hierarchicalInclude() throws Exception { + // Given + final AssemblyFileSet afs = AssemblyFileSet.builder() + .directory(sourceDirectory) + .include("1.txt") + .include("one/1.txt") + .include("two") + .build(); + final AssemblyConfiguration ac = AssemblyConfiguration.builder() + .name("deployments") + .build(); + // When + final Map permissions = AssemblyFileSetUtils.processAssemblyFileSet(baseDirectory, outputDirectory, afs, ac); + // Then + assertThat(permissions.entrySet(), hasSize(1)); + final File deployments = new File(outputDirectory, "deployments"); + assertThat(deployments.exists(), equalTo(true)); + assertThat(deployments.listFiles(), arrayWithSize(1)); + final File outputSourceDir = Objects.requireNonNull(deployments.listFiles())[0]; + assertThat(outputSourceDir.getName(), equalTo("source-directory")); + assertThat(outputSourceDir.exists(), equalTo(true)); + assertThat(outputSourceDir.listFiles(), arrayWithSize(3)); + assertThat(outputSourceDir.list(), arrayContainingInAnyOrder("one", "two", "1.txt")); + assertThat(new File(outputSourceDir, "one").listFiles(), arrayWithSize(1)); + assertThat(new File(outputSourceDir, "two").listFiles(), arrayWithSize(3)); + } + + /** + * AssemblyFileSet#directory, relative outputDirectory and includes for files in several hierarchic levels. + * Has AssemblyConfiguration name. + * + * Should copy contents of AssemblyFileSet#directory to the outputDirectory in a subdirectory named as the AssemblyConfiguration#name. + */ + @Test + public void hierarchicalIncludeInRelativeDirectory() throws Exception { + // Given + final AssemblyFileSet afs = AssemblyFileSet.builder() + .directory(sourceDirectory) + .outputDirectory(new File("relative")) + .include("37") + .include("one/1.txt") + .include("three") + .build(); + final AssemblyConfiguration ac = AssemblyConfiguration.builder() + .name("maven") + .build(); + // When + final Map permissions = AssemblyFileSetUtils.processAssemblyFileSet(baseDirectory, outputDirectory, afs, ac); + // Then + assertThat(permissions.entrySet(), hasSize(1)); + final File maven = new File(outputDirectory, "maven"); + assertThat(maven.exists(), equalTo(true)); + assertThat(maven.listFiles(), arrayWithSize(1)); + final File outputSourceDir = Objects.requireNonNull(maven.listFiles())[0]; + assertThat(outputSourceDir.getName(), equalTo("relative")); + assertThat(outputSourceDir.exists(), equalTo(true)); + assertThat(outputSourceDir.listFiles(), arrayWithSize(3)); + assertThat(outputSourceDir.list(), arrayContainingInAnyOrder("one", "three", "37")); + assertThat(new File(outputSourceDir, "one").listFiles(), arrayWithSize(1)); + assertThat(new File(outputSourceDir, "three").listFiles(), arrayWithSize(3)); + } +} \ No newline at end of file diff --git a/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/archive/AssemblyFileSetUtilsTest.java b/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/archive/AssemblyFileSetUtilsTest.java new file mode 100644 index 0000000000..490e8e8e37 --- /dev/null +++ b/jkube-kit/common/src/test/java/org/eclipse/jkube/kit/common/archive/AssemblyFileSetUtilsTest.java @@ -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 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 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 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 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 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")); + } +} \ No newline at end of file diff --git a/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/build/BuildConfiguration.java b/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/build/BuildConfiguration.java index b21baa7b50..fea58bb759 100644 --- a/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/build/BuildConfiguration.java +++ b/jkube-kit/config/image/src/main/java/org/eclipse/jkube/kit/config/image/build/BuildConfiguration.java @@ -30,6 +30,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Singular; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.eclipse.jkube.kit.common.KitLogger; import org.eclipse.jkube.kit.common.archive.ArchiveCompression; import org.eclipse.jkube.kit.common.util.EnvUtil; diff --git a/jkube-kit/config/image/src/test/java/org/eclipse/jkube/kit/config/image/build/BuildConfigurationTest.java b/jkube-kit/config/image/src/test/java/org/eclipse/jkube/kit/config/image/build/BuildConfigurationTest.java index 2d45c23849..798747886f 100644 --- a/jkube-kit/config/image/src/test/java/org/eclipse/jkube/kit/config/image/build/BuildConfigurationTest.java +++ b/jkube-kit/config/image/src/test/java/org/eclipse/jkube/kit/config/image/build/BuildConfigurationTest.java @@ -16,6 +16,7 @@ import java.io.File; import mockit.Expectations; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.eclipse.jkube.kit.common.KitLogger; import mockit.Mocked; import org.junit.Test; diff --git a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildService.java b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildService.java index 3348c02bd9..44195bc899 100644 --- a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildService.java +++ b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildService.java @@ -55,7 +55,7 @@ import org.eclipse.jkube.kit.common.util.KubernetesHelper; import org.eclipse.jkube.kit.common.util.OpenshiftHelper; import org.eclipse.jkube.kit.config.image.ImageName; -import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; import org.eclipse.jkube.kit.config.image.build.OpenShiftBuildStrategy; import org.eclipse.jkube.kit.config.service.BuildService; diff --git a/jkube-kit/generator/java-exec/src/main/java/org/eclipse/jkube/generator/javaexec/JavaExecGenerator.java b/jkube-kit/generator/java-exec/src/main/java/org/eclipse/jkube/generator/javaexec/JavaExecGenerator.java index 63f0564b94..8b6222eafd 100644 --- a/jkube-kit/generator/java-exec/src/main/java/org/eclipse/jkube/generator/javaexec/JavaExecGenerator.java +++ b/jkube-kit/generator/java-exec/src/main/java/org/eclipse/jkube/generator/javaexec/JavaExecGenerator.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Map; -import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; import org.eclipse.jkube.kit.build.service.docker.ImageConfiguration; import org.eclipse.jkube.kit.common.Configs; @@ -178,7 +178,7 @@ protected void addAssembly(AssemblyConfiguration.AssemblyConfigurationBuilder bu if (assemblyRef != null) { builder.descriptorRef(assemblyRef); } else { - final List fileSets = new ArrayList<>(addAdditionalFiles(getProject())); + final List fileSets = new ArrayList<>(addAdditionalFiles()); if (isFatJar()) { FatJarDetector.Result fatJar = detectFatJar(); if (fatJar != null) { @@ -191,10 +191,10 @@ protected void addAssembly(AssemblyConfiguration.AssemblyConfigurationBuilder bu } } - public List addAdditionalFiles(JavaProject project) { + public List addAdditionalFiles() { List fileSets = new ArrayList<>(); - fileSets.add(createFileSet(project, "src/main/jkube-includes/bin","bin", "0755")); - fileSets.add(createFileSet(project, "src/main/jkube-includes",".", "0644")); + fileSets.add(createFileSet("src/main/jkube-includes/bin","bin", "0755")); + fileSets.add(createFileSet("src/main/jkube-includes",".", "0644")); return fileSets; } @@ -202,16 +202,15 @@ public AssemblyFileSet getOutputDirectoryFileSet(FatJarDetector.Result fatJar, J final File buildDirectory = project.getBuildDirectory(); return AssemblyFileSet.builder() .directory(getRelativePath(project.getBaseDirectory(), buildDirectory)) - .includes(Collections.singletonList(getRelativePath(buildDirectory, fatJar.getArchiveFile()).getPath())) + .include(getRelativePath(buildDirectory, fatJar.getArchiveFile()).getPath()) .outputDirectory(new File(".")) .fileMode("0640") .build(); } - public AssemblyFileSet createFileSet(JavaProject project, String sourceDir, String outputDir, String fileMode) { + public AssemblyFileSet createFileSet(String sourceDir, String outputDir, String fileMode) { return AssemblyFileSet.builder() - .directory(project.getBaseDirectory()) - .includes(Collections.singletonList(sourceDir)) + .directory(new File(sourceDir)) .outputDirectory(new File(outputDir)) .fileMode(fileMode) .build(); diff --git a/jkube-kit/generator/karaf/src/main/java/org/eclipse/jkube/generator/karaf/KarafGenerator.java b/jkube-kit/generator/karaf/src/main/java/org/eclipse/jkube/generator/karaf/KarafGenerator.java index 6e9d0374cf..cb004246a3 100644 --- a/jkube-kit/generator/karaf/src/main/java/org/eclipse/jkube/generator/karaf/KarafGenerator.java +++ b/jkube-kit/generator/karaf/src/main/java/org/eclipse/jkube/generator/karaf/KarafGenerator.java @@ -13,84 +13,98 @@ */ package org.eclipse.jkube.generator.karaf; -import java.util.ArrayList; +import java.io.File; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; -import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; -import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; -import org.eclipse.jkube.kit.build.service.docker.ImageConfiguration; -import org.eclipse.jkube.kit.common.Configs; -import org.eclipse.jkube.kit.common.util.JKubeProjectUtil; -import org.eclipse.jkube.kit.config.image.build.Arguments; import org.eclipse.jkube.generator.api.FromSelector; import org.eclipse.jkube.generator.api.GeneratorContext; import org.eclipse.jkube.generator.api.support.BaseGenerator; +import org.eclipse.jkube.kit.build.service.docker.ImageConfiguration; +import org.eclipse.jkube.kit.common.Assembly; +import org.eclipse.jkube.kit.common.AssemblyFileSet; +import org.eclipse.jkube.kit.common.Configs; +import org.eclipse.jkube.kit.common.util.JKubeProjectUtil; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; +import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; + import org.apache.commons.lang3.StringUtils; public class KarafGenerator extends BaseGenerator { - private static final String KARAF = "karaf"; - private static final String KARAF_MAVEN_PLUGIN_ARTIFACT_ID = "karaf-maven-plugin"; + private static final String KARAF = "karaf"; + private static final String KARAF_MAVEN_PLUGIN_ARTIFACT_ID = "karaf-maven-plugin"; - public KarafGenerator(GeneratorContext context) { - super(context, KARAF, new FromSelector.Default(context,KARAF)); - } + public KarafGenerator(GeneratorContext context) { + super(context, KARAF, new FromSelector.Default(context,KARAF)); + } - private enum Config implements Configs.Key { - baseDir {{ d = "/deployments/"; }}, - user {{ d = "jboss:jboss:jboss"; }}, - cmd {{ d = "/deployments/deploy-and-run.sh"; }}, - webPort {{ d = "8181"; }}, - jolokiaPort {{ d = "8778"; }}; + private enum Config implements Configs.Key { + baseDir {{ d = "/deployments"; }}, + webPort {{ d = "8181"; }}; - public String def() { return d; } protected String d; - } + public String def() { return d; } protected String d; + } - @Override - public List customize(List configs, boolean prePackagePhase) { - final ImageConfiguration.ImageConfigurationBuilder imageBuilder = ImageConfiguration.builder(); - final BuildConfiguration.BuildConfigurationBuilder buildBuilder = BuildConfiguration.builder(); + @Override + public boolean isApplicable(List configs) { + return shouldAddImageConfiguration(configs) && + JKubeProjectUtil.hasPluginOfAnyArtifactId(getProject(), KARAF_MAVEN_PLUGIN_ARTIFACT_ID); + } - buildBuilder.ports(extractPorts()).cmd(Arguments.builder().shell(getConfig(Config.cmd)).build()); + @Override + public List customize(List configs, boolean prePackagePhase) { + final ImageConfiguration.ImageConfigurationBuilder imageBuilder = ImageConfiguration.builder(); + final BuildConfiguration.BuildConfigurationBuilder buildBuilder = BuildConfiguration.builder(); - addSchemaLabels(buildBuilder, log); - addFrom(buildBuilder); - if (!prePackagePhase) { - buildBuilder.assembly(createAssembly()); - } - addLatestTagIfSnapshot(buildBuilder); - imageBuilder - .name(getImageName()) - .alias(getAlias()) - .build(buildBuilder.build()); - configs.add(imageBuilder.build()); - return configs; - } + buildBuilder.ports(extractPorts()); + buildBuilder + .putEnv("DEPLOYMENTS_DIR", getConfig(Config.baseDir)) + .putEnv("KARAF_HOME", "/deployments/karaf"); - @Override - public boolean isApplicable(List configs) { - return shouldAddImageConfiguration(configs) && - JKubeProjectUtil.hasPluginOfAnyArtifactId(getProject(), KARAF_MAVEN_PLUGIN_ARTIFACT_ID); + addSchemaLabels(buildBuilder, log); + addFrom(buildBuilder); + if (!prePackagePhase) { + buildBuilder.assembly(createDefaultAssembly()); } + addLatestTagIfSnapshot(buildBuilder); + imageBuilder + .name(getImageName()) + .alias(getAlias()) + .build(buildBuilder.build()); + configs.add(imageBuilder.build()); + return configs; + } - protected List extractPorts() { - List answer = new ArrayList<>(); - addPortIfValid(answer, getConfig(Config.webPort)); - addPortIfValid(answer, getConfig(Config.jolokiaPort)); - return answer; - } - private void addPortIfValid(List list, String port) { - if (StringUtils.isNotBlank(port)) { - list.add(port); - } - } + protected List extractPorts() { + return Stream.of(getConfig(Config.webPort)) + .filter(StringUtils::isNotBlank) + .collect(Collectors.toList()); + } - private AssemblyConfiguration createAssembly() { - return AssemblyConfiguration.builder() - .targetDir(getConfig(Config.baseDir)) - .user(getConfig(Config.user)) - .descriptorRef(KARAF) - .build(); - } + private AssemblyConfiguration createDefaultAssembly() { + return AssemblyConfiguration.builder() + .targetDir(getConfig(Config.baseDir)) + .descriptorRef(KARAF) + .name("deployments") + .inline(Assembly.builder() + .fileSet(AssemblyFileSet.builder() + .directory(new File(getProject().getBuildDirectory(), "assembly")) + .outputDirectory(new File(KARAF)) + .exclude("bin/**") + .directoryMode("0775") + .build()) + .fileSet(AssemblyFileSet.builder() + .directory(getProject().getBuildDirectory().toPath().resolve("assembly").resolve("bin").toFile()) + .outputDirectory(new File(KARAF, "bin")) + .exclude("contrib/**") + .exclude("*.bat") + .directoryMode("0775") + .fileMode("0777") + .build()) + .build()) + .build(); + } } diff --git a/jkube-kit/generator/karaf/src/main/resources/assemblies/karaf.xml b/jkube-kit/generator/karaf/src/main/resources/assemblies/karaf.xml deleted file mode 100644 index 6d2e4505ee..0000000000 --- a/jkube-kit/generator/karaf/src/main/resources/assemblies/karaf.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - karaf - - - - ${project.build.directory}/assembly/ - ${project.artifactId}-${project.version} - - bin/** - - false - 0775 - - - - ${project.build.directory}/assembly/bin - ${project.artifactId}-${project.version}/bin - false - 0775 - 0755 - - *.bat - contrib/** - - - - - ${project.build.directory}/assembly/bin - ${project.artifactId}-${project.version}/bin - false - 0775 - 0644 - - *.bat - contrib/** - - - - diff --git a/jkube-kit/generator/webapp/src/main/java/org/eclipse/jkube/generator/webapp/WebAppGenerator.java b/jkube-kit/generator/webapp/src/main/java/org/eclipse/jkube/generator/webapp/WebAppGenerator.java index a2b76a53c8..4f87817b56 100644 --- a/jkube-kit/generator/webapp/src/main/java/org/eclipse/jkube/generator/webapp/WebAppGenerator.java +++ b/jkube-kit/generator/webapp/src/main/java/org/eclipse/jkube/generator/webapp/WebAppGenerator.java @@ -23,7 +23,7 @@ import org.apache.commons.io.FilenameUtils; import org.eclipse.jkube.kit.common.Assembly; import org.eclipse.jkube.kit.common.AssemblyFile; -import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; import org.eclipse.jkube.kit.build.service.docker.ImageConfiguration; import org.eclipse.jkube.kit.common.Configs; diff --git a/jkube-kit/jkube-kit-openliberty/src/main/java/org/eclipse/jkube/openliberty/generator/OpenLibertyGenerator.java b/jkube-kit/jkube-kit-openliberty/src/main/java/org/eclipse/jkube/openliberty/generator/OpenLibertyGenerator.java index 22b67b8c4d..a3a0549be8 100644 --- a/jkube-kit/jkube-kit-openliberty/src/main/java/org/eclipse/jkube/openliberty/generator/OpenLibertyGenerator.java +++ b/jkube-kit/jkube-kit-openliberty/src/main/java/org/eclipse/jkube/openliberty/generator/OpenLibertyGenerator.java @@ -16,7 +16,7 @@ import org.eclipse.jkube.generator.api.GeneratorContext; import org.eclipse.jkube.generator.javaexec.FatJarDetector; import org.eclipse.jkube.generator.javaexec.JavaExecGenerator; -import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.eclipse.jkube.kit.build.service.docker.ImageConfiguration; import org.eclipse.jkube.kit.common.AssemblyFileSet; import org.eclipse.jkube.kit.common.JavaProject; @@ -74,7 +74,7 @@ protected void addAssembly(AssemblyConfiguration.AssemblyConfigurationBuilder bu if (assemblyRef != null) { builder.descriptorRef(assemblyRef); } else { - final List fileSets = new ArrayList<>(addAdditionalFiles(getProject())); + final List fileSets = new ArrayList<>(addAdditionalFiles()); if (isFatJar()) { FatJarDetector.Result fatJar = detectFatJar(); JavaProject project = getProject(); @@ -93,12 +93,12 @@ protected void addAssembly(AssemblyConfiguration.AssemblyConfigurationBuilder bu } @Override - public List addAdditionalFiles(JavaProject project) { + public List addAdditionalFiles() { List fileSets = new ArrayList<>(); - fileSets.add(createFileSet(project, "src/main/jkube-includes/bin","bin", "0755")); - fileSets.add(createFileSet(project, "src/main/jkube-includes",".", "0644")); + fileSets.add(createFileSet("src/main/jkube-includes/bin","bin", "0755")); + fileSets.add(createFileSet("src/main/jkube-includes",".", "0644")); // Add server.xml file - fileSets.add(createFileSet(project, "src/main/liberty/config","src/wlp/config", "0644")); + fileSets.add(createFileSet("src/main/liberty/config","src/wlp/config", "0644")); return fileSets; } diff --git a/jkube-kit/jkube-kit-openliberty/src/test/java/org/eclipse/jkube/openliberty/generator/OpenLibertyGeneratorTest.java b/jkube-kit/jkube-kit-openliberty/src/test/java/org/eclipse/jkube/openliberty/generator/OpenLibertyGeneratorTest.java index e959ed708a..0789f19803 100644 --- a/jkube-kit/jkube-kit-openliberty/src/test/java/org/eclipse/jkube/openliberty/generator/OpenLibertyGeneratorTest.java +++ b/jkube-kit/jkube-kit-openliberty/src/test/java/org/eclipse/jkube/openliberty/generator/OpenLibertyGeneratorTest.java @@ -19,7 +19,7 @@ import org.eclipse.jkube.generator.api.GeneratorContext; import org.eclipse.jkube.generator.javaexec.FatJarDetector; -import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.eclipse.jkube.kit.common.JavaProject; import org.eclipse.jkube.kit.common.KitLogger; diff --git a/jkube-kit/jkube-kit-quarkus/src/main/java/org/eclipse/jkube/quarkus/generator/QuarkusGenerator.java b/jkube-kit/jkube-kit-quarkus/src/main/java/org/eclipse/jkube/quarkus/generator/QuarkusGenerator.java index 069e3c72d0..8c9f38dde8 100644 --- a/jkube-kit/jkube-kit-quarkus/src/main/java/org/eclipse/jkube/quarkus/generator/QuarkusGenerator.java +++ b/jkube-kit/jkube-kit-quarkus/src/main/java/org/eclipse/jkube/quarkus/generator/QuarkusGenerator.java @@ -13,7 +13,7 @@ */ package org.eclipse.jkube.quarkus.generator; -import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; import org.eclipse.jkube.kit.build.service.docker.ImageConfiguration; import org.eclipse.jkube.kit.common.Configs; @@ -117,14 +117,14 @@ private AssemblyConfiguration createAssemblyConfiguration(String targetDir, Asse jKubeAssemblyFileSet.setOutputDirectory("."); return AssemblyConfiguration.builder() .targetDir(targetDir) - .inline(Assembly.builder().fileSets(Collections.singletonList(jKubeAssemblyFileSet)).build()) + .inline(Assembly.builder().fileSet(jKubeAssemblyFileSet).build()) .build(); } private AssemblyFileSet getJvmFilesToInclude() { AssemblyFileSet.AssemblyFileSetBuilder fileSetBuilder = getFileSetWithFileFromBuildThatEndsWith("-runner.jar"); - fileSetBuilder.include("lib/**"); + fileSetBuilder.include("lib"); // We also need to exclude default jar file File defaultJarFile = JKubeProjectUtil.getFinalOutputArtifact(getContext().getProject()); if (defaultJarFile != null) { diff --git a/jkube-kit/parent/pom.xml b/jkube-kit/parent/pom.xml index 2ef1bb3f99..e40326d81c 100644 --- a/jkube-kit/parent/pom.xml +++ b/jkube-kit/parent/pom.xml @@ -75,10 +75,11 @@ 2.3 + 0.0.5 - 0.0.3 - 0.0.3 + ${version.image.jkube-images} + ${version.image.jkube-images} 2.0 @@ -87,8 +88,8 @@ - 3.0 - ${version.image.karaf.upstream.docker} + ${version.image.jkube-images} + ${version.image.jkube-images} 2.0 @@ -96,8 +97,8 @@ - 0.0.3 - 0.0.3 + ${version.image.jkube-images} + ${version.image.jkube-images} 19.0.0.Final 19.0 @@ -115,9 +116,9 @@ fis-java-openshift:${version.image.java.redhat.s2i} - fabric8/s2i-karaf:${version.image.karaf.upstream.docker} - fabric8/s2i-karaf:${version.image.karaf.upstream.s2i} - fabric8-karaf:${version.image.karaf.upstream.s2i} + quay.io/jkube/jkube-karaf-binary-s2i:${version.image.karaf.upstream.docker} + quay.io/jkube/jkube-karaf-binary-s2i:${version.image.karaf.upstream.s2i} + jkube-karaf:${version.image.karaf.upstream.s2i} jboss-fuse-6/fis-karaf-openshift:${version.image.karaf.redhat.docker} jboss-fuse-6/fis-karaf-openshift:${version.image.karaf.redhat.s2i} diff --git a/kubernetes-maven-plugin/plugin/src/test/java/org/eclipse/jkube/generator/karaf/KarafGeneratorTest.java b/kubernetes-maven-plugin/plugin/src/test/java/org/eclipse/jkube/generator/karaf/KarafGeneratorTest.java new file mode 100644 index 0000000000..afd91b9b86 --- /dev/null +++ b/kubernetes-maven-plugin/plugin/src/test/java/org/eclipse/jkube/generator/karaf/KarafGeneratorTest.java @@ -0,0 +1,127 @@ +/** + * 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.generator.karaf; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.jkube.generator.api.GeneratorContext; +import org.eclipse.jkube.kit.build.service.docker.ImageConfiguration; +import org.eclipse.jkube.kit.common.Plugin; +import org.eclipse.jkube.kit.common.AssemblyConfiguration; +import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; + +import mockit.Expectations; +import mockit.Mocked; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasProperty; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.sameInstance; + + +public class KarafGeneratorTest { + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Mocked + private GeneratorContext generatorContext; + + @Test + public void isApplicableHasKarafMavenPluginShouldReturnTrue(@Mocked Plugin plugin) { + // Given + // @formatter:off + new Expectations() {{ + plugin.getGroupId(); result = "org.apache.karaf.or.any.other.groupid"; minTimes = 0; + plugin.getArtifactId(); result = "karaf-maven-plugin"; + generatorContext.getProject().getPlugins(); result = Collections.singletonList(plugin); + }}; + // @formatter:on + // When + final boolean result = new KarafGenerator(generatorContext).isApplicable(Collections.emptyList()); + // Then + assertThat(result, equalTo(true)); + } + + @Test + public void isApplicableHasNotKarafMavenPluginShouldReturnFalse(@Mocked Plugin plugin) { + // Given + // @formatter:off + new Expectations() {{ + plugin.getGroupId(); result = "org.apache.karaf.tooling"; minTimes = 0; + plugin.getArtifactId(); result = "not-karaf-maven-plugin"; + generatorContext.getProject().getPlugins(); result = Collections.singletonList(plugin); + }}; + // @formatter:on + // When + final boolean result = new KarafGenerator(generatorContext).isApplicable(Collections.emptyList()); + // Then + assertThat(result, equalTo(false)); + } + + @Test + public void customizeWithKarafMavenPluginShouldAddImageConfiguration(@Mocked Plugin plugin) throws IOException { + // Given + final List originalImageConfigurations = new ArrayList<>(); + // @formatter:off + new Expectations() {{ + plugin.getGroupId(); result = "org.apache.karaf.tooling"; minTimes = 0; + plugin.getArtifactId(); result = "karaf-maven-plugin"; minTimes = 0; + generatorContext.getProject().getPlugins(); result = Collections.singletonList(plugin); + generatorContext.getProject().getBuildDirectory(); result = temporaryFolder.getRoot(); + generatorContext.getProject().getVersion(); result = "1.33.7-SNAPSHOT"; + }}; + // @formatter:on + // When + final List result = new KarafGenerator(generatorContext) + .customize(originalImageConfigurations, false); + // Then + assertThat(originalImageConfigurations, sameInstance(result)); + assertThat(result, hasSize(1)); + final ImageConfiguration imageConfiguration = result.iterator().next(); + assertThat(imageConfiguration.getName(), equalTo("%g/%a:%l")); + assertThat(imageConfiguration.getAlias(), equalTo("karaf")); + final BuildConfiguration bc = imageConfiguration.getBuildConfiguration(); + assertThat(bc.getTags(), contains("latest")); + assertThat(bc.getPorts(), contains("8181")); + assertThat(bc.getEnv(), hasEntry("DEPLOYMENTS_DIR", "/deployments")); + assertThat(bc.getEnv(), hasEntry("KARAF_HOME", "/deployments/karaf")); + final AssemblyConfiguration ac = bc.getAssemblyConfiguration(); + assertThat(ac.getName(), equalTo("deployments")); + assertThat(ac.isExcludeFinalOutputArtifact(), equalTo(false)); + assertThat(ac.getInline().getFileSets(), contains( + allOf( + hasProperty("directory", equalTo(new File(temporaryFolder.getRoot(), "assembly"))), + hasProperty("outputDirectory", equalTo(new File("karaf"))), + hasProperty("directoryMode", equalTo("0775")) + ), + allOf( + hasProperty("directory", equalTo(temporaryFolder.getRoot().toPath().resolve("assembly").resolve("bin").toFile())), + hasProperty("outputDirectory", equalTo(new File("karaf", "bin"))), + hasProperty("fileMode", equalTo("0777")), + hasProperty("directoryMode", equalTo("0775")) + ) + )); + } +} \ No newline at end of file diff --git a/quickstarts/maven/karaf-camel-log/README.md b/quickstarts/maven/karaf-camel-log/README.md new file mode 100644 index 0000000000..d30e4c680e --- /dev/null +++ b/quickstarts/maven/karaf-camel-log/README.md @@ -0,0 +1,55 @@ +# Eclipse JKube Karaf Quickstart - Camel Log + +This quickstart shows a simple Apache Camel application that logs a series of messages to the Server log and +generates and processes random orders. + +## Features + +### Camel Log + +A Camel route defined in [camel-log.xml](src/main/resources/OSGI-INF/blueprint/camel-log.xml) (``) +will log some greeting messages to the Server log every second. + +The format and contents of the log messages is controlled in [org.ops4j.pax.logging.cfg +](src/main/resources/assembly/etc/org.ops4j.pax.logging.cfg) (`log4j2.appender.hello.name=hello-stdout`). + + +### Order generation and processing + +Two Camel route defined in [camel-log.xml](src/main/resources/OSGI-INF/blueprint/camel-log.xml) +(`` & ``), generates and processes some fake orders +every 5 seconds. +- Orders will be generated in `${KARAF_HOME}/work/orders/input` +- Orders will be processed and moved to `${KARAF_HOME}/work/orders/processed` +- Both actions will be logged to the Server output using a different logger. + + +## Building + +The quickstart can be built with `mvn clean install`. + +This will generate an Apache Karaf assembly ready to be deployed or run locally ( `./target/assembly/bin/karaf run`). + +## Deploying to Kubernetes + +Make sure you have access to a K8s cluster. + +Deploy the application: +``` +mvn k8s:build k8s:resource k8s:apply +``` + +Once the process is finished, you can retrieve the logs with `mvn k8s:log`. This should print the log messages +from the previously described Camel routes. + +## Deploying to OpenShift + +Make sure you have access to an OpenShift cluster. + +Deploy the application: +``` +mvn oc:build oc:resource oc:apply +``` + +Once the process is finished, you can retrieve the logs with `mvn oc:log`. This should print the log messages +from the previously described Camel routes. diff --git a/quickstarts/maven/karaf-camel-log/pom.xml b/quickstarts/maven/karaf-camel-log/pom.xml new file mode 100644 index 0000000000..dbb4007f82 --- /dev/null +++ b/quickstarts/maven/karaf-camel-log/pom.xml @@ -0,0 +1,155 @@ + + + + 4.0.0 + + org.eclipse.jkube.quickstarts.maven + karaf-camel-log + 1.0.0-SNAPSHOT + bundle + Eclipse JKube :: Quickstarts :: Maven :: Karaf Camel Log + + + 1.8 + 1.8 + 2.25.1 + 4.2.8 + + + + + org.apache.camel + camel-core + ${camel.version} + + + org.apache.camel + camel-blueprint + ${camel.version} + + + org.apache.karaf.features + framework + ${karaf.version} + kar + + + org.apache.karaf.features + framework + ${karaf.version} + features + xml + runtime + + + org.apache.karaf.features + standard + ${karaf.version} + features + xml + + + + + + + src/main/resources + true + + + + + org.apache.felix + maven-bundle-plugin + true + + + + * + + + + + + + + org.apache.maven.plugins + maven-install-plugin + + + default-install + + install + + install + + + + + org.apache.karaf.tooling + karaf-maven-plugin + ${karaf.version} + true + + + karaf-assembly + + assembly + + install + + + + 1.8 + framework + true + false + false + + framework + jaas + log + shell + bundle + feature + system + scr + management + aries-blueprint + camel-core + camel-blueprint + + + mvn:${project.groupId}/${project.artifactId}/${project.version};start-level=80 + + + + + org.eclipse.jkube + kubernetes-maven-plugin + ${project.version} + + + org.eclipse.jkube + openshift-maven-plugin + ${project.version} + + + + + diff --git a/quickstarts/maven/karaf-camel-log/src/main/java/org/eclipse/jkube/quickstart/karaf/OrderGenerator.java b/quickstarts/maven/karaf-camel-log/src/main/java/org/eclipse/jkube/quickstart/karaf/OrderGenerator.java new file mode 100644 index 0000000000..1163f57bd0 --- /dev/null +++ b/quickstarts/maven/karaf-camel-log/src/main/java/org/eclipse/jkube/quickstart/karaf/OrderGenerator.java @@ -0,0 +1,34 @@ +/** + * 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.quickstart.karaf; + +import org.apache.camel.CamelContext; + +import java.io.InputStream; +import java.util.Random; + +public class OrderGenerator { + private int count = 1; + private Random random = new Random(); + + public InputStream generateOrder(CamelContext camelContext) { + final int number = random.nextInt(5) + 1; + final String orderSource = String.format("data/order%s.xml", number); + return camelContext.getClassResolver().loadResourceAsStream(orderSource); + } + + public String generateFileName() { + return String.format("order%s.xml", count++); + } +} diff --git a/quickstarts/maven/karaf-camel-log/src/main/resources/OSGI-INF/blueprint/camel-log.xml b/quickstarts/maven/karaf-camel-log/src/main/resources/OSGI-INF/blueprint/camel-log.xml new file mode 100644 index 0000000000..a7753b35c3 --- /dev/null +++ b/quickstarts/maven/karaf-camel-log/src/main/resources/OSGI-INF/blueprint/camel-log.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Hello from Camel! + + + + + + diff --git a/quickstarts/maven/karaf-camel-log/src/main/resources/assembly/etc/org.ops4j.pax.logging.cfg b/quickstarts/maven/karaf-camel-log/src/main/resources/assembly/etc/org.ops4j.pax.logging.cfg new file mode 100644 index 0000000000..e04c936fa2 --- /dev/null +++ b/quickstarts/maven/karaf-camel-log/src/main/resources/assembly/etc/org.ops4j.pax.logging.cfg @@ -0,0 +1,34 @@ +# +# 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 +# + +log4j2.rootLogger.level=WARN +log4j2.rootLogger.appenderRef.Console.ref=global-stdout + +log4j2.logger.jkube.name=org.eclipse.jkube.quickstart.karaf +log4j2.logger.jkube.level=INFO + +log4j2.logger.jkube-hello.name=org.eclipse.jkube.quickstart.karaf.hello +log4j2.logger.jkube-hello.level=INFO +log4j2.logger.jkube-hello.additivity=false +log4j2.logger.jkube-hello.appenderRef.hello.ref=hello-stdout + +log4j2.appender.console.name=global-stdout +log4j2.appender.console.type=Console +log4j2.appender.console.layout.type=PatternLayout +log4j2.appender.console.layout.pattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n + +log4j2.appender.hello.name=hello-stdout +log4j2.appender.hello.type=Console +log4j2.appender.hello.layout.type=PatternLayout +log4j2.appender.hello.layout.pattern=>>> %highlight{%m}%n diff --git a/quickstarts/maven/karaf-camel-log/src/main/resources/data/order1.xml b/quickstarts/maven/karaf-camel-log/src/main/resources/data/order1.xml new file mode 100644 index 0000000000..1bd608c1f7 --- /dev/null +++ b/quickstarts/maven/karaf-camel-log/src/main/resources/data/order1.xml @@ -0,0 +1,41 @@ + + + + + + Antwerp Zoo + Antwerp + BE + + + 1985-10-25 + + + +

+ Bactrian Camel +
+ 1 + + +
+ Dromedary (Arabian Camel) +
+ 10 +
+ + diff --git a/quickstarts/maven/karaf-camel-log/src/main/resources/data/order2.xml b/quickstarts/maven/karaf-camel-log/src/main/resources/data/order2.xml new file mode 100644 index 0000000000..f1745418e9 --- /dev/null +++ b/quickstarts/maven/karaf-camel-log/src/main/resources/data/order2.xml @@ -0,0 +1,41 @@ + + + + + + Bristol Zoo Gardens + Bristol + UK + + + 2015-10-21 + + + +
+ Wild bactrian camel +
+ 2 +
+ +
+ Camel +
+ 200 +
+
+
diff --git a/quickstarts/maven/karaf-camel-log/src/main/resources/data/order3.xml b/quickstarts/maven/karaf-camel-log/src/main/resources/data/order3.xml new file mode 100644 index 0000000000..8f8d895431 --- /dev/null +++ b/quickstarts/maven/karaf-camel-log/src/main/resources/data/order3.xml @@ -0,0 +1,41 @@ + + + + + + Columbus Zoo and Aquarium + Columbus + US + + + 1955-11-05 + + + +
+ Camel +
+ 100 +
+ +
+ Llama +
+ 1 +
+
+
diff --git a/quickstarts/maven/karaf-camel-log/src/main/resources/data/order4.xml b/quickstarts/maven/karaf-camel-log/src/main/resources/data/order4.xml new file mode 100644 index 0000000000..d7cc6e37d4 --- /dev/null +++ b/quickstarts/maven/karaf-camel-log/src/main/resources/data/order4.xml @@ -0,0 +1,41 @@ + + + + + + Dartmoor Zoological Park + Devon + UK + + + 1985-10-26 + + + +
+ Horse +
+ 1 +
+ +
+ Camel +
+ 337 +
+
+
diff --git a/quickstarts/maven/karaf-camel-log/src/main/resources/data/order5.xml b/quickstarts/maven/karaf-camel-log/src/main/resources/data/order5.xml new file mode 100644 index 0000000000..2cd7754170 --- /dev/null +++ b/quickstarts/maven/karaf-camel-log/src/main/resources/data/order5.xml @@ -0,0 +1,41 @@ + + + + + + Erie Zoo + Erie + US + + + 1955-11-12 + + + +
+ Dromedary (Arabian Camel) +
+ 13 +
+ +
+ Camel +
+ 37 +
+
+
diff --git a/quickstarts/maven/quarkus/pom.xml b/quickstarts/maven/quarkus/pom.xml index 70046da9f8..85cb5141a0 100644 --- a/quickstarts/maven/quarkus/pom.xml +++ b/quickstarts/maven/quarkus/pom.xml @@ -20,7 +20,7 @@ org.eclipse.jkube.quickstarts.maven quarkus - 1.0.0-alpha-3 + 1.0.0-SNAPSHOT Eclipse JKube :: Quickstarts :: Maven :: Quarkus Quarkus REST JSON project