/******************************************************************************* * Copyright (c) 2012 Arapiki Solutions Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * "Peter Smith <psmith@arapiki.com>" - initial API and * implementation and/or initial documentation *******************************************************************************/ package com.buildml.main.commands; import com.buildml.main.CliUtils; import com.buildml.model.IBuildStore; import com.buildml.model.IFileMgr; import com.buildml.model.IPackageMemberMgr; import com.buildml.model.IPackageMemberMgr.PackageDesc; import com.buildml.model.IPackageMgr; import com.buildml.model.IReportMgr; import com.buildml.model.types.FileRecord; /** * BuildML CLI Command class that implements the "show-popular-files" command. * * @author "Peter Smith <psmith@arapiki.com>" */ public class CliCommandShowPopularFiles extends CliCommandShowFiles { /*=====================================================================================* * PUBLIC METHODS *=====================================================================================*/ /* (non-Javadoc) * @see com.buildml.main.commands.CliCommandShowFiles#getLongDescription() */ @Override public String getLongDescription() { return CliUtils.genLocalizedMessage("#include commands/show-popular-files.txt"); } /*-------------------------------------------------------------------------------------*/ /* (non-Javadoc) * @see com.buildml.main.commands.CliCommandShowFiles#getName() */ @Override public String getName() { return "show-popular-files"; } /*-------------------------------------------------------------------------------------*/ /* (non-Javadoc) * @see com.buildml.main.commands.CliCommandShowFiles#getParameterDescription() */ @Override public String getParameterDescription() { return ""; } /*-------------------------------------------------------------------------------------*/ /* (non-Javadoc) * @see com.buildml.main.commands.CliCommandShowFiles#getShortDescription() */ @Override public String getShortDescription() { return "Report on files that are accessed the most often."; } /*-------------------------------------------------------------------------------------*/ /* (non-Javadoc) * @see com.buildml.main.commands.CliCommandShowFiles#invoke(com.buildml.model.BuildStore, java.lang.String[]) */ @Override public void invoke(IBuildStore buildStore, String buildStorePath, String[] args) { CliUtils.validateArgs(getName(), args, 0, 0, "No arguments expected."); IFileMgr fileMgr = buildStore.getFileMgr(); IReportMgr reportMgr = buildStore.getReportMgr(); IPackageMgr pkgMgr = buildStore.getPackageMgr(); IPackageMemberMgr pkgMemberMgr = buildStore.getPackageMemberMgr(); /* fetch the list of most popular files */ FileRecord results[] = reportMgr.reportMostCommonlyAccessedFiles(); /* pretty print the results - only show files if they're in the filter set */ for (FileRecord fileRecord : results) { int id = fileRecord.getId(); if ((filterFileSet == null) || (filterFileSet.isMember(id))){ int count = fileRecord.getCount(); String pathName = fileMgr.getPathName(id, optionShowRoots); /* should we show package names? */ if (optionShowPkgs) { PackageDesc cmptScopeIds = pkgMemberMgr.getPackageOfMember(IPackageMemberMgr.TYPE_FILE, id); String cmptName = pkgMgr.getName(cmptScopeIds.pkgId); String sectName = pkgMemberMgr.getScopeName(cmptScopeIds.pkgScopeId); System.out.println(count + "\t" + pathName + " (" + cmptName + "/" + sectName + ")"); } /* no, just the file names without packages */ else { System.out.println(count + "\t" + pathName); } } } } /*-------------------------------------------------------------------------------------*/ }