forked from classmethod/gradle-aws-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// -*- coding: utf-8; mode: groovy -*- | ||
|
||
import groovy.json.JsonOutput | ||
import jp.classmethod.aws.gradle.sns.AmazonSNSPublishMessageTask; | ||
|
||
buildscript { | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
maven { url "https://plugins.gradle.org/m2/" } | ||
|
||
} | ||
dependencies { | ||
classpath "jp.classmethod.aws:gradle-aws-plugin:0.+" | ||
} | ||
} | ||
|
||
apply plugin: "jp.classmethod.aws.sns" | ||
|
||
task publishMessage(type: AmazonSNSPublishMessageTask) { | ||
topicArn 'arn:aws:sns:us-east-1:000000000000:gradle-aws-plugin-sns-topic' | ||
message 'Test body' | ||
subject 'Optional test subject' | ||
} | ||
|
||
task publishJsonMessage(type: AmazonSNSPublishMessageTask) { | ||
topicArn 'arn:aws:sns:us-east-1:000000000000:gradle-aws-plugin-sns-topic' | ||
message JsonOutput.toJson(['default': 'Default message body.', | ||
'email' : 'Email message body.', | ||
'sms': 'SMS message body.']) | ||
messageStructure 'json' | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/jp/classmethod/aws/gradle/sns/AmazonSNSPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package jp.classmethod.aws.gradle.sns; | ||
|
||
import jp.classmethod.aws.gradle.AwsPlugin; | ||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
|
||
public class AmazonSNSPlugin implements Plugin<Project> { | ||
|
||
public void apply(Project project) { | ||
project.getPluginManager().apply(AwsPlugin.class); | ||
project.getExtensions().create(AmazonSNSPluginExtension.NAME, AmazonSNSPluginExtension.class, project); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/jp/classmethod/aws/gradle/sns/AmazonSNSPluginExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package jp.classmethod.aws.gradle.sns; | ||
|
||
import com.amazonaws.services.sns.AmazonSNSClient; | ||
import jp.classmethod.aws.gradle.common.BaseRegionAwarePluginExtension; | ||
import org.gradle.api.Project; | ||
|
||
public class AmazonSNSPluginExtension extends BaseRegionAwarePluginExtension<AmazonSNSClient> { | ||
|
||
public static final String NAME = "sns"; | ||
|
||
public AmazonSNSPluginExtension(Project project) { | ||
super(project, AmazonSNSClient.class); | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/jp/classmethod/aws/gradle/sns/AmazonSNSPublishMessageTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package jp.classmethod.aws.gradle.sns; | ||
|
||
import com.amazonaws.services.sns.AmazonSNS; | ||
import com.amazonaws.services.sns.model.PublishRequest; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.gradle.api.GradleException; | ||
import org.gradle.api.internal.ConventionTask; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
public class AmazonSNSPublishMessageTask extends ConventionTask { | ||
|
||
@Getter @Setter | ||
private String topicArn; | ||
|
||
@Getter @Setter | ||
private String message; | ||
|
||
@Getter @Setter | ||
private String subject; | ||
|
||
@Getter @Setter | ||
private String messageStructure; | ||
|
||
public AmazonSNSPublishMessageTask() { | ||
setDescription("Publish message to SNS"); | ||
setGroup("AWS"); | ||
} | ||
|
||
@TaskAction | ||
public void publishMessage() { | ||
String topicArn = getTopicArn(); | ||
String message = getMessage(); | ||
String subject = getSubject(); | ||
String messageStructure = getMessageStructure(); | ||
|
||
if (topicArn == null) throw new GradleException("Must specify SNS topicArn"); | ||
if (message == null) throw new GradleException("Must provide message to send to SNS"); | ||
|
||
AmazonSNSPluginExtension ext = getProject().getExtensions().getByType(AmazonSNSPluginExtension.class); | ||
AmazonSNS sns = ext.getClient(); | ||
|
||
PublishRequest request = new PublishRequest().withTopicArn(topicArn).withMessage(message); | ||
if (subject != null) { | ||
request.setSubject(subject); | ||
} | ||
if (messageStructure != null) { | ||
request.setMessageStructure(messageStructure); | ||
} | ||
sns.publish(request); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/resources/META-INF/gradle-plugins/jp.classmethod.aws.sns.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# 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. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
implementation-class=jp.classmethod.aws.gradle.sns.AmazonSNSPlugin |