@Override public void setValues(String attributeName, List<String> value) throws ValueStorageException, InvalidValueException { try { VirtualFile pom = getPom(projectFolder); if (pom == null) { Model model = Model.createModel(); model.setModelVersion("4.0.0"); projectFolder.createFile("pom.xml", new byte[0], "text/xml"); } if (attributeName.equals(MavenAttributes.ARTIFACT_ID)) Model.readFrom(pom).setArtifactId(value.get(0)).writeTo(pom); if (attributeName.equals(MavenAttributes.GROUP_ID)) Model.readFrom(pom).setGroupId(value.get(0)).writeTo(pom); if (attributeName.equals(MavenAttributes.PACKAGING)) { Model model = Model.readFrom(pom); if (model.getPackaging() != null && value.get(0).equals("pom")) { model.setPackaging(value.get(0)).writeTo(pom); } } if (attributeName.equals(MavenAttributes.VERSION)) Model.readFrom(pom).setVersion(value.get(0)).writeTo(pom); } catch (ForbiddenException | ServerException | IOException | ConflictException e) { throwWriteException(e); } }
protected Model readModel(FolderEntry projectFolder) throws ValueStorageException, ServerException, ForbiddenException, IOException { FileEntry pomFile = (FileEntry) projectFolder.getChild("pom.xml"); if (pomFile == null) { throw new ValueStorageException("pom.xml does not exist."); } return Model.readFrom(pomFile.getInputStream()); }