Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 177461
Collapse All | Expand All

(-)core.startup/nbproject/project.xml (-1 / +1 lines)
 Lines 60-66    Link Here 
60
                    <build-prerequisite/>
60
                    <build-prerequisite/>
61
                    <compile-dependency/>
61
                    <compile-dependency/>
62
                    <run-dependency>
62
                    <run-dependency>
63
                        <specification-version>7.25</specification-version>
63
                        <specification-version>7.34</specification-version>
64
                    </run-dependency>
64
                    </run-dependency>
65
                </dependency>
65
                </dependency>
66
                <dependency>
66
                <dependency>
(-)core.startup/src/org/netbeans/core/startup/layers/ArchiveURLMapper.java (-7 / +2 lines)
 Lines 159-171    Link Here 
159
        if (reference == null || (jfs = reference.get()) == null) {
159
        if (reference == null || (jfs = reference.get()) == null) {
160
            jfs = findJarFileSystemInRepository(file);
160
            jfs = findJarFileSystemInRepository(file);
161
            if (jfs == null) {
161
            if (jfs == null) {
162
                try {
162
                File aRoot = FileUtil.normalizeFile(file);
163
                    jfs = new JarFileSystem();
163
                jfs = new JarFileSystem(aRoot);
164
                    File aRoot = FileUtil.normalizeFile(file);
165
                    jfs.setJarFile(aRoot);
166
                } catch (PropertyVetoException pve) {
167
                    throw new AssertionError(pve);
168
                }
169
            }
164
            }
170
            mountRoots.put(file, new JFSReference(jfs));
165
            mountRoots.put(file, new JFSReference(jfs));
171
        }
166
        }
(-)openide.filesystems/apichanges.xml (+17 lines)
 Lines 46-51    Link Here 
46
        <apidef name="filesystems">Filesystems API</apidef>
46
        <apidef name="filesystems">Filesystems API</apidef>
47
    </apidefs>
47
    </apidefs>
48
    <changes>
48
    <changes>
49
          <change id="JarFileSystem-constructor-file">
50
             <api name="filesystems"/>
51
             <summary>Effective constructor for JarFileSystem</summary>
52
             <version major="7" minor="34"/>
53
             <date day="26" month="1" year="2010"/>
54
             <author login="jtulach"/>
55
             <compatibility addition="yes" binary="compatible" source="compatible" semantic="compatible" deprecation="no" deletion="no" modification="no"/>
56
             <description>
57
                 <p>
58
                     New constructor for <code>JarFileSystem</code>
59
                     that initializes everything without opening the underlaying
60
                     JAR file.
61
                 </p>
62
             </description>
63
             <class package="org.openide.filesystems" name="JarFileSystem"/>
64
             <issue number="177461"/>
65
         </change>
49
          <change id="recursive-listener">
66
          <change id="recursive-listener">
50
             <api name="filesystems"/>
67
             <api name="filesystems"/>
51
             <summary>Support for recursive listeners</summary>
68
             <summary>Support for recursive listeners</summary>
(-)openide.filesystems/nbproject/project.properties (-1 / +1 lines)
 Lines 44-47    Link Here 
44
javadoc.main.page=org/openide/filesystems/doc-files/api.html
44
javadoc.main.page=org/openide/filesystems/doc-files/api.html
45
javadoc.arch=${basedir}/arch.xml
45
javadoc.arch=${basedir}/arch.xml
46
javadoc.apichanges=${basedir}/apichanges.xml
46
javadoc.apichanges=${basedir}/apichanges.xml
47
spec.version.base=7.33.0
47
spec.version.base=7.34.0
(-)openide.filesystems/src/org/openide/filesystems/JarFileSystem.java (-26 / +70 lines)
 Lines 71-76    Link Here 
71
import java.util.logging.Level;
71
import java.util.logging.Level;
72
import java.util.logging.Logger;
72
import java.util.logging.Logger;
73
import java.util.zip.ZipException;
73
import java.util.zip.ZipException;
74
import org.openide.util.Exceptions;
74
import org.openide.util.NbBundle;
75
import org.openide.util.NbBundle;
75
import org.openide.util.RequestProcessor;
76
import org.openide.util.RequestProcessor;
76
import org.openide.util.Utilities;
77
import org.openide.util.Utilities;
 Lines 88-94    Link Here 
