Skip to content

Commit

Permalink
code format
Browse files Browse the repository at this point in the history
  • Loading branch information
dai0304 committed Jul 14, 2016
1 parent 9f1c8c4 commit 59bb90e
Show file tree
Hide file tree
Showing 91 changed files with 2,292 additions and 1,789 deletions.
15 changes: 0 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ spotless {
customReplaceRegex 'Add space before comment asterisk', '^(\\t*)\\*', '$1 *'
// customReplaceRegex 'Remove indent before line comment', '^\\t*//', '//'
}

// this will create two tasks: spotlessMiscCheck and spotlessMiscApply
format 'misc', {
// target determines which files this format will apply to
// - if you pass a string or a list of strings, they will be treated
// as 'include' parameters to a fileTree in the root directory
// - if you pass a FileCollection, it will pass through untouched
// e.g. project.files('build.gradle', 'settings.gradle')
// - if you pass anything else, it will be sent to project.files(yourArg)
target '**/*.gradle', '**/*.md', '**/.gitignore'

// spotless has built-in rules for the most basic formatting tasks
indentWithTabs() // or spaces. Takes an integer argument if you don't like 4
endWithNewline()
}
}

// ======== create source and javadoc bundles ========
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/jp/classmethod/aws/gradle/AwsPlugin.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2013-2016 Classmethod, Inc.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -18,9 +18,9 @@
import org.gradle.api.Plugin;
import org.gradle.api.Project;


