1 17 package org.apache.servicemix.maven.plugin.jbi; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.util.Iterator ; 22 import java.util.Set ; 23 24 import org.apache.maven.artifact.Artifact; 25 import org.apache.maven.artifact.resolver.ArtifactNotFoundException; 26 import org.apache.maven.artifact.resolver.ArtifactResolutionException; 27 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; 28 import org.apache.maven.plugin.MojoExecutionException; 29 import org.apache.maven.plugin.MojoFailureException; 30 import org.apache.maven.project.MavenProject; 31 import org.apache.maven.project.ProjectBuildingException; 32 import org.codehaus.plexus.util.FileUtils; 33 34 45 public class GenerateServiceAssemblyMojo extends AbstractJbiMojo { 46 47 53 private File workDirectory; 54 55 public void execute() throws MojoExecutionException, MojoFailureException { 56 try { 57 injectDependentServiceUnits(); 58 } catch (Exception e) { 59 throw new MojoExecutionException("Failed to inject dependencies", e); 60 } 61 } 62 63 private void injectDependentServiceUnits() throws JbiPluginException, 64 ArtifactResolutionException, ArtifactNotFoundException { 65 Set artifacts = project.getArtifacts(); 66 for (Iterator iter = artifacts.iterator(); iter.hasNext();) { 67 Artifact artifact = (Artifact) iter.next(); 68 69 ScopeArtifactFilter filter = new ScopeArtifactFilter( 71 Artifact.SCOPE_RUNTIME); 72 if (!artifact.isOptional() && filter.include(artifact) 73 && (artifact.getDependencyTrail().size() == 2)) { 74 MavenProject project = null; 75 try { 76 project = projectBuilder.buildFromRepository(artifact, 77 remoteRepos, localRepo); 78 } catch (ProjectBuildingException e) { 79 getLog().warn( 80 "Unable to determine packaging for dependency : " 81 + artifact.getArtifactId() 82 + " assuming jar"); 83 } 84 if ((project != null) 85 && (project.getPackaging().equals("jbi-service-unit"))) { 86 try { 87 String path = artifact.getFile().getAbsolutePath(); 88 path = path.substring(0, path.lastIndexOf('.')) + ".zip"; 89 FileUtils.copyFileToDirectory(new File (path), 90 workDirectory); 91 } catch (IOException e) { 92 throw new JbiPluginException(e); 93 } 94 } 95 } 96 } 97 } 98 99 } 100 | Popular Tags |