KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > queries > UpdateTrackingFileOwnerQueryTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project.queries;
21
22 import org.netbeans.api.java.classpath.ClassPath;
23 import org.netbeans.api.project.FileOwnerQuery;
24 import org.netbeans.api.project.Project;
25 import org.netbeans.api.project.ProjectManager;
26 import org.netbeans.modules.apisupport.project.TestBase;
27 import org.netbeans.spi.project.support.ant.PropertyUtils;
28 import org.openide.filesystems.FileObject;
29 import org.openide.filesystems.FileUtil;
30
31 /**
32  * Test that project association by module inclusion list works.
33  * @author Jesse Glick
34  */

35 public class UpdateTrackingFileOwnerQueryTest extends TestBase {
36
37     public UpdateTrackingFileOwnerQueryTest(String JavaDoc name) {
38         super(name);
39     }
40     
41     public void testOwnershipNetBeansOrg() throws Exception JavaDoc {
42         // Basic module:
43
assertOwnership("ant", "nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-apache-tools-ant-module.jar");
44         // Explicitly listed additions:
45
assertOwnership("ant", "nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/ant/nblib/bridge.jar");
46         // Pattern matches (here "ant/lib/"):
47
assertTrue("ant module built (cannot scan by pattern unless files exist)", file("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/ant/lib/ant.jar").isFile());
48         assertOwnership("ant", "nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/ant/lib/ant.jar");
49         // These two always included:
50
assertOwnership("ant", "nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/config/Modules/org-apache-tools-ant-module.xml");
51         assertOwnership("ant", "nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/update_tracking/org-apache-tools-ant-module.xml");
52         // Different pattern match ("modules/ext/jh*.jar"):
53
assertOwnership("core/javahelp", "nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/ext/jh-2.0_04.jar");
54         // Use of release dir:
55
assertOwnership("extbrowser", "nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/lib/extbrowser.dll");
56     }
57     
58     public void testOwnershipExternal() throws Exception JavaDoc {
59         // Will not normally exist when test is run:
60
assertOwnership(resolveEEPPath("/suite1/action-project"), resolveEEPPath("/suite1/build/cluster/modules/org-netbeans-examples-modules-action.jar"));
61         assertOwnership(resolveEEPPath("/suite1/action-project"), resolveEEPPath("/suite1/build/cluster/update_tracking/org-netbeans-examples-modules-action.xml"));
62     }
63     
64     private void assertOwnership(String JavaDoc project, String JavaDoc file) throws Exception JavaDoc {
65         FileObject projectFO = FileUtil.toFileObject(PropertyUtils.resolveFile(nbCVSRootFile(), project));
66         assertNotNull("have project " + project, projectFO);
67         Project p = ProjectManager.getDefault().findProject(projectFO);
68         assertNotNull("have a project in " + project, p);
69         // This has the side effect of forcing a scan of the module universe:
70
ClassPath.getClassPath(projectFO.getFileObject("src"), ClassPath.COMPILE);
71         FileObject fileFO = FileUtil.toFileObject(PropertyUtils.resolveFile(nbCVSRootFile(), file));
72         if (fileFO != null) { // OK if not currently built
73
assertEquals("correct owner by FileObject of " + file, p, FileOwnerQuery.getOwner(fileFO));
74         }
75         assertEquals("correct owner by URI of " + file, p, FileOwnerQuery.getOwner(
76                 PropertyUtils.resolveFile(nbCVSRootFile(), file).toURI()));
77     }
78     
79 }
80
Popular Tags