Project { public ProjectConfig getConfig() throws ServerException, ValueStorageException, ProjectTypeConstraintException, InvalidValueException { final ProjectJson projectJson = ProjectJson.load(this); ProjectTypes types = new ProjectTypes(projectJson.getType(), projectJson.getMixinTypes()); types.addTransient(); final Map<String, AttributeValue> attributes = new HashMap<>(); for (ProjectType t : types.all.values()) { for (Attribute attr : t.getAttributes()) { if (attr.isVariable()) { Variable var = (Variable)attr; final ValueProviderFactory factory = var.getValueProviderFactory(); List<String> val; if (factory != null) { val = factory.newInstance(baseFolder).getValues(var.getName()); if (val == null) throw new ProjectTypeConstraintException( "Value Provider must not produce NULL value of variable " + var.getId()); } else { val = projectJson.getAttributes().get(attr.getName()); } if (val == null || val.isEmpty()) { if (var.isRequired()) throw new ProjectTypeConstraintException( "No Value nor ValueProvider defined for required variable " + var.getId()); } else { attributes.put(var.getName(), new AttributeValue(val)); } } else { attributes.put(attr.getName(), attr.getValue()); } } } Builders builders = (projectJson.getBuilders() == null) ? new Builders(types.primary.getDefaultBuilder()) : projectJson.getBuilders(); Runners runners = (projectJson.getRunners() == null) ? new Runners(types.primary.getDefaultRunner()) : projectJson.getRunners(); return new ProjectConfig(projectJson.getDescription(), types.primary.getId(), attributes, runners, builders, types.mixinIds()); } Project(FolderEntry baseFolder, ProjectManager manager); String getWorkspace(); String getName(); String getPath(); FolderEntry getBaseFolder(); long getCreationDate(); long getModificationDate(); String getContentRoot(); ProjectMisc getMisc(); void saveMisc(ProjectMisc misc); static Path getAbsoluteModulePath(String modulePath, Project parentProject); ProjectConfig getConfig(); final void updateConfig(ProjectConfig update); String getVisibility(); void setVisibility(String projectVisibility); List<AccessControlEntry> getPermissions(); void setPermissions(List<AccessControlEntry> acl); VirtualFileEntry getItem(String path); Modules getModules();  }
@Test public void testGetProjectDescriptor() throws Exception { Project myProject = pm.getProject("my_ws", "my_project"); Map<String, List<String>> attributes = new HashMap<>(3); attributes.put("my_property_1", Arrays.asList("value_1", "value_2")); attributes.put("my_property_2", Arrays.asList("value_3", "value_4")); ProjectJson json = new ProjectJson(); json.withType("my_project_type").withAttributes(attributes).save(myProject); ProjectConfig myConfig = myProject.getConfig(); Assert.assertEquals(myConfig.getTypeId(), "my_project_type"); Assert.assertEquals(pm.getProjectTypeRegistry().getProjectType("my_project_type").getAttributes().size(), 3); Assert.assertEquals(myConfig.getAttributes().size(), 3); AttributeValue attributeVal; Assert.assertNotNull(myConfig.getAttributes().get("calculated_attribute")); attributeVal = myConfig.getAttributes().get("calculated_attribute"); Assert.assertEquals(attributeVal.getList(), Arrays.asList("hello")); Assert.assertNotNull(myConfig.getAttributes().get("my_property_1")); attributeVal = myConfig.getAttributes().get("my_property_1"); Assert.assertEquals(attributeVal.getList(), Arrays.asList("value_1", "value_2")); Assert.assertNotNull(myConfig.getAttributes().get("my_property_2")); attributeVal = myConfig.getAttributes().get("my_property_2"); Assert.assertEquals(attributeVal.getList(), Arrays.asList("value_3", "value_4")); }
@Test public void testIfDefaultBuilderRunnerAppearsInProject() throws Exception { Project myProject = pm.getProject("my_ws", "my_project"); Map<String, List<String>> attributes = new HashMap<>(2); attributes.put("my_property_1", Arrays.asList("value_1", "value_2")); ProjectJson projectJson = new ProjectJson("my_project_type", attributes, null , null, "test project"); projectJson.save(myProject); Assert.assertNotNull(myProject.getConfig().getRunners()); Assert.assertEquals(myProject.getConfig().getRunners().getDefault(), "system:/runner/runner1"); Assert.assertNotNull(myProject.getConfig().getBuilders()); Assert.assertEquals(myProject.getConfig().getBuilders().getDefault(), "builder1"); }