Dépendances et releases avec nexus, maven et svn

16/11/2009

1) Installer svn
Créer un repository avec à la racine trunk, branches, tags

2) Installer la webapp nexus

#!/bin/bash
cd /usr/local/mycompany/tomcat-cluster/instance0/webapps/ &&
wget http://nexus.sonatype.org/downloads/nexus-webapp-1.4.0.war &&
unzip -o nexus-webapp-1.4.0.war -d nexus && rm nexus-webapp-1.4.0.war && 

cat > /etc/httpd/conf.d/nexus.conf <<EOF
<VirtualHost *:80>
    ServerName mvn.mycompany.fr
    ServerAlias mvn.mycompany.net
    ProxyPreserveHost   On
    ProxyPass           /   http://localhost:8080/nexus
    ProxyPassReverse    /   http://localhost:8080/nexus
    ErrorLog logs/nexus/error.log
    CustomLog logs/nexus/access.log common
</VirtualHost>
EOF
/etc/init.d/httpd restart &&
/etc/init.d/tomcat restart

3) Configurer nexus
Editer les users, desactiver le user anonymous, changer le mot de passe admin.
Ajouter un compte avec le role developer et system feed
Verifer les path des stores de tous les serveurs et lancer la reindexation
Configurer le server de mail et désactiver l’accès anonyme

4) Créer le fichier $HOME/.m2/settings.xml sur les machines de dev

<settings>
    <servers>
    <server>
        <id>mycompany-server</id>
        <username>myuser</username>
        <password>mypassword</password>
    </server>
    </servers>
    <profiles>
        <profile>
            <id>developer</id>
            <properties>
                <!-- global properties -->
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

                <!-- internal repositories informations -->
                <snapshotsRepository.id>mycompany-server</snapshotsRepository.id>
                <snapshotsRepository.name>mycompany snapshots repository</snapshotsRepository.name>
                <snapshotsRepository.url>http://www.mycompagny.fr/nexus/content/repositories/snapshots</snapshotsRepository.url>

                <repository.id>mycompany-server</repository.id>
                <repository.name>mycompany releases repository</repository.name>
                <repository.url>http://www.mycompagny.fr/nexus/content/repositories/releases</repository.url>

                <!-- internal scm informations -->
                <scm.url.tags>svn+ssh://www.mycompagny.fr/tags/releases</scm.url.tags>
            </properties>
            <repositories>
            <repository>
                <id>mycompany-server</id>
                <url>http://www.mycompagny.fr/nexus/content/repositories/snapshots</url>
            </repository>
            <repository>
                <id>mycompany-server</id>
                <url>http://www.mycompagny.fr/nexus/content/groups/central</url>
            </repository>
            </repositories>
            <pluginRepositories>
            <pluginRepository>
                <id>mycompany-server</id>
                <url>http://www.mycompagny.fr/nexus/content/groups/central</url>
            </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>developer</activeProfile>
    </activeProfiles>
</settings>

5) Créer un projet A sur la machine dev1
mvn archetype:create -DgroupId=test.maven -DartifactId=projectA -DarchetypeArtifactId=maven-archetype-archetype

Editer le pom.xml

<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>test.maven</groupId>
    <artifactId>projectA</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>Archetype - projectA</name>
    <url>http://maven.apache.org</url>
    <scm>
        <connection>scm:svn:http://svn</connection>
    </scm>
    <distributionManagement>
        <repository>
            <id>${repository.id}</id>
            <name>${repository.name}</name>
            <url>${repository.url}</url>
        </repository>
        <snapshotRepository>
            <id>${snapshotsRepository.id}</id>
            <name>${snapshotsRepository.name}</name>
            <url>${snapshotsRepository.url}</url>
            <uniqueVersion>true</uniqueVersion>
        </snapshotRepository>
        </distributionManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <configuration>
                    <tagBase>${scm.url.tags}/test</tagBase>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.14</version>
        </dependency>
    </dependencies>
</project>

6) Créer un projet B sur la machine dev2
mvn archetype:create -DgroupId=test.maven -DartifactId=projectB -DarchetypeArtifactId=maven-archetype-archetype

Editer le pom.xml

<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>test.maven</groupId>
    <artifactId>projectB</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>Archetype - projectB</name>
    <url>http://maven.apache.org</url>
    <scm>
        <connection>scm:svn:http://svn</connection>
    </scm>
    <distributionManagement>
        <repository>
            <id>${repository.id}</id>
            <name>${repository.name}</name>
            <url>${repository.url}</url>
        </repository>
        <snapshotRepository>
            <id>${snapshotsRepository.id}</id>
            <name>${snapshotsRepository.name}</name>
            <url>${snapshotsRepository.url}</url>
            <uniqueVersion>true</uniqueVersion>
        </snapshotRepository>
    </distributionManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <configuration>
                    <tagBase>${scm.url.tags}/test</tagBase>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>test.maven</groupId>
            <artifactId>projectA</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>
