org.ow2.util.maven.jbuilding.GenerateSUGroupMojo Maven / Gradle / Ivy
/**
* OW2 Util
* Copyright (C) 2010 Bull S.A.S.
* Copyright (C) 2010 INRIA, SARDES
* Contact: [email protected]
*
* 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.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
* --------------------------------------------------------------------------
* $Id: GenerateSUGroupMojo.java 5519 2010-06-01 15:48:16Z loris $
* --------------------------------------------------------------------------
*/
package org.ow2.util.maven.jbuilding;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Date;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.util.FileUtils;
/**
* Generate SU group.
*
* @goal generate-su-group
* @author Loris Bouzonnet
*/
public class GenerateSUGroupMojo extends AbstractResolverMojo {
/**
* Location new resources directory.
*
* @parameter expression="${project.build.directory}/generated-su-resources"
* @required
*/
private File output;
/**
* Group name.
*
* @parameter expression="jonas-autodeploy-bundles"
* @required
*/
private String group;
public void execute() throws MojoExecutionException, MojoFailureException {
final Collection artifactsToInstall =
resolveArtifacts(SERVER_SIDE, BOTH_MODE,
AUTO_DEPLOY_ARTIFACT_ITEMS).get(
AUTO_DEPLOY_ARTIFACT_ITEMS);
// OK, now we're sure that everything is in the local repository
// We will generate a xml file
final File propertyFile =
new File(this.output, this.group + "-su.xml");
final File parent = propertyFile.getParentFile();
// Create the directory
if (!parent.exists()) {
if (!parent.mkdirs()) {
throw new MojoExecutionException("Cannot create directory: "
+ parent);
}
}
// Generate the xml
final StringBuilder sb = new StringBuilder();
sb.append("\n");
sb.append("\n");
sb.append("\n");
if (artifactsToInstall != null) {
for (final Artifact artifact : artifactsToInstall) {
sb.append(" \n");
sb.append(" \n");
sb.append(" " + artifact.getGroupId() + " \n");
sb.append(" " + artifact.getArtifactId() + " \n");
if (artifact.getClassifier() != null) {
sb.append(" " + artifact.getClassifier() + " \n");
}
sb.append(" " + artifact.getVersion() + " \n");
sb.append(" " + artifact.getType() + " \n");
sb.append(" \n");
sb.append(" \n");
}
}
sb.append(" ");
// add a final EOL
sb.append("\n");
// Flush the content
try {
FileUtils.fileWrite(propertyFile.getPath(), sb.toString());
} catch (final IOException e) {
throw new MojoExecutionException("Cannot create file "
+ propertyFile);
}
}
/**
* @return the output file.
*/
public File getOutput() {
return this.output;
}
/**
* @return the group.
*/
public String getGroup() {
return this.group;
}
/**
* Set the given output.
*
* @param output
* the output file
*/
public void setOutput(final File output) {
this.output = output;
}
/**
* Sets the given group.
*
* @param group
* the group name
*/
public void setGroup(final String group) {
this.group = group;
}
}