Line 1: |
|
|
+ |
This report shows a user an estimate of the artifact disk usage per project. This report has to be used in conjunction with a report template such as the [[HTML Template]].
|
|
|
|
|
|
|
+ |
----
|
|
|
|
|
|
|
+ |
''Meta-Data Script:''
|
|
|
|
|
|
|
+ |
<pre>import com.urbancode.anthill3.domain.reporting.*;
|
|
|
|
|
|
|
+ |
ReportMetaData rmd = new ReportMetaData();
|
|
|
|
|
|
|
|
|
|
|
+ |
SelectParamMetaData sortParam = new SelectParamMetaData();
|
|
|
+ |
String [] sortLabels = new String[3];
|
|
|
+ |
String [] sortValues = new String[3];
|
|
|
+ |
sortLabels[0]="Name";
|
|
|
+ |
sortLabels[1]="Size";
|
|
|
+ |
sortLabels[2]="Type";
|
|
|
+ |
sortValues[0]="0";
|
|
|
+ |
sortValues[1]="1";
|
|
|
+ |
sortValues[2]="2";
|
|
|
|
|
|
|
+ |
sortParam.setLabels(sortLabels);
|
|
|
+ |
sortParam.setValues(sortValues);
|
|
|
+ |
sortParam.setName("sort");
|
|
|
+ |
sortParam.setLabel("Sort");
|
|
|
+ |
sortParam.setDescription("Select the field to sort this report by.");
|
|
|
+ |
rmd.addParameter(sortParam);
|
|
|
|
|
|
|
|
|
|
|
+ |
rmd.addColumn("Project");
|
|
|
+ |
rmd.addColumn("Type");
|
|
|
+ |
rmd.addColumn("TotalSize");
|
|
|
|
|
|
|
+ |
return rmd;
|
|
|
|
|
|
|
|
|
|
|
+ |
</pre>
|
|
|
|
|
|
|
+ |
----
|
|
|
|
|
|
|
+ |
''Context Script:''
|
|
|
|
|
|
|
+ |
<pre>import com.urbancode.anthill3.domain.reporting.*;
|
|
|
+ |
import com.urbancode.anthill3.runtime.paths.CodestationPathHelper;
|
|
|
+ |
import com.urbancode.codestation2.domain.artifacts.*;
|
|
|
+ |
import com.urbancode.codestation2.domain.buildlife.*;
|
|
|
+ |
import com.urbancode.codestation2.domain.project.*;
|
|
|
+ |
import com.urbancode.codestation2.server.CodestationRepositoryFileHelper;
|
|
|
+ |
import com.urbancode.commons.fileutils.FileUtils;
|
|
|
+ |
import com.urbancode.anthill3.domain.project.*;
|
|
|
+ |
import com.urbancode.anthill3.domain.buildlife.*;
|
|
|
+ |
import com.urbancode.devilfish.services.var.VarService;
|
|
|
+ |
import com.urbancode.devilfish.services.file.FileInfo;
|
|
|
+ |
import com.urbancode.commons.util.ObjectUtil;
|
|
|
+ |
import java.util.HashMap;
|
|
|
+ |
import java.util.List;
|
|
|
+ |
import java.util.Map;
|
|
|
+ |
import java.util.Collection;
|
|
|
+ |
import java.util.Comparator;
|
|
|
+ |
import java.io.File;
|
|
|
|
|
|
|
+ |
List mapList = new ArrayList();
|
|
|
+ |
ReportOutput output = new ReportOutput(metaData);
|
|
|
+ |
int sortId=Integer.parseInt(sort);
|
|
|
+ |
System.out.println(sortId);
|
|
|
|
|
|
|
+ |
CodestationRepositoryFileHelper cs = CodestationRepositoryFileHelper.getInstance();
|
|
|
+ |
Project[] projects = ProjectFactory.getInstance().restoreAll();
|
|
|
+ |
for (int p=0; p<projects.length; p++) {
|
|
|
+ |
Map projMap=new HashMap();
|
|
|
+ |
projMap.put("projName", projects[p].getName());
|
|
|
+ |
long Totalsize=0;
|
|
|
+ |
//store name
|
|
|
+ |
BuildLife[] buildLives = BuildLifeFactory.getInstance().restoreAllForProject(projects[p]);
|
|
|
+ |
for (b=0; b<buildLives.length; b++) {
|
|
|
+ |
CodestationCompatableArtifactSet[] sets = cs.getPopulatedBuildLifeArtifactSetList(buildLives[b]);
|
|
|
+ |
for (int s=0; s<sets.length; s++) {
|
|
|
+ |
String rawRepoLifeSetPath = CodestationPathHelper.getInstance().getSetPath(buildLives[b], sets[s]);
|
|
|
+ |
String repoLifeSetPath = VarService.getInstance().resolve(rawRepoLifeSetPath);
|
|
|
+ |
File baseSetDir = new File(repoLifeSetPath);
|
|
|
|
|
|
|
+ |
FileInfo[] files = cs.getBuildLifeArtifactSetFileInfo(buildLives[b], sets[s]);
|
|
|
|
|
|
|
+ |
for (int f=0; f<files.length; f++) {
|
|
|
+ |
if (!".ahs.dig".equals(files[f].getName())) {
|
|
|
+ |
Totalsize+=files[f].length();
|
|
|
+ |
}
|
|
|
+ |
}
|
|
|
|
|
|
|
+ |
}
|
|
|
+ |
}
|
|
|
+ |
//store totalsize
|
|
|
+ |
projMap.put("size", Totalsize);
|
|
|
+ |
projMap.put("Type", "Anthill");
|
|
|
+ |
mapList.add(projMap);
|
|
|
+ |
}
|
|
|
+ |
CodestationCompatableProject[] cprojects = CodestationProjectFactory.getInstance().restoreAllCodestation();
|
|
|
+ |
for (int p=0; p<cprojects.length; p++) {
|
|
|
+ |
Map projMap=new HashMap();
|
|
|
+ |
projMap.put("projName", cprojects[p].getName());
|
|
|
+ |
long Totalsize=0;
|
|
|
+ |
//store name
|
|
|
+ |
CodestationBuildLife[] buildLives = CodestationBuildLifeFactory.getInstance().restoreAllForProject(cprojects[p]);
|
|
|
+ |
for (b=0; b<buildLives.length; b++) {
|
|
|
+ |
CodestationCompatableArtifactSet[] sets = cs.getPopulatedBuildLifeArtifactSetList(buildLives[b]);
|
|
|
+ |
for (int s=0; s<sets.length; s++) {
|
|
|
+ |
String rawRepoLifeSetPath = CodestationPathHelper.getInstance().getSetPath(buildLives[b], sets[s]);
|
|
|
+ |
String repoLifeSetPath = VarService.getInstance().resolve(rawRepoLifeSetPath);
|
|
|
+ |
File baseSetDir = new File(repoLifeSetPath);
|
|
|
|
|
|
|
+ |
FileInfo[] files = cs.getBuildLifeArtifactSetFileInfo(buildLives[b], sets[s]);
|
|
|
|
|
|
|
+ |
for (int f=0; f<files.length; f++) {
|
|
|
+ |
if (!".ahs.dig".equals(files[f].getName())) {
|
|
|
+ |
Totalsize+=files[f].length();
|
|
|
+ |
}
|
|
|
+ |
}
|
|
|
|
|
|
|
+ |
}
|
|
|
+ |
}
|
|
|
+ |
//store totalsize
|
|
|
+ |
projMap.put("size", Totalsize);
|
|
|
+ |
projMap.put("Type", "Codestation");
|
|
|
+ |
mapList.add(projMap);
|
|
|
+ |
}
|
|
|
+ |
//sort here
|
|
|
+ |
Comparator mapComp = new Comparator() {
|
|
|
+ |
public int compare(Object o1, Object o2) {
|
|
|
+ |
Map map1=(Map) o1;
|
|
|
+ |
Map map2=(Map) o2;
|
|
|
+ |
if(sortId==0) {
|
|
|
+ |
return ObjectUtil.compare(map1.get("projName"), map2.get("projName"));
|
|
|
+ |
} else if(sortId==1) {
|
|
|
+ |
return ObjectUtil.compare(map2.get("size"), map1.get("size"));
|
|
|
+ |
} else {
|
|
|
+ |
return ObjectUtil.compare(map1.get("Type"), map2.get("Type"));
|
|
|
+ |
}
|
|
|
+ |
}
|
|
|
+ |
};
|
|
|
|
|
|
|
+ |
Collections.sort(mapList, mapComp);
|
|
|
+ |
for (int p=0; p<mapList.size(); p++) {
|
|
|
+ |
ReportRow row = new ReportRow(output, "1");
|
|
|
+ |
row.setColumnValue("Project", mapList.get(p).get("projName"));
|
|
|
+ |
row.setColumnValue("TotalSize",
|
|
|
+ |
FileUtils.getNearestBytes(mapList.get(p).get("size")));
|
|
|
+ |
row.setColumnValue("Type", mapList.get(p).get("Type"));
|
|
|
+ |
output.addRow(row);
|
|
|
+ |
}
|
|
|
+ |
return output;
|
|
|
|
|
|
|
+ |
</pre>
|
|
|
|
|
|
|
+ |
----
|
|
|
|
|
|
|
+ |
'''Related Content'''
|
|
|
|
|
|
|
+ |
[[AnthillPro Template Reports]]<br/>
|
|
|
+ |
[[Report Templates]]
|