import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
-import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.jar.Manifest;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.metadata.ArtifactMetadata;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.artifact.ProjectArtifactMetadata;
/**
+ * Base class for MoJo analyzing a set of bundles directories.
+ *
* @author mbaudier
*
*/
protected List analyze(boolean willGenerate) throws MojoExecutionException {
List list = new ArrayList();
- File[] bundleDirs = bundlesDirectory.listFiles(new FileFilter() {
- public boolean accept(File file) {
- if (!file.isDirectory())
- return false;
-
- return manifestFileFromDir(file).exists();
- }
- });
+ File[] bundleDirs = bundlesDirectory.listFiles(bundleFileFilter());
for (int i = 0; i < bundleDirs.length; i++) {
File dir = bundleDirs[i];
else
versionMfMain = versionMf;
- int sIndex = project.getModel().getVersion().lastIndexOf("-SNAPSHOT");
+ int sIndex = snapshotIndex();
String versionMain;
String buildId;
boolean isSnapshot = false;
if (sIndex >= 0) {// SNAPSHOT
- versionMain = project.getVersion().substring(0, sIndex);
+ versionMain = versionMain(sIndex);
// buildId = "D_" + sdf.format(new Date());// D for dev
buildId = "SNAPSHOT";
isSnapshot = true;
if (debug && willGenerate) {
getLog().info("\n## " + artifactId);
getLog().info("project.getVersion()=" + project.getVersion());
- // getLog().info(
- // "project.getModel().getVersion()="
- // + project.getModel().getVersion());
- // getLog().info("versionMf=" + versionMf);
- // getLog().info("buildId=" + buildId);
getLog().info("newVersionMf=" + newVersionMf);
}
return pom.toString();
}
+ protected Manifest readManifest(File file) throws IOException {
+ Manifest manifest = new Manifest();
+ FileInputStream in = new FileInputStream(file);
+ manifest.read(in);
+ in.close();
+ return manifest;
+ }
+
+ protected int snapshotIndex() {
+ return project.getModel().getVersion().lastIndexOf("-SNAPSHOT");
+ }
+
+ protected String versionMain(int sIndex) {
+ return project.getVersion().substring(0, sIndex);
+ }
+
+ protected File getBundleDirectory() {
+ return bundlesDirectory;
+ }
+
+ protected FileFilter bundleFileFilter() {
+ return new FileFilter() {
+ public boolean accept(File file) {
+ if (!file.isDirectory())
+ return false;
+
+ return manifestFileFromDir(file).exists();
+ }
+ };
+ }
+
protected static class BundlePackage {
private final Artifact artifact;
private final File bundleDir;
public File getPomFile() {
return new File(getPackageFile().getPath() + ".pom.xml");
}
- }
- protected Manifest readManifest(File file) throws IOException {
- Manifest manifest = new Manifest();
- FileInputStream in = new FileInputStream(file);
- manifest.read(in);
- in.close();
- return manifest;
+ public String toString() {
+ return "Bundle: " + bundleDir;
+ }
+
}
+
}