Example usage for org.apache.commons.lang.time StopWatch reset

List of usage examples for org.apache.commons.lang.time StopWatch reset

Introduction

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

Prototype

public void reset() 

Source Link

Document

Resets the stopwatch.

Usage

From source file:nu.mine.kino.projects.PVCreatorTest.java

@Test
public void test() throws FileNotFoundException, ProjectException {

    File input = new File("project_management_tools.xls");
    System.out.println(input.getAbsolutePath());

    // File create = PVCreator.create(input);
    // System.out.println(create.getAbsolutePath());

    Project project = new ExcelProjectCreator(input).createProject();
    StopWatch watch = new StopWatch();
    watch.start();//w  w w. ja v  a2 s .co  m
    WriteUtils.writePVForPivot(project, new File(input.getParent(), "hogehoge.tsv"));
    watch.stop();
    System.out.println(watch.getTime() + " ms.");
    watch.reset();

}

From source file:nu.mine.kino.projects.utils.ProjectUtilsTest.java

public void test0(String fileName) throws FileNotFoundException, ProjectException {
    File baseDir = new File("./");
    // String fileName = "project_management_tools";
    String input = fileName + "." + "xls";

    // java.io.InputStream in = null;
    File target = new File(baseDir, input);
    // in = new java.io.FileInputStream(target);

    StopWatch watch = new StopWatch();
    watch.start();//w w w. j a va  2s  . c om
    Project projectOrg = new ExcelProjectCreator(target).createProject();
    watch.stop();
    System.out.println(watch.getTime() + " ms.");
    watch.reset();
    // fail("Not yet implemented");
    File output = ProjectWriter.write(projectOrg, new File(input + ".json"));
    System.out.println(output.getAbsolutePath());

    watch.start();
    // Project projectJ = new JSONProjectCreator(new
    // FileInputStream(output))
    // .createProject();
    // watch.stop();
    // System.out.println(watch.getTime() + " ms.");
    //
    // // projectJ.getProjectStartDate().setTime(new Date().getTime());
    //
    // String expected = JSON.encode(projectOrg);
    // String actual = JSON.encode(projectJ);
    //
    // System.out.println("---------------");
    // System.out.println(expected);
    // System.out.println(actual);
    // System.out.println("---------------");
    // assertEquals(expected, actual);

}

From source file:nu.mine.kino.projects.utils.ProjectUtilsTest.java

public void testDate(String fileName) throws FileNotFoundException, ProjectException {
    File baseDir = new File("./");
    String input = fileName + "." + "xls";
    File target = new File(baseDir, input);

    StopWatch watch = new StopWatch();
    watch.start();//ww  w. java  2  s  . c  o  m
    Project projectOrg = new ExcelProjectCreator(target).createProject();
    watch.stop();
    System.out.println(watch.getTime() + " ms.");
    watch.reset();
    System.out.println(projectOrg.getBaseDate());
    System.out.println(ProjectUtils.nextTradingDate(projectOrg));
    System.out.println(ProjectUtils.nextTradingDate(new Date(), projectOrg));

    sevenDaysLater(projectOrg);
}

From source file:nu.mine.kino.projects.utils.ProjectUtilsTest.java

@Test
public void test() throws FileNotFoundException, ProjectException {
    File baseDir = new File("./");
    String fileName = "project_management_tools";
    String input = fileName + "." + "xls";

    // java.io.InputStream in = null;
    File target = new File(baseDir, input);
    // in = new java.io.FileInputStream(target);

    StopWatch watch = new StopWatch();
    watch.start();//www. j a va 2 s. com
    Project projectOrg = new ExcelProjectCreator(target).createProject();
    watch.stop();
    System.out.println(watch.getTime() + " ms.");
    watch.reset();
    // fail("Not yet implemented");
    File output = ProjectWriter.write(projectOrg, new File(input + ".json"));
    System.out.println(output.getAbsolutePath());

    watch.start();
    Project projectJ = new JSONProjectCreator(new FileInputStream(output)).createProject();
    watch.stop();
    System.out.println(watch.getTime() + " ms.");

    // projectJ.getProjectStartDate().setTime(new Date().getTime());

    String expected = JSON.encode(projectOrg);
    String actual = JSON.encode(projectJ);

    System.out.println("---------------");
    System.out.println(expected);
    System.out.println(actual);
    System.out.println("---------------");
    assertEquals(expected, actual);

}

