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: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2007 Sun Microsystems, Inc.
038: */
039:
040: package org.netbeans.modules.apisupport.project.universe;
041:
042: import java.io.File;
043: import java.io.IOException;
044: import java.util.Collections;
045: import java.util.HashMap;
046: import java.util.Map;
047: import java.util.Set;
048: import java.util.logging.Level;
049: import java.util.logging.Logger;
050: import org.netbeans.modules.apisupport.project.ManifestManager.PackageExport;
051: import org.openide.filesystems.FileUtil;
052:
053: /**
054: * A netbeans.org module as described by nbbuild/nbproject/private/scan-cache-full.ser.
055: * See org.netbeans.nbbuild.ModuleListParser.{scanNetBeansOrgSources,Entry} for details.
056: */
057: final class NetBeansOrgCachedEntry extends AbstractEntryWithSources {
058:
059: private static final Logger LOG = Logger
060: .getLogger(NetBeansOrgCachedEntry.class.getName());
061:
062: private final File nb_all;
063: private final File nbdestdir;
064: private final String cnb;
065: private final File jar;
066: private final String classPathExtensions;
067: private final File sourceLocation;
068: private final String netbeansOrgPath;
069: private final String[] buildPrerequisites;
070: private final File cluster;
071: private final String[] runtimeDependencies;
072: private final String[] testDependencies;
073: private ModuleEntry officialEntry;
074:
075: public NetBeansOrgCachedEntry(File nb_all, File nbdestdir,
076: String cnb, File jar, File[] classPathExtensions,
077: File sourceLocation, String netbeansOrgPath,
078: String[] buildPrerequisites, String clusterName,
079: String[] runtimeDependencies, String[] testDependencies) {
080: super (/* will not be used */null);
081: this .nb_all = nb_all;
082: this .nbdestdir = FileUtil.normalizeFile(nbdestdir);
083: this .cnb = cnb;
084: this .jar = FileUtil.normalizeFile(jar);
085: StringBuilder b = new StringBuilder();
086: for (File f : classPathExtensions) {
087: b.append(File.pathSeparatorChar);
088: b.append(FileUtil.normalizeFile(f).getAbsolutePath());
089: }
090: this .classPathExtensions = b.toString();
091: this .sourceLocation = FileUtil.normalizeFile(sourceLocation);
092: this .netbeansOrgPath = netbeansOrgPath;
093: this .buildPrerequisites = buildPrerequisites;
094: this .cluster = new File(this .nbdestdir, clusterName);
095: this .runtimeDependencies = runtimeDependencies;
096: this .testDependencies = testDependencies;
097: }
098:
099: public String getNetBeansOrgPath() {
100: return netbeansOrgPath;
101: }
102:
103: public File getSourceLocation() {
104: return sourceLocation;
105: }
106:
107: public String getCodeNameBase() {
108: return cnb;
109: }
110:
111: public File getClusterDirectory() {
112: return cluster;
113: }
114:
115: public File getJarLocation() {
116: return jar;
117: }
118:
119: public String getClassPathExtensions() {
120: if (officialEntry != null) {
121: // This is preferable because it may take into account <binary-origin> in project.xml.
122: return officialEntry.getClassPathExtensions();
123: } else {
124: return classPathExtensions;
125: }
126: }
127:
128: public File getDestDir() {
129: return nbdestdir;
130: }
131:
132: private synchronized void ensureOfficialEntry(String why) {
133: if (officialEntry == null) {
134: LOG.fine("Had to fall back to loading official entry for "
135: + cnb + " because of " + why);
136: Map<String, ModuleEntry> entries = new HashMap<String, ModuleEntry>();
137: try {
138: ModuleList.scanPossibleProject(sourceLocation, entries,
139: false, false, nb_all, nbdestdir,
140: netbeansOrgPath, false);
141: officialEntry = entries.get(cnb);
142: if (officialEntry == null) {
143: LOG
144: .fine("Failed to load official entry for "
145: + cnb);
146: }
147: } catch (IOException x) {
148: LOG.log(Level.FINE, null, x);
149: }
150: }
151: }
152:
153: public String getReleaseVersion() {
154: ensureOfficialEntry("getReleaseVersion");
155: if (officialEntry != null) {
156: return officialEntry.getReleaseVersion();
157: } else {
158: return null;
159: }
160: }
161:
162: public String[] getProvidedTokens() {
163: ensureOfficialEntry("getProvidedTokens");
164: if (officialEntry != null) {
165: return officialEntry.getProvidedTokens();
166: } else {
167: return new String[0];
168: }
169: }
170:
171: public PackageExport[] getPublicPackages() {
172: ensureOfficialEntry("getPublicPackages");
173: if (officialEntry != null) {
174: return officialEntry.getPublicPackages();
175: } else {
176: return new PackageExport[0];
177: }
178: }
179:
180: public boolean isDeclaredAsFriend(String cnb) {
181: ensureOfficialEntry("isDeclaredAsFriend");
182: if (officialEntry != null) {
183: return officialEntry.isDeclaredAsFriend(cnb);
184: } else {
185: return false;
186: }
187: }
188:
189: public boolean isDeprecated() {
190: ensureOfficialEntry("isDeprecated");
191: if (officialEntry != null) {
192: return officialEntry.isDeprecated();
193: } else {
194: return false;
195: }
196: }
197:
198: public @Override
199: Set<String> getPublicClassNames() {
200: ensureOfficialEntry("getPublicClassNames");
201: if (officialEntry != null) {
202: return officialEntry.getPublicClassNames();
203: } else {
204: return Collections.emptySet();
205: }
206: }
207:
208: public @Override
209: String toString() {
210: return "NetBeansOrgCachedEntry[" + getSourceLocation()
211: + (officialEntry != null ? "->" + officialEntry : "")
212: + "]"; // NOI18N
213: }
214:
215: }
|