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-2006 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.apisupport.project.universe;
043:
044: import java.util.Comparator;
045:
046: /**
047: * Represents one test dependency. I.e. <em><test-dependency></em>
048: * element in module's <em>project.xml</em>.
049: *
050: * @author pzajac
051: */
052: public class TestModuleDependency implements Comparable {
053:
054: public static final String UNIT = "unit"; // NOI18N
055: public static final String QA_FUNCTIONAL = "qa-functional"; // NOI18N
056:
057: private final ModuleEntry module;
058: // depends also on tests of modules
059: private boolean test;
060: // depends on execution classpath of the modules
061: private boolean recursive;
062: // compilation dependency
063: private boolean compile;
064:
065: public static final Comparator<TestModuleDependency> CNB_COMPARATOR = new Comparator<TestModuleDependency>() {
066: public int compare(TestModuleDependency tmd1,
067: TestModuleDependency tmd2) {
068: return (tmd1).module.getCodeNameBase().compareTo(
069: (tmd2).module.getCodeNameBase());
070: }
071: };
072:
073: /**
074: * Creates a new instance of TestModuleDependency
075: */
076: public TestModuleDependency(ModuleEntry me, boolean test,
077: boolean recursive, boolean compile) {
078: this .module = me;
079: this .test = test;
080: this .recursive = recursive;
081: this .compile = compile;
082: }
083:
084: public ModuleEntry getModule() {
085: return module;
086: }
087:
088: public boolean isTest() {
089: return test;
090: }
091:
092: public void setTest(boolean test) {
093: this .test = test;
094: }
095:
096: public boolean isRecursive() {
097: return recursive;
098: }
099:
100: public void setRecursive(boolean recursive) {
101: this .recursive = recursive;
102: }
103:
104: public boolean isCompile() {
105: return compile;
106: }
107:
108: public void setCompile(boolean compile) {
109: this .compile = compile;
110: }
111:
112: // td1 equals td2 iff cnb and all three boolean fileds of td are the same
113: public boolean equals(Object o) {
114: if (o instanceof TestModuleDependency) {
115: TestModuleDependency tmd = (TestModuleDependency) o;
116: return tmd.isCompile() == this .isCompile()
117: && tmd.isRecursive() == this .isRecursive()
118: && tmd.isTest() == this .isTest()
119: && tmd.getModule().getCodeNameBase().equals(
120: this .getModule().getCodeNameBase());
121: } else {
122: return false;
123: }
124: }
125:
126: //compare only on cnb. ATTENTION, compareTo is not consistent with equals method!
127: //i.e. two instances of TestModuleDependency can be nonequal, and tmd1.compareTo(tmd2)
128: // can return 0
129: public int compareTo(Object o) {
130: TestModuleDependency tmd = (TestModuleDependency) o;
131: return this .module.getCodeNameBase().compareTo(
132: tmd.module.getCodeNameBase());
133: }
134:
135: //hash from CNB only
136: public int hashCode() {
137: int hash = module.getCodeNameBase().hashCode();
138: // if(test) hash*=5;
139: // if(recursive) hash*=7;
140: // if(compile) hash*=11;
141: return hash;
142: }
143: }
|