|
1 |
| -// snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.] |
2 |
| -// snippet-sourcedescription:[CreateBranch.java demonstrates how to create a branch.] |
3 |
| -// snippet-service:[AWS CodeCommit] |
4 |
| -// snippet-keyword:[Java] |
5 |
| -// snippet-keyword:[AWS CodeCommit] |
6 |
| -// snippet-keyword:[Code Sample] |
7 |
| -// snippet-sourcetype:[full-example] |
8 |
| -// snippet-sourcedate:[2020-09-30] |
9 |
| -// snippet-sourceauthor:[AWS - scmacdon] |
10 |
| - |
11 |
| -/** |
12 |
| - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
13 |
| - * |
14 |
| - * This file is licensed under the Apache License, Version 2.0 (the "License"). |
15 |
| - * You may not use this file except in compliance with the License. A copy of |
16 |
| - * the License is located at |
17 |
| - * |
18 |
| - * http://aws.amazon.com/apache2.0/ |
19 |
| - * |
20 |
| - * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
21 |
| - * CONDITIONS OF ANY KIND, either express or implied. See the License for the |
22 |
| - * specific language governing permissions and limitations under the License. |
23 |
| - * |
24 |
| - */ |
25 |
| -package com.example.commit; |
26 |
| - |
27 |
| -// snippet-start:[codecommit.java2.create_branch.import] |
28 |
| -import software.amazon.awssdk.regions.Region; |
29 |
| -import software.amazon.awssdk.services.codecommit.CodeCommitClient; |
30 |
| -import software.amazon.awssdk.services.codecommit.model.CodeCommitException; |
31 |
| -import software.amazon.awssdk.services.codecommit.model.CreateBranchRequest; |
32 |
| -// snippet-end:[codecommit.java2.create_branch.import] |
33 |
| - |
34 |
| -public class CreateBranch { |
35 |
| - |
36 |
| - public static void main(String[] args) { |
37 |
| - |
38 |
| - final String USAGE = "\n" + |
39 |
| - "Usage:\n" + |
40 |
| - " CreateBranch <repoName> <branchName> <commitId> \n\n" + |
41 |
| - "Where:\n" + |
42 |
| - " repoName - the name of the repository,\n" + |
43 |
| - " branchName - the name of the branch,\n" + |
44 |
| - " commitId - The ID of the commit to point the new branch to \n"; |
45 |
| - |
46 |
| - if (args.length < 3) { |
47 |
| - System.out.println(USAGE); |
48 |
| - System.exit(1); |
49 |
| - } |
50 |
| - |
51 |
| - /* Read the name from command args*/ |
52 |
| - String repoName = args[0]; |
53 |
| - String branchName = args[1]; |
54 |
| - String commitId = args[2]; |
55 |
| - |
56 |
| - Region region = Region.US_EAST_1; |
57 |
| - CodeCommitClient codeCommitClient = CodeCommitClient.builder() |
58 |
| - .region(region) |
59 |
| - .build(); |
60 |
| - |
61 |
| - createSpecificBranch(codeCommitClient, repoName, branchName, commitId); |
62 |
| - } |
63 |
| - |
64 |
| - // snippet-start:[codecommit.java2.create_branch.main] |
65 |
| - public static void createSpecificBranch(CodeCommitClient codeCommitClient, |
66 |
| - String repoName, |
67 |
| - String branchName, |
68 |
| - String commitId) { |
69 |
| - |
70 |
| - try { |
71 |
| - CreateBranchRequest branchRequest = CreateBranchRequest.builder() |
72 |
| - .branchName(branchName) |
73 |
| - .repositoryName(repoName) |
74 |
| - .commitId(commitId) |
75 |
| - .build(); |
76 |
| - |
77 |
| - codeCommitClient.createBranch(branchRequest); |
78 |
| - System.out.println("Branch "+branchName + " was created"); |
79 |
| - |
80 |
| - } catch (CodeCommitException e) { |
81 |
| - System.err.println(e.getMessage()); |
82 |
| - System.exit(1); |
83 |
| - } |
84 |
| - } |
85 |
| - // snippet-end:[codecommit.java2.create_branch.main] |
86 |
| -} |
| 1 | +// snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.] |
| 2 | +// snippet-sourcedescription:[CreateBranch.java demonstrates how to create a branch.] |
| 3 | +//snippet-keyword:[AWS SDK for Java v2] |
| 4 | +//snippet-keyword:[Code Sample] |
| 5 | +// snippet-service:[AWS CodeCommit] |
| 6 | +// snippet-sourcetype:[full-example] |
| 7 | +//snippet-sourcedate:[11/03/2020] |
| 8 | +// snippet-sourceauthor:[AWS - scmacdon] |
| 9 | + |
| 10 | +/* |
| 11 | + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 12 | + SPDX-License-Identifier: Apache-2.0 |
| 13 | +*/ |
| 14 | +package com.example.commit; |
| 15 | + |
| 16 | +// snippet-start:[codecommit.java2.create_branch.import] |
| 17 | +import software.amazon.awssdk.regions.Region; |
| 18 | +import software.amazon.awssdk.services.codecommit.CodeCommitClient; |
| 19 | +import software.amazon.awssdk.services.codecommit.model.CodeCommitException; |
| 20 | +import software.amazon.awssdk.services.codecommit.model.CreateBranchRequest; |
| 21 | +// snippet-end:[codecommit.java2.create_branch.import] |
| 22 | + |
| 23 | +public class CreateBranch { |
| 24 | + |
| 25 | + public static void main(String[] args) { |
| 26 | + |
| 27 | + final String USAGE = "\n" + |
| 28 | + "Usage:\n" + |
| 29 | + " CreateBranch <repoName> <branchName> <commitId> \n\n" + |
| 30 | + "Where:\n" + |
| 31 | + " repoName - the name of the repository.\n" + |
| 32 | + " branchName - the name of the branch.\n" + |
| 33 | + " commitId - The ID of the commit to point the new branch to. \n"; |
| 34 | + |
| 35 | + if (args.length != 3) { |
| 36 | + System.out.println(USAGE); |
| 37 | + System.exit(1); |
| 38 | + } |
| 39 | + |
| 40 | + String repoName = args[0]; |
| 41 | + String branchName = args[1]; |
| 42 | + String commitId = args[2]; |
| 43 | + |
| 44 | + Region region = Region.US_EAST_1; |
| 45 | + CodeCommitClient codeCommitClient = CodeCommitClient.builder() |
| 46 | + .region(region) |
| 47 | + .build(); |
| 48 | + |
| 49 | + createSpecificBranch(codeCommitClient, repoName, branchName, commitId); |
| 50 | + codeCommitClient.close(); |
| 51 | + } |
| 52 | + |
| 53 | + // snippet-start:[codecommit.java2.create_branch.main] |
| 54 | + public static void createSpecificBranch(CodeCommitClient codeCommitClient, |
| 55 | + String repoName, |
| 56 | + String branchName, |
| 57 | + String commitId) { |
| 58 | + |
| 59 | + try { |
| 60 | + CreateBranchRequest branchRequest = CreateBranchRequest.builder() |
| 61 | + .branchName(branchName) |
| 62 | + .repositoryName(repoName) |
| 63 | + .commitId(commitId) |
| 64 | + .build(); |
| 65 | + |
| 66 | + codeCommitClient.createBranch(branchRequest); |
| 67 | + System.out.println("Branch "+branchName + " was created"); |
| 68 | + |
| 69 | + } catch (CodeCommitException e) { |
| 70 | + System.err.println(e.getMessage()); |
| 71 | + System.exit(1); |
| 72 | + } |
| 73 | + } |
| 74 | + // snippet-end:[codecommit.java2.create_branch.main] |
| 75 | +} |
0 commit comments