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.compapp.projects.jbi.api;
043:
044: import org.openide.filesystems.FileObject;
045:
046: import org.openide.loaders.DataFolder;
047: import org.openide.loaders.DataObject;
048: import org.openide.util.Lookup;
049: import org.netbeans.api.project.Project;
050: import org.netbeans.api.project.ant.AntArtifact;
051: import org.netbeans.spi.project.ant.AntArtifactProvider;
052:
053: import java.net.URL;
054: import java.util.*;
055:
056: /**
057: * DOCUMENT ME!
058: *
059: * @author
060: * @version
061: */
062: public class JbiInstalledProjectPluginInfo {
063:
064: private static JbiInstalledProjectPluginInfo singleton = null;
065:
066: // a list of Jbi Extension Info known at design time
067: private List<InternalProjectTypePlugin> extensionList = new ArrayList<InternalProjectTypePlugin>();
068: private List<InternalProjectTypePlugin> paletteList = new ArrayList<InternalProjectTypePlugin>();
069: private List<InternalProjectTypePlugin> nonPaletteList = new ArrayList<InternalProjectTypePlugin>();
070:
071: private JbiInstalledProjectPluginInfo() {
072: }
073:
074: /**
075: * Factory method for the default component list object
076: *
077: * @return the default component list object
078: */
079: public static JbiInstalledProjectPluginInfo getProjectPluginInfo() {
080: if (singleton == null) {
081: try {
082: singleton = new JbiInstalledProjectPluginInfo();
083:
084: Collection<? extends InternalProjectTypePlugin> projectPlugins = Lookup
085: .getDefault().lookupAll(
086: InternalProjectTypePlugin.class);
087:
088: for (InternalProjectTypePlugin projectPlugin : projectPlugins) {
089: singleton.extensionList.add(projectPlugin);
090: String category = projectPlugin.getCategoryName();
091: if (category != null) {
092: singleton.paletteList.add(projectPlugin);
093: } else {
094: singleton.nonPaletteList.add(projectPlugin);
095: }
096: }
097:
098: } catch (Exception ex) {
099: // failed... return withopt changing the selector content.
100: ex.printStackTrace();
101: }
102: }
103:
104: return singleton;
105: }
106:
107: /**
108: * Getter for the installed project plug-in info list
109: *
110: * @return the default installed project plug-in info list
111: */
112: public List<InternalProjectTypePlugin> getProjectPluginList() {
113: return extensionList;
114: }
115:
116: /**
117: * Getter for the categorized project plug-in info list
118: *
119: * @return the default categorized project plug-in info list
120: */
121: public List<InternalProjectTypePlugin> getCategorizedProjectPluginList() {
122: return paletteList;
123: }
124:
125: /**
126: * Getter for the uncategorized project plug-in info list
127: *
128: * @return the default uncategorized project plug-in info list
129: */
130: public List<InternalProjectTypePlugin> getUncategorizedProjectPluginList() {
131: return nonPaletteList;
132: }
133:
134: /**
135: * Check if the child project is an internal subproject of parent
136: *
137: * @param parent the parent project
138: * @param child the child project
139: * @return true, if it is an internal subproject
140: */
141: public static boolean isInternalSubproject(Project parent,
142: Project child) {
143: if ((parent != null) && (child != null)) {
144: String pPath = parent.getProjectDirectory().getPath();
145: String cPath = child.getProjectDirectory().getPath();
146: if ((pPath != null) && (cPath != null)) {
147: return cPath.startsWith(pPath);
148: }
149: }
150: return false;
151: }
152:
153: /**
154: * Get the plugin project type from a project
155: *
156: * @param project a project
157: * @return project plugin
158: */
159: public static InternalProjectTypePlugin getPlugin(Project project) {
160: if (project == null) {
161: return null;
162: }
163:
164: // get target component name
165: AntArtifactProvider prov = project.getLookup().lookup(
166: AntArtifactProvider.class);
167: String target = null;
168: if (prov != null) {
169: AntArtifact[] artifacts = prov.getBuildArtifacts();
170: if (artifacts != null) {
171: for (int i = 0; i < artifacts.length; i++) {
172: String type = artifacts[i].getType();
173: // System.out.println(i+": "+type);
174: if (type
175: .startsWith(JbiProjectConstants.ARTIFACT_TYPE_JBI_ASA)) {
176: target = type
177: .substring(JbiProjectConstants.ARTIFACT_TYPE_JBI_ASA
178: .length() + 1);
179: }
180: }
181: }
182: }
183: if (target == null) {
184: return null;
185: }
186:
187: // loop thru plugin list
188: JbiInstalledProjectPluginInfo info = JbiInstalledProjectPluginInfo
189: .getProjectPluginInfo();
190: if (info != null) {
191: List<InternalProjectTypePlugin> plugins = info
192: .getProjectPluginList();
193: for (InternalProjectTypePlugin plugin : plugins) {
194: if (target.equalsIgnoreCase(plugin.getJbiTargetName())) {
195: return plugin;
196: }
197: }
198: }
199: return null;
200: }
201: }
|