88
    static final long serialVersionUID = -98124752801761145L;
89
    static final long serialVersionUID = -98124752801761145L;
89
90
90
    /** One request proccesor shared for all instances of JarFileSystem*/
91
    /** One request proccesor shared for all instances of JarFileSystem*/
91
    private static RequestProcessor req = new RequestProcessor("JarFs - modification watcher", 1, false, false); // NOI18N
92
    private static final RequestProcessor req = new RequestProcessor("JarFs - modification watcher", 1, false, false); // NOI18N
92
93
93
    /** Controlls the LocalFileSystem's automatic refresh.
94
    /** Controlls the LocalFileSystem's automatic refresh.
94
    * If the refresh time interval is set from the System.property, than this value is used.
95
    * If the refresh time interval is set from the System.property, than this value is used.
 Lines 171-176    Link Here 
171
        setCapability(cap);
172
        setCapability(cap);
172
    }
173
    }
173
174
175
    /** Creates new JAR for a given JAR file. This constructor
176
     * behaves basically like:
177
     * <pre>
178
     * JarFileSystem fs = new JarFileSystem();
179
     * fs.setJarFile(jar);
180
     * </pre>
181
     * but it is more effective in some situations. It does not open and
182
     * read the content of the jar file immediately. Instead
183
     * it waits until somebody asks for resources from inside the JAR.
184
     *
185
     * @param jar location of the JAR file
186
     * @since 7.34
187
     */
188
    public JarFileSystem(File jar) throws IOException {
189
        this();
190
        try {
191
            setJarFile(jar, true, false);
192
        } catch (PropertyVetoException ex) {
193
            // cannot happen, setSystemName can throw the exception only
194
            // if the filesystem is already in Repository, which this one
195
            // is not.
196
            throw (IOException)new IOException().initCause(ex);
197
        }
198
    }
199
174
    /* Creates Reference. In FileSystem, which subclasses AbstractFileSystem, you can overload method
200
    /* Creates Reference. In FileSystem, which subclasses AbstractFileSystem, you can overload method
175
     * createReference(FileObject fo) to achieve another type of Reference (weak, strong etc.)
201
     * createReference(FileObject fo) to achieve another type of Reference (weak, strong etc.)
176
     * @param fo is FileObject. It`s reference yourequire to get.
202
     * @param fo is FileObject. It`s reference yourequire to get.
 Lines 233-239    Link Here 
233
    * @throws IOException if the file is not valid
259
    * @throws IOException if the file is not valid
234
    */
260
    */
235
    public void setJarFile(final File aRoot) throws IOException, PropertyVetoException {
261
    public void setJarFile(final File aRoot) throws IOException, PropertyVetoException {
236
        setJarFile(aRoot, true);
262
        setJarFile(aRoot, true, true);
237
    }
263
    }
238
    
264
    
239
    @SuppressWarnings("deprecation") // need to set it for compat
265
    @SuppressWarnings("deprecation") // need to set it for compat
 Lines 241-247    Link Here 
241
        setSystemName(s);
267
        setSystemName(s);
242
    }
268
    }
243
269
244
    private void setJarFile(final File aRoot, boolean refreshRoot)
270
    private void setJarFile(final File aRoot, boolean refreshRoot, boolean openJar)
