Coverage Report - org.yoshiori.mvn.plugins.ConsoleMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
ConsoleMojo
0%
0/65
0%
0/28
0
 
 1  
 /**
 2  
  * 
 3  
  */
 4  
 package org.yoshiori.mvn.plugins;
 5  
 
 6  
 import java.io.File;
 7  
 import java.util.ArrayList;
 8  
 import java.util.Collections;
 9  
 import java.util.HashSet;
 10  
 import java.util.List;
 11  
 import java.util.Set;
 12  
 
 13  
 import org.apache.maven.artifact.Artifact;
 14  
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
 15  
 import org.apache.maven.artifact.repository.ArtifactRepository;
 16  
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
 17  
 import org.apache.maven.artifact.resolver.ArtifactResolver;
 18  
 import org.apache.maven.plugin.AbstractMojo;
 19  
 import org.apache.maven.plugin.MojoExecutionException;
 20  
 import org.apache.maven.plugin.MojoFailureException;
 21  
 import org.apache.maven.project.MavenProject;
 22  
 import org.python.util.InteractiveConsole;
 23  
 
 24  
 /**
 25  
  * Jython Console Open Plugin.
 26  
  * 
 27  
  * @author yoshiori
 28  
  * @goal console
 29  
  * @execute phase="compile"
 30  0
  * @requiresDependencyResolution runtime
 31  
  */
 32  0
 public class ConsoleMojo extends AbstractMojo {
 33  
 
 34  
         /**
 35  
          * @parameter expression="${project}"
 36  
          * @required
 37  
          * @readonly
 38  
          */
 39  
         private MavenProject project;
 40  
 
 41  
         /**
 42  
          * The local repository, from which to delete artifacts.
 43  
          * 
 44  
          * @parameter default-value="${localRepository}"
 45  
          * @required
 46  
          * @readonly
 47  
          */
 48  
         private ArtifactRepository localRepository;
 49  
 
 50  
         /**
 51  
          * The artifact resolver used to re-resolve dependencies, if that option is
 52  
          * enabled.
 53  
          * 
 54  
          * @component
 55  
          */
 56  
         private ArtifactResolver resolver;
 57  
 
 58  
         /**
 59  
          * The artifact metadata source used to resolve dependencies
 60  
          * 
 61  
          * @component
 62  
          */
 63  
         private ArtifactMetadataSource source;
 64  
 
 65  
         private static final String JYTHON_PLUGIN_ARTIFACT_ID = "maven-jython-plugin";
 66  
 
 67  
         /*
 68  
          * (non-Javadoc)
 69  
          * 
 70  
          * @see org.apache.maven.plugin.Mojo#execute()
 71  
          */
 72  0
         @SuppressWarnings("unchecked")
 73  
         public void execute() throws MojoExecutionException, MojoFailureException {
 74  0
                 List<File> artifactFile = new ArrayList<File>();
 75  0
 
 76  0
                 // add jython plugin artifact liblary
 77  0
                 Set<Artifact> pluginDependencyArtifacts = new HashSet<Artifact>();
 78  0
                 for (Artifact artifact : (Set<Artifact>) project.getPluginArtifacts()) {
 79  0
                         if (artifact.getArtifactId().equals(JYTHON_PLUGIN_ARTIFACT_ID)) {
 80  0
                                 pluginDependencyArtifacts.add(artifact);
 81  
                         }
 82  0
                 }
 83  0
                 try {
 84  0
                         ArtifactResolutionResult result = resolver.resolveTransitively(
 85  0
                                         pluginDependencyArtifacts, project.getArtifact(),
 86  0
                                         Collections.EMPTY_LIST, localRepository, source);
 87  0
                         for (Artifact artifact : (Set<Artifact>) result.getArtifacts()) {
 88  0
                                 artifactFile.add(artifact.getFile());
 89  0
                         }
 90  0
                 } catch (Exception e) {
 91  0
                         e.printStackTrace();
 92  0
                         throw new MojoExecutionException("Exception occured.:", e);
 93  
                 }
 94  0
 
 95  0
                 // add projct artifacts liblary
 96  0
                 for (Artifact artifact : (Set<Artifact>) project.getArtifacts()) {
 97  0
                         artifactFile.add(artifact.getFile());
 98  
                 }
 99  0
 
 100  
                 // added build path
 101  0
                 artifactFile.add(new File(project.getBuild().getOutputDirectory()));
 102  0
 
 103  0
                 // for debug
 104  0
                 if (getLog().isDebugEnabled()) {
 105  0
                         for (File file : artifactFile) {
 106  0
                                 getLog().debug("added File:" + file);
 107  0
                         }
 108  0
                 }
 109  0
                 InteractiveConsole console = new InteractiveConsole();
 110  0
                 console.exec("import sys");
 111  0
                 for (File file : artifactFile) {
 112  0
                         console.exec("sys.path.append('" + file + "')");
 113  0
                 }
 114  0
                 console.interact();
 115  0
         }
 116  0
 
 117  
         public MavenProject getProject() {
 118  0
                 return project;
 119  
         }
 120  0
 
 121  0
         public void setProject(MavenProject project) {
 122  0
                 this.project = project;
 123  0
         }
 124  
 
 125  
         /**
 126  
          * @return the localRepository
 127  0
          */
 128  
         public ArtifactRepository getLocalRepository() {
 129  0
                 return localRepository;
 130  
         }
 131  
 
 132  
         /**
 133  
          * @param localRepository
 134  
          *            the localRepository to set
 135  0
          */
 136  0
         public void setLocalRepository(ArtifactRepository localRepository) {
 137  0
                 this.localRepository = localRepository;
 138  0
         }
 139  
 
 140  
         /**
 141  
          * @return the resolver
 142  0
          */
 143  
         public ArtifactResolver getResolver() {
 144  0
                 return resolver;
 145  
         }
 146  
 
 147  
         /**
 148  
          * @param resolver
 149  
          *            the resolver to set
 150  0
          */
 151  0
         public void setResolver(ArtifactResolver resolver) {
 152  0
                 this.resolver = resolver;
 153  0
         }
 154  
 
 155  
         /**
 156  
          * @return the source
 157  0
          */
 158  
         public ArtifactMetadataSource getSource() {
 159  0
                 return source;
 160  
         }
 161  
 
 162  
         /**
 163  
          * @param source
 164  
          *            the source to set
 165  0
          */
 166  0
         public void setSource(ArtifactMetadataSource source) {
 167  0
                 this.source = source;
 168  0
         }
 169  
 }