Author: veithen Date: Sun Aug 1 14:59:17 2010 New Revision: 981237 URL: http://svn.apache.org/viewvc?rev=981237&view=rev Log: Enhanced the axis2-repo-maven-plugin so that it can write services.list and modules.list files. This will eventually allow us to get rid of the Groovy stuff in the distribution module.
Added: axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/ArchiveDeployer.java (with props) Modified: axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/AbstractCreateRepositoryMojo.java Modified: axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/AbstractCreateRepositoryMojo.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/AbstractCreateRepositoryMojo.java?rev=981237&r1=981236&r2=981237&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/AbstractCreateRepositoryMojo.java (original) +++ axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/AbstractCreateRepositoryMojo.java Sun Aug 1 14:59:17 2010 @@ -21,8 +21,10 @@ package org.apache.axis2.maven2.repo; import java.io.File; import java.io.IOException; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import org.apache.maven.artifact.Artifact; @@ -126,6 +128,14 @@ public abstract class AbstractCreateRepo */ private boolean useModules; + /** + * Specifies whether the plugin should generate <tt>services.list</tt> and <tt>modules.list</tt> + * files. + * + * @parameter default-value="false" + */ + private boolean generateFileLists; + protected abstract String getScope(); protected abstract File getOutputDirectory(); @@ -151,18 +161,16 @@ public abstract class AbstractCreateRepo } artifacts = replaceIncompleteArtifacts(artifacts); File outputDirectory = getOutputDirectory(); - File servicesDirectory = new File(outputDirectory, this.servicesDirectory); - File modulesDirectory = new File(outputDirectory, this.modulesDirectory); + Map<String,ArchiveDeployer> deployers = new HashMap<String,ArchiveDeployer>(); + deployers.put("aar", new ArchiveDeployer(outputDirectory, servicesDirectory, "services.list", generateFileLists)); + deployers.put("mar", new ArchiveDeployer(outputDirectory, modulesDirectory, "modules.list", generateFileLists)); for (Artifact artifact : artifacts) { String type = artifact.getType(); - String destFileName = artifact.getArtifactId() + "-" + artifact.getVersion() + "." + type; - File targetDir = type.equals("mar") ? modulesDirectory : servicesDirectory; - getLog().info("Adding " + destFileName); - try { - FileUtils.copyFile(artifact.getFile(), new File(targetDir, destFileName)); - } catch (IOException ex) { - throw new MojoExecutionException("Error copying " + destFileName + ": " + ex.getMessage(), ex); + ArchiveDeployer deployer = deployers.get(type); + if (deployer == null) { + throw new MojoExecutionException("No deployer found for artifact type " + type); } + deployer.deploy(getLog(), artifact); } if (axis2xml != null) { getLog().info("Copying axis2.xml"); @@ -174,6 +182,9 @@ public abstract class AbstractCreateRepo throw new MojoExecutionException("Error copying axis2.xml file: " + ex.getMessage(), ex); } } + for (ArchiveDeployer deployer : deployers.values()) { + deployer.finish(getLog()); + } } /** Added: axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/ArchiveDeployer.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/ArchiveDeployer.java?rev=981237&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/ArchiveDeployer.java (added) +++ axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/ArchiveDeployer.java Sun Aug 1 14:59:17 2010 @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.maven2.repo; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.logging.Log; +import org.codehaus.plexus.util.FileUtils; + +/** + * Deploys artifacts of a given type into an Axis2 repository. + */ +public class ArchiveDeployer { + private final File directory; + private final String fileListName; + private final boolean generateFileList; + private final List<String> files = new ArrayList<String>(); + + public ArchiveDeployer(File repositoryDirectory, String directory, String fileListName, boolean generateFileList) { + this.directory = new File(repositoryDirectory, directory); + this.fileListName = fileListName; + this.generateFileList = generateFileList; + } + + public void deploy(Log log, Artifact artifact) throws MojoExecutionException { + String destFileName = artifact.getArtifactId() + "-" + artifact.getVersion() + "." + artifact.getType(); + log.info("Adding " + destFileName); + try { + FileUtils.copyFile(artifact.getFile(), new File(directory, destFileName)); + } catch (IOException ex) { + throw new MojoExecutionException("Error copying " + destFileName + ": " + ex.getMessage(), ex); + } + files.add(destFileName); + } + + public void finish(Log log) throws MojoExecutionException { + if (generateFileList && !files.isEmpty()) { + log.info("Writing " + fileListName); + try { + OutputStream out = new FileOutputStream(new File(directory, fileListName)); + try { + Writer writer = new OutputStreamWriter(out, "UTF-8"); + for (String file : files) { + writer.write(file); + writer.write('\n'); + } + writer.flush(); + } finally { + out.close(); + } + } catch (IOException ex) { + throw new MojoExecutionException("Error writing " + fileListName + ": " + ex.getMessage(), ex); + } + } + } +} Propchange: axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/ArchiveDeployer.java ------------------------------------------------------------------------------ svn:eol-style = native