245
    throws IOException, PropertyVetoException {
271
    throws IOException, PropertyVetoException {
246
        if (!aRoot.equals(FileUtil.normalizeFile(aRoot))) {
272
        if (!aRoot.equals(FileUtil.normalizeFile(aRoot))) {
247
            throw new IllegalArgumentException(
273
            throw new IllegalArgumentException(
 Lines 279-296    Link Here 
279
305
280
        JarFile tempJar = null;
306
        JarFile tempJar = null;
281
307
282
        try {
308
        if (openJar) {
283
            tempJar = new JarFile(s);
309
            try {
284
            LOGGER.log(Level.FINE, "opened: "+ System.currentTimeMillis()+ "   " + s);//NOI18N
310
                tempJar = new JarFile(s);
285
        } catch (ZipException e) {
311
                LOGGER.log(Level.FINE, "opened: "+ System.currentTimeMillis()+ "   " + s);//NOI18N
286
            throw new FSException(NbBundle.getMessage(JarFileSystem.class, "EXC_NotValidJarFile2", e.getLocalizedMessage(), s));
312
            } catch (ZipException e) {
313
                throw new FSException(NbBundle.getMessage(JarFileSystem.class, "EXC_NotValidJarFile2", e.getLocalizedMessage(), s));
314
            }
287
        }
315
        }
288
316
289
        synchronized (closeSync) {
317
        synchronized (closeSync) {
290
            _setSystemName(s);
318
            _setSystemName(s);
291
319
292
            closeCurrentRoot(false);
320
            closeCurrentRoot(false);
293
            jar = tempJar;
321
            setJar(tempJar);
294
            openRequestTime = System.currentTimeMillis();
322
            openRequestTime = System.currentTimeMillis();
295
            root = new File(s);
323
            root = new File(s);
296
324
 Lines 328-334    Link Here 
328
356
329
                    if ((f != null) && !f.equals(aRoot)) {
357
                    if ((f != null) && !f.equals(aRoot)) {
330
                        try {
358
                        try {
331
                            setJarFile(f, false);
359
                            setJarFile(f, false, true);
332
                        } catch (IOException iex) {
360
                        } catch (IOException iex) {
333
                            ExternalUtil.exception(iex);
361
                            ExternalUtil.exception(iex);
334
                        } catch (PropertyVetoException pvex) {
362
                        } catch (PropertyVetoException pvex) {
 Lines 688-705    Link Here 
688
            // 150% of time from last open request, but between CLOSE_DELAY_MIN and CLOSE_DELAY_MAX
716
            // 150% of time from last open request, but between CLOSE_DELAY_MIN and CLOSE_DELAY_MAX
689
            closeDelay = (int) Math.min(CLOSE_DELAY_MAX, Math.max(CLOSE_DELAY_MIN, (1.5 * requestPeriod)));
717
            closeDelay = (int) Math.min(CLOSE_DELAY_MAX, Math.max(CLOSE_DELAY_MIN, (1.5 * requestPeriod)));
690
718
691
            JarFile j = jar;
719
            return getJar(true);
692
693
            if (j != null) {
694
                return j;
695
            }
696
697
            if ((jar == null) && (root != null)) {
698
                jar = new JarFile(root);
699
                LOGGER.log(Level.FINE, "opened: "+ System.currentTimeMillis()+ "   " + root.getAbsolutePath());//NOI18N
700
            }
701
702
            return jar;
703
        }
720
        }
704
    }
721
    }
705
722
 Lines 724-738    Link Here 
724
        return new Runnable() {
741
        return new Runnable() {
725
                public void run() {
742
                public void run() {
726
                    synchronized (closeSync) {
743
                    synchronized (closeSync) {
727
                        if (jar != null) {
744
                    final JarFile jarFile = getJar(false);
745
                        if (jarFile != null) {
728
                            try {
746
                            try {
729
                                jar.close();
747
                                jarFile.close();
730
                                LOGGER.log(Level.FINE, "closed: "+ System.currentTimeMillis()+ "   " + root.getAbsolutePath());//NOI18N
748
                                LOGGER.log(Level.FINE, "closed: "+ System.currentTimeMillis()+ "   " + root.getAbsolutePath());//NOI18N
731
                            } catch (Exception exc) {
749
                            } catch (Exception exc) {
732
                                // ignore exception during closing, just log it
750
                                // ignore exception during closing, just log it
733
                                ExternalUtil.exception(exc);
751
                                ExternalUtil.exception(exc);
734
                            } finally {
752
                            } finally {
735
                                jar = null;
753
                                setJar(null);
736
                                closeTask = null;
754
                                closeTask = null;
737
                            }
755
                            }
738
                        }
756
                        }
 Lines 895-901    Link Here 
895
            synchronized (closeSync) {
913
            synchronized (closeSync) {
896
                j = reOpenJarFile();
914
                j = reOpenJarFile();
897
915
898
                JarEntry je = j.getJarEntry(file);
916
                JarEntry je = null;
917
                if (j != null) {
918
                    je = j.getJarEntry(file);
919
                }
899
920
900
                if (je != null) {
921
                if (je != null) {
901
                    return je;
922
                    return je;
 Lines 907-912    Link Here 
907
        return new JarEntry(file);
928
        return new JarEntry(file);
908
    }
929
    }
909
930
931
    /**
932
     * @return the jar
933
     */
934
    private JarFile getJar(boolean create) {
935
        assert Thread.holdsLock(closeSync);
936
        if (jar == null && create) {
937
            try {
938
                jar = new JarFile(root);
939
                LOGGER.log(Level.FINE, "opened: {0} {1}", new Object[]{System.currentTimeMillis(), root.getAbsolutePath()}); //NOI18N
940
            } catch (IOException ex) {
941
                Exceptions.printStackTrace(ex);
942
            }
943
        }
944
        return jar;
945
    }
946
947
    /**
948
     * @param jar the jar to set
949
     */
950
    private void setJar(JarFile jar) {
951
        this.jar = jar;
952
    }
953
910
    /** Use soft-references to not throw away the data that quickly.
954
    /** Use soft-references to not throw away the data that quickly.
911
     * JarFS if often queried for its FOs e.g. by java parser, which
955
     * JarFS if often queried for its FOs e.g. by java parser, which
912
     * leaves the references immediately.
956
     * leaves the references immediately.
(-)openide.filesystems/test/unit/src/org/openide/filesystems/JarFileSystemHidden.java (+80 lines)
Added Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
38
 */
39
40
package org.openide.filesystems;
41
42
import java.io.File;
43
import java.util.jar.JarException;
44
import org.netbeans.junit.NbTestCase;
45
46
/**
47
 *
48
 * @author Jaroslav Tulach <jtulach@netbeans.org>
49
 */
50
public class JarFileSystemHidden extends NbTestCase {
51
52
    public JarFileSystemHidden(String name) {
53
        super(name);
54
    }
55
56
    public void testLazyJarForNonExistingConstructor() throws Exception {
57
        File f = new File(getWorkDir(), "broken.jar");
58
        f.createNewFile();
59
60
        JarFileSystem fs = new JarFileSystem(f);
61
62
        assertEquals("No children", 0, fs.getRoot().getChildren().length);
63
    }
64
65
    public void testEagerJarForNonExistingSetter() throws Exception {
66
        File f = new File(getWorkDir(), "broken.jar");
67
        f.createNewFile();
68
69
        JarFileSystem fs = new JarFileSystem();
70
        try {
71
            fs.setJarFile(f);
72
            fail("This shall fail, with JarException as the file cannot be opened");
73
        } catch (FSException ex) {
74
            assertTrue(ex.getMessage(), ex.getMessage().contains("Error in JAR"));
75
        }
76
77
        assertEquals("No children", 0, fs.getRoot().getChildren().length);
78
    }
79
80
}
(-)openide.filesystems/test/unit/src/org/openide/filesystems/JarFileSystemTest.java (-1 / +2 lines)
 Lines 72-78    Link Here 
72
        /*failing tests*/
72
        /*failing tests*/
73
        suite.addTestSuite(URLMapperTestHidden.class);
73
        suite.addTestSuite(URLMapperTestHidden.class);
74
        suite.addTestSuite(URLMapperTestInternalHidden.class);
74
        suite.addTestSuite(URLMapperTestInternalHidden.class);
75
        suite.addTestSuite(FileUtilTestHidden.class);                        
75
        suite.addTestSuite(FileUtilTestHidden.class);
76
        suite.addTestSuite(JarFileSystemHidden.class);
76
        
77
        
77
        return new JarFileSystemTest(suite);
78
        return new JarFileSystemTest(suite);
78
    }
79
    }

Return to bug 177461
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo