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

(-)a/api.java/apichanges.xml (+20 lines)
Lines 73-78 made subject to such option by the copyr Link Here
73
<!-- ACTUAL CHANGES BEGIN HERE: -->
73
<!-- ACTUAL CHANGES BEGIN HERE: -->
74
74
75
<changes>
75
<changes>
76
77
        <change id="ClassPath.string">
78
            <api name="classpath"/>
79
            <summary>Interconversions with string-format classpaths</summary>
80
            <version major="1" minor="15"/>
81
            <date day="17" month="3" year="2008"/>
82
            <author login="jglick"/>
83
            <compatibility addition="yes"/>
84
            <description>
85
                <p>
86
                    <code>ClassPath.toString(PathConversionMode)</code> and
87
                    <code>ClassPathSupport.createClassPath(String)</code>
88
                    can be used to easily convert between traditional string classpaths
89
                    and NetBeans' internal representation.
90
                </p>
91
            </description>
92
            <class package="org.netbeans.api.java.classpath" name="ClassPath"/>
93
            <class package="org.netbeans.spi.java.classpath.support" name="ClassPathSupport"/>
94
            <issue number="59311"/>
95
        </change>
76
96
77
        <change id="includes-excludes.classpath">
97
        <change id="includes-excludes.classpath">
78
            <api name="classpath"/>
98
            <api name="classpath"/>
(-)a/api.java/manifest.mf (-1 / +1 lines)
Lines 1-6 Manifest-Version: 1.0 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.api.java/1
2
OpenIDE-Module: org.netbeans.api.java/1
3
OpenIDE-Module-Specification-Version: 1.14
3
OpenIDE-Module-Specification-Version: 1.15
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/java/classpath/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/java/classpath/Bundle.properties
5
AutoUpdate-Show-In-Client: false
5
AutoUpdate-Show-In-Client: false
6
6
(-)a/api.java/nbproject/project.xml (-31 / +31 lines)
Lines 47-58 made subject to such option by the copyr Link Here
47
            <code-name-base>org.netbeans.api.java</code-name-base>
47
            <code-name-base>org.netbeans.api.java</code-name-base>
48
            <module-dependencies>
48
            <module-dependencies>
49
                <dependency>
49
                <dependency>
50
                    <code-name-base>org.openide.execution</code-name-base>
51
                    <build-prerequisite/>
52
                    <compile-dependency/>
53
                    <run-dependency>
54
                        <specification-version>1.2</specification-version>
55
                    </run-dependency>
56
                </dependency>
57
                <dependency>
50
                    <code-name-base>org.openide.filesystems</code-name-base>
58
                    <code-name-base>org.openide.filesystems</code-name-base>
51
                    <build-prerequisite/>
59
                    <build-prerequisite/>
52
                    <compile-dependency/>
60
                    <compile-dependency/>
53
                    <run-dependency>
61
                    <run-dependency>
54
                        <specification-version>7.7</specification-version>
62
                        <specification-version>7.8</specification-version>
55
                    </run-dependency>
63
                    </run-dependency>
64
                </dependency>
65
                <dependency>
66
                    <code-name-base>org.openide.io</code-name-base>
67
                    <build-prerequisite/>
68
                    <compile-dependency/>
69
                    <run-dependency/>
56
                </dependency>
70
                </dependency>
57
                <dependency>
71
                <dependency>
58
                    <code-name-base>org.openide.util</code-name-base>
72
                    <code-name-base>org.openide.util</code-name-base>
Lines 62-98 made subject to such option by the copyr Link Here
62
                        <specification-version>7.8</specification-version>
76
                        <specification-version>7.8</specification-version>
63
                    </run-dependency>
77
                    </run-dependency>
64
                </dependency>
78
                </dependency>
65
                <dependency>
66
                    <code-name-base>org.openide.execution</code-name-base>
67
                    <build-prerequisite/>
68
                    <compile-dependency/>
69
                    <run-dependency>
70
                        <specification-version>1.2</specification-version>
71
                    </run-dependency>
72
                </dependency>
73
                <dependency>
74
                    <code-name-base>org.openide.io</code-name-base>
75
                    <build-prerequisite/>
76
                    <compile-dependency/>
77
                    <run-dependency/>
78
                </dependency>
79
            </module-dependencies>
79
            </module-dependencies>
80
          <test-dependencies>
80
            <test-dependencies>
81
              <test-type>
81
                <test-type>
82
                  <name>unit</name>
82
                    <name>unit</name>
83
                  <test-dependency>
83
                    <test-dependency>
84
                      <code-name-base>org.openide.util</code-name-base>
84
                        <code-name-base>org.openide.util</code-name-base>
85
                  </test-dependency>
85
                    </test-dependency>
86
                  <test-dependency>
86
                    <test-dependency>
87
                      <code-name-base>org.openide.modules</code-name-base>
87
                        <code-name-base>org.openide.modules</code-name-base>
88
                  </test-dependency>
88
                    </test-dependency>
89
                  <test-dependency>
89
                    <test-dependency>
90
                      <code-name-base>org.netbeans.modules.masterfs</code-name-base>
90
                        <code-name-base>org.netbeans.modules.masterfs</code-name-base>
91
                  </test-dependency>
91
                    </test-dependency>
92
              </test-type>
92
                </test-type>
93
              <test-type>
93
                <test-type>
94
                  <name>qa-functional</name>
94
                    <name>qa-functional</name>
95
              </test-type>
95
                </test-type>
96
            </test-dependencies>
96
            </test-dependencies>
97
            <public-packages>
97
            <public-packages>
98
                <package>org.netbeans.api.java.classpath</package>
98
                <package>org.netbeans.api.java.classpath</package>
