1 17 package org.apache.servicemix.maven.plugin.jbi; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Set ; 25 26 import org.apache.maven.artifact.Artifact; 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.codehaus.plexus.util.FileUtils; 31 32 43 public class GenerateSharedLibraryDescriptorMojo extends AbstractJbiMojo { 44 45 public static final String UTF_8 = "UTF-8"; 46 47 52 private Boolean generateJbiDescriptor = Boolean.TRUE; 53 54 59 private String name; 60 61 66 private String description; 67 68 73 private String version; 74 75 80 private String classLoaderDelegation; 81 82 87 private String encoding = UTF_8; 88 89 94 private String generatedDescriptorLocation; 95 96 public void execute() throws MojoExecutionException, MojoFailureException { 97 98 getLog() 99 .debug( 100 " ======= GenerateSharedLibraryDescriptorMojo settings ======="); 101 getLog().debug("workDirectory[" + workDirectory + "]"); 102 getLog().debug("generateJbiDescriptor[" + generateJbiDescriptor + "]"); 103 getLog().debug("name[" + name + "]"); 104 getLog().debug("description[" + description + "]"); 105 getLog().debug("encoding[" + encoding + "]"); 106 getLog().debug("generatedDescriptorLocation[" + generatedDescriptorLocation + "]"); 107 getLog().debug("version[" + version + "]"); 108 109 if (!generateJbiDescriptor.booleanValue()) { 110 getLog().debug("Generation of jbi.xml is disabled"); 111 return; 112 } 113 114 getLog().info("Generating jbi.xml"); 116 try { 117 generateJbiDescriptor(); 118 } catch (JbiPluginException e) { 119 throw new MojoExecutionException("Failed to generate jbi.xml", e); 120 } 121 122 try { 123 FileUtils.copyFileToDirectory(new File (generatedDescriptorLocation, 124 JBI_DESCRIPTOR), new File (getWorkDirectory(), META_INF)); 125 } catch (IOException e) { 126 throw new MojoExecutionException( 127 "Unable to copy jbi.xml to final destination", e); 128 } 129 } 130 131 134 protected void generateJbiDescriptor() throws JbiPluginException { 135 File outputDir = new File (generatedDescriptorLocation); 136 if (!outputDir.exists()) { 137 outputDir.mkdirs(); 138 } 139 140 File descriptor = new File (outputDir, JBI_DESCRIPTOR); 141 142 List embeddedLibraries = new ArrayList (); 143 144 DependencyInformation info = new DependencyInformation(); 145 info.setFilename(LIB_DIRECTORY + "/" + project.getArtifactId() + "-" 146 + project.getVersion() + ".jar"); 147 info.setVersion(project.getVersion()); 148 info.setName(project.getArtifactId()); 149 info.setType("jar"); 150 embeddedLibraries.add(info); 151 152 Set artifacts = project.getArtifacts(); 153 for (Iterator iter = artifacts.iterator(); iter.hasNext();) { 154 Artifact artifact = (Artifact) iter.next(); 155 156 ScopeArtifactFilter filter = new ScopeArtifactFilter( 158 Artifact.SCOPE_RUNTIME); 159 if (!artifact.isOptional() && filter.include(artifact)) { 160 String type = artifact.getType(); 161 if ("jar".equals(type)) { 162 info = new DependencyInformation(); 163 info.setFilename(LIB_DIRECTORY + "/" + artifact.getFile().getName()); 164 embeddedLibraries.add(info); 165 } 166 } 167 } 168 169 JbiSharedLibraryDescriptorWriter writer = new JbiSharedLibraryDescriptorWriter( 170 encoding); 171 writer.write(descriptor, name, description, version, 172 classLoaderDelegation, embeddedLibraries); 173 } 174 } 175 | Popular Tags |