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.spi.project.support.ant;
0043:
0044: import java.io.File;
0045: import java.io.OutputStream;
0046: import java.net.URI;
0047: import java.net.URL;
0048: import java.util.ArrayList;
0049: import java.util.Arrays;
0050: import java.util.Collection;
0051: import java.util.Collections;
0052: import java.util.List;
0053: import java.util.Properties;
0054: import java.util.Set;
0055: import java.util.TreeSet;
0056: import org.netbeans.api.project.Project;
0057: import org.netbeans.api.project.ProjectManager;
0058: import org.netbeans.api.project.ProjectUtils;
0059: import org.netbeans.api.project.TestUtil;
0060: import org.netbeans.api.project.ant.AntArtifact;
0061: import org.netbeans.api.project.ant.AntArtifactQuery;
0062: import org.netbeans.api.project.libraries.Library;
0063: import org.netbeans.api.project.libraries.LibraryManager;
0064: import org.netbeans.api.queries.CollocationQuery;
0065: import org.netbeans.junit.NbTestCase;
0066: import org.netbeans.modules.project.ant.ProjectLibraryProvider;
0067: import org.netbeans.modules.project.ant.Util;
0068: import org.netbeans.spi.project.AuxiliaryConfiguration;
0069: import org.netbeans.spi.project.SubprojectProvider;
0070: import org.netbeans.spi.queries.CollocationQueryImplementation;
0071: import org.openide.filesystems.FileLock;
0072: import org.openide.filesystems.FileObject;
0073: import org.openide.filesystems.FileUtil;
0074: import org.openide.util.lookup.Lookups;
0075: import org.openide.util.test.MockLookup;
0076: import org.w3c.dom.Document;
0077: import org.w3c.dom.Element;
0078: import org.w3c.dom.NodeList;
0079:
0080: /* XXX tests needed
0081: * - testAddArtifactCollocation
0082: * check that collocated foreign projects update project.properties
0083: * while noncollocated foreign projects update private.properties
0084: * and that absolute artifact locns -> private.properties
0085: * also addForeignFileReference(File,String) on plain files needs to
0086: * check collocation
0087: * - testUniquifyProjectNames
0088: * check that foreign project names are uniquified correctly
0089: * both in addReference and addForeignFileReference etc.
0090: * - testVcsFriendliness
0091: * check that refs are added in a predictable order
0092: */
0093:
0094: /**
0095: * Test functionality of ReferenceHelper.
0096: * @author Jesse Glick
0097: */
0098: public class ReferenceHelperTest extends NbTestCase {
0099:
0100: /**
0101: * Create the test suite.
0102: * @param name suite name
0103: */
0104: public ReferenceHelperTest(String name) {
0105: super (name);
0106: }
0107:
0108: /** Scratch directory. */
0109: private FileObject scratch;
0110: /** Directory of master project (proj). */
0111: private FileObject projdir;
0112: /**
0113: * Directory of a collocated sister project (proj2).
0114: * Has artifacts build.jar=dist/proj2.jar and
0115: * build.javadoc=build/javadoc as well as
0116: * build.javadoc.complete=build/complete-javadoc.
0117: */
0118: private FileObject sisterprojdir;
0119: /**
0120: * The same structure as sisterprojdir but in different folder.
0121: * Useful for testing that referenceIDs are uniquified.
0122: */
0123: private FileObject sisterprojdir2;
0124: /**
0125: * Directory of a noncollocated project (proj3).
0126: * Has artifact build.jar=d i s t/p r o j 3.jar.
0127: */
0128: private FileObject sepprojdir;
0129: /** The project manager singleton. */
0130: private ProjectManager pm;
0131: /** The master project. */
0132: private Project p;
0133: /** The master project's helper. */
0134: private AntProjectHelper h;
0135: /** The collocated sister project's helper. */
0136: private AntProjectHelper sisterh;
0137: /** The collocated sister2 project's helper. */
0138: private AntProjectHelper sisterh2;
0139: /** The noncollocated project's helper. */
0140: private AntProjectHelper seph;
0141: /** The master project's reference helper. */
0142: private ReferenceHelper r;
0143: //private AntBasedTestUtil.TestListener l;
0144: private PropertyEvaluator pev;
0145:
0146: private static void setCodeNameOfTestProject(
0147: AntProjectHelper helper, String name) {
0148: Element data = helper.getPrimaryConfigurationData(true);
0149: Element nameEl = data.getOwnerDocument().createElementNS(
0150: "urn:test:shared", "name");
0151: nameEl
0152: .appendChild(data.getOwnerDocument().createTextNode(
0153: name));
0154: data.appendChild(nameEl);
0155: helper.putPrimaryConfigurationData(data, true);
0156: }
0157:
0158: protected void setUp() throws Exception {
0159: super .setUp();
0160: ClassLoader l = ReferenceHelper.class.getClassLoader();
0161: MockLookup.setLookup(Lookups.fixed(AntBasedTestUtil
0162: .testAntBasedProjectType(), AntBasedTestUtil
0163: .testCollocationQueryImplementation(getWorkDir())),
0164: Lookups.singleton(l), Lookups.exclude(Lookups
0165: .metaInfServices(l),
0166: CollocationQueryImplementation.class));
0167: scratch = TestUtil.makeScratchDir(this );
0168: projdir = scratch.createFolder("proj");
0169: TestUtil.createFileFromContent(ReferenceHelperTest.class
0170: .getResource("data/project.xml"), projdir,
0171: "nbproject/project.xml");
0172: pm = ProjectManager.getDefault();
0173: p = pm.findProject(projdir);
0174: assertNotNull("found project in " + projdir, p);
0175: h = p.getLookup().lookup(AntProjectHelper.class);
0176: assertNotNull("found helper for " + p, h);
0177: r = p.getLookup().lookup(ReferenceHelper.class);
0178: assertNotNull("found ref helper for " + p, r);
0179: sisterprojdir = FileUtil.createFolder(scratch, "proj2");
0180: assertTrue("projdir and sisterprojdir collocated",
0181: CollocationQuery.areCollocated(
0182: FileUtil.toFile(projdir), FileUtil
0183: .toFile(sisterprojdir)));
0184: sisterh = ProjectGenerator.createProject(sisterprojdir, "test");
0185: setCodeNameOfTestProject(sisterh, "proj2");
0186: EditableProperties props = sisterh
0187: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
0188: props.setProperty("build.jar", "dist/proj2.jar");
0189: props.setProperty("build.javadoc", "build/javadoc");
0190: props.setProperty("build.javadoc.complete",
0191: "build/complete-javadoc");
0192: sisterh.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,
0193: props);
0194: // Probably unnecessary: pm.saveProject(pm.findProject(sisterprojdir));
0195:
0196: sisterprojdir2 = FileUtil.createFolder(scratch, "proj2-copy");
0197: assertTrue("projdir and sisterprojdir2 collocated",
0198: CollocationQuery.areCollocated(
0199: FileUtil.toFile(projdir), FileUtil
0200: .toFile(sisterprojdir2)));
0201: sisterh2 = ProjectGenerator.createProject(sisterprojdir2,
0202: "test");
0203: setCodeNameOfTestProject(sisterh2, "proj2");
0204: props = sisterh2
0205: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
0206: props.setProperty("build.jar", "dist/proj2.jar");
0207: props.setProperty("build.javadoc", "build/javadoc");
0208: props.setProperty("build.javadoc.complete",
0209: "build/complete-javadoc");
0210: sisterh2.putProperties(
0211: AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
0212:
0213: sepprojdir = FileUtil.createFolder(scratch, "separate/proj3");
0214: // If following assert fails then there is a global impl of collocation
0215: // query which says that these two files are collocated. Hidden it
0216: // similarly as it is done for SampleCVSCollocationQueryImpl
0217: // in META-INF/services.
0218: assertFalse("" + projdir + " and " + sepprojdir
0219: + " cannot be collocated", CollocationQuery
0220: .areCollocated(FileUtil.toFile(projdir), FileUtil
0221: .toFile(sepprojdir)));
0222: seph = ProjectGenerator.createProject(sepprojdir, "test");
0223: setCodeNameOfTestProject(seph, "proj3");
0224: props = seph
0225: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
0226: props.setProperty("build.jar", "d i s t/p r o j 3.jar");
0227: seph.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,
0228: props);
0229: //l = new AntBasedTestUtil.TestListener();
0230:
0231: pev = h.getStandardPropertyEvaluator();
0232: }
0233:
0234: protected void tearDown() throws Exception {
0235: scratch = null;
0236: projdir = null;
0237: sisterprojdir = null;
0238: sisterh = null;
0239: //sepprojdir = null;
0240: pm = null;
0241: p = null;
0242: h = null;
0243: //l = null;
0244: super .tearDown();
0245: }
0246:
0247: /**
0248: * Check that the raw add, get, and remove calls work.
0249: * @throws Exception in case of unexpected failures
0250: */
0251: @SuppressWarnings("deprecation")
0252: public void testRawReferenceManipulation() throws Exception {
0253: assertEquals("starting with no raw references",
0254: Collections.EMPTY_LIST, Arrays.asList(r
0255: .getRawReferences()));
0256: // Test simple adding of a reference.
0257: ReferenceHelper.RawReference ref = new ReferenceHelper.RawReference(
0258: "otherproj", "jar", URI.create("build.xml"), "dojar",
0259: "clean", "dojarID");
0260: assertTrue("successfully added a raw ref to otherproj.dojar", r
0261: .addRawReference(ref));
0262: assertNull("project.properties not changed", pev
0263: .getProperty("project.otherproj"));
0264: assertTrue("project is modified", pm.isModified(p));
0265: ref = r.getRawReference("otherproj", "dojarID");
0266: assertNotNull("found otherproj.dojar", ref);
0267: assertEquals("correct foreign project name", "otherproj", ref
0268: .getForeignProjectName());
0269: assertEquals("correct artifact type", "jar", ref
0270: .getArtifactType());
0271: assertEquals("correct script location",
0272: URI.create("build.xml"), ref.getScriptLocation());
0273: assertEquals("correct script location",
0274: "${project.otherproj}/build.xml", ref
0275: .getScriptLocationValue());
0276: assertEquals("correct target name", "dojar", ref
0277: .getTargetName());
0278: assertEquals("correct clean target name", "clean", ref
0279: .getCleanTargetName());
0280: assertEquals("correct ID name", "dojarID", ref.getID());
0281: // Nonexistent references are not returned.
0282: ref = r.getRawReference("otherproj2", "dojarID");
0283: assertNull("no such ref otherproj2.dojar", ref);
0284: ref = r.getRawReference("otherproj", "dojar2");
0285: assertNull("no such ref otherproj.dojar2", ref);
0286: ref = r.getRawReference("otherproj2", "dojar2");
0287: assertNull("no such ref otherproj2.dojar2", ref);
0288: // The reference is found now.
0289: ReferenceHelper.RawReference[] refs = r.getRawReferences();
0290: assertEquals("one reference here", 1, refs.length);
0291: ref = refs[0];
0292: assertEquals("correct foreign project name", "otherproj", ref
0293: .getForeignProjectName());
0294: assertEquals("correct artifact type", "jar", ref
0295: .getArtifactType());
0296: assertEquals("correct script location",
0297: "${project.otherproj}/build.xml", ref
0298: .getScriptLocationValue());
0299: assertEquals("correct target name", "dojar", ref
0300: .getTargetName());
0301: assertEquals("correct clean target name", "clean", ref
0302: .getCleanTargetName());
0303: assertEquals("correct ID name", "dojarID", ref.getID());
0304: // Test removing it.
0305: assertTrue("successfully removed otherproj.dojar", r
0306: .removeRawReference("otherproj", "dojarID"));
0307: refs = r.getRawReferences();
0308: assertEquals("no references here", 0, refs.length);
0309: ref = r.getRawReference("otherproj", "dojar");
0310: assertNull("otherproj.dojar is gone", ref);
0311: // Test adding several references.
0312: ref = new ReferenceHelper.RawReference("otherproj", "jar", URI
0313: .create("build.xml"), "dojar", "clean", "dojarID");
0314: assertTrue("added ref to otherproj.dojar", r
0315: .addRawReference(ref));
0316: ref = new ReferenceHelper.RawReference("otherproj", "jar", URI
0317: .create("build.xml"), "dojar2", "clean", "dojar2ID");
0318: assertTrue("added ref to otherproj.dojar2", r
0319: .addRawReference(ref));
0320: ref = new ReferenceHelper.RawReference("otherproj2", "ear", URI
0321: .create("build.xml"), "dojar", "clean", "dojarID");
0322: assertTrue("added ref to otherproj2.dojar", r
0323: .addRawReference(ref));
0324: assertEquals("have three refs", 3, r.getRawReferences().length);
0325: // Test no-op adds and removes.
0326: pm.saveProject(p);
0327: assertFalse("project is saved", pm.isModified(p));
0328: ref = new ReferenceHelper.RawReference("otherproj", "jar", URI
0329: .create("build.xml"), "dojar", "clean", "dojarID");
0330: assertFalse("already had ref to otherproj.dojar", r
0331: .addRawReference(ref));
0332: assertFalse("project is not modified by no-op add", pm
0333: .isModified(p));
0334: assertEquals("still have three refs", 3,
0335: r.getRawReferences().length);
0336: assertFalse("did not have ref to foo.bar", r
0337: .removeRawReference("foo", "bar"));
0338: assertFalse("project is not modified by no-op remove", pm
0339: .isModified(p));
0340: assertEquals("still have three refs", 3,
0341: r.getRawReferences().length);
0342: // Test modifications.
0343: ref = new ReferenceHelper.RawReference("otherproj", "war", URI
0344: .create("build.xml"), "dojar", "clean", "dojarID");
0345: assertTrue("modified ref to otherproj.dojar", r
0346: .addRawReference(ref));
0347: assertTrue("project is modified by changed ref", pm
0348: .isModified(p));
0349: assertEquals("still have three refs", 3,
0350: r.getRawReferences().length);
0351: ref = r.getRawReference("otherproj", "dojarID");
0352: assertEquals("correct foreign project name", "otherproj", ref
0353: .getForeignProjectName());
0354: assertEquals("correct modified artifact type", "war", ref
0355: .getArtifactType());
0356: assertEquals("correct script location",
0357: "${project.otherproj}/build.xml", ref
0358: .getScriptLocationValue());
0359: assertEquals("correct target name", "dojar", ref
0360: .getTargetName());
0361: assertEquals("correct clean target name", "clean", ref
0362: .getCleanTargetName());
0363: assertEquals("correct ID name", "dojarID", ref.getID());
0364: ref = new ReferenceHelper.RawReference("otherproj", "war", URI
0365: .create("build2.xml"), "dojar", "clean", "dojarID");
0366: assertTrue("modified ref to otherproj.dojar", r
0367: .addRawReference(ref));
0368: ref = new ReferenceHelper.RawReference("otherproj", "war", URI
0369: .create("build2.xml"), "dojar", "clean2", "dojarID");
0370: assertTrue("modified ref to otherproj.dojar", r
0371: .addRawReference(ref));
0372: ref = r.getRawReference("otherproj", "dojarID");
0373: assertEquals("correct foreign project name", "otherproj", ref
0374: .getForeignProjectName());
0375: assertEquals("correct modified artifact type", "war", ref
0376: .getArtifactType());
0377: assertEquals("correct script location",
0378: "${project.otherproj}/build2.xml", ref
0379: .getScriptLocationValue());
0380: assertEquals("correct target name", "dojar", ref
0381: .getTargetName());
0382: assertEquals("correct clean target name", "clean2", ref
0383: .getCleanTargetName());
0384: assertEquals("correct ID name", "dojarID", ref.getID());
0385: assertEquals("still have three refs", 3,
0386: r.getRawReferences().length);
0387: // More removals and adds.
0388: assertTrue("now removing otherproj.dojar2", r
0389: .removeRawReference("otherproj", "dojar2ID"));
0390: assertNull("otherproj.dojar2 is gone", r.getRawReference(
0391: "otherproj", "dojar2ID"));
0392: assertNotNull("otherproj.jar is still there", r
0393: .getRawReference("otherproj", "dojarID"));
0394: assertNotNull("otherproj2.dojar is still there", r
0395: .getRawReference("otherproj2", "dojarID"));
0396: assertEquals("down to two refs", 2, r.getRawReferences().length);
0397: ref = new ReferenceHelper.RawReference("aardvark", "jar", URI
0398: .create("build.xml"), "jar", "clean", "jarID");
0399: assertTrue("added ref to aardvark.jar", r.addRawReference(ref));
0400: // Check list of refs.
0401: refs = r.getRawReferences();
0402: assertEquals("back to three refs", 3, refs.length);
0403: // NOTE on undocumented constraint: getRawReferences should sort results by proj then target
0404: ref = refs[0];
0405: assertEquals("correct foreign project name", "aardvark", ref
0406: .getForeignProjectName());
0407: assertEquals("correct modified artifact type", "jar", ref
0408: .getArtifactType());
0409: assertEquals("correct script location",
0410: "${project.aardvark}/build.xml", ref
0411: .getScriptLocationValue());
0412: assertEquals("correct target name", "jar", ref.getTargetName());
0413: assertEquals("correct clean target name", "clean", ref
0414: .getCleanTargetName());
0415: assertEquals("correct ID name", "jarID", ref.getID());
0416: ref = refs[1];
0417: assertEquals("correct foreign project name", "otherproj", ref
0418: .getForeignProjectName());
0419: assertEquals("correct modified artifact type", "war", ref
0420: .getArtifactType());
0421: assertEquals("correct script location",
0422: "${project.otherproj}/build2.xml", ref
0423: .getScriptLocationValue());
0424: assertEquals("correct target name", "dojar", ref
0425: .getTargetName());
0426: assertEquals("correct clean target name", "clean2", ref
0427: .getCleanTargetName());
0428: assertEquals("correct ID name", "dojarID", ref.getID());
0429: ref = refs[2];
0430: assertEquals("correct foreign project name", "otherproj2", ref
0431: .getForeignProjectName());
0432: assertEquals("correct modified artifact type", "ear", ref
0433: .getArtifactType());
0434: assertEquals("correct script location",
0435: "${project.otherproj2}/build.xml", ref
0436: .getScriptLocationValue());
0437: assertEquals("correct target name", "dojar", ref
0438: .getTargetName());
0439: assertEquals("correct clean target name", "clean", ref
0440: .getCleanTargetName());
0441: assertEquals("correct ID name", "dojarID", ref.getID());
0442: // Try saving and checking that project.xml is correct.
0443: assertTrue("Project is still modified", pm.isModified(p));
0444: pm.saveProject(p);
0445: Document doc = AntBasedTestUtil.slurpXml(h,
0446: AntProjectHelper.PROJECT_XML_PATH);
0447: Element config = Util.findElement(doc.getDocumentElement(),
0448: "configuration", AntProjectHelper.PROJECT_NS);
0449: assertNotNull("have <configuration>", config);
0450: Element references = Util.findElement(config,
0451: ReferenceHelper.REFS_NAME, ReferenceHelper.REFS_NS);
0452: assertNotNull("have <references>", references);
0453: NodeList nl = references.getElementsByTagNameNS(
0454: ReferenceHelper.REFS_NS, "reference");
0455: assertEquals("have three <reference>s", 3, nl.getLength());
0456: String[] elementNames = { "foreign-project", "artifact-type",
0457: "script", "target", "clean-target", "id", };
0458: String[][] values = {
0459: { "aardvark", "jar", "build.xml", "jar", "clean",
0460: "jarID", },
0461: { "otherproj", "war", "build2.xml", "dojar", "clean2",
0462: "dojarID", },
0463: { "otherproj2", "ear", "build.xml", "dojar", "clean",
0464: "dojarID", }, };
0465: for (int i = 0; i < 3; i++) {
0466: Element reference = (Element) nl.item(i);
0467: for (int j = 0; j < 6; j++) {
0468: String elementName = elementNames[j];
0469: Element element = Util.findElement(reference,
0470: elementName, ReferenceHelper.REFS_NS);
0471: assertNotNull("had element " + elementName
0472: + " in ref #" + i, element);
0473: assertEquals("correct text in " + elementName
0474: + " in ref #" + i, values[i][j], Util
0475: .findText(element));
0476: }
0477: }
0478: }
0479:
0480: /**
0481: * Check that the adding and removing artifact objects updates everything it should.
0482: * @throws Exception in case of unexpected failures
0483: */
0484: @SuppressWarnings("deprecation")
0485: public void testAddRemoveArtifact() throws Exception {
0486: // Add one artifact. Check that the raw reference is there.
0487: assertFalse("project not initially modified", pm.isModified(p));
0488: AntArtifact art = sisterh.createSimpleAntArtifact("jar",
0489: "build.jar", sisterh.getStandardPropertyEvaluator(),
0490: "dojar", "clean");
0491: assertFalse("reference exist", r.isReferenced(art, art
0492: .getArtifactLocations()[0]));
0493: assertTrue("added a ref to proj2.dojar", r.addReference(art));
0494: assertTrue("reference exist", r.isReferenced(art, art
0495: .getArtifactLocations()[0]));
0496: assertTrue("project now modified", pm.isModified(p));
0497: ReferenceHelper.RawReference[] refs = r.getRawReferences();
0498: assertEquals("one ref now", 1, refs.length);
0499: ReferenceHelper.RawReference ref = refs[0];
0500: assertEquals("correct foreign project name", "proj2", ref
0501: .getForeignProjectName());
0502: assertEquals("correct artifact type", "jar", ref
0503: .getArtifactType());
0504: assertEquals("correct script location",
0505: "${project.proj2}/build.xml", ref
0506: .getScriptLocationValue());
0507: assertEquals("correct target name", "dojar", ref
0508: .getTargetName());
0509: assertEquals("correct clean target name", "clean", ref
0510: .getCleanTargetName());
0511: // Check that the project properties are correct.
0512: EditableProperties props = h
0513: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
0514: assertEquals("correct ${project.proj2}", "../proj2", props
0515: .getProperty("project.proj2"));
0516: assertEquals("correct evaluated ${project.proj2}", FileUtil
0517: .toFile(sisterprojdir), h.resolveFile(pev
0518: .getProperty("project.proj2")));
0519: assertEquals("correct ${reference.proj2.dojar}",
0520: "${project.proj2}/dist/proj2.jar", props
0521: .getProperty("reference.proj2.dojar"));
0522: assertEquals("correct evaluated ${reference.proj2.dojar}",
0523: new File(new File(FileUtil.toFile(sisterprojdir),
0524: "dist"), "proj2.jar"), h.resolveFile(pev
0525: .getProperty("reference.proj2.dojar")));
0526: // Check no-op adds.
0527: pm.saveProject(p);
0528: assertTrue("reference exist", r.isReferenced(art, art
0529: .getArtifactLocations()[0]));
0530: assertFalse("no-op add", r.addReference(art));
0531: assertFalse("project not modified by no-op add", pm
0532: .isModified(p));
0533: // Try another artifact from the same project.
0534: art = sisterh.createSimpleAntArtifact("javadoc",
0535: "build.javadoc",
0536: sisterh.getStandardPropertyEvaluator(), "dojavadoc",
0537: "clean");
0538: assertFalse("reference does not exist", r.isReferenced(art, art
0539: .getArtifactLocations()[0]));
0540: assertNotNull("added a ref to proj2.dojavadoc", r.addReference(
0541: art, art.getArtifactLocations()[0]));
0542: assertTrue("project now modified", pm.isModified(p));
0543: refs = r.getRawReferences();
0544: assertEquals("two refs now", 2, refs.length);
0545: ref = refs[0];
0546: assertEquals("correct foreign project name", "proj2", ref
0547: .getForeignProjectName());
0548: assertEquals("correct target name", "dojar", ref
0549: .getTargetName());
0550: ref = refs[1];
0551: assertEquals("correct foreign project name", "proj2", ref
0552: .getForeignProjectName());
0553: assertEquals("correct artifact type", "javadoc", ref
0554: .getArtifactType());
0555: assertEquals("correct script location",
0556: "${project.proj2}/build.xml", ref
0557: .getScriptLocationValue());
0558: assertEquals("correct target name", "dojavadoc", ref
0559: .getTargetName());
0560: assertEquals("correct clean target name", "clean", ref
0561: .getCleanTargetName());
0562: props = h
0563: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
0564: assertEquals("correct ${project.proj2}", "../proj2", props
0565: .getProperty("project.proj2"));
0566: assertEquals("still correct ${reference.proj2.dojar}",
0567: "${project.proj2}/dist/proj2.jar", props
0568: .getProperty("reference.proj2.dojar"));
0569: assertEquals("correct ${reference.proj2.dojavadoc}",
0570: "${project.proj2}/build/javadoc", props
0571: .getProperty("reference.proj2.dojavadoc"));
0572: assertEquals("correct evaluated ${reference.proj2.dojavadoc}",
0573: new File(new File(FileUtil.toFile(sisterprojdir),
0574: "build"), "javadoc"), h.resolveFile(pev
0575: .getProperty("reference.proj2.dojavadoc")));
0576: pm.saveProject(p);
0577: assertTrue("reference exist", r.isReferenced(art, art
0578: .getArtifactLocations()[0]));
0579: r.addReference(art, art.getArtifactLocations()[0]);
0580: assertFalse("project not modified by no-op add", pm
0581: .isModified(p));
0582: // Try modifying the second artifact in some way.
0583: // Note that only changes in the type, clean target, and artifact path count as modifications.
0584: art = sisterh.createSimpleAntArtifact("javadoc.html",
0585: "build.javadoc",
0586: sisterh.getStandardPropertyEvaluator(), "dojavadoc",
0587: "clean");
0588: assertFalse("reference exist but needs to be updated", r
0589: .isReferenced(art, art.getArtifactLocations()[0]));
0590: r.addReference(art, art.getArtifactLocations()[0]);
0591: assertTrue("project modified by ref mod", pm.isModified(p));
0592: refs = r.getRawReferences();
0593: assertEquals("still two refs", 2, refs.length);
0594: ref = refs[1];
0595: assertEquals("correct foreign project name", "proj2", ref
0596: .getForeignProjectName());
0597: assertEquals("correct modified artifact type", "javadoc.html",
0598: ref.getArtifactType());
0599: assertEquals("correct script location",
0600: "${project.proj2}/build.xml", ref
0601: .getScriptLocationValue());
0602: assertEquals("correct target name", "dojavadoc", ref
0603: .getTargetName());
0604: assertEquals("correct clean target name", "clean", ref
0605: .getCleanTargetName());
0606: art = sisterh.createSimpleAntArtifact("javadoc.html",
0607: "build.javadoc",
0608: sisterh.getStandardPropertyEvaluator(), "dojavadoc",
0609: "realclean");
0610: r.addReference(art, art.getArtifactLocations()[0]);
0611: pm.saveProject(p);
0612: art = sisterh.createSimpleAntArtifact("javadoc.html",
0613: "build.javadoc.complete", sisterh
0614: .getStandardPropertyEvaluator(), "dojavadoc",
0615: "realclean");
0616: r.addReference(art, art.getArtifactLocations()[0]);
0617: assertTrue("project modified by ref mod", pm.isModified(p));
0618: refs = r.getRawReferences();
0619: assertEquals("still two refs", 2, refs.length);
0620: ref = refs[1];
0621: assertEquals("correct foreign project name", "proj2", ref
0622: .getForeignProjectName());
0623: assertEquals("correct modified artifact type", "javadoc.html",
0624: ref.getArtifactType());
0625: assertEquals("correct script location",
0626: "${project.proj2}/build.xml", ref
0627: .getScriptLocationValue());
0628: assertEquals("correct target name", "dojavadoc", ref
0629: .getTargetName());
0630: assertEquals("correct modified clean target name", "realclean",
0631: ref.getCleanTargetName());
0632: // Check that changing the artifact location property changed the reference property too.
0633: props = h
0634: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
0635: assertEquals("correct ${project.proj2}", "../proj2", props
0636: .getProperty("project.proj2"));
0637: assertEquals("still correct ${reference.proj2.dojar}",
0638: "${project.proj2}/dist/proj2.jar", props
0639: .getProperty("reference.proj2.dojar"));
0640: assertEquals("correct ${reference.proj2.dojavadoc}",
0641: "${project.proj2}/build/complete-javadoc", props
0642: .getProperty("reference.proj2.dojavadoc"));
0643: assertEquals("correct evaluated ${reference.proj2.dojavadoc}",
0644: new File(new File(FileUtil.toFile(sisterprojdir),
0645: "build"), "complete-javadoc"),
0646: h.resolveFile(pev
0647: .getProperty("reference.proj2.dojavadoc")));
0648: // Check that changing the value of the artifact location property
0649: // in the subproject modifies this project.
0650: pm.saveProject(p);
0651: assertTrue("reference exist but needs to be updated", r
0652: .isReferenced(art, art.getArtifactLocations()[0]));
0653: r.addReference(art, art.getArtifactLocations()[0]);
0654: assertFalse("project not modified by no-op add", pm
0655: .isModified(p));
0656: props = sisterh
0657: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
0658: props.setProperty("build.javadoc.complete",
0659: "build/total-javadoc");
0660: sisterh.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,
0661: props);
0662: r.addReference(art, art.getArtifactLocations()[0]);
0663: assertTrue(
0664: "project modified by new ${reference.proj2.dojavadoc}",
0665: pm.isModified(p));
0666: props = h
0667: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
0668: assertEquals("correct ${reference.proj2.dojavadoc}",
0669: "${project.proj2}/build/total-javadoc", props
0670: .getProperty("reference.proj2.dojavadoc"));
0671: assertEquals("correct evaluated ${reference.proj2.dojavadoc}",
0672: new File(new File(FileUtil.toFile(sisterprojdir),
0673: "build"), "total-javadoc"), h.resolveFile(pev
0674: .getProperty("reference.proj2.dojavadoc")));
0675: // Now try removing first ref. Should remove raw ref, ref property, but not project property.
0676: pm.saveProject(p);
0677: assertTrue("remove proj2.dojar succeeded", r
0678: .destroyReference("${reference.proj2.dojar}"));
0679: assertTrue("remove ref modified project", pm.isModified(p));
0680: refs = r.getRawReferences();
0681: assertEquals("now have just one ref", 1, refs.length);
0682: ref = refs[0];
0683: assertEquals("correct foreign project name", "proj2", ref
0684: .getForeignProjectName());
0685: assertEquals("correct modified artifact type", "javadoc.html",
0686: ref.getArtifactType());
0687: assertEquals("correct script location",
0688: "${project.proj2}/build.xml", ref
0689: .getScriptLocationValue());
0690: assertEquals("correct target name", "dojavadoc", ref
0691: .getTargetName());
0692: assertEquals("correct modified clean target name", "realclean",
0693: ref.getCleanTargetName());
0694: props = h
0695: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
0696: assertEquals("correct ${project.proj2}", "../proj2", props
0697: .getProperty("project.proj2"));
0698: assertEquals("no more ${reference.proj2.dojar}", null, props
0699: .getProperty("reference.proj2.dojar"));
0700: assertEquals("still correct ${reference.proj2.dojavadoc}",
0701: "${project.proj2}/build/total-javadoc", props
0702: .getProperty("reference.proj2.dojavadoc"));
0703: pm.saveProject(p);
0704: assertFalse("no-op remove proj2.dojar failed", r
0705: .destroyReference("${reference.proj2.dojar}"));
0706: assertFalse("no-op remove did not modify project", pm
0707: .isModified(p));
0708: // Try removing second ref. Should now remove project property.
0709: assertTrue("remove proj2.dojavadoc succeeded", r
0710: .destroyReference("${reference.proj2.dojavadoc}"));
0711: assertTrue("remove ref modified project", pm.isModified(p));
0712: refs = r.getRawReferences();
0713: assertEquals("now have no refs", 0, refs.length);
0714: props = h
0715: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
0716: assertEquals("no more ${project.proj2}", null, props
0717: .getProperty("project.proj2"));
0718: assertEquals("no more ${reference.proj2.dojar}", null, props
0719: .getProperty("reference.proj2.dojar"));
0720: assertEquals("no more ${reference.proj2.dojavadoc}", null,
0721: props.getProperty("reference.proj2.dojavadoc"));
0722: // XXX check add ref not coming from project gives IAE
0723:
0724: // test AA with multiple outputs:
0725: AntArtifact aa = new AntBasedTestUtil.TestAntArtifact(
0726: new URI[] { new URI("dist/foo.jar"),
0727: new URI("dist/bar.jar") }, sisterh);
0728: String ref1 = r.addReference(aa, aa.getArtifactLocations()[0]);
0729: String ref2 = r.addReference(aa, aa.getArtifactLocations()[1]);
0730: assertEquals("correct evaluated ref1", new File(new File(
0731: FileUtil.toFile(sisterprojdir), "dist"), "foo.jar"), h
0732: .resolveFile(pev.evaluate(ref1)));
0733: assertEquals("correct evaluated ref2", new File(new File(
0734: FileUtil.toFile(sisterprojdir), "dist"), "bar.jar"), h
0735: .resolveFile(pev.evaluate(ref2)));
0736: r.destroyReference(ref1);
0737: assertEquals("correct evaluated ref2", new File(new File(
0738: FileUtil.toFile(sisterprojdir), "dist"), "bar.jar"), h
0739: .resolveFile(pev.evaluate(ref2)));
0740: assertEquals("ref1 does not exist", ref1, pev.evaluate(ref1));
0741: r.destroyReference(ref2);
0742: assertEquals("ref1 does not exist", ref1, pev.evaluate(ref1));
0743: assertEquals("ref2 does not exist", ref2, pev.evaluate(ref2));
0744: pm.saveProject(p);
0745: }
0746:
0747: @SuppressWarnings("deprecation")
0748: public void testReferenceEscaping() throws Exception {
0749: // check that artifact reference is correctly escaped. All dot characters
0750: // in project name or artifact ID must be escaped, etc.
0751: FileObject proj4Folder = FileUtil
0752: .createFolder(scratch, "proj4");
0753: AntProjectHelper proj4Helper = ProjectGenerator.createProject(
0754: proj4Folder, "test");
0755: setCodeNameOfTestProject(proj4Helper, "pro-ject.4");
0756: Project p = pm.findProject(projdir);
0757: ReferenceHelper referenceHelperProj4 = p.getLookup().lookup(
0758: ReferenceHelper.class);
0759: AntArtifact art = proj4Helper.createSimpleAntArtifact("jar",
0760: "build.jar",
0761: proj4Helper.getStandardPropertyEvaluator(), "do.jar",
0762: "clean");
0763: String ref = referenceHelperProj4.addReference(art, art
0764: .getArtifactLocations()[0]);
0765: assertEquals("Project reference was not correctly escaped",
0766: "${reference.pro-ject_4.do_jar}", ref);
0767:
0768: // test that it can be found
0769: ReferenceHelper.RawReference rr = referenceHelperProj4
0770: .getRawReference("pro-ject_4", "do_jar", false);
0771: assertNull("Cannot be found because it was escaped", rr);
0772: rr = referenceHelperProj4.getRawReference("pro-ject_4",
0773: "do_jar", true);
0774: assertNotNull("Created reference was not created", rr);
0775: assertEquals("do.jar", rr.getID());
0776: assertEquals("pro-ject_4", rr.getForeignProjectName());
0777:
0778: // test deletion
0779: referenceHelperProj4.destroyForeignFileReference(ref);
0780: rr = referenceHelperProj4.getRawReference("pro-ject_4",
0781: "do_jar", true);
0782: assertNull("Reference was not deleted", rr);
0783: }
0784:
0785: public void testArtifactProperties() throws Exception {
0786: assertFalse("project not initially modified", pm.isModified(p));
0787: AntArtifact art = sisterh.createSimpleAntArtifact("jar",
0788: "build.jar", sisterh.getStandardPropertyEvaluator(),
0789: "dojar", "clean");
0790: art.getProperties().setProperty("configuration", "debug");
0791: art.getProperties().setProperty("empty", "");
0792: assertFalse("reference exist", r.isReferenced(art, art
0793: .getArtifactLocations()[0]));
0794: assertEquals("added a ref to proj2.dojar",
0795: "${reference.proj2.dojar}", r.addReference(art, art
0796: .getArtifactLocations()[0]));
0797: assertTrue("reference exist", r.isReferenced(art, art
0798: .getArtifactLocations()[0]));
0799: assertTrue("project now modified", pm.isModified(p));
0800: ProjectManager.getDefault().saveAllProjects();
0801: ReferenceHelper.RawReference[] refs = r.getRawReferences();
0802: assertEquals("one ref now", 1, refs.length);
0803: ReferenceHelper.RawReference ref = refs[0];
0804: assertEquals("correct foreign project name", "proj2", ref
0805: .getForeignProjectName());
0806: assertEquals("correct artifact type", "jar", ref
0807: .getArtifactType());
0808: assertEquals("correct script location",
0809: "${project.proj2}/build.xml", ref
0810: .getScriptLocationValue());
0811: assertEquals("correct target name", "dojar", ref
0812: .getTargetName());
0813: assertEquals("correct clean target name", "clean", ref
0814: .getCleanTargetName());
0815: assertEquals("correct property keys",
0816: new TreeSet<String>(Arrays.asList(new String[] {
0817: "configuration", "empty" })), ref
0818: .getProperties().keySet());
0819: assertEquals("correct property values", new TreeSet<String>(
0820: Arrays.asList(new String[] { "debug", "" })),
0821: new TreeSet<Object>(ref.getProperties().values()));
0822: }
0823:
0824: /**
0825: * Check that the {@link SubprojectProvider} implementation behaves correctly.
0826: * @throws Exception in case of unexpected failures
0827: */
0828: public void testSubprojectProviderImpl() throws Exception {
0829: AntArtifact art = sisterh.createSimpleAntArtifact("jar",
0830: "build.jar", sisterh.getStandardPropertyEvaluator(),
0831: "dojar", "clean");
0832: assertNotNull("added a ref to proj2.dojar", r.addReference(art,
0833: art.getArtifactLocations()[0]));
0834: art = sisterh.createSimpleAntArtifact("javadoc",
0835: "build.javadoc",
0836: sisterh.getStandardPropertyEvaluator(), "dojavadoc",
0837: "clean");
0838: assertNotNull("added a ref to proj2.dojavadoc", r.addReference(
0839: art, art.getArtifactLocations()[0]));
0840: art = seph.createSimpleAntArtifact("jar", "build.jar", seph
0841: .getStandardPropertyEvaluator(), "dojar", "clean");
0842: assertNotNull("added a ref to proj3.dojar", r.addReference(art,
0843: art.getArtifactLocations()[0]));
0844: SubprojectProvider sp = r.createSubprojectProvider();
0845: Set<? extends Project> subprojs = sp.getSubprojects();
0846: assertEquals("two subprojects", 2, subprojs.size());
0847: Project[] subprojsA = subprojs.toArray(new Project[2]);
0848: Project proj2, proj3;
0849: if (ProjectUtils.getInformation(subprojsA[0]).getName().equals(
0850: "proj2")) {
0851: proj2 = subprojsA[0];
0852: proj3 = subprojsA[1];
0853: } else {
0854: proj2 = subprojsA[1];
0855: proj3 = subprojsA[0];
0856: }
0857: assertEquals("proj2 was found correctly", pm
0858: .findProject(sisterprojdir), proj2);
0859: assertEquals("proj3 was found correctly", pm
0860: .findProject(sepprojdir), proj3);
0861: }
0862:
0863: /**
0864: * Check that methods to add foreign file references really work.
0865: * @throws Exception in case of unexpected failure
0866: */
0867: @SuppressWarnings("deprecation")
0868: public void testForeignFileReferences() throws Exception {
0869: // test collocated foreign project reference
0870: File f = new File(new File(FileUtil.toFile(sisterprojdir),
0871: "dist"), "proj2.jar");
0872: assertEquals("can add a ref to an artifact",
0873: "${reference.proj2.dojar}", r
0874: .createForeignFileReference(f, "jar"));
0875: assertEquals(
0876: "creating reference second time must return already existing ID",
0877: "${reference.proj2.dojar}", r
0878: .createForeignFileReference(f, "jar"));
0879: assertNotNull("ref added", r.getRawReference("proj2", "dojar"));
0880: EditableProperties privateProps = h
0881: .getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
0882: String refval = privateProps.getProperty("project.proj2");
0883: assertNull(
0884: "reference correctly stored into private.properties",
0885: refval);
0886: EditableProperties projectProps = h
0887: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
0888: refval = projectProps.getProperty("project.proj2");
0889: assertEquals(
0890: "reference correctly stored into project.properties",
0891: "../proj2", refval);
0892: refval = pev.getProperty("reference.proj2.dojar");
0893: assertNotNull("reference correctly evaluated", refval);
0894: assertEquals("reference correctly evaluated", f, h
0895: .resolveFile(refval));
0896: AntArtifact art = r
0897: .getForeignFileReferenceAsArtifact("${reference.proj2.dojar}");
0898: assertNotNull("got the reference back", art);
0899: assertEquals("correct project", sisterprojdir, art.getProject()
0900: .getProjectDirectory());
0901: assertEquals("correct target name", "dojar", art
0902: .getTargetName());
0903: assertEquals("correct type", "jar", art.getType());
0904: assertEquals("correct artifact location", URI
0905: .create("dist/proj2.jar"),
0906: art.getArtifactLocations()[0]);
0907: art = (AntArtifact) r
0908: .findArtifactAndLocation("reference.proj2.dojar")[0];
0909: assertNull("bad format", art);
0910: art = (AntArtifact) r
0911: .findArtifactAndLocation("${reference.proj2.doojar}")[0];
0912: assertNull("wrong target name", art);
0913: File f2 = new File(new File(FileUtil.toFile(sisterprojdir2),
0914: "dist"), "proj2.jar");
0915: assertEquals("reference ID must be unique",
0916: "${reference.proj2-1.dojar}", r
0917: .createForeignFileReference(f2, "jar"));
0918: assertEquals(
0919: "creating reference second time must return already existing ID",
0920: "${reference.proj2-1.dojar}", r
0921: .createForeignFileReference(f2, "jar"));
0922: r.destroyForeignFileReference("${reference.proj2-1.dojar}");
0923: assertNull("ref removed", r.getRawReference("proj2-1", "dojar"));
0924: r.destroyForeignFileReference("${reference.proj2.dojar}");
0925: assertNull("ref removed", r.getRawReference("proj2", "dojar"));
0926: assertNull("project ref property removed", pev
0927: .getProperty("reference.proj2.dojar"));
0928: assertEquals("no refs remaining", 0,
0929: r.getRawReferences().length);
0930:
0931: // test non-collocated foreign project reference
0932: FileObject nonCollocatedProjectLib = scratch.getFileObject(
0933: "separate/proj3").createFolder("d i s t").createData(
0934: "p r o j 3.jar");
0935: f = FileUtil.toFile(nonCollocatedProjectLib);
0936: art = AntArtifactQuery.findArtifactByID(pm
0937: .findProject(sepprojdir), "dojar");
0938: assertNotNull("have an artifact proj3.dojar", art);
0939: assertEquals("can add a reference to a direct artifact",
0940: "${reference.proj3.dojar}", r
0941: .createForeignFileReference(art));
0942: assertEquals(
0943: "creating reference second time must return already existing ID",
0944: "${reference.proj3.dojar}", r
0945: .createForeignFileReference(art));
0946: assertNotNull("ref added", r.getRawReference("proj3", "dojar"));
0947: refval = pev.getProperty("reference.proj3.dojar");
0948: String val = h.getProperties(
0949: AntProjectHelper.PROJECT_PROPERTIES_PATH).getProperty(
0950: "reference.proj3.dojar");
0951: assertEquals("reference was not correctly set",
0952: "${project.proj3}/d i s t/p r o j 3.jar", val);
0953: assertEquals("reference correctly evaluated", f, h
0954: .resolveFile(refval));
0955: val = h.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH)
0956: .getProperty("project.proj3");
0957: assertEquals("reference correctly evaluated", FileUtil.toFile(
0958: sepprojdir).getAbsolutePath(), val);
0959: art = (AntArtifact) r
0960: .findArtifactAndLocation("${reference.proj3.dojar}")[0];
0961: assertNotNull("got the reference back", art);
0962: assertEquals("correct project", sepprojdir, art.getProject()
0963: .getProjectDirectory());
0964: assertEquals("correct target name", "dojar", art
0965: .getTargetName());
0966: r.destroyForeignFileReference("${reference.proj3.dojar}");
0967: assertNull("ref removed", r.getRawReference("proj3", "dojar"));
0968: assertNull("project ref property removed", pev
0969: .getProperty("reference.proj3.dojar"));
0970: assertEquals("no refs remaining", 0,
0971: r.getRawReferences().length);
0972:
0973: // test foreign file reference for collocated jar
0974: FileObject collocatedLib = scratch.createFolder("j a r s")
0975: .createData("m y l i b.jar");
0976: f = FileUtil.toFile(collocatedLib);
0977: String ref = r.createForeignFileReference(f, "jar");
0978: String ref2 = r.createForeignFileReference(f, "jar");
0979: assertEquals("Duplicate reference created", ref, ref2);
0980: assertEquals(
0981: "Foreign file reference was not correctly created",
0982: "${file.reference.m_y_l_i_b.jar}", ref);
0983: refval = h.getProperties(
0984: AntProjectHelper.PROJECT_PROPERTIES_PATH).getProperty(
0985: ref.substring(2, ref.length() - 1));
0986: assertEquals(
0987: "Reference was not correctly evaluated from project.properties",
0988: "../j a r s/m y l i b.jar", refval);
0989: refval = h.getProperties(
0990: AntProjectHelper.PRIVATE_PROPERTIES_PATH).getProperty(
0991: ref.substring(2, ref.length() - 1));
0992: assertNull(
0993: "Reference was not correctly evaluated from private.properties",
0994: refval);
0995: collocatedLib = scratch.createFolder("jars2").createData(
0996: "m y l i b.jar");
0997: f = FileUtil.toFile(collocatedLib);
0998: ref = r.createForeignFileReference(f, "jar");
0999: ref2 = r.createForeignFileReference(f, "jar");
1000: assertEquals("Duplicate reference created", ref, ref2);
1001: assertEquals(
1002: "Foreign file reference was not correctly created",
1003: "${file.reference.m_y_l_i_b.jar-1}", ref);
1004: refval = h.getProperties(
1005: AntProjectHelper.PROJECT_PROPERTIES_PATH).getProperty(
1006: ref.substring(2, ref.length() - 1));
1007: assertEquals(
1008: "Reference was not correctly evaluated form project.properties",
1009: "../jars2/m y l i b.jar", refval);
1010: refval = h.getProperties(
1011: AntProjectHelper.PRIVATE_PROPERTIES_PATH).getProperty(
1012: ref.substring(2, ref.length() - 1));
1013: assertNull(
1014: "Reference was not correctly evaluated from private.properties",
1015: refval);
1016: collocatedLib = scratch.createFolder("jars3").createData(
1017: "m y l i b.jar");
1018: f = FileUtil.toFile(collocatedLib);
1019: ref = r.createForeignFileReference(f, "jar");
1020: ref2 = r.createForeignFileReference(f, "jar");
1021: assertEquals("Duplicate reference created", ref, ref2);
1022: assertEquals(
1023: "Foreign file reference was not correctly created",
1024: "${file.reference.m_y_l_i_b.jar-2}", ref);
1025: refval = h.getProperties(
1026: AntProjectHelper.PROJECT_PROPERTIES_PATH).getProperty(
1027: ref.substring(2, ref.length() - 1));
1028: assertEquals(
1029: "Reference was not correctly evaluated from project.properties",
1030: "../jars3/m y l i b.jar", refval);
1031: refval = h.getProperties(
1032: AntProjectHelper.PRIVATE_PROPERTIES_PATH).getProperty(
1033: ref.substring(2, ref.length() - 1));
1034: assertNull(
1035: "Reference was not correctly evaluated from private.properties",
1036: refval);
1037:
1038: assertTrue("Reference was not removed", r.destroyReference(ref));
1039: assertFalse("There should not be any reference", r
1040: .destroyReference(ref));
1041: refval = pev.evaluate(ref);
1042: assertEquals("Reference was not removed", ref, refval);
1043:
1044: // test foreign file reference for non-collocated jar
1045: FileObject nonCollocatedLib = scratch.getFileObject("separate")
1046: .createFolder("jars").createData("mylib2.jar");
1047: f = FileUtil.toFile(nonCollocatedLib);
1048: ref = r.createForeignFileReference(f, "jar");
1049: ref2 = r.createForeignFileReference(f, "jar");
1050: assertEquals("Duplicate reference created", ref, ref2);
1051: assertEquals(
1052: "Foreign file reference was not correctly created",
1053: "${file.reference.mylib2.jar}", ref);
1054: refval = h.getProperties(
1055: AntProjectHelper.PROJECT_PROPERTIES_PATH).getProperty(
1056: ref.substring(2, ref.length() - 1));
1057: assertNull(
1058: "Foreign file reference is stored into project.properties",
1059: refval);
1060: refval = h.getProperties(
1061: AntProjectHelper.PRIVATE_PROPERTIES_PATH).getProperty(
1062: ref.substring(2, ref.length() - 1));
1063: assertEquals("Reference was not correctly evaluated", f
1064: .getAbsolutePath(), refval);
1065: assertEquals("Reference was not correctly evaluated", f, h
1066: .resolveFile(refval));
1067: nonCollocatedLib = scratch.getFileObject("separate")
1068: .createFolder("jars2").createData("mylib2.jar");
1069: f = FileUtil.toFile(nonCollocatedLib);
1070: ref = r.createForeignFileReference(f, "jar");
1071: ref2 = r.createForeignFileReference(f, "jar");
1072: assertEquals("Duplicate reference created", ref, ref2);
1073: assertEquals(
1074: "Foreign file reference was not correctly created",
1075: "${file.reference.mylib2.jar-1}", ref);
1076: refval = h.getProperties(
1077: AntProjectHelper.PROJECT_PROPERTIES_PATH).getProperty(
1078: ref.substring(2, ref.length() - 1));
1079: assertNull(
1080: "Foreign file reference is stored into project.properties",
1081: refval);
1082: refval = h.getProperties(
1083: AntProjectHelper.PRIVATE_PROPERTIES_PATH).getProperty(
1084: ref.substring(2, ref.length() - 1));
1085: assertEquals("Reference was not correctly evaluated", f
1086: .getAbsolutePath(), refval);
1087: nonCollocatedLib = scratch.getFileObject("separate")
1088: .createFolder("jars3").createData("mylib2.jar");
1089: f = FileUtil.toFile(nonCollocatedLib);
1090: ref = r.createForeignFileReference(f, "jar");
1091: ref2 = r.createForeignFileReference(f, "jar");
1092: assertEquals("Duplicate reference created", ref, ref2);
1093: assertEquals(
1094: "Foreign file reference was not correctly created",
1095: "${file.reference.mylib2.jar-2}", ref);
1096: refval = h.getProperties(
1097: AntProjectHelper.PROJECT_PROPERTIES_PATH).getProperty(
1098: ref.substring(2, ref.length() - 1));
1099: assertNull(
1100: "Foreign file reference is stored into project.properties",
1101: refval);
1102: refval = h.getProperties(
1103: AntProjectHelper.PRIVATE_PROPERTIES_PATH).getProperty(
1104: ref.substring(2, ref.length() - 1));
1105: assertEquals("Reference was not correctly evaluated", f
1106: .getAbsolutePath(), refval);
1107: r.destroyForeignFileReference(ref);
1108: refval = pev.evaluate(ref);
1109: assertEquals("Reference was not removed", ref, refval);
1110:
1111: }
1112:
1113: public void testToAntArtifact() throws Exception {
1114: ReferenceHelper.RawReference ref = new ReferenceHelper.RawReference(
1115: "proj2", "irrelevant", new URI("also-irrelevant"),
1116: "dojar", "totally-irrelevant", "dojar");
1117: AntArtifact art = ref.toAntArtifact(r);
1118: assertNull("${project.proj2} not set, will not be found", art);
1119: EditableProperties props = h
1120: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
1121: props.setProperty("project.proj2", "../proj2");
1122: h
1123: .putProperties(
1124: AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
1125: art = ref.toAntArtifact(r);
1126: assertNotNull("now artifact will be found", art);
1127: assertEquals("correct directory", sisterprojdir, art
1128: .getProject().getProjectDirectory());
1129: assertEquals("correct artifact location", URI
1130: .create("dist/proj2.jar"),
1131: art.getArtifactLocations()[0]);
1132: assertEquals("correct script location", new File(FileUtil
1133: .toFile(sisterprojdir), "build.xml"), art
1134: .getScriptLocation());
1135: assertEquals("correct target name", "dojar", art
1136: .getTargetName());
1137: assertEquals("correct clean target name", "clean", art
1138: .getCleanTargetName());
1139: ref = new ReferenceHelper.RawReference("proj2", "irrelevant",
1140: new URI("also-irrelevant"), "doojar",
1141: "totally-irrelevant", "doojar");
1142: art = ref.toAntArtifact(r);
1143: assertNull("wrong target name, will not be found", art);
1144: }
1145:
1146: public void testAddRemoveExtraBaseDirectory() throws Exception {
1147: // test foreign file reference for non-collocated jar under extra base folder
1148: FileObject nonCollocatedLib = scratch.getFileObject("separate")
1149: .createFolder("jars").createData("mylib.jar");
1150: File f = FileUtil.toFile(nonCollocatedLib);
1151: EditableProperties props = h
1152: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
1153: props.setProperty("externalSourceRoot", "../separate");
1154: h
1155: .putProperties(
1156: AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
1157: r.addExtraBaseDirectory("externalSourceRoot");
1158: String ref = r.createForeignFileReference(f, "jar");
1159: assertEquals("foreign file reference created",
1160: "${file.reference.mylib.jar}", ref);
1161: String refval = h.getProperties(
1162: AntProjectHelper.PROJECT_PROPERTIES_PATH).getProperty(
1163: ref.substring(2, ref.length() - 1));
1164: assertEquals("reference is using extra base folder",
1165: "${externalSourceRoot}/jars/mylib.jar", refval);
1166: assertEquals("reference is correctly evaluated", f, h
1167: .resolveFile(h.getStandardPropertyEvaluator().evaluate(
1168: refval)));
1169: // test removal of extra base folder
1170: r.removeExtraBaseDirectory("externalSourceRoot");
1171: refval = h.getProperties(
1172: AntProjectHelper.PROJECT_PROPERTIES_PATH).getProperty(
1173: ref.substring(2, ref.length() - 1));
1174: assertEquals("reference does not contain extra base folder",
1175: "../separate/jars/mylib.jar", refval);
1176: assertEquals("reference is correctly evaluated", f, h
1177: .resolveFile(refval));
1178:
1179: // the same test as above but with extra base folder defined in PRIVATE props
1180: nonCollocatedLib = scratch.createFolder("separate2")
1181: .createFolder("jars").createData("mylib2.jar");
1182: f = FileUtil.toFile(nonCollocatedLib);
1183: props = h
1184: .getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
1185: String absolutePath = FileUtil.toFile(
1186: scratch.getFileObject("separate2")).getAbsolutePath();
1187: props.setProperty("externalSourceRootAbsolute", absolutePath);
1188: h
1189: .putProperties(
1190: AntProjectHelper.PRIVATE_PROPERTIES_PATH, props);
1191: r.addExtraBaseDirectory("externalSourceRootAbsolute");
1192: ref = r.createForeignFileReference(f, "jar");
1193: assertEquals("foreign file reference created",
1194: "${file.reference.mylib2.jar}", ref);
1195: refval = h.getProperties(
1196: AntProjectHelper.PROJECT_PROPERTIES_PATH).getProperty(
1197: ref.substring(2, ref.length() - 1));
1198: assertEquals("reference is using extra base folder",
1199: "${externalSourceRootAbsolute}/jars/mylib2.jar", refval);
1200: assertEquals("reference is correctly evaluated", f, h
1201: .resolveFile(h.getStandardPropertyEvaluator().evaluate(
1202: refval)));
1203: r.removeExtraBaseDirectory("externalSourceRootAbsolute");
1204: refval = h.getProperties(
1205: AntProjectHelper.PROJECT_PROPERTIES_PATH).getProperty(
1206: ref.substring(2, ref.length() - 1));
1207: assertNull(
1208: "reference was removed from PROJECT_PROPERTIES_PATH",
1209: refval);
1210: refval = h.getProperties(
1211: AntProjectHelper.PRIVATE_PROPERTIES_PATH).getProperty(
1212: ref.substring(2, ref.length() - 1));
1213: assertNotNull("reference was moved to PRIVATE_PROPERTIES_PATH",
1214: refval);
1215: assertEquals("reference does not contain extra base folder",
1216: absolutePath + "/jars/mylib2.jar", refval);
1217: assertEquals("reference is correctly evaluated", f, h
1218: .resolveFile(h.getStandardPropertyEvaluator().evaluate(
1219: refval)));
1220: }
1221:
1222: /**
1223: * Check that adding and removing artifact locations dynamically doesn't break anything.
1224: * Cf. #55413 and #55423.
1225: */
1226: public void testDeletionOfArtifactLocations() throws Exception {
1227: final URI[] locations = { URI.create("dist/output1.jar"),
1228: URI.create("dist/output2.jar"),
1229: URI.create("dist/output3.jar"), };
1230: final boolean[] includeLocations = { true, false, true, };
1231: class MultiAntArtifact extends AntArtifact {
1232: public String getType() {
1233: return "jar";
1234: }
1235:
1236: public String getTargetName() {
1237: return "build";
1238: }
1239:
1240: public String getCleanTargetName() {
1241: return "clean";
1242: }
1243:
1244: public File getScriptLocation() {
1245: return sisterh.resolveFile("build.xml");
1246: }
1247:
1248: public URI[] getArtifactLocations() {
1249: List<URI> locs = new ArrayList<URI>();
1250: for (int i = 0; i < locations.length; i++) {
1251: if (includeLocations[i]) {
1252: locs.add(locations[i]);
1253: }
1254: }
1255: return locs.toArray(new URI[locs.size()]);
1256: }
1257: }
1258: AntArtifact art = new MultiAntArtifact();
1259: assertFalse("project not initially modified", pm.isModified(p));
1260: assertFalse("no refs yet", r.isReferenced(art, locations[0]));
1261: assertEquals("added a ref to output1.jar",
1262: "${reference.proj2.build}", r.addReference(art,
1263: locations[0]));
1264: assertEquals("added a ref to output3.jar",
1265: "${reference.proj2.build.1}", r.addReference(art,
1266: locations[2]));
1267: try {
1268: r.addReference(art, locations[1]);
1269: fail("Should not be permitted to add ref to output2.jar yet");
1270: } catch (IllegalArgumentException e) {
1271: // Expected.
1272: }
1273: assertTrue("output1.jar ref'd", r.isReferenced(art,
1274: locations[0]));
1275: assertTrue("output3.jar ref'd", r.isReferenced(art,
1276: locations[2]));
1277: try {
1278: r.isReferenced(art, locations[1]);
1279: fail("Should not be permitted to check ref to output2.jar yet");
1280: } catch (IllegalArgumentException e) {
1281: // Expected.
1282: }
1283: // Make sure proj2 actually reports our special provider:
1284: Project sisterproj = ProjectManager.getDefault().findProject(
1285: sisterprojdir);
1286: sisterproj.getLookup().lookup(
1287: AntBasedTestUtil.AntArtifactProviderMutable.class)
1288: .setBuildArtifacts(new AntArtifact[] { art });
1289: // Now check findArtifactAndLocation usage.
1290: assertEquals("output1.jar found", Arrays.asList(new Object[] {
1291: art, locations[0] }), Arrays.asList(r
1292: .findArtifactAndLocation("${reference.proj2.build}")));
1293: assertEquals("output3.jar found", Arrays.asList(new Object[] {
1294: art, locations[2] }), Arrays.asList(r
1295: .findArtifactAndLocation("${reference.proj2.build.1}")));
1296: // Now add output2.jar to list and see that lookups work somehow.
1297: includeLocations[1] = true;
1298: assertEquals(
1299: "output1.jar still there",
1300: Arrays.asList(new Object[] { art, locations[0] }),
1301: Arrays
1302: .asList(r
1303: .findArtifactAndLocation("${reference.proj2.build}")));
1304: assertEquals(
1305: "output2.jar now magically referenced instead of output3.jar (but oh well)",
1306: Arrays.asList(new Object[] { art, locations[1] }),
1307: Arrays
1308: .asList(r
1309: .findArtifactAndLocation("${reference.proj2.build.1}")));
1310: assertEquals(
1311: "output3.jar now magically referenced (even though we have no such property ourselves)",
1312: Arrays.asList(new Object[] { art, locations[2] }),
1313: Arrays
1314: .asList(r
1315: .findArtifactAndLocation("${reference.proj2.build.2}")));
1316: // Now *remove* some items and see what happens!
1317: includeLocations[0] = false;
1318: includeLocations[1] = false;
1319: assertEquals(
1320: "output3.jar now only referent",
1321: Arrays.asList(new Object[] { art, locations[2] }),
1322: Arrays
1323: .asList(r
1324: .findArtifactAndLocation("${reference.proj2.build}")));
1325: assertEquals("second item no longer exists", Arrays
1326: .asList(new Object[] { null, null }), Arrays.asList(r
1327: .findArtifactAndLocation("${reference.proj2.build.1}")));
1328: assertEquals("third item no longer exists", Arrays
1329: .asList(new Object[] { null, null }), Arrays.asList(r
1330: .findArtifactAndLocation("${reference.proj2.build.2}")));
1331: assertTrue("output3.jar ref'd", r.isReferenced(art,
1332: locations[2]));
1333: try {
1334: r.isReferenced(art, locations[0]);
1335: fail("Should not be permitted to check ref to first item any more, oops");
1336: } catch (IllegalArgumentException e) {
1337: // Expected.
1338: }
1339: try {
1340: r.isReferenced(art, locations[1]);
1341: fail("Should not be permitted to check ref to second item any more");
1342: } catch (IllegalArgumentException e) {
1343: // Expected.
1344: }
1345: // Now destroy the references and make sure there are no issues.
1346: assertTrue(
1347: "Can really get rid of output3.jar (even though it used to be output1.jar)",
1348: r.destroyReference("${reference.proj2.build}"));
1349: assertTrue(
1350: "Can also get rid of what used to be output3.jar somehow - just the property at least",
1351: r.destroyReference("${reference.proj2.build.1}"));
1352: assertFalse("output3.jar no longer ref'd", r.isReferenced(art,
1353: locations[2]));
1354: assertEquals("No raw references left", Collections.EMPTY_LIST,
1355: Arrays.asList(r.getRawReferences()));
1356: assertEquals(
1357: "No shared properties left",
1358: Collections.EMPTY_MAP,
1359: h
1360: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH));
1361: assertEquals(
1362: "No private properties left",
1363: Collections.EMPTY_MAP,
1364: h
1365: .getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH));
1366: }
1367:
1368: private void writeProperties(FileObject prop, String[] keys,
1369: String[] values) throws Exception {
1370: EditableProperties p = new EditableProperties();
1371:
1372: for (int cntr = 0; cntr < keys.length; cntr++) {
1373: p.setProperty(keys[cntr], values[cntr]);
1374: }
1375:
1376: FileLock lock = prop.lock();
1377: try {
1378: OutputStream os = prop.getOutputStream(lock);
1379: try {
1380: p.store(os);
1381: } finally {
1382: os.close();
1383: }
1384: } finally {
1385: lock.releaseLock();
1386: }
1387: }
1388:
1389: public void testFixReferences() throws Exception {
1390: FileObject originalProject = scratch.createFolder("orig-proj");
1391: FileObject originalSrcDir = originalProject.createFolder("src");
1392:
1393: FileObject testProject = scratch.createFolder("test-proj");
1394: FileObject nbprojectDir = testProject.createFolder("nbproject");
1395:
1396: TestUtil.createFileFromContent(ReferenceHelperTest.class
1397: .getResource("data/project.xml"), testProject,
1398: "nbproject/project.xml");
1399:
1400: FileObject publicProperties = nbprojectDir
1401: .createData("project.properties");
1402: FileObject privateDir = nbprojectDir.createFolder("private");
1403: FileObject privateProperties = privateDir
1404: .createData("private.properties");
1405: FileObject srcDir = testProject.createFolder("src");
1406:
1407: writeProperties(publicProperties,
1408: new String[] { "file.reference.x", },
1409: new String[] { "src", });
1410:
1411: writeProperties(privateProperties,
1412: new String[] { "file.reference.x", },
1413: new String[] { FileUtil.toFile(originalSrcDir)
1414: .getAbsolutePath(), });
1415:
1416: Project nue = pm.findProject(testProject);
1417: assertNotNull("found project in " + testProject, nue);
1418: AntProjectHelper h = nue.getLookup().lookup(
1419: AntProjectHelper.class);
1420: assertNotNull("found helper for " + nue, h);
1421: ReferenceHelper r = nue.getLookup().lookup(
1422: ReferenceHelper.class);
1423: assertNotNull("found ref helper for " + p, r);
1424:
1425: r.fixReferences(FileUtil.toFile(originalProject));
1426:
1427: pm.saveProject(nue);
1428:
1429: String resolvedProperty = h.getStandardPropertyEvaluator()
1430: .getProperty("file.reference.x");
1431:
1432: assertNotNull("the property can be resolved", resolvedProperty);
1433:
1434: File resolvedFile = PropertyUtils.resolveFile(FileUtil
1435: .toFile(testProject), resolvedProperty);
1436:
1437: assertNotNull("the file can be resolved", resolvedFile);
1438:
1439: assertEquals("referencing correct file", FileUtil
1440: .toFile(srcDir).getAbsolutePath(), resolvedFile
1441: .getAbsolutePath());
1442: }
1443:
1444: public void testSlash1ToSlash2Upgrade() throws Exception { // #91760
1445: class AnArtifact extends AntArtifact {
1446: URI u;
1447: Properties p;
1448:
1449: public AnArtifact(URI u, Properties p) {
1450: this .u = u;
1451: this .p = p;
1452: }
1453:
1454: public String getType() {
1455: return "jar";
1456: }
1457:
1458: public File getScriptLocation() {
1459: return sisterh.resolveFile(getTargetName() + ".xml");
1460: }
1461:
1462: public String getTargetName() {
1463: return u.toString().replaceAll("\\.jar$", "");
1464: }
1465:
1466: public String getCleanTargetName() {
1467: return "clean";
1468: }
1469:
1470: @Override
1471: public URI[] getArtifactLocations() {
1472: return new URI[] { u };
1473: }
1474:
1475: @Override
1476: public Properties getProperties() {
1477: return p;
1478: }
1479:
1480: }
1481: URI xJar = new URI(null, null, "x.jar", null);
1482: r.addReference(new AnArtifact(xJar, new Properties()), xJar);
1483: assertReferenceXmlFragment(ReferenceHelper.REFS_NS, "x.xml");
1484: Properties p = new Properties();
1485: p.setProperty("k", "v");
1486: URI yJar = new URI(null, null, "y.jar", null);
1487: r.addReference(new AnArtifact(yJar, p), yJar);
1488: assertReferenceXmlFragment(ReferenceHelper.REFS_NS2,
1489: "${project.proj2}/x.xml", "${project.proj2}/y.xml");
1490: URI zJar = new URI(null, null, "z.jar", null);
1491: r.addReference(new AnArtifact(zJar, new Properties()), zJar);
1492: assertReferenceXmlFragment(ReferenceHelper.REFS_NS2,
1493: "${project.proj2}/x.xml", "${project.proj2}/y.xml",
1494: "${project.proj2}/z.xml");
1495: }
1496:
1497: private void assertReferenceXmlFragment(String namespace,
1498: String... scriptLocations) {
1499: Element refs = p.getLookup().lookup(
1500: AuxiliaryConfiguration.class).getConfigurationFragment(
1501: ReferenceHelper.REFS_NAME, namespace, true);
1502: assertNotNull(refs);
1503: List<String> actualScriptLocations = new ArrayList<String>();
1504: for (Element ref : Util.findSubElements(refs)) {
1505: Element script = Util.findElement(ref, "script", namespace);
1506: actualScriptLocations.add(Util.findText(script));
1507: }
1508: assertEquals(Arrays.asList(scriptLocations),
1509: actualScriptLocations);
1510: }
1511:
1512: public void testProjectLibraryReferences() throws Exception {
1513: ProjectLibraryProvider.FIRE_CHANGES_SYNCH = true;
1514: assertProjectLibraryManagers(null);
1515: File fooJar = new File(getWorkDir(), "foo.jar");
1516: File f = new File(getWorkDir(), "libs.properties");
1517: URL loc = f.toURI().toURL();
1518: LibraryManager mgr = LibraryManager.forLocation(loc);
1519: assertEquals(loc, mgr.getLocation());
1520: Library fooLib = mgr.createLibrary("j2se", "foo", Collections
1521: .singletonMap("classpath", Arrays.asList(new URL("jar:"
1522: + fooJar.toURI() + "!/"))));
1523: assertEquals(mgr, fooLib.getManager());
1524: try {
1525: r.createLibraryReference(fooLib, "classpath");
1526: fail("cannot reference library which is not reachable from project");
1527: } catch (IllegalArgumentException ex) {
1528: // as expected
1529: }
1530: h.setLibrariesLocation(f.getAbsolutePath());
1531: String fooref = r.createLibraryReference(fooLib, "classpath");
1532: assertEquals("${libs.foo.classpath}", fooref);
1533: assertEquals(fooJar.getAbsolutePath(), pev.evaluate(fooref)
1534: .replace('/', File.separatorChar));
1535: assertProjectLibraryManagers(loc);
1536: assertEquals("foo", r.findLibrary("foo").getName());
1537: assertEquals("foo", r.findLibrary("${libs.foo.classpath}")
1538: .getName());
1539: assertNull(r.findLibrary("nonexistent"));
1540: assertNull(r.findLibrary("${libs.nonexistent.classpath}"));
1541: assertNull(r.findLibrary("${some.other.foo.stuff}"));
1542: File barDir = new File(getWorkDir(), "bar");
1543: barDir.mkdirs();
1544: String barref = r.createLibraryReference(mgr.createLibrary(
1545: "j2se", "bar", Collections.singletonMap("classpath",
1546: Arrays.asList(barDir.toURI().toURL()))),
1547: "classpath");
1548: assertEquals("${libs.bar.classpath}", barref);
1549: assertEquals(barDir.getAbsolutePath(), pev.evaluate(barref)
1550: .replace('/', File.separatorChar));
1551: EditableProperties props = h
1552: .getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
1553: props.put("javac.classpath", "stuff:" + fooref
1554: + ":which-is-not-bar");
1555: h
1556: .putProperties(
1557: AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
1558: assertProjectLibraryManagers(loc);
1559: assertEquals("foo", r.findLibrary("foo").getName());
1560: assertEquals("foo", r.findLibrary("${libs.foo.classpath}")
1561: .getName());
1562: assertEquals("bar", r.findLibrary("bar").getName());
1563: assertEquals("bar", r.findLibrary("${libs.bar.classpath}")
1564: .getName());
1565: mgr.createLibrary("j2se", "empty", Collections
1566: .<String, List<URL>> emptyMap());
1567: assertEquals("stuff:" + fooJar + ":which-is-not-bar", pev
1568: .evaluate("${javac.classpath}").replace('/',
1569: File.separatorChar));
1570: props.put("javac.classpath", "nolibshere");
1571: h
1572: .putProperties(
1573: AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
1574: assertEquals("nolibshere", pev.getProperty("javac.classpath"));
1575: assertEquals(fooJar.getAbsolutePath(), pev.getProperty(
1576: "libs.foo.classpath").replace('/', File.separatorChar));
1577: assertProjectLibraryManagers(loc);
1578: assertEquals("foo", r.findLibrary("foo").getName());
1579: assertEquals("foo", r.findLibrary("${libs.foo.classpath}")
1580: .getName());
1581: assertEquals("bar", r.findLibrary("bar").getName());
1582: assertEquals("bar", r.findLibrary("${libs.bar.classpath}")
1583: .getName());
1584: }
1585:
1586: private void assertProjectLibraryManagers(URL expectedUrl) {
1587: LibraryManager mgr = r.getProjectLibraryManager();
1588: if (mgr == null) {
1589: assertNull(expectedUrl);
1590: } else {
1591: assertEquals(expectedUrl, mgr.getLocation());
1592: }
1593: }
1594:
1595: }
|