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);
}
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();
}
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);
}
}
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;
}
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");
}
Aggregations