Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
AWS Toolkit for Eclipse: v201710260046 Release.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhx committed Oct 26, 2017
1 parent 0095935 commit 7f6ef6d
Show file tree
Hide file tree
Showing 44 changed files with 267 additions and 169 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"current": [
"* Update Java SDK samples."
],
"v201710231659": [
"* Refine the Maven configuration component to have consistent behavior.",
"* Update AWS logo."
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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 com.amazonaws.eclipse.core.util;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import org.eclipse.core.runtime.FileLocator;
import org.osgi.framework.Bundle;

/**
* Utilities for Bundle management.
*/
public class BundleUtils {

/**
* Return the actual file location in the bundle. The bundle could be a regular folder, or a jar file.
*/
public static File getFileFromBundle(Bundle bundle, String... path) throws IOException, URISyntaxException {
URL rootUrl = FileLocator.toFileURL(bundle.getEntry("/"));
URI resolvedUrl = new URI(rootUrl.getProtocol(), rootUrl.getPath(), null);
File file = new File(resolvedUrl);
for (String segment : path) {
file = new File(file, segment);
}
return file;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;

Expand Down Expand Up @@ -47,6 +49,7 @@
import com.amazonaws.eclipse.core.AwsToolkitCore;
import com.amazonaws.eclipse.core.maven.MavenFactory;
import com.amazonaws.eclipse.core.model.MavenConfigurationDataModel;
import com.amazonaws.eclipse.core.util.BundleUtils;
import com.amazonaws.eclipse.core.validator.JavaPackageName;
import com.amazonaws.eclipse.elasticbeanstalk.ElasticBeanstalkPlugin;

Expand Down Expand Up @@ -175,16 +178,19 @@ private void addTemplateFiles(IProject project) throws IOException, CoreExceptio
final String PACKAGE_NAME_PLACEHOLDER = "{PACKAGE_NAME}";

Bundle bundle = ElasticBeanstalkPlugin.getDefault().getBundle();
URL url = FileLocator.resolve(bundle.getEntry("/"));
IPath templateRoot = new Path(url.getFile(), "templates");

File templateRoot = null;
try {
templateRoot = BundleUtils.getFileFromBundle(bundle, "templates");
} catch (URISyntaxException e) {
throw new RuntimeException("Failed to load templates from ElasticBeanstalk bundle.", e);
}
AccountInfo currentAccountInfo = AwsToolkitCore.getDefault().getAccountManager().getAccountInfo(dataModel.getAccountId());
File pomFile = project.getFile("pom.xml").getLocation().toFile();
MavenConfigurationDataModel mavenConfig = dataModel.getMavenConfigurationDataModel();

switch (dataModel.getProjectTemplate()) {
case WORKER:
replacePomFile(templateRoot.append("worker/pom.xml").toFile(),
replacePomFile(new File(templateRoot, "worker/pom.xml"),
mavenConfig.getGroupId(), mavenConfig.getArtifactId(), mavenConfig.getVersion(), pomFile);
String packageName = dataModel.getMavenConfigurationDataModel().getPackageName();

Expand All @@ -194,7 +200,7 @@ private void addTemplateFiles(IProject project) throws IOException, CoreExceptio
location = location.append(component);
}

FileUtils.copyDirectory(templateRoot.append("worker/src").toFile(),
FileUtils.copyDirectory(new File(templateRoot, "worker/src"),
location.toFile());

File workerServlet = location.append("WorkerServlet.java").toFile();
Expand All @@ -205,19 +211,19 @@ private void addTemplateFiles(IProject project) throws IOException, CoreExceptio

location = project.getFile("src/main/webapp").getLocation();
FileUtils.copyDirectory(
templateRoot.append("worker/WebContent/").toFile(),
new File(templateRoot, "worker/WebContent/"),
location.toFile());
File webXml = location.append("WEB-INF/web.xml").toFile();
replaceStringInFile(webXml, PACKAGE_NAME_PLACEHOLDER, packageName);
break;

case DEFAULT:
replacePomFile(templateRoot.append("basic/pom.xml").toFile(),
replacePomFile(new File(templateRoot, "basic/pom.xml"),
mavenConfig.getGroupId(), mavenConfig.getArtifactId(), mavenConfig.getVersion(), pomFile);

location = project.getFile("src/main/webapp").getLocation();
FileUtils.copyDirectory(
templateRoot.append("basic/WebContent").toFile(),
new File(templateRoot, "basic/WebContent"),
location.toFile());

File indexJsp = location.append("index.jsp").toFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public String getInputType() {
}

public void setInputType(String inputType) {
this.setProperty(P_INPUT_TYPE, inputType, this::getInputType, (newValue) -> this.inputType = newValue);
this.selectedBlueprint = getLambdaBlueprint(inputType);
this.setProperty(P_INPUT_TYPE, inputType, this::getInputType, (newValue) -> this.inputType = newValue);
}

public LambdaBlueprint getSelectedBlueprint() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.io.IOException;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.PojoObservables;
import org.eclipse.core.databinding.beans.PojoProperties;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer;
import org.eclipse.jdt.internal.ui.text.SimpleJavaSourceViewerConfiguration;
Expand Down Expand Up @@ -117,7 +117,7 @@ public void createClassNameControl() {
this.classNameComplex = TextComplex.builder()
.composite(inputComposite)
.dataBindingContext(dataBindingContext)
.pojoObservableValue(PojoObservables.observeValue(dataModel, P_CLASS_NAME))
.pojoObservableValue(PojoProperties.value(LambdaFunctionDataModel.class, P_CLASS_NAME).observe(dataModel))
.addValidator(new NotEmptyValidator("Please provide a valid class name for the handler"))
.labelValue("Class Name:")
.defaultValue(dataModel.getClassName())
Expand All @@ -129,7 +129,7 @@ public void createInputTypeControl() {
this.inputTypeComplex = ComboComplex.<LambdaBlueprint> builder()
.composite(inputComposite)
.dataBindingContext(dataBindingContext)
.pojoObservableValue(PojoObservables.observeValue(dataModel, P_INPUT_TYPE))
.pojoObservableValue(PojoProperties.value(LambdaFunctionDataModel.class, P_INPUT_TYPE).observe(dataModel))
.labelValue("Input Type:")
.items(lambdaBlueprintConfig.getBlueprints().values())
.defaultItemName(dataModel.getInputType())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,8 @@
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
import com.amazonaws.services.dynamodbv2.model.AttributeDefinition;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.ComparisonOperator;
Expand Down Expand Up @@ -58,7 +59,7 @@ public class AmazonDynamoDBSample {
* the credentials file in your source directory.
*/

static AmazonDynamoDBClient dynamoDB;
static AmazonDynamoDB dynamoDB;

/**
* The only information needed to create a client are security credentials
Expand All @@ -77,19 +78,20 @@ private static void init() throws Exception {
* credential profile by reading from the credentials file located at
* (~/.aws/credentials).
*/
AWSCredentials credentials = null;
ProfileCredentialsProvider credentialsProvider = new ProfileCredentialsProvider();
try {
credentials = new ProfileCredentialsProvider().getCredentials();
credentialsProvider.getCredentials();
} catch (Exception e) {
throw new AmazonClientException(
"Cannot load the credentials from the credential profiles file. " +
"Please make sure that your credentials file is at the correct " +
"location (~/.aws/credentials), and is in valid format.",
e);
}
dynamoDB = new AmazonDynamoDBClient(credentials);
Region usWest2 = Region.getRegion(Regions.US_WEST_2);
dynamoDB.setRegion(usWest2);
dynamoDB = AmazonDynamoDBClientBuilder.standard()
.withCredentials(credentialsProvider)
.withRegion("us-west-2")
.build();
}

public static void main(String[] args) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand All @@ -21,11 +21,12 @@
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.ec2.AmazonEC2;
import com.amazonaws.services.ec2.AmazonEC2Client;
import com.amazonaws.services.ec2.AmazonEC2ClientBuilder;
import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest;
import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest;
import com.amazonaws.services.ec2.model.CreateSecurityGroupResult;
Expand Down Expand Up @@ -65,9 +66,10 @@ public static void main(String[] args) {
}

// Create the AmazonEC2Client object so we can call various APIs.
AmazonEC2 ec2 = new AmazonEC2Client(credentials);
Region usWest2 = Region.getRegion(Regions.US_WEST_2);
ec2.setRegion(usWest2);
AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion("us-west-2")
.build();

// Create a new security group.
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand All @@ -20,11 +20,12 @@
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.ec2.AmazonEC2;
import com.amazonaws.services.ec2.AmazonEC2Client;
import com.amazonaws.services.ec2.AmazonEC2ClientBuilder;
import com.amazonaws.services.ec2.model.BlockDeviceMapping;
import com.amazonaws.services.ec2.model.CancelSpotInstanceRequestsRequest;
import com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsRequest;
Expand Down Expand Up @@ -94,9 +95,10 @@ public static void main(String[] args) {
}

// Create the AmazonEC2Client object so we can call various APIs.
AmazonEC2 ec2 = new AmazonEC2Client(credentials);
Region usWest2 = Region.getRegion(Regions.US_WEST_2);
ec2.setRegion(usWest2);
AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion("us-west-2")
.build();

// Initializes a Spot Instance Request
RequestSpotInstancesRequest requestRequest = new RequestSpotInstancesRequest();
Expand Down
Loading

0 comments on commit 7f6ef6d

Please sign in to comment.