From f2e3043d12a90f5f8e5ce354004c7d4e17380a89 Mon Sep 17 00:00:00 2001 From: Damjan Jovanovic Date: Wed, 25 Nov 2009 21:27:06 +0300 Subject: [PATCH] 4899516: Transferable has no DataFlavors when dragging from Gnome window to Swing Reviewed-by: uta, dav --- .../sun/awt/datatransfer/DataTransferer.java | 161 +++++++++++++----- .../classes/sun/awt/X11/XDataTransferer.java | 84 +++++++++ jdk/src/solaris/lib/flavormap.properties | 1 + .../sun/awt/windows/WDataTransferer.java | 31 ++++ .../FileListTransferable.java | 58 +++++++ .../InterprocessMessages.java | 27 +++ .../SourceFileListFrame.java | 97 +++++++++++ .../TargetFileListFrame.java | 144 ++++++++++++++++ .../URIListBetweenJVMsTest.html | 25 +++ .../URIListBetweenJVMsTest.java | 158 +++++++++++++++++ .../process/ProcessCommunicator.java | 10 +- 11 files changed, 751 insertions(+), 45 deletions(-) create mode 100644 jdk/test/java/awt/dnd/URIListBetweenJVMsTest/FileListTransferable.java create mode 100644 jdk/test/java/awt/dnd/URIListBetweenJVMsTest/InterprocessMessages.java create mode 100644 jdk/test/java/awt/dnd/URIListBetweenJVMsTest/SourceFileListFrame.java create mode 100644 jdk/test/java/awt/dnd/URIListBetweenJVMsTest/TargetFileListFrame.java create mode 100644 jdk/test/java/awt/dnd/URIListBetweenJVMsTest/URIListBetweenJVMsTest.html create mode 100644 jdk/test/java/awt/dnd/URIListBetweenJVMsTest/URIListBetweenJVMsTest.java diff --git a/jdk/src/share/classes/sun/awt/datatransfer/DataTransferer.java b/jdk/src/share/classes/sun/awt/datatransfer/DataTransferer.java index a0853088e42..64ff903ac90 100644 --- a/jdk/src/share/classes/sun/awt/datatransfer/DataTransferer.java +++ b/jdk/src/share/classes/sun/awt/datatransfer/DataTransferer.java @@ -51,6 +51,9 @@ import java.io.Reader; import java.io.SequenceInputStream; import java.io.StringReader; +import java.net.URI; +import java.net.URISyntaxException; + import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; @@ -203,8 +206,6 @@ public abstract class DataTransferer { private static final Map nativeEOLNs = Collections.synchronizedMap(new HashMap()); - private static final byte [] UNICODE_NULL_TERMINATOR = new byte [] {0,0}; - /** * The number of terminating NUL bytes for the Set of textNatives. */ @@ -627,6 +628,14 @@ public abstract class DataTransferer { */ public abstract boolean isImageFormat(long format); + /** + * Determines whether the format is a URI list we can convert to + * a DataFlavor.javaFileListFlavor. + */ + protected boolean isURIListFormat(long format) { + return false; + } + /** * Returns a Map whose keys are all of the possible formats into which the * Transferable's transfer data flavors can be translated. The value of @@ -1299,58 +1308,55 @@ search: if (!DataFlavor.javaFileListFlavor.equals(flavor)) { throw new IOException("data translation failed"); } - final List list = (List)obj; - final ArrayList fileList = new ArrayList(); + final List list = (List)obj; final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents); - int nFiles = 0; - for (int i = 0; i < list.size(); i++) { - Object o = list.get(i); - if (o instanceof File || o instanceof String) { - nFiles++; + final ArrayList fileList = castToFiles(list, userProtectionDomain); + + bos = convertFileListToBytes(fileList); + + + // Target data is a URI list. Source data must be a + // java.util.List which contains java.io.File or String instances. + } else if (isURIListFormat(format)) { + if (!DataFlavor.javaFileListFlavor.equals(flavor)) { + throw new IOException("data translation failed"); + } + String nat = getNativeForFormat(format); + String targetCharset = null; + if (nat != null) { + try { + targetCharset = new DataFlavor(nat).getParameter("charset"); + } catch (ClassNotFoundException cnfe) { + throw new IOException(cnfe); } } - - try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws IOException { - for (Object fileObject : list) - { - File file = castToFile(fileObject); - if (null == System.getSecurityManager() || - !(isFileInWebstartedCache(file) || - isForbiddenToRead(file, userProtectionDomain))) - { - fileList.add(file.getCanonicalPath()); - } - } - return null; - } - }); - } catch (PrivilegedActionException pae) { - throw new IOException(pae.getMessage()); + if (targetCharset == null) { + targetCharset = "UTF-8"; } + final List list = (List)obj; + final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents); + final ArrayList fileList = castToFiles(list, userProtectionDomain); + final ArrayList uriList = new ArrayList(fileList.size()); + for (String fileObject : fileList) { + final URI uri = new File(fileObject).toURI(); + // Some implementations are fussy about the number of slashes (file:///path/to/file is best) + try { + uriList.add(new URI(uri.getScheme(), "", uri.getPath(), uri.getFragment()).toString()); + } catch (URISyntaxException uriSyntaxException) { + throw new IOException(uriSyntaxException); + } + } - if(fileList.isEmpty()) { - //store empty unicode string (null terminator) - bos.write(UNICODE_NULL_TERMINATOR); - } else { - for (int i = 0; i < fileList.size(); i++) { - byte[] bytes = fileList.get(i).getBytes(getDefaultUnicodeEncoding()); - //store unicode string with null terminator - bos.write(bytes, 0, bytes.length); - bos.write(UNICODE_NULL_TERMINATOR); - } + byte[] eoln = "\r\n".getBytes(targetCharset); + for (int i = 0; i < uriList.size(); i++) { + byte[] bytes = uriList.get(i).getBytes(targetCharset); + bos.write(bytes, 0, bytes.length); + bos.write(eoln, 0, eoln.length); } - // According to MSDN the byte array have to be double NULL-terminated. - // The array contains Unicode characters, so each NULL-terminator is - // a pair of bytes - - bos.write(UNICODE_NULL_TERMINATOR); - // Source data is an InputStream. For arbitrary flavors, just grab the // bytes and dump them into a byte array. For text flavors, decode back // to a String and recur to reencode according to the requested format. @@ -1398,6 +1404,8 @@ search: return ret; } + protected abstract ByteArrayOutputStream convertFileListToBytes(ArrayList fileList) throws IOException; + private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str) throws IOException { @@ -1465,6 +1473,33 @@ search: return true; } + private ArrayList castToFiles(final List files, + final ProtectionDomain userProtectionDomain) throws IOException + { + final ArrayList fileList = new ArrayList(); + try { + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws IOException { + for (Object fileObject : files) + { + File file = castToFile(fileObject); + if (file != null && + (null == System.getSecurityManager() || + !(isFileInWebstartedCache(file) || + isForbiddenToRead(file, userProtectionDomain)))) + { + fileList.add(file.getCanonicalPath()); + } + } + return null; + } + }); + } catch (PrivilegedActionException pae) { + throw new IOException(pae.getMessage()); + } + return fileList; + } + // It is important do not use user's successors // of File class. private File castToFile(Object fileObject) throws IOException { @@ -1473,6 +1508,8 @@ search: filePath = ((File)fileObject).getCanonicalPath(); } else if (fileObject instanceof String) { filePath = (String) fileObject; + } else { + return null; } return new File(filePath); } @@ -1578,6 +1615,29 @@ search: // Turn the list of Files into a List and return return Arrays.asList(files); + // Source data is a URI list. Convert to DataFlavor.javaFileListFlavor + // where possible. + } else if (isURIListFormat(format) && DataFlavor.javaFileListFlavor.equals(flavor)) { + try { + URI uris[] = dragQueryURIs(str, bytes, format, localeTransferable); + if (uris == null) { + return null; + } + ArrayList files = new ArrayList(); + for (URI uri : uris) { + try { + files.add(new File(uri)); + } catch (IllegalArgumentException illegalArg) { + // When converting from URIs to less generic files, + // common practice (Wine, SWT) seems to be to + // silently drop the URIs that aren't local files. + } + } + return files; + } finally { + str.close(); + } + // Target data is a String. Strip terminating NUL bytes. Decode bytes // into characters. Search-and-replace EOLN. } else if (String.class.equals(flavor.getRepresentationClass()) && @@ -1962,6 +2022,19 @@ search: */ protected abstract String[] dragQueryFile(byte[] bytes); + /** + * Decodes URIs from either a byte array or a stream. + */ + protected URI[] dragQueryURIs(InputStream stream, + byte[] bytes, + long format, + Transferable localeTransferable) + throws IOException + { + throw new IOException( + new UnsupportedOperationException("not implemented on this platform")); + } + /** * Translates either a byte array or an input stream which contain * platform-specific image data in the given format into an Image. diff --git a/jdk/src/solaris/classes/sun/awt/X11/XDataTransferer.java b/jdk/src/solaris/classes/sun/awt/X11/XDataTransferer.java index c82f6b11b51..b08eed94dc2 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XDataTransferer.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XDataTransferer.java @@ -28,14 +28,21 @@ package sun.awt.X11; import java.awt.Image; import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.awt.image.WritableRaster; +import java.io.BufferedReader; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -48,6 +55,8 @@ import javax.imageio.spi.ImageWriterSpi; import sun.awt.datatransfer.DataTransferer; import sun.awt.datatransfer.ToolkitThreadBlockedHandler; +import java.io.ByteArrayOutputStream; + /** * Platform-specific support for the data transfer subsystem. */ @@ -108,6 +117,22 @@ public class XDataTransferer extends DataTransferer { return super.getCharsetForTextFormat(lFormat); } + protected boolean isURIListFormat(long format) { + String nat = getNativeForFormat(format); + if (nat == null) { + return false; + } + try { + DataFlavor df = new DataFlavor(nat); + if (df.getPrimaryType().equals("text") && df.getSubType().equals("uri-list")) { + return true; + } + } catch (Exception e) { + // Not a MIME format. + } + return false; + } + public boolean isFileFormat(long format) { return format == FILE_NAME_ATOM.getAtom() || format == DT_NET_FILE_ATOM.getAtom(); @@ -170,6 +195,19 @@ public class XDataTransferer extends DataTransferer { } } + protected ByteArrayOutputStream convertFileListToBytes(ArrayList fileList) + throws IOException + { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + for (int i = 0; i < fileList.size(); i++) + { + byte[] bytes = fileList.get(i).getBytes(); + if (i != 0) bos.write(0); + bos.write(bytes, 0, bytes.length); + } + return bos; + } + /** * Translates either a byte array or an input stream which contain * platform-specific image data in the given format into an Image. @@ -215,6 +253,52 @@ public class XDataTransferer extends DataTransferer { } } + protected URI[] dragQueryURIs(InputStream stream, + byte[] bytes, + long format, + Transferable localeTransferable) + throws IOException { + + String charset = null; + if (localeTransferable != null && + isLocaleDependentTextFormat(format) && + localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor)) { + try { + charset = new String( + (byte[])localeTransferable.getTransferData(javaTextEncodingFlavor), + "UTF-8" + ); + } catch (UnsupportedFlavorException cannotHappen) { + } + } else { + charset = getCharsetForTextFormat(format); + } + if (charset == null) { + // Only happens when we have a custom text type. + charset = getDefaultTextCharset(); + } + + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(stream, charset)); + String line; + ArrayList uriList = new ArrayList(); + URI uri; + while ((line = reader.readLine()) != null) { + try { + uri = new URI(line); + } catch (URISyntaxException uriSyntaxException) { + throw new IOException(uriSyntaxException); + } + uriList.add(uri); + } + return uriList.toArray(new URI[uriList.size()]); + } finally { + if (reader != null) + reader.close(); + } + } + /** * Returns true if and only if the name of the specified format Atom * constitutes a valid MIME type with the specified primary type. diff --git a/jdk/src/solaris/lib/flavormap.properties b/jdk/src/solaris/lib/flavormap.properties index e96da314c93..223002a69aa 100644 --- a/jdk/src/solaris/lib/flavormap.properties +++ b/jdk/src/solaris/lib/flavormap.properties @@ -73,5 +73,6 @@ UTF8_STRING=text/plain;charset=UTF-8;eoln="\n";terminators=0 TEXT=text/plain;eoln="\n";terminators=0 STRING=text/plain;charset=iso8859-1;eoln="\n";terminators=0 FILE_NAME=application/x-java-file-list;class=java.util.List +text/uri-list=application/x-java-file-list;class=java.util.List PNG=image/x-java-image;class=java.awt.Image JFIF=image/x-java-image;class=java.awt.Image diff --git a/jdk/src/windows/classes/sun/awt/windows/WDataTransferer.java b/jdk/src/windows/classes/sun/awt/windows/WDataTransferer.java index b996974ff18..ec19fcd1b49 100644 --- a/jdk/src/windows/classes/sun/awt/windows/WDataTransferer.java +++ b/jdk/src/windows/classes/sun/awt/windows/WDataTransferer.java @@ -72,6 +72,10 @@ import sun.awt.datatransfer.ToolkitThreadBlockedHandler; import sun.awt.image.ImageRepresentation; import sun.awt.image.ToolkitImage; +import java.util.ArrayList; + +import java.io.ByteArrayOutputStream; + /** * Platform-specific support for the data transfer subsystem. * @@ -342,6 +346,33 @@ public class WDataTransferer extends DataTransferer { return imageDataToPlatformImageBytes(imageData, width, height, format); } + private static final byte [] UNICODE_NULL_TERMINATOR = new byte [] {0,0}; + + protected ByteArrayOutputStream convertFileListToBytes(ArrayList fileList) + throws IOException + { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + if(fileList.isEmpty()) { + //store empty unicode string (null terminator) + bos.write(UNICODE_NULL_TERMINATOR); + } else { + for (int i = 0; i < fileList.size(); i++) { + byte[] bytes = fileList.get(i).getBytes(getDefaultUnicodeEncoding()); + //store unicode string with null terminator + bos.write(bytes, 0, bytes.length); + bos.write(UNICODE_NULL_TERMINATOR); + } + } + + // According to MSDN the byte array have to be double NULL-terminated. + // The array contains Unicode characters, so each NULL-terminator is + // a pair of bytes + + bos.write(UNICODE_NULL_TERMINATOR); + return bos; + } + /** * Returns a byte array which contains data special for the given format * and for the given image data. diff --git a/jdk/test/java/awt/dnd/URIListBetweenJVMsTest/FileListTransferable.java b/jdk/test/java/awt/dnd/URIListBetweenJVMsTest/FileListTransferable.java new file mode 100644 index 00000000000..24cdcb356f0 --- /dev/null +++ b/jdk/test/java/awt/dnd/URIListBetweenJVMsTest/FileListTransferable.java @@ -0,0 +1,58 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.File; +import java.io.IOException; + +class FileListTransferable implements Transferable { + + final private DataFlavor[] supportedFlavors = + {DataFlavor.javaFileListFlavor}; + + private java.util.List list; + + public FileListTransferable(java.util.List list) { + this.list = list; + } + + public DataFlavor[] getTransferDataFlavors() { + return supportedFlavors; + } + + public boolean isDataFlavorSupported(DataFlavor flavor) { + for (DataFlavor df:supportedFlavors) { + if (df.equals(flavor)) return true; + } + return false; + } + + public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { + if (flavor.equals(DataFlavor.javaFileListFlavor)) { + return list; + } + throw new UnsupportedFlavorException(flavor); + } +} diff --git a/jdk/test/java/awt/dnd/URIListBetweenJVMsTest/InterprocessMessages.java b/jdk/test/java/awt/dnd/URIListBetweenJVMsTest/InterprocessMessages.java new file mode 100644 index 00000000000..c7a3230b5e8 --- /dev/null +++ b/jdk/test/java/awt/dnd/URIListBetweenJVMsTest/InterprocessMessages.java @@ -0,0 +1,27 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +public interface InterprocessMessages { + final static int EXECUTION_IS_SUCCESSFULL = 0; + final static int WRONG_FILES_NUMBER_ON_TARGET = 212; +} diff --git a/jdk/test/java/awt/dnd/URIListBetweenJVMsTest/SourceFileListFrame.java b/jdk/test/java/awt/dnd/URIListBetweenJVMsTest/SourceFileListFrame.java new file mode 100644 index 00000000000..aa42c51276f --- /dev/null +++ b/jdk/test/java/awt/dnd/URIListBetweenJVMsTest/SourceFileListFrame.java @@ -0,0 +1,97 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import test.java.awt.regtesthelpers.Util; + +import java.awt.*; +import java.awt.dnd.DragGestureListener; +import java.awt.dnd.DragSource; +import java.awt.dnd.DnDConstants; +import java.awt.dnd.DragGestureEvent; +import java.io.File; +import java.util.Arrays; + + +class SourceFileListFrame extends Frame implements DragGestureListener { + + private final static int SOURCE_POINT_SHIFT = 3; + + private List list = new List(URIListBetweenJVMsTest.VISIBLE_RAWS_IN_LIST); + private File[] files; + + SourceFileListFrame() { + super("Source File List Frame"); + extractFilesFromTheWorkingDirectory(); + initList(); + initGUI(); + new DragSource().createDefaultDragGestureRecognizer(list, + DnDConstants.ACTION_COPY,this); + } + + private void extractFilesFromTheWorkingDirectory() { + files = new File(System.getProperty("java.home", "")).listFiles(); + } + + private void initList() { + for (File currFile:files) { + list.add(currFile.getName()); + } + } + + private void initGUI() { + this.addWindowListener(Util.getClosingWindowAdapter()); + this.setLocation(300,250); + this.add(new Panel().add(list)); + this.pack(); + this.setVisible(true); + } + + int getNextLocationX() { + return getX()+getWidth(); + } + + int getNextLocationY() { + return getY(); + } + + int getDragSourcePointX() { + return (int)list.getLocationOnScreen().getX()+(list.getWidth()/2); + } + + int getDragSourcePointY() { + return (int)list.getLocationOnScreen().getY()+ SOURCE_POINT_SHIFT; + } + + int getSourceFilesNumber() { + return files.length; + } + + public void dragGestureRecognized(DragGestureEvent dge) { + String [] filesAsStringArray = list.getItems(); + File [] files = new File[filesAsStringArray.length]; + for (int fileNumber=0; fileNumber fileList = extractListOfFiles(dtde); + for (File file:fileList) { + list.add(file.getName()); + } + + if (fileList.size() != expectationTransferredFilesNumber) + { + System.err.println("ERROR: Expected file number:" + + expectationTransferredFilesNumber + + "; Received file number: " + + fileList.size()); + TargetFileListFrame.this.dispose(); + System.exit(InterprocessMessages.WRONG_FILES_NUMBER_ON_TARGET); + } + + TargetFileListFrame.this.dispose(); + + } + + private java.util.List extractListOfFiles(DropTargetDropEvent dtde) { + BufferedReader reader = null; + ArrayList files = new ArrayList(); + try { + reader = new BufferedReader((Reader)dtde.getTransferable(). + getTransferData(dropFlavor)); + String line; + while ((line = reader.readLine()) != null) { + files.add(new File(new URI(line))); + } + } catch (UnsupportedFlavorException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException ignored) { + } + } + } + return files; + } + + Point getDropTargetPoint() { + return new Point((int)list.getLocationOnScreen().getX()+(list.getWidth()/2), + (int)list.getLocationOnScreen().getY()+(list.getHeight()/2)); + } +} diff --git a/jdk/test/java/awt/dnd/URIListBetweenJVMsTest/URIListBetweenJVMsTest.html b/jdk/test/java/awt/dnd/URIListBetweenJVMsTest/URIListBetweenJVMsTest.html new file mode 100644 index 00000000000..cf5a41c0f3c --- /dev/null +++ b/jdk/test/java/awt/dnd/URIListBetweenJVMsTest/URIListBetweenJVMsTest.html @@ -0,0 +1,25 @@ + + + + DnD of URI-List across JVM + + + +

URIListBetweenJVMsTest
Bug ID: 4899516

+ +

This is an AUTOMATIC test, simply wait for completion

+ + + + diff --git a/jdk/test/java/awt/dnd/URIListBetweenJVMsTest/URIListBetweenJVMsTest.java b/jdk/test/java/awt/dnd/URIListBetweenJVMsTest/URIListBetweenJVMsTest.java new file mode 100644 index 00000000000..63775943465 --- /dev/null +++ b/jdk/test/java/awt/dnd/URIListBetweenJVMsTest/URIListBetweenJVMsTest.java @@ -0,0 +1,158 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + test + @bug 4899516 + @summary Transferable has no DataFlavors when dragging from Gnome window to Swing + @author : area=dnd + @run applet URIListBetweenJVMsTest.html +*/ + +/** + * URIListBetweenJVMsTest.java + * + * summary: Transferable has no DataFlavors when dragging from Gnome window to Swing + */ + +import static java.lang.Thread.sleep; + +import test.java.awt.regtesthelpers.process.ProcessCommunicator; +import test.java.awt.regtesthelpers.process.ProcessResults; +import test.java.awt.regtesthelpers.Util; +import java.applet.Applet; +import java.awt.*; +import java.awt.event.InputEvent; +import java.io.*; + +public class URIListBetweenJVMsTest extends Applet { + + // information related to the test in common + static int VISIBLE_RAWS_IN_LIST=15; + + public void init() { + setLayout(new BorderLayout()); + + }//End init() + + public void start() { + + String toolkit = Toolkit.getDefaultToolkit().getClass().getName(); + if (toolkit.equals("sun.awt.windows.WToolkit")){ + System.out.println("This test is not for the Windows platform. Passed."); + return; + } else { + System.out.println("Toolkit = " + toolkit); + } + + SourceFileListFrame sourceFrame = new SourceFileListFrame(); + + Util.waitForIdle(null); + + String [] args = new String [] { + String.valueOf(sourceFrame.getNextLocationX()), + String.valueOf(sourceFrame.getNextLocationY()), + String.valueOf(sourceFrame.getDragSourcePointX()), + String.valueOf(sourceFrame.getDragSourcePointY()), + String.valueOf(sourceFrame.getSourceFilesNumber()) + }; + + String classpath = System.getProperty("java.class.path"); + ProcessResults processResults = + ProcessCommunicator.executeChildProcess(this.getClass(), classpath, args); + + verifyTestResults(processResults); + + }// start() + + private static void verifyTestResults(ProcessResults processResults) { + if ( InterprocessMessages.WRONG_FILES_NUMBER_ON_TARGET == + processResults.getExitValue()) + { + processResults.printProcessErrorOutput(System.err); + throw new RuntimeException("TEST IS FAILED: Target has recieved" + + " wrong number of files."); + } + processResults.verifyStdErr(System.err); + processResults.verifyProcessExitValue(System.err); + processResults.printProcessStandartOutput(System.out); + } + + //We cannot make an instance of the applet without the default constructor + public URIListBetweenJVMsTest () { + super(); + } + + //We need in this constructor to pass frame position between JVMs + public URIListBetweenJVMsTest (Point targetFrameLocation, Point dragSourcePoint, + int transferredFilesNumber) + throws InterruptedException + { + TargetFileListFrame targetFrame = new TargetFileListFrame(targetFrameLocation, + transferredFilesNumber); + + Util.waitForIdle(null); + + final Robot robot = Util.createRobot(); + + robot.mouseMove((int)dragSourcePoint.getX(),(int)dragSourcePoint.getY()); + sleep(100); + robot.mousePress(InputEvent.BUTTON1_MASK); + sleep(100); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + sleep(100); + + Util.drag(robot, dragSourcePoint, targetFrame.getDropTargetPoint(), + InputEvent.BUTTON1_MASK); + + } + + enum InterprocessArguments { + TARGET_FRAME_X_POSITION_ARGUMENT, + TARGET_FRAME_Y_POSITION_ARGUMENT, + DRAG_SOURCE_POINT_X_ARGUMENT, + DRAG_SOURCE_POINT_Y_ARGUMENT, + FILES_IN_THE_LIST_NUMBER_ARGUMENT; + + int extract (String [] args) { + return Integer.parseInt(args[this.ordinal()]); + } + } + + public static void main (String [] args) { + Point dragSourcePoint = new Point(InterprocessArguments.DRAG_SOURCE_POINT_X_ARGUMENT.extract(args), + InterprocessArguments.DRAG_SOURCE_POINT_Y_ARGUMENT.extract(args)); + Point targetFrameLocation = new Point(InterprocessArguments.TARGET_FRAME_X_POSITION_ARGUMENT.extract(args), + InterprocessArguments.TARGET_FRAME_Y_POSITION_ARGUMENT.extract(args)); + int transferredFilesNumber = InterprocessArguments.FILES_IN_THE_LIST_NUMBER_ARGUMENT.extract(args); + + try { + new URIListBetweenJVMsTest(targetFrameLocation, dragSourcePoint, transferredFilesNumber); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } + + +}// class URIListBetweenJVMsTest diff --git a/jdk/test/java/awt/regtesthelpers/process/ProcessCommunicator.java b/jdk/test/java/awt/regtesthelpers/process/ProcessCommunicator.java index 820c6cb1803..15f5560cca0 100644 --- a/jdk/test/java/awt/regtesthelpers/process/ProcessCommunicator.java +++ b/jdk/test/java/awt/regtesthelpers/process/ProcessCommunicator.java @@ -146,7 +146,15 @@ public class ProcessCommunicator { final String classPathArguments, final String [] args) { StringBuilder commandBuilder = new StringBuilder(); - commandBuilder.append(javaPath).append(classPathArguments).append(classToExecute.getName()); + commandBuilder.append(javaPath).append(" "); + commandBuilder.append("-cp ").append(System.getProperty("test.classes", ".")).append(File.pathSeparatorChar); + + if (classPathArguments.trim().length() > 0) { + commandBuilder.append(classPathArguments).append(" "); + } + + commandBuilder.append(" "); + commandBuilder.append(classToExecute.getName()); for (String argument:args) { commandBuilder.append(" ").append(argument); }