From source file:nu.mine.kino.projects.utils.ProjectUtilsTest.java

@Test
public void test2() throws FileNotFoundException, ProjectException {
    File baseDir = new File("./");
    String fileName = "project_management_tools";
    String input = fileName + "." + "xls";

    // java.io.InputStream in = null;
    File target = new File(baseDir, input);
    // in = new java.io.FileInputStream(target);

    StopWatch watch = new StopWatch();
    watch.start();/*from   w  w w  . ja  v a 2s  .c  o  m*/
    Project projectOrg = new ExcelProjectCreator(target).createProject();
    watch.stop();
    System.out.println(watch.getTime() + " ms.");
    watch.reset();

    List<PVBean> list = PVCreator.createCurrentList(projectOrg);
    for (PVBean pvBean : list) {
        System.out.println(pvBean);
    }

    Date startDate = projectOrg.getProjectStartDate();
    Date endDate = projectOrg.getProjectEndDate();
    Date cursor = startDate;
    while (cursor.getTime() <= endDate.getTime()) {
        // System.out.println(cursor);
        System.out.println(ProjectUtils.calculateTotalPVOfProject(projectOrg, cursor));
        cursor = DateUtils.addDays(cursor, 1);

    }
}

From source file:org.apache.archiva.indexer.maven.merger.DefaultIndexMerger.java

@Override
public IndexingContext buildMergedIndex(IndexMergerRequest indexMergerRequest) throws IndexMergerException {
    String groupId = indexMergerRequest.getGroupId();

    if (runningGroups.contains(groupId)) {
        log.info("skip build merge remote indexes for id: '{}' as already running", groupId);
        return null;
    }//www. j  ava 2s.  c o m

    runningGroups.add(groupId);

    StopWatch stopWatch = new StopWatch();
    stopWatch.reset();
    stopWatch.start();

    Path mergedIndexDirectory = indexMergerRequest.getMergedIndexDirectory();

    String tempRepoId = mergedIndexDirectory.getFileName().toString();

    try {
        Path indexLocation = mergedIndexDirectory.resolve(indexMergerRequest.getMergedIndexPath());

        List<IndexingContext> members = indexMergerRequest.getRepositoriesIds().stream()
                .map(id -> repositoryRegistry.getRepository(id))
                .filter(repo -> repo.getType().equals(RepositoryType.MAVEN)).map(repo -> {
                    try {
                        return repo.getIndexingContext().getBaseContext(IndexingContext.class);
                    } catch (UnsupportedBaseContextException e) {
                        return null;
                        // Ignore
                    }
                }).filter(Objects::nonNull).collect(Collectors.toList());
        ContextMemberProvider memberProvider = new StaticContextMemberProvider(members);
        IndexingContext mergedCtx = indexer.createMergedIndexingContext(tempRepoId, tempRepoId,
                mergedIndexDirectory.toFile(), indexLocation.toFile(), true, memberProvider);
        mergedCtx.optimize();

        if (indexMergerRequest.isPackIndex()) {
            IndexPackingRequest request = new IndexPackingRequest(mergedCtx, //
                    mergedCtx.acquireIndexSearcher().getIndexReader(), //
                    indexLocation.toFile());
            indexPacker.packIndex(request);
        }

        if (indexMergerRequest.isTemporary()) {
            temporaryGroupIndexes.add(new TemporaryGroupIndex(mergedIndexDirectory, tempRepoId, groupId,
                    indexMergerRequest.getMergedIndexTtl()));
            temporaryContextes.add(mergedCtx);
        }
        stopWatch.stop();
        log.info("merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(),
                stopWatch.getTime());
        return mergedCtx;
    } catch (IOException e) {
        throw new IndexMergerException(e.getMessage(), e);
    } finally {
        runningGroups.remove(groupId);
    }
}

From source file:org.apache.archiva.indexer.merger.DefaultIndexMerger.java