(-)a/api.java/src/org/netbeans/api/java/classpath/ClassPath.java (-14 / +80 lines)
Lines 58-64 import java.util.Collection; Link Here
58
import java.util.Collection;
58
import java.util.Collection;
59
import java.util.Collections;
59
import java.util.Collections;
60
import java.util.HashSet;
60
import java.util.HashSet;
61
import java.util.LinkedHashSet;
62
import java.util.List;
61
import java.util.List;
63
import java.util.Map;
62
import java.util.Map;
64
import java.util.Set;
63
import java.util.Set;
Lines 76-82 import org.openide.filesystems.FileObjec Link Here
76
import org.openide.filesystems.FileObject;
75
import org.openide.filesystems.FileObject;
77
import org.openide.filesystems.FileRenameEvent;
76
import org.openide.filesystems.FileRenameEvent;
78
import org.openide.filesystems.FileStateInvalidException;
77
import org.openide.filesystems.FileStateInvalidException;
79
import org.openide.filesystems.FileSystem;
80
import org.openide.filesystems.FileUtil;
78
import org.openide.filesystems.FileUtil;
81
import org.openide.filesystems.URLMapper;
79
import org.openide.filesystems.URLMapper;
82
import org.openide.util.Exceptions;
80
import org.openide.util.Exceptions;
Lines 265-273 public final class ClassPath { Link Here
265
    private FileObject[] createRoots (final List<ClassPath.Entry> entries) {
263
    private FileObject[] createRoots (final List<ClassPath.Entry> entries) {
266
        List<FileObject> l = new ArrayList<FileObject> ();
264
        List<FileObject> l = new ArrayList<FileObject> ();
267
        for (Entry entry : entries) {
265
        for (Entry entry : entries) {
268
            RootsListener rootsListener = this.getRootsListener();
266
            RootsListener rL = this.getRootsListener();
269
            if (rootsListener != null) {
267
            if (rL != null) {
270
                rootsListener.addRoot (entry.getURL());
268
                rL.addRoot (entry.getURL());
271
            }
269
            }
272
            FileObject fo = entry.getRoot();
270
            FileObject fo = entry.getRoot();
273
            if (fo != null) {
271
            if (fo != null) {
Lines 560-567 public final class ClassPath { Link Here
560
	propSupport.firePropertyChange(event);
558
	propSupport.firePropertyChange(event);
561
    }
559
    }
562
560
563
    public String toString() {
561
    /**
564
        return "ClassPath" + entries(); // NOI18N
562
     * Policy for handling path items which cannot be converted into the desired format.
563
     * @see #toString(ClassPath.PathConversionMode)
564
     * @since org.netbeans.api.java/1 1.15
565
     */
566
    public enum PathConversionMode {
567
        /**
568
         * Drop entry silently.
569
         */
570
        SKIP,
571
        /**
572
         * Entry is dropped but a warning is logged.
573
         */
574
        WARN,
575
        /**
576
         * {@link #toString(ClassPath.PathConversionMode)} will fail with an {@link IllegalArgumentException}.
577
         */
578
        FAIL,
579
        /**
580
         * The entry is simply displayed as a URL.
581
         * Useful for debug logging or unit tests.
582
         * Used by {@link ClassPath#toString}.
583
         */
584
        PRINT,
585
    }
586
587
    /**
588
     * Render this classpath in the conventional format used by the Java launcher.
589
     * @param conversionMode policy for converting unusual entries
590
     * @return a conventionally-formatted representation of the classpath
591
     * @since org.netbeans.api.java/1 1.15
592
     * @see File#pathSeparator
593
     * @see FileUtil#archiveOrDirForURL
594
     * @see ClassPathSupport#createClassPath(String)
595
     */
596
    public String toString(PathConversionMode conversionMode) {
597
        StringBuilder b = new StringBuilder();
598
        for (Entry e : entries()) {
599
            URL u = e.getURL();
600
            File f = FileUtil.archiveOrDirForURL(u);
601
            if (f != null) {
602
                if (b.length() > 0) {
603
                    b.append(File.pathSeparatorChar);
604
                }
605
                b.append(f.getAbsolutePath());
606
            } else {
607
                switch (conversionMode) {
608
                case SKIP:
609
                    break;
610
                case PRINT:
611
                    if (b.length() > 0) {
612
                        b.append(File.pathSeparatorChar);
613
                    }
614
                    b.append(u);
615
                    break;
616
                case WARN:
617
                    LOG.warning("Encountered untranslatable classpath entry: " + u);
618
                    break;
619
                case FAIL:
620
                    throw new IllegalArgumentException("Encountered untranslatable classpath entry: " + u); // NOI18N
621
                default:
622
                    assert false : conversionMode;
623
                }
624
            }
625
        }
626
        return b.toString();
627
    }
628
629
    public @Override String toString() {
630
        return toString(PathConversionMode.PRINT);
565
    }
631
    }
566
632
567
    /**
633
    /**
Lines 623-630 public final class ClassPath { Link Here
623
         * folder.
689
         * folder.
624
         */
690
         */
625
        public boolean isValid() {
691
        public boolean isValid() {
626
            FileObject root = getRoot();
692
            FileObject r = getRoot();
627
            return root != null && root.isValid();
693
            return r != null && r.isValid();
628
        }
694
        }
629
695
630
        /**
696
        /**
Lines 688-700 public final class ClassPath { Link Here
688
         * @since org.netbeans.api.java/1 1.13
754
         * @since org.netbeans.api.java/1 1.13
689
         */
755
         */
690
        public boolean includes(FileObject file) {
756
        public boolean includes(FileObject file) {
691
            FileObject root = getRoot();
757
            FileObject r = getRoot();
692
            if (root == null) {
758
            if (r == null) {
693
                throw new IllegalArgumentException("no root in " + url);
759
                throw new IllegalArgumentException("no root in " + url);
694
            }
760
            }
695
            String path = FileUtil.getRelativePath(root, file);
761
            String path = FileUtil.getRelativePath(r, file);
696
            if (path == null) {
762
            if (path == null) {
697
                throw new IllegalArgumentException(file + " not in " + root);
763
                throw new IllegalArgumentException(file + " not in " + r);
698
            }
764
            }
699
            if (file.isFolder()) {
765
            if (file.isFolder()) {
700
                path += "/"; // NOI18N
766
                path += "/"; // NOI18N
Lines 709-715 public final class ClassPath { Link Here
709
            this.filter = filter;
775
            this.filter = filter;
710
        }
776
        }
711
777
712
        public String toString() {
778
        public @Override String toString() {
713
            return "Entry[" + url + "]"; // NOI18N
779
            return "Entry[" + url + "]"; // NOI18N
714
        }
780
        }
715
        
781
        
(-)a/api.java/src/org/netbeans/spi/java/classpath/support/ClassPathSupport.java (+22 lines)
Lines 40-45 Link Here
40
 */
40
 */
41
package org.netbeans.spi.java.classpath.support;
41
package org.netbeans.spi.java.classpath.support;
42
42
43
import java.io.File;
43
import org.netbeans.spi.java.classpath.PathResourceImplementation;
44
import org.netbeans.spi.java.classpath.PathResourceImplementation;
44
import org.netbeans.spi.java.classpath.ClassPathImplementation;
45
import org.netbeans.spi.java.classpath.ClassPathImplementation;
45
import org.netbeans.spi.java.classpath.ClassPathFactory;
46
import org.netbeans.spi.java.classpath.ClassPathFactory;
Lines 161-166 public class ClassPathSupport { Link Here
161
        return createClassPath(l);
162
        return createClassPath(l);
162
    }
163
    }
163
164
165
    /**
166
     * Convenience method to create a classpath object from a conventional string representation.
167
     * @param jvmPath a JVM-style classpath (folder or archive paths separated by {@link File#pathSeparator})
168
     * @return a corresponding classpath object
169
     * @throws IllegalArgumentException in case a path entry looks to be invalid
170
     * @since org.netbeans.api.java/1 1.15
171
     * @see FileUtil#urlForArchiveOrDir
172
     * @see ClassPath#toJVMPath
173
     */
174
    public static ClassPath createClassPath(String jvmPath) throws IllegalArgumentException {
175
        List<PathResourceImplementation> l = new ArrayList<PathResourceImplementation>();
176
        for (String piece : jvmPath.split(File.pathSeparator)) {
177
            File f = FileUtil.normalizeFile(new File(piece));
178
            URL u = FileUtil.urlForArchiveOrDir(f);
179
            if (u == null) {
180
                throw new IllegalArgumentException("Path entry looks to be invalid: " + piece); // NOI18N
181
            }
182
            l.add(createResource(u));
183
        }
184
        return createClassPath(l);
185
    }
164
186
165
    /**
187
    /**
166
     * Creates read only proxy ClassPathImplementation for given delegates.
188
     * Creates read only proxy ClassPathImplementation for given delegates.
(-)a/api.java/test/unit/src/org/netbeans/api/java/classpath/ClassPathTest.java (-2 / +31 lines)
Lines 62-68 import java.util.StringTokenizer; Link Here
62
import java.util.StringTokenizer;
62
import java.util.StringTokenizer;
63
import java.util.TreeSet;
63
import java.util.TreeSet;
64
import java.util.jar.JarOutputStream;
64
import java.util.jar.JarOutputStream;
65
import java.util.logging.Level;
65
import java.util.zip.ZipEntry;
66
import java.util.zip.ZipEntry;
67
import org.netbeans.junit.Log;
66
import org.netbeans.junit.NbTestCase;
68
import org.netbeans.junit.NbTestCase;
67
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
69
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
68
import org.netbeans.spi.java.classpath.ClassPathImplementation;
70
import org.netbeans.spi.java.classpath.ClassPathImplementation;
Lines 78-84 public class ClassPathTest extends NbTes Link Here
78
        super(testName);
80
        super(testName);
79
    }
81
    }
80
82
81
    protected void setUp() throws Exception {
83
    protected @Override void setUp() throws Exception {
82
        super.setUp();
84
        super.setUp();
83
        clearWorkDir();
85
        clearWorkDir();
84
    }
86
    }
Lines 192-197 public class ClassPathTest extends NbTes Link Here
192
     * ClassPath.entries () and classpath SPI.
194
     * ClassPath.entries () and classpath SPI.
193
     */
195
     */
194
    public void testListening() throws Exception {
196
    public void testListening() throws Exception {
197
        // XXX unreliable, would be improved by usage of TestFileUtils methods:
195
198
196
        File root_1 = new File (getBaseDir(),"root_1");
199
        File root_1 = new File (getBaseDir(),"root_1");
197
        root_1.mkdir();
200
        root_1.mkdir();
Lines 668-672 public class ClassPathTest extends NbTes Link Here
668
        return !fo.getName().contains("$");     //NOI18N
671
        return !fo.getName().contains("$");     //NOI18N
669
                
672
                
670
    }
673
    }
671
    
674
675
    public void testJVMPathConversion() throws Exception {
676
        String root = getWorkDir().toURI().toString();
677
        ClassPath cp = ClassPathSupport.createClassPath(
678
                new URL(root + "folder/"),
679
                new URL("jar:" + root + "file.zip!/"),
680
                new URL("jar:" + root + "file.zip!/subdir/"));
681
        assertEquals(massagePath("<root>/folder:<root>/file.zip"), cp.toString(ClassPath.PathConversionMode.SKIP));
682
        assertEquals(massagePath("<root>/folder:<root>/file.zip:") + "jar:" + root + "file.zip!/subdir/", cp.toString(ClassPath.PathConversionMode.PRINT));
683
        try {
684
            cp.toString(ClassPath.PathConversionMode.FAIL);
685
            fail();
686
        } catch (IllegalArgumentException x) {/* OK */}
687
        CharSequence warnings = Log.enable(ClassPath.class.getName(), Level.WARNING);
688
        assertEquals(massagePath("<root>/folder:<root>/file.zip"), cp.toString(ClassPath.PathConversionMode.WARN));
689
        assertTrue(warnings.toString(), warnings.toString().contains("subdir"));
690
691
        cp = ClassPathSupport.createClassPath(
692
                new URL(root + "folder/"),
693
                new URL("jar:" + root + "file.zip!/"));
694
        assertEquals(cp.toString(), ClassPathSupport.createClassPath(cp.toString()).toString());
695
        // XXX could also test IAE (tricky - need to have a URLMapper in Lookup, etc.)
696
    }
697
    private String massagePath(String path) throws Exception {
698
        return path.replace('/', File.separatorChar).replace(':', File.pathSeparatorChar).replace("<root>", getWorkDir().getAbsolutePath());
699
    }
700
672
}
701
}
(-)a/apisupport.project/nbproject/project.xml (-1 / +2 lines)
Lines 70-75 made subject to such option by the copyr Link Here
70
                    <compile-dependency/>
70
                    <compile-dependency/>
71
                    <run-dependency>
71
                    <run-dependency>
72
                        <release-version>1</release-version>
72
                        <release-version>1</release-version>
73
                        <specification-version>1.15</specification-version>
73
                    </run-dependency>
74
                    </run-dependency>
74
                </dependency>
75
                </dependency>
75
                <dependency>
76
                <dependency>
Lines 239-245 made subject to such option by the copyr Link Here
239
                    <build-prerequisite/>
240
                    <build-prerequisite/>
240
                    <compile-dependency/>
241
                    <compile-dependency/>
241
                    <run-dependency>
242
                    <run-dependency>
242
                        <specification-version>7.0</specification-version>
243
                        <specification-version>7.8</specification-version>
243
                    </run-dependency>
244
                    </run-dependency>
244
                </dependency>
245
                </dependency>
245
                <dependency>
246
                <dependency>
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/Evaluator.java (-20 / +1 lines)
Lines 47-54 import java.beans.PropertyChangeSupport; Link Here
47
import java.beans.PropertyChangeSupport;
47
import java.beans.PropertyChangeSupport;
48
import java.io.File;
48
import java.io.File;
49
import java.io.IOException;
49
import java.io.IOException;
50
import java.net.URI;
51
import java.net.URL;
52
import java.util.ArrayList;
50
import java.util.ArrayList;
53
import java.util.Arrays;
51
import java.util.Arrays;
54
import java.util.Collection;
52
import java.util.Collection;
Lines 494-520 final class Evaluator implements Propert Link Here
494
                    for (JavaPlatform platform : JavaPlatformManager.getDefault().getInstalledPlatforms()) {
492
                    for (JavaPlatform platform : JavaPlatformManager.getDefault().getInstalledPlatforms()) {
495
                        if (new HashSet<FileObject>(platform.getInstallFolders()).equals(Collections.singleton(homeFO))) {
493
                        if (new HashSet<FileObject>(platform.getInstallFolders()).equals(Collections.singleton(homeFO))) {
496
                            // Matching JDK is registered, so look up its real bootcp.
494
                            // Matching JDK is registered, so look up its real bootcp.
497
                            StringBuffer bootcpSB = new StringBuffer();
498
                            ClassPath boot = platform.getBootstrapLibraries();
495
                            ClassPath boot = platform.getBootstrapLibraries();
499
                            boot.removePropertyChangeListener(weakListener);
496
                            boot.removePropertyChangeListener(weakListener);
500
                            boot.addPropertyChangeListener(weakListener);
497
                            boot.addPropertyChangeListener(weakListener);
501
                            for (ClassPath.Entry entry : boot.entries()) {
498
                            bootcp = boot.toString(ClassPath.PathConversionMode.WARN);
502
                                URL u = entry.getURL();
503
                                if (u.toExternalForm().endsWith("!/")) { // NOI18N
504
                                    URL nested = FileUtil.getArchiveFile(u);
505
                                    if (nested != null) {
506
                                        u = nested;
507
                                    }
508
                                }
509
                                if ("file".equals(u.getProtocol())) { // NOI18N
510
                                    File f = new File(URI.create(u.toExternalForm()));
511
                                    if (bootcpSB.length() > 0) {
512
                                        bootcpSB.append(File.pathSeparatorChar);
513
                                    }
514
                                    bootcpSB.append(f.getAbsolutePath());
515
                                }
516
                            }
517
                            bootcp = bootcpSB.toString();
518
                            break;
499
                            break;
519
                        }
500
                        }
520
                    }
501
                    }
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/Util.java (-38 / +6 lines)
Lines 224-280 public final class Util { Link Here
224
        return to;
224
        return to;
225
    }
225
    }
226
226
227
    // CANDIDATES FOR FileUtil (#59311):
228
    
229
    /**
227
    /**
230
     * Creates a URL for a directory on disk.
228
     * @deprecated Use FileUtil#urlForArchiveOrDir instead.
231
     * Works correctly even if the directory does not currently exist.
232
     */
229
     */
233
    public static URL urlForDir(File dir) {
230
    public static URL urlForDir(File dir) {
234
        try {
231
        return FileUtil.urlForArchiveOrDir(dir);
235
            URL u = FileUtil.normalizeFile(dir).toURI().toURL();
236
            String s = u.toExternalForm();
237
            if (s.endsWith("/")) { // NOI18N
238
                return u;
239
            } else {
240
                return new URL(s + "/"); // NOI18N
241
            }
242
        } catch (MalformedURLException e) {
243
            throw new AssertionError(e);
244
        }
245
    }
232
    }
246
    
233
    
247
    /**
234
    /**
248
     * Creates a URL for the root of a JAR on disk.
235
     * @deprecated Use FileUtil#urlForArchiveOrDir instead.
249
     */
236
     */
250
    public static URL urlForJar(File jar) {
237
    public static URL urlForJar(File jar) {
251
        try {
238
        return FileUtil.urlForArchiveOrDir(jar);
252
            return FileUtil.getArchiveRoot(FileUtil.normalizeFile(jar).toURI().toURL());
253
        } catch (MalformedURLException e) {
254
            throw new AssertionError(e);
255
        }
256
    }
239
    }
257
    
240
    
258
    /**
241
    /**
259
     * Creates a URL for a directory on disk or the root of a JAR.
242
     * @deprecated Use FileUtil#urlForArchiveOrDir instead.
260
     * Works correctly whether or not the directory or JAR currently exists.
261
     * Detects whether the file is supposed to be a directory or a JAR.
262
     */
243
     */
263
    public static URL urlForDirOrJar(File location) {
244
    public static URL urlForDirOrJar(File location) {
264
        try {
245
        return FileUtil.urlForArchiveOrDir(location);
265
            URL u = FileUtil.normalizeFile(location).toURI().toURL();
266
            if (FileUtil.isArchiveFile(u)) {
267
                u = FileUtil.getArchiveRoot(u);
268
            } else {
269
                String us = u.toExternalForm();
270
                if (!us.endsWith("/")) { // NOI18N
271
                    u = new URL(us + "/"); // NOI18N
272
                }
273
            }
274
            return u;
275
        } catch (MalformedURLException e) {
276
            throw new AssertionError(e);
277
        }
278
    }
246
    }
279
    
247
    
280
    /**
248
    /**
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/ui/platform/PlatformComponentFactory.java (-10 / +2 lines)
Lines 45-51 import java.awt.Component; Link Here
45
import java.awt.Component;
45
import java.awt.Component;
46
import java.io.File;
46
import java.io.File;
47
import java.io.IOException;
47
import java.io.IOException;
48
import java.net.URI;
49
import java.net.URL;
48
import java.net.URL;
50
import java.text.Collator;
49
import java.text.Collator;
51
import java.util.Arrays;
50
import java.util.Arrays;
Lines 501-515 public final class PlatformComponentFact Link Here
501
        public @Override Component getListCellRendererComponent(JList list, Object value,
500
        public @Override Component getListCellRendererComponent(JList list, Object value,
502
                int index, boolean isSelected, boolean cellHasFocus) {
501
                int index, boolean isSelected, boolean cellHasFocus) {
503
            URL u = (URL) value;
502
            URL u = (URL) value;
504
            String text = u.toExternalForm();
503
            File f = FileUtil.archiveOrDirForURL(u);
505
            if (u.getProtocol().equals("file")) { // NOI18N
504
            String text = f != null ? f.getAbsolutePath() : u.toString();
506
                text = new File(URI.create(u.toExternalForm())).getAbsolutePath();
507
            } else if (u.getProtocol().equals("jar")) { // NOI18N
508
                URL baseU = FileUtil.getArchiveFile(u);
509
                if (u.equals(FileUtil.getArchiveRoot(baseU)) && baseU.getProtocol().equals("file")) { // NOI18N
510
                    text = new File(URI.create(baseU.toExternalForm())).getAbsolutePath();
511
                }
512
            }
513
            return super.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus);
505
            return super.getListCellRendererComponent(list, text, index, isSelected, cellHasFocus);
514
        }
506
        }
515
    }
507
    }
(-)a/apisupport.project/src/org/netbeans/modules/apisupport/project/universe/NbPlatform.java (-16 / +3 lines)
Lines 65-73 import java.util.TreeSet; Link Here
65
import java.util.TreeSet;
65
import java.util.TreeSet;
66
import java.util.jar.JarFile;
66
import java.util.jar.JarFile;
67
import java.util.zip.ZipEntry;
67
import java.util.zip.ZipEntry;
68
import org.netbeans.api.java.classpath.ClassPath;
68
import org.netbeans.api.project.ProjectManager;
69
import org.netbeans.api.project.ProjectManager;
69
import org.netbeans.modules.apisupport.project.ManifestManager;
70
import org.netbeans.modules.apisupport.project.ManifestManager;
70
import org.netbeans.modules.apisupport.project.Util;
71
import org.netbeans.modules.apisupport.project.Util;
72
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
71
import org.netbeans.spi.project.support.ant.EditableProperties;
73
import org.netbeans.spi.project.support.ant.EditableProperties;
72
import org.netbeans.spi.project.support.ant.PropertyUtils;
74
import org.netbeans.spi.project.support.ant.PropertyUtils;
73
import org.openide.ErrorManager;
75
import org.openide.ErrorManager;
Lines 669-690 public final class NbPlatform { Link Here
669
    }
671
    }
670
    
672
    
671
    static String urlsToAntPath(final URL[] urls) {
673
    static String urlsToAntPath(final URL[] urls) {
672
        StringBuffer path = new StringBuffer();
674
        return ClassPathSupport.createClassPath(urls).toString(ClassPath.PathConversionMode.WARN);
673
        for (int i = 0; i < urls.length; i++) {
674
            if (urls[i].getProtocol().equals("jar")) { // NOI18N
675
                path.append(urlToAntPath(FileUtil.getArchiveFile(urls[i])));
676
            } else {
677
                path.append(urlToAntPath(urls[i]));
678
            }
679
            if (i != urls.length - 1) {
680
                path.append(':'); // NOI18N
681
            }
682
        }
683
        return path.toString();
684
    }
685
    
686
    private static String urlToAntPath(final URL url) {
687
        return new File(URI.create(url.toExternalForm())).getAbsolutePath();
688
    }
675
    }
689
    
676
    
690
    private void putGlobalProperty(final String key, final String value) throws IOException {
677
    private void putGlobalProperty(final String key, final String value) throws IOException {
(-)a/java.api.common/nbproject/project.xml (-1 / +1 lines)
Lines 89-95 Link Here
89
                    <build-prerequisite/>
89
                    <build-prerequisite/>
90
                    <compile-dependency/>
90
                    <compile-dependency/>
91
                    <run-dependency>
91
                    <run-dependency>
92
                        <specification-version>7.4</specification-version>
92
                        <specification-version>7.8</specification-version>
93
                    </run-dependency>
93
                    </run-dependency>
94
                </dependency>
94
                </dependency>
95
                <dependency>
95
                <dependency>
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/classpath/j2ee/BaseClassPathSupport.java (-5 / +1 lines)
Lines 107-117 abstract class BaseClassPathSupport<T ex Link Here
107
            case LIBRARY:
107
            case LIBRARY:
108
                List<URL> roots = item.getLibrary().getContent("classpath"); // NOI18N
108
                List<URL> roots = item.getLibrary().getContent("classpath"); // NOI18N
109
                for (URL rootUrl : roots) {
109
                for (URL rootUrl : roots) {
110
                    FileObject root = URLMapper.findFileObject(rootUrl);
110
                    File f = FileUtil.archiveOrDirForURL(rootUrl);
111
                    if ("jar".equals(rootUrl.getProtocol())) { // NOI18N
112
                        root = FileUtil.getArchiveFile(root);
113
                    }
114
                    File f = FileUtil.toFile(root);
115
                    if (f != null) {
111
                    if (f != null) {
116
                        if (f.isFile()) {
112
                        if (f.isFile()) {
117
                            files.add(f);
113
                            files.add(f);
(-)a/java.j2seproject/nbproject/project.xml (-1 / +1 lines)
Lines 247-253 made subject to such option by the copyr Link Here
247
                    <build-prerequisite/>
247
                    <build-prerequisite/>
248
                    <compile-dependency/>
248
                    <compile-dependency/>
249
                    <run-dependency>
249
                    <run-dependency>
250
                        <specification-version>6.2</specification-version>
250
                        <specification-version>7.8</specification-version>
251
                    </run-dependency>
251
                    </run-dependency>
252
                </dependency>
252
                </dependency>
253
                <dependency>
253
                <dependency>
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProjectUtil.java (-5 / +3 lines)
Lines 132-142 public class J2SEProjectUtil { Link Here
132
     * @throws MalformedURLException if the URL cannot be created
132
     * @throws MalformedURLException if the URL cannot be created
133
     */
133
     */
134
    public static URL getRootURL (File root, String offset) throws MalformedURLException {
134
    public static URL getRootURL (File root, String offset) throws MalformedURLException {
135
        URL url = root.toURI().toURL();
135
        URL url = FileUtil.urlForArchiveOrDir(root);
136
        if (FileUtil.isArchiveFile(url)) {
136
        if (url == null) {
137
            url = FileUtil.getArchiveRoot(url);
137
            throw new IllegalArgumentException(root.getAbsolutePath());
138
        } else if (!root.exists()) {
139
            url = new URL(url.toExternalForm() + "/"); // NOI18N
140
        }
138
        }
141
        if (offset != null) {
139
        if (offset != null) {
142
            assert offset.endsWith("/");    //NOI18N
140
            assert offset.endsWith("/");    //NOI18N
(-)a/java.project/nbproject/project.xml (-1 / +1 lines)
Lines 167-173 made subject to such option by the copyr Link Here
167
                    <build-prerequisite/>
167
                    <build-prerequisite/>
168
                    <compile-dependency/>
168
                    <compile-dependency/>
169
                    <run-dependency>
169
                    <run-dependency>
170
                        <specification-version>6.2</specification-version>
170
                        <specification-version>7.8</specification-version>
171
                    </run-dependency>
171
                    </run-dependency>
172
                </dependency>
172
                </dependency>
173
                <dependency>
173
                <dependency>
(-)a/java.project/src/org/netbeans/modules/java/project/ExtraProjectJavadocForBinaryQueryImpl.java (-12 / +5 lines)
Lines 146-163 public final class ExtraProjectJavadocFo Link Here
146
                String val = entry.getKey().substring(REF_START.length());
146
                String val = entry.getKey().substring(REF_START.length());
147
                String sourceKey = JAVADOC_START + val;
147
                String sourceKey = JAVADOC_START + val;
148
                String source = props.get(sourceKey);
148
                String source = props.get(sourceKey);
149
                try {
149
                File bin = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), entry.getValue());
150
                    File bin = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), entry.getValue());
150
                URL binURL = FileUtil.urlForArchiveOrDir(bin);
151
                    URL binURL = bin.toURI().toURL();
151
                if (source != null && binURL != null) {
152
                    if (FileUtil.isArchiveFile(binURL)) {
152
                    File src = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), source);
153
                        binURL = FileUtil.getArchiveRoot(binURL);
153
                    result.put(binURL, src.toURI());
154
                    }
155
                    if (source != null) {
156
                        File src = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), source);
157
                        result.put(binURL, src.toURI());
158
                    } 
159
                } catch (MalformedURLException ex) {
160
                    Exceptions.printStackTrace(ex);
161
                }
154
                }
162
            }
