Search in sources :

Example 1 with AssemblyFileSet

use of org.eclipse.jkube.kit.common.AssemblyFileSet in project jkube by eclipse.

the class AssemblyManager method getAssemblyConfigurationForDockerfileMode.

@Nonnull
private static AssemblyConfiguration getAssemblyConfigurationForDockerfileMode(JKubeConfiguration configuration, BuildConfiguration buildConfiguration, JKubeConfiguration params) throws IOException {
    AssemblyConfiguration assemblyConfig = getAssemblyConfigurationOrCreateDefault(buildConfiguration);
    final AssemblyConfiguration.AssemblyConfigurationBuilder builder = assemblyConfig.toBuilder();
    File contextDir = buildConfiguration.getAbsoluteContextDirPath(params.getSourceDirectory(), params.getBasedir().getAbsolutePath());
    final AssemblyFileSet assemblyFileSet = AssemblyFileSet.builder().directory(contextDir).outputDirectory(new File(".")).directoryMode("0775").excludes(createDockerExcludesList(contextDir, params.getOutputDirectory())).includes(createDockerIncludesList(contextDir)).build();
    builder.layer(Assembly.builder().fileSet(assemblyFileSet).build());
    return builder.build().getFlattenedClone(configuration);
}
Also used : AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) AssemblyFileSet(org.eclipse.jkube.kit.common.AssemblyFileSet) AssemblyFileSetUtils.processAssemblyFileSet(org.eclipse.jkube.kit.common.archive.AssemblyFileSetUtils.processAssemblyFileSet) AssemblyFileUtils.resolveSourceFile(org.eclipse.jkube.kit.common.archive.AssemblyFileUtils.resolveSourceFile) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Nonnull(javax.annotation.Nonnull)

Example 2 with AssemblyFileSet

use of org.eclipse.jkube.kit.common.AssemblyFileSet in project jkube by eclipse.

the class AssemblyConfigurationUtilsTest method getJKubeAssemblyFileSetsNullFileSetsShouldReturnEmptyList.

@Test
public void getJKubeAssemblyFileSetsNullFileSetsShouldReturnEmptyList() {
    // Given
    final Assembly assembly = new Assembly();
    // When
    final List<AssemblyFileSet> result = getJKubeAssemblyFileSets(assembly);
    // Then
    assertThat(result).isNotNull().isEmpty();
}
Also used : AssemblyFileSet(org.eclipse.jkube.kit.common.AssemblyFileSet) Assembly(org.eclipse.jkube.kit.common.Assembly) Test(org.junit.Test)

Example 3 with AssemblyFileSet

use of org.eclipse.jkube.kit.common.AssemblyFileSet in project jkube by eclipse.

the class WildflyJARGeneratorTest method slimServerAbsoluteDir.

@Test
public void slimServerAbsoluteDir(@Mocked final JavaProject project) throws IOException {
    Map<String, Object> options = new HashMap<>();
    Map<String, String> pluginOptions = new HashMap();
    Path tmpDir = Files.createTempDirectory("bootable-jar-test-project2");
    Path targetDir = tmpDir.resolve("target");
    Path repoDir = targetDir.resolve("myrepo");
    Files.createDirectories(repoDir);
    options.put(PLUGIN_OPTIONS, pluginOptions);
    pluginOptions.put(JBOSS_MAVEN_DIST, null);
    pluginOptions.put(JBOSS_MAVEN_REPO, repoDir.toString());
    try {
        GeneratorContext ctx = contextForSlimServer(project, options, null);
        WildflyJARGenerator generator = new WildflyJARGenerator(ctx);
        List<String> extraOptions = generator.getExtraJavaOptions();
        assertNotNull(extraOptions);
        assertEquals(2, extraOptions.size());
        assertEquals("-Djava.net.preferIPv4Stack=true", extraOptions.get(0));
        assertEquals("-Dmaven.repo.local=/deployments/myrepo", extraOptions.get(1));
        List<AssemblyFileSet> files = generator.addAdditionalFiles();
        assertFalse(files.isEmpty());
        AssemblyFileSet set = files.get(files.size() - 1);
        assertEquals(targetDir.toFile(), set.getDirectory());
        assertEquals(1, set.getIncludes().size());
        assertEquals("myrepo", set.getIncludes().get(0));
    } finally {
        Files.delete(repoDir);
        Files.delete(targetDir);
        Files.delete(tmpDir);
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) AssemblyFileSet(org.eclipse.jkube.kit.common.AssemblyFileSet) GeneratorContext(org.eclipse.jkube.generator.api.GeneratorContext) Test(org.junit.Test)

Example 4 with AssemblyFileSet

use of org.eclipse.jkube.kit.common.AssemblyFileSet in project jkube by eclipse.

the class AssemblyFileSetUtils method processAssemblyFileSet.

/**
 * Will copy files from the provided <code>baseDirectory</code> into
 * <code>outputDirectory/assemblyConfiguration.targetDir[/layer.directory]</code>
 * considering the inclusion and exclusion rules defined in the provided {@link AssemblyFileSet}.
 *
 * @param baseDirectory directory from where to resolve source files.
 * @param outputDirectory directory where files should be output.
 * @param assemblyFileSet fileSet to process.
 * @param layer the layer to which fileSet belongs to.
 * @param assemblyConfiguration configuration for assembly.
 * @return List containing the copied {@link AssemblyFileEntry} for the processed {@link AssemblyFileSet}
 * @throws IOException in case something goes wrong when performing File operations.
 */
@SuppressWarnings("squid:S3864")
@Nonnull
public static List<AssemblyFileEntry> processAssemblyFileSet(File baseDirectory, File outputDirectory, AssemblyFileSet assemblyFileSet, Assembly layer, AssemblyConfiguration assemblyConfiguration) throws IOException {
    final File sourceDirectory = resolveSourceDirectory(baseDirectory, assemblyFileSet);
    Objects.requireNonNull(assemblyConfiguration.getTargetDir(), "Assembly Configuration target dir is required");
    if (!sourceDirectory.exists()) {
        return Collections.emptyList();
    }
    final File targetDirectory;
    if (StringUtils.isNotBlank(layer.getId())) {
        targetDirectory = new File(new File(outputDirectory, layer.getId()), assemblyConfiguration.getTargetDir());
    } else {
        targetDirectory = new File(outputDirectory, assemblyConfiguration.getTargetDir());
    }
    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<String> includes = Optional.ofNullable(assemblyFileSet.getIncludes()).filter(i -> !i.isEmpty()).orElse(Collections.singletonList(PATH_TO_SELF));
    final List<AssemblyFileEntry> allEntries = new ArrayList<>();
    for (String include : includes) {
        final String effectiveInclude = isSelfPath(include) ? "**" : include;
        allEntries.addAll(processInclude(sourceDirectory.toPath(), effectiveInclude, destinationDirectory.toPath(), assemblyFileSet));
    }
    return allEntries;
}
Also used : AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) File(java.io.File) AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) ArrayList(java.util.ArrayList) AssemblyFileSet(org.eclipse.jkube.kit.common.AssemblyFileSet) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Assembly(org.eclipse.jkube.kit.common.Assembly) PathMatcher(java.nio.file.PathMatcher) FileUtil(org.eclipse.jkube.kit.common.util.FileUtil) Optional(java.util.Optional) Path(java.nio.file.Path) Collections(java.util.Collections) Nonnull(javax.annotation.Nonnull) FileSystems(java.nio.file.FileSystems) LinkedHashSet(java.util.LinkedHashSet) AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) ArrayList(java.util.ArrayList) File(java.io.File) Nonnull(javax.annotation.Nonnull)

