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;
043:
044: import java.io.File;
045: import org.netbeans.api.project.Project;
046: import org.netbeans.api.project.ProjectManager;
047: import org.netbeans.spi.project.support.ant.EditableProperties;
048: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
049: import org.openide.filesystems.FileObject;
050: import org.openide.filesystems.FileUtil;
051:
052: /**
053: * Test {@link Evaluator} generally (but also see {@link ClassPathProviderImplTest}).
054: * @author Jesse Glick
055: */
056: public class EvaluatorTest extends TestBase {
057:
058: public EvaluatorTest(String name) {
059: super (name);
060: }
061:
062: private NbModuleProject javaProjectProject;
063: private NbModuleProject loadersProject;
064: private File userPropertiesFile;
065:
066: protected void setUp() throws Exception {
067: super .setUp();
068: userPropertiesFile = TestBase.initializeBuildProperties(
069: getWorkDir(), getDataDir());
070: FileObject dir = nbRoot().getFileObject("java.project");
071: assertNotNull("have java/project checked out", dir);
072: Project p = ProjectManager.getDefault().findProject(dir);
073: javaProjectProject = (NbModuleProject) p;
074: dir = nbRoot().getFileObject("openide.loaders");
075: assertNotNull("have openide/loaders checked out", dir);
076: p = ProjectManager.getDefault().findProject(dir);
077: loadersProject = (NbModuleProject) p;
078: }
079:
080: public void testEvaluator() throws Exception {
081: PropertyEvaluator eval = javaProjectProject.evaluator();
082: assertEquals("right basedir", file("java.project"),
083: javaProjectProject.getHelper().resolveFile(
084: eval.getProperty("basedir")));
085: assertEquals("right nb_all", nbRootFile(), javaProjectProject
086: .getHelper().resolveFile(eval.getProperty("nb_all")));
087: assertEquals("right code.name.base.dashes",
088: "org-netbeans-modules-java-project", eval
089: .getProperty("code.name.base.dashes"));
090: assertEquals("right is.autoload", "true", eval
091: .getProperty("is.autoload"));
092: assertEquals("right manifest.mf", "manifest.mf", eval
093: .getProperty("manifest.mf"));
094: assertEquals("right o.n.core.dir", file("nbbuild/netbeans/"
095: + TestBase.CLUSTER_PLATFORM), javaProjectProject
096: .getHelper().resolveFile(
097: eval.getProperty("o.n.core.dir")));
098: assertEquals(
099: "right apisupport.project.dir",
100: file("nbbuild/netbeans/" + TestBase.CLUSTER_APISUPPORT),
101: javaProjectProject.getHelper().resolveFile(
102: eval.getProperty("apisupport.project.dir")));
103: assertEquals("right module JAR", file("nbbuild/netbeans/"
104: + TestBase.CLUSTER_JAVA
105: + "/modules/org-netbeans-modules-java-project.jar"),
106: javaProjectProject.getHelper().resolveFile(
107: eval.evaluate("${cluster}/${module.jar}")));
108: eval = loadersProject.evaluator();
109: assertEquals("right module JAR", file("nbbuild/netbeans/"
110: + TestBase.CLUSTER_PLATFORM
111: + "/modules/org-openide-loaders.jar"), loadersProject
112: .getHelper().resolveFile(
113: eval.evaluate("${cluster}/${module.jar}")));
114: }
115:
116: /** @see "#63541" */
117: public void testJdkProperties() throws Exception {
118: File testjdk = new File(getWorkDir(), "testjdk");
119: EditableProperties ep = Util.loadProperties(FileUtil
120: .toFileObject(userPropertiesFile));
121: ep.setProperty("platforms.testjdk.home", testjdk
122: .getAbsolutePath());
123: Util.storeProperties(FileUtil.toFileObject(userPropertiesFile),
124: ep);
125: NbModuleProject p = generateStandaloneModule("module");
126: PropertyEvaluator eval = p.evaluator();
127: TestBase.TestPCL l = new TestBase.TestPCL();
128: eval.addPropertyChangeListener(l);
129: String bootcp = eval.getProperty("nbjdk.bootclasspath");
130: String origbootcp = bootcp;
131: assertNotNull(bootcp); // who knows what actual value will be inside a unit test - probably empty
132: ep = p.getHelper().getProperties(
133: "nbproject/platform.properties");
134: ep.setProperty("nbjdk.active", "testjdk");
135: p.getHelper()
136: .putProperties("nbproject/platform.properties", ep);
137: assertTrue("got a change in bootcp", l.changed
138: .contains("nbjdk.bootclasspath"));
139: l.reset();
140: bootcp = eval.getProperty("nbjdk.bootclasspath");
141: assertEquals("correct bootcp", new File(testjdk,
142: "jre/lib/rt.jar".replace('/', File.separatorChar))
143: .getAbsolutePath(), bootcp);
144: ep = p.getHelper().getProperties(
145: "nbproject/platform.properties");
146: ep.setProperty("nbjdk.active", "default");
147: p.getHelper()
148: .putProperties("nbproject/platform.properties", ep);
149: assertTrue("got a change in bootcp", l.changed
150: .contains("nbjdk.bootclasspath"));
151: l.reset();
152: bootcp = eval.getProperty("nbjdk.bootclasspath");
153: assertEquals(origbootcp, bootcp);
154: }
155:
156: }
|