Skip to content

Commit bb7935b

Browse files
committed
Update to build with new Jenkins POM.
* Fixes release process to use appropriate Maven repository. * Fixes FindBugs warnings found with new default FindBugs invocation. * Fixes Jelly warnings with new default tests.
1 parent efe5c60 commit bb7935b

File tree

6 files changed

+40
-24
lines changed

6 files changed

+40
-24
lines changed

pom.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.jenkins-ci.plugins</groupId>
55
<artifactId>plugin</artifactId>
6-
<version>1.554.1</version>
6+
<version>2.19</version>
77
</parent>
88

99
<artifactId>codedeploy</artifactId>
@@ -16,9 +16,9 @@
1616

1717
<developers>
1818
<developer>
19-
<id>afitzgibbon</id>
20-
<name>Andrew Fitz Gibbon</name>
21-
<email>gibbon@amazon.com</email>
19+
<id>jmcfar</id>
20+
<name>Josh McFarlane</name>
21+
<email>jmcfar@amazon.com</email>
2222
</developer>
2323
</developers>
2424

@@ -45,9 +45,8 @@
4545
</repositories>
4646

4747
<properties>
48-
<jackson.version>2.1.1</jackson.version>
49-
<spring.version>3.0.7.RELEASE</spring.version>
5048
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
49+
<jenkins.version>1.580.3</jenkins.version>
5150
</properties>
5251

5352
<dependencies>
@@ -69,7 +68,6 @@
6968
<plugins>
7069
<plugin>
7170
<artifactId>maven-release-plugin</artifactId>
72-
<version>2.5</version>
7371
</plugin>
7472
<plugin>
7573
<groupId>org.apache.maven.plugins</groupId>

