Skip to content

Commit

Permalink
Fix #112: Quarkus Error while trying to build the image: Unexpected i…
Browse files Browse the repository at this point in the history
…nternal error near index 1

Fix Windows specific path parsing error
  • Loading branch information
rohanKanojia authored and manusa committed Mar 24, 2020
1 parent 1f5a81d commit d610d31
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Usage:
* Fix #53: Renamed plugins to openshift/kubernetes-maven-plugin keeping acronym (oc/k8s) for goal
* Fix #97: Port of fabric8io/fabric8-maven-plugin#1794 to fix ImageChange triggers not being set in DeploymentConfig when resource fragments are used
* Ported PR fabric8io/fabric8-maven-plugin#1802, Labels are missing for some objects
* Fix #112: Fix windows specific path error while splitting file path

### 0.2.0 (05-03-2020)
* Fix #71: script to extract changelog information for notifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,11 @@ public File createArchive(File inputDirectory, BuildDirs buildDirs, ArchiveCompr
String targetFileName = entry.getValue();

// 1. Check whether nested directory is there, if not create it
String[] pathParts = targetFileName.split(File.separator);
File parentDirectory = inputDirectory;
if (pathParts.length > 0) {
StringBuilder finalPathBuilder = new StringBuilder();
for (int i = 0; i < pathParts.length - 1; i++) {
String pathPart = pathParts[i];
finalPathBuilder.append(pathPart + File.separator);
}
parentDirectory = new File(inputDirectory, finalPathBuilder.toString());
parentDirectory.mkdirs();
File parentDirectory = new File(targetFileName).getParentFile();
if (parentDirectory != null) {
FileUtil.createDirectory(new File(inputDirectory, parentDirectory.getPath()));
}
File targetFile = new File(parentDirectory, pathParts[pathParts.length - 1]);
File targetFile = new File(inputDirectory, targetFileName);
// Check whether file is not already created.
if (!targetFile.exists()) {
FileUtils.copyFile(srcFile, targetFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.stream.Stream;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* 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.util;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import java.io.File;
import java.io.IOException;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class FileUtilTest {
@Rule
public TemporaryFolder folder = new TemporaryFolder();

@Test
public void testCreateDirectory() throws IOException {
File newDirectory = new File(folder.getRoot(), "firstdirectory");
FileUtil.createDirectory(newDirectory);
assertTrue(newDirectory.exists());
}

@Test
public void testListFilesRecursively() throws IOException {
prepareDirectory();
List<File> fileList = FileUtil.listFilesRecursivelyInDirectory(folder.getRoot());
assertNotNull(fileList);
assertEquals(3, fileList.size());
}

@Test
public void testCleanDirectory() throws IOException {
prepareDirectory();
List<File> fileList = FileUtil.listFilesRecursivelyInDirectory(folder.getRoot());
assertEquals(3, fileList.size());
FileUtil.cleanDirectory(folder.getRoot());
assertFalse(folder.getRoot().exists());
}

@Test
public void trimWildCardCharactersFromPath() {
assertEquals("lib", FileUtil.trimWildcardCharactersFromPath("lib/**"));
}

@Test
public void testCopyDir() throws IOException {
prepareDirectory();
File copyTarget = new File(folder.getRoot(), "copyTarget");
FileUtil.copyDirectory(new File(folder.getRoot(), "foo"), copyTarget);

assertTrue(copyTarget.exists());
assertEquals(1, FileUtil.listFilesRecursivelyInDirectory(copyTarget).size());
assertTrue(new File(copyTarget, "fileInfoo1").exists());
}

@Test
public void testGetRelativePath() throws IOException {
prepareDirectory();
File relativeFile = FileUtil.getRelativePath(folder.getRoot(), new File(folder.getRoot(), "foo"));
assertEquals("foo", relativeFile.getPath());
relativeFile = FileUtil.getRelativePath(folder.getRoot(), new File(folder.getRoot().getAbsolutePath() + File.separator + "foo" + File.separator + "fileInfoo1"));
assertEquals("foo/fileInfoo1", relativeFile.getPath());
}

private void prepareDirectory() throws IOException {
File dir1 = folder.newFolder("foo");
File file1 = new File(dir1, "fileInfoo1");
folder.newFile("something");
File dir2 = folder.newFolder("bar");
File file2 = new File(dir2, "fileInfoo2");
file1.createNewFile();
file2.createNewFile();
}

}

0 comments on commit d610d31

Please sign in to comment.