From: Mathieu Baudier Date: Fri, 24 Apr 2009 14:16:29 +0000 (+0000) Subject: New versions X-Git-Tag: argeo-slc-2.1.7~1972 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=18286b44ee18356985d0b435bd1aa3f34bc6425c;p=gpl%2Fargeo-slc.git New versions git-svn-id: https://svn.argeo.org/slc/trunk@2343 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/maven/maven-argeo-osgi-plugin/pom.xml b/maven/maven-argeo-osgi-plugin/pom.xml index af234f940..5480ddb34 100644 --- a/maven/maven-argeo-osgi-plugin/pom.xml +++ b/maven/maven-argeo-osgi-plugin/pom.xml @@ -1,8 +1,13 @@ 4.0.0 - org.argeo.slc.maven + + org.argeo.slc.maven + slc-maven + 0.1.1 + .. + maven-argeo-osgi-plugin - 0.1.3 + 0.1.4 maven-plugin Argeo OSGi Plugin @@ -10,10 +15,6 @@ maven-compiler-plugin - - 1.4 - 1.4 - maven-plugin-plugin @@ -31,45 +32,23 @@ org.apache.maven - maven-plugin-api - 2.0 + maven-project org.apache.maven - maven-script-ant - 2.0.9 + maven-plugin-api + + + org.codehaus.plexus + plexus-archiver org.apache.maven - maven-project - 2.0.7 + maven-script-ant ant-contrib ant-contrib - 1.0b3 - - - ant - ant - - - - - false - argeo-restricted - Argeo FOSS Repository - file:///var/argeo/maven2/argeo - - - - true - argeo-snapshots-restricted - Argeo FOSS Snapshots Repository - file:///var/argeo/maven2/argeo-snapshots - - - diff --git a/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/AbstractBundlesPackagerMojo.java b/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/AbstractBundlesPackagerMojo.java new file mode 100644 index 000000000..5fc37a776 --- /dev/null +++ b/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/AbstractBundlesPackagerMojo.java @@ -0,0 +1,190 @@ +package org.argeo.slc.maven.plugins.osgi; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.jar.Manifest; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; + +/** + * @author mbaudier + * + */ +public abstract class AbstractBundlesPackagerMojo extends AbstractOsgiMojo { + + /** + * The maven project. + * + * @parameter expression="${project}" + * @required + * @readonly + */ + protected MavenProject project; + + /** + * Directory of the simple bundles + * + * @parameter expression="${bundlesDirectory}" default-value="." + * @required + */ + private File bundlesDirectory; + + /** + * Directory containing the packaged bundles. + * + * @parameter expression="${packagedBundlesDir}" + * default-value="${project.build.directory}/argeo-osgi" + * @required + */ + protected File packagedBundlesDir; + + /** + * Artifact id for the dependency pom + * + * @parameter expression="${bundlesPomArtifactId}" default-value="bundles" + * @required + */ + protected String bundlesPomArtifactId; + + protected List analyze() 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(); + } + }); + for (int i = 0; i < bundleDirs.length; i++) { + File dir = bundleDirs[i]; + File manifestFile = manifestFileFromDir(dir); + String artifactId = dir.getName(); + File destFile = new File(packagedBundlesDir.getPath() + + File.separator + artifactId + ".jar"); + try { + Manifest manifest = readManifest(manifestFile); + // Symbolic name + String symbolicNameMf = manifest.getMainAttributes().getValue( + "Bundle-SymbolicName"); + if (!artifactId.equals(symbolicNameMf)) + getLog().warn( + "Symbolic name " + symbolicNameMf + + " does not match with directory name " + + artifactId); + + // Version + String versionMf = manifest.getMainAttributes().getValue( + "Bundle-Version"); + int qIndex = versionMf.lastIndexOf(".qualifier"); + String versionMfMain; + if (qIndex >= 0) + versionMfMain = versionMf.substring(0, qIndex); + else + versionMfMain = versionMf; + + int sIndex = project.getVersion().lastIndexOf("-SNAPSHOT"); + String versionMain; + boolean isSnapshot = false; + if (sIndex >= 0) {// SNAPSHOT + versionMain = project.getVersion().substring(0, sIndex); + isSnapshot = true; + } else { + versionMain = project.getVersion(); + } + + if (!versionMain.equals(versionMfMain)) + getLog() + .warn( + "Main manifest version " + + versionMfMain + + " of bundle " + + artifactId + + " do not match with main project version " + + versionMain); + + String newVersionMf; + String newVersionArt; + if (isSnapshot) { + newVersionMf = versionMfMain + ".SNAPSHOT"; + newVersionArt = versionMfMain + "-SNAPSHOT"; + } else { + newVersionMf = versionMfMain; + newVersionArt = versionMfMain; + } + + manifest.getMainAttributes().putValue("Bundle-Version", + newVersionMf); + Artifact artifact = artifactFactory.createBuildArtifact(project + .getGroupId(), artifactId, newVersionArt, "jar"); + BundlePackage bundlePackage = new BundlePackage(artifact, dir, + manifest, destFile); + list.add(bundlePackage); + } catch (Exception e) { + throw new MojoExecutionException("Could not analyze " + dir, e); + } + } + return list; + } + + protected File manifestFileFromDir(File dir) { + return new File(dir + File.separator + "META-INF" + File.separator + + "MANIFEST.MF"); + } + + protected File bundlesPomFile() { + return new File(packagedBundlesDir + File.separator + "bundles.pom"); + } + + protected Artifact bundlesPomArtifact() { + return artifactFactory.createBuildArtifact(project.getGroupId(), + bundlesPomArtifactId, project.getVersion(), "pom"); + } + + protected static class BundlePackage { + private final Artifact artifact; + private final File bundleDir; + private final Manifest manifest; + private final File packageFile; + + public BundlePackage(Artifact artifact, File bundleDir, + Manifest manifest, File packageFile) { + super(); + this.artifact = artifact; + this.bundleDir = bundleDir; + this.manifest = manifest; + this.packageFile = packageFile; + } + + public Artifact getArtifact() { + return artifact; + } + + public File getPackageFile() { + return packageFile; + } + + public File getBundleDir() { + return bundleDir; + } + + public Manifest getManifest() { + return manifest; + } + } + + protected Manifest readManifest(File file) throws IOException { + Manifest manifest = new Manifest(); + FileInputStream in = new FileInputStream(file); + manifest.read(in); + in.close(); + return manifest; + } +} diff --git a/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/AbstractOsgiMojo.java b/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/AbstractOsgiMojo.java new file mode 100644 index 000000000..30c4ffd60 --- /dev/null +++ b/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/AbstractOsgiMojo.java @@ -0,0 +1,53 @@ +package org.argeo.slc.maven.plugins.osgi; + +import java.io.File; + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.plugin.AbstractMojo; + +/** + * Factorize common configuration + */ +public abstract class AbstractOsgiMojo extends AbstractMojo { + /** + * List of Remote Repositories used by the resolver + * + * @parameter expression="${project.remoteArtifactRepositories}" + * @readonly + * @required + */ + protected java.util.List remoteRepos; + /** + * Location of the local repository. + * + * @parameter expression="${localRepository}" + * @readonly + * @required + */ + protected ArtifactRepository local; + + /** + * @parameter + * expression="${project.distributionManagementArtifactRepository}" + */ + protected ArtifactRepository deploymentRepository; + + /** + * The directory for the pom + * + * @parameter expression="${basedir}" + * @required + */ + protected File baseDir; + + /** + * Directory containing the build files. + * + * @parameter expression="${project.build.directory}" + */ + protected File buildDirectory; + + /** @component */ + protected org.apache.maven.artifact.factory.ArtifactFactory artifactFactory; + +} diff --git a/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/DeployBundlesMojo.java b/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/DeployBundlesMojo.java new file mode 100644 index 000000000..75b52b010 --- /dev/null +++ b/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/DeployBundlesMojo.java @@ -0,0 +1,47 @@ +package org.argeo.slc.maven.plugins.osgi; + +import java.io.File; +import java.util.List; + +import org.apache.maven.artifact.deployer.ArtifactDeployer; +import org.apache.maven.artifact.deployer.ArtifactDeploymentException; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; + +/** + * @goal deploy-bundles + * @phase deploy + * @author mbaudier + * + */ +public class DeployBundlesMojo extends AbstractBundlesPackagerMojo { + /** @component */ + private ArtifactDeployer deployer; + + public void execute() throws MojoExecutionException, MojoFailureException { + List bundlePackages = analyze(); + for (int i = 0; i < bundlePackages.size(); i++) { + AbstractBundlesPackagerMojo.BundlePackage bundlePackage = (BundlePackage) bundlePackages + .get(i); + try { + deployer.deploy(bundlePackage.getPackageFile(), bundlePackage + .getArtifact(), deploymentRepository, local); + } catch (ArtifactDeploymentException e) { + throw new MojoExecutionException("Could not deploy bundle " + + bundlePackage.getBundleDir(), e); + } + } + + // bundles POM + try { + deployer.deploy(bundlesPomFile(), bundlesPomArtifact(), + deploymentRepository, local); + deployer.deploy(new File(baseDir.getPath() + File.separator + + "pom.xml"), project.getArtifact(), deploymentRepository, + local); + } catch (ArtifactDeploymentException e) { + throw new MojoExecutionException("Could not deploy bundles POM", e); + } + + } +} diff --git a/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/InstallBundlesMojo.java b/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/InstallBundlesMojo.java new file mode 100644 index 000000000..d46ff5d40 --- /dev/null +++ b/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/InstallBundlesMojo.java @@ -0,0 +1,45 @@ +package org.argeo.slc.maven.plugins.osgi; + +import java.io.File; +import java.util.List; + +import org.apache.maven.artifact.installer.ArtifactInstallationException; +import org.apache.maven.artifact.installer.ArtifactInstaller; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; + +/** + * @goal install-bundles + * @phase install + * @author mbaudier + * + */ +public class InstallBundlesMojo extends AbstractBundlesPackagerMojo { + /** @component */ + private ArtifactInstaller installer; + + public void execute() throws MojoExecutionException, MojoFailureException { + List bundlePackages = analyze(); + for (int i = 0; i < bundlePackages.size(); i++) { + AbstractBundlesPackagerMojo.BundlePackage bundlePackage = (BundlePackage) bundlePackages + .get(i); + try { + installer.install(bundlePackage.getPackageFile(), bundlePackage + .getArtifact(), local); + } catch (ArtifactInstallationException e) { + throw new MojoExecutionException("Could not install bundle " + + bundlePackage.getBundleDir(), e); + } + } + + // Bundles pom + try { + installer.install(bundlesPomFile(), bundlesPomArtifact(), local); + installer.install(new File(baseDir.getPath() + File.separator + + "pom.xml"), project.getArtifact(), local); + } catch (ArtifactInstallationException e) { + throw new MojoExecutionException("Could not install bundles POM", e); + } + + } +} diff --git a/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/PackageBundlesMojo.java b/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/PackageBundlesMojo.java new file mode 100644 index 000000000..00da0777e --- /dev/null +++ b/maven/maven-argeo-osgi-plugin/src/main/java/org/argeo/slc/maven/plugins/osgi/PackageBundlesMojo.java @@ -0,0 +1,122 @@ +package org.argeo.slc.maven.plugins.osgi; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import java.util.jar.Attributes; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.archiver.util.DefaultFileSet; + +/** + * @goal package-bundles + * @phase package + * @author mbaudier + * + */ +public class PackageBundlesMojo extends AbstractBundlesPackagerMojo { + + public void execute() throws MojoExecutionException, MojoFailureException { + StringBuffer bundlesPom = new StringBuffer(); + // not using append() systematically for the sake of clarity + bundlesPom.append("\n"); + bundlesPom.append("\t4.0.0\n"); + bundlesPom.append("\t\n"); + bundlesPom.append("\t\t" + + project.getParentArtifact().getGroupId() + "\n"); + bundlesPom.append("\t\t" + + project.getParentArtifact().getArtifactId() + + "\n"); + bundlesPom.append("\t\t" + + project.getParentArtifact().getVersion() + "\n"); + bundlesPom.append("\t\n"); + bundlesPom + .append("\t" + project.getGroupId() + "\n"); + bundlesPom.append("\t" + bundlesPomArtifactId + + "\n"); + bundlesPom.append("\tpom\n"); + bundlesPom.append("\t\n"); + + List bundlePackages = analyze(); + + for (int i = 0; i < bundlePackages.size(); i++) { + AbstractBundlesPackagerMojo.BundlePackage bundlePackage = (BundlePackage) bundlePackages + .get(i); + + File manifestFile = new File(bundlePackage.getPackageFile() + .getPath() + + ".MF"); + + // Package as jar + JarArchiver jarArchiver = new JarArchiver(); + jarArchiver.setDestFile(bundlePackage.getPackageFile()); + DefaultFileSet fileSet = new DefaultFileSet(); + fileSet.setDirectory(bundlePackage.getBundleDir()); + String[] includes = { "**/*" }; + String[] excludes = { "**/.svn", "**/.svn/**" }; + fileSet.setIncludes(includes); + fileSet.setExcludes(excludes); + try { + jarArchiver.addFileSet(fileSet); + + // Write manifest + FileOutputStream out = new FileOutputStream(manifestFile); + bundlePackage.getManifest().getMainAttributes().put( + Attributes.Name.MANIFEST_VERSION, "1.0"); + + System.out.println("# BUNDLE " + + bundlePackage.getArtifact().getArtifactId()); + Attributes mainAttrs = bundlePackage.getManifest() + .getMainAttributes(); + for (Iterator it = mainAttrs.keySet().iterator(); it.hasNext();) { + Object key = it.next(); + Object value = mainAttrs.get(key); + System.out.println(key + ": " + value); + } + + bundlePackage.getManifest().write(out); + out.close(); + jarArchiver.setManifest(manifestFile); + + jarArchiver.createArchive(); + } catch (Exception e) { + throw new MojoExecutionException("Could not package bundle " + + bundlePackage.getBundleDir(), e); + } + + // update dependencies POM + bundlesPom.append("\t\t\n"); + bundlesPom + .append("\t\t\t" + + bundlePackage.getArtifact().getGroupId() + + "\n"); + bundlesPom.append("\t\t\t" + + bundlePackage.getArtifact().getArtifactId() + + "\n"); + bundlesPom + .append("\t\t\t" + + bundlePackage.getArtifact().getVersion() + + "\n"); + bundlesPom.append("\t\t\n"); + + } + + bundlesPom.append("\t\n"); + bundlesPom.append("\n"); + + try { + FileWriter writer = new FileWriter(bundlesPomFile()); + writer.write(bundlesPom.toString()); + writer.close(); + } catch (IOException e) { + throw new MojoExecutionException("Could not write dependency pom", + e); + } + } + +} diff --git a/maven/maven-argeo-osgi-plugin/src/main/resources/META-INF/plexus/components.xml b/maven/maven-argeo-osgi-plugin/src/main/resources/META-INF/plexus/components.xml new file mode 100644 index 000000000..d9ad3c56d --- /dev/null +++ b/maven/maven-argeo-osgi-plugin/src/main/resources/META-INF/plexus/components.xml @@ -0,0 +1,25 @@ + + + + org.apache.maven.lifecycle.mapping.LifecycleMapping + + bundles + + org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping + + + + + org.argeo.slc.maven:maven-argeo-osgi-plugin:package-bundles + + + org.argeo.slc.maven:maven-argeo-osgi-plugin:install-bundles + + + org.argeo.slc.maven:maven-argeo-osgi-plugin:deploy-bundles + + + + + + diff --git a/maven/maven-argeo-osgi-plugin/src/main/scripts/argeo-osgi.mojos.xml b/maven/maven-argeo-osgi-plugin/src/main/scripts/argeo-osgi.mojos.xml index a29990b64..289783418 100644 --- a/maven/maven-argeo-osgi-plugin/src/main/scripts/argeo-osgi.mojos.xml +++ b/maven/maven-argeo-osgi-plugin/src/main/scripts/argeo-osgi.mojos.xml @@ -1,8 +1,8 @@ - simple-bundles - simple-bundles + simple-bundles-old + simple-bundles-old Process a simple bundle (no Java) diff --git a/maven/maven-argeo-qooxdoo-plugin/pom.xml b/maven/maven-argeo-qooxdoo-plugin/pom.xml index 29bb3db34..25f8fae04 100644 --- a/maven/maven-argeo-qooxdoo-plugin/pom.xml +++ b/maven/maven-argeo-qooxdoo-plugin/pom.xml @@ -1,9 +1,14 @@ - + 4.0.0 - org.argeo.slc.maven - maven-argeo-qooxdoo-plugin - - 0.8.1.3 + + org.argeo.slc.maven + slc-maven + 0.1.1 + .. + + maven-argeo-qooxdoo-plugin + 0.8.1.4 maven-plugin Argeo Qooxdoo Plugin @@ -19,47 +24,21 @@ + + org.argeo.slc.maven + org.argeo.slc.maven.plugin + org.apache.maven maven-plugin-api - 2.0 org.apache.maven maven-project - 2.0.7 org.codehaus.plexus plexus-archiver - 1.0-alpha-9 - - - org.codehaus.plexus - plexus-container-default - - - - org.codehaus.plexus - plexus-component-api - - - - - false - argeo-restricted - Argeo FOSS Repository - file:///var/argeo/maven2/argeo - - - - true - argeo-snapshots-restricted - Argeo FOSS Snapshots Repository - file:///var/argeo/maven2/argeo-snapshots - - - diff --git a/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/AbstractQooxdooMojo.java b/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/AbstractQooxdooMojo.java new file mode 100644 index 000000000..290366e83 --- /dev/null +++ b/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/AbstractQooxdooMojo.java @@ -0,0 +1,112 @@ +package org.argeo.slc.maven.plugins.qooxdoo; + +import java.io.File; + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.plugin.AbstractMojo; +import org.argeo.slc.maven.plugin.MavenDependencyManager; + +/** + * Factorize common configuration + */ +public abstract class AbstractQooxdooMojo extends AbstractMojo { + /** + * List of Remote Repositories used by the resolver + * + * @parameter expression="${project.remoteArtifactRepositories}" + * @readonly + * @required + */ + protected java.util.List remoteRepos; + /** + * Location of the local repository. + * + * @parameter expression="${localRepository}" + * @readonly + * @required + */ + protected org.apache.maven.artifact.repository.ArtifactRepository local; + + /** + * The directory for the pom + * + * @parameter expression="${basedir}" + * @required + */ + protected File baseDir; + + /** + * Dependency manager + * + * @component + */ + protected MavenDependencyManager depManager; + + /** + * Source base where Qooxdoo SDK will be unpacked + * + * @parameter expression="${srcBase}" default-value="src" + * @required + */ + protected File srcBase; + + /** + * Qooxdoo cache location + * + * @parameter expression="${cache}" default-value="cache" + * @required + */ + protected File cache; + + /** + * Name of the SDK directory (the base dire in the unpacked distribution) + * + * @parameter expression="${sdkDirName}" default-value="qooxdoo-sdk" + * @required + */ + protected String sdkDirName; + + /** + * SDK maven groupId + * + * @parameter expression="${sdkGroupId}" default-value="org.argeo.dep.dist" + * @required + */ + protected String sdkGroupId; + + /** + * SDK maven artifactId + * + * @parameter expression="${sdkArtifactId}" default-value="qooxdoo-sdk" + * @required + */ + protected String sdkArtifactId; + + /** + * SDK maven classifier + * + * @parameter expression="${sdkClassifier}" default-value="dist" + * @required + */ + protected String sdkClassifier; + + /** + * SDK maven version + * + * @parameter expression="${sdkVersion}" default-value="0.8.1.argeo.1" + * @required + */ + protected String sdkVersion; + + /** + * SDK maven type + * + * @parameter expression="${sdkType}" default-value="zip" + * @required + */ + protected String sdkType; + + protected File getSdkDir() { + return new File(srcBase.getPath() + File.separator + sdkDirName); + } +} diff --git a/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/EnvironmentMojo.java b/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/EnvironmentMojo.java index c1326be39..c618b64ce 100644 --- a/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/EnvironmentMojo.java +++ b/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/EnvironmentMojo.java @@ -1,139 +1,24 @@ package org.argeo.slc.maven.plugins.qooxdoo; -import java.io.File; - import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.codehaus.plexus.archiver.ArchiverException; -import org.codehaus.plexus.archiver.UnArchiver; -import org.codehaus.plexus.archiver.manager.ArchiverManager; -import org.codehaus.plexus.archiver.manager.NoSuchArchiverException; /** * Prepares Qooxdoo environment * * @goal env */ -public class EnvironmentMojo extends AbstractMojo { - /** - * Used to look up Artifacts in the remote repository. - * - * @parameter expression= - * "${component.org.apache.maven.artifact.factory.ArtifactFactory}" - * @required - * @readonly - */ - protected org.apache.maven.artifact.factory.ArtifactFactory factory; - - /** - * Used to look up Artifacts in the remote repository. - * - * @parameter expression= - * "${component.org.apache.maven.artifact.resolver.ArtifactResolver}" - * @required - * @readonly - */ - protected org.apache.maven.artifact.resolver.ArtifactResolver resolver; - - /** - * Location of the local repository. - * - * @parameter expression="${localRepository}" - * @readonly - * @required - */ - protected org.apache.maven.artifact.repository.ArtifactRepository local; - - /** - * List of Remote Repositories used by the resolver - * - * @parameter expression="${project.remoteArtifactRepositories}" - * @readonly - * @required - */ - protected java.util.List remoteRepos; - /** - * To look up Archiver/UnArchiver implementations - * - * @parameter expression= - * "${component.org.codehaus.plexus.archiver.manager.ArchiverManager}" - * @required - * @readonly - */ - protected ArchiverManager archiverManager; - - /** - * Source base where Qooxdoo SDK will be unpacked - * - * @parameter expression="${srcBase}" default-value="src" - * @required - */ - private File srcBase; - - private String qxSdkDirName = "qooxdoo-sdk"; - - private String qxSdkGroupId = "org.argeo.dep.dist"; - private String qxSdkArtifactId = "qooxdoo-sdk"; - private String qxSdkClassifier = "dist"; - private String qxSdkVersion = "0.8.1.argeo.1"; - private String qxSdkType = "zip"; +public class EnvironmentMojo extends AbstractQooxdooMojo { public void execute() throws MojoExecutionException, MojoFailureException { - Artifact qxSdkArtifact = getQxSdkArtifact(); - File qxSdkDir = new File(srcBase.getPath() + File.separator - + qxSdkDirName); - if (!qxSdkDir.exists()) - unpackArtifact(qxSdkArtifact, srcBase); + Artifact qxSdkArtifact = depManager.getResolvedArtifact(remoteRepos, + local, sdkGroupId, sdkArtifactId, sdkVersion, sdkType, + sdkClassifier, Artifact.SCOPE_COMPILE); + if (!getSdkDir().exists()) + depManager.unpackArtifact(qxSdkArtifact, srcBase); else - getLog() - .warn("Qooxdoo SDK already unpacked, skipping unpacking..."); + getLog().warn("Qooxdoo SDK already unpacked, skip unpacking..."); getLog().info("Qooxdoo environment prepared"); } - - protected Artifact getQxSdkArtifact() throws MojoExecutionException { - VersionRange vr; - try { - vr = VersionRange.createFromVersionSpec(qxSdkVersion); - } catch (InvalidVersionSpecificationException e1) { - e1.printStackTrace(); - vr = VersionRange.createFromVersion(qxSdkVersion); - } - - Artifact qxSdkArtifact = factory.createDependencyArtifact(qxSdkGroupId, - qxSdkArtifactId, vr, qxSdkType, qxSdkClassifier, - Artifact.SCOPE_COMPILE); - try { - resolver.resolve(qxSdkArtifact, remoteRepos, local); - } catch (ArtifactResolutionException e) { - throw new MojoExecutionException("Unable to resolve artifact.", e); - } catch (ArtifactNotFoundException e) { - throw new MojoExecutionException("Unable to find artifact.", e); - } - - return qxSdkArtifact; - } - - protected void unpackArtifact(Artifact artifact, File location) - throws MojoExecutionException { - File file = artifact.getFile(); - try { - UnArchiver unArchiver; - unArchiver = archiverManager.getUnArchiver(file); - unArchiver.setSourceFile(file); - unArchiver.setDestDirectory(location); - unArchiver.extract(); - } catch (NoSuchArchiverException e) { - throw new MojoExecutionException("Unknown archiver type", e); - } catch (ArchiverException e) { - e.printStackTrace(); - throw new MojoExecutionException("Error unpacking file: " + file - + " to: " + location + "\r\n" + e.toString(), e); - } - } } diff --git a/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java b/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java index 61988cbd0..9c581df57 100644 --- a/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java +++ b/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/GenerateMojo.java @@ -2,7 +2,6 @@ package org.argeo.slc.maven.plugins.qooxdoo; import java.io.File; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; @@ -16,7 +15,7 @@ import org.codehaus.plexus.util.cli.StreamConsumer; * * @goal generate */ -public class GenerateMojo extends AbstractMojo { +public class GenerateMojo extends AbstractQooxdooMojo { /** * The Qooxdoo build target. * @@ -24,34 +23,11 @@ public class GenerateMojo extends AbstractMojo { * @required */ private String job; - - /** - * Location of the qooxdoo sdk. - * - * @parameter expression="${qooxdooSdk}" default-value="src/qooxdoo-sdk" - */ - private String qooxdooSdk; - - /** - * The build directory. - * - * @parameter expression="${project.build.directory}" - * @required - */ - private File buildDirectory; - - /** - * The directory for the pom - * - * @parameter expression="${basedir}" - * @required - */ - private File baseDir; public void execute() throws MojoExecutionException, MojoFailureException { try { - File generateScript = new File(baseDir.getPath() + File.separator - + qooxdooSdk + File.separator + "tool" + File.separator + File generateScript = new File(srcBase+ File.separator + + sdkDirName + File.separator + "tool" + File.separator + "bin", "generator.py"); getLog().info("Running Qooxdoo job: " + job + " ..."); diff --git a/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/ResetMojo.java b/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/ResetMojo.java new file mode 100644 index 000000000..4d0aa24f7 --- /dev/null +++ b/maven/maven-argeo-qooxdoo-plugin/src/main/java/org/argeo/slc/maven/plugins/qooxdoo/ResetMojo.java @@ -0,0 +1,35 @@ +package org.argeo.slc.maven.plugins.qooxdoo; + +import java.io.File; +import java.io.IOException; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.codehaus.plexus.util.FileUtils; + +/** + * Reset Qooxdoo context: removes SDK, clean cache, etc. + * + * @goal reset + */ +public class ResetMojo extends AbstractQooxdooMojo { + public void execute() throws MojoExecutionException, MojoFailureException { + if (getSdkDir().exists()) { + delete(getSdkDir()); + } + + if (cache.exists()) { + delete(cache); + } + + } + + protected void delete(File dir) throws MojoExecutionException { + try { + FileUtils.deleteDirectory(dir); + getLog().info("Deleted directory " + dir); + } catch (IOException e) { + throw new MojoExecutionException("Cannot delete " + dir, e); + } + } +} diff --git a/maven/org.argeo.slc.maven.plugin/.classpath b/maven/org.argeo.slc.maven.plugin/.classpath new file mode 100644 index 000000000..30baf1326 --- /dev/null +++ b/maven/org.argeo.slc.maven.plugin/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/maven/org.argeo.slc.maven.plugin/.project b/maven/org.argeo.slc.maven.plugin/.project new file mode 100644 index 000000000..25790ca7e --- /dev/null +++ b/maven/org.argeo.slc.maven.plugin/.project @@ -0,0 +1,23 @@ + + + org.argeo.slc.maven.plugin + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.maven.ide.eclipse.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/maven/org.argeo.slc.maven.plugin/pom.xml b/maven/org.argeo.slc.maven.plugin/pom.xml new file mode 100644 index 000000000..401d6880d --- /dev/null +++ b/maven/org.argeo.slc.maven.plugin/pom.xml @@ -0,0 +1,35 @@ + + 4.0.0 + + org.argeo.slc.maven + slc-maven + 0.1.1 + .. + + org.argeo.slc.maven.plugin + jar + Argeo Maven Plugin Development Support + + + + + maven-compiler-plugin + + + + + + org.apache.maven + maven-plugin-api + + + org.apache.maven + maven-project + + + org.codehaus.plexus + plexus-archiver + + + diff --git a/maven/org.argeo.slc.maven.plugin/src/main/java/org/argeo/slc/maven/plugin/DefaultMavenDependencyManager.java b/maven/org.argeo.slc.maven.plugin/src/main/java/org/argeo/slc/maven/plugin/DefaultMavenDependencyManager.java new file mode 100644 index 000000000..0c432acde --- /dev/null +++ b/maven/org.argeo.slc.maven.plugin/src/main/java/org/argeo/slc/maven/plugin/DefaultMavenDependencyManager.java @@ -0,0 +1,97 @@ +package org.argeo.slc.maven.plugin; + +import java.io.File; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.plugin.MojoExecutionException; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.UnArchiver; +import org.codehaus.plexus.archiver.manager.ArchiverManager; +import org.codehaus.plexus.archiver.manager.NoSuchArchiverException; + +/** + * Abstract Maven plugin for interacting with dependencies + */ +public class DefaultMavenDependencyManager implements MavenDependencyManager { + /** + * Used to look up Artifacts in the remote repository. + * + * @parameter expression= + * "${component.org.apache.maven.artifact.factory.ArtifactFactory}" + * @required + * @readonly + */ + protected org.apache.maven.artifact.factory.ArtifactFactory factory; + + /** + * Used to look up Artifacts in the remote repository. + * + * @parameter expression= + * "${component.org.apache.maven.artifact.resolver.ArtifactResolver}" + * @required + * @readonly + */ + protected org.apache.maven.artifact.resolver.ArtifactResolver resolver; + + /** + * To look up Archiver/UnArchiver implementations + * + * @parameter expression= + * "${component.org.codehaus.plexus.archiver.manager.ArchiverManager}" + * @required + * @readonly + */ + protected ArchiverManager archiverManager; + + public DefaultMavenDependencyManager() { + } + + public Artifact getResolvedArtifact(List remoteRepos, + ArtifactRepository local, String groupId, String artifactId, + String version, String type, String classifier, String scope) + throws MojoExecutionException { + VersionRange vr; + try { + vr = VersionRange.createFromVersionSpec(version); + } catch (InvalidVersionSpecificationException e1) { + e1.printStackTrace(); + vr = VersionRange.createFromVersion(version); + } + + Artifact qxSdkArtifact = factory.createDependencyArtifact(groupId, + artifactId, vr, type, classifier, scope); + try { + resolver.resolve(qxSdkArtifact, remoteRepos, local); + } catch (ArtifactResolutionException e) { + throw new MojoExecutionException("Unable to resolve artifact.", e); + } catch (ArtifactNotFoundException e) { + throw new MojoExecutionException("Unable to find artifact.", e); + } + + return qxSdkArtifact; + } + + public void unpackArtifact(Artifact artifact, File location) + throws MojoExecutionException { + File file = artifact.getFile(); + try { + UnArchiver unArchiver; + unArchiver = archiverManager.getUnArchiver(file); + unArchiver.setSourceFile(file); + unArchiver.setDestDirectory(location); + unArchiver.extract(); + } catch (NoSuchArchiverException e) { + throw new MojoExecutionException("Unknown archiver type", e); + } catch (ArchiverException e) { + e.printStackTrace(); + throw new MojoExecutionException("Error unpacking file: " + file + + " to: " + location + "\r\n" + e.toString(), e); + } + } +} diff --git a/maven/org.argeo.slc.maven.plugin/src/main/java/org/argeo/slc/maven/plugin/MavenDependencyManager.java b/maven/org.argeo.slc.maven.plugin/src/main/java/org/argeo/slc/maven/plugin/MavenDependencyManager.java new file mode 100644 index 000000000..09bae0245 --- /dev/null +++ b/maven/org.argeo.slc.maven.plugin/src/main/java/org/argeo/slc/maven/plugin/MavenDependencyManager.java @@ -0,0 +1,21 @@ +package org.argeo.slc.maven.plugin; + +import java.io.File; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.plugin.MojoExecutionException; + +public interface MavenDependencyManager { + String ROLE = MavenDependencyManager.class.getName(); + + public Artifact getResolvedArtifact(List remoteRepos, + ArtifactRepository local, String groupId, String artifactId, + String version, String type, String classifier, String scope) + throws MojoExecutionException; + + public void unpackArtifact(Artifact artifact, File location) + throws MojoExecutionException; + +} diff --git a/maven/org.argeo.slc.maven.plugin/src/main/resources/META-INF/plexus/components.xml b/maven/org.argeo.slc.maven.plugin/src/main/resources/META-INF/plexus/components.xml new file mode 100644 index 000000000..0d76e0d10 --- /dev/null +++ b/maven/org.argeo.slc.maven.plugin/src/main/resources/META-INF/plexus/components.xml @@ -0,0 +1,29 @@ + + + + org.argeo.slc.maven.plugin.MavenDependencyManager + + + org.argeo.slc.maven.plugin.DefaultMavenDependencyManager + + + + org.apache.maven.artifact.factory.ArtifactFactory + + factory + + + org.apache.maven.artifact.resolver.ArtifactResolver + + resolver + + + org.codehaus.plexus.archiver.manager.ArchiverManager + + archiverManager + + + + + +