diff --git a/java.j2seplatform/nbproject/project.xml b/java.j2seplatform/nbproject/project.xml
--- a/java.j2seplatform/nbproject/project.xml
+++ b/java.j2seplatform/nbproject/project.xml
@@ -124,7 +124,7 @@
1
- 1.15
+ 1.31
diff --git a/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/J2SELibraryTypeProvider.java b/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/J2SELibraryTypeProvider.java
--- a/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/J2SELibraryTypeProvider.java
+++ b/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/libraries/J2SELibraryTypeProvider.java
@@ -71,6 +71,7 @@
import java.net.URI;
import java.util.HashSet;
import java.util.logging.Logger;
+import org.netbeans.spi.project.libraries.NamedLibraryImplementation;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
@@ -101,27 +102,33 @@
VOLUME_TYPE_JAVADOC,
}));
+ @Override
public String getLibraryType() {
return LIBRARY_TYPE;
}
+ @Override
public String getDisplayName () {
return NbBundle.getMessage (J2SELibraryTypeProvider.class,"TXT_J2SELibraryType");
}
+ @Override
public String[] getSupportedVolumeTypes () {
return VOLUME_TYPES;
}
+ @Override
public LibraryImplementation createLibrary() {
return new J2SELibraryImpl ();
}
+ @Override
public void libraryCreated(final LibraryImplementation libraryImpl) {
assert libraryImpl != null;
ProjectManager.mutex().postWriteRequest(
new Runnable () {
+ @Override
public void run () {
try {
EditableProperties props = PropertyUtils.getGlobalProperties();
@@ -137,9 +144,11 @@
);
}
+ @Override
public void libraryDeleted(final LibraryImplementation libraryImpl) {
assert libraryImpl != null;
ProjectManager.mutex().postWriteRequest(new Runnable () {
+ @Override
public void run() {
try {
EditableProperties props = PropertyUtils.getGlobalProperties();
@@ -155,6 +164,7 @@
});
}
+ @Override
public Customizer getCustomizer(String volumeType) {
if (VOLUME_TYPES[0].equals(volumeType)||
VOLUME_TYPES[1].equals(volumeType)||
@@ -167,6 +177,7 @@
}
+ @Override
public Lookup getLookup() {
return Lookup.EMPTY;
}
@@ -228,7 +239,7 @@
}
//Like DefaultLibraryTypeProvider but in addition checks '/' on the end of folder URLs.
- private static class J2SELibraryImpl implements LibraryImplementation {
+ private static class J2SELibraryImpl implements NamedLibraryImplementation {
private String description;
private Map> contents;
@@ -236,6 +247,8 @@
// library 'binding name' as given by user
private String name;
+ private String displayName;
+
private String localizingBundle;
private List listeners;
@@ -251,20 +264,34 @@
}
+ @Override
public String getType() {
return LIBRARY_TYPE;
}
+ @Override
public void setName(final String name) throws UnsupportedOperationException {
String oldName = this.name;
this.name = name;
this.firePropertyChange (PROP_NAME, oldName, this.name);
}
+ @Override
public String getName() {
return name;
}
+ @Override
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return this.displayName;
+ }
+
+ @Override
public List getContent(String contentType) throws IllegalArgumentException {
List content = contents.get(contentType);
if (content == null)
@@ -272,6 +299,7 @@
return Collections.unmodifiableList (content);
}
+ @Override
public void setContent(final String contentType, List path) throws IllegalArgumentException {
if (path == null) {
throw new IllegalArgumentException ();
@@ -311,37 +339,44 @@
return checkedResources;
}
+ @Override
public String getDescription () {
return this.description;
}
+ @Override
public void setDescription (String text) {
String oldDesc = this.description;
this.description = text;
this.firePropertyChange (PROP_DESCRIPTION, oldDesc, this.description);
}
+ @Override
public String getLocalizingBundle() {
return this.localizingBundle;
}
+ @Override
public void setLocalizingBundle(String resourceName) {
this.localizingBundle = resourceName;
}
+ @Override
public synchronized void addPropertyChangeListener (PropertyChangeListener l) {
if (this.listeners == null)
this.listeners = new ArrayList();
this.listeners.add (l);
}
+ @Override
public synchronized void removePropertyChangeListener (PropertyChangeListener l) {
if (this.listeners == null)
return;
this.listeners.remove (l);
}
- public @Override String toString() {
+ @Override
+ public String toString() {
return this.getClass().getName()+"[" + name + "]"; // NOI18N
}
diff --git a/java.project/nbproject/project.xml b/java.project/nbproject/project.xml
--- a/java.project/nbproject/project.xml
+++ b/java.project/nbproject/project.xml
@@ -125,6 +125,7 @@
1
+ 1.31
diff --git a/java.project/src/org/netbeans/spi/java/project/support/ui/SharableLibrariesUtils.java b/java.project/src/org/netbeans/spi/java/project/support/ui/SharableLibrariesUtils.java
--- a/java.project/src/org/netbeans/spi/java/project/support/ui/SharableLibrariesUtils.java
+++ b/java.project/src/org/netbeans/spi/java/project/support/ui/SharableLibrariesUtils.java
@@ -512,7 +512,18 @@
NbBundle.getMessage(SharableLibrariesUtils.class, "ERR_LibraryExists", library.getDisplayName()),
NotifyDescriptor.WARNING_MESSAGE));
} else {
- man.createURILibrary(library.getType(), library.getName(), volumes);
+ final String name = library.getName();
+ String displayName = library.getDisplayName();
+ if (name.equals(displayName)) {
+ //No need to set displayName when it's same as name
+ displayName = null;
+ }
+ man.createURILibrary(
+ library.getType(),
+ name,
+ displayName,
+ library.getDescription(),
+ volumes);
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
diff --git a/project.ant/nbproject/project.xml b/project.ant/nbproject/project.xml
--- a/project.ant/nbproject/project.xml
+++ b/project.ant/nbproject/project.xml
@@ -72,7 +72,7 @@
1
- 1.15
+ 1.31
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
@@ -76,6 +76,7 @@
import javax.swing.JFileChooser;
import javax.swing.event.ChangeListener;
import javax.swing.filechooser.FileFilter;
+import org.netbeans.api.annotations.common.NullAllowed;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.api.project.libraries.Library;
@@ -91,6 +92,7 @@
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.NamedLibraryImplementation;
import org.netbeans.spi.project.libraries.support.LibrariesSupport;
import org.netbeans.spi.project.support.ant.AntProjectEvent;
import org.netbeans.spi.project.support.ant.AntProjectHelper;
@@ -130,6 +132,7 @@
private static final String NAMESPACE = "http://www.netbeans.org/ns/ant-project-libraries/1"; // NOI18N
private static final String EL_LIBRARIES = "libraries"; // NOI18N
private static final String EL_DEFINITIONS = "definitions"; // NOI18N
+ private static final String SFX_DISPLAY_NAME = "displayName"; //NOI18N
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
private AntProjectListener apl;
@@ -496,6 +499,7 @@
String name = entry.getKey();
String type = "j2se"; // NOI18N
String description = null;
+ String displayName = null;
Map> contents = new HashMap>();
for (Map.Entry subentry : entry.getValue().entrySet()) {
String k = subentry.getKey();
@@ -505,6 +509,8 @@
// XXX currently overriding display name is not supported
} else if (k.equals("description")) { // NOI18N
description = subentry.getValue();
+ } else if (k.equals(SFX_DISPLAY_NAME)) { //NOI18N
+ displayName = subentry.getValue();
} else {
final String[] path = sanitizeHttp(subentry.getKey(), PropertyUtils.tokenizePath(subentry.getValue()));
List volume = new ArrayList(path.length);
@@ -535,7 +541,16 @@
contents.put(k, volume);
}
}
- libs.put(name, new ProjectLibraryImplementation(def.mainPropertiesFile, def.privatePropertiesFile, type, name, description, contents));
+ libs.put(
+ name,
+ new ProjectLibraryImplementation(
+ def.mainPropertiesFile,
+ def.privatePropertiesFile,
+ type,
+ name,
+ description,
+ displayName,
+ contents));
}
return libs;
}
@@ -642,12 +657,13 @@
return result.toArray(new String[result.size()]);
}
- static final class ProjectLibraryImplementation implements LibraryImplementation2 {
+ static final class ProjectLibraryImplementation implements LibraryImplementation2, NamedLibraryImplementation {
final File mainPropertiesFile, privatePropertiesFile;
final String type;
String name;
String description;
+ String displayName;
Map> contents;
final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
@@ -675,12 +691,20 @@
return null;
}
- ProjectLibraryImplementation(File mainPropertiesFile, File privatePropertiesFile, String type, String name, String description, Map> contents) {
+ ProjectLibraryImplementation(
+ File mainPropertiesFile,
+ File privatePropertiesFile,
+ String type,
+ String name,
+ final @NullAllowed String description,
+ final @NullAllowed String displayName,
+ Map> contents) {
this.mainPropertiesFile = mainPropertiesFile;
this.privatePropertiesFile = privatePropertiesFile;
this.type = type;
this.name = name;
this.description = description;
+ this.displayName = displayName;
this.contents = contents;
}
@@ -704,6 +728,11 @@
return null;
}
+ @Override
+ public String getDisplayName() {
+ return displayName;
+ }
+
public List getContent(String volumeType) throws IllegalArgumentException {
List uris = getURIContent(volumeType);
List resolvedUrls = new ArrayList(uris.size());
@@ -807,6 +836,26 @@
throw new UnsupportedOperationException();
}
+ @Override
+ public void setDisplayName(final @NullAllowed String displayName) {
+ if (Utilities.compareObjects(this.displayName, displayName)) {
+ return;
+ }
+ final String oldDisplayName = this.displayName;
+ this.displayName = displayName;
+ try {
+ final String key = String.format("libs.%s.%s",name, SFX_DISPLAY_NAME); //NOI18N
+ replaceProperty(
+ mainPropertiesFile,
+ false,
+ key,
+ displayName == null ? new String[0] : new String[]{displayName});
+ } catch (IOException x) {
+ throw new IllegalArgumentException(x);
+ }
+ pcs.firePropertyChange(LibraryImplementation.PROP_CONTENT, oldDisplayName, displayName);
+ }
+
public void addPropertyChangeListener(PropertyChangeListener l) {
pcs.addPropertyChangeListener(l);
}
@@ -1169,7 +1218,12 @@
index++;
}
}
- return man.createURILibrary(lib.getType(), name, content);
+ String displayName = lib.getDisplayName();
+ if (name.equals(displayName)) {
+ //No need to set displayName when it's same as name
+ displayName = null;
+ }
+ return man.createURILibrary(lib.getType(), name, displayName, lib.getDescription(), content);
}
});
} catch (MutexException ex) {
diff --git a/project.libraries/apichanges.xml b/project.libraries/apichanges.xml
--- a/project.libraries/apichanges.xml
+++ b/project.libraries/apichanges.xml
@@ -107,6 +107,22 @@
+
+
+ Allow user created library to provide display name
+
+
+
+
+
+ Added displayName
property into the Library
's SPI
+ allowing an implementor to provide the a display name of the Library
+ which differs from the system (identifying) name.
+
+
+
+
+
URI used for relative library entries instead of URL
diff --git a/project.libraries/manifest.mf b/project.libraries/manifest.mf
--- a/project.libraries/manifest.mf
+++ b/project.libraries/manifest.mf
@@ -2,7 +2,7 @@
OpenIDE-Module: org.netbeans.modules.project.libraries/1
OpenIDE-Module-Install: org/netbeans/modules/project/libraries/LibrariesModule.class
OpenIDE-Module-Layer: org/netbeans/modules/project/libraries/resources/mf-layer.xml
-OpenIDE-Module-Specification-Version: 1.30
+OpenIDE-Module-Specification-Version: 1.31
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/libraries/resources/Bundle.properties
AutoUpdate-Show-In-Client: false
diff --git a/project.libraries/src/org/netbeans/api/project/libraries/LibrariesCustomizer.java b/project.libraries/src/org/netbeans/api/project/libraries/LibrariesCustomizer.java
--- a/project.libraries/src/org/netbeans/api/project/libraries/LibrariesCustomizer.java
+++ b/project.libraries/src/org/netbeans/api/project/libraries/LibrariesCustomizer.java
@@ -50,6 +50,7 @@
import java.awt.Dialog;
import javax.swing.border.EmptyBorder;
import org.netbeans.modules.project.libraries.LibraryTypeRegistry;
+import org.netbeans.modules.project.libraries.Util;
import org.netbeans.modules.project.libraries.ui.LibrariesModel;
import org.netbeans.modules.project.libraries.ui.NewLibraryPanel;
import org.netbeans.spi.project.libraries.LibraryImplementation;
@@ -125,9 +126,15 @@
setAccessibleDescription(dlg, customizer.getAccessibleContext().getAccessibleDescription());
dlg.setVisible(true);
if (dd.getValue() == DialogDescriptor.OK_OPTION) {
+ final String currentLibraryName = p.getLibraryName();
+ final String antLibraryName =
+ org.netbeans.modules.project.libraries.ui.LibrariesCustomizer.createFreeAntLibraryName(
+ currentLibraryName,
+ customizer.getModel(),
+ area);
LibraryImplementation impl;
if (area != LibrariesModel.GLOBAL_AREA) {
- impl = customizer.getModel().createArealLibrary(p.getLibraryType(), p.getLibraryName(), manager.getArea());
+ impl = customizer.getModel().createArealLibrary(p.getLibraryType(), antLibraryName, manager.getArea());
} else {
LibraryTypeProvider provider = LibraryTypeRegistry.getDefault().getLibraryTypeProvider(p.getLibraryType());
if (provider == null) {
@@ -136,6 +143,7 @@
impl = provider.createLibrary();
impl.setName(p.getLibraryName());
}
+ Util.setDisplayName(impl, currentLibraryName);
customizer.getModel().addLibrary(impl);
customizer.forceTreeRecreation();
if (customizeLibrary(customizer, impl)) {
diff --git a/project.libraries/src/org/netbeans/api/project/libraries/Library.java b/project.libraries/src/org/netbeans/api/project/libraries/Library.java
--- a/project.libraries/src/org/netbeans/api/project/libraries/Library.java
+++ b/project.libraries/src/org/netbeans/api/project/libraries/Library.java
@@ -54,6 +54,7 @@
import java.util.ResourceBundle;
import java.util.logging.Logger;
import org.netbeans.modules.project.libraries.LibraryAccessor;
+import org.netbeans.modules.project.libraries.Util;
import org.netbeans.modules.project.libraries.ui.LibrariesModel;
import org.netbeans.spi.project.libraries.LibraryImplementation;
import org.netbeans.spi.project.libraries.LibraryImplementation2;
@@ -176,7 +177,7 @@
* @return String the display name, never returns null.
*/
public String getDisplayName () {
- return org.netbeans.modules.project.libraries.ui.LibrariesCustomizer.getLocalizedName(this.impl);
+ return Util.getLocalizedName(this.impl);
}
diff --git a/project.libraries/src/org/netbeans/api/project/libraries/LibraryManager.java b/project.libraries/src/org/netbeans/api/project/libraries/LibraryManager.java
--- a/project.libraries/src/org/netbeans/api/project/libraries/LibraryManager.java
+++ b/project.libraries/src/org/netbeans/api/project/libraries/LibraryManager.java
@@ -58,7 +58,10 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.api.annotations.common.NullAllowed;
import org.netbeans.modules.project.libraries.LibraryAccessor;
+import org.netbeans.modules.project.libraries.Util;
import org.netbeans.modules.project.libraries.WritableLibraryProvider;
import org.netbeans.modules.project.libraries.ui.LibrariesModel;
import org.netbeans.spi.project.libraries.ArealLibraryProvider;
@@ -286,6 +289,29 @@
* @since org.netbeans.modules.project.libraries/1 1.15
*/
public Library createLibrary(String type, String name, Map> contents) throws IOException {
+ return createLibrary(type, name, null, null, contents);
+ }
+
+ /**
+ * Creates a new library definition and adds it to the list.
+ * @param type the type of library, as in {@link LibraryTypeProvider#getLibraryType} or {@link LibraryImplementation#getType}
+ * @param name the identifying name of the new library (must not duplicate a name already in use by a library in this manager)
+ * @param displayName the display name of the library. If null the identifying name is used
+ * @param description the library description
+ * @param contents the initial contents of the library's volumes, as a map from volume type to volume content
+ * @return a newly created library
+ * @throws IOException if the new definition could not be stored
+ * @throws IllegalArgumentException if the library type or one of the content volume types is not supported,
+ * or if a library of the same name already exists in this manager
+ * @see ArealLibraryProvider#createLibrary
+ * @since org.netbeans.modules.project.libraries/1 1.31
+ */
+ public Library createLibrary(
+ @NonNull final String type,
+ @NonNull final String name,
+ @NullAllowed final String displayName,
+ @NullAllowed final String description,
+ @NonNull final Map> contents) throws IOException {
if (getLibrary(name) != null) {
throw new IllegalArgumentException("Name already in use: " + name); // NOI18N
}
@@ -297,6 +323,7 @@
}
impl = ltp.createLibrary();
impl.setName(name);
+ Util.setDisplayName(impl, displayName);
for (Map.Entry> entry : contents.entrySet()) {
impl.setContent(entry.getKey(), entry.getValue());
}
@@ -307,6 +334,7 @@
cont.put(entry.getKey(), LibrariesModel.convertURLsToURIs(entry.getValue()));
}
impl = LibraryAccessor.createLibrary(alp, type, name, area, cont);
+ Util.setDisplayName(impl, displayName);
}
return new Library(impl, this);
}
@@ -321,9 +349,32 @@
* @throws IllegalArgumentException if the library type or one of the content volume types is not supported,
* or if a library of the same name already exists in this manager
* @see ArealLibraryProvider#createLibrary
+ * @since org.netbeans.modules.project.libraries/1 1.31
+ */
+ public Library createURILibrary(String type, String name, Map> contents) throws IOException {
+ return createURILibrary(type, name, null, null, contents);
+ }
+
+ /**
+ * Creates a new library definition and adds it to the list.
+ * @param type the type of library, as in {@link LibraryTypeProvider#getLibraryType} or {@link LibraryImplementation#getType}
+ * @param name the identifying name of the new library (must not duplicate a name already in use by a library in this manager)
+ * @param displayName the display name of the library. If null the identifying name is used
+ * @param description the library description
+ * @param contents the initial contents of the library's volumes, as a map from volume type to volume content
+ * @return a newly created library
+ * @throws IOException if the new definition could not be stored
+ * @throws IllegalArgumentException if the library type or one of the content volume types is not supported,
+ * or if a library of the same name already exists in this manager
+ * @see ArealLibraryProvider#createLibrary
* @since org.netbeans.modules.project.libraries/1 1.18
*/
- public Library createURILibrary(String type, String name, Map> contents) throws IOException {
+ public Library createURILibrary(
+ @NonNull final String type,
+ @NonNull final String name,
+ @NullAllowed final String displayName,
+ @NullAllowed final String description,
+ @NonNull final Map> contents) throws IOException {
if (getLibrary(name) != null) {
throw new IllegalArgumentException("Name already in use: " + name); // NOI18N
}
@@ -335,13 +386,15 @@
}
impl = ltp.createLibrary();
impl.setName(name);
+ Util.setDisplayName(impl, displayName);
for (Map.Entry> entry : contents.entrySet()) {
impl.setContent(entry.getKey(), LibrariesModel.convertURIsToURLs(entry.getValue()));
}
Lookup.getDefault().lookup(WritableLibraryProvider.class).addLibrary(impl);
} else {
impl = LibraryAccessor.createLibrary(alp, type, name, area, contents);
- }
+ Util.setDisplayName(impl, displayName);
+ }
return new Library(impl, this);
}
diff --git a/project.libraries/src/org/netbeans/modules/project/libraries/DefaultLibraryImplementation.java b/project.libraries/src/org/netbeans/modules/project/libraries/DefaultLibraryImplementation.java
--- a/project.libraries/src/org/netbeans/modules/project/libraries/DefaultLibraryImplementation.java
+++ b/project.libraries/src/org/netbeans/modules/project/libraries/DefaultLibraryImplementation.java
@@ -45,12 +45,14 @@
package org.netbeans.modules.project.libraries;
import java.net.URL;
-import org.netbeans.spi.project.libraries.LibraryImplementation;
import java.util.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
+import org.netbeans.api.annotations.common.CheckForNull;
+import org.netbeans.api.annotations.common.NullAllowed;
+import org.netbeans.spi.project.libraries.NamedLibraryImplementation;
-public final class DefaultLibraryImplementation implements LibraryImplementation {
+public final class DefaultLibraryImplementation implements NamedLibraryImplementation {
private String description;
@@ -63,6 +65,8 @@
private String localizingBundle;
+ private String displayName;
+
private List listeners;
/**
@@ -78,20 +82,24 @@
}
+ @Override
public String getType() {
return libraryType;
}
+ @Override
public void setName(final String name) throws UnsupportedOperationException {
String oldName = this.name;
this.name = name;
this.firePropertyChange (PROP_NAME, oldName, this.name);
}
+ @Override
public String getName() {
return name;
}
+ @Override
public List getContent(String contentType) throws IllegalArgumentException {
List content = contents.get(contentType);
if (content == null)
@@ -99,6 +107,7 @@
return Collections.unmodifiableList (content);
}
+ @Override
public void setContent(String contentType, List path) throws IllegalArgumentException {
if (path == null) {
throw new IllegalArgumentException ();
@@ -112,37 +121,53 @@
}
}
+ @Override
public String getDescription () {
return this.description;
}
+ @Override
public void setDescription (String text) {
String oldDesc = this.description;
this.description = text;
this.firePropertyChange (PROP_DESCRIPTION, oldDesc, this.description);
}
+ @Override
public String getLocalizingBundle() {
return this.localizingBundle;
}
+ @Override
public void setLocalizingBundle(String resourceName) {
this.localizingBundle = resourceName;
}
+ @Override
+ public @CheckForNull String getDisplayName() {
+ return this.displayName;
+ }
+
+ public void setDisplayName(final @NullAllowed String displayName) {
+ this.displayName = displayName;
+ }
+
+ @Override
public synchronized void addPropertyChangeListener (PropertyChangeListener l) {
if (this.listeners == null)
this.listeners = new ArrayList();
this.listeners.add (l);
}
+ @Override
public synchronized void removePropertyChangeListener (PropertyChangeListener l) {
if (this.listeners == null)
return;
this.listeners.remove (l);
}
- public @Override String toString() {
+ @Override
+ public String toString() {
return "DefaultLibraryImplementation[" + name + "]"; // NOI18N
}
diff --git a/project.libraries/src/org/netbeans/modules/project/libraries/LibrariesStorage.java b/project.libraries/src/org/netbeans/modules/project/libraries/LibrariesStorage.java
--- a/project.libraries/src/org/netbeans/modules/project/libraries/LibrariesStorage.java
+++ b/project.libraries/src/org/netbeans/modules/project/libraries/LibrariesStorage.java
@@ -53,7 +53,6 @@
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
@@ -64,7 +63,6 @@
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.xml.parsers.ParserConfigurationException;
-import org.netbeans.modules.project.libraries.ui.LibrariesCustomizer;
import org.netbeans.spi.project.libraries.LibraryImplementation;
import org.netbeans.spi.project.libraries.LibraryTypeProvider;
import org.openide.filesystems.FileChangeAdapter;
@@ -75,9 +73,6 @@
import org.openide.filesystems.FileUtil;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
-import org.openide.xml.XMLUtil;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -177,7 +172,7 @@
}
librariesByFileNames.put(descriptorFile.getPath(),impl);
libraries.put (impl.getName(),impl);
- LibrariesCustomizer.registerSource(impl, descriptorFile);
+ Util.registerSource(impl, descriptorFile);
}
}
} catch (SAXException e) {
@@ -235,7 +230,7 @@
final LibraryDeclarationParser parser = new LibraryDeclarationParser(handler,convertor);
handler.setLibrary (impl);
readLibrary (descriptorFile, parser);
- LibrariesCustomizer.registerSource(impl, descriptorFile);
+ Util.registerSource(impl, descriptorFile);
return handler.getLibrary();
}
@@ -261,58 +256,24 @@
return;
}
FileObject fo = storage.createData (library.getName(),"xml"); //NOI18N
- writeLibraryDefinition (fo, library, libraryTypeProvider);
+ LibraryDeclarationParser.writeLibraryDefinition (fo, library, libraryTypeProvider);
}
}
);
}
-
- private static void writeLibraryDefinition (final FileObject definitionFile, final LibraryImplementation library, final LibraryTypeProvider libraryTypeProvider) throws IOException {
- Document doc = XMLUtil.createDocument("library", null,
- "-//NetBeans//DTD Library Declaration 1.0//EN",
- "http://www.netbeans.org/dtds/library-declaration-1_0.dtd"); // NOI18N
- Element libraryE = doc.getDocumentElement();
- libraryE.setAttribute("version", "1.0"); // NOI18N
- libraryE.appendChild(doc.createElement("name")).appendChild(doc.createTextNode(library.getName())); // NOI18N
- libraryE.appendChild(doc.createElement("type")).appendChild(doc.createTextNode(library.getType())); // NOI18N
- String description = library.getDescription();
- if (description != null && description.length() > 0) {
- libraryE.appendChild(doc.createElement("description")).appendChild(doc.createTextNode(description)); // NOI18N
- }
- String localizingBundle = library.getLocalizingBundle();
- if (localizingBundle != null && localizingBundle.length() > 0) {
- libraryE.appendChild(doc.createElement("localizing-bundle")).appendChild(doc.createTextNode(localizingBundle)); // NOI18N
- }
- for (String vtype : libraryTypeProvider.getSupportedVolumeTypes()) {
- Element volumeE = (Element) libraryE.appendChild(doc.createElement("volume")); // NOI18N
- volumeE.appendChild(doc.createElement("type")).appendChild(doc.createTextNode(vtype)); // NOI18N
- List volume = library.getContent(vtype);
- if (volume != null) {
- //If null -> broken library, repair it.
- for (URL url : volume) {
- volumeE.appendChild(doc.createElement("resource")).appendChild(doc.createTextNode(url.toString())); // NOI18N
- }
- }
- }
- OutputStream os = definitionFile.getOutputStream();
- try {
- XMLUtil.write(doc, os, "UTF-8"); // NOI18N
- } finally {
- os.close();
- }
- }
-
-
+
private void fireLibrariesChanged () {
this.support.firePropertyChange(PROP_LIBRARIES,null,null);
}
+ @Override
public final void addPropertyChangeListener (PropertyChangeListener listener) {
this.support.addPropertyChangeListener(listener);
}
+ @Override
public final void removePropertyChangeListener (PropertyChangeListener listener) {
this.support.removePropertyChangeListener(listener);
}
@@ -320,6 +281,7 @@
/**
* Return all libraries in memory.
*/
+ @Override
public final LibraryImplementation[] getLibraries() {
final Libs res = initStorage();
assert res != null;
@@ -327,12 +289,14 @@
} // end getLibraries
+ @Override
public void addLibrary (LibraryImplementation library) throws IOException {
this.initStorage();
assert this.storage != null : "Storage is not initialized";
writeLibrary(this.storage,library);
}
+ @Override
public void removeLibrary (LibraryImplementation library) throws IOException {
final Libs data = this.initStorage();
assert this.storage != null : "Storage is not initialized";
@@ -345,6 +309,7 @@
}
}
+ @Override
public void updateLibrary(final LibraryImplementation oldLibrary, final LibraryImplementation newLibrary) throws IOException {
final Libs data = this.initStorage();
assert this.storage != null : "Storage is not initialized";
@@ -361,7 +326,7 @@
this.storage.getFileSystem().runAtomicAction(
new FileSystem.AtomicAction() {
public void run() throws IOException {
- writeLibraryDefinition (fo, newLibrary, libraryTypeProvider);
+ LibraryDeclarationParser.writeLibraryDefinition (fo, newLibrary, libraryTypeProvider);
}
}
);
diff --git a/project.libraries/src/org/netbeans/modules/project/libraries/LibraryDeclarationHandler.java b/project.libraries/src/org/netbeans/modules/project/libraries/LibraryDeclarationHandler.java
--- a/project.libraries/src/org/netbeans/modules/project/libraries/LibraryDeclarationHandler.java
+++ b/project.libraries/src/org/netbeans/modules/project/libraries/LibraryDeclarationHandler.java
@@ -91,7 +91,7 @@
* @param meta attributes
*
*/
- public void start_library(final Attributes meta) throws SAXException;
+ public String start_library(final String nameSpace, final Attributes meta) throws SAXException;
/**
* A container element end event handling method.
@@ -117,5 +117,7 @@
public void handle_localizingBundle (final String data, final Attributes meta) throws SAXException;
+ public void handle_displayName (String data, Attributes meta) throws SAXException;
+
}
diff --git a/project.libraries/src/org/netbeans/modules/project/libraries/LibraryDeclarationHandlerImpl.java b/project.libraries/src/org/netbeans/modules/project/libraries/LibraryDeclarationHandlerImpl.java
--- a/project.libraries/src/org/netbeans/modules/project/libraries/LibraryDeclarationHandlerImpl.java
+++ b/project.libraries/src/org/netbeans/modules/project/libraries/LibraryDeclarationHandlerImpl.java
@@ -53,8 +53,10 @@
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
+import java.util.regex.Pattern;
import org.netbeans.spi.project.libraries.LibraryImplementation;
import org.netbeans.spi.project.libraries.LibraryTypeProvider;
+import org.openide.util.Utilities;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
@@ -68,11 +70,11 @@
private LibraryImplementation library;
-
private String libraryType;
private String libraryDescription;
private String libraryName;
private String localizingBundle;
+ private String displayName;
private Map> contentTypes = new HashMap>();
// last volume
@@ -122,8 +124,13 @@
}
@Override
- public void start_library(final Attributes meta) throws SAXException {
- if ("1.0".equals(meta.getValue("version")) == false) { // NOI18N
+ public String start_library(final String nameSpace, final Attributes meta) throws SAXException {
+ final String version = meta.getValue("version");
+ if (LibraryDeclarationParser.VER_1.equals(version)) {
+ return ""; //NOI18N
+ } else if (LibraryDeclarationParser.VER_2.equals(version)) {
+ return LibraryDeclarationParser.LIBRARY_NS;
+ } else {
throw new SAXException("Invalid librray descriptor version"); // NOI18N
}
}
@@ -137,8 +144,7 @@
library.getType()+" to: " + libraryType, null); //NOI18N
}
update = true;
- }
- else {
+ } else {
if (this.libraryType == null) {
throw new SAXParseException("Unspecified library type for: "+this.libraryName, null); //NOI18N
}
@@ -150,15 +156,18 @@
update = false;
LibrariesStorage.LOG.log(Level.FINE, "LibraryDeclarationHandlerImpl library {0} type {1} found", new Object[] { this.libraryName, this.libraryType });
}
- if (!update || !safeEquals(this.library.getLocalizingBundle(), localizingBundle)) {
+ if (!update || !Utilities.compareObjects(this.library.getLocalizingBundle(), localizingBundle)) {
this.library.setLocalizingBundle (this.localizingBundle);
}
- if (!update || !safeEquals(this.library.getName(), libraryName)) {
+ if (!update || !Utilities.compareObjects(this.library.getName(), libraryName)) {
this.library.setName (this.libraryName);
}
- if (!update || !safeEquals(this.library.getDescription(), libraryDescription)) {
+ if (!update || !Utilities.compareObjects(this.library.getDescription(), libraryDescription)) {
this.library.setDescription (this.libraryDescription);
}
+ if (!update || !Utilities.compareObjects(this.library.getLocalizingBundle(), displayName)) {
+ Util.setDisplayName(this.library,displayName);
+ }
for (Map.Entry> entry : contentTypes.entrySet()) {
String contentType = entry.getKey();
List cp = entry.getValue();
@@ -194,6 +203,11 @@
this.localizingBundle = data;
}
+ @Override
+ public void handle_displayName (String data, Attributes meta) throws SAXException {
+ this.displayName = data;
+ }
+
public void setLibrary (LibraryImplementation library) {
this.library = library;
}
@@ -203,10 +217,6 @@
}
- private static boolean safeEquals (Object o1, Object o2) {
- return o1 == null ? o2 == null : o1.equals (o2);
- }
-
private static boolean urlsEqual (final Collection extends URL> first, final Collection extends URL> second) {
assert first != null;
assert second != null;
diff --git a/project.libraries/src/org/netbeans/modules/project/libraries/LibraryDeclarationParser.java b/project.libraries/src/org/netbeans/modules/project/libraries/LibraryDeclarationParser.java
--- a/project.libraries/src/org/netbeans/modules/project/libraries/LibraryDeclarationParser.java
+++ b/project.libraries/src/org/netbeans/modules/project/libraries/LibraryDeclarationParser.java
@@ -47,10 +47,20 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.List;
import java.util.Stack;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.xml.parsers.ParserConfigurationException;
+import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.spi.project.libraries.LibraryImplementation;
+import org.netbeans.spi.project.libraries.LibraryTypeProvider;
+import org.netbeans.spi.project.libraries.NamedLibraryImplementation;
+import org.openide.filesystems.FileObject;
import org.openide.xml.XMLUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.EntityResolver;
@@ -75,10 +85,26 @@
*/
public class LibraryDeclarationParser implements ContentHandler, EntityResolver {
+ private static final String LIBRARY_DEF_1 = "-//NetBeans//DTD Library Declaration 1.0//EN"; //NOI18N
+ private static final String LIBRARY_DTD_1 = "http://www.netbeans.org/dtds/library-declaration-1_0.dtd"; //NOI18N
+ static final String LIBRARY_NS = "http://www.netbeans.org/ns/library-declaration/2"; //NOI18N
+ static final String VER_1 = "1.0"; //NOI18N
+ static final String VER_2 = "2.0"; //NOI18N
+ private static final String LIBRARY = "library"; //NOI18N
+ private static final String VERSION = "version"; //NOI18N
+ private static final String VOLUME = "volume"; //NOI18N
+ private static final String DESCRIPTION = "description"; //NOI18N
+ private static final String TYPE = "type"; //NOI18N
+ private static final String RESOURCE = "resource"; //NOI18N
+ private static final String NAME = "name"; //NOI18N
+ private static final String BUNDLE = "localizing-bundle"; //NOI18N
+ private static final String DISPLAY_NAME = "display-name"; //NOI18N
+
private StringBuffer buffer;
private final LibraryDeclarationConvertor parslet;
private final LibraryDeclarationHandler handler;
private Stack