Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactoring #54

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
157ee22
[JENKINS-30586] Fixed alignment of project graph
mkaring Sep 23, 2015
2839dad
Fixed typo Calcualete -> Calculate
petacz Oct 1, 2015
61274bc
Fix URL on images
ejouvin Oct 1, 2015
0bfcd2a
Merge pull request #33 from petacz/fix_typo
lvotypko Oct 12, 2015
05dd253
Merge pull request #34 from ejouvin/master
lvotypko Oct 12, 2015
4855568
Merge pull request #32 from mkaring/master
lvotypko Oct 12, 2015
f0ffb21
JENKINS-30934 - remove dubious Thread.sleep(60000)
thomasgl-orange Oct 13, 2015
8ca492d
Merge pull request #37 from thomasgl-orange/dont-Thread-sleep
lvotypko Oct 16, 2015
1c34d56
Add checking of unused data - not loaded builds and jobs.
lvotypko Nov 2, 2015
9f7e135
Merge branch 'master' of github.com:jenkinsci/disk-usage-plugin
lvotypko Nov 2, 2015
6bb9c07
Give support to Folder plugin.
lvotypko Nov 11, 2015
b6d3e61
Fix broken tests and bug in code.
lvotypko Feb 9, 2016
6a778c0
Fix UI for filtering.
lvotypko Feb 10, 2016
282084e
Add test for issue JENKINS-20176
Sep 4, 2017
5842185
Reproduce issue JENKINS-40728
Sep 5, 2017
e43d1e2
check if workspace of promoted build is assigned to its job.
Sep 5, 2017
1ea3c76
Add check if job workspace contains workspace of its promoted builds.
Sep 5, 2017
178e06f
fix class cast in action too.
Sep 5, 2017
68870cf
Add check for casting in Action too.
Sep 5, 2017
9ccc3e1
Fix issue for action.
Sep 5, 2017
e851c55
fix exception throwing in addProperty
Sep 6, 2017
9284626
fix exception in test.
Sep 6, 2017
04b3ea2
test reproducing issue JENKINS-33219.
Sep 11, 2017
a13fd18
Reproducing issue JENKINS-33219 by test (and neccessary update of jen…
Sep 14, 2017
feda364
fix JENKINS-33219.
Sep 14, 2017
054a25c
Do not write NullPointerException/
Sep 14, 2017
b0fa6b6
Fix problems revealed by test.
Sep 15, 2017
b40c893
use DiskUsageUtil.getDiskUsageProperty() for obtaining property.
Sep 18, 2017
ac64a46
Fix future usage.
Sep 19, 2017
c27bf35
build id can be both in case of old builds - number or time of creation
Sep 19, 2017
c50cdf8
Fix tests.
Sep 20, 2017
e10aa6b
Do not save reference on diskUsage. Obtain it from property.
Sep 21, 2017
2760866
fix creation of executable in test.
Sep 25, 2017
72884e8
Fix incorrectly addition of build information and fix that old versio…
Sep 25, 2017
b6076f9
add jelly files required field.
Sep 25, 2017
d66b02b
fix random failure of test.
Sep 27, 2017
b82fa84
Remove useless outputs created for fixing the tests.
Sep 27, 2017
1864e57
Change settings to allow easilly choose the level of check and have l…
Oct 18, 2017
bcb64f9
Update UI to ne settings.
Oct 24, 2017
8e13e80
keep backward compatibility by keeping old config as CUSTOM typ.
Oct 24, 2017
36a1869
fix loading old configuration
Oct 24, 2017
b58a6b3
Change calculation of build to not load it if exact info about build …
Oct 25, 2017
27b3a67
Add test for new settings and fix bugs.
Oct 25, 2017
2439f2e
Remove duplicate dependency
Oct 25, 2017
160059d
Remove duplicated dependency
Oct 25, 2017
b551574
Add Jenkinsfile
olivergondza Jun 15, 2018
daf049e
Merge pull request #39 from olivergondza/add-jenkinsfile
olivergondza Jun 18, 2018
75382e8
Update pom.xml
lvotypko Aug 30, 2019
308337d
minor refactoring
StefanSpieker Nov 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env groovy

/* `buildPlugin` step provided by: https://github.com/jenkins-infra/pipeline-library */
buildPlugin()
56 changes: 40 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.580.3</version>
</parent>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.29</version>
</parent>

<artifactId>disk-usage</artifactId>
<packaging>hpi</packaging>
<name>Jenkins disk-usage plugin</name>
<version>0.29-SNAPSHOT</version>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Disk+Usage+Plugin</url>

<properties>
<jenkins.version>1.650</jenkins.version>
</properties>

<artifactId>disk-usage</artifactId>
<packaging>hpi</packaging>
<name>Jenkins disk-usage plugin</name>
<version>0.29-SNAPSHOT</version>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Disk+Usage+Plugin</url>

<developers>
<developer>
<id>lvotypko</id>
<name>Lucie Votypkova</name>
</developer>
</developers>
<developers/>

<scm>
<connection>scm:git:git://github.com/jenkinsci/disk-usage-plugin.git</connection>
Expand Down Expand Up @@ -46,6 +46,18 @@
<artifactId>mailer</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.6</version>
<scope>test</scope>
</dependency>
<!-- <dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jobConfigHistory</artifactId>
<version>2.16</version>
<scope>test</scope>
</dependency>-->
<!-- <dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
Expand All @@ -64,6 +76,18 @@
<version>1.4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>promoted-builds</artifactId>
<version>2.28</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.olivergondza.dumpling</groupId>
<artifactId>dumpling</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand Down
124 changes: 88 additions & 36 deletions src/main/java/hudson/plugins/disk_usage/BuildDiskUsageAction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package hudson.plugins.disk_usage;

import hudson.FilePath;
import hudson.XmlFile;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
Expand All @@ -9,12 +11,14 @@
import hudson.model.ProminentProjectAction;
import hudson.model.Run;
import hudson.model.TopLevelItem;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.RunAction2;
import org.apache.commons.io.FileUtils;
import org.kohsuke.stapler.export.ExportedBean;

/**
Expand All @@ -33,14 +37,18 @@ public class BuildDiskUsageAction implements ProminentProjectAction, BuildBadgeA

public BuildDiskUsageAction(AbstractBuild build) {
this.build = build;
DiskUsageProperty property = (DiskUsageProperty) build.getProject().getProperty(DiskUsageProperty.class);
if(property==null){
DiskUsageUtil.addProperty(build.getProject());
property = (DiskUsageProperty) build.getProject().getProperty(DiskUsageProperty.class);
}
DiskUsageBuildInformation information = property.getDiskUsageBuildInformation(build.getId());
}

// DiskUsageProperty property = (DiskUsageProperty) build.getProject().getProperty(DiskUsageProperty.class);
// if(property==null){
// try {
// property = DiskUsageUtil.addProperty(build.getProject());
// }
// catch(Exception e){
// Logger.getLogger(this.getClass().getName()).log(Level.WARNING, null, e);
// }
// }
//DiskUsageBuildInformation information = property.getDiskUsageBuildInformation(build.getId());
}

public String getIconFileName() {
return null;
}
Expand All @@ -53,34 +61,40 @@ public String getUrlName() {
return Messages.UrlName();
}

public void setDiskUsage(Long size) throws IOException{
public void setDiskUsage(Long size) throws Exception{
AbstractProject project = build.getProject();
DiskUsageProperty property = (DiskUsageProperty) project.getProperty(DiskUsageProperty.class);
if(property==null){
DiskUsageUtil.addProperty(project);
property = (DiskUsageProperty) project.getProperty(DiskUsageProperty.class);
}
DiskUsageProperty property = DiskUsageUtil.getDiskUsageProperty(project);
DiskUsageBuildInformation information = property.getDiskUsageBuildInformation(build.getId());
if(information==null){
information = property.getDiskUsageBuildInformation(build.getNumber());
}
if(information!=null){
information.setSize(size);
}
else{
property.getDiskUsage().addBuildInformation(new DiskUsageBuildInformation(build.getId(), build.getTimeInMillis(), build.getNumber(), size), build);
property.getDiskUsage().addBuildInformation(new DiskUsageBuildInformation(build.getId(), build.getTimeInMillis(), build.getNumber(), size, build.isKeepLog()), build);
}
property.saveDiskUsage();
ProjectDiskUsageAction action = project.getAction(ProjectDiskUsageAction.class);
if(action!=null){
action.actualizeCashedBuildsData();
}
}

/**
* @return Disk usage of the build (included child builds)
*/
public Long getDiskUsage() {
AbstractProject project = build.getProject();
DiskUsageProperty property = (DiskUsageProperty) project.getProperty(DiskUsageProperty.class);
if(property==null){
DiskUsageUtil.addProperty(project);
property = (DiskUsageProperty) project.getProperty(DiskUsageProperty.class);
DiskUsageProperty property = DiskUsageUtil.getDiskUsageProperty(project);
Long size = property.getDiskUsageOfBuild(build.getId());
if(size==null || !(size>0)) {
size = property.getDiskUsageOfBuild(build.getNumber());
}
if(size==null || !(size>0)) {
size = property.getDiskUsageOfBuild(String.valueOf(build.getNumber()));
}
return property.getDiskUsageOfBuild(build.getId());
return size;
}

public Long getAllDiskUsage(){
Expand All @@ -105,11 +119,7 @@ private Long getBuildsDiskUsageAllSubItems(ItemGroup group){
else{
if(item instanceof AbstractProject){
AbstractProject project = (AbstractProject) item;
DiskUsageProperty property = (DiskUsageProperty) project.getProperty(DiskUsageProperty.class);
if(property==null){
DiskUsageUtil.addProperty(project);
property = (DiskUsageProperty) project.getProperty(DiskUsageProperty.class);
}
DiskUsageProperty property = DiskUsageUtil.getDiskUsageProperty(project);
Set<DiskUsageBuildInformation> informations = property.getDiskUsageOfBuilds();
for(DiskUsageBuildInformation information : informations){
if(information.getNumber() == build.getNumber()){
Expand All @@ -128,10 +138,27 @@ public Object readResolve() {
buildDiskUsage = diskUsage.buildUsage;
Node node = build.getBuiltOn();
if(node!=null && diskUsage.wsUsage!=null && diskUsage.wsUsage > 0){
DiskUsageProperty property = (DiskUsageProperty) build.getProject().getProperty(DiskUsageProperty.class);
DiskUsageProperty property = DiskUsageUtil.getDiskUsageProperty(build.getProject());
AbstractProject project = build.getProject().getRootProject();
if(property!=null && (project instanceof TopLevelItem))
property.putSlaveWorkspaceSize(node, node.getWorkspaceFor((TopLevelItem)project).getRemote(), diskUsage.wsUsage);
if(property!=null && (project instanceof TopLevelItem)){
FilePath workspace = build.getWorkspace();
if(workspace==null){
workspace = node.getWorkspaceFor((TopLevelItem)project);
}
Map<String,Long> paths = property.getSlaveWorkspaceUsage().get(node.getDisplayName());
Long size = null;
if(paths!=null){
size = paths.get(workspace.getRemote());
}
try {
//previous data about workspace was quite tricky, so check if there is such workspace and size were not recounted
if(workspace.exists() && size!=null && size>0){
property.putSlaveWorkspaceSize(node, node.getWorkspaceFor((TopLevelItem)project).getRemote(), diskUsage.wsUsage);
}
} catch (IOException | InterruptedException ex) {
Logger.getLogger(BuildDiskUsageAction.class.getName()).log(Level.WARNING, null, ex);
}
}
}
diskUsage=null;
}
Expand All @@ -145,34 +172,59 @@ public void onAttached(Run<?, ?> r) {

@Override
public void onLoad(Run<?, ?> r) {
DiskUsageProperty property = (DiskUsageProperty) build.getProject().getProperty(DiskUsageProperty.class);
DiskUsageProperty property = DiskUsageUtil.getDiskUsageProperty(build.getProject());
long size = 0L;
if(buildDiskUsage != null){
size = buildDiskUsage;
}
if(property==null){
return;
}
//backward compatibility
BuildDiskUsageAction action = null;
for(Action a : build.getActions()){

if(a instanceof BuildDiskUsageAction){
action = (BuildDiskUsageAction) a;
if(action.buildDiskUsage != null){

size=action.buildDiskUsage;
}
}
}
if(action!=null){
//remove old action, now it is added by transition action factory
DiskUsageBuildInformation information = property.getDiskUsageBuildInformation(build.getNumber());
//Transient actions can be created even during deletion of job
Boolean isLocked = DiskUsageUtil.isKeepLog(build);
if(information==null && build.getRootDir().exists()){
if(isLocked==null){
isLocked=false;
}
property.getDiskUsage().addBuildInformation(new DiskUsageBuildInformation(build.getId(),build.getTimeInMillis(), build.getNumber(), size, isLocked), build);
}
else{
if(information!=null && !(build.getProject() instanceof ItemGroup)){
//check if lock is still valide
//not for ItemGroup, because MatrixProject causes recursion

if(isLocked!=null && information.isLocked()!= isLocked){
information.setLockState(isLocked);
property.getDiskUsage().save();
}
}

}

if(action!=null || buildDiskUsage!=null){
property.getDiskUsageBuildInformation(build.getNumber()).setSize(buildDiskUsage);
buildDiskUsage=null;
//remove old action, now it is added by transition action factor
build.getActions().remove(action);
try {
build.save();
} catch (IOException ex) {
Logger.getLogger(BuildDiskUsageAction.class.getName()).log(Level.SEVERE, null, ex);
}
}
//Transient actions can be created even during deletion of job
if(property.getDiskUsageBuildInformation(build.getNumber())==null && build.getRootDir().exists()){
property.getDiskUsage().addBuildInformation(new DiskUsageBuildInformation(build.getId(),build.getTimeInMillis(), build.getNumber(), size), build);
}
}

}
Loading