Configure Git to use with a proxy and switching back

git-logo-2color

Sometimes it can be useful and even necessary to configure Git to use a proxy in the global configuration.
It’s a easy as (https://git-scm.com/docs/git-config#git-config-httpproxy) :
git config --global http.proxy host:port

This configuration will then be written in ~/.gitconfig.

You will then have something like that :

[user]
	name = Me
	email = me@company.com
[http]
	proxy = host:port

Then one day you want to switch and use a different proxy, or none.

But it’s not obvious to configure, regarding the official documentation (https://git-scm.com/docs/git-config).

I could simply unset the proxy if I want to use none, like this :
git config --global --unset http.proxy

I also tried to create aliases to switch to another configuration, like :

  1. git config --global alias.proxy-local 'config --local http.proxy host:port'
  2. git config --global alias.noproxy-local 'config --local http.proxy none'

So I can use ‘git proxy-local’ or ‘git noproxy-local’ depending of the project.

But it could be more practical. By searching further I found a way to configure the proxy depending on the URL. Within the configuration we can use this format to configure options : http.<url>.* (https://git-scm.com/docs/git-config#git-config-httplturlgt).
Some examples are also documented like this :

; HTTP
[http]
	sslVerify
[http "https://weak.example.com"]
	sslVerify = false
	cookieFile = /tmp/cookie.txt

So that way you can configure a proxy by default, and for some URL use another proxy or none :

; Use a proxy by default
[http]
	proxy = host:port
; Use no proxy on internal server
[http "http://myserver.mycompany/"]
	proxy = 

That’s it !

Publicités

Generating a link to your issue tracker with IntelliJ

Sometimes it’s a good practice to post a commit message to your VCS (version control system), including a pattern with the issue number.

For example, you could commit changes towards Git or Subversion, with this commit message : « I fixed this nasty bug : #123 ».

And it could be nice to automatically generate a link to your issue tracker directly inside your favorite Java IDE.

Here’s how to do with IntelliJ IDEA :

  • Go to File > Settings > Version Control > Issue Navigation
  • Then add an item : here you have to fill in the issue ID (regex), and the issue link that will be generated (regex with replacement of the capturing group)

The dialog box you’ll get looks like this :

add-issue-nav-link

If you want to capture just a part of the regex, you can use the capturing groups.
Let’s say the pattern you use is « #issue-number », but you want to exclude the « # » from the URL generated. So in this case you will use a regex with one non-capturing group, and a capturing group.
So the issue ID regex will be : (?:#)([0-9]+)
And the issue link will be : http://my-issue-tracker/$1

That way, you’ll be able so see a clickable link in the Version Control window (ALT+9).

See also :

JMX MBean provided with Oracle JDBC Driver

I discovered that Oracle added a JMX MBean in Oracle JDBC Driver.
It’s called « Diagnosability Management ».

Doc for version 11g :
https://docs.oracle.com/cd/B28359_01/java.111/b31224/diagnose.htm#CIAIEEFF

Resume :

The JDBC diagnosability management feature introduces an MBean, oracle.jdbc.driver.OracleDiagnosabilityMBean. This MBean provides means to enable and disable JDBC logging.

Description of the MBean :

  • Name :
    • Domain : com.oracle.jdbc
    • Name : org.jboss.classloader.spi.base.BaseClassLoader
    • Type : diagnosability
  • Attribute Name : LoggingEnabled (boolean)

Logging with Oracle JDBC Driver

Doc for version 11g :
https://docs.oracle.com/cd/B28359_01/java.111/b31224/diagnose.htm#CIAGBGFI

Logging is done using java.util.logging package provided by Java SE.

To get log output, you must use the debug JAR files, which are indicated with a « _g » in the file name, like ojdbc5_g.jar or ojdbc6_g.jar. The debug JAR file must be included in the CLASSPATH environment variable.

Resume :

This feature logs information about events that occur when JDBC driver code runs. Events can include user-visible events, such as SQL exceptions, running of SQL statements, and detailed JDBC internal events, such as entry to and exit from internal JDBC methods. Users can enable this feature to log specific events or all the events.

Générateur de méthodes Fluent en Java avec IntelliJ

Il peut être intéressant de générer des méthodes automatiquement sur le modèle Fluent API.
C’est-à-dire que les méthodes « setter » peuvent ensuite être chainées dans la même instruction.

Dans l’IDE IntelliJ, il y a deux méthodes pour cela.

1/ Utiliser un template de code pour le setter
Dans l’IDE, clic droit sur un champ d’une classe, puis :
Generate > Setter
Puis dans template, choisir « Builder ».

On peut personnaliser le template pour préfixer le champ par « with » par exemple.
Dans ce cas copier le template « Builder » et le renommer en « Fluent Setter » par exemple, et remplacer « set » par « with » (with$StringUtil.capitalizeWithJavaBeanConvention …).

Exemple de template :

2/ Installer un plugin IntelliJ

Working with IntelliJ and a corporate Maven repository over HTTPS

Prérequis :

  • IntelliJ 14+
  • Maven 3
  • Sonatype Nexus (ou autre repo d’entreprise)

Config Maven locale :
~/.m2/settings.xml

    <mirrors>
        <mirror>
            <id>nexus-forge</id>
            <mirrorOf>*</mirrorOf>
            <name>Nexus (FORGE)</name>
            <url>https://forge.company/nexus/content/groups/public/</url>
        </mirror>
    </mirrors>
    <servers>
        <!-- Ajouter authentification sur Nexus Interne, si necessaire -->
        <server>
            <id>nexus-forge</id>
            <username>who</username>
            <password>ami</password>
        </server>        
    </servers>

Si utilisation de HTTPS pour le serveur, configurer la Java Property « javax.net.ssl.trustStore ».

Par exemple sous Windows : « -Djavax.net.ssl.trustStore=C:\Users\<ME>\cacerts » • (rajouter à JAVA_OPTS, ou MAVEN_OPTS).

Dans IntelliJ, pour permettre de télécharger des librairies dans l’IDE :

File > Settings > … > Maven > Importing :
VM options for importer : rajouter -Djavax.net.ssl.trustStore=…\cacerts

Penser aussi à configurer l’exécution du build dans :

File > Settings > … > Maven > Runner:
VM Options : rajouter -Djavax.net.ssl.trustStore=…\cacerts

Normalement ensuite tout devrait bien se passer.