src/main/java/com/amazonaws/codedeploy/AWSClients.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private File createTestFile() throws IOException {
129129
File file = File.createTempFile("codedeploy-jenkins-plugin", ".txt");
130130
file.deleteOnExit();
131131

132-
Writer writer = new OutputStreamWriter(new FileOutputStream(file));
132+
Writer writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
133133
writer.write("");
134134
writer.close();
135135

src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@
5656
import org.kohsuke.stapler.StaplerRequest;
5757

5858
import java.io.File;
59+
import java.io.FileInputStream;
5960
import java.io.FileOutputStream;
60-
import java.io.FileReader;
61+
import java.io.InputStreamReader;
6162
import java.io.IOException;
6263
import java.io.PrintStream;
6364
import java.util.Date;
@@ -78,7 +79,7 @@ public class AWSCodeDeployPublisher extends Publisher {
7879
public static final long DEFAULT_TIMEOUT_SECONDS = 900;
7980
public static final long DEFAULT_POLLING_FREQUENCY_SECONDS = 15;
8081
public static final String ROLE_SESSION_NAME = "jenkins-codedeploy-plugin";
81-
public static final Regions[] AVAILABLE_REGIONS = {Regions.AP_NORTHEAST_1, Regions.AP_SOUTHEAST_1, Regions.AP_SOUTHEAST_2, Regions.EU_WEST_1, Regions.US_EAST_1, Regions.US_WEST_2, Regions.EU_CENTRAL_1, Regions.US_WEST_1, Regions.SA_EAST_1, Regions.AP_NORTHEAST_2, Regions.AP_SOUTH_1};
82+
private static final Regions[] AVAILABLE_REGIONS = {Regions.AP_NORTHEAST_1, Regions.AP_SOUTHEAST_1, Regions.AP_SOUTHEAST_2, Regions.EU_WEST_1, Regions.US_EAST_1, Regions.US_WEST_2, Regions.EU_CENTRAL_1, Regions.US_WEST_1, Regions.SA_EAST_1, Regions.AP_NORTHEAST_2, Regions.AP_SOUTH_1};
8283

8384
private final String s3bucket;
8485
private final String s3prefix;
@@ -190,7 +191,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
190191
return true;
191192
}
192193

193-
AWSClients aws;
194+
final AWSClients aws;
194195
if ("awsAccessKey".equals(credentials)) {
195196
if (StringUtils.isEmpty(this.awsAccessKey) && StringUtils.isEmpty(this.awsSecretKey)) {
196197
aws = AWSClients.fromDefaultCredentialChain(
@@ -220,8 +221,13 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
220221

221222
verifyCodeDeployApplication(aws);
222223

223-
String projectName = build.getProject().getName();
224-
RevisionLocation revisionLocation = zipAndUpload(aws, projectName, getSourceDirectory(build.getWorkspace()));
224+
final String projectName = build.getProject().getName();
225+
final FilePath workspace = build.getWorkspace();
226+
if (workspace == null) {
227+
throw new IllegalArgumentException("No workspace present for the build.");
228+
}
229+
final FilePath sourceDirectory = getSourceDirectory(workspace);
230+
final RevisionLocation revisionLocation = zipAndUpload(aws, projectName, sourceDirectory);
225231

226232
registerRevision(aws, revisionLocation);
227233
if ("onlyRevision".equals(deploymentMethod)){
@@ -296,10 +302,10 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
296302
File versionFile;
297303
versionFile = new File(sourceDirectory + "/" + versionFileName);
298304

299-
FileReader reader = null;
305+
InputStreamReader reader = null;
300306
String version = null;
301307
try {
302-
reader = new FileReader(versionFile);
308+
reader = new InputStreamReader(new FileInputStream(versionFile), "UTF-8");
303309
char[] chars = new char[(int) versionFile.length() -1];
304310
reader.read(chars);
305311
version = new String(chars);
@@ -312,7 +318,10 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
312318

313319
if (version != null){
314320
zipFile = new File("/tmp/" + projectName + "-" + version + ".zip");
315-
zipFile.createNewFile();
321+
final boolean fileCreated = zipFile.createNewFile();
322+
if (!fileCreated) {
323+
logger.println("File already exists, overwriting: " + zipFile.getPath());
324+
}
316325
} else {
317326
zipFile = File.createTempFile(projectName + "-", ".zip");
318327
}
@@ -344,12 +353,15 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
344353

345354
logger.println("Zipping files into " + zipFile.getAbsolutePath());
346355

347-
348-
349-
sourceDirectory.zip(
350-
new FileOutputStream(zipFile),
351-
new DirScanner.Glob(this.includes, this.excludes)
352-
);
356+
FileOutputStream outputStream = new FileOutputStream(zipFile);
357+
try {
358+
sourceDirectory.zip(
359+
outputStream,
360+
new DirScanner.Glob(this.includes, this.excludes)
361+
);
362+
} finally {
363+
outputStream.close();
364+
}
353365

354366
if (prefix.isEmpty()) {
355367
key = zipFile.getName();
@@ -376,7 +388,10 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
376388

377389
return revisionLocation;
378390
} finally {
379-
zipFile.delete();
391+
final boolean deleted = zipFile.delete();
392+
if (!deleted) {
393+
logger.println("Failed to clean up file " + zipFile.getPath());
394+
}
380395
}
381396
}
382397

@@ -531,7 +546,7 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
531546
awsAccessKey = formData.getString("awsAccessKey");
532547
awsSecretKey = formData.getString("awsSecretKey");
533548
proxyHost = formData.getString("proxyHost");
534-
proxyPort = Integer.valueOf(formData.getString("proxyPort"));
549+
proxyPort = Integer.parseInt(formData.getString("proxyPort"));
535550

536551
req.bindJSON(this, formData);
537552
save();

src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/config.jelly

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?jelly escape-by-default='true'?>
12
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
23
<f:entry title="AWS CodeDeploy Application Name" field="applicationName">
34
<f:textbox />

src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/global.jelly

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?jelly escape-by-default='true'?>
12
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
23
<f:section title="AWS CodeDeploy Credentials">
34
<f:description>

src/main/resources/index.jelly

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?jelly escape-by-default='true'?>
12
<div>
23
This plugin provides a "post-build" step for AWS CodeDeploy.
34
</div>

0 commit comments

Comments
 (0)