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.nbbuild;
041:
042: import java.io.IOException;
043: import java.util.Hashtable;
044: import org.apache.tools.ant.BuildException;
045: import org.apache.tools.ant.Project;
046: import org.apache.tools.ant.ProjectComponent;
047: import org.apache.tools.ant.taskdefs.condition.Condition;
048:
049: /**
050: * Condition that determines whether a given module exports an API.
051: * This is true if any of the following hold:
052: * <ol>
053: * <li>The module lists public API packages.
054: * <li>The module lists friend API packages, and at least one friend is external (not known in module universe).
055: * <li>The module lists friend API packages, and at least one friend is located in a different cluster.
056: * </ol>
057: * This condition must be called from a module build, which is why it accepts no parameters:
058: * various properties are picked up from the project. Only works for nb.org modules.
059: */
060: public class ExportedAPICondition extends ProjectComponent implements
061: Condition {
062:
063: public boolean eval() throws BuildException {
064: @SuppressWarnings("unchecked")
065: Hashtable<String, String> props = getProject().getProperties();
066: if (props.get("public.packages").equals("-")) {
067: log("No exported packages", Project.MSG_VERBOSE);
068: return false;
069: }
070: String friends = props.get("friends");
071: if (friends == null) {
072: log("Public API", Project.MSG_VERBOSE);
073: return true;
074: }
075: ModuleListParser mlp;
076: try {
077: mlp = new ModuleListParser(props,
078: ParseProjectXml.TYPE_NB_ORG, getProject());
079: } catch (IOException x) {
080: throw new BuildException(x, getLocation());
081: }
082: String mycluster = mlp.findByCodeNameBase(
083: props.get("code.name.base.dashes").replace('-', '.'))
084: .getClusterName();
085: for (String friend : friends.split(", ")) {
086: ModuleListParser.Entry entry = mlp
087: .findByCodeNameBase(friend);
088: if (entry == null) {
089: log("External friend " + friend, Project.MSG_VERBOSE);
090: return true;
091: }
092: String cluster = entry.getClusterName();
093: if (!mycluster.equals(cluster)) {
094: log("Friend " + friend + " is in cluster " + cluster
095: + " rather than " + mycluster,
096: Project.MSG_VERBOSE);
097: return true;
098: }
099: }
100: log("No friends outside cluster", Project.MSG_VERBOSE);
101: return false;
102: }
103:
104: }
|