use of org.finos.legend.sdlc.domain.model.version.VersionId in project legend-sdlc by finos.
the class ProjectDependency method parseProjectDependency.
public static ProjectDependency parseProjectDependency(String string, int start, int end, char delimiter) {
if (string == null) {
throw new IllegalArgumentException("Invalid project dependency string: null");
}
int delimiterIndex = string.lastIndexOf(delimiter, end - 1);
if ((delimiterIndex == -1) || (delimiterIndex < start)) {
throw new IllegalArgumentException(new StringBuilder("Invalid project dependency string: \"").append(string, start, end).append('"').toString());
}
String projectId = string.substring(start, delimiterIndex);
VersionId versionId;
try {
versionId = VersionId.parseVersionId(string, delimiterIndex + 1, end);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(new StringBuilder("Invalid project dependency string: \"").append(string, start, end).append('"').toString(), e);
}
return newProjectDependency(projectId, versionId);
}
use of org.finos.legend.sdlc.domain.model.version.VersionId in project legend-sdlc by finos.
the class MultiModuleMavenProjectStructure method createMavenOtherModuleModel.
protected Model createMavenOtherModuleModel(String otherModuleName, BiFunction<String, VersionId, ProjectFileAccessProvider.FileAccessContext> versionFileAccessContextProvider) {
Model mavenModel = createMavenModuleModel(otherModuleName);
ArtifactType typeForConfig = otherModules.get(otherModuleName);
Map<ModuleConfigType, Method> otherModuleConfigMethods = this.moduleConfigMethods.get(getModuleConfigName(typeForConfig));
if (otherModuleConfigMethods != null) {
// Properties
Method propertiesMethod = otherModuleConfigMethods.get(ModuleConfigType.PROPERTIES);
if (propertiesMethod != null) {
try {
Properties properties = new SortedPropertiesForSerialization();
invokeConfigMethod(propertiesMethod, (BiConsumer<String, String>) properties::setProperty);
if (!properties.isEmpty()) {
mavenModel.setProperties(properties);
}
} catch (LegendSDLCServerException e) {
throw e;
} catch (Exception e) {
throw new LegendSDLCServerException("Error adding maven properties for module " + otherModuleName, e);
}
}
// Module dependencies
Method moduleDependenciesMethod = otherModuleConfigMethods.get(ModuleConfigType.MODULE_DEPENDENCIES);
if (moduleDependenciesMethod != null) {
try {
invokeConfigMethod(moduleDependenciesMethod, (Consumer<String>) m -> mavenModel.addDependency(getModuleWithNoVersionDependency(m)));
} catch (LegendSDLCServerException e) {
throw e;
} catch (Exception e) {
throw new LegendSDLCServerException("Error adding maven module dependencies for module " + otherModuleName, e);
}
}
// Dependencies
Method dependenciesMethod = otherModuleConfigMethods.get(ModuleConfigType.DEPENDENCIES);
if (dependenciesMethod != null) {
try {
invokeConfigMethod(dependenciesMethod, versionFileAccessContextProvider, (Consumer<Dependency>) mavenModel::addDependency);
} catch (LegendSDLCServerException e) {
throw e;
} catch (Exception e) {
throw new LegendSDLCServerException("Error adding maven dependencies for module " + otherModuleName, e);
}
}
// Plugins
Method pluginsMethod = otherModuleConfigMethods.get(ModuleConfigType.PLUGINS);
if (pluginsMethod != null) {
try {
Build build = new Build();
invokeConfigMethod(pluginsMethod, otherModuleName, versionFileAccessContextProvider, (Consumer<Plugin>) build::addPlugin);
if (!build.getPlugins().isEmpty()) {
mavenModel.setBuild(build);
}
} catch (LegendSDLCServerException e) {
throw e;
} catch (Exception e) {
throw new LegendSDLCServerException("Error adding maven plugins for module " + otherModuleName, e);
}
}
}
return mavenModel;
}
use of org.finos.legend.sdlc.domain.model.version.VersionId in project legend-sdlc by finos.
the class GitLabVersionApi method newVersion.
@Override
public Version newVersion(String projectId, NewVersionType type, String revisionId, String notes) {
LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null");
LegendSDLCServerException.validateNonNull(type, "type may not be null");
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
switch(getProjectTypeFromMode(gitLabProjectId.getGitLabMode())) {
case PROTOTYPE:
{
throw new LegendSDLCServerException("Cannot create versions for prototype projects", Status.BAD_REQUEST);
}
case PRODUCTION:
{
Version latestVersion = getLatestVersion(gitLabProjectId);
VersionId latestVersionId = (latestVersion == null) ? NULL_VERSION : latestVersion.getId();
VersionId nextVersionId;
switch(type) {
case MAJOR:
{
nextVersionId = latestVersionId.nextMajorVersion();
break;
}
case MINOR:
{
nextVersionId = latestVersionId.nextMinorVersion();
break;
}
case PATCH:
{
nextVersionId = latestVersionId.nextPatchVersion();
break;
}
default:
{
throw new LegendSDLCServerException("Unknown new version type: " + type, Status.BAD_REQUEST);
}
}
return newVersion(gitLabProjectId, revisionId, nextVersionId, notes);
}
default:
{
throw new LegendSDLCServerException("Unknown project: " + projectId, Status.BAD_REQUEST);
}
}
}
use of org.finos.legend.sdlc.domain.model.version.VersionId in project legend-sdlc by finos.
the class GitLabVersionApi method newVersion.
private Version newVersion(GitLabProjectId projectId, String revisionId, VersionId versionId, String notes) {
String tagName = buildVersionTagName(versionId);
String message = "Release tag for version " + versionId.toVersionIdString();
try {
GitLabApi gitLabApi = getGitLabApi(projectId.getGitLabMode());
CommitsApi commitsApi = gitLabApi.getCommitsApi();
Commit referenceCommit;
if (revisionId == null) {
referenceCommit = commitsApi.getCommit(projectId.getGitLabId(), MASTER_BRANCH);
if (referenceCommit == null) {
throw new LegendSDLCServerException("Cannot create version " + versionId.toVersionIdString() + " of project " + projectId + ": cannot find current revision (project may be corrupt)", Status.INTERNAL_SERVER_ERROR);
}
} else {
try {
referenceCommit = commitsApi.getCommit(projectId.getGitLabId(), revisionId);
} catch (GitLabApiException e) {
if (GitLabApiTools.isNotFoundGitLabApiException(e)) {
throw new LegendSDLCServerException("Revision " + revisionId + " is unknown in project " + projectId, Status.BAD_REQUEST);
}
throw e;
}
Pager<CommitRef> referenceCommitBranchPager = withRetries(() -> commitsApi.getCommitRefs(projectId.getGitLabId(), referenceCommit.getId(), RefType.BRANCH, ITEMS_PER_PAGE));
Stream<CommitRef> referenceCommitBranches = PagerTools.stream(referenceCommitBranchPager);
if (referenceCommitBranches.noneMatch(ref -> MASTER_BRANCH.equals(ref.getName()))) {
throw new LegendSDLCServerException("Revision " + revisionId + " is unknown in project " + projectId, Status.BAD_REQUEST);
}
}
String referenceRevisionId = referenceCommit.getId();
Pager<CommitRef> referenceCommitTagPager = withRetries(() -> commitsApi.getCommitRefs(projectId.getGitLabId(), referenceRevisionId, RefType.TAG, ITEMS_PER_PAGE));
List<CommitRef> referenceCommitTags = PagerTools.stream(referenceCommitTagPager).collect(Collectors.toList());
if (referenceCommitTags.stream().map(CommitRef::getName).anyMatch(GitLabVersionApi::isVersionTagName)) {
StringBuilder builder = new StringBuilder("Revision ").append(referenceRevisionId).append(" has already been released in ");
List<VersionId> revisionVersionIds = referenceCommitTags.stream().map(CommitRef::getName).filter(GitLabVersionApi::isVersionTagName).map(GitLabVersionApi::parseVersionTagName).collect(Collectors.toList());
if (revisionVersionIds.size() == 1) {
builder.append("version ");
revisionVersionIds.get(0).appendVersionIdString(builder);
} else {
builder.append("versions ");
revisionVersionIds.sort(Comparator.naturalOrder());
boolean first = true;
for (VersionId revisionVersionId : revisionVersionIds) {
if (first) {
first = false;
} else {
builder.append(", ");
}
revisionVersionId.appendVersionIdString(builder);
}
}
throw new LegendSDLCServerException(builder.toString());
}
Tag tag = getGitLabApi(projectId.getGitLabMode()).getTagsApi().createTag(projectId.getGitLabId(), tagName, referenceRevisionId, message, notes);
return fromGitLabTag(projectId.toString(), tag);
} catch (Exception e) {
throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to create version " + versionId.toVersionIdString() + " of project " + projectId, () -> "Unknown project: " + projectId, () -> "Error creating version " + versionId.toVersionIdString() + " of project " + projectId);
}
}
use of org.finos.legend.sdlc.domain.model.version.VersionId in project legend-sdlc by finos.
the class DepotProjectVersion method parseDepotProjectVersion.
public static DepotProjectVersion parseDepotProjectVersion(String depotProjectVersion) {
if (depotProjectVersion == null) {
return null;
}
int delimiterIndex = depotProjectVersion.lastIndexOf(DELIMITER);
if (delimiterIndex == -1) {
throw new IllegalArgumentException("Invalid project string: " + depotProjectVersion);
}
String projectId = depotProjectVersion.substring(0, delimiterIndex);
VersionId versionId;
try {
versionId = VersionId.parseVersionId(depotProjectVersion, delimiterIndex + 1, depotProjectVersion.length());
} catch (IllegalArgumentException ex) {
throw new IllegalArgumentException("Invalid project string: " + depotProjectVersion, ex);
}
return newDepotProjectVersion(projectId, versionId);
}
Aggregations