0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041:
0042: package org.netbeans.modules.java.j2seproject;
0043:
0044: import java.beans.PropertyChangeListener;
0045: import java.io.IOException;
0046: import java.io.OutputStream;
0047: import java.io.PrintWriter;
0048: import java.net.URL;
0049: import java.util.ArrayList;
0050: import java.util.Arrays;
0051: import java.util.Collection;
0052: import java.util.Collections;
0053: import java.util.List;
0054: import java.util.Map;
0055: import java.util.Properties;
0056: import org.netbeans.api.fileinfo.NonRecursiveFolder;
0057: import org.netbeans.api.java.classpath.ClassPath;
0058: import org.netbeans.api.java.platform.JavaPlatform;
0059: import org.netbeans.api.java.platform.Specification;
0060: import org.netbeans.api.java.project.JavaProjectConstants;
0061: import org.netbeans.api.project.Project;
0062: import org.netbeans.api.project.ProjectManager;
0063: import org.netbeans.junit.NbTestCase;
0064: import org.netbeans.modules.java.j2seproject.applet.AppletSupport;
0065: import org.netbeans.modules.java.j2seproject.ui.customizer.MainClassChooser;
0066: import org.netbeans.spi.project.ProjectConfiguration;
0067: import org.netbeans.spi.project.ProjectConfigurationProvider;
0068: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
0069: import org.openide.filesystems.FileLock;
0070: import org.openide.filesystems.FileObject;
0071: import org.netbeans.api.project.TestUtil;
0072: import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties;
0073: import org.netbeans.modules.java.platform.JavaPlatformProvider;
0074: import org.netbeans.spi.java.classpath.support.ClassPathSupport;
0075: import org.netbeans.spi.project.ActionProvider;
0076: import org.netbeans.spi.project.support.ant.AntProjectHelper;
0077: import org.netbeans.spi.project.support.ant.EditableProperties;
0078: import org.openide.filesystems.FileUtil;
0079: import org.openide.filesystems.URLMapper;
0080: import org.openide.filesystems.test.TestFileUtils;
0081: import org.openide.loaders.DataFolder;
0082: import org.openide.loaders.DataObject;
0083: import org.openide.modules.SpecificationVersion;
0084: import org.openide.util.Lookup;
0085: import org.openide.util.Mutex;
0086: import org.openide.util.lookup.Lookups;
0087: import org.openide.util.test.MockLookup;
0088:
0089: /**
0090: * Tests for J2SEActionProvider
0091: *
0092: * @author David Konecny
0093: */
0094: public class J2SEActionProviderTest extends NbTestCase {
0095:
0096: public J2SEActionProviderTest(String testName) {
0097: super (testName);
0098: }
0099:
0100: private FileObject scratch;
0101: private FileObject projdir;
0102: private FileObject sources;
0103: private FileObject build;
0104: private FileObject tests;
0105: private ProjectManager pm;
0106: private Project pp;
0107: private AntProjectHelper helper;
0108: private J2SEActionProvider actionProvider;
0109: private DataFolder sourcePkg1;
0110: private DataFolder sourcePkg2;
0111: private DataFolder testPkg1;
0112: private DataFolder testPkg2;
0113: private DataObject someSource1;
0114: private DataObject someSource2;
0115: private DataObject someSource3;
0116: private DataObject someTest1;
0117: private DataObject someTest2;
0118:
0119: protected @Override
0120: void setUp() throws Exception {
0121: super .setUp();
0122: MockLookup.setInstances(new SimplePlatformProvider());
0123: scratch = TestUtil.makeScratchDir(this );
0124: projdir = scratch.createFolder("proj");
0125: J2SEProjectGenerator
0126: .setDefaultSourceLevel(new SpecificationVersion("1.4")); //NOI18N
0127: helper = J2SEProjectGenerator.createProject(FileUtil
0128: .toFile(projdir), "proj", "foo.Main", "manifest.mf",
0129: null); //NOI18N
0130: EditableProperties ep = helper
0131: .getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
0132: ep.put(J2SEProjectProperties.DO_DEPEND, "true"); // to avoid too many changes in tests from issue #118079
0133: helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH,
0134: ep);
0135: J2SEProjectGenerator.setDefaultSourceLevel(null);
0136: pm = ProjectManager.getDefault();
0137: pp = pm.findProject(projdir);
0138: actionProvider = pp.getLookup()
0139: .lookup(J2SEActionProvider.class);
0140: sources = projdir.getFileObject("src");
0141: tests = projdir.getFileObject("test");
0142: // projdir.createData("build.xml");
0143: build = projdir.createFolder("build");
0144: build.createFolder("classes");
0145: FileObject pkg = sources.createFolder("foo");
0146: FileObject fo = pkg.createData("Bar.java");
0147: sourcePkg1 = DataFolder.findFolder(pkg);
0148: pkg = sources.createFolder("foo2");
0149: sourcePkg2 = DataFolder.findFolder(pkg);
0150: someSource1 = DataObject.find(fo);
0151: fo = sources.getFileObject("foo").createData("Main.java");
0152: createMain(fo);
0153: someSource2 = DataObject.find(fo);
0154: fo = sources.getFileObject("foo").createData("Third.java");
0155: someSource3 = DataObject.find(fo);
0156: pkg = tests.createFolder("foo");
0157: fo = pkg.createData("BarTest.java");
0158: testPkg1 = DataFolder.findFolder(pkg);
0159: pkg = tests.createFolder("foo2");
0160: testPkg2 = DataFolder.findFolder(pkg);
0161: someTest1 = DataObject.find(fo);
0162: fo = tests.getFileObject("foo").createData("MainTest.java");
0163: someTest2 = DataObject.find(fo);
0164: assertNotNull(someSource1);
0165: assertNotNull(someSource2);
0166: assertNotNull(someTest1);
0167: assertNotNull(someTest2);
0168: }
0169:
0170: protected @Override
0171: void tearDown() throws Exception {
0172: scratch = null;
0173: projdir = null;
0174: pm = null;
0175: super .tearDown();
0176: }
0177:
0178: private void createMain(FileObject fo) throws Exception {
0179: FileLock lock = fo.lock();
0180: PrintWriter pw = new PrintWriter(fo.getOutputStream(lock));
0181: pw.println("package foo;");
0182: pw
0183: .println("public class Main { public static void main(String[] args){}; };");
0184: pw.flush();
0185: pw.close();
0186: lock.releaseLock();
0187: }
0188:
0189: public void testGetTargetNames() throws Exception {
0190: implTestGetTargetNames();
0191: }
0192:
0193: public void testGetTargetNamesMultiRoots() throws Exception {
0194: SourceRootsTest.addSourceRoot(helper, projdir, "src.other.dir",
0195: "other");
0196: implTestGetTargetNames();
0197: }
0198:
0199: public void implTestGetTargetNames() throws Exception {
0200: Properties p;
0201: Lookup context;
0202: String[] targets;
0203:
0204: // test COMMAND_COMPILE_SINGLE
0205:
0206: p = new Properties();
0207: context = Lookups.fixed(someSource1);
0208: targets = actionProvider.getTargetNames(
0209: ActionProvider.COMMAND_COMPILE_SINGLE, context, p);
0210: assertNotNull(
0211: "Must found some targets for COMMAND_COMPILE_SINGLE",
0212: targets);
0213: assertEquals(
0214: "There must be one target for COMMAND_COMPILE_SINGLE",
0215: 1, targets.length);
0216: assertEquals("Unexpected target name", "compile-single",
0217: targets[0]);
0218: assertEquals("There must be one target parameter", 1, p
0219: .keySet().size());
0220: assertEquals("There must be be target parameter",
0221: "foo/Bar.java", p.getProperty("javac.includes"));
0222: p = new Properties();
0223: context = Lookups.fixed(someTest1, someTest2);
0224: targets = actionProvider.getTargetNames(
0225: ActionProvider.COMMAND_COMPILE_SINGLE, context, p);
0226: assertNotNull(
0227: "Must found some targets for COMMAND_COMPILE_SINGLE",
0228: targets);
0229: assertEquals(
0230: "There must be one target for COMMAND_COMPILE_SINGLE",
0231: 1, targets.length);
0232: assertEquals("Unexpected target name", "compile-test-single",
0233: targets[0]);
0234: assertEquals("There must be one target parameter", 1, p
0235: .keySet().size());
0236: assertEquals("There must be be target parameter",
0237: "foo/BarTest.java,foo/MainTest.java", p
0238: .getProperty("javac.includes"));
0239: p = new Properties();
0240: context = Lookups.fixed(sourcePkg1);
0241: targets = actionProvider.getTargetNames(
0242: ActionProvider.COMMAND_COMPILE_SINGLE, context, p);
0243: assertNotNull(
0244: "Must found some targets for COMMAND_COMPILE_SINGLE",
0245: targets);
0246: assertEquals(
0247: "There must be one target for COMMAND_COMPILE_SINGLE",
0248: 1, targets.length);
0249: assertEquals("Unexpected target name", "compile-single",
0250: targets[0]);
0251: assertEquals("There must be one target parameter", 1, p
0252: .keySet().size());
0253: assertEquals("There must be be target parameter", "foo/**", p
0254: .getProperty("javac.includes"));
0255: p = new Properties();
0256: context = Lookups.fixed(sourcePkg1, sourcePkg2);
0257: targets = actionProvider.getTargetNames(
0258: ActionProvider.COMMAND_COMPILE_SINGLE, context, p);
0259: assertNotNull(
0260: "Must found some targets for COMMAND_COMPILE_SINGLE",
0261: targets);
0262: assertEquals(
0263: "There must be one target for COMMAND_COMPILE_SINGLE",
0264: 1, targets.length);
0265: assertEquals("Unexpected target name", "compile-single",
0266: targets[0]);
0267: assertEquals("There must be one target parameter", 1, p
0268: .keySet().size());
0269: assertEquals("There must be be target parameter",
0270: "foo/**,foo2/**", p.getProperty("javac.includes"));
0271: p = new Properties();
0272: context = Lookups.fixed(DataFolder.findFolder(sources));
0273: targets = actionProvider.getTargetNames(
0274: ActionProvider.COMMAND_COMPILE_SINGLE, context, p);
0275: assertNotNull(
0276: "Must found some targets for COMMAND_COMPILE_SINGLE",
0277: targets);
0278: assertEquals(
0279: "There must be one target for COMMAND_COMPILE_SINGLE",
0280: 1, targets.length);
0281: assertEquals("Unexpected target name", "compile-single",
0282: targets[0]);
0283: assertEquals("There must be one target parameter", 1, p
0284: .keySet().size());
0285: assertEquals("There must be be target parameter", "**", p
0286: .getProperty("javac.includes"));
0287:
0288: p = new Properties();
0289: context = Lookups.fixed(sourcePkg1, new NonRecursiveFolderImpl(
0290: sourcePkg1));
0291: targets = actionProvider.getTargetNames(
0292: ActionProvider.COMMAND_COMPILE_SINGLE, context, p);
0293: assertNotNull(
0294: "Must found some targets for COMMAND_COMPILE_SINGLE",
0295: targets);
0296: assertEquals(
0297: "There must be one target for COMMAND_COMPILE_SINGLE",
0298: 1, targets.length);
0299: assertEquals("Unexpected target name", "compile-single",
0300: targets[0]);
0301: assertEquals("There must be one target parameter", 1, p
0302: .keySet().size());
0303: assertEquals("There must be be target parameter", "foo/*", p
0304: .getProperty("javac.includes"));
0305: p = new Properties();
0306: context = Lookups.fixed(sourcePkg1, sourcePkg2,
0307: new NonRecursiveFolderImpl(sourcePkg1),
0308: new NonRecursiveFolderImpl(sourcePkg2));
0309: targets = actionProvider.getTargetNames(
0310: ActionProvider.COMMAND_COMPILE_SINGLE, context, p);
0311: assertNotNull(
0312: "Must found some targets for COMMAND_COMPILE_SINGLE",
0313: targets);
0314: assertEquals(
0315: "There must be one target for COMMAND_COMPILE_SINGLE",
0316: 1, targets.length);
0317: assertEquals("Unexpected target name", "compile-single",
0318: targets[0]);
0319: assertEquals("There must be one target parameter", 1, p
0320: .keySet().size());
0321: assertEquals("There must be be target parameter",
0322: "foo/*,foo2/*", p.getProperty("javac.includes"));
0323: p = new Properties();
0324: context = Lookups.fixed(DataFolder.findFolder(sources),
0325: new NonRecursiveFolderImpl(sources));
0326: targets = actionProvider.getTargetNames(
0327: ActionProvider.COMMAND_COMPILE_SINGLE, context, p);
0328: assertNotNull(
0329: "Must found some targets for COMMAND_COMPILE_SINGLE",
0330: targets);
0331: assertEquals(
0332: "There must be one target for COMMAND_COMPILE_SINGLE",
0333: 1, targets.length);
0334: assertEquals("Unexpected target name", "compile-single",
0335: targets[0]);
0336: assertEquals("There must be one target parameter", 1, p
0337: .keySet().size());
0338: assertEquals("There must be be target parameter", "*", p
0339: .getProperty("javac.includes"));
0340:
0341: // test COMMAND_TEST_SINGLE
0342:
0343: p = new Properties();
0344: context = Lookups.fixed(someSource1);
0345: targets = actionProvider.getTargetNames(
0346: ActionProvider.COMMAND_TEST_SINGLE, context, p);
0347: assertNotNull(
0348: "Must found some targets for COMMAND_TEST_SINGLE",
0349: targets);
0350: assertEquals(
0351: "There must be one target for COMMAND_TEST_SINGLE", 1,
0352: targets.length);
0353: assertEquals("Unexpected target name", "test-single",
0354: targets[0]);
0355: assertEquals("There must be one target parameter", 2, p
0356: .keySet().size());
0357: assertEquals("There must be be target parameter",
0358: "foo/BarTest.java", p.getProperty("javac.includes"));
0359: assertEquals("There must be be target parameter",
0360: "foo/BarTest.java", p.getProperty("test.includes"));
0361: p = new Properties();
0362: context = Lookups.fixed(someSource1, someSource2);
0363: targets = actionProvider.getTargetNames(
0364: ActionProvider.COMMAND_TEST_SINGLE, context, p);
0365: assertNotNull(
0366: "Must found some targets for COMMAND_TEST_SINGLE",
0367: targets);
0368: assertEquals(
0369: "There must be one target for COMMAND_TEST_SINGLE", 1,
0370: targets.length);
0371: assertEquals("Unexpected target name", "test-single",
0372: targets[0]);
0373: assertEquals("There must be one target parameter", 2, p
0374: .keySet().size());
0375: assertEquals("There must be be target parameter",
0376: "foo/BarTest.java,foo/MainTest.java", p
0377: .getProperty("javac.includes"));
0378: assertEquals("There must be be target parameter",
0379: "foo/BarTest.java,foo/MainTest.java", p
0380: .getProperty("test.includes"));
0381:
0382: // test COMMAND_DEBUG_TEST_SINGLE
0383:
0384: p = new Properties();
0385: context = Lookups.fixed(someSource1);
0386: targets = actionProvider.getTargetNames(
0387: ActionProvider.COMMAND_DEBUG_TEST_SINGLE, context, p);
0388: assertNotNull(
0389: "Must found some targets for COMMAND_DEBUG_TEST_SINGLE",
0390: targets);
0391: assertEquals(
0392: "There must be one target for COMMAND_DEBUG_TEST_SINGLE",
0393: 1, targets.length);
0394: assertEquals("Unexpected target name", "debug-test", targets[0]);
0395: assertEquals("There must be two target parameters", 2, p
0396: .keySet().size());
0397: assertEquals("There must be be target parameter",
0398: "foo.BarTest", p.getProperty("test.class"));
0399: assertEquals("There must be be target parameter",
0400: "foo/BarTest.java", p.getProperty("javac.includes"));
0401:
0402: // test COMMAND_DEBUG_FIX
0403: actionProvider.unitTestingSupport_fixClasses = "foo/Bar";
0404: p = new Properties();
0405: context = Lookups.fixed(someSource1);
0406: targets = actionProvider.getTargetNames(
0407: JavaProjectConstants.COMMAND_DEBUG_FIX, context, p);
0408: actionProvider.unitTestingSupport_fixClasses = null;
0409: assertNotNull("Must found some targets for COMMAND_DEBUG_FIX",
0410: targets);
0411: assertEquals("There must be one target for COMMAND_DEBUG_FIX",
0412: 1, targets.length);
0413: assertEquals("Unexpected target name", "debug-fix", targets[0]);
0414: assertEquals("There must be one target parameter", 2, p
0415: .keySet().size());
0416: assertEquals("There must be be target parameter", "foo/Bar", p
0417: .getProperty("fix.includes"));
0418: assertEquals("There must be be target parameter", "foo/Bar", p
0419: .getProperty("fix.classes"));
0420: p = new Properties();
0421: context = Lookups.fixed(someTest1);
0422: targets = actionProvider.getTargetNames(
0423: JavaProjectConstants.COMMAND_DEBUG_FIX, context, p);
0424: assertNotNull("Must found some targets for COMMAND_DEBUG_FIX",
0425: targets);
0426: assertEquals("There must be one target for COMMAND_DEBUG_FIX",
0427: 1, targets.length);
0428: assertEquals("Unexpected target name", "debug-fix-test",
0429: targets[0]);
0430: assertEquals("There must be one target parameter", 2, p
0431: .keySet().size());
0432: assertEquals("There must be be target parameter",
0433: "foo/BarTest", p.getProperty("fix.includes"));
0434: assertEquals("There must be be target parameter", "", p
0435: .getProperty("fix.classes")); //XXX: currently not set for tests, intentionally?
0436:
0437: // test COMMAND_RUN_SINGLE
0438:
0439: p = new Properties();
0440: context = Lookups.fixed(someSource2);
0441: MainClassChooser.unitTestingSupport_hasMainMethodResult = Boolean.TRUE;
0442: try {
0443: targets = actionProvider.getTargetNames(
0444: ActionProvider.COMMAND_RUN_SINGLE, context, p);
0445: } finally {
0446: MainClassChooser.unitTestingSupport_hasMainMethodResult = null;
0447: }
0448: assertNotNull("Must found some targets for COMMAND_RUN_SINGLE",
0449: targets);
0450: assertEquals("There must be one target for COMMAND_RUN_SINGLE",
0451: 1, targets.length);
0452: assertEquals("Unexpected target name", "run-single", targets[0]);
0453: assertEquals("There must be one target parameter", 2, p
0454: .keySet().size());
0455: assertEquals("There must be be target parameter",
0456: "foo/Main.java", p.getProperty("javac.includes"));
0457: assertEquals("There must be be target parameter", "foo.Main", p
0458: .getProperty("run.class"));
0459: p = new Properties();
0460: context = Lookups.fixed(someSource2);
0461: MainClassChooser.unitTestingSupport_hasMainMethodResult = Boolean.FALSE;
0462: AppletSupport.unitTestingSupport_isApplet = Boolean.TRUE;
0463: try {
0464: targets = actionProvider.getTargetNames(
0465: ActionProvider.COMMAND_RUN_SINGLE, context, p);
0466: } finally {
0467: MainClassChooser.unitTestingSupport_hasMainMethodResult = null;
0468: AppletSupport.unitTestingSupport_isApplet = null;
0469: }
0470: assertNotNull("Must found some targets for COMMAND_RUN_SINGLE",
0471: targets);
0472: assertEquals("There must be one target for COMMAND_RUN_SINGLE",
0473: 1, targets.length);
0474: assertEquals("Unexpected target name", "run-applet", targets[0]);
0475: assertEquals("There must be one target parameter", 2, p
0476: .keySet().size());
0477: assertEquals("There must be be target parameter",
0478: "foo/Main.java", p.getProperty("javac.includes"));
0479: FileObject appletHtml = build.getFileObject("Main", "html");
0480: assertNotNull("Applet HTML page must be generated", appletHtml);
0481: URL appletUrl = URLMapper.findURL(appletHtml,
0482: URLMapper.EXTERNAL);
0483: assertEquals("There must be be target parameter", appletUrl
0484: .toExternalForm(), p.getProperty("applet.url"));
0485: p = new Properties();
0486: context = Lookups.fixed(someTest1);
0487: MainClassChooser.unitTestingSupport_hasMainMethodResult = Boolean.TRUE;
0488: AppletSupport.unitTestingSupport_isApplet = Boolean.TRUE;
0489: try {
0490: targets = actionProvider.getTargetNames(
0491: ActionProvider.COMMAND_RUN_SINGLE, context, p);
0492: } finally {
0493: MainClassChooser.unitTestingSupport_hasMainMethodResult = null;
0494: AppletSupport.unitTestingSupport_isApplet = null;
0495: }
0496: assertNotNull("Must found some targets for COMMAND_RUN_SINGLE",
0497: targets);
0498: assertEquals("There must be one target for COMMAND_RUN_SINGLE",
0499: 1, targets.length);
0500: assertEquals("Unexpected target name", "test-single",
0501: targets[0]);
0502: assertEquals("There must be one target parameter", 2, p
0503: .keySet().size());
0504: assertEquals("There must be be target parameter",
0505: "foo/BarTest.java", p.getProperty("javac.includes"));
0506: assertEquals("There must be be target parameter",
0507: "foo/BarTest.java", p.getProperty("test.includes"));
0508:
0509: // test COMMAND_DEBUG_SINGLE
0510:
0511: p = new Properties();
0512: context = Lookups.fixed(someSource2);
0513: MainClassChooser.unitTestingSupport_hasMainMethodResult = Boolean.TRUE;
0514: try {
0515: targets = actionProvider.getTargetNames(
0516: ActionProvider.COMMAND_DEBUG_SINGLE, context, p);
0517: } finally {
0518: MainClassChooser.unitTestingSupport_hasMainMethodResult = null;
0519: }
0520: assertNotNull(
0521: "Must found some targets for COMMAND_DEBUG_SINGLE",
0522: targets);
0523: assertEquals(
0524: "There must be one target for COMMAND_DEBUG_SINGLE", 1,
0525: targets.length);
0526: assertEquals("Unexpected target name", "debug-single",
0527: targets[0]);
0528: assertEquals("There must be one target parameter", 2, p
0529: .keySet().size());
0530: assertEquals("There must be be target parameter",
0531: "foo/Main.java", p.getProperty("javac.includes"));
0532: assertEquals("There must be be target parameter", "foo.Main", p
0533: .getProperty("debug.class"));
0534: p = new Properties();
0535: context = Lookups.fixed(someSource2);
0536: MainClassChooser.unitTestingSupport_hasMainMethodResult = Boolean.FALSE;
0537: AppletSupport.unitTestingSupport_isApplet = Boolean.TRUE;
0538: try {
0539: targets = actionProvider.getTargetNames(
0540: ActionProvider.COMMAND_DEBUG_SINGLE, context, p);
0541: } finally {
0542: MainClassChooser.unitTestingSupport_hasMainMethodResult = null;
0543: AppletSupport.unitTestingSupport_isApplet = null;
0544: }
0545: assertNotNull(
0546: "Must found some targets for COMMAND_DEBUG_SINGLE",
0547: targets);
0548: assertEquals(
0549: "There must be one target for COMMAND_DEBUG_SINGLE", 1,
0550: targets.length);
0551: assertEquals("Unexpected target name", "debug-applet",
0552: targets[0]);
0553: assertEquals("There must be one target parameter", 3, p
0554: .keySet().size());
0555: assertEquals("There must be be target parameter",
0556: "foo/Main.java", p.getProperty("javac.includes"));
0557: appletHtml = build.getFileObject("Main", "html");
0558: assertNotNull("Applet HTML page must be generated", appletHtml);
0559: appletUrl = URLMapper.findURL(appletHtml, URLMapper.EXTERNAL);
0560: assertEquals("There must be be target parameter", appletUrl
0561: .toExternalForm(), p.getProperty("applet.url"));
0562: p = new Properties();
0563: context = Lookups.fixed(someTest1);
0564: MainClassChooser.unitTestingSupport_hasMainMethodResult = Boolean.TRUE;
0565: AppletSupport.unitTestingSupport_isApplet = Boolean.TRUE;
0566: try {
0567: targets = actionProvider.getTargetNames(
0568: ActionProvider.COMMAND_DEBUG_SINGLE, context, p);
0569: } finally {
0570: MainClassChooser.unitTestingSupport_hasMainMethodResult = null;
0571: AppletSupport.unitTestingSupport_isApplet = null;
0572: }
0573: assertNotNull(
0574: "Must found some targets for COMMAND_DEBUG_SINGLE",
0575: targets);
0576: assertEquals(
0577: "There must be one target for COMMAND_DEBUG_SINGLE", 1,
0578: targets.length);
0579: assertEquals("Unexpected target name", "debug-test", targets[0]);
0580: assertEquals("There must be two target parameters", 2, p
0581: .keySet().size());
0582: assertEquals("There must be be target parameter",
0583: "foo.BarTest", p.getProperty("test.class"));
0584: assertEquals("There must be be target parameter",
0585: "foo/BarTest.java", p.getProperty("javac.includes"));
0586:
0587: // test COMMAND_RUN
0588:
0589: p = new Properties();
0590: context = Lookup.EMPTY;
0591: MainClassChooser.unitTestingSupport_hasMainMethodResult = Boolean.TRUE;
0592: try {
0593: targets = actionProvider.getTargetNames(
0594: ActionProvider.COMMAND_RUN, context, p);
0595: } finally {
0596: MainClassChooser.unitTestingSupport_hasMainMethodResult = null;
0597: }
0598: assertNotNull("Must found some targets for COMMAND_RUN",
0599: targets);
0600: assertEquals("There must be one target for COMMAND_RUN", 1,
0601: targets.length);
0602: assertEquals("Unexpected target name", "run", targets[0]);
0603: //The project is saved after the main.class property was added into the project's properties,
0604: //it is no more needed to pass the main.class in the properties.
0605: //See issue #61244: Main class setting not saved for J2SE Project during IDE session
0606: assertEquals("There must be no target parameter", Collections
0607: .emptyMap(), p);
0608:
0609: // test COMMAND_DEBUG
0610:
0611: p = new Properties();
0612: context = Lookup.EMPTY;
0613: MainClassChooser.unitTestingSupport_hasMainMethodResult = Boolean.TRUE;
0614: try {
0615: targets = actionProvider.getTargetNames(
0616: ActionProvider.COMMAND_DEBUG, context, p);
0617: } finally {
0618: MainClassChooser.unitTestingSupport_hasMainMethodResult = null;
0619: }
0620: assertNotNull("Must found some targets for COMMAND_DEBUG",
0621: targets);
0622: assertEquals("There must be one target for COMMAND_DEBUG", 1,
0623: targets.length);
0624: assertEquals("Unexpected target name", "debug", targets[0]);
0625: //The project is saved after the main.class property was added into the project's properties,
0626: //it is no more needed to pass it in the properties.
0627: //See issue #61244: Main class setting not saved for J2SE Project during IDE session
0628: assertEquals("There must be one target parameter", 1, p
0629: .keySet().size());
0630: assertEquals("There must be be target parameter", "foo.Main", p
0631: .getProperty("debug.class"));
0632:
0633: // test COMMAND_DEBUG_STEP_INTO
0634:
0635: p = new Properties();
0636: context = Lookup.EMPTY;
0637: MainClassChooser.unitTestingSupport_hasMainMethodResult = Boolean.TRUE;
0638: try {
0639: targets = actionProvider.getTargetNames(
0640: ActionProvider.COMMAND_DEBUG_STEP_INTO, context, p);
0641: } finally {
0642: MainClassChooser.unitTestingSupport_hasMainMethodResult = null;
0643: }
0644: assertNotNull(
0645: "Must found some targets for COMMAND_DEBUG_STEP_INTO",
0646: targets);
0647: assertEquals(
0648: "There must be one target for COMMAND_DEBUG_STEP_INTO",
0649: 1, targets.length);
0650: assertEquals("Unexpected target name", "debug-stepinto",
0651: targets[0]);
0652: //The project is saved after the main.class property was added into the project's properties,
0653: //it is no more needed to pass it in the properties.
0654: //See issue #61244: Main class setting not saved for J2SE Project during IDE session
0655: assertEquals("There must be one target parameter", 1, p
0656: .keySet().size());
0657: assertEquals("There must be be target parameter", "foo.Main", p
0658: .getProperty("debug.class"));
0659: }
0660:
0661: public void testGetTargetNamesFromConfig() throws Exception {
0662: final FileObject projdirFO = scratch
0663: .createFolder("projectwithconfigs");
0664: J2SEProjectGenerator.createProject(FileUtil.toFile(projdirFO),
0665: "projectwithconfigs", null, null, null);
0666: final J2SEProject proj = (J2SEProject) ProjectManager
0667: .getDefault().findProject(projdirFO);
0668: final ProjectConfigurationProvider pcp = proj.getLookup()
0669: .lookup(ProjectConfigurationProvider.class);
0670: ProjectManager.mutex().writeAccess(
0671: new Mutex.ExceptionAction<Void>() {
0672: @SuppressWarnings("unchecked")
0673: // due to ProjectConfiguration type
0674: public Void run() throws Exception {
0675: Properties props = new Properties();
0676: props.setProperty("main.class", "foo.Bar");
0677: props.setProperty("$target.build", "");
0678: props.setProperty("$target.run", "runtarget");
0679: props.setProperty("$target.debug",
0680: "debugtarget1 debugtarget2");
0681: write(props, projdirFO,
0682: "nbproject/configs/test.properties");
0683: props = new Properties();
0684: write(props, projdirFO,
0685: "nbproject/private/configs/test.properties");
0686: props = new Properties();
0687: props.setProperty("config", "test");
0688: write(props, projdirFO,
0689: "nbproject/private/config.properties");
0690: ProjectManager.getDefault().saveProject(proj);
0691: List<ProjectConfiguration> configs = new ArrayList<ProjectConfiguration>(
0692: pcp.getConfigurations());
0693: pcp.setActiveConfiguration(configs.get(1));
0694: return null;
0695: }
0696: });
0697: J2SEActionProvider ap = proj.getLookup().lookup(
0698: J2SEActionProvider.class);
0699: PropertyEvaluator eval = proj.evaluator();
0700: String config = eval.getProperty("config");
0701: assertEquals("Name of active config from Evaluator is test",
0702: "test", config);
0703: FileObject src = projdirFO.getFileObject("src");
0704: FileObject pkg = src.createFolder("foo");
0705: FileObject file = pkg.createData("Bar.java");
0706: DataObject srcDO = DataObject.find(file);
0707: Lookup context = Lookups.fixed(srcDO);
0708: MainClassChooser.unitTestingSupport_hasMainMethodResult = Boolean.TRUE;
0709: try {
0710: // test of targets defined in config
0711: String[] targets = ap.getTargetNames(
0712: ActionProvider.COMMAND_DEBUG, context,
0713: new Properties());
0714: assertEquals(
0715: "There must be two Debug targets in test config",
0716: 2, targets.length);
0717: assertEquals("First Debug target name is debugtarget1",
0718: "debugtarget1", targets[0]);
0719: assertEquals("Second Debug target name is debugtarget2",
0720: "debugtarget2", targets[1]);
0721: targets = ap.getTargetNames(ActionProvider.COMMAND_BUILD,
0722: context, new Properties());
0723: assertEquals("There must be 1 Build target in test config",
0724: 1, targets.length);
0725: // target is not in fact from the config, config contains empty string
0726: assertEquals("Build target name is jar", "jar", targets[0]);
0727: targets = ap.getTargetNames(ActionProvider.COMMAND_RUN,
0728: context, new Properties());
0729: assertEquals("There must be 1 Run target in test config",
0730: 1, targets.length);
0731: assertEquals("Run target name is runtarget", "runtarget",
0732: targets[0]);
0733: // test of targets not in config
0734: targets = ap.getTargetNames(ActionProvider.COMMAND_CLEAN,
0735: context, new Properties());
0736: assertEquals("There must be 1 Clean target", 1,
0737: targets.length);
0738: assertEquals("Clean target name is runtarget", "clean",
0739: targets[0]);
0740: } finally {
0741: MainClassChooser.unitTestingSupport_hasMainMethodResult = null;
0742: }
0743: }
0744:
0745: public void testIsActionEnabled() throws Exception {
0746: implTestIsActionEnabled();
0747: }
0748:
0749: public void testIsActionEnabledMultiRoot() throws Exception {
0750: FileObject newRoot = SourceRootsTest.addSourceRoot(helper,
0751: projdir, "src.other.dir", "other");
0752: implTestIsActionEnabled();
0753: Lookup context = Lookups.fixed(sourcePkg1, DataFolder
0754: .findFolder(newRoot));
0755: boolean enabled = actionProvider.isActionEnabled(
0756: ActionProvider.COMMAND_COMPILE_SINGLE, context);
0757: assertFalse(
0758: "COMMAND_COMPILE_SINGLE must be disabled on multiple src packages from different roots",
0759: enabled);
0760: }
0761:
0762: private void implTestIsActionEnabled() throws Exception {
0763: Lookup context;
0764: boolean enabled;
0765:
0766: // test COMMAND_COMPILE_SINGLE
0767:
0768: context = Lookups.fixed(someSource1);
0769: enabled = actionProvider.isActionEnabled(
0770: ActionProvider.COMMAND_COMPILE_SINGLE, context);
0771: assertTrue(
0772: "COMMAND_COMPILE_SINGLE must be enabled on one source",
0773: enabled);
0774:
0775: context = Lookups.fixed(someSource1, someSource2);
0776: enabled = actionProvider.isActionEnabled(
0777: ActionProvider.COMMAND_COMPILE_SINGLE, context);
0778: assertTrue(
0779: "COMMAND_COMPILE_SINGLE must be enabled on multiple sources",
0780: enabled);
0781:
0782: context = Lookups.fixed(someTest1, someTest2);
0783: enabled = actionProvider.isActionEnabled(
0784: ActionProvider.COMMAND_COMPILE_SINGLE, context);
0785: assertTrue(
0786: "COMMAND_COMPILE_SINGLE must be enabled on multiple tests",
0787: enabled);
0788:
0789: context = Lookups.fixed(someSource1, someTest1);
0790: enabled = actionProvider.isActionEnabled(
0791: ActionProvider.COMMAND_COMPILE_SINGLE, context);
0792: assertFalse(
0793: "COMMAND_COMPILE_SINGLE must be disabled on mixed files",
0794: enabled);
0795:
0796: context = Lookups.fixed(sourcePkg1);
0797: enabled = actionProvider.isActionEnabled(
0798: ActionProvider.COMMAND_COMPILE_SINGLE, context);
0799: assertTrue(
0800: "COMMAND_COMPILE_SINGLE must be enabled on one src package",
0801: enabled);
0802:
0803: context = Lookups.fixed(sourcePkg1, sourcePkg2);
0804: enabled = actionProvider.isActionEnabled(
0805: ActionProvider.COMMAND_COMPILE_SINGLE, context);
0806: assertTrue(
0807: "COMMAND_COMPILE_SINGLE must be enabled on multiple src packages",
0808: enabled);
0809:
0810: context = Lookups.fixed(sourcePkg1, someSource1);
0811: enabled = actionProvider.isActionEnabled(
0812: ActionProvider.COMMAND_COMPILE_SINGLE, context);
0813: assertTrue(
0814: "COMMAND_COMPILE_SINGLE must be enabled on mixed src packages/files",
0815: enabled);
0816:
0817: context = Lookups.fixed(testPkg1);
0818: enabled = actionProvider.isActionEnabled(
0819: ActionProvider.COMMAND_COMPILE_SINGLE, context);
0820: assertTrue(
0821: "COMMAND_COMPILE_SINGLE must be enabled on one test package",
0822: enabled);
0823:
0824: context = Lookups.fixed(testPkg1, testPkg2);
0825: enabled = actionProvider.isActionEnabled(
0826: ActionProvider.COMMAND_COMPILE_SINGLE, context);
0827: assertTrue(
0828: "COMMAND_COMPILE_SINGLE must be enabled on multiple test packages",
0829: enabled);
0830:
0831: context = Lookups.fixed(testPkg1, someTest1);
0832: enabled = actionProvider.isActionEnabled(
0833: ActionProvider.COMMAND_COMPILE_SINGLE, context);
0834: assertTrue(
0835: "COMMAND_COMPILE_SINGLE must be enabled on mixed test packages/files",
0836: enabled);
0837:
0838: context = Lookups.fixed(DataFolder.findFolder(projdir));
0839: enabled = actionProvider.isActionEnabled(
0840: ActionProvider.COMMAND_COMPILE_SINGLE, context);
0841: assertFalse(
0842: "COMMAND_COMPILE_SINGLE must not be enabled on non source folder",
0843: enabled);
0844:
0845: context = Lookups.fixed(sourcePkg1, testPkg1);
0846: enabled = actionProvider.isActionEnabled(
0847: ActionProvider.COMMAND_COMPILE_SINGLE, context);
0848: assertFalse(
0849: "COMMAND_COMPILE_SINGLE must not be enabled on non mixed packages",
0850: enabled);
0851:
0852: // test COMMAND_TEST_SINGLE
0853:
0854: context = Lookups.fixed(someTest1);
0855: enabled = actionProvider.isActionEnabled(
0856: ActionProvider.COMMAND_TEST_SINGLE, context);
0857: assertFalse("COMMAND_TEST_SINGLE must be disabled on one test",
0858: enabled);
0859:
0860: context = Lookups.fixed(someTest1, someTest2);
0861: enabled = actionProvider.isActionEnabled(
0862: ActionProvider.COMMAND_TEST_SINGLE, context);
0863: assertFalse(
0864: "COMMAND_TEST_SINGLE must be disabled on multiple tests",
0865: enabled);
0866:
0867: context = Lookups.fixed(someSource3);
0868: enabled = actionProvider.isActionEnabled(
0869: ActionProvider.COMMAND_TEST_SINGLE, context);
0870: assertFalse(
0871: "COMMAND_TEST_SINGLE must be disabled on non-test file which does not have associated test",
0872: enabled);
0873:
0874: context = Lookups.fixed(someSource2);
0875: enabled = actionProvider.isActionEnabled(
0876: ActionProvider.COMMAND_TEST_SINGLE, context);
0877: assertTrue(
0878: "COMMAND_TEST_SINGLE must be enabled on source file which has associated test",
0879: enabled);
0880:
0881: context = Lookups.fixed(someSource1, someSource2);
0882: enabled = actionProvider.isActionEnabled(
0883: ActionProvider.COMMAND_TEST_SINGLE, context);
0884: assertTrue(
0885: "COMMAND_TEST_SINGLE must be enabled on source files which has associated tests",
0886: enabled);
0887:
0888: context = Lookups.fixed(someSource1, someSource3);
0889: enabled = actionProvider.isActionEnabled(
0890: ActionProvider.COMMAND_TEST_SINGLE, context);
0891: assertFalse(
0892: "COMMAND_TEST_SINGLE must be disabled on mixture of source files when some files do not have tests",
0893: enabled);
0894:
0895: context = Lookups.fixed(someSource1, someTest1);
0896: enabled = actionProvider.isActionEnabled(
0897: ActionProvider.COMMAND_TEST_SINGLE, context);
0898: assertFalse(
0899: "COMMAND_TEST_SINGLE must be disabled on mixture of source files and test files",
0900: enabled);
0901:
0902: // test COMMAND_DEBUG_TEST_SINGLE
0903:
0904: context = Lookups.fixed(someTest1);
0905: enabled = actionProvider.isActionEnabled(
0906: ActionProvider.COMMAND_DEBUG_TEST_SINGLE, context);
0907: assertFalse(
0908: "COMMAND_DEBUG_TEST_SINGLE must be disabled on test files",
0909: enabled);
0910:
0911: context = Lookups.fixed(someTest1, someTest2);
0912: enabled = actionProvider.isActionEnabled(
0913: ActionProvider.COMMAND_DEBUG_TEST_SINGLE, context);
0914: assertFalse(
0915: "COMMAND_DEBUG_TEST_SINGLE must be disabled on multiple tests",
0916: enabled);
0917:
0918: context = Lookups.fixed(someSource3);
0919: enabled = actionProvider.isActionEnabled(
0920: ActionProvider.COMMAND_DEBUG_TEST_SINGLE, context);
0921: assertFalse(
0922: "COMMAND_DEBUG_TEST_SINGLE must be disabled on non-test file which does not have associated test",
0923: enabled);
0924:
0925: context = Lookups.fixed(someSource2);
0926: enabled = actionProvider.isActionEnabled(
0927: ActionProvider.COMMAND_DEBUG_TEST_SINGLE, context);
0928: assertTrue(
0929: "COMMAND_DEBUG_TEST_SINGLE must be enabled on source file which has associated test",
0930: enabled);
0931:
0932: context = Lookups.fixed(someSource1, someSource2);
0933: enabled = actionProvider.isActionEnabled(
0934: ActionProvider.COMMAND_DEBUG_TEST_SINGLE, context);
0935: assertFalse(
0936: "COMMAND_DEBUG_TEST_SINGLE must be disabled on multiple source files",
0937: enabled);
0938:
0939: // test COMMAND_DEBUG_FIX
0940:
0941: context = Lookups.fixed(someTest1);
0942: enabled = actionProvider.isActionEnabled(
0943: JavaProjectConstants.COMMAND_DEBUG_FIX, context);
0944: assertTrue("COMMAND_DEBUG_FIX must be enabled on one test",
0945: enabled);
0946:
0947: context = Lookups.fixed(someTest1, someTest2);
0948: enabled = actionProvider.isActionEnabled(
0949: JavaProjectConstants.COMMAND_DEBUG_FIX, context);
0950: assertFalse(
0951: "COMMAND_DEBUG_FIX must be disabled on multiple tests",
0952: enabled);
0953:
0954: context = Lookups.fixed(someSource1);
0955: enabled = actionProvider.isActionEnabled(
0956: JavaProjectConstants.COMMAND_DEBUG_FIX, context);
0957: assertTrue("COMMAND_DEBUG_FIX must be enabled on one source",
0958: enabled);
0959:
0960: context = Lookups.fixed(someSource1, someSource2);
0961: enabled = actionProvider.isActionEnabled(
0962: JavaProjectConstants.COMMAND_DEBUG_FIX, context);
0963: assertFalse(
0964: "COMMAND_DEBUG_FIX must be disabled on multiple source files",
0965: enabled);
0966:
0967: context = Lookups.fixed(someSource1, someTest1);
0968: enabled = actionProvider.isActionEnabled(
0969: JavaProjectConstants.COMMAND_DEBUG_FIX, context);
0970: assertFalse(
0971: "COMMAND_DEBUG_FIX must be disabled on multiple mixed files",
0972: enabled);
0973:
0974: // test COMMAND_RUN_SINGLE
0975:
0976: context = Lookups.fixed(someSource1);
0977: enabled = actionProvider.isActionEnabled(
0978: ActionProvider.COMMAND_RUN_SINGLE, context);
0979: assertTrue("COMMAND_RUN_SINGLE must be enabled on one source",
0980: enabled);
0981:
0982: context = Lookups.fixed(someSource1, someSource2);
0983: enabled = actionProvider.isActionEnabled(
0984: ActionProvider.COMMAND_RUN_SINGLE, context);
0985: assertFalse(
0986: "COMMAND_RUN_SINGLE must be disabled on multiple sources",
0987: enabled);
0988:
0989: context = Lookups.fixed(someTest1);
0990: enabled = actionProvider.isActionEnabled(
0991: ActionProvider.COMMAND_RUN_SINGLE, context);
0992: assertTrue("COMMAND_RUN_SINGLE must be enabled on test file",
0993: enabled);
0994:
0995: context = Lookups.fixed(someTest1, someTest2);
0996: enabled = actionProvider.isActionEnabled(
0997: ActionProvider.COMMAND_RUN_SINGLE, context);
0998: assertFalse(
0999: "COMMAND_RUN_SINGLE must be disabled on multiple test files",
1000: enabled);
1001:
1002: context = Lookups.fixed(someSource1, someTest1);
1003: enabled = actionProvider.isActionEnabled(
1004: ActionProvider.COMMAND_RUN_SINGLE, context);
1005: assertFalse(
1006: "COMMAND_RUN_SINGLE must be disabled on mixed multiple test files",
1007: enabled);
1008:
1009: // test COMMAND_DEBUG_SINGLE
1010:
1011: context = Lookups.fixed(someSource1);
1012: enabled = actionProvider.isActionEnabled(
1013: ActionProvider.COMMAND_DEBUG_SINGLE, context);
1014: assertTrue(
1015: "COMMAND_DEBUG_SINGLE must be enabled on one source",
1016: enabled);
1017:
1018: context = Lookups.fixed(someSource1, someSource2);
1019: enabled = actionProvider.isActionEnabled(
1020: ActionProvider.COMMAND_DEBUG_SINGLE, context);
1021: assertFalse(
1022: "COMMAND_DEBUG_SINGLE must be disabled on multiple sources",
1023: enabled);
1024:
1025: context = Lookups.fixed(someTest1);
1026: enabled = actionProvider.isActionEnabled(
1027: ActionProvider.COMMAND_DEBUG_SINGLE, context);
1028: assertTrue("COMMAND_DEBUG_SINGLE must be enabled on test file",
1029: enabled);
1030:
1031: context = Lookups.fixed(someTest1, someTest2);
1032: enabled = actionProvider.isActionEnabled(
1033: ActionProvider.COMMAND_DEBUG_SINGLE, context);
1034: assertFalse(
1035: "COMMAND_DEBUG_SINGLE must be disabled on multiple test files",
1036: enabled);
1037:
1038: context = Lookups.fixed(someSource1, someTest1);
1039: enabled = actionProvider.isActionEnabled(
1040: ActionProvider.COMMAND_DEBUG_SINGLE, context);
1041: assertFalse(
1042: "COMMAND_DEBUG_SINGLE must be disabled on mixed multiple test files",
1043: enabled);
1044: }
1045:
1046: public void testBuildWithDirtyList() throws Exception { // #104508
1047: Properties p = new Properties();
1048: assertEquals("[jar]", Arrays.toString(actionProvider
1049: .getTargetNames(ActionProvider.COMMAND_BUILD,
1050: Lookup.EMPTY, p)));
1051: assertEquals("{}", p.toString());
1052: TestFileUtils.touch(someSource1.getPrimaryFile(), null);
1053: assertEquals("[jar]", Arrays.toString(actionProvider
1054: .getTargetNames(ActionProvider.COMMAND_BUILD,
1055: Lookup.EMPTY, p)));
1056: assertEquals("{}", p.toString());
1057: EditableProperties ep = helper
1058: .getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
1059: ep.put(J2SEProjectProperties.DO_JAR, "false");
1060: helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH,
1061: ep);
1062: assertEquals("[compile]", Arrays.toString(actionProvider
1063: .getTargetNames(ActionProvider.COMMAND_BUILD,
1064: Lookup.EMPTY, p)));
1065: assertEquals("{}", p.toString());
1066: ep.put(J2SEProjectProperties.DO_DEPEND, "false");
1067: helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH,
1068: ep);
1069: assertEquals("[compile]", Arrays.toString(actionProvider
1070: .getTargetNames(ActionProvider.COMMAND_BUILD,
1071: Lookup.EMPTY, p)));
1072: assertEquals("{}", p.toString());
1073: TestFileUtils.touch(someSource1.getPrimaryFile(), null);
1074: assertEquals("[compile]", Arrays.toString(actionProvider
1075: .getTargetNames(ActionProvider.COMMAND_BUILD,
1076: Lookup.EMPTY, p)));
1077: assertEquals("{includes=foo/Bar.java}", p.toString());
1078: p.clear();
1079: TestFileUtils.touch(someSource2.getPrimaryFile(), null);
1080: TestFileUtils.touch(someSource1.getPrimaryFile(), null);
1081: assertEquals("[compile]", Arrays.toString(actionProvider
1082: .getTargetNames(ActionProvider.COMMAND_BUILD,
1083: Lookup.EMPTY, p)));
1084: assertEquals("{includes=foo/Bar.java,foo/Main.java}", p
1085: .toString());
1086: p.clear();
1087: assertEquals("[compile]", Arrays.toString(actionProvider
1088: .getTargetNames(ActionProvider.COMMAND_BUILD,
1089: Lookup.EMPTY, p)));
1090: assertEquals("{}", p.toString());
1091: TestFileUtils.touch(someTest1.getPrimaryFile(), null);
1092: assertEquals("[compile]", Arrays.toString(actionProvider
1093: .getTargetNames(ActionProvider.COMMAND_BUILD,
1094: Lookup.EMPTY, p)));
1095: assertEquals("{}", p.toString());
1096: sources.createData("x.properties");
1097: assertEquals("[compile]", Arrays.toString(actionProvider
1098: .getTargetNames(ActionProvider.COMMAND_BUILD,
1099: Lookup.EMPTY, p)));
1100: assertEquals("{includes=x.properties}", p.toString());
1101: p.clear();
1102: someSource1.setModified(true);
1103: assertEquals("[compile]", Arrays.toString(actionProvider
1104: .getTargetNames(ActionProvider.COMMAND_BUILD,
1105: Lookup.EMPTY, p)));
1106: assertEquals("{includes=foo/Bar.java}", p.toString());
1107: p.clear();
1108: TestFileUtils.touch(someSource1.getPrimaryFile(), null);
1109: assertEquals("[clean, compile]", Arrays.toString(actionProvider
1110: .getTargetNames(ActionProvider.COMMAND_REBUILD,
1111: Lookup.EMPTY, p)));
1112: assertEquals("{}", p.toString());
1113: }
1114:
1115: public void testBuildWithDirtyListFirstTime() throws Exception { // #119777
1116: J2SEProject prj = (J2SEProject) pp;
1117: // Use a new instance, since the old one will already have a dirty list from setUp():
1118: actionProvider = new J2SEActionProvider(prj, prj
1119: .getUpdateHelper());
1120: EditableProperties ep = helper
1121: .getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
1122: ep.put(J2SEProjectProperties.DO_DEPEND, "false");
1123: helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH,
1124: ep);
1125: Properties p = new Properties();
1126: MainClassChooser.unitTestingSupport_hasMainMethodResult = true;
1127: try {
1128: assertEquals("[run]", Arrays.toString(actionProvider
1129: .getTargetNames(ActionProvider.COMMAND_RUN,
1130: Lookup.EMPTY, p)));
1131: assertEquals("{}", p.toString());
1132: assertEquals("[run]", Arrays.toString(actionProvider
1133: .getTargetNames(ActionProvider.COMMAND_RUN,
1134: Lookup.EMPTY, p)));
1135: assertEquals("{includes=nothing whatsoever}", p.toString());
1136: } finally {
1137: MainClassChooser.unitTestingSupport_hasMainMethodResult = null;
1138: }
1139: }
1140:
1141: private static final class NonRecursiveFolderImpl implements
1142: NonRecursiveFolder {
1143:
1144: private FileObject fobj;
1145:
1146: public NonRecursiveFolderImpl(DataObject dobj) {
1147: assert dobj != null;
1148: this .fobj = dobj.getPrimaryFile();
1149: }
1150:
1151: public NonRecursiveFolderImpl(FileObject fobj) {
1152: assert fobj != null;
1153: this .fobj = fobj;
1154: }
1155:
1156: public FileObject getFolder() {
1157: return this .fobj;
1158: }
1159: }
1160:
1161: private static class SimplePlatformProvider implements
1162: JavaPlatformProvider {
1163:
1164: public void removePropertyChangeListener(
1165: PropertyChangeListener listener) {
1166: }
1167:
1168: public void addPropertyChangeListener(
1169: PropertyChangeListener listener) {
1170: }
1171:
1172: public JavaPlatform[] getInstalledPlatforms() {
1173: return new JavaPlatform[] { getDefaultPlatform() };
1174: }
1175:
1176: public JavaPlatform getDefaultPlatform() {
1177: return new TestDefaultPlatform();
1178: }
1179:
1180: }
1181:
1182: private static class TestDefaultPlatform extends JavaPlatform {
1183:
1184: public TestDefaultPlatform() {
1185:
1186: }
1187:
1188: public FileObject findTool(String toolName) {
1189: return null;
1190: }
1191:
1192: public String getDisplayName() {
1193: return "Default Platform";
1194: }
1195:
1196: public ClassPath getBootstrapLibraries() {
1197: return ClassPathSupport.createClassPath(new URL[0]);
1198: }
1199:
1200: public Collection<FileObject> getInstallFolders() {
1201: return null;
1202: }
1203:
1204: public ClassPath getStandardLibraries() {
1205: return ClassPathSupport.createClassPath(new URL[0]);
1206: }
1207:
1208: public String getVendor() {
1209: return null;
1210: }
1211:
1212: public Specification getSpecification() {
1213: return new Specification("j2se", new SpecificationVersion(
1214: "1.4"));
1215: }
1216:
1217: public ClassPath getSourceFolders() {
1218: return ClassPathSupport.createClassPath(new URL[0]);
1219: }
1220:
1221: public List<URL> getJavadocFolders() {
1222: return null;
1223: }
1224:
1225: public Map<String, String> getProperties() {
1226: return Collections.singletonMap("platform.ant.name",
1227: "default_platform");
1228: }
1229:
1230: }
1231:
1232: private void write(Properties p, FileObject d, String path)
1233: throws IOException {
1234: FileObject f = FileUtil.createData(d, path);
1235: OutputStream os = f.getOutputStream();
1236: p.store(os, null);
1237: os.close();
1238: }
1239:
1240: }
|