Search in sources :

Example 1 with ReleaseException

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

the class AbstractReleaseManager method setFrontendVersion.

protected void setFrontendVersion(String fullVersionName) {
    String newVersion = fullVersionName.toLowerCase();
    // 
    for (String frontendModule : getFrontendModules(newVersion)) {
        File modulePackage = new File(getFrontendModuleBasePath(frontendModule), "package.json");
        Assert.isTrue(modulePackage.exists(), String.format("Frontend module [%s] not found on filesystem.", frontendModule));
        // 
        try {
            ObjectNode json = (ObjectNode) getPackageJson(modulePackage);
            json.put("version", newVersion);
            // 
            try (FileOutputStream outputStream = new FileOutputStream(modulePackage)) {
                JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
                getMapper().writer(getPrettyPrinter()).writeValue(jGenerator, json);
                jGenerator.close();
                // 
                LOG.info("Frontend module [{}] version set to [{}]", frontendModule, newVersion);
            } catch (Exception ex) {
                throw new ReleaseException(ex);
            }
        } catch (Exception ex) {
            throw new ReleaseException(ex);
        }
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FileOutputStream(java.io.FileOutputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) 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 2 with ReleaseException

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

the class AbstractReleaseManager method revertVersion.

@Override
public String revertVersion() {
    gitSwitchBranch(getDevelopBranch());
    // 
    String forVersion = getCurrentBackendModuleVersion(getRootBackendModule());
    // checkout doesn't support wildcards, don't know why ...
    List<String> allProjectFiles = Stream.concat(getBackendModules(forVersion).stream().map(moduleName -> {
        return String.format("%s/pom.xml", getBackendModuleRelativePath(moduleName));
    }), getFrontendModules(forVersion).stream().map(moduleName -> {
        return String.format("%s/package.json", getFrontendModuleRelativePath(moduleName));
    })).collect(Collectors.toList());
    // 
    try {
        gitCheckout(allProjectFiles);
        // 
        String currentVersion = getCurrentVersion();
        LOG.info("Project files (pom.xml, package.json) reverted. Current version [{}].", currentVersion);
        return currentVersion;
    } catch (Exception ex) {
        throw new ReleaseException("Revert project files failed", ex);
    }
}
Also used : GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ReleaseException(eu.bcvsolutions.idm.tool.exception.ReleaseException) ReleaseException(eu.bcvsolutions.idm.tool.exception.ReleaseException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoWorkTreeException(org.eclipse.jgit.errors.NoWorkTreeException)

Example 3 with ReleaseException

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

the class AbstractReleaseManager method getCurrentBackendModuleVersion.

protected String getCurrentBackendModuleVersion(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);
        // 
        String currentVersion = null;
        JsonNode versionNode = json.get("version");
        if (versionNode == null) {
            JsonNode parentNode = json.get("parent");
            if (parentNode != null) {
                versionNode = parentNode.get("version");
            }
        }
        if (versionNode != null) {
            currentVersion = versionNode.textValue();
        }
        // 
        return currentVersion;
    } catch (Exception ex) {
        throw new ReleaseException(ex);
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) 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) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 4 with ReleaseException

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

the class AbstractReleaseManager method getCurrentFrontendModuleVersion.

protected String getCurrentFrontendModuleVersion(String moduleName) {
    File modulePackage = new File(getFrontendModuleBasePath(moduleName), "package.json");
    Assert.isTrue(modulePackage.exists(), String.format("Frontend module [%s] not found on filesystem.", moduleName));
    // 
    try {
        JsonNode json = getPackageJson(modulePackage);
        String currentVersion = json.get("version").textValue();
        // 
        return currentVersion;
    } catch (Exception ex) {
        throw new ReleaseException(ex);
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) 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 5 with ReleaseException

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

the class AbstractReleaseManager method release.

@Override
public String release(String releaseVersion, String newDevelopVersion) {
    // no local changes
    if (!gitIsClean()) {
        throw new ReleaseException("Local changes found - push or revert changes before release");
    }
    // switch develop
    gitSwitchBranch(getDevelopBranch());
    gitPull();
    // 
    if (StringUtils.isEmpty(releaseVersion)) {
        releaseVersion = getVersionNumber(getCurrentVersion());
    }
    // 
    LOG.info("Release version [{}] ...", releaseVersion);
    // 
    // set stable version
    setVersion(releaseVersion);
    if (checkChanges() > 0) {
        // prevent to create empty commit
        gitAddAll();
        gitCommit(String.format("Release version [%s] - prepare", releaseVersion));
    }
    // deploy - its saver than merge stable into master (this takes long time and conflict can occurs)
    deploy();
    // 
    if (checkChanges() > 0) {
        // prevent to create empty commit
        // package-lock is changed after build + deploy => we need to commit it into tag / master
        gitAddAll();
        gitCommit(String.format("Release version [%s] - alfter build", releaseVersion));
    }
    // create tag
    gitCreateTag(releaseVersion);
    // merge into master, if branch is given
    // sometimes merge is not needed (e.g. when some old hotfix branch is released - set null)
    String masterBranch = getMasterBranch();
    if (StringUtils.isNotEmpty(masterBranch)) {
        gitSwitchBranch(masterBranch);
        gitPull();
        // merge develop into master - conflict can occurs => just this and next step should be repeated.
        gitMerge(getDevelopBranch());
        // switch develop
        gitSwitchBranch(getDevelopBranch());
    }
    // set new develop version version
    if (StringUtils.isEmpty(newDevelopVersion)) {
        newDevelopVersion = getNextSnapshotVersionNumber(releaseVersion, null);
    }
    setVersion(newDevelopVersion);
    if (checkChanges() > 0) {
        // prevent to create empty commit
        gitAddAll();
        gitCommit(String.format("New develop version [%s]", newDevelopVersion));
    }
    // 
    LOG.info("Version released [{}]. New development version [{}].", releaseVersion, newDevelopVersion);
    LOG.info("Branches [{}], [{}] and tag [{}] are prepared to push into origin.", getDevelopBranch(), getMasterBranch(), releaseVersion);
    // 
    return releaseVersion;
}
Also used : GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ReleaseException(eu.bcvsolutions.idm.tool.exception.ReleaseException)

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