1 19 20 package org.netbeans.modules.apisupport.project; 21 22 import java.io.File ; 23 import java.util.Collections ; 24 import org.netbeans.api.project.ProjectManager; 25 import org.netbeans.junit.NbTestCase; 26 import org.netbeans.modules.apisupport.project.suite.SuiteProject; 27 import org.netbeans.modules.apisupport.project.suite.SuiteProjectGenerator; 28 import org.netbeans.modules.apisupport.project.suite.SuiteProjectTest; 29 import org.netbeans.modules.apisupport.project.universe.ModuleEntry; 30 import org.netbeans.modules.apisupport.project.universe.NbPlatform; 31 import org.netbeans.spi.project.support.ant.EditableProperties; 32 import org.netbeans.spi.project.support.ant.PropertyUtils; 33 import org.openide.filesystems.FileObject; 34 import org.openide.filesystems.FileUtil; 35 import org.openide.util.SharedClassObject; 36 37 42 public final class BrokenPlatformReferenceTest extends NbTestCase { 43 44 public BrokenPlatformReferenceTest(String name) { 45 super(name); 46 } 47 48 49 private File install; 50 51 private File install2; 52 53 private File user; 54 55 protected void setUp() throws Exception { 56 super.setUp(); 57 clearWorkDir(); 58 NbPlatform.reset(); 59 user = new File (getWorkDir(), "user"); 60 user.mkdirs(); 61 System.setProperty("netbeans.user", user.getAbsolutePath()); 62 install = new File (getWorkDir(), "install"); 63 TestBase.makePlatform(install); 64 InstalledFileLocatorImpl.registerDestDir(install); 66 ((Install) SharedClassObject.findObject(Install.class, true)).restored(); 67 assertEquals("set up run correctly", install.getAbsolutePath(), PropertyUtils.getGlobalProperties().getProperty("nbplatform.default.netbeans.dest.dir")); 68 install2 = new File (getWorkDir(), "install2"); 69 TestBase.makePlatform(install2); 70 NbPlatform.addPlatform("install2", install2, "install2"); 71 } 72 73 74 public void testEverythingNormal() throws Exception { 75 File d = new File (getWorkDir(), "standalone"); 77 NbModuleProjectGenerator.createStandAloneModule(d, "x", "X", null, null, NbPlatform.PLATFORM_ID_DEFAULT); 78 NbModuleProject p = (NbModuleProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(d)); 79 NbPlatform pl = p.getPlatform(false); 80 assertNotNull(pl); 81 assertEquals(install, pl.getDestDir()); 82 assertEquals(pl, p.getPlatform(true)); 83 d = new File (getWorkDir(), "standalone2"); 85 NbModuleProjectGenerator.createStandAloneModule(d, "x", "X", null, null, "install2"); 86 p = (NbModuleProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(d)); 87 pl = p.getPlatform(false); 88 assertNotNull(pl); 89 assertEquals(install2, pl.getDestDir()); 90 File sd = new File (getWorkDir(), "suite"); 92 SuiteProjectGenerator.createSuiteProject(sd, NbPlatform.PLATFORM_ID_DEFAULT); 93 d = new File (getWorkDir(), "suitecomp"); 94 NbModuleProjectGenerator.createSuiteComponentModule(d, "x", "X", null, null, sd); 95 SuiteProject s = (SuiteProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(sd)); 96 pl = s.getPlatform(false); 97 assertNotNull(pl); 98 assertEquals(install, pl.getDestDir()); 99 assertEquals(pl, s.getPlatform(true)); 100 p = (NbModuleProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(d)); 101 assertEquals(pl, p.getPlatform(false)); 102 sd = new File (getWorkDir(), "suite2"); 104 SuiteProjectGenerator.createSuiteProject(sd, "install2"); 105 d = new File (getWorkDir(), "suitecomp2"); 106 NbModuleProjectGenerator.createSuiteComponentModule(d, "x", "X", null, null, sd); 107 s = (SuiteProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(sd)); 108 pl = s.getPlatform(false); 109 assertNotNull(pl); 110 assertEquals(install2, pl.getDestDir()); 111 p = (NbModuleProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(d)); 112 assertEquals(pl, p.getPlatform(false)); 113 } 114 115 116 public void testMissingPlatformPrivatePropertiesDefaultPlatform() throws Exception { 117 File d = new File (getWorkDir(), "standalone"); 119 NbModuleProjectGenerator.createStandAloneModule(d, "x", "X", null, null, NbPlatform.PLATFORM_ID_DEFAULT); 120 NbModuleProject p = (NbModuleProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(d)); 121 p.open(); 122 assertEquals(Collections.singletonMap("user.properties.file", new File (user, "build.properties").getAbsolutePath()), 123 Util.loadProperties(p.getProjectDirectory().getFileObject("nbproject/private/platform-private.properties"))); 124 File sd = new File (getWorkDir(), "suite"); 126 SuiteProjectGenerator.createSuiteProject(sd, NbPlatform.PLATFORM_ID_DEFAULT); 127 SuiteProject s = (SuiteProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(sd)); 128 SuiteProjectTest.openSuite(s); 129 assertEquals(Collections.singletonMap("user.properties.file", new File (user, "build.properties").getAbsolutePath()), 130 Util.loadProperties(s.getProjectDirectory().getFileObject("nbproject/private/platform-private.properties"))); 131 } 132 133 134 public void testIncorrectPlatformPrivatePropertiesDefaultPlatform() throws Exception { 135 File d = new File (getWorkDir(), "standalone"); 137 NbModuleProjectGenerator.createStandAloneModule(d, "x", "X", null, null, NbPlatform.PLATFORM_ID_DEFAULT); 138 FileObject props = FileUtil.createData(FileUtil.toFileObject(d), "nbproject/private/platform-private.properties"); 139 Util.storeProperties(props, new EditableProperties(Collections.singletonMap("user.properties.file", "bogus"))); 140 NbModuleProject p = (NbModuleProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(d)); 141 NbPlatform pl = p.getPlatform(true); assertNotNull(pl); 143 assertEquals(install, pl.getDestDir()); 144 p.open(); 145 assertEquals(Collections.singletonMap("user.properties.file", new File (user, "build.properties").getAbsolutePath()), 146 Util.loadProperties(props)); 147 assertEquals(pl, p.getPlatform(true)); 148 assertEquals(pl, p.getPlatform(false)); File sd = new File (getWorkDir(), "suite"); 151 SuiteProjectGenerator.createSuiteProject(sd, NbPlatform.PLATFORM_ID_DEFAULT); 152 props = FileUtil.createData(FileUtil.toFileObject(sd), "nbproject/private/platform-private.properties"); 153 Util.storeProperties(props, new EditableProperties(Collections.singletonMap("user.properties.file", "bogus"))); 154 d = new File (getWorkDir(), "suitecomp"); 155 NbModuleProjectGenerator.createSuiteComponentModule(d, "x", "X", null, null, sd); 156 SuiteProject s = (SuiteProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(sd)); 157 p = (NbModuleProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(d)); 158 pl = s.getPlatform(true); 159 assertNotNull(pl); 160 assertEquals(install, pl.getDestDir()); 161 assertEquals(pl, p.getPlatform(true)); 162 SuiteProjectTest.openSuite(s); 163 p.open(); assertEquals(Collections.singletonMap("user.properties.file", new File (user, "build.properties").getAbsolutePath()), 165 Util.loadProperties(props)); 166 assertEquals(pl, s.getPlatform(true)); 167 assertEquals(pl, s.getPlatform(false)); 168 assertEquals(pl, p.getPlatform(true)); 169 assertEquals(pl, p.getPlatform(false)); 170 } 171 172 public void testUsableModuleListForBrokenPlatform() throws Exception { 173 File sd = new File (getWorkDir(), "suite"); 174 SuiteProjectGenerator.createSuiteProject(sd, NbPlatform.PLATFORM_ID_DEFAULT); 175 File d = new File (getWorkDir(), "suitecomp"); 176 NbModuleProjectGenerator.createSuiteComponentModule(d, "x", "X", null, null, sd); 177 TestBase.delete(sd); 178 NbModuleProject p = (NbModuleProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(d)); 179 ModuleEntry e = p.getModuleList().getEntry("core"); 180 assertNotNull("#67148: can find core.jar from default platform", e); 181 assertEquals("correct JAR path", new File (new File (new File (install, "platform"), "core"), "core.jar"), e.getJarLocation()); 182 p.open(); } 184 185 191 } 192 | Popular Tags |