155
            }
163
        }
156
        }
(-)a/java.project/src/org/netbeans/modules/java/project/ExtraProjectSourceForBinaryQueryImpl.java (-11 / +4 lines)
Lines 150-166 public final class ExtraProjectSourceFor Link Here
150
                String sourceKey = SOURCE_START + val;
150
                String sourceKey = SOURCE_START + val;
151
                String source = props.get(sourceKey);
151
                String source = props.get(sourceKey);
152
                File bin = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), entry.getValue());
152
                File bin = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), entry.getValue());
153
                try {
153
                URL binURL = FileUtil.urlForArchiveOrDir(bin);
154
                    URL binURL = bin.toURI().toURL();
154
                if (source != null && binURL != null) {
155
                    if (FileUtil.isArchiveFile(binURL)) {
155
                    File src = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), source);
156
                        binURL = FileUtil.getArchiveRoot(binURL);
156
                    result.put(binURL, src.toURI());
157
                    }
158
                    if (source != null) {
159
                        File src = PropertyUtils.resolveFile(FileUtil.toFile(helper.getProjectDirectory()), source);
160
                        result.put(binURL, src.toURI());
161
                    } 
162
                } catch (MalformedURLException ex) {
163
                    Exceptions.printStackTrace(ex);
164
                }
157
                }