public class AwsPlugin implements Plugin<Project> {



@Override
public void apply(Project project) {
project.getExtensions().create(AwsPluginExtension.NAME, AwsPluginExtension.class, project);
Expand Down
30 changes: 17 additions & 13 deletions src/main/java/jp/classmethod/aws/gradle/AwsPluginExtension.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2013-2016 Classmethod, Inc.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -19,7 +19,6 @@
import java.util.ArrayList;
import java.util.List;

import jp.xet.sparwings.aws.auth.AwsCliConfigProfileCredentialsProvider;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -42,8 +41,11 @@
import com.amazonaws.services.identitymanagement.model.GetUserResult;
import com.google.common.base.Strings;

import jp.xet.sparwings.aws.auth.AwsCliConfigProfileCredentialsProvider;

public class AwsPluginExtension {


public static final String NAME = "aws";

@Getter
Expand All @@ -57,23 +59,24 @@ public class AwsPluginExtension {
@Getter
@Setter
private String region = Regions.US_EAST_1.getName();

@Setter
private String proxyHost;

@Setter
private int proxyPort = -1;

@Setter
private AWSCredentialsProvider credentialsProvider;



public AwsPluginExtension(Project project) {
this.project = project;
}

public AWSCredentialsProvider newCredentialsProvider(String profileName) {
List<AWSCredentialsProvider> providers = new ArrayList<AWSCredentialsProvider>();
if(credentialsProvider != null) {
if (credentialsProvider != null) {
providers.add(credentialsProvider);
}
providers.add(new EnvironmentVariableCredentialsProvider());
Expand All @@ -89,11 +92,12 @@ public AWSCredentialsProvider newCredentialsProvider(String profileName) {
return new AWSCredentialsProviderChain(providers.toArray(new AWSCredentialsProvider[providers.size()]));
}

public <T extends AmazonWebServiceClient>T createClient(Class<T> serviceClass, String profileName) {
public <T extends AmazonWebServiceClient> T createClient(Class<T> serviceClass, String profileName) {
return createClient(serviceClass, profileName, null);
}

public <T extends AmazonWebServiceClient>T createClient(Class<T> serviceClass, String profileName, ClientConfiguration config) {

public <T extends AmazonWebServiceClient> T createClient(Class<T> serviceClass, String profileName,
ClientConfiguration config) {
if (profileName == null) {
if (this.profileName == null) {
throw new IllegalStateException("default profileName is null");
Expand All @@ -112,7 +116,7 @@ public <T extends AmazonWebServiceClient>T createClient(Class<T> serviceClass, S
return createClient(serviceClass, credentialsProvider, config);
}

private static <T extends AmazonWebServiceClient>T createClient(Class<T> serviceClass,
private static <T extends AmazonWebServiceClient> T createClient(Class<T> serviceClass,
AWSCredentialsProvider credentials, ClientConfiguration config) {
Constructor<T> constructor;
T client;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2013-2016 Classmethod, Inc.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -37,25 +37,30 @@
import com.amazonaws.services.cloudformation.model.Parameter;
import com.amazonaws.services.cloudformation.model.Stack;


public class AmazonCloudFormationCreateChangeSetTask extends ConventionTask {

@Getter @Setter

@Getter
@Setter
private String stackName;

@Getter @Setter
@Getter
@Setter
private String cfnTemplateUrl;

@Getter @Setter
@Getter
@Setter
private List<Parameter> cfnStackParams = new ArrayList<>();

@Getter @Setter
@Getter
@Setter
private boolean capabilityIam;

@Getter @Setter
@Getter
@Setter
private List<String> stableStatuses = Arrays.asList(
"CREATE_COMPLETE", "ROLLBACK_COMPLETE", "UPDATE_COMPLETE", "UPDATE_ROLLBACK_COMPLETE"
);
"CREATE_COMPLETE", "ROLLBACK_COMPLETE", "UPDATE_COMPLETE", "UPDATE_ROLLBACK_COMPLETE");


public AmazonCloudFormationCreateChangeSetTask() {
setDescription("Create cfn change set.");
Expand All @@ -69,13 +74,17 @@ public void creatChangeSet() throws InterruptedException {
String cfnTemplateUrl = getCfnTemplateUrl();
List<String> stableStatuses = getStableStatuses();

if (stackName == null) throw new GradleException("stackName is not specified");
if (cfnTemplateUrl == null) throw new GradleException("cfnTemplateUrl is not specified");
if (stackName == null)
throw new GradleException("stackName is not specified");
if (cfnTemplateUrl == null)
throw new GradleException("cfnTemplateUrl is not specified");

AmazonCloudFormationPluginExtension ext = getProject().getExtensions().getByType(AmazonCloudFormationPluginExtension.class);
AmazonCloudFormationPluginExtension ext =
getProject().getExtensions().getByType(AmazonCloudFormationPluginExtension.class);
AmazonCloudFormation cfn = ext.getClient();

DescribeStacksResult describeStackResult = cfn.describeStacks(new DescribeStacksRequest().withStackName(stackName));
DescribeStacksResult describeStackResult =
cfn.describeStacks(new DescribeStacksRequest().withStackName(stackName));
Stack stack = describeStackResult.getStacks().get(0);
if (stableStatuses.contains(stack.getStackStatus())) {
createChangeSet(cfn);
Expand All @@ -94,16 +103,16 @@ private void createChangeSet(AmazonCloudFormation cfn) {
getLogger().info("Create change set '{}' for stack '{}'", changeSetName, stackName);
CreateChangeSetRequest req = new CreateChangeSetRequest()
.withChangeSetName(changeSetName)
.withStackName(stackName)
.withTemplateURL(cfnTemplateUrl)
.withParameters(cfnStackParams);
.withStackName(stackName)
.withTemplateURL(cfnTemplateUrl)
.withParameters(cfnStackParams);
if (isCapabilityIam()) {
req.setCapabilities(Arrays.asList(Capability.CAPABILITY_IAM.toString()));
}
CreateChangeSetResult createChangeSetResult = cfn.createChangeSet(req);
getLogger().info("Create change set requested: {}", createChangeSetResult.getId());
}

private String changeSetName(String stackName) {
return stackName + new SimpleDateFormat("-yyyyMMdd-HHmmss").format(new Date());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2013-2016 Classmethod, Inc.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -25,12 +25,14 @@
import com.amazonaws.services.cloudformation.AmazonCloudFormation;
import com.amazonaws.services.cloudformation.model.DeleteStackRequest;


public class AmazonCloudFormationDeleteStackTask extends ConventionTask {

@Getter @Setter

@Getter
@Setter
private String stackName;


public AmazonCloudFormationDeleteStackTask() {
setDescription("Delete cfn stack.");
setGroup("AWS");
Expand All @@ -40,13 +42,15 @@ public AmazonCloudFormationDeleteStackTask() {
public void deleteStack() {
// to enable conventionMappings feature
String stackName = getStackName();

if (stackName == null) throw new GradleException("stackName is not specified");

AmazonCloudFormationPluginExtension ext = getProject().getExtensions().getByType(AmazonCloudFormationPluginExtension.class);
if (stackName == null)
throw new GradleException("stackName is not specified");

AmazonCloudFormationPluginExtension ext =
getProject().getExtensions().getByType(AmazonCloudFormationPluginExtension.class);
AmazonCloudFormation cfn = ext.getClient();

cfn.deleteStack(new DeleteStackRequest().withStackName(stackName));
getLogger().info("delete stack "+stackName+" requested");
getLogger().info("delete stack " + stackName + " requested");
}
}
Loading

0 comments on commit 59bb90e

Please sign in to comment.