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.queries;
043:
044: import org.netbeans.api.java.classpath.ClassPath;
045: import org.netbeans.api.project.FileOwnerQuery;
046: import org.netbeans.api.project.Project;
047: import org.netbeans.api.project.ProjectManager;
048: import org.netbeans.modules.apisupport.project.TestBase;
049: import org.netbeans.spi.project.support.ant.PropertyUtils;
050: import org.openide.filesystems.FileObject;
051: import org.openide.filesystems.FileUtil;
052:
053: /**
054: * Test that project association by module inclusion list works.
055: * @author Jesse Glick
056: */
057: public class UpdateTrackingFileOwnerQueryTest extends TestBase {
058:
059: public UpdateTrackingFileOwnerQueryTest(String name) {
060: super (name);
061: }
062:
063: public void testOwnershipNetBeansOrg() throws Exception {
064: // Basic module:
065: assertOwnership("o.apache.tools.ant.module",
066: "nbbuild/netbeans/" + TestBase.CLUSTER_JAVA
067: + "/modules/org-apache-tools-ant-module.jar");
068: // Explicitly listed additions:
069: assertOwnership("o.apache.tools.ant.module",
070: "nbbuild/netbeans/" + TestBase.CLUSTER_JAVA
071: + "/ant/nblib/bridge.jar");
072: // Pattern matches (here "ant/lib/"):
073: assertTrue(
074: "ant module built (cannot scan by pattern unless files exist)",
075: file(
076: "nbbuild/netbeans/" + TestBase.CLUSTER_JAVA
077: + "/ant/lib/ant.jar").isFile());
078: assertOwnership("o.apache.tools.ant.module",
079: "nbbuild/netbeans/" + TestBase.CLUSTER_JAVA
080: + "/ant/lib/ant.jar");
081: // These two always included:
082: assertOwnership(
083: "o.apache.tools.ant.module",
084: "nbbuild/netbeans/"
085: + TestBase.CLUSTER_JAVA
086: + "/config/Modules/org-apache-tools-ant-module.xml");
087: assertOwnership(
088: "o.apache.tools.ant.module",
089: "nbbuild/netbeans/"
090: + TestBase.CLUSTER_JAVA
091: + "/update_tracking/org-apache-tools-ant-module.xml");
092: // Different pattern match ("modules/ext/jh*.jar"):
093: assertOwnership("javahelp", "nbbuild/netbeans/"
094: + TestBase.CLUSTER_PLATFORM
095: + "/modules/ext/jh-2.0_05.jar");
096: // Use of release dir:
097: assertOwnership("extbrowser", "nbbuild/netbeans/"
098: + TestBase.CLUSTER_IDE + "/modules/lib/extbrowser.dll");
099: }
100:
101: public void testOwnershipExternal() throws Exception {
102: // Will not normally exist when test is run:
103: assertOwnership(
104: resolveEEPPath("/suite1/action-project"),
105: resolveEEPPath("/suite1/build/cluster/modules/org-netbeans-examples-modules-action.jar"));
106: assertOwnership(
107: resolveEEPPath("/suite1/action-project"),
108: resolveEEPPath("/suite1/build/cluster/update_tracking/org-netbeans-examples-modules-action.xml"));
109: }
110:
111: private void assertOwnership(String project, String file)
112: throws Exception {
113: FileObject projectFO = FileUtil.toFileObject(PropertyUtils
114: .resolveFile(nbRootFile(), project));
115: assertNotNull("have project " + project, projectFO);
116: Project p = ProjectManager.getDefault().findProject(projectFO);
117: assertNotNull("have a project in " + project, p);
118: // This has the side effect of forcing a scan of the module universe:
119: ClassPath.getClassPath(projectFO.getFileObject("src"),
120: ClassPath.COMPILE);
121: FileObject fileFO = FileUtil.toFileObject(PropertyUtils
122: .resolveFile(nbRootFile(), file));
123: if (fileFO != null) { // OK if not currently built
124: assertEquals("correct owner by FileObject of " + file, p,
125: FileOwnerQuery.getOwner(fileFO));
126: }
127: assertEquals("correct owner by URI of " + file, p,
128: FileOwnerQuery.getOwner(PropertyUtils.resolveFile(
129: nbRootFile(), file).toURI()));
130: }
131:
132: }
|