[Arakhnę-Dev] [240] * Prepare for Maven 3 |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
Revision: 240
Author: galland
Date: 2011-08-13 14:45:42 +0200 (Sat, 13 Aug 2011)
Log Message:
-----------
* Prepare for Maven 3
Modified Paths:
--------------
trunk/maventools/pom.xml
trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java
trunk/maventools/src/main/java/org/arakhne/maven/ExtendedArtifact.java
trunk/maventools/src/main/java/org/arakhne/maven/HtmlFileFilter.java
trunk/maventools/src/main/java/org/arakhne/maven/JavaSourceFileFilter.java
trunk/maventools/src/main/java/org/arakhne/maven/MultiFileFilter.java
trunk/maventools/src/main/java/org/arakhne/maven/PropertyFileFilter.java
Modified: trunk/maventools/pom.xml
===================================================================
--- trunk/maventools/pom.xml 2011-08-06 14:07:15 UTC (rev 239)
+++ trunk/maventools/pom.xml 2011-08-13 12:45:42 UTC (rev 240)
@@ -33,6 +33,10 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.tmatesoft.svnkit</groupId>
+ <artifactId>svnkit</artifactId>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java
===================================================================
--- trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java 2011-08-06 14:07:15 UTC (rev 239)
+++ trunk/maventools/src/main/java/org/arakhne/maven/AbstractArakhneMojo.java 2011-08-13 12:45:42 UTC (rev 240)
@@ -1,9 +1,7 @@
/*
* $Id$
*
- * Copyright (C) 2010-11 Stéphane GALLAND
- *
- * This library is free software; you can redistribute it and/or
+ * Copyright (C) 2010-11 Stephane GALLAND This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
@@ -37,7 +35,12 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.tmatesoft.svn.core.SVNException;
+import org.tmatesoft.svn.core.wc.SVNClientManager;
+import org.tmatesoft.svn.core.wc.SVNInfo;
+import org.tmatesoft.svn.core.wc.SVNRevision;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
@@ -46,17 +49,32 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.Reader;
+import java.lang.reflect.Array;
+import java.math.BigDecimal;
+import java.math.BigInteger;
import java.net.URL;
+import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CodingErrorAction;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
+import java.util.Set;
import java.util.TreeMap;
-import java.util.regex.Matcher;
+import java.util.TreeSet;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Pattern;
/**
@@ -64,7 +82,7 @@
* This implementation is thread safe.
*
* @author $Author: galland$
- * @version $Name$ $Revision$ $Date$
+ * @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*
@@ -90,7 +108,23 @@
* Maven tag for version description
*/
public static final String PROP_VERSION = "version"; //$NON-NLS-1$
-
+
+ /** Preferred charset for the new MacOS and Linux operating systems.
+ */
+ public static final String PREFERRED_CHARSET_UNIX = "UTF-8"; //$NON-NLS-1$
+
+ /** Preferred charset for the Windows operating systems.
+ */
+ public static final String PREFERRED_CHARSET_WINDOWS = "windows-1250"; //$NON-NLS-1$
+
+ /** Preferred charset for the old MacOS operating systems.
+ */
+ public static final String PREFERRED_CHARSET_MACOS = "MacRoman"; //$NON-NLS-1$
+
+ /** Preferred charset for the Java virtual machine (internal charset).
+ */
+ public static final String PREFERRED_CHARSET_JVM = "UTF-16"; //$NON-NLS-1$
+
/** Copy a file.
*
* @param in
@@ -167,48 +201,81 @@
return r;
}
- /** Quote the dollar and backslash characters in a replacement text.
- *
- * @param replacement is the replacement text.
- * @return the quoted replacement text
- * @see #unquoteReplacementText(String)
- * @see Matcher#replaceAll(String)
- * @see String#replaceAll(String, String)
- * @see Pattern#quote(String)
+ /** Invocation date.
*/
- public String quoteReplacementText(String replacement) {
- // Protect the dollar and backslashs signs
- String s = replacement.replaceAll(Pattern.quote("$"), "$"); //$NON-NLS-1$//$NON-NLS-2$
- s = s.replaceAll(Pattern.quote("\\\\"), "\"); //$NON-NLS-1$//$NON-NLS-2$
- return s;
+ protected final Date invocationDate = new Date();
+
+ /** Map the directory of pom.xml files to the definition
+ * of the corresponding maven module.
+ */
+ private final Map<File,ExtendedArtifact> artifactDescriptions = new TreeMap<File,ExtendedArtifact>();
+
+ /** Manager of the SVN repository.
+ */
+ private SVNClientManager svnManager = null;
+
+ /** Are the preferred charset in the preferred order.
+ */
+ private Charset[] preferredCharsets;
+
+ /**
+ */
+ public AbstractArakhneMojo() {
+ List<Charset> availableCharsets = new ArrayList<Charset>();
+
+ // New Mac OS and Linux OS
+ addCharset(availableCharsets, PREFERRED_CHARSET_UNIX);
+ // Windows OS
+ addCharset(availableCharsets, PREFERRED_CHARSET_WINDOWS);
+ // Old Mac OS
+ addCharset(availableCharsets, PREFERRED_CHARSET_MACOS);
+ // Java Internal
+ addCharset(availableCharsets, PREFERRED_CHARSET_JVM);
+
+ this.preferredCharsets = new Charset[availableCharsets.size()];
+ availableCharsets.toArray(this.preferredCharsets);
+ availableCharsets.clear();
}
+
+ private static void addCharset(List<Charset> availableCharsets, String csName) {
+ try {
+ Charset cs = Charset.forName(csName);
+ if (!availableCharsets.contains(cs)) {
+ availableCharsets.add(cs);
+ }
+ }
+ catch(Throwable _) {
+ //
+ }
+ }
- /** Unquote the dollar and backslash characters in a replacement text.
+ /** Replies the preferred charsets in the preferred order of use.
*
- * @param replacement is the replacement text.
- * @return the unquoted replacement text
- * @see #quoteReplacementText(String)
- * @see Matcher#replaceAll(String)
- * @see String#replaceAll(String, String)
- * @see Pattern#quote(String)
+ * @return the preferred charsets in the preferred order of use.
*/
- public String unquoteReplacementText(String replacement) {
- // Unprotect the dollar and backslashs signs
- String s = replacement;
- s = s.replaceAll(Pattern.quote("$"), "\\$"); //$NON-NLS-1$//$NON-NLS-2$
- s = s.replaceAll(Pattern.quote("\"), "\\\\"); //$NON-NLS-1$//$NON-NLS-2$
- return s;
+ protected Charset[] getPreferredCharsets() {
+ return this.preferredCharsets;
}
+
+ /** Set the preferred charsets in the preferred order of use.
+ *
+ * @param charsets are the preferred charsets in the preferred order of use.
+ */
+ protected void setPreferredCharsets(Charset... charsets) {
+ this.preferredCharsets = charsets;
+ }
- /** Invocation date.
+ /** Replies the manager of the SVN repository.
+ *
+ * @return the manager of the SVN repository.
*/
- protected final Date invocationDate = new Date();
+ protected synchronized final SVNClientManager getSVNClientManager() {
+ if (this.svnManager==null) {
+ this.svnManager = SVNClientManager.newInstance();
+ }
+ return this.svnManager;
+ }
- /** Map the directory of pom.xml files to the definition
- * of the corresponding maven module.
- */
- private final Map<File,ExtendedArtifact> artifactDescriptions = new TreeMap<File,ExtendedArtifact>();
-
/** Replies the artifact handler manager.
* <p>
* It is an attribute defined as:
@@ -345,6 +412,53 @@
}
}
+ /** Replies a map of files which are found on the file system.
+ * The map has the found files as keys and the search directory
+ * as values.
+ *
+ * @param directory is the directory to search in.
+ * @param filter is the file selector
+ * @param fileOut is the list of files to fill.
+ */
+ protected synchronized void findFiles(File directory, FileFilter filter, Map<? super File,File> fileOut) {
+ if (directory!=null && filter!=null) {
+ File candidate;
+ List<File> candidates = new ArrayList<File>();
+
+ String relativePath = removePathPrefix(getBaseDirectory(), directory);
+
+ getLog().debug("Retreiving " //$NON-NLS-1$
+ +filter.toString()
+ +" files from " //$NON-NLS-1$
+ +relativePath);
+
+ candidates.add(directory);
+ int nbFiles = 0;
+
+ while (!candidates.isEmpty()) {
+ candidate = candidates.remove(0);
+ if (candidate.isDirectory()) {
+ File[] children = candidate.listFiles(filter);
+ if (children!=null) {
+ for(File child : children) {
+ if (child!=null && child.isDirectory()) {
+ candidates.add(child);
+ }
+ else {
+ fileOut.put(child, directory);
+ ++nbFiles;
+ }
+ }
+ }
+ }
+ }
+
+ getLog().debug("Found " //$NON-NLS-1$
+ +nbFiles
+ +" file(s)"); //$NON-NLS-1$
+ }
+ }
+
/** Log an information message.
*
* @param message
@@ -499,11 +613,27 @@
getLog().warn(e);
}
}
+
+ String scmRevision = null;
+
+ try {
+ SVNClientManager svnManager = getSVNClientManager();
+ SVNInfo svnInfo = svnManager.getWCClient().doInfo(pomDirectory, SVNRevision.UNDEFINED);
+ if (svnInfo!=null) {
+ SVNRevision revision = svnInfo.getRevision();
+ if (revision!=null) {
+ scmRevision = Long.toString(revision.getNumber());
+ }
+ }
+ }
+ catch (SVNException _) {
+ //
+ }
Artifact a = createArtifact(groupId, artifactId, version);
return new ExtendedArtifact(
a, name,
- url, organization, scm,
+ url, organization, scmRevision, scm,
developers, contributors,
licenses);
}
@@ -577,15 +707,53 @@
* correctly set.
* This function may be overridden by subclasses to
* test subclasse's attributes.
+ *
+ * @throws MojoExecutionException
*/
- public abstract void checkMojoAttributes();
+ public abstract void checkMojoAttributes() throws MojoExecutionException;
+ private String getLogType(Object o) {
+ if (o instanceof Boolean
+ || o instanceof AtomicBoolean) return "B"; //$NON-NLS-1$
+ if (o instanceof Byte) return "b"; //$NON-NLS-1$
+ if (o instanceof Short) return "s"; //$NON-NLS-1$
+ if (o instanceof Integer
+ || o instanceof AtomicInteger) return "i"; //$NON-NLS-1$
+ if (o instanceof Long
+ || o instanceof AtomicLong) return "l"; //$NON-NLS-1$
+ if (o instanceof Float) return "f"; //$NON-NLS-1$
+ if (o instanceof Double) return "d"; //$NON-NLS-1$
+ if (o instanceof BigDecimal) return "D"; //$NON-NLS-1$
+ if (o instanceof BigInteger) return "I"; //$NON-NLS-1$
+ if (o instanceof String
+ || o instanceof StringBuffer) return "s"; //$NON-NLS-1$
+ if (o instanceof Array) {
+ Array a = (Array)o;
+ return a.getClass().getComponentType().getName()+"[]"; //$NON-NLS-1$
+ }
+ if (o instanceof Set<?>) return "set"; //$NON-NLS-1$
+ if (o instanceof Map<?,?>) return "map"; //$NON-NLS-1$
+ if (o instanceof List<?>) return "list"; //$NON-NLS-1$
+ if (o instanceof Collection<?>) return "col"; //$NON-NLS-1$
+ return "o"; //$NON-NLS-1$
+ }
+
/** Throw an exception when the given object is null.
*
* @param message is the message to put in the exception.
* @param o
*/
protected void assertNotNull(String message, Object o) {
+ if (getLog().isDebugEnabled()) {
+ StringBuffer b = new StringBuffer();
+ b.append("\t("); //$NON-NLS-1$
+ b.append(getLogType(o));
+ b.append(") "); //$NON-NLS-1$
+ b.append(message);
+ b.append(" = "); //$NON-NLS-1$
+ b.append(o);
+ getLog().debug(b.toString());
+ }
if (o==null) throw new AssertionError("assertNotNull: "+message); //$NON-NLS-1$
}
@@ -614,4 +782,92 @@
*/
protected abstract void executeMojo() throws MojoExecutionException;
+ /** Join the values with the given joint
+ *
+ * @param joint
+ * @param values
+ * @return the jointed values
+ */
+ protected static String join(String joint, String... values) {
+ StringBuffer b = new StringBuffer();
+ for(String value : values) {
+ if (value!=null && !EMPTY_STRING.equals(value)) {
+ if (b.length()>0) {
+ b.append(joint);
+ }
+ b.append(value);
+ }
+ }
+ return b.toString();
+ }
+
+ private void detectEncoding(File file, CharsetDecoder decoder) throws IOException, CharacterCodingException {
+ decoder.onMalformedInput(CodingErrorAction.REPORT);
+ decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+ ReadableByteChannel channel = Channels.newChannel(new FileInputStream(file));
+ Reader reader = Channels.newReader(channel, decoder, -1);
+ BufferedReader bReader = new BufferedReader(reader);
+ try {
+ String line = bReader.readLine();
+ while (line!=null) {
+ line = bReader.readLine();
+ }
+ }
+ finally {
+ channel.close();
+ }
+ }
+
+ /** Try to detect and reply the encoding of the given file.
+ * This function uses the charsets replied by {@link #getPreferredCharsets()}
+ * to select a charset when many are possible.
+ *
+ * @param file is the file to read.
+ * @return the encoding charset of the given file or <code>null</code>
+ * if the encoding could not be detected.
+ * @see #getPreferredCharsets()
+ * @see #setPreferredCharsets(Charset...)
+ */
+ protected Charset detectEncoding(File file) {
+ Collection<Charset> fittingCharsets = new TreeSet<Charset>();
+ for(Charset c : Charset.availableCharsets().values()) {
+ CharsetDecoder decoder = c.newDecoder();
+ try {
+ detectEncoding(file, decoder);
+ fittingCharsets.add(c);
+ }
+ catch(Throwable e) {
+ //
+ }
+ }
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("Valid charsets for "+file.getName()+":\n"+fittingCharsets.toString()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ for(Charset prefCharset : getPreferredCharsets()) {
+ if (prefCharset.canEncode() && fittingCharsets.contains(prefCharset)) {
+ getLog().debug("Use preferred charset for "+file.getName()+": "+prefCharset.displayName()); //$NON-NLS-1$ //$NON-NLS-2$
+ return prefCharset;
+ }
+ }
+
+ Charset platformCharset = Charset.defaultCharset();
+
+ if (platformCharset.canEncode() && fittingCharsets.contains(platformCharset)) {
+ getLog().debug("Use platform default charset for "+file.getName()+": "+platformCharset.displayName()); //$NON-NLS-1$ //$NON-NLS-2$
+ return Charset.defaultCharset();
+ }
+
+ Iterator<Charset> iterator = fittingCharsets.iterator();
+ while (iterator.hasNext()) {
+ Charset c = iterator.next();
+ if (c.canEncode()) {
+ getLog().debug("Use first valid charset for "+file.getName()+": "+c.displayName()); //$NON-NLS-1$ //$NON-NLS-2$
+ return c;
+ }
+ }
+
+ return null;
+ }
+
}
\ No newline at end of file
Modified: trunk/maventools/src/main/java/org/arakhne/maven/ExtendedArtifact.java
===================================================================
--- trunk/maventools/src/main/java/org/arakhne/maven/ExtendedArtifact.java 2011-08-06 14:07:15 UTC (rev 239)
+++ trunk/maventools/src/main/java/org/arakhne/maven/ExtendedArtifact.java 2011-08-13 12:45:42 UTC (rev 240)
@@ -1,9 +1,7 @@
/*
* $Id$
*
- * Copyright (C) 2010-11 Stéphane GALLAND
- *
- * This library is free software; you can redistribute it and/or
+ * Copyright (C) 2010-11 Stephane GALLAND This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
@@ -44,7 +42,7 @@
* contributors, authors, and website.
*
* @author $Author: galland$
- * @version $Name$ $Revision$ $Date$
+ * @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
@@ -62,6 +60,7 @@
private final String website;
private final Organization organization;
private final Scm scm;
+ private final String scmRevision;
private final List<? extends License> licenses;
/**
@@ -69,6 +68,7 @@
* @param name
* @param website
* @param organization
+ * @param scmRevision
* @param scm
* @param developers
* @param contributors
@@ -77,6 +77,7 @@
public ExtendedArtifact(
Artifact a, String name,
String website, Organization organization,
+ String scmRevision,
Scm scm,
List<? extends Developer> developers,
List<? extends Contributor> contributors,
@@ -88,6 +89,7 @@
this.website = website;
this.organization = organization;
this.scm = scm;
+ this.scmRevision = scmRevision;
this.licenses = licenses;
}
@@ -506,5 +508,13 @@
public void setOptional(boolean optional) {
this.original.setOptional(optional);
}
+
+ /** Replies the SCM revision for the artifact.
+ *
+ * @return the revision number in the SCM repository.
+ */
+ public String getScmRevision() {
+ return this.scmRevision;
+ }
} // class ExtendedArtifact
\ No newline at end of file
Modified: trunk/maventools/src/main/java/org/arakhne/maven/HtmlFileFilter.java
===================================================================
--- trunk/maventools/src/main/java/org/arakhne/maven/HtmlFileFilter.java 2011-08-06 14:07:15 UTC (rev 239)
+++ trunk/maventools/src/main/java/org/arakhne/maven/HtmlFileFilter.java 2011-08-13 12:45:42 UTC (rev 240)
@@ -1,9 +1,7 @@
/*
* $Id$
*
- * Copyright (C) 2010-11 Stéphane GALLAND
- *
- * This library is free software; you can redistribute it and/or
+ * Copyright (C) 2010-11 Stephane GALLAND This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
@@ -27,7 +25,7 @@
* File filter for HTML file.
*
* @author $Author: galland$
- * @version $Name$ $Revision$ $Date$
+ * @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
Modified: trunk/maventools/src/main/java/org/arakhne/maven/JavaSourceFileFilter.java
===================================================================
--- trunk/maventools/src/main/java/org/arakhne/maven/JavaSourceFileFilter.java 2011-08-06 14:07:15 UTC (rev 239)
+++ trunk/maventools/src/main/java/org/arakhne/maven/JavaSourceFileFilter.java 2011-08-13 12:45:42 UTC (rev 240)
@@ -1,9 +1,7 @@
/*
* $Id$
*
- * Copyright (C) 2010-11 Stéphane GALLAND
- *
- * This library is free software; you can redistribute it and/or
+ * Copyright (C) 2010-11 Stephane GALLAND This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
@@ -27,7 +25,7 @@
* File filter for HTML Java file.
*
* @author $Author: galland$
- * @version $Name$ $Revision$ $Date$
+ * @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
Modified: trunk/maventools/src/main/java/org/arakhne/maven/MultiFileFilter.java
===================================================================
--- trunk/maventools/src/main/java/org/arakhne/maven/MultiFileFilter.java 2011-08-06 14:07:15 UTC (rev 239)
+++ trunk/maventools/src/main/java/org/arakhne/maven/MultiFileFilter.java 2011-08-13 12:45:42 UTC (rev 240)
@@ -1,9 +1,7 @@
/*
* $Id$
*
- * Copyright (C) 2011 Stéphane GALLAND
- *
- * This library is free software; you can redistribute it and/or
+ * Copyright (C) 2011 Stephane GALLAND This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
@@ -31,7 +29,7 @@
* of file filters.
*
* @author $Author: galland$
- * @version $Name$ $Revision$ $Date$
+ * @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
Modified: trunk/maventools/src/main/java/org/arakhne/maven/PropertyFileFilter.java
===================================================================
--- trunk/maventools/src/main/java/org/arakhne/maven/PropertyFileFilter.java 2011-08-06 14:07:15 UTC (rev 239)
+++ trunk/maventools/src/main/java/org/arakhne/maven/PropertyFileFilter.java 2011-08-13 12:45:42 UTC (rev 240)
@@ -1,9 +1,7 @@
/*
* $Id$
*
- * Copyright (C) 2011 Stéphane GALLAND
- *
- * This library is free software; you can redistribute it and/or
+ * Copyright (C) 2011 Stephane GALLAND This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
@@ -27,7 +25,7 @@
* File filter for property file.
*
* @author $Author: galland$
- * @version $Name$ $Revision$ $Date$
+ * @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/