This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 207659
Collapse All | Expand All

(-)a/dlight.remote.impl/nbproject/project.xml (-1 / +1 lines)
Lines 85-91 Link Here
85
                    <build-prerequisite/>
85
                    <build-prerequisite/>
86
                    <compile-dependency/>
86
                    <compile-dependency/>
87
                    <run-dependency>
87
                    <run-dependency>
88
                        <specification-version>7.56</specification-version>
88
                        <specification-version>7.60</specification-version>
89
                    </run-dependency>
89
                    </run-dependency>
90
                </dependency>
90
                </dependency>
91
                <dependency>
91
                <dependency>
(-)a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileSystem.java (+41 lines)
Lines 66-71 Link Here
66
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
66
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
67
import org.netbeans.modules.nativeexecution.api.util.ConnectionListener;
67
import org.netbeans.modules.nativeexecution.api.util.ConnectionListener;
68
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
68
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
69
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager.CancellationException;
70
import org.netbeans.modules.nativeexecution.api.util.HostInfoUtils;
69
import org.netbeans.modules.remote.api.ui.ConnectionNotifier;
71
import org.netbeans.modules.remote.api.ui.ConnectionNotifier;
70
import org.netbeans.modules.remote.spi.FileSystemCacheProvider;
72
import org.netbeans.modules.remote.spi.FileSystemCacheProvider;
71
import org.netbeans.modules.remote.impl.RemoteLogger;
73
import org.netbeans.modules.remote.impl.RemoteLogger;
Lines 262-267 Link Here
262
            return getRoot().getFileObject(name);
264
            return getRoot().getFileObject(name);
263
        }
265
        }
264
    }
266
    }
267
268
    @Override
269
    public FileObject getTempFolder() throws IOException {
270
        try {
271
            String tmpName = HostInfoUtils.getHostInfo(execEnv).getTempDir();
272
            RemoteFileObject tmpDir = findResource(tmpName);
273
            if (tmpDir != null && tmpDir.isFolder() && tmpDir.isValid()) {
274
                return tmpDir;
275
            }
276
        } catch (CancellationException ex) {
277
            //
278
        }
279
        throw new IOException("Cannot find temporary folder"); // NOI18N
280
    }
281
    
282
    @Override
283
    public FileObject createTempFile(FileObject parent, String prefix, String suffix) throws IOException {
284
        if (parent.isFolder() && parent.isValid()) {
285
            while(true) {
286
                File tmpFile = File.createTempFile(prefix, suffix);
287
                String tmpName = tmpFile.getName();
288
                tmpFile.delete();
289
                try {
290
                    FileObject fo = parent.createData(tmpName);
291
                    if (fo != null && fo.isData() && fo.isValid()) {
292
                        return fo;
293
                    }
294
                    break;   
295
                } catch (IOException ex) {
296
                    FileObject test = parent.getFileObject(tmpName);
297
                    if (test != null) {
298
                        continue;
299
                    }
300
                    throw ex;
301
                }
302
            }
303
        }
304
        throw new IOException("Cannot create temporary file"); // NOI18N
305
    }
265
    
306
    
