Search in sources :

Example 6 with ReleaseException

use of eu.bcvsolutions.idm.tool.exception.ReleaseException in project CzechIdMng by bcvsolutions.

the class AbstractReleaseManager method getCurrentVersion.

protected String getCurrentVersion() {
    String currentVersion = null;
    // BE
    for (String backendModule : getBackendModules(getCurrentBackendModuleVersion(getRootBackendModule()))) {
        String moduleVersion = getCurrentBackendModuleVersion(backendModule);
        LOG.debug("Backend module [{}] has current version [{}].", backendModule, moduleVersion);
        if (StringUtils.isEmpty(moduleVersion)) {
            throw new ReleaseException(String.format("Backend module [%s] version cannot be resolved.", backendModule));
        }
        if (currentVersion == null) {
            currentVersion = moduleVersion;
        } else if (!currentVersion.equals(moduleVersion)) {
            throw new ReleaseException(String.format("Backend module [%s] has wrong version [%s], expected version [%s].", backendModule, moduleVersion, currentVersion));
        }
    }
    // FE
    for (String frontendModule : getFrontendModules(currentVersion)) {
        String moduleVersion = getCurrentFrontendModuleVersion(frontendModule);
        LOG.debug("Frontend module [{}] has current version [{}].", frontendModule, moduleVersion);
        if (StringUtils.isEmpty(moduleVersion)) {
            throw new ReleaseException(String.format("Frontend module [%s] version cannot be resolved.", moduleVersion));
        }
        if (currentVersion == null) {
            currentVersion = moduleVersion;
        } else if (!currentVersion.equalsIgnoreCase(moduleVersion)) {
            throw new ReleaseException(String.format("Frontend module [%s] has wrong version [%s], expected version [%s].", frontendModule, moduleVersion, currentVersion.toLowerCase()));
        }
    }
    // 
    LOG.info("Current product version [{}].", currentVersion);
    // 
    return currentVersion;
}
Also used : GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ReleaseException(eu.bcvsolutions.idm.tool.exception.ReleaseException)

Example 7 with ReleaseException

use of eu.bcvsolutions.idm.tool.exception.ReleaseException in project CzechIdMng by bcvsolutions.

the class AbstractReleaseManager method hasParentModule.

/**
 * If module has parent defined.
 *
 * @param moduleName
 * @return true = is submodule.
 */
protected boolean hasParentModule(String moduleName) {
    File modulePackage = new File(String.format("%s/pom.xml", getBackendModuleBasePath(moduleName)));
    Assert.isTrue(modulePackage.exists(), String.format("Backend module [%s] not found on filesystem.", moduleName));
    // 
    try {
        XmlMapper xmlMapper = new XmlMapper();
        JsonNode json = xmlMapper.readTree(modulePackage);
        // 
        return json.get("parent") != null;
    } catch (Exception ex) {
        throw new ReleaseException(ex);
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ReleaseException(eu.bcvsolutions.idm.tool.exception.ReleaseException) File(java.io.File) ReleaseException(eu.bcvsolutions.idm.tool.exception.ReleaseException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoWorkTreeException(org.eclipse.jgit.errors.NoWorkTreeException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 8 with ReleaseException

use of eu.bcvsolutions.idm.tool.exception.ReleaseException in project CzechIdMng by bcvsolutions.

the class AbstractReleaseManager method gitCreateTag.

protected String gitCreateTag(String tagVersion) {
    Assert.hasLength(tagVersion, "Tag version (~name) is required.");
    // 
    boolean isSnapshotVersion = false;
    if (isSnapshotVersion(tagVersion)) {
        LOG.warn("Tag will be created for development version [{}] - it's only for development puprose (should not be pushed to origin).", tagVersion);
        isSnapshotVersion = true;
    }
    String message;
    if (isSnapshotVersion) {
        ZonedDateTime now = ZonedDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(ConfigurationService.DEFAULT_APP_DATETIME_WITH_SECONDS_FORMAT);
        message = String.format("Snapshot version %s (%s)", tagVersion, formatter.format(now));
    } else {
        message = String.format("Release version %s", tagVersion);
    }
    // 
    try {
        git.tag().setName(tagVersion).setMessage(message).call();
    } catch (Exception ex) {
        throw new ReleaseException("Tag failed", ex);
    }
    // 
    if (isSnapshotVersion) {
        LOG.info("Snapshot tag [{}] created.", tagVersion);
    } else {
        LOG.info("Tag [{}] created. Don't forget to push tag to origin if needed.", tagVersion);
    }
    // 
    return tagVersion;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ReleaseException(eu.bcvsolutions.idm.tool.exception.ReleaseException) DateTimeFormatter(java.time.format.DateTimeFormatter) ReleaseException(eu.bcvsolutions.idm.tool.exception.ReleaseException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoWorkTreeException(org.eclipse.jgit.errors.NoWorkTreeException)

Example 9 with ReleaseException

use of eu.bcvsolutions.idm.tool.exception.ReleaseException in project CzechIdMng by bcvsolutions.

the class AbstractReleaseManager method init.

@Override
public void init() {
    mavenManager = new MavenManager(mavenHome);
    // 
    String repositoryRoot = getRepositoryRoot();
    LOG.info("Repository location: [{}].", repositoryRoot);
    Assert.hasLength(repositoryRoot, "Repository root is required.");
    Assert.isTrue(new File(repositoryRoot).exists(), String.format("Repository root [%s] not found.", repositoryRoot));
    // 
    LOG.info("Develop branch: [{}].", getDevelopBranch());
    LOG.info("Master branch: [{}].", getMasterBranch());
    // 
    try {
        git = Git.open(new File(repositoryRoot));
    } catch (Exception ex) {
        throw new ReleaseException(String.format("Git repository in folder [%s] cannot be inited.", repositoryRoot), ex);
    }
}
Also used : GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ReleaseException(eu.bcvsolutions.idm.tool.exception.ReleaseException) File(java.io.File) ReleaseException(eu.bcvsolutions.idm.tool.exception.ReleaseException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoWorkTreeException(org.eclipse.jgit.errors.NoWorkTreeException)

Example 10 with ReleaseException

use of eu.bcvsolutions.idm.tool.exception.ReleaseException in project CzechIdMng by bcvsolutions.

the class AbstractReleaseManager method gitInitRepository.

/**
 * Init repository - usable for tests
 */
protected void gitInitRepository() {
    File repositoryRoot = new File(getRepositoryRoot());
    Assert.isTrue(repositoryRoot.exists(), "Product root has to exist.");
    // 
    try {
        git = Git.init().setDirectory(repositoryRoot).call();
        FileUtils.writeStringToFile(new File(repositoryRoot.getPath() + "/README.md"), "test repo", AttachableEntity.DEFAULT_CHARSET);
        gitAddAll();
        gitCommit("start commit");
    } catch (Exception ex) {
        throw new ReleaseException("Init repository failed", ex);
    }
}
Also used : ReleaseException(eu.bcvsolutions.idm.tool.exception.ReleaseException) File(java.io.File) ReleaseException(eu.bcvsolutions.idm.tool.exception.ReleaseException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoWorkTreeException(org.eclipse.jgit.errors.NoWorkTreeException)

Aggregations

ReleaseException (eu.bcvsolutions.idm.tool.exception.ReleaseException)10 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)8 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)8 NoWorkTreeException (org.eclipse.jgit.errors.NoWorkTreeException)8 File (java.io.File)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 FileOutputStream (java.io.FileOutputStream)1 ZonedDateTime (java.time.ZonedDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1