diff --git a/project.ant/src/org/netbeans/modules/project/ant/ProjectLibraryProvider.java b/project.ant/src/org/netbeans/modules/project/ant/ProjectLibraryProvider.java --- a/project.ant/src/org/netbeans/modules/project/ant/ProjectLibraryProvider.java +++ b/project.ant/src/org/netbeans/modules/project/ant/ProjectLibraryProvider.java @@ -30,8 +30,8 @@ import java.lang.ref.Reference; import java.lang.ref.Reference; import java.lang.ref.WeakReference; import java.lang.reflect.Field; -import java.lang.reflect.Method; import java.net.MalformedURLException; +import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; @@ -60,6 +60,7 @@ import org.netbeans.spi.project.Auxiliar import org.netbeans.spi.project.AuxiliaryConfiguration; import org.netbeans.spi.project.libraries.ArealLibraryProvider; import org.netbeans.spi.project.libraries.LibraryImplementation; +import org.netbeans.spi.project.libraries.LibraryImplementation2; import org.netbeans.spi.project.libraries.LibraryProvider; import org.netbeans.spi.project.libraries.LibraryStorageArea; import org.netbeans.spi.project.libraries.support.LibrariesSupport; @@ -280,7 +281,7 @@ public class ProjectLibraryProvider impl return lp; } - public ProjectLibraryImplementation createLibrary(String type, String name, ProjectLibraryArea area, Map> contents) throws IOException { + public ProjectLibraryImplementation createLibrary(String type, String name, ProjectLibraryArea area, Map> contents) throws IOException { File f = area.mainPropertiesFile; assert listening; listening = false; @@ -297,8 +298,8 @@ public class ProjectLibraryProvider impl boolean fire = delta(lp.libraries, calculate(area), new HashMap>()); ProjectLibraryImplementation impl = lp.getLibrary(name); assert impl != null : name + " not found in " + f; - for (Map.Entry> entry : contents.entrySet()) { - impl.setContent(entry.getKey(), entry.getValue()); + for (Map.Entry> entry : contents.entrySet()) { + impl.setURIContent(entry.getKey(), entry.getValue()); } if (fire) { lp.pcs.firePropertyChange(LibraryProvider.PROP_LIBRARIES, null, null); @@ -440,7 +441,7 @@ public class ProjectLibraryProvider impl String name = entry.getKey(); String type = "j2se"; // NOI18N String description = null; - Map> contents = new HashMap>(); + Map> contents = new HashMap>(); for (Map.Entry subentry : entry.getValue().entrySet()) { String k = subentry.getKey(); if (k.equals("type")) { // NOI18N @@ -451,7 +452,7 @@ public class ProjectLibraryProvider impl description = subentry.getValue(); } else { String[] path = PropertyUtils.tokenizePath(subentry.getValue()); - List volume = new ArrayList(path.length); + List volume = new ArrayList(path.length); for (String component : path) { String jarFolder = null; // "!/" was replaced in def.properties() with "!"+File.separatorChar @@ -463,16 +464,15 @@ public class ProjectLibraryProvider impl String f = component.replace('/', File.separatorChar).replace('\\', File.separatorChar).replace("${base}"+File.separatorChar, ""); File normalizedFile = FileUtil.normalizeFile(new File(component.replace('/', File.separatorChar).replace('\\', File.separatorChar).replace("${base}", area.mainPropertiesFile.getParent()))); try { - URL u = LibrariesSupport.convertFilePathToURL(f); + URI u = LibrariesSupport.convertFilePathToURI(f); if (FileUtil.isArchiveFile(normalizedFile.toURI().toURL())) { - u = FileUtil.getArchiveRoot(u); - if (jarFolder != null) { - u = appendJarFolder(u, jarFolder); - } - } else if (!u.toExternalForm().endsWith("/")) { - u = new URL(u.toExternalForm() + "/"); + u = appendJarFolder(u, jarFolder); + } else if (!u.getPath().endsWith("/")) { // NOI18N + u = new URI(u.toString() + "/"); // NOI18N } volume.add(u); + } catch (URISyntaxException x) { + Exceptions.printStackTrace(x); } catch (MalformedURLException x) { Exceptions.printStackTrace(x); } @@ -538,10 +538,9 @@ public class ProjectLibraryProvider impl return !added.isEmpty() || !removed.isEmpty(); } - /** for jar url this method returns path wihtin jar or null*/ - private static String getJarFolder(URL url) { - assert "jar".equals(url.getProtocol()) : url; - String u = url.toExternalForm(); + /** for jar uri this method returns path wihtin jar or null*/ + private static String getJarFolder(URI uri) { + String u = uri.toString(); int index = u.indexOf("!/"); //NOI18N if (index != -1 && index + 2 < u.length()) { return u.substring(index+2); @@ -549,23 +548,39 @@ public class ProjectLibraryProvider impl return null; } - /** append path to given jar root url */ - private static URL appendJarFolder(URL u, String jarFolder) { - assert "jar".equals(u.getProtocol()) && u.toExternalForm().endsWith("!/") : u; + private static URI getArchiveURI(URI uri) { + String u = uri.toString(); + int index = u.indexOf("!/"); //NOI18N + if (index != -1) { + try { + return new URI(u.substring(u.startsWith("jar:") ? 4 : 0, index)); // NOI18N + } catch (URISyntaxException e) { + throw new AssertionError(e); + } + } + return null; + } + + /** append path to given jar root uri */ + private static URI appendJarFolder(URI u, String jarFolder) { try { - return new URL(u + jarFolder.replace('\\', '/')); //NOI18N - } catch (MalformedURLException e) { + if (u.isAbsolute()) { + return new URI("jar:" + u.toString() + "!/" + (jarFolder == null ? "" : jarFolder.replace('\\', '/'))); // NOI18N + } else { + return new URI(u.toString() + "!/" + (jarFolder == null ? "" : jarFolder.replace('\\', '/'))); // NOI18N + } + } catch (URISyntaxException e) { throw new AssertionError(e); } } - static final class ProjectLibraryImplementation implements LibraryImplementation { + static final class ProjectLibraryImplementation implements LibraryImplementation2 { final File mainPropertiesFile, privatePropertiesFile; final String type; String name; String description; - Map> contents; + Map> contents; final PropertyChangeSupport pcs = new PropertyChangeSupport(this); static Field libraryImplField; @@ -592,7 +607,7 @@ public class ProjectLibraryProvider impl return null; } - ProjectLibraryImplementation(File mainPropertiesFile, File privatePropertiesFile, String type, String name, String description, Map> contents) { + ProjectLibraryImplementation(File mainPropertiesFile, File privatePropertiesFile, String type, String name, String description, Map> contents) { this.mainPropertiesFile = mainPropertiesFile; this.privatePropertiesFile = privatePropertiesFile; this.type = type; @@ -622,7 +637,20 @@ public class ProjectLibraryProvider impl } public List getContent(String volumeType) throws IllegalArgumentException { - List content = contents.get(volumeType); + List uris = getURIContent(volumeType); + List resolvedUrls = new ArrayList(uris.size()); + for (URI u : uris) { + try { + resolvedUrls.add(LibrariesSupport.resolveLibraryEntryURI(mainPropertiesFile.toURI().toURL(), u).toURL()); + } catch (MalformedURLException ex) { + Exceptions.printStackTrace(ex); + } + } + return resolvedUrls; + } + + public List getURIContent(String volumeType) throws IllegalArgumentException { + List content = contents.get(volumeType); if (content == null) { content = Collections.emptyList(); } @@ -640,29 +668,36 @@ public class ProjectLibraryProvider impl } public void setContent(String volumeType, List path) throws IllegalArgumentException { + List uris = new ArrayList(path.size()); + for (URL u : path) { + uris.add(URI.create(u.toExternalForm())); + } + setURIContent(volumeType, uris); + } + + public void setURIContent(String volumeType, List path) throws IllegalArgumentException { if (path.equals(getContent(volumeType))) { return; } - contents.put(volumeType, new ArrayList(path)); + contents.put(volumeType, new ArrayList(path)); List value = new ArrayList(); - for (URL entry : path) { + for (URI entry : path) { String jarFolder = null; - if ("jar".equals(entry.getProtocol())) { // NOI18N + if (entry.toString().contains("!/")) { // NOI18N jarFolder = getJarFolder(entry); - entry = FileUtil.getArchiveFile(entry); - } else if (!"file".equals(entry.getProtocol())) { // NOI18N + entry = getArchiveURI(entry); + } else if (entry.isAbsolute() && !"file".equals(entry.getScheme())) { // NOI18N value.add(entry.toString()); - Logger.getLogger(ProjectLibraryProvider.class.getName()).fine("Setting url=" + entry + " as content for library volume type: " + volumeType); + Logger.getLogger(ProjectLibraryProvider.class.getName()).fine("Setting uri=" + entry + " as content for library volume type: " + volumeType); continue; } - String p = LibrariesSupport.convertURLToFilePath(entry); - File f = new File(p); // store properties always separated by '/' for consistency + String entryPath = LibrariesSupport.convertURIToFilePath(entry).replace('\\', '/'); StringBuilder s = new StringBuilder(); - if (f.isAbsolute()) { - s.append(f.getAbsolutePath().replace('\\', '/')); //NOI18N + if (entry.isAbsolute()) { + s.append(entryPath); //NOI18N } else { - s.append("${base}/" + p.replace('\\', '/')); // NOI18N + s.append("${base}/" + entryPath); // NOI18N } if (jarFolder != null) { s.append("!/"); // NOI18N @@ -964,8 +999,7 @@ public class ProjectLibraryProvider impl */ public static Library copyLibrary(final Library lib, final URL location, final boolean generateLibraryUniqueName) throws IOException { - assert LibrariesSupport.isAbsoluteURL(location); - final File libBaseFolder = new File(LibrariesSupport.convertURLToFilePath(location)).getParentFile(); + final File libBaseFolder = new File(URI.create(location.toExternalForm())).getParentFile(); FileObject sharedLibFolder; try { sharedLibFolder = ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { @@ -980,15 +1014,15 @@ public class ProjectLibraryProvider impl } catch (MutexException ex) { throw (IOException)ex.getException(); } - final Map> content = new HashMap>(); + final Map> content = new HashMap>(); String[] volumes = LibrariesSupport.getLibraryTypeProvider(lib.getType()).getSupportedVolumeTypes(); for (String volume : volumes) { - List volumeContent = new ArrayList(); + List volumeContent = new ArrayList(); for (URL origlibEntry : lib.getContent(volume)) { URL libEntry = origlibEntry; String jarFolder = null; if ("jar".equals(libEntry.getProtocol())) { // NOI18N - jarFolder = getJarFolder(libEntry); + jarFolder = getJarFolder(URI.create(libEntry.toExternalForm())); libEntry = FileUtil.getArchiveFile(libEntry); } FileObject libEntryFO = URLMapper.findFileObject(libEntry); @@ -1004,7 +1038,7 @@ public class ProjectLibraryProvider impl continue; } } - URL u; + URI u; FileObject newFO; String name; if (CollocationQuery.areCollocated(libBaseFolder, FileUtil.toFile(libEntryFO))) { @@ -1022,11 +1056,8 @@ public class ProjectLibraryProvider impl name = sharedLibFolder.getNameExt()+File.separatorChar+newFO.getNameExt(); } } - u = LibrariesSupport.convertFilePathToURL(name); + u = LibrariesSupport.convertFilePathToURI(name); if (FileUtil.isArchiveFile(newFO)) { - u = FileUtil.getArchiveRoot(u); - } - if (jarFolder != null) { u = appendJarFolder(u, jarFolder); } volumeContent.add(u); @@ -1045,7 +1076,7 @@ public class ProjectLibraryProvider impl index++; } } - return man.createLibrary(lib.getType(), name, content); + return man.createURILibrary(lib.getType(), name, content); } }); } catch (MutexException ex) { diff --git a/project.ant/test/unit/src/org/netbeans/modules/project/ant/ProjectLibraryProviderTest.java b/project.ant/test/unit/src/org/netbeans/modules/project/ant/ProjectLibraryProviderTest.java --- a/project.ant/test/unit/src/org/netbeans/modules/project/ant/ProjectLibraryProviderTest.java +++ b/project.ant/test/unit/src/org/netbeans/modules/project/ant/ProjectLibraryProviderTest.java @@ -29,6 +29,7 @@ import java.io.InputStream; import java.io.InputStream; import java.io.OutputStream; import java.lang.reflect.Method; +import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; @@ -53,6 +54,7 @@ import org.netbeans.junit.NbTestCase; import org.netbeans.junit.NbTestCase; import org.netbeans.spi.project.AuxiliaryConfiguration; import org.netbeans.spi.project.libraries.LibraryImplementation; +import org.netbeans.spi.project.libraries.LibraryImplementation2; import org.netbeans.spi.project.libraries.LibraryProvider; import org.netbeans.spi.project.libraries.LibraryTypeProvider; import org.netbeans.spi.project.libraries.support.LibrariesSupport; @@ -147,8 +149,9 @@ public class ProjectLibraryProviderTest assertEquals("jgraph", lib.getDisplayName()); assertNull(lib.getDescription()); assertEquals("j2se", lib.getType()); - assertEquals(Arrays.asList(new URL("jar:file:jgraph.jar!/"), new URL("jar:file:../extra%20libs/jgraph-extras.jar!/")), lib.getRawContent("classpath")); - assertEquals(Arrays.asList(new URL("file:api/jgraph-docs/"), new URL("jar:file:api/jgraph-docs.zip!/docs/api/")), lib.getRawContent("javadoc")); + assertEquals(Arrays.asList(new URI("jgraph.jar!/"), new URI("../extra%20libs/jgraph-extras.jar!/")), lib.getURIContent("classpath")); + assertEquals(Arrays.asList(new URL("jar:"+base.toExternalForm()+"libs/jgraph.jar!/"), new URL("jar:"+base.toExternalForm()+"extra%20libs/jgraph-extras.jar!/")), lib.getContent("classpath")); + assertEquals(Arrays.asList(new URI("api/jgraph-docs/"), new URI("api/jgraph-docs.zip!/docs/api/")), lib.getURIContent("javadoc")); assertEquals(Collections.emptyList(), lib.getContent("src")); //if this field is null, it means the reflection won't work on Library instances @@ -164,9 +167,10 @@ public class ProjectLibraryProviderTest "libs.jgraph.javadoc=" + new File(getWorkDir(), "jgraph-api")); storeDefs(project, "../libs/libraries.properties"); Library lib = LibraryManager.forLocation(new URL(base, "libs/libraries.properties")).getLibrary("jgraph"); - assertEquals(Collections.singletonList(new URL("jar:file:jgraph.jar!/")), lib.getRawContent("classpath")); - assertEquals(Collections.singletonList(new URL("jar:" + base + "jgraph-src.zip!/")), lib.getRawContent("src")); - assertEquals(Collections.singletonList(new URL(base, "jgraph-api/")), lib.getRawContent("javadoc")); + assertEquals(Collections.singletonList(new URI("jgraph.jar!/")), lib.getURIContent("classpath")); + assertEquals(Collections.singletonList(new URI("jar:" + base.toExternalForm() + "jgraph-src.zip!/")), lib.getURIContent("src")); + assertEquals(Collections.singletonList(new URL("jar:" + base.toExternalForm() + "jgraph-src.zip!/")), lib.getContent("src")); + assertEquals(Collections.singletonList(new URL(base, "jgraph-api/").toURI()), lib.getURIContent("javadoc")); } public void testPrivateOverridesSharedProperties() throws Exception { @@ -176,7 +180,7 @@ public class ProjectLibraryProviderTest "libs.jgraph.classpath=" + new File(getWorkDir(), "jgraph-api")); storeDefs(project, "../libs/libraries.properties"); Library lib = LibraryManager.forLocation(new URL(base, "libs/libraries.properties")).getLibrary("jgraph"); - assertEquals(Collections.singletonList(new URL(base, "jgraph-api/")), lib.getContent("classpath")); + assertEquals(Collections.singletonList(new URL(base, "jgraph-api/").toURI()), lib.getURIContent("classpath")); } public void testSetContent() throws Exception { @@ -184,9 +188,9 @@ public class ProjectLibraryProviderTest "libs.jgraph.classpath="); storeDefs(project, "../libs/libraries.properties"); Library lib = LibraryManager.forLocation(new URL(base, "libs/libraries.properties")).getLibrary("jgraph"); - setLibraryContent(lib, "classpath", new URL("jar:file:jgraph.jar!/"), new URL("jar:file:../extra%20libs/jgraph-extras.jar!/")); - setLibraryContent(lib, "src", new URL(base, "separate/jgraph-src/"), new URL(base, "jgraph-other-src/")); - setLibraryContent(lib, "javadoc", new URL("jar:" + base + "separate/jgraph-api.zip!/"), new URL("jar:file:../separate/jgraph-api.zip!/docs/api/")); + setLibraryContent(lib, "classpath", new URI("jgraph.jar!/"), new URI("../extra%20libs/jgraph-extras.jar!/")); + setLibraryContent(lib, "src", new URL(base, "separate/jgraph-src/").toURI(), new URL(base, "jgraph-other-src/").toURI()); + setLibraryContent(lib, "javadoc", new URI("jar:" + base + "separate/jgraph-api.zip!/"), new URI("../separate/jgraph-api.zip!/docs/api/")); Map m = new HashMap(); File separate = new File(getWorkDir(), "separate"); m.put("libs.jgraph.classpath", "${base}/jgraph.jar"+File.pathSeparatorChar+"${base}/../extra libs/jgraph-extras.jar"); @@ -241,11 +245,11 @@ public class ProjectLibraryProviderTest "libs.jgraph.classpath=${base}/jgraph", "libs.collections.classpath=${base}/collections"); contentlist.assertEventCount(1); - assertEquals(Collections.singletonList(new URL("file:jgraph/")), lib1.getRawContent("classpath")); + assertEquals(Collections.singletonList(new URI("jgraph/")), lib1.getURIContent("classpath")); liblist.assertEventCount(1); assertEquals(lib1, mgr.getLibrary("jgraph")); Library lib2 = mgr.getLibrary("collections"); - assertEquals(Collections.singletonList(new URL("file:collections/")), lib2.getRawContent("classpath")); + assertEquals(Collections.singletonList(new URI("collections/")), lib2.getURIContent("classpath")); pplist.assertEventCount(1); assertEquals(("{libs.collections.classpath=" + getWorkDir() + "/collections, libs.jgraph.classpath=" + getWorkDir() + "/jgraph}").replace('/', File.separatorChar), @@ -263,20 +267,20 @@ public class ProjectLibraryProviderTest public void testCreateRemoveLibrary() throws Exception { LibraryManager mgr = LibraryManager.forLocation(new URL(base, "libraries.properties")); - Map> content = new HashMap>(); - content.put("classpath", Arrays.asList(new URL("jar:file:jh.jar!/"), new URL("jar:file:jh-search.jar!/"))); - content.put("javadoc", Arrays.asList(new URL("file:jh-api/"))); - Library lib = mgr.createLibrary("j2se", "javahelp", content); + Map> content = new HashMap>(); + content.put("classpath", Arrays.asList(new URI("jh.jar!/"), new URI("jh-search.jar!/"))); + content.put("javadoc", Arrays.asList(new URI("jh-api/"))); + Library lib = mgr.createURILibrary("j2se", "javahelp", content); assertEquals("j2se", lib.getType()); assertEquals("javahelp", lib.getName()); - assertEquals(content.get("classpath"), lib.getRawContent("classpath")); - assertEquals(content.get("javadoc"), lib.getRawContent("javadoc")); - lib = mgr.createLibrary("j2me", "gps", Collections.>emptyMap()); + assertEquals(content.get("classpath"), lib.getURIContent("classpath")); + assertEquals(content.get("javadoc"), lib.getURIContent("javadoc")); + lib = mgr.createURILibrary("j2me", "gps", Collections.>emptyMap()); assertEquals("j2me", lib.getType()); assertEquals("gps", lib.getName()); Map expected = new HashMap(); expected.put("libs.javahelp.classpath", "${base}/jh.jar"+File.pathSeparatorChar+"${base}/jh-search.jar"); - expected.put("libs.javahelp.javadoc", "${base}/jh-api"); + expected.put("libs.javahelp.javadoc", "${base}/jh-api/"); expected.put("libs.gps.type", "j2me"); assertEquals(expected, loadProperties("libraries.properties")); mgr.removeLibrary(lib); @@ -286,20 +290,20 @@ public class ProjectLibraryProviderTest public void testCreateLibraryUnderFSAtomicAction() throws Exception { final LibraryManager mgr = LibraryManager.forLocation(new URL(base, "libraries.properties")); - final Map> content = new HashMap>(); - content.put("classpath", Arrays.asList(new URL("jar:file:jh.jar!/"), new URL("jar:file:jh-search.jar!/"))); - content.put("javadoc", Arrays.asList(new URL("file:jh-api/"))); + final Map> content = new HashMap>(); + content.put("classpath", Arrays.asList(new URI("jh.jar!/"), new URI("jh-search.jar!/"))); + content.put("javadoc", Arrays.asList(new URI("jh-api/"))); FileSystem fs = projdir.getFileSystem(); fs.runAtomicAction(new FileSystem.AtomicAction() { public void run() throws IOException { - Library lib = mgr.createLibrary("j2se", "javahelp", content); + Library lib = mgr.createURILibrary("j2se", "javahelp", content); assertEquals("j2se", lib.getType()); assertEquals("javahelp", lib.getName()); - assertEquals(content.get("classpath"), lib.getRawContent("classpath")); - assertEquals(content.get("javadoc"), lib.getRawContent("javadoc")); + assertEquals(content.get("classpath"), lib.getURIContent("classpath")); + assertEquals(content.get("javadoc"), lib.getURIContent("javadoc")); try { - setLibraryContent(lib, "src", new URL(base, "separate/jgraph-src/"), new URL(base, "jgraph-other-src/")); + setLibraryContent(lib, "src", new URL(base, "separate/jgraph-src/").toURI(), new URL(base, "jgraph-other-src/").toURI()); } catch (Exception e) { throw new IOException(e.toString()); } @@ -308,9 +312,9 @@ public class ProjectLibraryProviderTest public void testCreateLibraryAndLibrariesEventFiring() throws Exception { final LibraryManager mgr = LibraryManager.forLocation(new URL(base, "libraries.properties")); - final Map> content = new HashMap>(); - content.put("classpath", Arrays.asList(new URL("jar:file:jh.jar!/"), new URL("jar:file:jh-search.jar!/"))); - content.put("javadoc", Arrays.asList(new URL("file:jh-api/"))); + final Map> content = new HashMap>(); + content.put("classpath", Arrays.asList(new URI("jh.jar!/"), new URI("jh-search.jar!/"))); + content.put("javadoc", Arrays.asList(new URI("jh-api/"))); final List list = new ArrayList(); final PropertyChangeListener l = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { @@ -318,13 +322,13 @@ public class ProjectLibraryProviderTest if (evt.getPropertyName().equals(LibraryManager.PROP_LIBRARIES)) { // by the time we got this event library must be fully set up: assertTrue("must have one library", mgr.getLibraries().length == 1); - assertEquals("library content must be set", content.get("classpath"), mgr.getLibraries()[0].getRawContent("classpath")); - assertEquals("library content must be set", content.get("javadoc"), mgr.getLibraries()[0].getRawContent("javadoc")); + assertEquals("library content must be set", content.get("classpath"), mgr.getLibraries()[0].getURIContent("classpath")); + assertEquals("library content must be set", content.get("javadoc"), mgr.getLibraries()[0].getURIContent("javadoc")); } } }; mgr.addPropertyChangeListener(l); - Library lib = mgr.createLibrary("j2se", "javahelp", content); + Library lib = mgr.createURILibrary("j2se", "javahelp", content); mgr.removePropertyChangeListener(l); assertTrue(list.size() == 1); mgr.removeLibrary(lib); @@ -332,7 +336,7 @@ public class ProjectLibraryProviderTest fs.runAtomicAction(new FileSystem.AtomicAction() { public void run() throws IOException { mgr.addPropertyChangeListener(l); - mgr.createLibrary("j2se", "javahelp", content); + mgr.createURILibrary("j2se", "javahelp", content); mgr.removePropertyChangeListener(l); assertTrue(list.size() == 2); }}); @@ -408,20 +412,20 @@ public class ProjectLibraryProviderTest OpenProjects.getDefault().close(projects); } - private static void setLibraryContent(Library lib, String volumeType, URL... paths) throws Exception { + private static void setLibraryContent(Library lib, String volumeType, URI... paths) throws Exception { MockPropertyChangeListener l = new MockPropertyChangeListener(Library.PROP_CONTENT); lib.addPropertyChangeListener(l); - LibraryImplementation impl = getLibraryImplementation(lib); - List path = Arrays.asList(paths); - impl.setContent(volumeType, path); + LibraryImplementation2 impl = getLibraryImplementation(lib); + List path = Arrays.asList(paths); + impl.setURIContent(volumeType, path); l.assertEventCount(1); - assertEquals(path, lib.getRawContent(volumeType)); + assertEquals(path, lib.getURIContent(volumeType)); } - private static LibraryImplementation getLibraryImplementation(Library lib) throws Exception { + private static LibraryImplementation2 getLibraryImplementation(Library lib) throws Exception { Method getLibraryImplementation = Library.class.getDeclaredMethod("getLibraryImplementation"); getLibraryImplementation.setAccessible(true); - return (LibraryImplementation) getLibraryImplementation.invoke(lib); + return (LibraryImplementation2) getLibraryImplementation.invoke(lib); } private Map loadProperties(String path) throws IOException { @@ -457,7 +461,7 @@ public class ProjectLibraryProviderTest new File(this.getWorkDir(), "libraries2").mkdir(); File f4 = new File(this.getWorkDir(), "libraries2/libs.properties"); f4.createNewFile(); - FileUtil.toFileObject(getWorkDir()).refresh(); + FileUtil.toFileObject(getWorkDir()).getFileSystem().refresh(false); LibraryImplementation l1 = LibrariesSupport.createLibraryImplementation("j2test", new String[]{"jars", "sources"}); l1.setName("vino"); l1.setContent("jars", Arrays.asList(new URL[]{f.toURI().toURL(), f1.toURI().toURL()})); @@ -470,17 +474,21 @@ public class ProjectLibraryProviderTest Library result = ProjectLibraryProvider.copyLibrary(l, u, false); assertNotNull(result); assertEquals(u, result.getManager().getLocation()); - assertEquals(Arrays.asList(new URL("jar:file:vino/bertie.jar!/"), - new URL("jar:file:vino/dog.jar!/")), result.getRawContent("jars")); - assertEquals(Arrays.asList(new URL("jar:file:vino/bertie-2.jar!/docs/api/")), result.getRawContent("sources")); + assertEquals(Arrays.asList(new URI("vino/bertie.jar!/"), + new URI("vino/dog.jar!/")), result.getURIContent("jars")); + assertEquals(Arrays.asList(new URI("vino/bertie-2.jar!/docs/api/")), result.getURIContent("sources")); assertEquals("vino", result.getName()); assertEquals("j2test", result.getType()); - //assertNotNull(LibrariesSupport.resolveLibraryEntryFileObject(u, result.getContent("jars").get(0))); - assertEquals(new File(this.getWorkDir(), "libraries/vino/bertie.jar").getPath(), - FileUtil.toFile(LibrariesSupport.resolveLibraryEntryFileObject(u, FileUtil.getArchiveFile(result.getRawContent("jars").get(0)))).getPath()); + //assertNotNull(LibrariesSupport.resolveLibraryEntryFileObject(u, result.getURIContent("jars").get(0))); + assertEquals("jar:"+(new File(this.getWorkDir(), "libraries/vino/bertie.jar").toURI().toString())+"!/", + LibrariesSupport.resolveLibraryEntryURI(u, result.getURIContent("jars").get(0)).toString()); + assertEquals("jar:"+(new File(this.getWorkDir(), "libraries/vino/bertie.jar").toURI().toString())+"!/", + result.getContent("jars").get(0).toExternalForm()); //assertNotNull(LibrariesSupport.resolveLibraryEntryFileObject(u, result.getContent("sources").get(0))); - assertEquals(new File(this.getWorkDir(), "libraries/vino/bertie-2.jar").getPath(), - FileUtil.toFile(LibrariesSupport.resolveLibraryEntryFileObject(u, FileUtil.getArchiveFile(result.getRawContent("sources").get(0)))).getPath()); + assertEquals("jar:"+(new File(this.getWorkDir(), "libraries/vino/bertie-2.jar").toURI())+"!/docs/api/", + LibrariesSupport.resolveLibraryEntryURI(u, result.getURIContent("sources").get(0)).toString()); + assertEquals("jar:"+(new File(this.getWorkDir(), "libraries/vino/bertie-2.jar").toURI())+"!/docs/api/", + result.getContent("sources").get(0).toExternalForm()); // enable test collocation query: MockLookup.setLookup(Lookups.fixed(AntBasedTestUtil.testAntBasedProjectType(), AntBasedTestUtil.testCollocationQueryImplementation(getWorkDir()), libraryProvider), // Filter out standard CQIs since they are bogus. @@ -489,9 +497,9 @@ public class ProjectLibraryProviderTest result = ProjectLibraryProvider.copyLibrary(l, u, false); assertNotNull(result); assertEquals(u, result.getManager().getLocation()); - assertEquals(Arrays.asList(new URL("jar:file:../bertie.jar!/"), - new URL("jar:file:../dog.jar!/")), result.getRawContent("jars")); - assertEquals(Arrays.asList(new URL("jar:file:../sources/bertie.jar!/docs/api/")), result.getRawContent("sources")); + assertEquals(Arrays.asList(new URI("../bertie.jar!/"), + new URI("../dog.jar!/")), result.getURIContent("jars")); + assertEquals(Arrays.asList(new URI("../sources/bertie.jar!/docs/api/")), result.getURIContent("sources")); }