165
            }
158
            }
166
        }
159
        }
(-)a/java.project/src/org/netbeans/modules/java/project/JavaAntLogger.java (-11 / +3 lines)
Lines 294-310 public final class JavaAntLogger extends Link Here
294
            while (tok.hasMoreTokens()) {
294
            while (tok.hasMoreTokens()) {
295
                String binrootS = tok.nextToken();
295
                String binrootS = tok.nextToken();
296
                File f = FileUtil.normalizeFile(new File(binrootS));
296
                File f = FileUtil.normalizeFile(new File(binrootS));
297
                URL binroot;
297
                URL binroot = FileUtil.urlForArchiveOrDir(f);
298
                try {
298
                if (binroot == null) {
299
                    binroot = f.toURI().toURL();
299
                    continue;
300
                } catch (MalformedURLException e) {
301
                    throw new AssertionError(e);
302
                }
303
                if (FileUtil.isArchiveFile(binroot)) {
304
                    URL root = FileUtil.getArchiveRoot(binroot);
305
                    if (root != null) {
306
                        binroot = root;
307
                    }
308
                }
300
                }
309
                FileObject[] someRoots = SourceForBinaryQuery.findSourceRoots(binroot).getRoots();
301
                FileObject[] someRoots = SourceForBinaryQuery.findSourceRoots(binroot).getRoots();
310
                data.classpathSourceRoots.addAll(Arrays.asList(someRoots));
302
                data.classpathSourceRoots.addAll(Arrays.asList(someRoots));
(-)a/java.project/src/org/netbeans/spi/java/project/classpath/support/ProjectClassPathImplementation.java (-20 / +5 lines)
Lines 45-64 import java.beans.PropertyChangeListener Link Here
45
import java.beans.PropertyChangeListener;
45
import java.beans.PropertyChangeListener;
46
import java.beans.PropertyChangeSupport;
46
import java.beans.PropertyChangeSupport;
47
import java.io.File;
47
import java.io.File;
48
import java.net.MalformedURLException;
49
import java.net.URL;
48
import java.net.URL;
50
import java.util.ArrayList;
49
import java.util.ArrayList;
51
import java.util.Arrays;
50
import java.util.Arrays;
52
import java.util.Collections;
51
import java.util.Collections;
53
import java.util.List;
52
import java.util.List;
54
import java.util.concurrent.atomic.AtomicBoolean;
53
import java.util.concurrent.atomic.AtomicBoolean;
54
import java.util.logging.Logger;
55
import org.netbeans.api.project.ProjectManager;
55
import org.netbeans.api.project.ProjectManager;
56
import org.netbeans.spi.java.classpath.ClassPathImplementation;
56
import org.netbeans.spi.java.classpath.ClassPathImplementation;
57
import org.netbeans.spi.java.classpath.PathResourceImplementation;
57
import org.netbeans.spi.java.classpath.PathResourceImplementation;
58
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
58
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
59
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
59
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
60
import org.netbeans.spi.project.support.ant.PropertyUtils;
60
import org.netbeans.spi.project.support.ant.PropertyUtils;
61
import org.openide.ErrorManager;
62
import org.openide.filesystems.FileUtil;
61
import org.openide.filesystems.FileUtil;
63
import org.openide.util.WeakListeners;
62
import org.openide.util.WeakListeners;
64
63
Lines 137-161 final class ProjectClassPathImplementati Link Here
137
            if (prop != null) {
136
            if (prop != null) {
138
                for (String piece : PropertyUtils.tokenizePath(prop)) {
137
                for (String piece : PropertyUtils.tokenizePath(prop)) {
139
                    File f = PropertyUtils.resolveFile(this.projectFolder, piece);
138
                    File f = PropertyUtils.resolveFile(this.projectFolder, piece);
140
                    try {
139
                    URL entry = FileUtil.urlForArchiveOrDir(f);
141
                        URL entry = f.toURI().toURL();
140
                    if (entry != null) {
142
                        if (FileUtil.isArchiveFile(entry) || (f.isFile() && f.length()<4)) {    //XXX: Not yet closed archive file
143
                            entry = FileUtil.getArchiveRoot(entry);
144
                        } else if (!f.exists()) {
145
                            // if file does not exist (e.g. build/classes folder
146
                            // was not created yet) then corresponding File will
147
                            // not be ended with slash. Fix that.
148
                            assert !entry.toExternalForm().endsWith("/") : f; // NOI18N
149
                            entry = new URL(entry.toExternalForm() + "/"); // NOI18N
150
                        }
151
                        else if (f.isFile()) {
152
                            ErrorManager.getDefault().log(ErrorManager.ERROR,"ProjectClassPathImplementation: file: "+f.getAbsolutePath()
153
                            +" is not a valid archive file.");   //NOI18N
154
                            continue;
155
                        }
156
                        result.add(ClassPathSupport.createResource(entry));
141
                        result.add(ClassPathSupport.createResource(entry));
157
                    } catch (MalformedURLException mue) {
142
                    } else {
158
                        assert false : mue;
143
                        Logger.getLogger(ProjectClassPathImplementation.class.getName()).warning(f + " does not look like a valid archive file");
159
                    }
144
                    }
160
                }
145
                }
161
            }
146
            }
(-)a/openide.filesystems/apichanges.xml (+16 lines)
Lines 46-51 made subject to such option by the copyr 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="FileUtil.urlForArchiveOrDir.archiveOrDirForURL">
50
            <api name="filesystems"/>
51
            <summary>Added methods to interconvert URLs and traditional path entries</summary>
52
            <version major="7" minor="8"/>
53
            <date day="17" month="3" year="2008"/>
54
            <author login="jglick"/>
55
            <compatibility addition="yes"/>
56
            <description>
57
                <p>
58
                    Added methods <code>urlForArchiveOrDir</code> and <code>archiveOrDirForURL</code>
59
                    to <code>FileUtil</code> to make it easier to work with classpaths.
60
                </p>
61
            </description>
62
            <class package="org.openide.filesystems" name="FileUtil"/>
63
            <issue number="59311"/>
64
        </change>
49
        <change id="FileUtil.addFileChangeListener">
65
        <change id="FileUtil.addFileChangeListener">
50
            <api name="filesystems"/>
66
            <api name="filesystems"/>
51
            <summary>Add methods: addFileChangeListener, removeFileChangeListener, refreshAll</summary>
67
            <summary>Add methods: addFileChangeListener, removeFileChangeListener, refreshAll</summary>
(-)a/openide.filesystems/manifest.mf (-1 / +1 lines)
Lines 1-5 Manifest-Version: 1.0 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.filesystems
2
OpenIDE-Module: org.openide.filesystems
3
OpenIDE-Module-Specification-Version: 7.7
3
OpenIDE-Module-Specification-Version: 7.8
4
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
5
5
(-)a/openide.filesystems/src/org/openide/filesystems/FileUtil.java (+49 lines)
Lines 1683-1688 public final class FileUtil extends Obje Link Here
1683
    }
1683
    }