</project>

7) Faire une release, changer de version du projet…
# mvn release:prepare -Dresume=false

What is the release version for “Archetype - projectA”? (test.maven:projectA) 1.0: :
What is SCM release tag or label for “Archetype - projectA”? (test.maven:projectA) projectA-1.0: :
What is the new development version for “Archetype - projectA”? (test.maven:projectA) 1.1-SNAPSHOT: :

(va créer le tag sur svn et mettre à jour la version du projet)

# mvn release:perform

(va récupérer les dernières sources taggées, builder et uploader le jar sur le repository)

(c’est mortel)

Divers

# force la recupération des derniers snapshots
mvn -U compile
# Le flux rss qui notifie de toutes les releases/snapshots publiées
feed://www.mycompagny.fr/nexus/service/local/feeds/recentlyDeployedArtifacts

Frédéric Java , ,

Maven 2: Spring and JTA dependencies

13/11/2009

download from http://java.sun.com/products/jta/
and
mvn install:install-file \
-Dfile=./jta-1_0_1B-classes.zip \
-DgroupId=javax.transaction \
-DartifactId=jta -Dversion=1.0.1B \
-Dpackaging=jar

Frédéric Java ,

INNODB Specific options

10/11/2009

# Use this option if you have a MySQL server with InnoDB support enabled
# but you do not plan to use it. This will save memory and disk space
# and speed up some things.
#skip-innodb

# Additional memory pool that is used by InnoDB to store metadata
# information. If InnoDB requires more memory for this purpose it will
# start to allocate it from the OS. As this is fast enough on most
# recent operating systems, you normally do not need to change this
# value. SHOW INNODB STATUS will display the current amount used.
innodb_additional_mem_pool_size=20M

# If set to 1, InnoDB will flush (fsync) the transaction logs to the
# disk at each commit, which offers full ACID behavior. If you are
# willing to compromise this safety, and you are running small
# transactions, you may set this to 0 or 2 to reduce disk I/O to the
# logs. Value 0 means that the log is only written to the log file and
# the log file flushed to disk approximately once per second. Value 2
# means the log is written to the log file at each commit, but the log
# file is only flushed to disk approximately once per second.
innodb_flush_log_at_trx_commit=0

# The size of the buffer InnoDB uses for buffering log data. As soon as
# it is full, InnoDB will have to flush it to disk. As it is flushed
# once per second anyway, it does not make sense to have it very large
# (even with long transactions).
innodb_log_buffer_size=8M

# InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and
# row data. The bigger you set this the less disk I/O is needed to
# access data in tables. On a dedicated database server you may set this
# parameter up to 80% of the machine physical memory size. Do not set it
# too large, though, because competition of the physical memory may
# cause paging in the operating system. Note that on 32bit systems you
# might be limited to 2-3.5G of user level memory per process, so do not
# set it too high.
innodb_buffer_pool_size=512M

# Size of each log file in a log group. You should set the combined size
# of log files to about 25%-100% of your buffer pool size to avoid
# unneeded buffer pool flush activity on log file overwrite. However,
# note that a larger logfile size will increase the time needed for the
# recovery process.
innodb_log_file_size=256M
innodb_file_io_threads=16

# Number of threads allowed inside the InnoDB kernel. The optimal value
# depends highly on the application, hardware as well as the OS
# scheduler properties. A too high value may lead to thread thrashing.
innodb_thread_concurrency=8

#Max packetlength to send/receive from to server.
#max_allowed_packet=32M

#This option makes InnoDB to store each created table into its own .ibd file.
innodb_file_per_table

Frédéric Mysql , ,

UBER COOL

08/07/2009

Extraire un UIView d’une ressource NIB

08/07/2009
+ (id) ExtractView: (NSString*) viewName
           nibName: (NSString*) nibName
	     owner: (UIViewController*) owner {
    NSArray * nibContents = [[NSBundle mainBundle] loadNibNamed:nibName
   					 	          owner:owner
							options:nil];
    NSEnumerator * nibEnumerator = [nibContents objectEnumerator];
    id object;
    int count = 0;

    while ((object = [nibEnumerator nextObject])) {
 	const char * returnClassName = object_getClassName(object);
	NSString * className = [NSString stringWithUTF8String:returnClassName];

	if([className isEqualToString:viewName] == TRUE) {
 	    return object;
	}

	count++;
   }

   return nil;
}

Frédéric iPhone