Example usage for org.apache.commons.lang.time DurationFormatUtils formatPeriod

List of usage examples for org.apache.commons.lang.time DurationFormatUtils formatPeriod

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DurationFormatUtils formatPeriod.

Prototype

public static String formatPeriod(long startMillis, long endMillis, String format) 

Source Link

Document

Formats the time gap as a string, using the specified format.

Usage

From source file:org.artifactory.repo.service.DeployServiceImpl.java

@Override
public void deployBundle(File bundle, RealRepoDescriptor targetRepo, final BasicStatusHolder status,
        boolean failFast, String prefix, Properties properties) {
    long start = System.currentTimeMillis();
    if (!bundle.exists()) {
        String message = "Specified location '" + bundle + "' does not exist. Deployment aborted.";
        status.error(message, log);/*  w  ww . j a v  a2 s .  c  o  m*/
        return;
    }
    File extractFolder;
    try {
        extractFolder = extractArchive(status, bundle);
    } catch (Exception e) {
        status.error(e.getLocalizedMessage(), e, log);
        return;
    }
    if (extractFolder == null) {
        //We have errors
        return;
    }
    try {
        IOFileFilter deployableFilesFilter = new AbstractFileFilter() {
            @Override
            public boolean accept(File file) {
                if (NamingUtils.isSystem(file.getAbsolutePath()) || GlobalExcludes.isInGlobalExcludes(file)
                        || file.getName().contains(MavenNaming.MAVEN_METADATA_NAME)) {
                    status.debug("Excluding '" + file.getAbsolutePath() + "' from bundle deployment.", log);
                    return false;
                }

                return true;
            }
        };
        List<File> archiveContent = Lists.newArrayList(
                FileUtils.listFiles(extractFolder, deployableFilesFilter, DirectoryFileFilter.DIRECTORY));
        Collections.sort(archiveContent);

        Repo repo = repositoryService.repositoryByKey(targetRepo.getKey());
        for (File file : archiveContent) {
            String parentPath = extractFolder.getAbsolutePath();
            String filePath = file.getAbsolutePath();
            String relPath = PathUtils
                    .trimSlashes(prefix + "/" + PathUtils.getRelativePath(parentPath, filePath)).toString();

            ModuleInfo moduleInfo = repo.getItemModuleInfo(relPath);
            if (MavenNaming.isPom(file.getName())) {
                try {
                    mavenService.validatePomFile(file, relPath, moduleInfo,
                            targetRepo.isSuppressPomConsistencyChecks());
                } catch (Exception e) {
                    String msg = "The pom: " + file.getName()
                            + " could not be validated, and thus was not deployed.";
                    status.error(msg, e, log);
                    if (failFast) {
                        return;
                    }
                    continue;
                }
            }

            try {
                getTransactionalMe().deploy(targetRepo, new ArtifactInfo(relPath), file, null, false, true,
                        properties);
            } catch (IllegalArgumentException iae) {
                status.error(iae.getMessage(), iae, log);
                if (failFast) {
                    return;
                }
            } catch (Exception e) {
                // Fail fast
                status.error("Error during deployment: " + e.getMessage(), e, log);
                if (failFast) {
                    return;
                }
            }
        }

        String bundleName = bundle.getName();
        String timeTaken = DurationFormatUtils.formatPeriod(start, System.currentTimeMillis(), "s");
        int archiveContentSize = archiveContent.size();

        status.status("Successfully deployed " + archiveContentSize + " artifacts from archive: " + bundleName
                + " (" + timeTaken + " seconds).", log);
    } catch (Exception e) {
        status.error(e.getMessage(), e, log);
    } finally {
        FileUtils.deleteQuietly(extractFolder);
    }
}

From source file:org.artifactory.webapp.servlet.ArtifactoryContextConfigListener.java

private void configure(ServletContext servletContext, Logger log) throws Exception {
    long start = System.currentTimeMillis();

    ArtifactoryHome artifactoryHome = (ArtifactoryHome) servletContext
            .getAttribute(ArtifactoryHome.SERVLET_CTX_ATTR);
    VersionProviderImpl versionProvider = (VersionProviderImpl) servletContext
            .getAttribute(ArtifactoryHome.ARTIFACTORY_VERSION_PROVIDER_OBJ);
    ConverterManager converterManager = (ConverterManager) servletContext
            .getAttribute(ArtifactoryHome.ARTIFACTORY_CONVERTER_OBJ);

    if (artifactoryHome == null) {
        throw new IllegalStateException("Artifactory home not initialized.");
    }/*from  w  w  w.java  2  s. c  o m*/
    CompoundVersionDetails runningVersionDetails = versionProvider.getRunning();

    logAsciiArt(log, artifactoryHome, runningVersionDetails);

    ApplicationContext context;
    try {
        ArtifactoryHome.bind(artifactoryHome);

        //todo consider moving to org.artifactory.webapp.servlet.ArtifactoryHomeConfigListener.contextInitialized()
        if (artifactoryHome.isHaConfigured()) {
            log.debug("Not using Artifactory lock file on HA environment");
        } else {
            artifactoryLockFile = new ArtifactoryLockFile(
                    new File(artifactoryHome.getDataDir(), LOCK_FILENAME));
            artifactoryLockFile.tryLock();
        }

        Class<?> contextClass = ClassUtils.forName("org.artifactory.spring.ArtifactoryApplicationContext",
                ClassUtils.getDefaultClassLoader());
        Constructor<?> constructor = contextClass.getConstructor(String.class, SpringConfigPaths.class,
                ArtifactoryHome.class, ConverterManager.class, VersionProviderImpl.class);
        //Construct the context name based on the context path
        //(will not work with multiple servlet containers on the same vm!)
        String contextUniqueName = HttpUtils.getContextId(servletContext);
        SpringConfigPaths springConfigPaths = SpringConfigResourceLoader.getConfigurationPaths(artifactoryHome);
        context = (ApplicationContext) constructor.newInstance(contextUniqueName, springConfigPaths,
                artifactoryHome, converterManager, versionProvider);
    } finally {
        ArtifactoryHome.unbind();
    }
    log.info("\n" + "###########################################################\n"
            + "### Artifactory successfully started ("
            + String.format("%-17s",
                    (DurationFormatUtils.formatPeriod(start, System.currentTimeMillis(), "s.S")) + " seconds)")
            + " ###\n" + "###########################################################\n");

    //Register the context for easy retrieval for faster destroy
    servletContext.setAttribute(ArtifactoryContext.APPLICATION_CONTEXT_KEY, context);
}

From source file:org.kuali.kra.bo.KcPerson.java

/**
 * Calculates the age based on a date of birth and the current system date.
 * @param dob the date of birth/*  w  w w  . ja va2s  .  c om*/
 * @return the age in days
 */
private Integer calcAge(Date dob) {
    return Integer.getInteger(DurationFormatUtils.formatPeriod(dob.getTime(), new Date().getTime(), "y"));
}