| 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 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | 0 | |
| 31 | |
|
| 32 | 0 | public class ConsoleMojo extends AbstractMojo { |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
private MavenProject project; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
private ArtifactRepository localRepository; |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
private ArtifactResolver resolver; |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
private ArtifactMetadataSource source; |
| 64 | |
|
| 65 | |
private static final String JYTHON_PLUGIN_ARTIFACT_ID = "maven-jython-plugin"; |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | 0 | @SuppressWarnings("unchecked") |
| 73 | |
public void execute() throws MojoExecutionException, MojoFailureException { |
| 74 | 0 | List<File> artifactFile = new ArrayList<File>(); |
| 75 | 0 | |
| 76 | 0 | |
| 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 | |
| 96 | 0 | for (Artifact artifact : (Set<Artifact>) project.getArtifacts()) { |
| 97 | 0 | artifactFile.add(artifact.getFile()); |
| 98 | |
} |
| 99 | 0 | |
| 100 | |
|
| 101 | 0 | artifactFile.add(new File(project.getBuild().getOutputDirectory())); |
| 102 | 0 | |
| 103 | 0 | |
| 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 | |
|
| 127 | 0 | |
| 128 | |
public ArtifactRepository getLocalRepository() { |
| 129 | 0 | return localRepository; |
| 130 | |
} |
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | 0 | |
| 136 | 0 | public void setLocalRepository(ArtifactRepository localRepository) { |
| 137 | 0 | this.localRepository = localRepository; |
| 138 | 0 | } |
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | 0 | |
| 143 | |
public ArtifactResolver getResolver() { |
| 144 | 0 | return resolver; |
| 145 | |
} |
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | 0 | |
| 151 | 0 | public void setResolver(ArtifactResolver resolver) { |
| 152 | 0 | this.resolver = resolver; |
| 153 | 0 | } |
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | 0 | |
| 158 | |
public ArtifactMetadataSource getSource() { |
| 159 | 0 | return source; |
| 160 | |
} |
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | 0 | |
| 166 | 0 | public void setSource(ArtifactMetadataSource source) { |
| 167 | 0 | this.source = source; |
| 168 | 0 | } |
| 169 | |
} |