Example 5 with AssemblyFileSet

use of org.eclipse.jkube.kit.common.AssemblyFileSet in project jkube by eclipse.

the class AssemblyFileSetUtilsProcessAssemblyFileSetTest method minimumRequiredFieldsWithAssemblyId.

/**
 * @see #minimumRequiredFields()
 */
@Test
public void minimumRequiredFieldsWithAssemblyId() throws Exception {
    // Given
    final AssemblyFileSet afs = AssemblyFileSet.builder().directory(sourceDirectory).build();
    final Assembly layer = Assembly.builder().id("layer-1").build();
    final AssemblyConfiguration ac = AssemblyConfiguration.builder().targetDir("deployments").build();
    // When
    final List<AssemblyFileEntry> result = processAssemblyFileSet(baseDirectory, outputDirectory, afs, layer, ac);
    // Then
    assertThat(result).hasSize(16);
    FileAssertions.assertThat(new File(outputDirectory, "layer-1")).exists().fileTree().containsExactlyInAnyOrder("deployments", "deployments/source-directory", "deployments/source-directory/1.txt", "deployments/source-directory/3.other", "deployments/source-directory/37", "deployments/source-directory/one", "deployments/source-directory/one/1.txt", "deployments/source-directory/one/3.other", "deployments/source-directory/one/37", "deployments/source-directory/two", "deployments/source-directory/two/1.txt", "deployments/source-directory/two/3.other", "deployments/source-directory/two/37", "deployments/source-directory/three", "deployments/source-directory/three/1.txt", "deployments/source-directory/three/3.other", "deployments/source-directory/three/37");
}
Also used : AssemblyFileEntry(org.eclipse.jkube.kit.common.AssemblyFileEntry) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) AssemblyFileSet(org.eclipse.jkube.kit.common.AssemblyFileSet) AssemblyFileSetUtils.processAssemblyFileSet(org.eclipse.jkube.kit.common.archive.AssemblyFileSetUtils.processAssemblyFileSet) File(java.io.File) Assembly(org.eclipse.jkube.kit.common.Assembly) Test(org.junit.Test)

Aggregations

AssemblyFileSet (org.eclipse.jkube.kit.common.AssemblyFileSet)33 Test (org.junit.Test)30 File (java.io.File)26 AssemblyFileEntry (org.eclipse.jkube.kit.common.AssemblyFileEntry)21 AssemblyFileSetUtils.processAssemblyFileSet (org.eclipse.jkube.kit.common.archive.AssemblyFileSetUtils.processAssemblyFileSet)19 Assembly (org.eclipse.jkube.kit.common.Assembly)18 AssemblyConfiguration (org.eclipse.jkube.kit.common.AssemblyConfiguration)18 Path (java.nio.file.Path)6 HashMap (java.util.HashMap)2 Nonnull (javax.annotation.Nonnull)2 GeneratorContext (org.eclipse.jkube.generator.api.GeneratorContext)2 IOException (java.io.IOException)1 FileSystems (java.nio.file.FileSystems)1 Files (java.nio.file.Files)1 PathMatcher (java.nio.file.PathMatcher)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Objects (java.util.Objects)1