View Javadoc
1   /*
2    * Copyright (c) 2016 ingenieux Labs
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package br.com.ingenieux.mojo.beanstalk.bundle;
18  
19  import com.amazonaws.AmazonClientException;
20  import com.amazonaws.AmazonServiceException;
21  
22  import org.apache.maven.plugin.MojoExecutionException;
23  import org.apache.maven.plugin.MojoFailureException;
24  import org.apache.maven.plugins.annotations.Mojo;
25  import org.apache.maven.plugins.annotations.Parameter;
26  
27  import java.util.Calendar;
28  import java.util.Date;
29  
30  import br.com.ingenieux.mojo.aws.util.BeanstalkerS3Client;
31  import br.com.ingenieux.mojo.beanstalk.AbstractBeanstalkMojo;
32  
33  /**
34   * Uploads a packed war file to Amazon S3 for further Deployment.
35   *
36   * @since 0.2.7
37   */
38  @Mojo(name = "delete-multiparts")
39  public class DeleteMultipartsMojo extends AbstractBeanstalkMojo {
40  
41    /**
42     * S3 Bucket
43     */
44    @Parameter(property = "beanstalk.s3Bucket", defaultValue = "${project.artifactId}", required = true)
45    String s3Bucket;
46  
47    /**
48     * How many delete to delete? Defaults to 365 days
49     */
50    @Parameter(property = "beanstalk.daysToDelete", defaultValue = "365")
51    Integer daysToDelete;
52  
53    protected Object executeInternal() throws MojoExecutionException, MojoFailureException, AmazonServiceException, AmazonClientException, InterruptedException {
54      BeanstalkerS3Client client = new BeanstalkerS3Client(getAWSCredentials(), getClientConfiguration(), getRegion());
55  
56      Calendar c = Calendar.getInstance();
57  
58      c.add(Calendar.DAY_OF_YEAR, -daysToDelete);
59  
60      Date since = c.getTime();
61  
62      client.deleteMultiparts(s3Bucket, since);
63  
64      return null;
65    }
66  }