[JAWS-UG CLI] CodeBuild: # 1 Creating Source Code (Java)

Reference: http://docs.aws.amazon.com/codebuild/latest/userguide/getting-started.html

Prerequisites

--The git command can be executed.

  1. Preparation =======

nothing special

  1. Pre-work ===========

1.1. Specifying a working directory

bash:Variable setting:


DIR_WORK="${HOME}/src-codebuild-demo-java"

1.2. Creating and moving working directories

bash:command:


mkdir -p ${DIR_WORK}/src/{main,test}/java \
        && cd ${DIR_WORK}/
  1. Source code creation =====================

2.1. Creating the main program

bash:command:


FILE_INPUT='src/main/java/MessageUtil.java'

bash:command:


cat << EOF > ${FILE_INPUT}
public class MessageUtil {
  private String message;

  public MessageUtil(String message) {
    this.message = message;
  }

  public String printMessage() {
    System.out.println(message);
    return message;
  }

  public String salutationMessage() {
    message = "Hi!" + message;
    System.out.println(message);
    return message;
  }
}
EOF

cat ${FILE_INPUT}

2.2. Writing test code

bash:command:


FILE_INPUT='src/test/java/TestMessageUtil.java'

bash:command:


cat << EOF > ${FILE_INPUT}
import org.junit.Test;
import org.junit.Ignore;
import static org.junit.Assert.assertEquals;

public class TestMessageUtil {

  String message = "Robert";
  MessageUtil messageUtil = new MessageUtil(message);

  @Test
  public void testPrintMessage() {
    System.out.println("Inside testPrintMessage()");
    assertEquals(message,messageUtil.printMessage());
  }

  @Test
  public void testSalutationMessage() {
    System.out.println("Inside testSalutationMessage()");
    message = "Hi!" + "Robert";
    assertEquals(message,messageUtil.salutationMessage());
  }
}
EOF

cat ${FILE_INPUT}

2.3. Creating configuration information for Moven

bash:command:


FILE_INPUT='pom.xml'

bash:command:


cat << EOF > ${FILE_INPUT}
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example</groupId>
  <artifactId>messageUtil</artifactId>
  <version>1.0</version>
  <packaging>jar</packaging>
  <name>Message Utility Java Sample App</name>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>
EOF

cat ${FILE_INPUT}

bash:command:


xmllint --noout ${FILE_INPUT}

If nothing is displayed, it's OK.

  1. Post-work ===========

3.1. Creating a repository

bash:command:


git init

3.2. Specifying an email address

bash:Variable setting:


GIT_ADDR='<mail address>'

bash:command:


git config --global user.email "${GIT_ADDR}"

3.3. Specifying the user name

bash:Variable setting:


GIT_NAME='Your Name'

bash:command:


git config --global user.name "${GIT_NAME}"

3.4. Add to repository

bash:command:


git add .

3.5. First commit

bash:command:


git commit -m 'created repository.'

bash:command:


git log

Result (example):

  commit 95d8522773831827702fe9841aff4c33acb7f514
  Author: Your Name <[email protected]>
  Date:   Sun Apr 17 12:38:37 2017 +0000

      created repository.

Done

Recommended Posts

[JAWS-UG CLI] CodeBuild: # 1 Creating Source Code (Java)
[JAWS-UG CLI] CodeBuild: # 3 Creating buildspec (Java)
Java source code reading java.lang.Math class
Basic structure of Java source code
[Java] Flow from source code to execution
Script Java code
Java code TIPS
Technology for reading Java source code in Eclipse
Java sample code 02
Java sample code 03
Java sample code 04
Java sample code 01
Java character code
Comments in Java source
java (split source file)
Eval Java source from Java
Read Java HashMap source
How to decompile apk file to java source code with MAC