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.suite;
043:
044: import java.util.Arrays;
045: import java.util.Collections;
046: import java.util.HashSet;
047: import org.netbeans.api.project.ProjectInformation;
048: import org.netbeans.api.project.ProjectManager;
049: import org.netbeans.api.project.ProjectUtils;
050: import org.netbeans.junit.NbTestCase;
051: import org.netbeans.modules.apisupport.project.NbModuleProject;
052: import org.netbeans.modules.apisupport.project.TestBase;
053: import org.netbeans.modules.apisupport.project.Util;
054: import org.netbeans.modules.apisupport.project.ui.customizer.BasicBrandingModel;
055: import org.netbeans.modules.apisupport.project.ui.customizer.SuiteProperties;
056: import org.netbeans.modules.apisupport.project.universe.NbPlatform;
057: import org.netbeans.spi.project.support.ant.AntProjectHelper;
058: import org.netbeans.spi.project.support.ant.EditableProperties;
059: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
060: import org.openide.filesystems.FileObject;
061: import org.openide.util.Mutex;
062:
063: /**
064: * Test basic {@link SuiteProject} stuff.
065: * @author Jesse Glick
066: */
067: public class SuiteProjectTest extends NbTestCase {
068:
069: public SuiteProjectTest(String name) {
070: super (name);
071: }
072:
073: protected @Override
074: void setUp() throws Exception {
075: super .setUp();
076: clearWorkDir();
077: TestBase.initializeBuildProperties(getWorkDir(), getDataDir());
078: }
079:
080: public void testProjectInformation() throws Exception {
081: SuiteProject p = TestBase.generateSuite(getWorkDir(),
082: "Sweet Stuff");
083: ProjectInformation i = ProjectUtils.getInformation(p);
084: assertEquals("Sweet_Stuff", i.getName());
085: assertEquals("Sweet Stuff", i.getDisplayName());
086: BasicBrandingModel model = new BasicBrandingModel(
087: new SuiteProperties(p, p.getHelper(), p.getEvaluator(),
088: Collections.<NbModuleProject> emptySet()));
089: assertEquals("sweet_stuff", model.getName());
090: assertEquals("Sweet Stuff", model.getTitle());
091: TestBase.TestPCL l = new TestBase.TestPCL();
092: i.addPropertyChangeListener(l);
093: EditableProperties ep = p.getHelper().getProperties(
094: AntProjectHelper.PROJECT_PROPERTIES_PATH);
095: ep.setProperty("app.name", "sweetness");
096: ep.setProperty("app.title", "Sweetness is Now!");
097: p.getHelper().putProperties(
098: AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
099: assertEquals(new HashSet<String>(Arrays.asList(
100: ProjectInformation.PROP_NAME,
101: ProjectInformation.PROP_DISPLAY_NAME)), l.changed);
102: assertEquals("Sweet_Stuff", i.getName());
103: assertEquals("Sweetness is Now!", i.getDisplayName());
104: model = new BasicBrandingModel(new SuiteProperties(p, p
105: .getHelper(), p.getEvaluator(), Collections
106: .<NbModuleProject> emptySet()));
107: assertEquals("sweetness", model.getName());
108: assertEquals("Sweetness is Now!", model.getTitle());
109: }
110:
111: public void testSuiteEvaluatorReturnsUpToDateValues()
112: throws Exception { // #67314, #72981
113: SuiteProject suite1 = TestBase.generateSuite(getWorkDir(),
114: "suite1");
115: PropertyEvaluator eval = suite1.getEvaluator();
116: TestBase.generateSuiteComponent(suite1, "module1");
117:
118: FileObject suiteEPFO = suite1.getProjectDirectory()
119: .getFileObject("nbproject/project.properties");
120: EditableProperties suiteEP = Util.loadProperties(suiteEPFO);
121: assertEquals("modules property",
122: "${project.org.example.module1}", suiteEP
123: .getProperty("modules"));
124: assertEquals("project.org.example.module1 property", "module1",
125: suiteEP.getProperty("project.org.example.module1"));
126: // #67314
127: assertEquals(
128: "up-to-date 'modules' property from suite evaluator",
129: "module1", eval.getProperty("modules"));
130:
131: // branding.dir check (#72981)
132: assertEquals("branding.dir has a default value", "branding",
133: eval.getProperty("branding.dir"));
134: suiteEP.setProperty("custom.dir", "custom");
135: suiteEP.setProperty("branding.dir",
136: "${custom.dir}/nonDefaultBrandingDir");
137: suite1.getHelper().putProperties(
138: AntProjectHelper.PROJECT_PROPERTIES_PATH, suiteEP);
139: assertEquals("branding dir evaluated",
140: "custom/nonDefaultBrandingDir", eval
141: .getProperty("branding.dir"));
142: }
143:
144: public void testPlatformPropertiesFromEvaluatorAreUpToDate()
145: throws Exception {
146: final SuiteProject suite = TestBase.generateSuite(getWorkDir(),
147: "suite1", "custom");
148: PropertyEvaluator eval = suite.getEvaluator();
149: assertEquals("custom", eval.getProperty("nbplatform.active"));
150: assertEquals(NbPlatform.getPlatformByID("custom").getDestDir(),
151: suite.getHelper().resolveFile(
152: eval.getProperty("netbeans.dest.dir")));
153:
154: ProjectManager.mutex().writeAccess(
155: new Mutex.ExceptionAction<Void>() {
156: public Void run() throws Exception {
157: // simulate change (e.g. through suite properties)
158: FileObject plafProps = suite
159: .getProjectDirectory()
160: .getFileObject(
161: "nbproject/platform.properties");
162: EditableProperties ep = Util
163: .loadProperties(plafProps);
164: ep.setProperty("nbplatform.active", "default");
165: Util.storeProperties(plafProps, ep);
166: return null;
167: }
168: });
169:
170: assertEquals("nbplatform.active change took effect", "default",
171: eval.getProperty("nbplatform.active"));
172: assertEquals("#67628: netbeans.dest.dir change did as well",
173: NbPlatform.getDefaultPlatform().getDestDir(), suite
174: .getHelper().resolveFile(
175: eval.getProperty("netbeans.dest.dir")));
176: }
177:
178: }
|