You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ve...@apache.org on 2008/06/29 01:35:36 UTC
svn commit: r672593 - in /synapse/trunk/java: ./ modules/xar-maven-plugin/
modules/xar-maven-plugin/src/ modules/xar-maven-plugin/src/main/
modules/xar-maven-plugin/src/main/java/
modules/xar-maven-plugin/src/main/java/org/ modules/xar-maven-plugin/src...
Author: veithen
Date: Sat Jun 28 16:35:36 2008
New Revision: 672593
URL: http://svn.apache.org/viewvc?rev=672593&view=rev
Log:
SYNAPSE-377: Added initial version of the XAR Maven plugin
Added:
synapse/trunk/java/modules/xar-maven-plugin/
synapse/trunk/java/modules/xar-maven-plugin/pom.xml
synapse/trunk/java/modules/xar-maven-plugin/src/
synapse/trunk/java/modules/xar-maven-plugin/src/main/
synapse/trunk/java/modules/xar-maven-plugin/src/main/java/
synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/
synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/
synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/
synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/
synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/
synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/AbstractXarMojo.java
synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ClassScanner.java
synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ClassScannerException.java
synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ClassVisitor.java
synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ServiceLocator.java
synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/XarExplodedMojo.java
synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/XarMojo.java
synapse/trunk/java/modules/xar-maven-plugin/src/main/resources/
synapse/trunk/java/modules/xar-maven-plugin/src/main/resources/META-INF/
synapse/trunk/java/modules/xar-maven-plugin/src/main/resources/META-INF/plexus/
synapse/trunk/java/modules/xar-maven-plugin/src/main/resources/META-INF/plexus/components.xml
Modified:
synapse/trunk/java/pom.xml
Added: synapse/trunk/java/modules/xar-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/xar-maven-plugin/pom.xml?rev=672593&view=auto
==============================================================================
--- synapse/trunk/java/modules/xar-maven-plugin/pom.xml (added)
+++ synapse/trunk/java/modules/xar-maven-plugin/pom.xml Sat Jun 28 16:35:36 2008
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.synapse</groupId>
+ <artifactId>synapse-xar-maven-plugin</artifactId>
+ <version>SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+ <name>Apache Synapse - XAR Maven Plugin</name>
+ <description>Maven 2 plugin to create Synapse extension archives</description>
+
+ <properties>
+ <maven.version>2.0.7</maven.version>
+ <maven.artifact.version>2.0.8</maven.artifact.version>
+ <maven.archiver.version>2.2</maven.archiver.version>
+ <plexus.utils.version>1.5.4</plexus.utils.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>${maven.artifact.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-archiver</artifactId>
+ <version>${maven.archiver.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>${plexus.utils.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/AbstractXarMojo.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/AbstractXarMojo.java?rev=672593&view=auto
==============================================================================
--- synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/AbstractXarMojo.java (added)
+++ synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/AbstractXarMojo.java Sat Jun 28 16:35:36 2008
@@ -0,0 +1,394 @@
+/*
+ * 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.synapse.maven.xar;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.DebugResolutionListener;
+import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.artifact.resolver.filter.TypeArtifactFilter;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.project.artifact.InvalidDependencyVersionException;
+import org.codehaus.plexus.archiver.Archiver;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.logging.LogEnabled;
+import org.codehaus.plexus.logging.Logger;
+
+/**
+ * Abstract base class for all the mojos in the XAR plugin.
+ */
+public abstract class AbstractXarMojo extends AbstractMojo implements LogEnabled {
+ /**
+ * List of dependencies to be excluded by default because the corresponding APIs are provided
+ * by the Synapse runtime.
+ */
+ private static final String[] defaultRuntimeExcludes = {
+ "org.apache.synapse:synapse-core:jar",
+ "commons-logging:commons-logging-api:jar",
+ };
+
+ private static final String[] serviceClassNames = {
+ "org.apache.synapse.config.xml.MediatorFactory",
+ "org.apache.synapse.config.xml.MediatorSerializer",
+ "org.apache.synapse.config.xml.StartupFactory",
+ };
+
+ /**
+ * The projects base directory.
+ *
+ * @parameter expression="${project.basedir}"
+ * @required
+ * @readonly
+ */
+ private File baseDir;
+
+ /**
+ * The maven project.
+ *
+ * @parameter expression="${project}"
+ * @required
+ * @readonly
+ */
+ protected MavenProject project;
+
+ /**
+ * Local maven repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ * @readonly
+ */
+ private ArtifactRepository localRepository;
+
+ /**
+ * Remote repositories.
+ *
+ * @parameter expression="${project.remoteArtifactRepositories}"
+ * @required
+ * @readonly
+ */
+ private List remoteArtifactRepositories;
+
+ /**
+ * @component role="org.apache.maven.artifact.metadata.ArtifactMetadataSource" hint="maven"
+ */
+ private ArtifactMetadataSource artifactMetadataSource;
+
+ /**
+ * Artifact collector, needed to resolve dependencies.
+ *
+ * @component role="org.apache.maven.artifact.resolver.ArtifactCollector"
+ * @required
+ * @readonly
+ */
+ private ArtifactCollector artifactCollector;
+
+ /**
+ * Project builder.
+ *
+ * @component role="org.apache.maven.project.MavenProjectBuilder"
+ * @required
+ * @readonly
+ */
+ private MavenProjectBuilder projectBuilder;
+
+ /**
+ * Artifact factory.
+ *
+ * @component role="org.apache.maven.artifact.factory.ArtifactFactory"
+ * @required
+ * @readonly
+ */
+ private ArtifactFactory artifactFactory;
+
+ /**
+ * The directory containing generated classes.
+ *
+ * @parameter expression="${project.build.outputDirectory}"
+ * @required
+ */
+ private File buildOutputDirectory;
+
+ /**
+ * The directory where temporary files for inclusion in the XAR are stored.
+ *
+ * @parameter expression="${project.build.directory}/xar-files"
+ * @required
+ */
+ private File tmpDirectory;
+
+ /**
+ * Whether the dependency jars should be included in the XAR.
+ *
+ * @parameter expression="${includeDependencies}" default-value="true"
+ */
+ private boolean includeDependencies;
+
+ /**
+ * Whether metadata for the extensions should be generated automatically.
+ *
+ * @parameter expression="${generateMetadata}" default-value="true"
+ */
+ private boolean generateMetadata;
+
+ private Logger logger;
+
+ public void enableLogging(Logger logger) {
+ this.logger = logger;
+ }
+
+ /**
+ * Build the XAR using the provided archiver.
+ *
+ * @throws MojoExecutionException
+ */
+ protected void buildArchive(Archiver archiver)
+ throws ArchiverException, MojoExecutionException {
+
+ Log log = getLog();
+ archiver.addDirectory(buildOutputDirectory);
+ if (includeDependencies) {
+ log.debug("Adding dependencies ...");
+ addDependencies(archiver);
+ }
+ if (generateMetadata) {
+ log.debug("Generating XAR metadata ...");
+ generateMetadata(archiver);
+ }
+ }
+
+ private void addDependencies(Archiver archiver)
+ throws ArchiverException, MojoExecutionException {
+
+ Log log = getLog();
+ AndArtifactFilter filter = new AndArtifactFilter();
+ filter.add(new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME));
+ filter.add(new ArtifactFilter() {
+ public boolean include(Artifact artifact) {
+ return !artifact.isOptional();
+ }
+ });
+ filter.add(new TypeArtifactFilter("jar"));
+ filter.add(buildSynapseRuntimeArtifactFilter());
+ for (Artifact artifact : filterArtifacts(project.getArtifacts(), filter)) {
+ String targetFileName = artifact.getArtifactId() + "-" + artifact.getVersion() + "." +
+ artifact.getArtifactHandler().getExtension();
+ log.info("Adding " + targetFileName + " (scope " + artifact.getScope() + ")");
+ archiver.addFile(artifact.getFile(), "lib/" + targetFileName);
+ }
+ }
+
+ private void generateMetadata(Archiver archiver)
+ throws ArchiverException, MojoExecutionException {
+
+ Log log = getLog();
+ File tmpServicesDir = new File(new File(tmpDirectory, "META-INF"), "services");
+ File buildServicesDir = new File(new File(buildOutputDirectory, "META-INF"), "services");
+ tmpServicesDir.mkdirs();
+
+ log.debug("Initializing class scanner ...");
+ ClassScanner scanner = new ClassScanner(buildOutputDirectory);
+ for (Artifact artifact : filterArtifacts(project.getArtifacts(),
+ new ScopeArtifactFilter(Artifact.SCOPE_COMPILE))) {
+ scanner.addToClasspath(artifact.getFile());
+ }
+ List<ServiceLocator> serviceLocators =
+ new ArrayList<ServiceLocator>(serviceClassNames.length);
+ for (String serviceClassName : serviceClassNames) {
+ // If the user provided its own service file, skip generation
+ File file = new File(buildServicesDir, serviceClassName);
+ if (file.exists()) {
+ log.debug(file + " exists; don't scan for " + serviceClassName +
+ " implementation");
+ } else {
+ ServiceLocator sl = new ServiceLocator(serviceClassName);
+ serviceLocators.add(sl);
+ scanner.addVisitor(sl);
+ }
+ }
+ try {
+ scanner.scan();
+ } catch (ClassScannerException e) {
+ throw new MojoExecutionException("Failed to scan classes for services", e);
+ }
+ for (ServiceLocator sl : serviceLocators) {
+ File file = new File(tmpServicesDir, sl.getServiceClassName());
+ if (!sl.getImplementations().isEmpty()) {
+ String destFileName = "META-INF/services/" + sl.getServiceClassName();
+ log.info("Generating " + destFileName);
+ try {
+ Writer out = new OutputStreamWriter(new FileOutputStream(file));
+ try {
+ for (String impl : sl.getImplementations()) {
+ log.debug(" " + impl);
+ out.write(impl);
+ out.write("\n");
+ }
+ } finally {
+ out.close();
+ }
+ } catch (IOException e) {
+ throw new MojoExecutionException("Unable to create temporary file " + file, e);
+ }
+ archiver.addFile(file, destFileName);
+ }
+ }
+ }
+
+ /**
+ * Build a filter that excludes all artifacts that are provided by Synapse at runtime.
+ *
+ * @return
+ * @throws MojoExecutionException
+ */
+ private ArtifactFilter buildSynapseRuntimeArtifactFilter() throws MojoExecutionException {
+ final Map<String,Artifact> artifacts = new HashMap<String,Artifact>();
+ for (Artifact artifact : getSynapseRuntimeArtifacts()) {
+ artifacts.put(artifact.getDependencyConflictId(), artifact);
+ }
+ final Set<String> defaultExclusionSet
+ = new HashSet<String>(Arrays.asList(defaultRuntimeExcludes));
+ return new ArtifactFilter() {
+ public boolean include(Artifact artifact) {
+ Artifact runtimeArtifact = artifacts.get(artifact.getDependencyConflictId());
+ if (runtimeArtifact == null) {
+ return !defaultExclusionSet.contains(artifact.getDependencyConflictId());
+ } else {
+ if (!runtimeArtifact.getVersion().equals(artifact.getVersion())) {
+ getLog().warn("Possible runtime version conflict for "
+ + artifact.getArtifactId() + ": XAR depends on "
+ + artifact.getVersion() + ", Synapse runtime provides "
+ + runtimeArtifact.getVersion());
+ }
+ return false;
+ }
+ }
+ };
+ }
+
+ /**
+ * Get the set of artifacts that are provided by Synapse at runtime.
+ *
+ * @return
+ * @throws MojoExecutionException
+ */
+ private Set<Artifact> getSynapseRuntimeArtifacts() throws MojoExecutionException {
+ Log log = getLog();
+ log.debug("Looking for synapse-core artifact in XAR project dependencies ...");
+ Artifact synapseCore = null;
+ for (Iterator<?> it = project.getDependencyArtifacts().iterator(); it.hasNext(); ) {
+ Artifact artifact = (Artifact)it.next();
+ if (artifact.getGroupId().equals("org.apache.synapse")
+ && artifact.getArtifactId().equals("synapse-core")) {
+ synapseCore = artifact;
+ break;
+ }
+ }
+ if (synapseCore == null) {
+ throw new MojoExecutionException("Could not locate dependency on synapse-core");
+ }
+
+ log.debug("Loading project data for " + synapseCore + " ...");
+ MavenProject synapseCoreProject;
+ try {
+ synapseCoreProject = projectBuilder.buildFromRepository(synapseCore,
+ remoteArtifactRepositories, localRepository);
+ } catch (ProjectBuildingException e) {
+ throw new MojoExecutionException("Unable to retrieve project information for "
+ + synapseCore, e);
+ }
+ Set<Artifact> synapseRuntimeDeps;
+ try {
+ synapseRuntimeDeps = synapseCoreProject.createArtifacts(artifactFactory,
+ Artifact.SCOPE_RUNTIME, new TypeArtifactFilter("jar"));
+ } catch (InvalidDependencyVersionException e) {
+ throw new MojoExecutionException("Unable to get project dependencies for "
+ + synapseCore, e);
+ }
+ log.debug("Direct runtime dependencies for " + synapseCore + " :");
+ logArtifacts(synapseRuntimeDeps);
+
+ log.debug("Resolving transitive dependencies for " + synapseCore + " ...");
+ try {
+ synapseRuntimeDeps = artifactCollector.collect(synapseRuntimeDeps,
+ synapseCoreProject.getArtifact(), synapseCoreProject.getManagedVersionMap(),
+ localRepository, remoteArtifactRepositories, artifactMetadataSource, null,
+ Collections.singletonList(new DebugResolutionListener(logger))).getArtifacts();
+ } catch (ArtifactResolutionException e) {
+ throw new MojoExecutionException("Unable to resolve transitive dependencies for "
+ + synapseCore);
+ }
+ log.debug("All runtime dependencies for " + synapseCore + " :");
+ logArtifacts(synapseRuntimeDeps);
+
+ return synapseRuntimeDeps;
+ }
+
+ private void logArtifacts(Collection<Artifact> collection) {
+ List<Artifact> artifacts = new ArrayList<Artifact>(collection);
+ Collections.sort(artifacts, new Comparator<Artifact>() {
+ public int compare(Artifact o1, Artifact o2) {
+ return o1.getArtifactId().compareTo(o2.getArtifactId());
+ }
+ });
+ for (Artifact artifact : artifacts) {
+ getLog().debug(" " + artifact.getArtifactId() + "-" + artifact.getVersion()
+ + "." + artifact.getArtifactHandler().getExtension());
+ }
+ }
+
+ private static Set<Artifact> filterArtifacts(Set<Artifact> artifacts, ArtifactFilter filter) {
+ Set<Artifact> result = new HashSet<Artifact>();
+ for (Artifact artifact : artifacts) {
+ if (filter.include(artifact)) {
+ result.add(artifact);
+ }
+ }
+ return result;
+ }
+}
Added: synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ClassScanner.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ClassScanner.java?rev=672593&view=auto
==============================================================================
--- synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ClassScanner.java (added)
+++ synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ClassScanner.java Sat Jun 28 16:35:36 2008
@@ -0,0 +1,101 @@
+/*
+ * 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.synapse.maven.xar;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+public class ClassScanner {
+ private final File dir;
+ private List<File> classpath = new LinkedList<File>();
+ private List<ClassVisitor> visitors = new LinkedList<ClassVisitor>();
+ private ClassLoader loader;
+
+ public ClassScanner(File dir) {
+ this.dir = dir;
+ addToClasspath(dir);
+ }
+
+ public void addToClasspath(File file) {
+ classpath.add(file);
+ }
+
+ public void addVisitor(ClassVisitor visitor) {
+ visitors.add(visitor);
+ }
+
+ public void scan() throws ClassScannerException {
+ if (visitors.isEmpty()) {
+ return;
+ }
+ List<URL> urls = new ArrayList<URL>(classpath.size());
+ for (File classpathEntry : classpath) {
+ try {
+ urls.add(classpathEntry.toURL());
+ } catch (MalformedURLException e) {
+ throw new ClassScannerException("Unable to build classpath", e);
+ }
+ }
+ loader = URLClassLoader.newInstance(urls.toArray(new URL[urls.size()]));
+ try {
+ for (ClassVisitor visitor : visitors) {
+ visitor.init(loader);
+ }
+ scan(dir, null);
+ } finally {
+ loader = null;
+ }
+ }
+
+ private void scan(File dir, String packageName) throws ClassScannerException {
+ File[] children = dir.listFiles(new FileFilter() {
+ public boolean accept(File file) {
+ return file.isDirectory() || (file.isFile() && file.getName().endsWith(".class"));
+ }
+ });
+ for (File child : children) {
+ String name = child.getName();
+ if (child.isDirectory()) {
+ scan(child, packageName == null ? name : packageName + "." + name);
+ } else {
+ StringBuilder className = new StringBuilder();
+ if (packageName != null) {
+ className.append(packageName).append('.');
+ }
+ className.append(name.substring(0, name.length()-6));
+ Class<?> clazz;
+ try {
+ clazz = loader.loadClass(className.toString());
+ } catch (ClassNotFoundException e) {
+ throw new ClassScannerException("Unable to load class " + className, e);
+ }
+ for (ClassVisitor visitor : visitors) {
+ visitor.visit(clazz);
+ }
+ }
+ }
+ }
+}
Added: synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ClassScannerException.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ClassScannerException.java?rev=672593&view=auto
==============================================================================
--- synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ClassScannerException.java (added)
+++ synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ClassScannerException.java Sat Jun 28 16:35:36 2008
@@ -0,0 +1,32 @@
+/*
+ * 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.synapse.maven.xar;
+
+public class ClassScannerException extends Exception {
+ private static final long serialVersionUID = 7666486328035342350L;
+
+ public ClassScannerException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ClassScannerException(String message) {
+ super(message);
+ }
+}
Added: synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ClassVisitor.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ClassVisitor.java?rev=672593&view=auto
==============================================================================
--- synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ClassVisitor.java (added)
+++ synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ClassVisitor.java Sat Jun 28 16:35:36 2008
@@ -0,0 +1,25 @@
+/*
+ * 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.synapse.maven.xar;
+
+public interface ClassVisitor {
+ void init(ClassLoader classLoader) throws ClassScannerException;
+ void visit(Class<?> clazz) throws ClassScannerException;
+}
Added: synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ServiceLocator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ServiceLocator.java?rev=672593&view=auto
==============================================================================
--- synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ServiceLocator.java (added)
+++ synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/ServiceLocator.java Sat Jun 28 16:35:36 2008
@@ -0,0 +1,56 @@
+/*
+ * 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.synapse.maven.xar;
+
+import java.lang.reflect.Modifier;
+import java.util.LinkedList;
+import java.util.List;
+
+public class ServiceLocator implements ClassVisitor {
+ private final String serviceClassName;
+ private Class<?> serviceClass;
+ private List<String> implementations = new LinkedList<String>();
+
+ public ServiceLocator(String serviceClassName) {
+ this.serviceClassName = serviceClassName;
+ }
+
+ public String getServiceClassName() {
+ return serviceClassName;
+ }
+
+ public List<String> getImplementations() {
+ return implementations;
+ }
+
+ public void init(ClassLoader classLoader) throws ClassScannerException {
+ try {
+ serviceClass = classLoader.loadClass(serviceClassName);
+ } catch (ClassNotFoundException e) {
+ throw new ClassScannerException("Class " + serviceClassName + " not found");
+ }
+ }
+
+ public void visit(Class<?> clazz) throws ClassScannerException {
+ if (serviceClass.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) {
+ implementations.add(clazz.getName());
+ }
+ }
+}
Added: synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/XarExplodedMojo.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/XarExplodedMojo.java?rev=672593&view=auto
==============================================================================
--- synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/XarExplodedMojo.java (added)
+++ synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/XarExplodedMojo.java Sat Jun 28 16:35:36 2008
@@ -0,0 +1,58 @@
+/*
+ * 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.synapse.maven.xar;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.archiver.Archiver;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.dir.DirectoryArchiver;
+
+/**
+ * Generate the exploded XAR.
+ *
+ * @goal exploded
+ * @phase package
+ * @requiresDependencyResolution runtime
+ */
+public class XarExplodedMojo extends AbstractXarMojo {
+ /**
+ * The directory where the exploded XAR is built.
+ *
+ * @parameter expression="${project.build.directory}/xar"
+ * @required
+ */
+ private File xarDirectory;
+
+ public void execute() throws MojoExecutionException {
+ Archiver archiver = new DirectoryArchiver();
+ archiver.setDestFile(xarDirectory);
+ try {
+ buildArchive(archiver);
+ archiver.createArchive();
+ } catch (ArchiverException e) {
+ throw new MojoExecutionException("Unable to build archive", e);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Unable to build archive", e);
+ }
+ }
+}
Added: synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/XarMojo.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/XarMojo.java?rev=672593&view=auto
==============================================================================
--- synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/XarMojo.java (added)
+++ synapse/trunk/java/modules/xar-maven-plugin/src/main/java/org/apache/synapse/maven/xar/XarMojo.java Sat Jun 28 16:35:36 2008
@@ -0,0 +1,132 @@
+/*
+ * 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.synapse.maven.xar;
+
+import java.io.File;
+
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.archiver.MavenArchiver;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProjectHelper;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
+
+/**
+ * Build a XAR.
+ *
+ * @goal xar
+ * @phase package
+ * @requiresDependencyResolution runtime
+ */
+public class XarMojo extends AbstractXarMojo {
+ /**
+ * The directory for the generated XAR.
+ *
+ * @parameter expression="${project.build.directory}"
+ * @required
+ */
+ private String outputDirectory;
+
+ /**
+ * The name of the generated XAR.
+ *
+ * @parameter expression="${project.build.finalName}"
+ * @required
+ */
+ private String xarName;
+
+ /**
+ * The Jar archiver.
+ *
+ * @parameter expression="${component.org.codehaus.plexus.archiver.Archiver#jar}"
+ * @required
+ */
+ private JarArchiver jarArchiver;
+
+ /**
+ * The maven archive configuration to use.
+ *
+ * @parameter
+ */
+ private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
+
+ /**
+ * Classifier to add to the artifact generated. If given, the artifact will be an attachment
+ * instead.
+ *
+ * @parameter
+ */
+ private String classifier;
+
+ /**
+ * Whether this is the main artifact being built. Set to <code>false</code> if you don't want to
+ * install or deploy it to the local repository instead of the default one in an execution.
+ *
+ * @parameter expression="${primaryArtifact}" default-value="true"
+ */
+ private boolean primaryArtifact;
+
+ /**
+ * @component
+ */
+ private MavenProjectHelper projectHelper;
+
+ /**
+ * Executes the XarMojo on the current project.
+ *
+ * @throws MojoExecutionException if an error occurred while building the XAR
+ */
+ public void execute() throws MojoExecutionException {
+
+ File xarFile = new File(outputDirectory, xarName + ".xar");
+
+ // generate xar file
+ getLog().info("Generating XAR " + xarFile.getAbsolutePath());
+ MavenArchiver archiver = new MavenArchiver();
+ archiver.setArchiver(jarArchiver);
+ archiver.setOutputFile(xarFile);
+ try {
+ buildArchive(jarArchiver);
+ } catch (ArchiverException e) {
+ throw new MojoExecutionException("Unable to build archive", e);
+ }
+
+ // create archive
+ try {
+ archiver.createArchive(project, archive);
+ } catch (Exception e) {
+ throw new MojoExecutionException("Unable to create archive", e);
+ }
+
+ if (classifier != null) {
+ projectHelper.attachArtifact(project, "xar", classifier, xarFile);
+ } else {
+ Artifact artifact = project.getArtifact();
+ if (primaryArtifact) {
+ artifact.setFile(xarFile);
+ } else if (artifact.getFile() == null || artifact.getFile().isDirectory()) {
+ artifact.setFile(xarFile);
+ } else {
+ projectHelper.attachArtifact(project, "xar", xarFile);
+ }
+ }
+ }
+}
Added: synapse/trunk/java/modules/xar-maven-plugin/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/xar-maven-plugin/src/main/resources/META-INF/plexus/components.xml?rev=672593&view=auto
==============================================================================
--- synapse/trunk/java/modules/xar-maven-plugin/src/main/resources/META-INF/plexus/components.xml (added)
+++ synapse/trunk/java/modules/xar-maven-plugin/src/main/resources/META-INF/plexus/components.xml Sat Jun 28 16:35:36 2008
@@ -0,0 +1,53 @@
+<!--
+ ~ 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.
+ -->
+
+<component-set>
+ <components>
+ <component>
+ <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
+ <role-hint>xar</role-hint>
+ <implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
+ <configuration>
+ <classifier></classifier>
+ <extension>xar</extension>
+ <type>xar</type>
+ <packaging>jar</packaging>
+ <language>java</language>
+ <addedToClasspath>false</addedToClasspath>
+ </configuration>
+ </component>
+ <component>
+ <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
+ <role-hint>xar</role-hint>
+ <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
+ <configuration>
+ <phases>
+ <process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
+ <compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
+ <process-test-resources>org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
+ <test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
+ <test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
+ <package>org.apache.synapse:synapse-xar-maven-plugin:xar</package>
+ <install>org.apache.maven.plugins:maven-install-plugin:install</install>
+ <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
+ </phases>
+ </configuration>
+ </component>
+ </components>
+</component-set>
Modified: synapse/trunk/java/pom.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/pom.xml?rev=672593&r1=672592&r2=672593&view=diff
==============================================================================
--- synapse/trunk/java/pom.xml (original)
+++ synapse/trunk/java/pom.xml Sat Jun 28 16:35:36 2008
@@ -1107,6 +1107,7 @@
<module>modules/mar</module>
<module>modules/war</module>
<module>modules/handler</module>
+ <module>modules/xar-maven-plugin</module>
</modules>
<properties>