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 java.io.InputStream;
046: import javax.swing.JOptionPane;
047: import org.apache.tools.ant.module.api.support.ActionUtils;
048: import org.netbeans.api.project.ProjectManager;
049: import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
050: import org.netbeans.modules.apisupport.project.suite.SuiteProject;
051: import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
052: import org.openide.DialogDescriptor;
053: import org.openide.execution.ExecutorTask;
054: import org.openide.filesystems.FileObject;
055: import org.openide.filesystems.FileUtil;
056: import org.openide.util.Utilities;
057:
058: /**
059: * Tests Feedreader sample.
060: * Invokes various Ant targets over Feedreader sample.
061: *
062: * @author Tomas Musil
063: */
064: public class BuildFeedreaderTest extends TestBase {
065:
066: private File feedFolder = null;
067:
068: static {
069: // #65461: do not try to load ModuleInfo instances from ant module
070: System.setProperty(
071: "org.netbeans.core.startup.ModuleSystem.CULPRIT",
072: "true");
073: LayerTestBase.Lkp.setLookup(new Object[0]);
074: DialogDisplayerImpl
075: .returnFromNotify(DialogDescriptor.NO_OPTION);
076: }
077:
078: public BuildFeedreaderTest(String testName) {
079: super (testName);
080: }
081:
082: protected void setUp() throws Exception {
083: clearWorkDir();
084: noDataDir = true;
085: super .setUp();
086: InstalledFileLocatorImpl.registerDestDir(destDirF);
087: TestAntLogger.getDefault().setEnabled(true);
088: }
089:
090: protected void tearDown() throws Exception {
091: TestAntLogger.getDefault().setEnabled(false);
092: }
093:
094: /**
095: * Extracts feedreader to workdir, then platform properties are copied and ant task(s) is called. Build status is returned
096: */
097: public int runAntTargetsOnFeedreader(String[] targets)
098: throws Exception {
099: InputStream is = getClass()
100: .getClassLoader()
101: .getResourceAsStream(
102: "org/netbeans/modules/apisupport/feedreader/FeedReaderProject.zip");
103: assertNotNull(is);
104: feedFolder = new File(getWorkDir(), "feedreader");
105: feedFolder.mkdir();
106: FileObject fo = FileUtil.toFileObject(feedFolder);
107: assertNotNull(fo);
108:
109: try {
110: FileUtil.extractJar(fo, is);
111: } finally {
112: is.close();
113: }
114:
115: File buildProps = new File(getWorkDir(), "build.properties");
116: File privateFolder = new File(
117: new File(feedFolder, "nbproject"), "private");
118: privateFolder.mkdir();
119:
120: FileObject platfPrivateProps = FileUtil.copyFile(FileUtil
121: .toFileObject(buildProps), FileUtil
122: .toFileObject(privateFolder), "platform-private");
123: assertNotNull(platfPrivateProps);
124: SuiteProject feedreaderSuite = (SuiteProject) ProjectManager
125: .getDefault().findProject(fo);
126: assertNotNull(feedreaderSuite);
127: FileObject buildScript = feedreaderSuite.getProjectDirectory()
128: .getFileObject(GeneratedFilesHelper.BUILD_XML_PATH);
129: assertNotNull(buildScript);
130: assertTrue(buildScript.isValid());
131:
132: System.out.println("------------- BUILD OUTPUT --------------");
133: ExecutorTask et = ActionUtils.runTarget(buildScript, targets,
134: null);
135: et.waitFinished();
136: System.out.println("-----------------------------------------");
137: // ant task executor returns 0 on win and jdk 1.5.0_xxx
138: boolean win15 = Utilities.isWindows()
139: && System.getProperty("java.version").startsWith(
140: "1.5.0_");
141:
142: return (win15) ? 0 : et.result();
143: }
144:
145: /**
146: * Invokes build-jnlp target on feedreader
147: */
148: public void testBuildJNLP() throws Exception {
149: int ret = runAntTargetsOnFeedreader(new String[] { "build-jnlp" });
150: assertFileExists("dist/feedreader.war");
151: assertEquals(
152: "build-jnlp ant target should return zero - build successful",
153: 0, ret);
154: }
155:
156: /**
157: * Invokes build-zip target on feedreader
158: */
159: public void testBuildZip() throws Exception {
160: int ret = runAntTargetsOnFeedreader(new String[] { "build-zip" });
161: assertFileExists("dist/feedreader.zip");
162: assertEquals(
163: "build-zipant target should return zero - build successful",
164: 0, ret);
165: }
166:
167: /**
168: * Invokes build target on feedreader
169: */
170: public void testBuild() throws Exception {
171: int ret = runAntTargetsOnFeedreader(new String[] { "build" });
172: assertEquals(
173: "build ant target should return zero - build successful",
174: 0, ret);
175: }
176:
177: /**
178: * Invokes nbms target on feedreader
179: */
180: public void testBuildNBMs() throws Exception {
181: int ret = runAntTargetsOnFeedreader(new String[] { "nbms" });
182: assertFileExists("build/updates/com-sun-syndication-fetcher.nbm");
183: assertFileExists("build/updates/com-sun-syndication.nbm");
184: assertFileExists("build/updates/org-jdom.nbm");
185: assertFileExists("build/updates/org-myorg-feedreader.nbm");
186: assertFileExists("build/updates/updates.xml");
187: assertEquals(
188: "build ant target should return zero - build successful",
189: 0, ret);
190: }
191:
192: /**
193: * Invokes clean target on feedreader
194: */
195: public void testClean() throws Exception {
196: int ret = runAntTargetsOnFeedreader(new String[] { "clean" });
197: assertFalse("Empty build", new File(feedFolder, "build")
198: .exists());
199: assertFalse("Empty dist", new File(feedFolder, "dist").exists());
200:
201: assertEquals(
202: "clean ant target should return zero - build successful",
203: 0, ret);
204: }
205:
206: private void assertFileExists(String relPath) {
207: assertTrue("Feed reader folder exists", feedFolder.exists());
208: File f = new File(feedFolder, relPath);
209: assertTrue("File ${feedreader}/" + relPath, f.exists());
210: }
211:
212: }
|