Thursday, December 27, 2012

Git Merge and Stash


When you are in the middle of something, you learn that there are upstream changes that are possibly relevant to what you are doing. Two ways to solve it

Method 1:


PRE-MERGE CHECKS
Before applying outside changes, you should get your own work in good shape and committed locally, so it will not be clobbered if there are conflicts. git pull and git merge will stop without doing anything when local uncommitted changes overlap with files that git pull/git merge may need to update.
To avoid recording unrelated changes in the merge commit, git pull and git merge will also abort if there are any changes registered in the index relative to the HEAD commit. (One exception is when the changed index entries are in the state that would result from the merge already.)
Warning: Running git merge with uncommitted changes is discouraged: while possible, it leaves you in a state that is hard to back out of in the case of a conflict.


After commit, you can do a git pull or merge.
If seeing a conflict, you can do two things:
  • Decide not to merge. The only clean-ups you need are to reset the index file to the HEAD commit to reverse 2. and to clean up working tree changes made by 2. and 3.; git merge --abort can be used for this.
  • Resolve the conflicts. Git will mark the conflicts in the working tree. Edit the files into shape and git add them to the index. Use git commit to seal the deal.

$ git commit
$ git pull
$ git add
$ git commit


Method 2:


Pulling into a dirty tree
When you are in the middle of something, you learn that there are upstream changes that are possibly relevant to what you are doing. When your local changes do not conflict with the changes in the upstream, a simplegit pull will let you move forward.
However, there are cases in which your local changes do conflict with the upstream changes, and git pull refuses to overwrite your changes. In such a case, you can stash your changes away, perform a pull, and then unstash, like this:
$ git pull
 ...
file foobar not up to date, cannot merge.
$ git stash
$ git pull
$ git stash pop
 that basic stash support is now available in the "Git Repositories" view.
git stash ["Stash Changes" operation on right-click menu]
git stash list [the stashes are listed directly in this view under "Stashed Commits"]
git stash apply ["Apply stashed changes" from the right-click menu of items in "Stashed Commits"]
git stash show [double-click a listed stash to see it in a commit view]

Thursday, December 20, 2012

EGit: How to resolve a merge conflict


To resolve a merge conflict, two ways.


Using Merge Tool

  • select the top level resource showing the red conflict label decorator
  • click Team > Merge Tool
  • select the merge mode Use HEAD (the last local version) of conflicting files and click OK
Image:Egit-0.10-select-merge-mode.png
  • the merge editor opens showing the working tree version in the left pane and the version to be merged in the right pane
Image:Egit-0.10-merge-tool.png
  • edit the working tree version until you are happy with it
  • Team > Add the merged resource to mark the conflict as resolved
  • commit the merge commit via Team > Commit



Manual conflict resolution
To resolve a conflict you have to do the following steps:
§  Navigate to the conflicting resource
§  Edit the content of the conflicting resource
§  Tell EGit that the conflict is resolved with Team > Add
§  Commit the conflict resolution with Team > Commit

Spring NameSpaces: No version numbers in schema references

No version numbers in schema references

Instead of:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<!-- <bean/> definitions here -->

</beans>

Use this Config
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<!-- <bean/> definitions here -->

</beans>

Spring automatically picks the highest version available from the project dependencies (jars). As a project evolves, the Spring version will be updated, we won’t have to maintain all the XML config files to see the new features.

Tuesday, December 18, 2012

Eclipse Configuration: Use spaces for tabs


For the default text editor:
  • General > Editors > Text Editors > Insert spaces for tabs (check it)
For PHP:
  • PHP > Code Style > Formatter > Tab policy (choose "spaces")
  • PHP > Code Style > Formatter > Indentation size (set to 4)
For CSS:
  • Web > CSS > Editor > Indent using spaces (select it)
  • Web > CSS > Editor > Indentation size (set to 4)
For HTML:
  • Web > HTML > Editor > Indent using spaces (select it)
  • Web > HTML > Editor > Indentation size (set to 4)
For XML:
  • XML > XML Files > Editor > Indent using spaces (select it)
  • XML > XML Files > Editor > Indentation size (set to 4)
For Javascript:
  • Javascript > Preferences > Code Style > Formatter > Edit > Indentation (choose "spaces only")
  • Rename the formatter settings profile to save it
For Java:
  • Java > Preferences > Code Style > Formatter > Edit > Indentation (choose "spaces only")
  • Rename the formatter settings profile to save it

Friday, December 14, 2012

Spring Integration:Multiple methods routing




  <int:chain
      input-channel="inboundRequestChannel"
      output-channel="outboundResponseChannel">
    <int:header-enricher>
      <int:header name="service" ref="data-access.service" />
    </int:header-enricher>
    <int:service-activator>
       <int-groovy:script>headers['service']."${headers['METHOD_NAME']}"(payload)</int-groovy:script>
    </int:service-activator>
  </int:chain>

  <!-- The data access services instance -->
  <bean id="data-access.service" class="TestPackagesService" />


  <int:gateway id="gateway"
               service-interface="TestPackagesServiceGateway"
               default-request-channel="inboundRequestChannel"
               default-reply-channel="outboundResponseChannel"
               default-reply-timeout="10000"
               error-channel=“outboundErrorChannel">

    <int:method name="getTestSpec">
      <int:header name="METHOD_NAME" value="getTestSpec" />
    </int:method>
    <int:method name="saveTestSpec">
      <int:header name="METHOD_NAME" value="saveTestSpec" />
    </int:method>

  </int:gateway>






Friday, December 7, 2012

How to define Context-root for a webapp in Eclipse


To define the context-root for a webapp when deplopyed to server on eclipse, specify it by Project -> Properties -> WebProject Settings.

The properties is saved under .settings/org.eclipse.wst.common.component
<property name="context-root" value="test-package.rest-services"/>

When deployed to server, server.xml will contain

<Host ....>
            <Context docBase="test-package.rest-services" path="/test-package.rest-services" ..../>

</Host>


What JRE will a new Maven project in Eclipse use by default and how to change it?

m2eclipse ignores what you configure for the Eclipse default. It will always use 1.5 by default. 

So if you want a Maven project to be configured to use Java 1.6 settings when imported under Eclipse, configure the maven-compiler-plugin appropriately:


<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.1</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
  </configuration>
</plugin>