001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.visualweb.project.jsf.libraries;
043:
044: import org.netbeans.modules.visualweb.project.jsf.libraries.provider.ComponentLibraryTypeProvider;
045:
046: import java.io.IOException;
047: import java.net.URL;
048: import java.util.ArrayList;
049: import java.util.Iterator;
050: import java.util.List;
051:
052: import org.netbeans.api.project.Project;
053: import org.netbeans.api.project.libraries.Library;
054: import org.netbeans.api.project.libraries.LibraryManager;
055: import org.netbeans.spi.project.libraries.LibraryFactory;
056: import org.netbeans.spi.project.libraries.LibraryImplementation;
057: import org.netbeans.spi.project.libraries.LibraryTypeProvider;
058: import org.netbeans.spi.project.libraries.support.LibrariesSupport;
059:
060: /**
061: *
062: * @author Po-Ting Wu
063: */
064: public class ComponentLibraryDefinition extends LibraryDefinition {
065: /**
066: * Create a library definition with specified resources.
067: * @param name Internal name of the library from which the library definition file name will be derived as
068: * as well as the display name for the library
069: * @param description Description key to look up a text description from the localizingBundle
070: * @param localizingBundle Sets the localizing bundle. The bundle is used for localizing the name and
071: * description. The bundle is located using the system ClassLoader. This resource name will look
072: * something like: org.netbeans.modules.visualweb.mymodule.Bundle
073: * @param classPaths List of classpath references: jar, zip, or folder. Can be empty or null.
074: * @param javadocs List of javadoc references, jar zip, or folder. Can be empty or null.
075: * @param sources, List of jar, zip, or folder. Can be empty or null;
076: * @return Library The new Library instance registered with the NetBeans Library Manager
077: * @throws IOException if the library definition already exists or could not be created
078: */
079: public static Library create(String name, String description,
080: String localizingBundle, List<URL> classPaths,
081: List<URL> sources, List<URL> javadocs, List<URL> designtimes)
082: throws IOException {
083: LibraryImplementation impl = LibrariesSupport
084: .createLibraryImplementation(
085: ComponentLibraryTypeProvider.LIBRARY_TYPE,
086: ComponentLibraryTypeProvider.VOLUME_TYPES);
087: impl.setName(name);
088: impl.setDescription(description);
089: impl.setLocalizingBundle(localizingBundle);
090: if (classPaths != null) {
091: ArrayList a = new ArrayList(classPaths.size());
092: for (Iterator i = classPaths.iterator(); i.hasNext();) {
093: a.add(toResourceURL((URL) i.next()));
094: }
095: impl.setContent("classpath", a); // NOI18N
096: }
097: if (sources != null) {
098: ArrayList a = new ArrayList(sources.size());
099: for (Iterator i = sources.iterator(); i.hasNext();) {
100: a.add(toResourceURL((URL) i.next()));
101: }
102: impl.setContent("src", a); // NOI18N
103: }
104: if (javadocs != null) {
105: ArrayList a = new ArrayList(javadocs.size());
106: for (Iterator i = javadocs.iterator(); i.hasNext();) {
107: a.add(toResourceURL((URL) i.next()));
108: }
109: impl.setContent("javadoc", a); // NOI18N
110: }
111: if (designtimes != null) {
112: ArrayList a = new ArrayList(designtimes.size());
113: for (Iterator i = designtimes.iterator(); i.hasNext();) {
114: a.add(toResourceURL((URL) i.next()));
115: }
116: impl.setContent("visual-web-designtime", a); // NOI18N
117: }
118:
119: Library lib = LibraryFactory.createLibrary(impl);
120: LibraryManager.getDefault().addLibrary(lib);
121:
122: return lib;
123: }
124:
125: /**
126: * Convenience method to update an existing library definition with specified resources.
127: * @param name Internal name of the existing library from which the library definition file name
128: * will be derived as as well as the display name for the library
129: * @param description Description key to look up a text description from the localizingBundle
130: * @param localizingBundle Sets the localizing bundle. The bundle is used for localizing the name and
131: * description. The bundle is located using the system ClassLoader. This resource name will look
132: * something like: org.netbeans.modules.visualweb.mymodule.Bundle
133: * @param classPaths List of classpath references: jar, zip, or folder. Can be empty or null.
134: * @param javadocs List of javadoc references, jar zip, or folder. Can be empty or null.
135: * @param sources, List of jar, zip, or folder. Can be empty or null;
136: * @return Library The new Library instance registered with the NetBeans Library Manager
137: * @throws IOException if the library definition did not already exist or could not be updated
138: */
139:
140: public static Library update(String name, String description,
141: String localizingBundle, List<URL> classPaths,
142: List<URL> sources, List<URL> javadocs, List<URL> designtimes)
143: throws IOException {
144: remove(name);
145: return create(name, description, localizingBundle, classPaths,
146: sources, javadocs, designtimes);
147: }
148: }
|