use of org.eclipse.che.api.project.server.type.AttributeValue in project che by eclipse.
the class ProjectManagerWriteTest method testSettableValueProvider.
@Test
public void testSettableValueProvider() throws Exception {
assertTrue(((Variable) projectTypeRegistry.getProjectType("settableVPPT").getAttribute("my")).isValueProvided());
ProjectConfig pc = new NewProjectConfigImpl("/testSettableValueProvider", "settableVPPT", null, "", "", new HashMap<>(), null, null);
pm.createProject(pc, null);
RegisteredProject project = pm.getProject("/testSettableValueProvider");
assertEquals(1, project.getAttributes().size());
assertEquals("notset", project.getAttributes().get("my").get(0));
Map<String, List<String>> attributes = new HashMap<>();
attributes.put("my", new AttributeValue("set").getList());
pc = new NewProjectConfigImpl("/testSettableValueProvider", "settableVPPT", null, "", "", attributes, null, null);
pm.updateProject(pc);
project = pm.getProject("/testSettableValueProvider");
assertEquals("set", project.getAttributes().get("my").get(0));
}
use of org.eclipse.che.api.project.server.type.AttributeValue in project che by eclipse.
the class ProjectManagerWriteTest method testProvidedAttributesNotSerialized.
@Test
public void testProvidedAttributesNotSerialized() throws Exception {
Map<String, List<String>> attributes = new HashMap<>();
attributes.put("pt2-var2", new AttributeValue("test2").getList());
attributes.put("pt2-var1", new AttributeValue("test1").getList());
ProjectConfig pc = new NewProjectConfigImpl("/testProvidedAttributesNotSerialized", "pt3", null, "name", "descr", attributes, null, null);
pm.createProject(pc, null);
for (ProjectConfig project : workspaceHolder.getProjects()) {
if (project.getPath().equals("/testProvidedAttributesNotSerialized")) {
assertNotNull(project.getAttributes().get("pt2-var1"));
assertNotNull(project.getAttributes().get("pt2-var2"));
assertNull(project.getAttributes().get("pt2-const1"));
assertNull(project.getAttributes().get("pt2-provided1"));
}
}
}
use of org.eclipse.che.api.project.server.type.AttributeValue in project che by eclipse.
the class ProjectManagerWriteTest method testCreateProjectWithRequiredProvidedAttributeWhenGivenProjectTypeHasGenerator.
@Test
public void testCreateProjectWithRequiredProvidedAttributeWhenGivenProjectTypeHasGenerator() throws Exception {
final String path = "/testCreateProjectWithRequiredProvidedAttribute";
final String projectTypeId = "pt3";
final Map<String, List<String>> attributes = new HashMap<>();
attributes.put("pt2-var2", new AttributeValue("test").getList());
final ProjectConfig pc = new NewProjectConfigImpl(path, projectTypeId, null, "name", "descr", attributes, null, null);
pm.createProject(pc, null);
final RegisteredProject project = projectRegistry.getProject(path);
assertEquals(projectTypeId, project.getType());
assertNotNull(project.getBaseFolder().getChild("file1"));
assertEquals("pt2-provided1", project.getAttributes().get("pt2-provided1").get(0));
}
use of org.eclipse.che.api.project.server.type.AttributeValue in project che by eclipse.
the class RegisteredProject method initAttributes.
/**
* Initialize project attributes.
* Note: the problem with {@link Problem#code} = 13 will be added when a value for some attribute is not initialized
*/
private void initAttributes() {
// we take only defined attributes, others ignored
for (Map.Entry<String, Attribute> entry : types.getAttributeDefs().entrySet()) {
final Attribute definition = entry.getValue();
final String name = entry.getKey();
AttributeValue value = new AttributeValue(config.getAttributes().get(name));
if (!definition.isVariable()) {
// constant, value always assumed as stated in definition
attributes.put(name, definition.getValue());
} else {
// variable
final Variable variable = (Variable) definition;
// value provided
if (variable.isValueProvided()) {
final ValueProvider valueProvider = variable.getValueProviderFactory().newInstance(folder);
if (folder != null) {
try {
if (!valueProvider.isSettable() || value.isEmpty()) {
// get provided value
value = new AttributeValue(valueProvider.getValues(name));
} else {
// set provided (not empty) value
valueProvider.setValues(name, value.getList());
}
} catch (ValueStorageException e) {
final Problem problem = new Problem(ATTRIBUTE_NAME_PROBLEM, format("Value for attribute %s is not initialized, caused by: %s", variable.getId(), e.getLocalizedMessage()));
this.problems.add(problem);
}
} else {
continue;
}
}
if (value.isEmpty() && variable.isRequired()) {
final Problem problem = new Problem(ATTRIBUTE_NAME_PROBLEM, "Value for required attribute is not initialized " + variable.getId());
this.problems.add(problem);
//throw new ProjectTypeConstraintException("Value for required attribute is not initialized " + variable.getId());
}
if (!value.isEmpty()) {
this.attributes.put(name, value);
}
}
}
}
use of org.eclipse.che.api.project.server.type.AttributeValue in project che by eclipse.
the class ArchetypeGenerationStrategy method generateProject.
@Override
public void generateProject(final Path projectPath, Map<String, AttributeValue> attributes, Map<String, String> options) throws ForbiddenException, ConflictException, ServerException {
AttributeValue artifactId = attributes.get(ARTIFACT_ID);
AttributeValue groupId = attributes.get(GROUP_ID);
AttributeValue version = attributes.get(VERSION);
if (groupId == null || artifactId == null || version == null) {
throw new ServerException("Missed some required attribute (groupId, artifactId or version)");
}
String archetypeGroupId = null;
String archetypeArtifactId = null;
String archetypeVersion = null;
String archetypeRepository = null;
Map<String, String> archetypeProperties = new HashMap<>();
//TODO: remove prop 'type' now it use only for detecting generation strategy
options.remove("type");
for (Entry<String, String> entry : options.entrySet()) {
switch(entry.getKey()) {
case "archetypeGroupId":
archetypeGroupId = entry.getValue();
break;
case "archetypeArtifactId":
archetypeArtifactId = entry.getValue();
break;
case "archetypeVersion":
archetypeVersion = entry.getValue();
break;
case "archetypeRepository":
archetypeRepository = entry.getValue();
break;
default:
archetypeProperties.put(entry.getKey(), entry.getValue());
}
}
if (isNullOrEmpty(archetypeGroupId) || isNullOrEmpty(archetypeArtifactId) || isNullOrEmpty(archetypeVersion)) {
throw new ServerException("Missed some required option (archetypeGroupId, archetypeArtifactId or archetypeVersion)");
}
MavenArchetype mavenArchetype = new MavenArchetypeImpl(archetypeGroupId, archetypeArtifactId, archetypeVersion, archetypeRepository, archetypeProperties);
final MavenArtifact mavenArtifact = new MavenArtifact();
mavenArtifact.setGroupId(getFirst(groupId.getList(), projectPath.getName()));
mavenArtifact.setArtifactId(getFirst(artifactId.getList(), projectPath.getName()));
mavenArtifact.setVersion(getFirst(version.getList(), DEFAULT_VERSION));
archetypeGenerator.generateFromArchetype(vfs.getRoot().toIoFile(), mavenArchetype, mavenArtifact);
}
Aggregations