@Override
public IndexingContext buildMergedIndex(IndexMergerRequest indexMergerRequest) throws IndexMergerException {
    String groupId = indexMergerRequest.getGroupId();

    if (runningGroups.contains(groupId)) {
        log.info("skip build merge remote indexes for id: '{}' as already running", groupId);
        return null;
    }/*  w  w  w . ja v a 2  s  . c  om*/

    runningGroups.add(groupId);

    StopWatch stopWatch = new StopWatch();
    stopWatch.reset();
    stopWatch.start();

    File mergedIndexDirectory = indexMergerRequest.getMergedIndexDirectory();

    String tempRepoId = mergedIndexDirectory.getName();

    try {
        File indexLocation = new File(mergedIndexDirectory, indexMergerRequest.getMergedIndexPath());
        IndexingContext indexingContext = indexer.addIndexingContext(tempRepoId, tempRepoId,
                mergedIndexDirectory, indexLocation, null, null, mavenIndexerUtils.getAllIndexCreators());

        for (String repoId : indexMergerRequest.getRepositoriesIds()) {
            IndexingContext idxToMerge = indexer.getIndexingContexts().get(repoId);
            if (idxToMerge != null) {
                indexingContext.merge(idxToMerge.getIndexDirectory());
            }
        }

        indexingContext.optimize();

        if (indexMergerRequest.isPackIndex()) {
            IndexPackingRequest request = new IndexPackingRequest(indexingContext, indexLocation);
            indexPacker.packIndex(request);
        }

        if (indexMergerRequest.isTemporary()) {
            temporaryGroupIndexes.add(new TemporaryGroupIndex(mergedIndexDirectory, tempRepoId, groupId,
                    indexMergerRequest.getMergedIndexTtl()));
        }
        stopWatch.stop();
        log.info("merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(),
                stopWatch.getTime());
        return indexingContext;
    } catch (IOException e) {
        throw new IndexMergerException(e.getMessage(), e);
    } catch (UnsupportedExistingLuceneIndexException e) {
        throw new IndexMergerException(e.getMessage(), e);
    } finally {
        runningGroups.remove(groupId);
    }
}

From source file:org.apache.archiva.redback.rest.services.utils.EnvironmentChecker.java

@Inject
public EnvironmentChecker(ApplicationContext applicationContext) {
    Collection<EnvironmentCheck> checkers = applicationContext.getBeansOfType(EnvironmentCheck.class).values();

    StopWatch stopWatch = new StopWatch();
    stopWatch.reset();
    stopWatch.start();//w  ww. ja va  2  s  .c o  m

    if (checkers != null) {
        List<String> violations = new ArrayList<String>();

        for (EnvironmentCheck check : checkers) {
            check.validateEnvironment(violations);
        }

        if (!violations.isEmpty()) {
            StringBuilder msg = new StringBuilder();
            msg.append("EnvironmentCheck Failure.\n");
            msg.append("======================================================================\n");
            msg.append(" ENVIRONMENT FAILURE !! \n");
            msg.append("\n");

            for (String v : violations) {
                msg.append(v).append("\n");
            }

            msg.append("\n");
            msg.append("======================================================================");
            log.error(msg.toString());
        }
    }

    stopWatch.stop();
    log.info("time to execute all EnvironmentCheck: {} ms", stopWatch.getTime());
}

From source file:org.apache.archiva.redback.role.processor.DefaultRoleModelProcessor.java

