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 247673
Collapse All | Expand All

(-)a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/api/wizards/MakeSampleProjectGenerator.java (-1 / +45 lines)
Lines 43-52 Link Here
43
 */
43
 */
44
package org.netbeans.modules.cnd.makeproject.api.wizards;
44
package org.netbeans.modules.cnd.makeproject.api.wizards;
45
45
46
import com.sun.javafx.util.Utils;
46
import java.io.BufferedReader;
47
import java.io.BufferedReader;
47
import java.io.BufferedWriter;
48
import java.io.BufferedWriter;
48
import java.io.ByteArrayOutputStream;
49
import java.io.ByteArrayOutputStream;
49
import java.io.File;
50
import java.io.File;
51
import java.io.FileInputStream;
52
import java.io.FileOutputStream;
50
import java.io.IOException;
53
import java.io.IOException;
51
import java.io.InputStream;
54
import java.io.InputStream;
52
import java.io.InputStreamReader;
55
import java.io.InputStreamReader;
Lines 85-92 Link Here
85
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory;
88
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory;
86
import org.netbeans.modules.nativeexecution.api.util.ProcessUtils;
89
import org.netbeans.modules.nativeexecution.api.util.ProcessUtils;
87
import org.netbeans.modules.remote.spi.FileSystemProvider;
90
import org.netbeans.modules.remote.spi.FileSystemProvider;
91
import org.netbeans.modules.remote.spi.WarmapHintProvider;
88
import org.openide.filesystems.FileLock;
92
import org.openide.filesystems.FileLock;
89
import org.openide.filesystems.FileObject;
93
import org.openide.filesystems.FileObject;
94
import org.openide.filesystems.FileSystem;
90
import org.openide.filesystems.FileUtil;
95
import org.openide.filesystems.FileUtil;
91
import org.openide.filesystems.URLMapper;
96
import org.openide.filesystems.URLMapper;
92
import org.openide.util.Lookup;
97
import org.openide.util.Lookup;
Lines 520-527 Link Here
520
        }
525
        }
521
    }
526
    }
