Changeset 25618

Show
Ignore:
Timestamp:
12/01/08 19:06:43 (4 years ago)
Author:
tfunato
Message:

maven-groovy-pluginのようなconfigurationにpythonコードを書いて実行できるPluginを追加した。
ほとんど未テスト。

Location:
lang/java/misc/maven-jython-plugin/src/main/java/org/yoshiori/mvn/plugins
Files:
2 added
1 modified

Legend:

Unmodified
Added
Removed
  • lang/java/misc/maven-jython-plugin/src/main/java/org/yoshiori/mvn/plugins/ConsoleMojo.java

    r25110 r25618  
    55 
    66import java.io.File; 
    7 import java.util.ArrayList; 
    8 import java.util.Collections; 
    9 import java.util.HashSet; 
    107import java.util.List; 
    11 import java.util.Set; 
    128 
    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; 
    199import org.apache.maven.plugin.MojoExecutionException; 
    2010import org.apache.maven.plugin.MojoFailureException; 
    21 import org.apache.maven.project.MavenProject; 
    2211import org.python.util.InteractiveConsole; 
    2312 
     
    3019 * @requiresDependencyResolution runtime 
    3120 */ 
    32 public class ConsoleMojo extends AbstractMojo { 
     21public class ConsoleMojo extends AbstractJythonMojo { 
    3322 
    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"; 
    6623 
    6724        /* 
     
    7229        @SuppressWarnings("unchecked") 
    7330        public void execute() throws MojoExecutionException, MojoFailureException { 
    74                 List<File> artifactFile = new ArrayList<File>(); 
     31                List<File> artifactFile = getArtifactLiblary(); 
    7532 
    76                 artifactFile.addAll(getPluginArtifactLiblary()); 
    77  
    78                 // add projct artifacts liblary 
    79                 for (Artifact artifact : (Set<Artifact>) project.getArtifacts()) { 
    80                         artifactFile.add(artifact.getFile()); 
    81                 } 
    82  
    83                 // added build path 
    84                 artifactFile.add(new File(project.getBuild().getOutputDirectory())); 
    85  
    86                 // for debug 
    87                 if (getLog().isDebugEnabled()) { 
    88                         for (File file : artifactFile) { 
    89                                 getLog().debug("added File:" + file); 
    90                         } 
    91                 } 
    9233                InteractiveConsole console = new InteractiveConsole(); 
    9334                console.exec("import sys"); 
     
    9839        } 
    9940 
    100         /** 
    101          * @param artifactFile 
    102          * @throws MojoExecutionException 
    103          */ 
    104         @SuppressWarnings("unchecked") 
    105         protected List<File> getPluginArtifactLiblary() 
    106                         throws MojoExecutionException { 
    107                 List<File> artifactList = new ArrayList<File>(); 
    108                 Set<Artifact> pluginDependencyArtifacts = new HashSet<Artifact>(); 
    109                 for (Artifact artifact : (Set<Artifact>) project.getPluginArtifacts()) { 
    110                         if (artifact.getArtifactId().equals(JYTHON_PLUGIN_ARTIFACT_ID)) { 
    111                                 pluginDependencyArtifacts.add(artifact); 
    112                         } 
    113                 } 
    114                 try { 
    115                         ArtifactResolutionResult result = resolver.resolveTransitively( 
    116                                         pluginDependencyArtifacts, project.getArtifact(), 
    117                                         Collections.EMPTY_LIST, localRepository, source); 
    118                         for (Artifact artifact : (Set<Artifact>) result.getArtifacts()) { 
    119                                 artifactList.add(artifact.getFile()); 
    120                         } 
    121                 } catch (Exception e) { 
    122                         e.printStackTrace(); 
    123                         throw new MojoExecutionException("Exception occured.:", e); 
    124                 } 
    125                 return artifactList; 
    126         } 
     41         
    12742 
    128         public MavenProject getProject() { 
    129                 return project; 
    130         } 
    13143 
    132         public void setProject(MavenProject project) { 
    133                 this.project = project; 
    134         } 
    135  
    136         /** 
    137          * @return the localRepository 
    138          */ 
    139         public ArtifactRepository getLocalRepository() { 
    140                 return localRepository; 
    141         } 
    142  
    143         /** 
    144          * @param localRepository 
    145          *            the localRepository to set 
    146          */ 
    147         public void setLocalRepository(ArtifactRepository localRepository) { 
    148                 this.localRepository = localRepository; 
    149         } 
    150  
    151         /** 
    152          * @return the resolver 
    153          */ 
    154         public ArtifactResolver getResolver() { 
    155                 return resolver; 
    156         } 
    157  
    158         /** 
    159          * @param resolver 
    160          *            the resolver to set 
    161          */ 
    162         public void setResolver(ArtifactResolver resolver) { 
    163                 this.resolver = resolver; 
    164         } 
    165  
    166         /** 
    167          * @return the source 
    168          */ 
    169         public ArtifactMetadataSource getSource() { 
    170                 return source; 
    171         } 
    172  
    173         /** 
    174          * @param source 
    175          *            the source to set 
    176          */ 
    177         public void setSource(ArtifactMetadataSource source) { 
    178                 this.source = source; 
    179         } 
    18044}