1684
1684
1685
    /**
1685
    /**
1686
     * Convert a file such as would be shown in a classpath entry into a proper folder URL.
1687
     * If the file looks to represent a directory, a <code>file</code> URL will be created.
1688
     * If it looks to represent a ZIP archive, a <code>jar</code> URL will be created.
1689
     * @param entry a file or directory name
1690
     * @return an appropriate classpath URL which will always end in a slash (<samp>/</samp>),
1691
     *         or null for an existing file which does not look like a valid archive
1692
     * @since org.openide.filesystems 7.8
1693
     */
1694
    public static URL urlForArchiveOrDir(File entry) {
1695
        try {
1696
            URL u = entry.toURI().toURL();
1697
            if (isArchiveFile(u) || entry.isFile() && entry.length() < 4) {
1698
                return getArchiveRoot(u);
1699
            } else if (entry.isDirectory()) {
1700
                return u;
1701
            } else if (!entry.exists()) {
1702
                assert !u.toString().endsWith("/") : u;
1703
                return new URL(u + "/"); // NOI18N
1704
            } else {
1705
                return null;
1706
            }
1707
        } catch (MalformedURLException x) {
1708
            assert false : x;
1709
            return null;
1710
        }
1711
    }
1712
1713
    /**
1714
     * Convert a classpath-type URL to a corresponding file.
1715
     * If it is a <code>jar</code> URL representing the root folder of a local disk archive,
1716
     * that archive file will be returned.
1717
     * If it is a <code>file</code> URL representing a local disk folder,
1718
     * that folder will be returned.
1719
     * @param entry a classpath entry or similar URL
1720
     * @return a corresponding file, or null for e.g. a network URL or non-root JAR folder entry
1721
     * @since org.openide.filesystems 7.8
1722
     */
