Showing diffs
TweetPosted on Sunday Mar 09, 2014 at 09:06AM in Technology
Assume this:
kyle-no-MacBook:gitprac5 kyle$ ls -l total 8 -rw-r--r--+ 1 kyle staff 5 3 9 09:04 hoge.txt kyle-no-MacBook:gitprac5 kyle$ cat hoge.txt hoge kyle-no-MacBook:gitprac5 kyle$ git status # On branch master nothing to commit, working directory clean kyle-no-MacBook:gitprac5 kyle$
Show unstaged changes
kyle-no-MacBook:gitprac5 kyle$ echo hogehoge >> hoge.txt kyle-no-MacBook:gitprac5 kyle$ git diff diff --git a/hoge.txt b/hoge.txt index 2262de0..1904c09 100644 --- a/hoge.txt +++ b/hoge.txt @@ -1 +1,2 @@ hoge +hogehoge kyle-no-MacBook:gitprac5 kyle$
Show staged changes
kyle-no-MacBook:gitprac5 kyle$ git add hoge.txt kyle-no-MacBook:gitprac5 kyle$ git diff --cached diff --git a/hoge.txt b/hoge.txt index 2262de0..1904c09 100644 --- a/hoge.txt +++ b/hoge.txt @@ -1 +1,2 @@ hoge +hogehoge kyle-no-MacBook:gitprac5 kyle$
- There are no unstaged changes now so result of git diff is empty
kyle-no-MacBook:gitprac5 kyle$ git diff kyle-no-MacBook:gitprac5 kyle$
Show both of unstaged and staged changes
Edit hoge.txt again
kyle-no-MacBook:gitprac5 kyle$ echo hogehogehoge >> hoge.txt
Show unstaged changes
kyle-no-MacBook:gitprac5 kyle$ git diff diff --git a/hoge.txt b/hoge.txt index 1904c09..9d1d67e 100644 --- a/hoge.txt +++ b/hoge.txt @@ -1,2 +1,3 @@ hoge hogehoge +hogehogehoge
Show staged changes
kyle-no-MacBook:gitprac5 kyle$ git diff --cached diff --git a/hoge.txt b/hoge.txt index 2262de0..1904c09 100644 --- a/hoge.txt +++ b/hoge.txt @@ -1 +1,2 @@ hoge +hogehoge
- This means that an another copy is created when we execute git add.
Show diff between 2 branches
kyle-no-MacBook:hello kyle$ git diff b4 origin/b4 diff --git a/README.md b/README.md index b8630fa..9c70835 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ b4-local1 -CANCEL kyle-no-MacBook:hello kyle$
Tags: git
Statuses of resources
TweetPosted on Sunday Mar 09, 2014 at 08:28AM in Technology
Statuses
- untracked
- unmodified
- modified
- staged
untracked
- Newly created file what not connected to the any part of git.
- We use git add to connect these file to git.
unmodified
- Files connected to git but no changes were made yet.
modified
- Files connected to git and modified.
- When we do commit with this kind of resources only, no changes will be made.
staged
- Files connected to git and modified, and declared to commit next time.
Examples of an newly created file
Create a repository
kyle-no-MacBook:gitprac5 kyle$ git init Initialized empty Git repository in /Users/kyle/tmp/gitprac5/.git/ kyle-no-MacBook:gitprac5 kyle$
Create a file
kyle-no-MacBook:gitprac5 kyle$ echo hoge > hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # hoge.txt nothing added to commit but untracked files present (use "git add" to track) kyle-no-MacBook:gitprac5 kyle$
- Now hoge.txt is untracked.
Add to Index
kyle-no-MacBook:gitprac5 kyle$ git add hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: hoge.txt # kyle-no-MacBook:gitprac5 kyle$
- Now README is staged (?).
Commit
kyle-no-MacBook:gitprac5 kyle$ git commit -m 'initial' [master (root-commit) ffbe516] initial 1 file changed, 1 insertion(+) create mode 100644 hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master nothing to commit, working directory clean kyle-no-MacBook:gitprac5 kyle$
- Now README is unmodified.
Cancel git add to new file
- We can cancel it like this:
kyle-no-MacBook:gitprac5 kyle$ echo README! > README kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # README nothing added to commit but untracked files present (use "git add" to track) kyle-no-MacBook:gitprac5 kyle$ git add README kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: README # kyle-no-MacBook:gitprac5 kyle$ git reset HEAD README kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # README nothing added to commit but untracked files present (use "git add" to track) kyle-no-MacBook:gitprac5 kyle$
- Also this deletes all of untracked files:
kyle-no-MacBook:gitprac5 kyle$ git clean -f Removing README kyle-no-MacBook:gitprac5 kyle$ ls -l total 8 -rw-r--r--+ 1 kyle staff 5 3 9 08:40 hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master nothing to commit, working directory clean kyle-no-MacBook:gitprac5 kyle$
Examples of existing file that already tracked by git
kyle-no-MacBook:gitprac5 kyle$ echo hogehoge >> hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: hoge.txt # no changes added to commit (use "git add" and/or "git commit -a") kyle-no-MacBook:gitprac5 kyle$
- Now hoge.txt modified but not staged.
kyle-no-MacBook:gitprac5 kyle$ git add hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: hoge.txt # kyle-no-MacBook:gitprac5 kyle$
- Now hoge.txt staged.
- Let's take one more modify.
kyle-no-MacBook:gitprac5 kyle$ echo hogehogehoge >> hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: hoge.txt # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: hoge.txt # kyle-no-MacBook:gitprac5 kyle$
- This means last change (hogehogehoge) will not send by next commit.
- Next commit will send the change (hogehoge) only.
- So when you want to commit (hogehogehoge) next time, you need to execute git add once again.
kyle-no-MacBook:gitprac5 kyle$ git add hoge.txt kyle-no-MacBook:gitprac5 kyle$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: hoge.txt # kyle-no-MacBook:gitprac5 kyle$
References
Tags: git
How to define JVM parameters
TweetPosted on Friday Mar 07, 2014 at 08:09AM in Technology
Environment
- WildFly 8.0.0.Final
- JBoss Tools (Kepler) 4.1.1.Final
- Eclipse Kepler SR1
- Oracle JDK7u51
- OS X 10.9.2
Test Servlet
- This time we're going to test it with enabling of assertion.
@WebServlet("/") public class AssertServlet extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { assert false : "test"; } }
Configure standalone.conf for launching through standalone.sh
- Add this statement to $WILDFLY_HOME/bin/standalone.conf
JAVA_OPTS=$JAVA_OPTS -ea
- This can be done on unix systems like this:
echo "JAVA_OPTS=\"\$JAVA_OPTS -ea\"" >> standalone.conf
- Now the Servlet throws Assertion Error when we launch WildFly through standalone.sh:
09:05:00,614 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /assert/: java.lang.AssertionError: test at assert0.AssertServlet.doGet(AssertServlet.java:16) [classes:] at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final] ...
- But it won't work with WildFly instances that launched by Eclipse.
Configuring Eclipse
Open Servers view and double-click WildFly instance
Click “Open launch configuration”
Add “-ea” to “VM arguments:” - OK
wildfly-maven-plugin
- Like this:
<plugin> <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>1.0.1.Final</version> <configuration> <jboss-home>${wildfly.home}</jboss-home> <modules-path>${wildfly.home}/modules</modules-path> <jvm-args>-ea -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djboss.server.base.dir=${wildfly.home}/standalone -Djboss.socket.binding.port-offset=${wildfly.port.offset}</jvm-args> <port>${wildfly.port.mgmt}</port> </configuration> ...
Assertion notes
Eclipse
We can enable assertion for every JUnit run configuration which will newly create.
This won't make assertions enable for already created run configurations.
Maven Surefire Plugin
- “By default, Surefire enables JVM assertions for the execution of your test cases. To disable the assertions, set this flag to “false”[3].
References
Tags: wildfly
Profiling with VisualVM
TweetPosted on Thursday Mar 06, 2014 at 05:04PM in Technology
Environment
Local
- VisualVM 1.7.0_51 (Build 1352-130117); platform 20130117-unknown-revn
- WildFly 8.0.0.Final
- Oracle JDK7u51
- OS X 10.9.2
Remote profiling target
- WildFly 8.0.0.Final
- Oracle JDK7u45
- OS X 10.9.1
Profiling local instances
- We don't need any special operation to profiling with local instances.
- After just launch VisualVM, we can see local instances.
Profiling Remote instances
Create a management user in the target instance
kyle-no-MacBook:bin kyle$ pwd /Users/kyle/apps/wildfly-8.0.0.Final/bin kyle-no-MacBook:bin kyle$ ./add-user.sh kyle *** Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8 Added user 'kyle' to file '/Users/kyle/apps/wildfly-8.0.0.Final/standalone/configuration/mgmt-users.properties' Added user 'kyle' to file '/Users/kyle/apps/wildfly-8.0.0.Final/domain/configuration/mgmt-users.properties' kyle-no-MacBook:bin kyle$
Define a system property in the target instance to accept connection from remote host
- CAUTION: this makes management port to accept connections from everyone.
/system-property=jboss.bind.address.management:add(value=0.0.0.0)
Launch VisualVM
- We have to specify an additional jar on startup option like this:
jvisualvm --cp:a /Users/kyle/apps/wildfly-8.0.0.Final/bin/client/jboss-cli-client.jar
- If it doesn't work, try “-cp:a” instead
Add and connect to target
Right-click “Remote” - “Add a remote host”
Enter hostname - OK
Right-click hostname - add a JMX connection
Enter connection url, username and password that created in above step - OK NOTICE: Usually, WildFly's management port is 9990. I customized it as 49990 for my environment.
Double-click a icon which appeared with JMX icon. now we can do profiling with remote WildFly instance.
service:jmx:http-remoting-jmx://[HOSTNAME]:9990
References
- Connecting VisualVM with a remote JBoss AS 7 / EAP6 JVM process | akquinet-blog
- [AS7-4695] Server does not start with sun jmx enabled - JBoss Issue Tracker
- Using jconsole to connect to JMX on AS7 | Community
- adding alternative jmx connectivity (i.e. JBoss 7) | Oracle Community
- JMX subsystem configuration - WildFly 8 - Project Documentation Editor
Tags: wildfly
Deploying after integration test with Jenkins
TweetPosted on Wednesday Mar 05, 2014 at 04:09PM in Jenkins
Requirements
- I want to deploy the production resource after integration test.
- But some resources are environment-specific.
- So, after integration test succeeded, I want to replace such resources for production version.
How to achieve it?
- The deployment job is need to be a parameterized job.
- After integration test completed, then another mvn starts at post-build step of Jenkins.
- This mvn does only package goal with no tests.
- Deployment will be executed by SSH deploy plugin at post-build action of Jenkins.
How to apply this way to a Jenkins job?
- Create a parameterized job that can integration-test and deployment be done successfully.
- I assumed a job similar to one created at another my posting Deploying with Publish Over SSH Plugin
- Go to job configuration page
- Click “Add post-build step”
- Click “Invoke top-level Maven targets”
- Select “Run only if build succeeds”
- Select Maven Version “Default”
- Not (Default) which one with enclosed in parentheses. it won't work.
- Enter “Goals”
- Click “Advanced…”
- Enter “POM”, “Properties”.
- “hogeApp.environmentId=prod” triggers to Maven to include production resources in my pom.xml.
- Ensure that there is a post-build action which deploys the artifact to the production environment.
- Click “Save” of bottom of the page.
Log
Jenkins job output
... [INFO] --- maven-failsafe-plugin:2.16:verify (default) @ switch --- [INFO] Failsafe report directory: /Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/target/failsafe-reports [JENKINS] テスト結果の記録 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 11.169s [INFO] Finished at: Wed Mar 05 16:25:53 JST 2014 [INFO] Final Memory: 22M/318M [INFO] ------------------------------------------------------------------------ [JENKINS] Archiving /Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/pom.xml to org.nailedtothex/switch/0.0.1-SNAPSHOT/switch-0.0.1-SNAPSHOT.pom [JENKINS] Archiving /Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/target/switch.war to org.nailedtothex/switch/0.0.1-SNAPSHOT/switch-0.0.1-SNAPSHOT.war channel stopped [workspace] $ /Users/kyle/apps/apache-maven-3.1.1/bin/mvn -f switch/pom.xml -Dtag=v0.1 -Dmaven.test.skip=true -DhogeApp.environmentId=prod clean package [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building switch 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ switch --- [INFO] Deleting /Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ switch --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ switch --- [INFO] Compiling 1 source file to /Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/target/classes [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ switch --- [INFO] Not copying test resources [INFO] [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ switch --- [INFO] Not compiling test sources [INFO] [INFO] --- maven-surefire-plugin:2.16:test (default-test) @ switch --- [INFO] Tests are skipped. [INFO] [INFO] --- maven-war-plugin:2.4:war (default-war) @ switch --- [INFO] Packaging webapp [INFO] Assembling webapp [switch] in [/Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/target/switch] [INFO] Processing war project [INFO] Copying webapp webResources [/Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/src/main/webapp/_prod] to [/Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/target/switch] [INFO] Copying webapp resources [/Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/src/main/webapp] [INFO] Webapp assembled in [46 msecs] [INFO] Building war: /Users/Shared/Jenkins/Home/jobs/SwitchDeploy/workspace/switch/target/switch.war [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.595s [INFO] Finished at: Wed Mar 05 16:26:01 JST 2014 [INFO] Final Memory: 15M/245M [INFO] ------------------------------------------------------------------------ SSH: Connecting from host [kyle-no-MacBook.local] SSH: Connecting with configuration [osxserver] ... SSH: EXEC: STDOUT/STDERR from command [/Users/kyle/wildfly-8.0.0.Final/bin/jboss-cli.sh --connect --controller=localhost:49990 --command="deploy switch.war --force"] ... SSH: EXEC: completed after 3,256 ms SSH: Disconnecting configuration [osxserver] ... SSH: Transferred 1 file(s) Finished: SUCCESS
- Deployment succeeded as expectedly.
- After integration-test completed, another mvn was kicked, and it builds the package for production without testing once again.
Check the deployed application
kyle-osxserver:~ kyle$ telnet localhost 48080 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GET /switch/ HTTP/1.0 HTTP/1.0 200 OK Connection: close X-Powered-By: Undertow 1 X-Powered-By: JSP/2.2 Set-Cookie: JSESSIONID=gLpwDJ37tu-Uoxd0r9pWD2wH.kyle-osxserver; path=/switch Server: Wildfly 8 Content-Type: text/plain;charset=UTF-8 Date: Wed, 05 Mar 2014 07:27:29 GMT This value came from context-param defined in /src/main/webapp/_prod/WEB-INF/web.xml This value came from /src/main/resources/common.properties This value came from /src/main/resources/_prod/env-specific.properties Connection closed by foreign host. kyle-osxserver:~ kyle$
- I deployed a sample application created in Maven - Switching environment specific configuration files.
- I can see that pom.xml of it was included resources for production expectedly.
References
Tags: jenkins