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 java.io.IOException;
045: import java.net.URL;
046: import java.util.ArrayList;
047: import java.util.Iterator;
048: import java.util.List;
049:
050: import org.netbeans.api.project.Project;
051: import org.netbeans.api.project.libraries.Library;
052: import org.netbeans.api.project.libraries.LibraryManager;
053: import org.netbeans.spi.project.libraries.LibraryFactory;
054: import org.netbeans.spi.project.libraries.LibraryImplementation;
055: import org.netbeans.spi.project.libraries.LibraryTypeProvider;
056: import org.netbeans.spi.project.libraries.support.LibrariesSupport;
057:
058: /**
059: *
060: * @author Po-Ting Wu
061: */
062: public class J2SELibraryDefinition extends LibraryDefinition {
063: /**
064: * Create a library definition with specified resources.
065: * @param name Internal name of the library from which the library definition file name will be derived as
066: * as well as the display name for the library
067: * @param description Description key to look up a text description from the localizingBundle
068: * @param localizingBundle Sets the localizing bundle. The bundle is used for localizing the name and
069: * description. The bundle is located using the system ClassLoader. This resource name will look
070: * something like: org.netbeans.modules.visualweb.mymodule.Bundle
071: * @param classPaths List of classpath references: jar, zip, or folder. Can be empty or null.
072: * @param javadocs List of javadoc references, jar zip, or folder. Can be empty or null.
073: * @param sources, List of jar, zip, or folder. Can be empty or null;
074: * @return Library The new Library instance registered with the NetBeans Library Manager
075: * @throws IOException if the library definition already exists or could not be created
076: */
077: public static Library create(String name, String description,
078: String localizingBundle, List<URL> classPaths,
079: List<URL> sources, List<URL> javadocs) throws IOException {
080: LibraryManager libraryManager = LibraryManager.getDefault();
081: LibraryImplementation impl = LibrariesSupport
082: .getLibraryTypeProvider("j2se").createLibrary();
083:
084: impl.setName(name);
085: impl.setDescription(description);
086: impl.setLocalizingBundle(localizingBundle);
087: if (classPaths != null) {
088: ArrayList a = new ArrayList(classPaths.size());
089: for (Iterator i = classPaths.iterator(); i.hasNext();) {
090: a.add(toResourceURL((URL) i.next()));
091: }
092: impl.setContent("classpath", a); // NOI18N
093: }
094: if (sources != null) {
095: ArrayList a = new ArrayList(sources.size());
096: for (Iterator i = sources.iterator(); i.hasNext();) {
097: a.add(toResourceURL((URL) i.next()));
098: }
099: impl.setContent("src", a); // NOI18N
100: }
101: if (javadocs != null) {
102: ArrayList a = new ArrayList(javadocs.size());
103: for (Iterator i = javadocs.iterator(); i.hasNext();) {
104: a.add(toResourceURL((URL) i.next()));
105: }
106: impl.setContent("javadoc", a); // NOI18N
107: }
108:
109: Library lib = LibraryFactory.createLibrary(impl);
110: libraryManager.addLibrary(lib);
111:
112: return lib;
113: }
114:
115: /**
116: * Convenience method to update an existing library definition with specified resources.
117: * @param name Internal name of the existing library from which the library definition file name
118: * will be derived as as well as the display name for the library
119: * @param description Description key to look up a text description from the localizingBundle
120: * @param localizingBundle Sets the localizing bundle. The bundle is used for localizing the name and
121: * description. The bundle is located using the system ClassLoader. This resource name will look
122: * something like: org.netbeans.modules.visualweb.mymodule.Bundle
123: * @param classPaths List of classpath references: jar, zip, or folder. Can be empty or null.
124: * @param javadocs List of javadoc references, jar zip, or folder. Can be empty or null.
125: * @param sources, List of jar, zip, or folder. Can be empty or null;
126: * @return Library The new Library instance registered with the NetBeans Library Manager
127: * @throws IOException if the library definition did not already exist or could not be updated
128: */
129:
130: public static Library update(String name, String description,
131: String localizingBundle, List<URL> classPaths,
132: List<URL> sources, List<URL> javadocs) throws IOException {
133: remove(name);
134: return create(name, description, localizingBundle, classPaths,
135: sources, javadocs);
136: }
137: }
|