Skip to content

Commit

Permalink
switch from createLink to createSymbolicLink
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Amerson <gregory.amerson@liferay.com>
  • Loading branch information
gamerson committed Jan 6, 2017
1 parent 3a59711 commit 49ec044
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
24 changes: 4 additions & 20 deletions aQute.libg/src/aQute/lib/io/IO.java
Expand Up @@ -22,13 +22,12 @@
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.security.MessageDigest;
import java.util.Collection;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -628,31 +627,16 @@ public static PrintWriter writer(OutputStream out) throws IOException {
*/
public static boolean createSymbolicLink(File link, File target) throws Exception {
try {
Method toPath = link.getClass().getMethod("toPath");
Class< ? > Files = Class.forName("java.nio.file.Files");
for (Method m : Files.getMethods()) {
if (m.getName().equals("createSymbolicLink") && m.getParameterTypes().length == 3) {
Object attrs = Array.newInstance(m.getParameterTypes()[2].getComponentType(), 0);
m.invoke(null, toPath.invoke(link), toPath.invoke(target), attrs);
return true;
}
}
Files.createSymbolicLink(link.toPath(), target.toPath());
return true;
} catch (Exception e) {
// ignore
}
return false;
}

public static boolean isSymbolicLink(File link) {
try {
Method toPath = link.getClass().getMethod("toPath");
Class< ? > Files = Class.forName("java.nio.file.Files");
Method method = Files.getMethod("isSymbolicLink", toPath.getReturnType());
return (Boolean) method.invoke(null, toPath.invoke(link));
} catch (Exception e) {
// ignore
}
return false;
return Files.isSymbolicLink(link.toPath());
}

static public OutputStream nullStream = new OutputStream() {
Expand Down
Expand Up @@ -28,7 +28,7 @@ public class DownloadListenerPromise implements Success<File,Void>, Failure {

/**
* Use the promise to signal the Download Listeners
*
*
* @param reporter a reporter or null (will use a SLF4 in that case)
* @param task
* @param promise
Expand All @@ -50,7 +50,7 @@ public Promise<Void> call(Promise<File> resolved) throws Exception {
File file = resolved.getValue();

if (linked != null) {
Files.createLink(linked.toPath(), file.toPath());
Files.createSymbolicLink(linked.toPath(), file.toPath());
}

for (DownloadListener dl : dls) {
Expand Down
Expand Up @@ -96,7 +96,8 @@ File get(String bsn, Version version, Map<String,String> properties, DownloadLis
final File link = new File(location, bsn + "-" + version + ".jar");
if (link.isFile())
Files.delete(link.toPath());
Files.createLink(link.toPath(), source.toPath());

Files.createSymbolicLink(link.toPath(), source.toPath());

Promise<File> go = client.build().useCache(MAX_STALE).async(url.toURL()).map(new Function<File,File>() {
@Override
Expand Down

0 comments on commit 49ec044

Please sign in to comment.