ローカルリポジトリを最新版にして、プッシュするまでの流れ

まずはmasterブランチを最新の状態にする

masterに移動

git checkout master


upstream(fork元)から最新のものを取ってくる

git fetch upstream


fetchしたものをローカルのmasterに反映させる(ローカルのmasterを最新にする)

git rebase upstream/master


最新にしたmasterをプッシュしておく

git push origin master



作業ブランチのコミットを1つにまとめてから最新にする

作業ブランチへ移動

git checkout 作業してるブランチ名


作業中のものを避ける

git stash


masterと差分のコミットを一つにまとめる

git rebase -i master


すると、こんな感じのが出てくる

pick ai9j38h 新機能追加
pick onw832h 修正
pick ji8h84h エラー修正

# Rebase bdd3996..bd66e17 onto bdd3996
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#


iを押してINSERTモードにして二つ目以降のコミットのpicksquashへ変更する

pick ai9j38h 新機能追加
squash onw832h 修正
squash ji8h84h エラー修正

# Rebase bdd3996..bd66e17 onto bdd3996
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

escを押して、:wqで保存する


作業してるブランチを最新にする

git rebase master 作業してるブランチ名


コンフリクトしたら、奴らと戦う


最新にした作業ブランチをプッシュ

git push origin 作業してるブランチ名




参考:GitHubへpull requestする際のベストプラクティス - hnwの日記

Git 開発を始める

gitの初期化

git init



gitignoreファイル作成

vim .gitignore

.gitignoreの中身

build/
.classpath
.gradle/
.project
.settings/
bin/



リモートリポジトリにリポジトリを作る

git clone URL



リモートリポジトリを追加する

fork元

git remote add upstream fork元のURL

fork先(自分)

git remote add origin fork先のURL

リモートリポジトリの詳細一覧見る

git remote -v

Java Gradle マルチプロジェクト作成方法

プロジェクト構成
multi-sample
+--- sample-common
+--- sample-core (sample-commonに依存)



  • まずEclipsesample-commonsample-coreのGradle(STS)のプロジェクト作成



  • multi-sampleの直下でGradleによるプロジェクト初期化
gradle init



  • settings.gradleを編集
rootProject.name = 'multi-sample'
include "sample-common", "sample-core"



  • build.gradleを編集
subprojects {
    apply plugin: 'eclipse'
    apply plugin: 'java'
    apply plugin: 'idea'

    def defaultEncoding = 'UTF-8'
    tasks.withType(JavaCompile) {
        options.encoding = defaultEncoding
    }

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    project.ext {
      authorName = 'YOUR NAME'
      dropwizardVersion = 'バージョン'
    }

    repositories {
        mavenCentral()
    }

    dependencies {
        compile "io.dropwizard:dropwizard-core:${dropwizardVersion}"
    }

    version = '1.0'

    task wrapper(type: Wrapper) {
      gradleVersion = '2.14'
    }
}

project(':sample-common') {
}

project(':sample-core') {
    dependencies {
        compile project(':sample-common')
    }
}



  • gradle eclipseを叩く




参照:GradleによるJavaプロジェクトのビルド

Java デザインパターンとは

デザインパターン

よく使われる設計をパターン化したもの。


メリット

  • プログラムの再利用がしやすくなる

  • コードが読みやすくなる


有名なのがGoFデザインパターン
GoFには23個のデザインパターンがある。



Builderパターン

様々なオブジェクトを作るためのパターン。
ビルダクラス・ディレクタクラスの2つを用意する。


ビルダクラス:様々なオブジェクトを生成するためメソッドを提供する。
ディレクタクラス:複数のビルダクラスをまとめて管理するクラス。



参照:GoFの23のデザインパターンを,Javaで活用するための一覧表 (パターンごとの要約コメント付き) - 主に言語とシステム開発に関して

git rebase・squash

rebase

今までのコミットしてきたものの上にmasterのコミットをポンっと置くイメージ。
rebaseするときは一旦新たにブランチを切ってから行うべし。



squash

コミットを一つにまとめる


squashの流れ

コマンドでコミットのログを見る
git log --oneline

を叩くと、

nanako:gtest nanako$ git log --oneline
a0de58f last commit
1574f49 sample3
17a75e7 sample2
6b45ec9 sample1
791c07e first commit
sample1、sample2、sample3をcommit allとしてコミットをまとめるとすると、
git rebase -i 791c07e

を叩くと、下のものが出てくる。

pick 6b45ec9 sample1
pick 17a75e7 sample2
pick 1574f49 sample3
pick a0de58f last commit
sample2とsample3のpickの部分をsに変更して上書き保存。
コミットのメッセージが表示されるので、first commit's message isに描かれているsample1を消して、commit allと書いて上書き保存。
再度コミットのログを確認
git log --oneline
a0de58f last commit
84yeu43 commit all
791c07e first commit

Java パラメーターの種類

@FormParam

<form>
    <input name = "email">
    <input name = "password">

    <input type = "submit">
</form>


emailpasswordの部分にあたるものがパラメーターとして送られてくる。



@QueryParam

ブラウザから送るURLにある?以降がパラメーターになる。
ex) http://xxxx.com/hoge?email=hoge@xxx.jp&password=“pass”



@PathParam

URLが下記の時、
ex) http://xxxx.com/hoge/1

APIの方で指定しているresource
/hoge/{ id }の部分と対応していて、パラメーターはid = 1になる。

.ymlにあるhttpClientとは

そもそもHTTPとは

WebクライアントとWebサーバーの送受信において使われる取り決めのこと。
リクエスト・レスポンスのルール。


Webアクセスの流れ
  1. ユーザーがURLを入力する

  2. HTTPリクエストが、サーバーに送られる

  3. サーバーがHTTPリクエストを読み取って要求内容を分析する

  4. 要求されたデータを返す(HTTPレスポンス)

  5. Webブラウザが、サーバーからのデータを解析して、WebページとしてPCに表示する



connectionTimeout

クライアントからサーバーへの接続が確立するまで待って諦めるまでの時間。
1000ms = 1秒



timeout

接続後のデータ取得をするために待って諦めるまでの時間。