Skip to content

Commit 31ea90c

Browse files
author
Sean Turner
committed
Deal with FindBugs report
1 parent 9fb8260 commit 31ea90c

File tree

5 files changed

+52
-42
lines changed

5 files changed

+52
-42
lines changed

src/main/java/org/jenkinsci/plugins/artifactdeployer/ArtifactDeployerBuilder.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,21 +179,24 @@ public void onDeleted(AbstractBuild build) {
179179
if (entry.isDeleteRemoteArtifacts()) {
180180
List<ArtifactDeployerVO> listArtifacts = info.get(entry.getUniqueId());
181181
if (listArtifacts != null) {
182-
for (ArtifactDeployerVO vo : listArtifacts) {
183-
FilePath remoteArtifactPath = new FilePath(build.getWorkspace().getChannel(), vo.getRemotePath());
184-
try {
185-
if (remoteArtifactPath.exists()) {
186-
remoteArtifactPath.deleteRecursive();
182+
FilePath workspace = build.getWorkspace();
183+
if (workspace != null) {
184+
for (ArtifactDeployerVO vo : listArtifacts) {
185+
FilePath remoteArtifactPath = new FilePath(workspace.getChannel(), vo.getRemotePath());
186+
try {
187+
if (remoteArtifactPath.exists()) {
188+
remoteArtifactPath.deleteRecursive();
189+
}
190+
191+
if (remoteArtifactPath.getParent().exists() && remoteArtifactPath.getParent().list().size() == 0) {
192+
remoteArtifactPath.getParent().delete();
193+
}
194+
195+
} catch (IOException ioe) {
196+
logger.log(Level.SEVERE, "Error when deleting artifacts.", ioe);
197+
} catch (InterruptedException ie) {
198+
logger.log(Level.SEVERE, "Error when deleting artifacts.", ie);
187199
}
188-
189-
if (remoteArtifactPath.getParent().exists() && remoteArtifactPath.getParent().list().size() == 0) {
190-
remoteArtifactPath.getParent().delete();
191-
}
192-
193-
} catch (IOException ioe) {
194-
logger.log(Level.SEVERE, "Error when deleting artifacts.", ioe);
195-
} catch (InterruptedException ie) {
196-
logger.log(Level.SEVERE, "Error when deleting artifacts.", ie);
197200
}
198201
}
199202
}

src/main/java/org/jenkinsci/plugins/artifactdeployer/ArtifactDeployerEntry.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
*/
3333
public class ArtifactDeployerEntry implements Serializable {
3434

35+
static final long serialVersionUID = 1L;
36+
3537
@Deprecated
3638
@SuppressWarnings("unused")
3739
private transient String id;

src/main/java/org/jenkinsci/plugins/artifactdeployer/ArtifactDeployerPublisher.java

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,17 @@ public boolean perform(hudson.model.AbstractBuild<?, ?> build, hudson.Launcher l
104104

105105
private boolean isPerformDeployment(AbstractBuild build) {
106106
Result result = build.getResult();
107-
if (result == null) {
108-
return true;
109-
}
110107

111108
if (deployEvenBuildFail) {
112109
return true;
113110
}
114111

115-
return build.getResult().isBetterOrEqualTo(Result.UNSTABLE);
112+
if (result == null) {
113+
return true;
114+
}
115+
else {
116+
return result.isBetterOrEqualTo(Result.UNSTABLE);
117+
}
116118
}
117119

118120
private boolean _perform(hudson.model.AbstractBuild<?, ?> build, hudson.Launcher launcher, hudson.model.BuildListener listener) throws java.lang.InterruptedException, java.io.IOException {
@@ -292,26 +294,29 @@ public void onDeleted(AbstractBuild build) {
292294
List<ArtifactDeployerVO> listArtifacts = info.get(entry.getUniqueId());
293295
if (listArtifacts != null) {
294296
for (ArtifactDeployerVO vo : listArtifacts) {
295-
FilePath remoteArtifactPath = new FilePath(build.getWorkspace().getChannel(), vo.getRemotePath());
296-
try {
297-
if (remoteArtifactPath.exists()) {
298-
remoteArtifactPath.deleteRecursive();
299-
}
300-
301-
FilePath parent = remoteArtifactPath.getParent();
302-
boolean rest;
303-
do {
304-
rest = parent.exists() && parent.list().size() == 0;
305-
if (rest) {
306-
parent.delete();
297+
FilePath workspace = build.getWorkspace();
298+
if (workspace != null){
299+
FilePath remoteArtifactPath = new FilePath(workspace.getChannel(), vo.getRemotePath());
300+
try {
301+
if (remoteArtifactPath != null && remoteArtifactPath.exists()) {
302+
remoteArtifactPath.deleteRecursive();
307303
}
308-
parent = parent.getParent();
309-
} while (rest);
310304

311-
} catch (IOException ioe) {
312-
logger.log(Level.SEVERE, "Error when deleting artifacts.", ioe);
313-
} catch (InterruptedException ie) {
314-
logger.log(Level.SEVERE, "Error when deleting artifacts.", ie);
305+
FilePath parent = remoteArtifactPath.getParent();
306+
boolean rest;
307+
do {
308+
rest = parent.exists() && parent.list().size() == 0;
309+
if (rest) {
310+
parent.delete();
311+
}
312+
parent = parent.getParent();
313+
} while (rest);
314+
315+
} catch (IOException ioe) {
316+
logger.log(Level.SEVERE, "Error when deleting artifacts.", ioe);
317+
} catch (InterruptedException ie) {
318+
logger.log(Level.SEVERE, "Error when deleting artifacts.", ie);
319+
}
315320
}
316321
}
317322
}

src/main/java/org/jenkinsci/plugins/artifactdeployer/service/ArtifactDeployerCopy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public List<ArtifactDeployerVO> invoke(File localBasedir, VirtualChannel channel
7070
LocalCopy localCopy = new LocalCopy();
7171
List<File> outputFilesList = localCopy.copyAndGetNumbers(fileSet, flatten, new File(remote));
7272
if (inputFiles != outputFilesList.size()) {
73-
listener.getLogger().println(String.format("[ArtifactDeployer] - All the files have not been deployed. There was %d input files but only %d was copied. Maybe you have to use 'Delete content of remote directory' feature for deleting remote directory before deploying.", inputFiles, outputFilesList.size()));
73+
listener.getLogger().println(String.format("[ArtifactDeployer] - All the files have not been deployed. There were %d input files but only %d were copied. Maybe you need to use the 'Delete content of remote directory' feature for deleting the remote directory before deploying.", inputFiles, outputFilesList.size()));
7474
} else {
7575
listener.getLogger().println(String.format("[ArtifactDeployer] - %d file(s) have been copied from the '%s' to '%s'.", outputFilesList.size(), localBasedir.getPath(), outputFilePath));
7676
}

src/main/java/org/jenkinsci/plugins/artifactdeployer/service/LocalCopy.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ class CopyImpl extends CopyWithPerms {
4242

4343
private final List<File> deployedFiles = new ArrayList<File>();
4444

45-
private int copySize;
45+
//private int copySize;
4646

4747
public CopyImpl() {
4848
setProject(new org.apache.tools.ant.Project());
4949
}
5050

5151
@Override
5252
protected void doFileOperations() {
53-
copySize = super.fileCopyMap.size();
53+
//copySize = super.fileCopyMap.size();
5454
for (Object tabOb : super.fileCopyMap.values()) {
5555
String[] tab = (String[]) tabOb;
5656
for (String f : tab) {
@@ -60,9 +60,9 @@ protected void doFileOperations() {
6060
super.doFileOperations();
6161
}
6262

63-
public int getNumCopied() {
64-
return copySize;
65-
}
63+
//public int getNumCopied() {
64+
// return copySize;
65+
//}
6666

6767
public List<File> getDeployedFiles() {
6868
return deployedFiles;

0 commit comments

Comments
 (0)