Author: jstrachan
Date: Fri Sep 21 07:31:03 2007
New Revision: 578143
URL: http://svn.apache.org/viewvc?rev=578143&view=rev
Log:
the maven jbi tooling now automatically generates a
META-INF/maven/dependencies.properties file thats easy to parse from inside
JUnit test cases to boot up named dependencies from the local repo etc
Added:
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateDependsFileMojo.java
(with props)
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/MakeServiceMixDirsMojo.java
(with props)
Modified:
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiProjectDeployerMojo.java
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/resources/META-INF/plexus/components.xml
Added:
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateDependsFileMojo.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateDependsFileMojo.java?rev=578143&view=auto
==============================================================================
---
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateDependsFileMojo.java
(added)
+++
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateDependsFileMojo.java
Fri Sep 21 07:31:03 2007
@@ -0,0 +1,88 @@
+/*
+ * 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.servicemix.maven.plugin.jbi;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.apache.maven.model.Dependency;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Generates the dependencies properties file
+ *
+ * @version $Id: $
+ * @goal generate-depends-file
+ * @phase generate-resources
+ * @requiresDependencyResolution runtime
+ * @description Generates the dependencies properties file
+ */
+public class GenerateDependsFileMojo extends AbstractJbiMojo {
+
+ protected static final String SEPARATOR = "/";
+
+ /**
+ * The file to generate
+ *
+ * @parameter
default-value="${project.build.directory}/target/classes/META-INF/maven/dependencies.properties"
+ */
+
+ private File outputFile;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ OutputStream out = null;
+ try {
+ outputFile.getParentFile().mkdirs();
+ Properties properties = new Properties();
+ populateProperties(properties);
+ String comments = "Generated Maven dependencies by the ServiceMix
Maven Plugin";
+ out = new FileOutputStream(outputFile);
+ properties.store(out, comments);
+ getLog().info("Created: " + outputFile);
+
+ } catch (Exception e) {
+ throw new MojoExecutionException(
+ "Unable to create dependencies file: " + e, e);
+ } finally {
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ getLog().info("Failed to close: " + outputFile + ".
Reason: " + e, e);
+ }
+ }
+ }
+ }
+
+ protected void populateProperties(Properties properties) {
+ Iterator iterator = project.getDependencies().iterator();
+ while (iterator.hasNext()) {
+ Dependency dependency = (Dependency) iterator.next();
+ String prefix = dependency.getGroupId() + SEPARATOR +
dependency.getArtifactId() + SEPARATOR;
+ properties.put(prefix + "version", dependency.getVersion());
+ properties.put(prefix + "type", dependency.getType());
+ properties.put(prefix + "scope", dependency.getScope());
+
+ getLog().debug("Dependency: " + dependency + " classifier: " +
dependency.getClassifier() + " type: " + dependency.getType());
+ }
+ }
+}
\ No newline at end of file
Propchange:
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateDependsFileMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiProjectDeployerMojo.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiProjectDeployerMojo.java?rev=578143&r1=578142&r2=578143&view=diff
==============================================================================
---
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiProjectDeployerMojo.java
(original)
+++
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiProjectDeployerMojo.java
Fri Sep 21 07:31:03 2007
@@ -58,11 +58,11 @@
*/
public class JbiProjectDeployerMojo extends AbstractDeployableMojo {
- private static final String JBI_SHARED_LIBRARY = "jbi-shared-library";
+ public static final String JBI_SHARED_LIBRARY = "jbi-shared-library";
- private static final String JBI_COMPONENT = "jbi-component";
+ public static final String JBI_COMPONENT = "jbi-component";
- private static final String JBI_SERVICE_ASSEMBLY = "jbi-service-assembly";
+ public static final String JBI_SERVICE_ASSEMBLY = "jbi-service-assembly";
private List deploymentTypes;
@@ -176,7 +176,7 @@
}
- private void startDependency(JbiDeployableArtifact jbiDeployable) {
+ protected void startDependency(JbiDeployableArtifact jbiDeployable) {
getLog().info("Starting " + jbiDeployable.getName());
if (JBI_SERVICE_ASSEMBLY.equals(jbiDeployable.getType())) {
StartServiceAssemblyTask startTask = new
StartServiceAssemblyTask();
@@ -192,7 +192,7 @@
}
}
- private void undeployDependency(JbiDeployableArtifact jbiDeployable) {
+ protected void undeployDependency(JbiDeployableArtifact jbiDeployable) {
getLog().info("Undeploying " + jbiDeployable.getFile());
if (JBI_SHARED_LIBRARY.equals(jbiDeployable.getType())) {
UninstallSharedLibraryTask sharedLibraryTask = new
UninstallSharedLibraryTask();
@@ -213,7 +213,7 @@
}
}
- private boolean isDeployed(JbiDeployableArtifact jbiDeployable) {
+ protected boolean isDeployed(JbiDeployableArtifact jbiDeployable) {
IsDeployedTask isDeployedTask = new IsDeployedTask();
isDeployedTask.setType(jbiDeployable.getType());
isDeployedTask.setName(jbiDeployable.getName());
@@ -228,7 +228,7 @@
return deployed;
}
- private void stopDependency(JbiDeployableArtifact jbiDeployable) {
+ protected void stopDependency(JbiDeployableArtifact jbiDeployable) {
getLog().info("Stopping " + jbiDeployable.getName());
if (JBI_SERVICE_ASSEMBLY.equals(jbiDeployable.getType())) {
StopServiceAssemblyTask stopTask = new StopServiceAssemblyTask();
@@ -254,8 +254,8 @@
}
}
- private void deployDependency(JbiDeployableArtifact jbiDeployable,
- boolean doDeferExceptions) {
+ protected void deployDependency(JbiDeployableArtifact jbiDeployable,
+ boolean doDeferExceptions) throws MojoExecutionException {
getLog().info(
"Deploying " + jbiDeployable.getType() + " from "
@@ -283,7 +283,7 @@
}
- private List getDeployablePackagingTypes() {
+ protected List getDeployablePackagingTypes() {
if (deploymentTypes == null) {
deploymentTypes = new ArrayList();
deploymentTypes.add(JBI_SHARED_LIBRARY);
@@ -334,7 +334,7 @@
return dependencies;
}
- private JbiDeployableArtifact resolveDeploymentPackage(
+ protected JbiDeployableArtifact resolveDeploymentPackage(
MavenProject project,
Artifact artifact) throws ArtifactResolutionException,
ArtifactNotFoundException {
Artifact jbiArtifact = factory.createArtifactWithClassifier(artifact
@@ -345,7 +345,7 @@
.getPackaging(), jbiArtifact.getFile().getAbsolutePath());
}
- private String getExtension(MavenProject project2) {
+ protected String getExtension(MavenProject project2) {
if (project2.getPackaging().equals(JBI_SERVICE_ASSEMBLY)) {
return "";
} else {
@@ -353,7 +353,7 @@
}
}
- private class ArtifactDepthComparator implements Comparator {
+ protected class ArtifactDepthComparator implements Comparator {
public int compare(Object arg0, Object arg1) {
int size1 = ((Artifact) arg0).getDependencyTrail().size();
@@ -370,7 +370,7 @@
}
- private class JbiDeployableArtifact {
+ protected class JbiDeployableArtifact {
private String file;
private String type;
Added:
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/MakeServiceMixDirsMojo.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/MakeServiceMixDirsMojo.java?rev=578143&view=auto
==============================================================================
---
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/MakeServiceMixDirsMojo.java
(added)
+++
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/MakeServiceMixDirsMojo.java
Fri Sep 21 07:31:03 2007
@@ -0,0 +1,105 @@
+/*
+ * 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.servicemix.maven.plugin.jbi;
+
+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;
+
+/**
+ * Creates a binary servicemix install directory that can then be referenced
+ * by a spring.xml file for integration testing.
+ *
+ * @version $Id: $
+ * @goal createDirs
+ * @execute phase="test-compile"
+ * @requiresDependencyResolution runtime
+ * @description Creates the ServiceMix runtime directories
+ */
+public class MakeServiceMixDirsMojo extends JbiProjectDeployerMojo {
+
+ /**
+ * The deploy diretory to put the service assemblies inside
+ *
+ * @parameter default-value="${project.build.directory}/servicemix/deploy"
+ */
+ private String deployDirectory;
+
+ /**
+ * @parameter default-value="true"
+ */
+ private boolean cleanStart;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ try {
+
+ if (cleanStart) {
+ getLog().info(
+ "Cleaning ServiceMix root directory [" +
deployDirectory
+ + "]");
+ File rootDir = new File(deployDirectory);
+ FileUtils.deleteDirectory(rootDir);
+ rootDir.mkdirs();
+ }
+
+ deployProject();
+
+ getLog().info("Project deployed");
+
+ } catch (Exception e) {
+ throw new MojoExecutionException(
+ "Apache ServiceMix was unable to deploy project", e);
+ }
+ }
+
+ //@Override
+ protected void deployDependency(JbiDeployableArtifact jbiDeployable,
boolean doDeferExceptions) throws MojoExecutionException {
+ // do nothing
+ String name = jbiDeployable.getType();
+ getLog().info("deployDependency: type: " + name + " dependency: " +
jbiDeployable);
+ if (JBI_SERVICE_ASSEMBLY.equals(name)) {
+ File assemblyFile = new File(jbiDeployable.getFile());
+ File outputFile = new File(deployDirectory,
assemblyFile.getName());
+
+ getLog().info("copying service Assembly!: " + jbiDeployable + "
to: " + outputFile);
+ try {
+ FileUtils.copyFile(assemblyFile, outputFile);
+ } catch (IOException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ }
+ }
+ }
+
+ //@Override
+ protected void
startDependency(JbiProjectDeployerMojo.JbiDeployableArtifact jbiDeployable) {
+ // do nothing
+ }
+
+ //@Override
+ protected void stopDependency(JbiDeployableArtifact jbiDeployable) {
+ // do nothing
+ }
+
+ //@Override
+ protected boolean isDeployed(JbiDeployableArtifact jbiDeployable) {
+ return false;
+ }
+}
Propchange:
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/MakeServiceMixDirsMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/resources/META-INF/plexus/components.xml
URL:
http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/resources/META-INF/plexus/components.xml?rev=578143&r1=578142&r2=578143&view=diff
==============================================================================
---
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/resources/META-INF/plexus/components.xml
(original)
+++
incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/resources/META-INF/plexus/components.xml
Fri Sep 21 07:31:03 2007
@@ -73,7 +73,7 @@
<configuration>
<phases>
<process-classes>org.apache.servicemix.tooling:jbi-maven-plugin:generate-jbi-service-unit-descriptor</process-classes>
-
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
+
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources,org.apache.servicemix.tooling:jbi-maven-plugin:generate-depends-file</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>
@@ -100,7 +100,7 @@
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<phases>
-
<generate-resources>org.apache.servicemix.tooling:jbi-maven-plugin:generate-jbi-service-assembly-descriptor</generate-resources>
+
<generate-resources>org.apache.servicemix.tooling:jbi-maven-plugin:generate-jbi-service-assembly-descriptor,org.apache.servicemix.tooling:jbi-maven-plugin:generate-depends-file</generate-resources>
<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>