@SuppressWarnings("unchecked")
private void processRoles(RedbackRoleModel model) throws RoleManagerException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.reset();
    stopWatch.start();//from   w w  w.  ja va2  s.c o  m
    List<String> sortedGraph;
    try {
        sortedGraph = RoleModelUtils.reverseTopologicalSortedRoleList(model);
    } catch (CycleDetectedException e) {
        throw new RoleManagerException("cycle detected: this should have been caught in validation", e);
    }

    List<Role> allRoles;
    try {
        allRoles = rbacManager.getAllRoles();
    } catch (RbacManagerException e) {
        throw new RoleManagerException(e.getMessage(), e);
    }

    Set<String> allRoleNames = new HashSet<String>(allRoles.size());
    for (Role role : allRoles) {
        allRoleNames.add(role.getName());
    }

    for (String roleId : sortedGraph) {
        ModelRole roleProfile = RoleModelUtils.getModelRole(model, roleId);

        List<Permission> permissions = processPermissions(roleProfile.getPermissions());

        boolean roleExists = allRoleNames.contains(roleProfile.getName());// false;

        /*try
        {
        roleExists = rbacManager.roleExists( roleProfile.getName() );
        }
        catch ( RbacManagerException e )
        {
        throw new RoleManagerException( e.getMessage(), e );
        }*/

        if (!roleExists) {
            try {
                Role role = rbacManager.createRole(roleProfile.getName());
                role.setDescription(roleProfile.getDescription());
                role.setPermanent(roleProfile.isPermanent());
                role.setAssignable(roleProfile.isAssignable());

                // add any permissions associated with this role
                for (Permission permission : permissions) {
                    role.addPermission(permission);
                }

                // add child roles to this role
                if (roleProfile.getChildRoles() != null) {
                    for (String childRoleId : roleProfile.getChildRoles()) {
                        ModelRole childRoleProfile = RoleModelUtils.getModelRole(model, childRoleId);
                        role.addChildRoleName(childRoleProfile.getName());
                    }
                }

                rbacManager.saveRole(role);
                allRoleNames.add(role.getName());

                // add link from parent roles to this new role
                if (roleProfile.getParentRoles() != null) {
                    for (String parentRoleId : roleProfile.getParentRoles()) {
                        ModelRole parentModelRole = RoleModelUtils.getModelRole(model, parentRoleId);
                        Role parentRole = rbacManager.getRole(parentModelRole.getName());
                        parentRole.addChildRoleName(role.getName());
                        rbacManager.saveRole(parentRole);
                        allRoleNames.add(parentRole.getName());
                    }
                }

            } catch (RbacManagerException e) {
                throw new RoleManagerException("error creating role '" + roleProfile.getName() + "'", e);
            }
        } else {
            try {
                Role role = rbacManager.getRole(roleProfile.getName());

                boolean changed = false;
                for (Permission permission : permissions) {
                    if (!role.getPermissions().contains(permission)) {
                        log.info("Adding new permission '{}' to role '{}'", permission.getName(),
                                role.getName());
                        role.addPermission(permission);
                        changed = true;
                    }
                }

                // Copy list to avoid concurrent modification [REDBACK-220]
                List<Permission> oldPermissions = new ArrayList<Permission>(role.getPermissions());
                for (Permission permission : oldPermissions) {
                    if (!permissions.contains(permission)) {
                        log.info("Removing old permission '{}' from role '{}'", permission.getName(),
                                role.getName());
                        role.removePermission(permission);
                        changed = true;
                    }
                }
                if (changed) {
                    rbacManager.saveRole(role);
                    allRoleNames.add(role.getName());
                }
            } catch (RbacManagerException e) {
                throw new RoleManagerException("error updating role '" + roleProfile.getName() + "'", e);
            }
        }
    }
    stopWatch.stop();
    log.info("time to process roles model: {} ms", stopWatch.getTime());
}

From source file:org.apache.archiva.web.startup.SecuritySynchronization.java

private void executeEnvironmentChecks() throws ArchivaException {
    if ((checkers == null) || CollectionUtils.isEmpty(checkers.values())) {
        throw new ArchivaException("Unable to initialize the Redback Security Environment, "
                + "no Environment Check components found.");
    }/*from  w w  w.  j a  va2s  . c  o m*/

    StopWatch stopWatch = new StopWatch();
    stopWatch.reset();
    stopWatch.start();

    List<String> violations = new ArrayList<>();

    for (Entry<String, EnvironmentCheck> entry : checkers.entrySet()) {
        EnvironmentCheck check = entry.getValue();
        List<String> v = new ArrayList<>();
        check.validateEnvironment(v);
        log.info("Environment Check: {} -> {} violation(s)", entry.getKey(), v.size());
        for (String s : v) {
            violations.add("[" + entry.getKey() + "] " + s);
        }
    }

    if (CollectionUtils.isNotEmpty(violations)) {
        StringBuilder msg = new StringBuilder();
        msg.append("EnvironmentCheck Failure.\n");
        msg.append("======================================================================\n");
        msg.append(" ENVIRONMENT FAILURE !! \n");
        msg.append("\n");

        for (String violation : violations) {
            msg.append(violation).append("\n");
        }

        msg.append("\n");
        msg.append("======================================================================");
        log.error(msg.toString());

        throw new ArchivaException("Unable to initialize Redback Security Environment, [" + violations.size()
                + "] violation(s) encountered, See log for details.");
    }

    stopWatch.stop();
    log.info("time to execute all EnvironmentCheck: {} ms", stopWatch.getTime());
}