1723
    public static File archiveOrDirForURL(URL entry) {
1724
        String u = entry.toString();
1725
        if (u.startsWith("jar:file:") && u.endsWith("!/")) { // NOI18N
1726
            return new File(URI.create(u.substring(4, u.length() - 2)));
1727
        } else if (u.startsWith("file:")) { // NOI18N
1728
            return new File(URI.create(u));
1729
        } else {
1730
            return null;
1731
        }
1732
    }
1733
1734
    /**
1686
     * Make sure that a JFileChooser does not traverse symlinks on Unix.
1735
     * Make sure that a JFileChooser does not traverse symlinks on Unix.
1687
     * @param chooser a file chooser
1736
     * @param chooser a file chooser
1688
     * @param currentDirectory if not null, a file to set as the current directory
1737
     * @param currentDirectory if not null, a file to set as the current directory
(-)a/openide.filesystems/src/org/openide/filesystems/URLMapper.java (-6 / +9 lines)
Lines 100-105 public abstract class URLMapper { Link Here
100
100
101
    static {
101
    static {
102
        DefaultURLMapperProxy.setDefault(new DefaultURLMapper());
102
        DefaultURLMapperProxy.setDefault(new DefaultURLMapper());
103
        reset();
104
    }
105
106
    /** Cache of all available URLMapper instances. */