266
    /*package*/ RemoteFileObjectBase findResource(String name, Set<String> antiloop) {
307
    /*package*/ RemoteFileObjectBase findResource(String name, Set<String> antiloop) {
267
        if (name.isEmpty() || name.equals("/")) {  // NOI18N
308
        if (name.isEmpty() || name.equals("/")) {  // NOI18N
(-)a/dlight.remote.impl/test/unit/src/org/netbeans/modules/remote/test/RemoteFSTCKTest.java (+2 lines)
Lines 49-54 Link Here
49
import org.openide.filesystems.FileObjectTestHid;
49
import org.openide.filesystems.FileObjectTestHid;
50
import org.openide.filesystems.FileSystemTestHid;
50
import org.openide.filesystems.FileSystemTestHid;
51
import org.openide.filesystems.FileUtilTestHidden;
51
import org.openide.filesystems.FileUtilTestHidden;
52
import org.openide.filesystems.TempFileObjectTestHid;
52
import org.openide.filesystems.URLMapperTestHidden;
53
import org.openide.filesystems.URLMapperTestHidden;
53
54
54
/**
55
/**
Lines 69-74 Link Here
69
        //suite.addTestSuite(AttributesTestHidden.class);
70
        //suite.addTestSuite(AttributesTestHidden.class);
70
        suite.addTestSuite(URLMapperTestHidden.class);
71
        suite.addTestSuite(URLMapperTestHidden.class);
71
        suite.addTestSuite(FileUtilTestHidden.class);
72
        suite.addTestSuite(FileUtilTestHidden.class);
73
        suite.addTestSuite(TempFileObjectTestHid.class);
72
        return new RemoteFSTCKTest(suite);
74
        return new RemoteFSTCKTest(suite);
73
    }
75
    }
74
    
76
    
(-)a/masterfs/nbproject/project.xml (-1 / +1 lines)
Lines 63-69 Link Here
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <specification-version>7.54</specification-version>
66
                        <specification-version>7.60</specification-version>
67
                    </run-dependency>
67
                    </run-dependency>
68
                </dependency>
68
                </dependency>
69
                <dependency>
69
                <dependency>
(-)a/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedFileSystem.java (+23 lines)
Lines 48-53 Link Here
48
import java.io.IOException;
48
import java.io.IOException;
49
import java.io.ObjectStreamException;
49
import java.io.ObjectStreamException;
50
import java.io.Serializable;
50
import java.io.Serializable;
51
import java.security.SecureRandom;
51
import java.util.Collection;
52
import java.util.Collection;
52
import java.util.Collections;
53
import java.util.Collections;
53
import java.util.HashSet;
54
import java.util.HashSet;
Lines 211-216 Link Here
211
        }
212
        }
212
        return getFileObject(f);
213
        return getFileObject(f);
213
    }
214
    }
215
    
216
    @Override
217
    public FileObject getTempFolder() throws IOException {
218
        FileObject tmpDir = FileUtil.toFileObject(File.createTempFile("tmp", null).getParentFile()); // NOI18N
219
        if (tmpDir != null && tmpDir.isFolder() && tmpDir.isValid()) {
220
            return tmpDir;
221
        }
222
        throw new IOException("Cannot find temporary folder"); // NOI18N
223
    }
224
    
225
    @Override
226
    public FileObject createTempFile(FileObject parent, String prefix, String suffix) throws IOException {
227
        if (parent.isFolder() && parent.isValid()) {
228
            File tmpFile = File.createTempFile(prefix, suffix, FileUtil.toFile(parent));
229
            FileObject fo = FileUtil.toFileObject(tmpFile);
230
            if (fo != null && fo.isData() && fo.isValid()) {
231
                return fo;
232
            }
233
            tmpFile.delete();
234
        }
235
        throw new IOException("Cannot create temporary file"); // NOI18N
236
    }
214
237
215
    @Override
238
    @Override
216
    public SystemAction[] getActions() {
239
    public SystemAction[] getActions() {
(-)a/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/FileBasedFileSystemTest.java (+1 lines)
Lines 83-88 Link Here
83
        suite.addTestSuite(FileUtilTestHidden.class);
83
        suite.addTestSuite(FileUtilTestHidden.class);
84
        suite.addTestSuite(FileUtilJavaIOFileHidden.class);
84
        suite.addTestSuite(FileUtilJavaIOFileHidden.class);
85
        suite.addTestSuite(BaseFileObjectTestHid.class);
85
        suite.addTestSuite(BaseFileObjectTestHid.class);
86
        suite.addTestSuite(TempFileObjectTestHid.class);
86
        suite.addTest(new CheckProviders(created));
87
        suite.addTest(new CheckProviders(created));
87
        return suite;
88
        return suite;
88
    }
89
    }
(-)a/openide.filesystems/apichanges.xml (+16 lines)
Lines 49-54 Link Here
49
        <apidef name="filesystems">Filesystems API</apidef>
49
        <apidef name="filesystems">Filesystems API</apidef>
50
    </apidefs>
50
    </apidefs>
51
    <changes>
51
    <changes>
52
        <change id="FileSystem.createTemporaryFO">
53
            <api name="filesystems"/>
54
            <summary>File System can create temporary file</summary>
55
            <version major="7" minor="60"/>
56
            <date year="2012" month="2" day="14"/>
57
            <author login="alexvsimon"/>
58
            <compatibility addition="yes" deprecation="no"/>
59
            <description>
60
                <p>
61
                    Added methods to create temporary file objects:
62
                    <code>FileSystem.getTempFolder</code>,  <code>FileSystem.createTempFile</code>.
63
                </p>
64
            </description>
65
            <class package="org.openide.filesystems" name="FileSystem"/>
66
            <issue number="207659"/>
67
        </change>
52
        <change id="LayersProvider">
68
        <change id="LayersProvider">
53
            <api name="filesystems"/>
69
            <api name="filesystems"/>
54
            <summary>SPI for Additions to System File System</summary>
70
            <summary>SPI for Additions to System File System</summary>
(-)a/openide.filesystems/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.filesystems
2
OpenIDE-Module: org.openide.filesystems
3
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
4
OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml
4
OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml
5
OpenIDE-Module-Specification-Version: 7.59
5
OpenIDE-Module-Specification-Version: 7.60
6
6
(-)a/openide.filesystems/src/org/openide/filesystems/FileSystem.java (+23 lines)
Lines 442-447 Link Here
442
    */
442
    */
443
    public abstract FileObject findResource(String name);
443
    public abstract FileObject findResource(String name);
444
444
445
    /** Returns temporary folder if it is avaliable on this file system.
446
     * Method never returns null. IOException is thrown instead.
447
     * @return a file object for temporary folder
448
     * @throws IOException 
449
     * @since 7.60
450
     */
451
    public FileObject getTempFolder() throws IOException {
452
        throw new IOException("Unsupported operation"); // NOI18N
453
    }
454
    
455
    /** Creates temporary file in the given parent folder.
456
     * Method never returns null. IOException is thrown instead.
457
     * @param parent the parent folder where temporary file will be created
458
     * @param prefix prefix of the name of created file
459
     * @param suffix suffix of the name of created file
460
     * @return new temporary file
461
     * @throws IOException 
462
     * @since 7.60
463
     */
464
    public FileObject createTempFile(FileObject parent, String prefix, String suffix) throws IOException {
465
        throw new IOException("Unsupported operation"); // NOI18N
466
    }
467
        
445
    /** Returns an array of actions that can be invoked on any file in
468
    /** Returns an array of actions that can be invoked on any file in
446
    * this filesystem.
469
    * this filesystem.
447
    * These actions should preferably
470
    * These actions should preferably
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/TempFileObjectTestHid.java (+85 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.openide.filesystems;
43
44
/**
45
 *
46
 * @author Alexander Simon
47
 */
48
public class TempFileObjectTestHid extends TestBaseHid {
49
    private FileObject root;
50
51
    public TempFileObjectTestHid(String name) {
52
        super(name);
53
    }
54
55
    @Override
56
    protected void setUp() throws Exception {
57
        super.setUp();
58
        root = testedFS.findResource(getResourcePrefix());
59
    }
60
61
    @Override
62
    protected String[] getResources(String testName) {
63
        return new String[] {};
64
    }
65
    
66
    public void testTempDir() throws Exception {
67
        FileObject tempFolder = root.getFileSystem().getTempFolder();
68
        assertNotNull(tempFolder);
69
        assertTrue(tempFolder.isValid());
70
        assertTrue(tempFolder.isFolder());
71
        assertEquals(tempFolder.getFileSystem(), root.getFileSystem());
72
    }
73
74
    public void testTempFile() throws Exception {
75
        FileObject tempFolder = root.getFileSystem().getTempFolder();
76
        FileObject tempFile = root.getFileSystem().createTempFile(tempFolder, "out", ".tmp");
77
        assertNotNull(tempFile);
78
        assertTrue(tempFile.isValid());
79
        assertTrue(tempFile.isData());
80
        assertEquals(tempFile.getParent(), tempFolder);
81
        assertEquals(tempFolder.getFileSystem(), tempFile.getFileSystem());
82
        assertTrue(tempFile.getNameExt().startsWith("out"));
83
        assertTrue(tempFile.getNameExt().endsWith(".tmp"));
84
    }
85
}

Return to bug 207659