522
527
523
    private static void unzip(InputStream source, FileObject targetFolder) throws IOException {
528
    private static void unzip(InputStream source, FileObject targetFolder) throws IOException {        
524
        //installation
529
        //installation
530
        final ExecutionEnvironment env = FileSystemProvider.getExecutionEnvironment(targetFolder);
531
        if (env.isRemote()) {
532
            final FileSystem fs = targetFolder.getFileSystem();
533
            final FileObject zipFO = fs.createTempFile(targetFolder, "__tmp", ".zip", false); //NOI18N
534
            final OutputStream os = zipFO.getOutputStream();
535
            File tmpZipFile = null;
536
            try {
537
                tmpZipFile = File.createTempFile("sample", ".zip");                
538
                try (FileOutputStream fos = new FileOutputStream(tmpZipFile)) {
539
                    FileUtil.copy(source, fos);
540
                }
541
                source = new FileInputStream(tmpZipFile);                
542
                FileUtil.copy(source, os);
543
                os.close();
544
//                StringBuilder script = new StringBuilder();
545
//                script.append("\'").append("unzip -q ").append(zipFO.getNameExt()).append(" && rm ").append(zipFO.getPath()); //NOI18N
546
////                if (Utils.isWindows() || Boolean.getBoolean("remote.test.dos2unix")) { //NOI18N
547
////                    script.append(" && (which dos2unix > /dev/null; if [ $? = 0 ]; then find . -name \"*[Mm]akefile*\" -exec dos2unix {}  \\; ; else echo \"no_dos2unix\"; fi)"); //NOI18N
548
////                }
549
//                script.append("\'"); //NOI18N
550
//                ProcessUtils.ExitStatus rc = ProcessUtils.executeInDir(targetFolder.getPath(), env, "sh", "-x", "-c", script.toString()); //NOI18N
551
                ProcessUtils.ExitStatus rc = ProcessUtils.executeInDir(targetFolder.getPath(), env, "unzip", "-q", zipFO.getNameExt()); //NOI18N
552
                if (!rc.isOK()) {
553
                     throw new IOException(rc.getErrorString());
554
                }
555
                WarmapHintProvider.setWarmupZip(targetFolder, tmpZipFile);
556
                List<String> out = rc.getOutputLines();
557
                if (out != null && !out.isEmpty() && out.get(0).startsWith("no_dos2unix")) { //NOI18N
558
                    // There is no dos2unix on the machine:
559
                    // need to update makefiles one by one
560
                }
561
            } finally {
562
//                if (tmpZipFile != null) {
563
//                    tmpZipFile.delete();
564
//                }
565
                targetFolder.refresh();
566
            }
567
            return;
568
        }
525
        ZipInputStream zip = new ZipInputStream(source);
569
        ZipInputStream zip = new ZipInputStream(source);
526
        try {
570
        try {
527
            ZipEntry ent;
571
            ZipEntry ent;
(-)a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteDirectory.java (+24 lines)
Lines 44-49 Link Here
44
44
45
import java.io.BufferedReader;
45
import java.io.BufferedReader;
46
import java.io.File;
46
import java.io.File;
47
import java.io.FileInputStream;
47
import java.io.FileNotFoundException;
48
import java.io.FileNotFoundException;
48
import java.io.FileOutputStream;
49
import java.io.FileOutputStream;
49
import java.io.IOException;
50
import java.io.IOException;
Lines 80-85 Link Here
80
import org.netbeans.modules.remote.impl.fileoperations.spi.FilesystemInterceptorProvider;
81
import org.netbeans.modules.remote.impl.fileoperations.spi.FilesystemInterceptorProvider;
81
import org.netbeans.modules.remote.impl.fileoperations.spi.FilesystemInterceptorProvider.FilesystemInterceptor;
82
import org.netbeans.modules.remote.impl.fileoperations.spi.FilesystemInterceptorProvider.FilesystemInterceptor;
82
import org.netbeans.modules.remote.spi.FileSystemProvider;
83
import org.netbeans.modules.remote.spi.FileSystemProvider;
84
import org.netbeans.modules.remote.spi.WarmapHintProvider;
83
import org.openide.filesystems.FileChangeListener;
85
import org.openide.filesystems.FileChangeListener;
84
import org.openide.filesystems.FileEvent;
86
import org.openide.filesystems.FileEvent;
85
import org.openide.filesystems.FileLock;
87
import org.openide.filesystems.FileLock;
Lines 89-94 Link Here
89
import org.openide.util.Exceptions;
91
import org.openide.util.Exceptions;
90
import org.openide.util.NbBundle;
92
import org.openide.util.NbBundle;
91
import org.openide.util.Parameters;
93
import org.openide.util.Parameters;
94
import static java.nio.file.StandardCopyOption.*;
95
import java.util.zip.ZipInputStream;
96
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory;
92
97
93
/**
98
/**
94
 *
99
 *
Lines 1466-1473 Link Here
1466
        }
1471
        }
1467
    }
1472
    }
1468
1473
1474
    void setWarmupZip(File zip) {
1475
        getCache().mkdirs();
1476
        try {
1477
            RemoteFileSystemUtils.unpackZipFile(zip, getCache());
1478
        } catch (IOException ex) {
1479
            RemoteLogger.fine(ex);
1480
        }
1481
    }
1482
    
1469
    private boolean ensureChildSyncFromZip(RemotePlainFile child) {
1483
    private boolean ensureChildSyncFromZip(RemotePlainFile child) {
1470
        File file = new File(getCache(), RemoteFileSystem.CACHE_ZIP_FILE_NAME);
1484
        File file = new File(getCache(), RemoteFileSystem.CACHE_ZIP_FILE_NAME);
1485
        if (!file.exists()) {
1486
            File andRemoveWarmupZip = WarmapHintProvider.getAndRemoveWarmupZip(this.getOwnerFileObject());
1487
            if (andRemoveWarmupZip != null && andRemoveWarmupZip.exists()) {
1488
                try {
1489
                    Files.move(andRemoveWarmupZip.toPath(), file.toPath(), REPLACE_EXISTING);
1490
                } catch (IOException ex) {
1491
                    ex.printStackTrace(System.err);
1492
                }
1493
            }
1494
        }
1471
        if (file.exists()) {
1495
        if (file.exists()) {
1472
            ZipFile zipFile = null;
1496
            ZipFile zipFile = null;
1473
            InputStream is = null;
1497
            InputStream is = null;
(-)a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileSystemUtils.java (+47 lines)
Lines 43-49 Link Here
43
package org.netbeans.modules.remote.impl.fs;
43
package org.netbeans.modules.remote.impl.fs;
44
44
45
import java.io.File;
45
import java.io.File;
46
import java.io.FileInputStream;
46
import java.io.FileNotFoundException;
47
import java.io.FileNotFoundException;
48
import java.io.FileOutputStream;
47
import java.io.IOException;
49
import java.io.IOException;
48
import java.io.InputStream;
50
import java.io.InputStream;
49
import java.io.OutputStream;
51
import java.io.OutputStream;
Lines 53-58 Link Here
53
import java.util.concurrent.ExecutionException;
55
import java.util.concurrent.ExecutionException;
54
import java.util.concurrent.TimeoutException;
56
import java.util.concurrent.TimeoutException;
55
import java.util.logging.Level;
57
import java.util.logging.Level;
58
import java.util.zip.ZipEntry;
59
import java.util.zip.ZipInputStream;
56
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
60
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
57
import org.netbeans.modules.nativeexecution.api.HostInfo;
61
import org.netbeans.modules.nativeexecution.api.HostInfo;
58
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
62
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
Lines 389-394 Link Here
389
    public static void reportUnexpectedTimeout(TimeoutException ex, String path) {
393
    public static void reportUnexpectedTimeout(TimeoutException ex, String path) {
390
        RemoteLogger.getInstance().log(Level.FINE, "Unexpected TimeoutException with zero timeout " + path, ex);
394
        RemoteLogger.getInstance().log(Level.FINE, "Unexpected TimeoutException with zero timeout " + path, ex);
391
    }
395
    }
396
    
397
    /**
398
     * Unpacks a ZIP file to disk. All entries are unpacked, even
399
     * {@code META-INF/MANIFEST.MF} if present. Parent directories are created
400
     * as needed (even if not mentioned in the ZIP); empty ZIP directories are
401
     * created too. Existing files are overwritten.
402
     *
403
     * @param zip a ZIP file
404
     * @param dir the base directory in which to unpack (need not yet exist)
405
     * @throws IOException in case of problems
406
     */
407
    public static void unpackZipFile(File zip, File dir) throws IOException {
408
        byte[] buf = new byte[8192];
409
        InputStream is = new FileInputStream(zip);
410
        try {
411
            ZipInputStream zis = new ZipInputStream(is);
412
            ZipEntry entry;
413
            while ((entry = zis.getNextEntry()) != null) {
414
                String name = entry.getName();
415
                int slash = name.lastIndexOf('/');                
416
                if (slash >= 0) {
417
                    File baseDir = new File(dir, name.substring(0, slash).replace('/', File.separatorChar));
418
                    if (!baseDir.isDirectory() && !baseDir.mkdirs()) {
419
                        throw new IOException("could not make " + baseDir);
420
                    }
421
                }                
422
                if (slash != name.length() - 1) {
423
                    File f = new File(dir, name.replace('/', File.separatorChar));
424
                    OutputStream os = new FileOutputStream(f);
425
                    try {
426
                        int read;
427
                        while ((read = zis.read(buf)) != -1) {
428
                            os.write(buf, 0, read);
429
                        }
430
                    } finally {
431
                        os.close();
432
                    }
433
                }
434
            }
435
        } finally {
436
            is.close();
437
        }
438
    }    
392
439
393
    // <editor-fold desc="Copy-pastes from FileObject and/or FileUtil" defaultstate="collapsed">
440
    // <editor-fold desc="Copy-pastes from FileObject and/or FileUtil" defaultstate="collapsed">
394
441
(-)13ee6f16f094 (+64 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright (c) 2016 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
package org.netbeans.modules.remote.impl.fs;
41
42
import java.io.File;
43
import org.netbeans.modules.remote.spi.WarmapAdvisor;
44
import org.openide.filesystems.FileObject;
45
import org.openide.util.lookup.ServiceProvider;
46
47
/**
48
 *
49
 * @author vkvashin
50
 */
51
@ServiceProvider(service = WarmapAdvisor.class)
52
public class WarmapAdvisorimpl implements WarmapAdvisor {
53
54
    @Override
55
    public void setWarmupZip(FileObject directory, File zip) {
56
        if (directory instanceof RemoteFileObject) {
57
            RemoteFileObjectBase impl = ((RemoteFileObject) directory).getImplementor();
58
            if (impl instanceof RemoteDirectory) {
59
                ((RemoteDirectory) impl).setWarmupZip(zip);
60
            }
61
        }
62
    }
63
    
64
}
(-)13ee6f16f094 (+53 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright (c) 2016 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
package org.netbeans.modules.remote.spi;
41
42
import java.io.File;
43
import java.util.Map;
44
import java.util.concurrent.ConcurrentHashMap;
45
import org.openide.filesystems.FileObject;
46
47
/**
48
 *
49
 * @author vkvashin
50
 */
51
public interface WarmapAdvisor {
52
    void setWarmupZip(FileObject directory, File zip);
53
}
(-)13ee6f16f094 (+67 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright (c) 2016 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
package org.netbeans.modules.remote.spi;
41
42
import java.io.File;
43
import java.util.Locale;
44
import java.util.Map;
45
import java.util.concurrent.ConcurrentHashMap;
46
import org.openide.filesystems.FileObject;
47
import org.openide.util.Lookup;
48
49
/**
50
 *
51
 * @author vkvashin
52
 */
53
public class WarmapHintProvider {
54
55
    private static final Map<FileObject, File> zips = new ConcurrentHashMap<>();
56
    
57
    public static void setWarmupZip(FileObject directory, File zip) {
58
        zips.put(directory, zip);
59
        for (WarmapAdvisor wa : Lookup.getDefault().lookupAll(WarmapAdvisor.class)) {
60
            wa.setWarmupZip(directory, zip);
61
        }
62
    }
63
    
64
    public static File getAndRemoveWarmupZip(FileObject directory) {     
65
        return zips.remove(directory);
66
    }
67
}

Return to bug 247673