107
    private static List<URLMapper> cache;
108
109
    /** Reset cache, for use from unit tests. */
110
    static void reset() {
111
        cache = null;
103
        result = Lookup.getDefault().lookupResult(URLMapper.class);
112
        result = Lookup.getDefault().lookupResult(URLMapper.class);
104
        result.addLookupListener(
113
        result.addLookupListener(
105
            new LookupListener() {
114
            new LookupListener() {
Lines 111-122 public abstract class URLMapper { Link Here
111
            }
120
            }
112
        );
121
        );
113
    }
122
    }
114
115
    /** Basic impl. for JarFileSystem, LocalFileSystem, MultiFileSystem */
116
    private static URLMapper defMapper;
117
118
    /** Cache of all available URLMapper instances. */
119
    private static List<URLMapper> cache;
120
123
121
    /** Find a good URL for this file object which works according to type:
124
    /** Find a good URL for this file object which works according to type:
122
     * <ul>
125
     * <ul>
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/FileUtilTest.java (-13 / +73 lines)
Lines 43-51 package org.openide.filesystems; Link Here
43
43
44
import java.io.File;
44
import java.io.File;
45
import java.net.URL;
45
import java.net.URL;
46
import org.netbeans.junit.MockServices;
47
import org.netbeans.junit.NbTestCase;
46
import org.netbeans.junit.NbTestCase;
47
import org.openide.filesystems.test.TestFileUtils;
48
import org.openide.util.Utilities;
48
import org.openide.util.Utilities;
49
import org.openide.util.test.MockLookup;
49
50
50
/**
51
/**
51
 * @author Jesse Glick
52
 * @author Jesse Glick
Lines 64-86 public class FileUtilTest extends NbTest Link Here
64
        assertTrue(root.isDirectory());
65
        assertTrue(root.isDirectory());
65
        LocalFileSystem lfs = new LocalFileSystem();
66
        LocalFileSystem lfs = new LocalFileSystem();
66
        lfs.setRootDirectory(root);
67
        lfs.setRootDirectory(root);
67
        LFS_ROOT = lfs.getRoot();
68
        final FileObject LFS_ROOT = lfs.getRoot();
68
        MockServices.setServices(TestUM.class);
69
        MockLookup.setInstances(new URLMapper() {
70
            public URL getURL(FileObject fo, int type) {
71
                return null;
72
            }
73
            public FileObject[] getFileObjects(URL url) {
74
                if (url.toExternalForm().equals("file:/")) {
75
                    return new FileObject[] {LFS_ROOT};
76
                } else {
77
                    return null;
78
                }
79
            }
80
        });
81
        URLMapper.reset();
69
        assertEquals(LFS_ROOT, FileUtil.toFileObject(root));
82
        assertEquals(LFS_ROOT, FileUtil.toFileObject(root));
70
    }
83
    }
71
84
72
    private static FileObject LFS_ROOT;
85
    public void testArchiveConversion() throws Exception {
73
    public static class TestUM extends URLMapper {
86
        final LocalFileSystem lfs = new LocalFileSystem();
74
        public URL getURL(FileObject fo, int type) {
87
        clearWorkDir();
75
            throw new UnsupportedOperationException();
88
        lfs.setRootDirectory(getWorkDir());
76
        }
89
        MockLookup.setInstances(new URLMapper() {
77
        public FileObject[] getFileObjects(URL url) {
90
            String rootURL = lfs.getRoot().getURL().toString();
78
            if (url.toExternalForm().equals("file:/")) {
91
            @Override
79
                return new FileObject[] {LFS_ROOT};
92
            public FileObject[] getFileObjects(URL url) {
80
            } else {
93
                String u = url.toString();
94
                FileObject f = null;
95
                if (u.startsWith(rootURL)) {
96
                    f = lfs.findResource(u.substring(rootURL.length()));
97
                }
98
                return f != null ? new FileObject[] {f} : null;
99
            }
100
            @Override
101
            public URL getURL(FileObject fo, int type) {
81
                return null;
102
                return null;
82
            }
103
            }
83
        }
104
        });
105
        URLMapper.reset();
106
107
        TestFileUtils.writeFile(lfs.getRoot(), "README", "A random file with some stuff in it.");
108
        assertCorrectURL("README", null, null); // not an archive
109
        TestFileUtils.writeFile(lfs.getRoot(), "README.txt", "A random file with some stuff in it.");
110
        assertCorrectURL("README.txt", null, null); // not an archive either
111
        TestFileUtils.writeFile(lfs.getRoot(), "empty.zip", "");
112
        assertCorrectURL("empty.zip", "jar:", "empty.zip!/");
113
        TestFileUtils.writeZipFile(lfs.getRoot(), "normal.zip", "something:text inside a ZIP entry");
114
        assertCorrectURL("normal.zip", "jar:", "normal.zip!/");
115
        assertCorrectURL("nonexistent.zip", "jar:", "nonexistent.zip!/");
116
        lfs.getRoot().createFolder("folder");
117
        assertCorrectURL("folder", "", "folder/");
118
        lfs.getRoot().createFolder("some.folder");
119
        assertCorrectURL("some.folder", "", "some.folder/");
120
        assertCorrectURL("nonexistent", "", "nonexistent/");
121
        assertCorrectURL("non existent.zip", "jar:", "non%20existent.zip!/");
122
        assertCorrectURL("non existent", "", "non%20existent/");
123
124
        assertCorrectFile("folder", "", "folder/");
125
        assertCorrectFile("stuff.zip", "jar:", "stuff.zip!/");
126
        assertCorrectFile(null, "jar:", "stuff.zip!/subentry/");
127
        assertCorrectFile(null, "http:", "");
128
        // Impossible to even construct such a URL: assertCorrectFolder("stuff.zip", "jar:", "stuff.zip");
129
        assertCorrectFile("stuff.zip", "", "stuff.zip");
130
        assertCorrectFile("folder", "", "folder");
131
        assertCorrectFile("fol der", "", "fol%20der/");
132
        assertCorrectFile("stu ff.zip", "jar:", "stu%20ff.zip!/");
133
        assertCorrectFile("stu ff.zip", "", "stu%20ff.zip");
134
        assertCorrectFile("fol der", "", "fol%20der");
135
    }
136
    private void assertCorrectURL(String filename, String expectedURLPrefix, String expectedURLSuffix) throws Exception {
137
        File d = getWorkDir();
138
        assertEquals(expectedURLSuffix == null ? null : new URL(expectedURLPrefix + d.toURI() + expectedURLSuffix),
139
                FileUtil.urlForArchiveOrDir(new File(d, filename)));
140
    }
141
    private void assertCorrectFile(String expectedFilename, String urlPrefix, String urlSuffix) throws Exception {
142
        assertEquals(expectedFilename == null ? null : new File(getWorkDir(), expectedFilename),
143
                FileUtil.archiveOrDirForURL(new URL(urlPrefix + getWorkDir().toURI() + urlSuffix)));
84
    }
144
    }
85
145
86
}
146
}
(-)a/project.ant/nbproject/project.xml (-1 / +1 lines)
Lines 119-125 made subject to such option by the copyr Link Here
119
                    <build-prerequisite/>
119
                    <build-prerequisite/>
120
                    <compile-dependency/>
120
                    <compile-dependency/>
121
                    <run-dependency>
121
                    <run-dependency>
122
                        <specification-version>6.2</specification-version>
122
                        <specification-version>7.8</specification-version>
123
                    </run-dependency>
123
                    </run-dependency>
124
                </dependency>
124
                </dependency>
125
                <dependency>
125
                <dependency>
(-)a/project.ant/src/org/netbeans/spi/project/support/ant/GeneratedFilesHelper.java (-6 / +2 lines)
Lines 673-684 public final class GeneratedFilesHelper Link Here
673
673
674
    /** Find the time the file this URL represents was last modified xor its size, if possible. */
674
    /** Find the time the file this URL represents was last modified xor its size, if possible. */
675
    private static long checkFootprint(URL u) {
675
    private static long checkFootprint(URL u) {
676
        URL nested = FileUtil.getArchiveFile(u);
676
        File f = FileUtil.archiveOrDirForURL(u);
677
        if (nested != null) {
677
        if (f != null) {
678
            u = nested;
679
        }
680
        if (u.getProtocol().equals("file")) { // NOI18N
681
            File f = new File(URI.create(u.toExternalForm()));
682
            return f.lastModified() ^ f.length();
678
            return f.lastModified() ^ f.length();
683
        } else {
679
        } else {
684
            return 0L;
680
            return 0L;

Return to bug 59311