Skip to content

Commit

Permalink
Added formatting conventions and reformatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
Francis Upton IV committed Aug 17, 2015
1 parent 64bcd65 commit 85e9152
Show file tree
Hide file tree
Showing 54 changed files with 1,729 additions and 1,453 deletions.
8 changes: 8 additions & 0 deletions README_ECLIPSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The EC2 plugin formatting conventions are codified in the ec2FormallingEclipse.xml file
which can be imported into Eclipse as a code formatting convention.

This formatting convention follows rules that much of Jenkins seems to follow so there was minimal
code distruption when the conventions where applied.

17 Aug 2015
Francis Upton IV
295 changes: 295 additions & 0 deletions ec2FormattingEclipse.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/ec2/AMITypeData.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import hudson.model.AbstractDescribableImpl;

public abstract class AMITypeData extends AbstractDescribableImpl<AMITypeData>
{
public abstract class AMITypeData extends AbstractDescribableImpl<AMITypeData> {
public abstract boolean isWindows();

public abstract boolean isUnix();
}
85 changes: 38 additions & 47 deletions src/main/java/hudson/plugins/ec2/AmazonEC2Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class AmazonEC2Cloud extends EC2Cloud {
// Used when running unit tests
public static boolean testMode;


@DataBoundConstructor
public AmazonEC2Cloud(String cloudName, boolean useInstanceProfileForCredentials, String accessId, String secretKey, String region, String privateKey, String instanceCapStr, List<? extends SlaveTemplate> templates) {
super(createCloudId(cloudName), useInstanceProfileForCredentials, accessId, secretKey, privateKey, instanceCapStr, templates);
Expand All @@ -91,44 +90,44 @@ public String getRegion() {
// Handles pre 1.14 region names that used the old AwsRegion enum, note we don't change
// the region here to keep the meta-data compatible in the case of a downgrade (is that right?)
if (region.indexOf('_') > 0)
return region.replace('_', '-').toLowerCase(Locale.ENGLISH);
return region.replace('_', '-').toLowerCase(Locale.ENGLISH);
return region;
}

public static URL getEc2EndpointUrl(String region) {
try {
return new URL("https://" + region + "." + EC2_URL_HOST + "/");
} catch (MalformedURLException e) {
throw new Error(e); // Impossible
}
return new URL("https://" + region + "." + EC2_URL_HOST + "/");
} catch (MalformedURLException e) {
throw new Error(e); // Impossible
}
}

@Override
public URL getEc2EndpointUrl() {
return getEc2EndpointUrl(getRegion());
return getEc2EndpointUrl(getRegion());
}

@Override
public URL getS3EndpointUrl() {
try {
return new URL("https://"+getRegion()+".s3.amazonaws.com/");
} catch (MalformedURLException e) {
throw new Error(e); // Impossible
}
return new URL("https://" + getRegion() + ".s3.amazonaws.com/");
} catch (MalformedURLException e) {
throw new Error(e); // Impossible
}
}

@Extension
public static class DescriptorImpl extends EC2Cloud.DescriptorImpl {

@Override
public String getDisplayName() {
public String getDisplayName() {
return "Amazon EC2";
}

public FormValidation doCheckCloudName(@QueryParameter String value) {
try {
Jenkins.checkGoodName(value);
} catch (Failure e){
} catch (Failure e) {
return FormValidation.error(e.getMessage());
}

Expand All @@ -139,40 +138,35 @@ public FormValidation doCheckCloudName(@QueryParameter String value) {
found++;
}
}
if (found>1) {
if (found > 1) {
return FormValidation.error(Messages.AmazonEC2Cloud_NonUniqName());
}
return FormValidation.ok();
}

public ListBoxModel doFillRegionItems(@QueryParameter boolean useInstanceProfileForCredentials,
@QueryParameter String accessId, @QueryParameter String secretKey,
@QueryParameter String region) throws IOException, ServletException {
ListBoxModel model = new ListBoxModel();
if (testMode) {
model.add(DEFAULT_EC2_HOST);
return model;
}

if (useInstanceProfileForCredentials || (!StringUtils.isEmpty(accessId) && !StringUtils.isEmpty(secretKey))) {
AWSCredentialsProvider credentialsProvider = createCredentialsProvider(useInstanceProfileForCredentials, accessId, secretKey);
AmazonEC2 client = connect(credentialsProvider, new URL("http://ec2.amazonaws.com"));
DescribeRegionsResult regions = client.describeRegions();
List<Region> regionList = regions.getRegions();
for (Region r : regionList) {
String name = r.getRegionName();
model.add(name, name);
}
}
return model;
}

public FormValidation doTestConnection(
@QueryParameter String region,
@QueryParameter boolean useInstanceProfileForCredentials,
@QueryParameter String accessId,
@QueryParameter String secretKey,
@QueryParameter String privateKey) throws IOException, ServletException {
public ListBoxModel doFillRegionItems(@QueryParameter boolean useInstanceProfileForCredentials, @QueryParameter String accessId, @QueryParameter String secretKey, @QueryParameter String region)
throws IOException, ServletException {
ListBoxModel model = new ListBoxModel();
if (testMode) {
model.add(DEFAULT_EC2_HOST);
return model;
}

if (useInstanceProfileForCredentials || (!StringUtils.isEmpty(accessId) && !StringUtils.isEmpty(secretKey))) {
AWSCredentialsProvider credentialsProvider = createCredentialsProvider(useInstanceProfileForCredentials, accessId, secretKey);
AmazonEC2 client = connect(credentialsProvider, new URL("http://ec2.amazonaws.com"));
DescribeRegionsResult regions = client.describeRegions();
List<Region> regionList = regions.getRegions();
for (Region r : regionList) {
String name = r.getRegionName();
model.add(name, name);
}
}
return model;
}

public FormValidation doTestConnection(@QueryParameter String region, @QueryParameter boolean useInstanceProfileForCredentials, @QueryParameter String accessId, @QueryParameter String secretKey, @QueryParameter String privateKey)
throws IOException, ServletException {

if (Util.fixEmpty(region) == null) {
region = DEFAULT_EC2_HOST;
Expand All @@ -181,11 +175,8 @@ public FormValidation doTestConnection(
return super.doTestConnection(getEc2EndpointUrl(region), useInstanceProfileForCredentials, accessId, secretKey, privateKey);
}

public FormValidation doGenerateKey(StaplerResponse rsp,
@QueryParameter String region,
@QueryParameter boolean useInstanceProfileForCredentials,
@QueryParameter String accessId,
@QueryParameter String secretKey) throws IOException, ServletException {
public FormValidation doGenerateKey(StaplerResponse rsp, @QueryParameter String region, @QueryParameter boolean useInstanceProfileForCredentials, @QueryParameter String accessId, @QueryParameter String secretKey)
throws IOException, ServletException {
return super.doGenerateKey(rsp, getEc2EndpointUrl(region), useInstanceProfileForCredentials, accessId, secretKey);
}
}
Expand Down
Loading

0 comments on commit 85e9152

Please sign in to comment.