-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Hackathon merge #3013
[WIP] Hackathon merge #3013
Changes from all commits
2b3537e
338e8d9
56c09bd
07a4fcb
366b94f
ecad6a0
b6fe453
19979af
70c3e2f
6276380
a1606e6
cd108e7
c600fc8
df59b26
d09dd3c
d89ff97
bf966bc
8ce1e4f
4037072
84f57e7
5f12a55
4b30906
a916b01
2b896cb
6427a41
0f423e8
6b7edad
d3923c2
59b3816
703fb33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.commons.lang.os; | ||
|
||
/** | ||
* Escapes Windows path to unix-style path. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is used in several places in around docker usage in both Che and Codenvy. I think it is time to move that code in a single place since it is bad practice to use the same private methods in several classes. |
||
* | ||
* @author Alexander Garagatyi | ||
*/ | ||
public class WindowsPathEscaper { | ||
|
||
/** Implements singleton pattern. */ | ||
private static final WindowsPathEscaper escaper = new WindowsPathEscaper(); | ||
|
||
/** Does nothing. Can be used for mocking purposes. */ | ||
public WindowsPathEscaper() {} | ||
|
||
/** | ||
* Static version of method that escapes paths on Windows. | ||
* It is discouraged to use this method because it is too hard to mock it. | ||
* Use {@link #escapePath(String)} instead. | ||
* | ||
* @param path path on Windows. Can be unix-style path also. | ||
* @return unix-style path | ||
* @see #escapePath(String) | ||
*/ | ||
public static String escapePathStatic(String path) { | ||
return escaper.escapePath(path); | ||
} | ||
|
||
/** | ||
* Escapes Windows path to unix-style path. | ||
* | ||
* @param path path on Windows. Can be unix-style path also. | ||
* @return unix-style path | ||
*/ | ||
public String escapePath(String path) { | ||
String esc; | ||
if (path.indexOf(":") == 1) { | ||
// check and replace only occurrence of ":" after disk label on Windows host (e.g. C:/) | ||
// but keep other occurrences it can be marker for docker mount volumes | ||
// (e.g. /path/dir/from/host:/name/of/dir/in/container ) | ||
esc = path.replaceFirst(":", "").replace('\\', '/'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't like File.separator :) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not my code. And I don't want to introduce here additional changes in this PR because it will delay merge significantly. |
||
esc = Character.toLowerCase(esc.charAt(0)) + esc.substring(1); //letter of disk mark must be lower case | ||
} else { | ||
esc = path.replace('\\', '/'); | ||
} | ||
if (!esc.startsWith("/")) { | ||
esc = "/" + esc; | ||
} | ||
return esc; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.commons.lang.os; | ||
|
||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
/** | ||
* @author Alexander Garagatyi | ||
*/ | ||
public class WindowsPathEscaperTest { | ||
/** | ||
* E.g from https://github.com/boot2docker/boot2docker/blob/master/README.md#virtualbox-guest-additions | ||
* | ||
* Users should be /Users | ||
* /Users should be /Users | ||
* c/Users should be /c/Users | ||
* /c/Users should be /c/Users | ||
* c:/Users should be /c/Users | ||
*/ | ||
@Test(dataProvider = "pathProvider") | ||
public void shouldStaticallyEscapePathForWindowsHost(String windowsPath, String expectedPath) { | ||
assertEquals(WindowsPathEscaper.escapePathStatic(windowsPath), expectedPath); | ||
} | ||
|
||
/** | ||
* E.g from https://github.com/boot2docker/boot2docker/blob/master/README.md#virtualbox-guest-additions | ||
* | ||
* Users should be /Users | ||
* /Users should be /Users | ||
* c/Users should be /c/Users | ||
* /c/Users should be /c/Users | ||
* c:/Users should be /c/Users | ||
*/ | ||
@Test(dataProvider = "pathProvider") | ||
public void shouldNonStaticallyEscapePathForWindowsHost(String windowsPath, String expectedPath) { | ||
WindowsPathEscaper windowsPathEscaper = new WindowsPathEscaper(); | ||
assertEquals(windowsPathEscaper.escapePath(windowsPath), expectedPath); | ||
} | ||
|
||
@DataProvider(name = "pathProvider") | ||
public static Object[][] pathProvider() { | ||
return new Object[][] { | ||
{"Users", "/Users"}, | ||
{"/Users", "/Users"}, | ||
{"c/Users", "/c/Users"}, | ||
{"/c/Users", "/c/Users"}, | ||
{"c:/Users", "/c/Users"}, | ||
{"C:/Users", "/c/Users"}, | ||
{"C:/Users/path/dir/from/host:/name/of/dir/in/container", | ||
"/c/Users/path/dir/from/host:/name/of/dir/in/container"} | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose to use separate folder for that. Let's call it
/agent-binaries
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
separate folder by duplicating the existing binaries ? because agents are inside CHE_HOME/lib for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose that we can move agents binaries to any folder, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose to move agents away from
/lib
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok but it might take some time to validate this change no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skabashnyuk are you ok if we postpone that and do after merging that PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes