浏览 3559 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2014-01-23
我想手动调用execute()方法来获取几个我需要的信息,我的代码是: @SuppressWarnings("unchecked") public class GenerateTriggerMojo extends AbstractMojo { /** * @parameter */ private List<String> searchPackageNames; /** * @parameter expression="${project}" */ private MavenProject mavenProject; @Override public void execute() throws MojoExecutionException, MojoFailureException { searchPackageNames=null; //Model model=new Model(); //model.setArtifactId("test.mojo"); //mavenProject=new MavenProject(model); //mavenProject.setArtifactId("test.mojo"); //File file =new File("Volumes/MacHD/Users/john/Documents/workspace/MojoTest"); //mavenProject.setFile(file); //mavenProject.setGroupId("com.java"); //init(); String currentModule = mavenProject.getArtifactId(); List<String> classpathElementList = (List<String>) mavenProject.getCompileClasspathElements(); String basedir=mavenProject.getBasedir().toString(); } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2014-01-23
试试:(MavenProject)getPluginContext().get("project");
|
|
返回顶楼 | |
发表时间:2014-01-24
谢谢啊,我试了不行,还是抛空指针,因为我是直接在JAVA代码里调用这个GenerateTriggerMojo这个类的execute(),不是通过mvn命令运行,所以应该超类里的方法为空
|
|
返回顶楼 | |
发表时间:2014-01-24
也就是说有什么方法能脱离mvn命令,直接通过JAVA代码调用来初始化这个对象或者通过什么方式能初始化这个对象呢?
|
|
返回顶楼 | |
发表时间:2014-01-30
我有写过一个小工具,供你参考下,主要关注这个类所属的模块来解析MavenXpp3Reader
Model model = null; FileReader reader = null; MavenXpp3Reader mavenreader = new MavenXpp3Reader(); String pomfile = destFile; reader = new FileReader(pomfile); model = mavenreader.read(reader); model.setPomFile(new File(pomfile)); // exclude 此模块的依赖的本地模块 UpDependency exit = new UpDependency(); exit.setArtifactId(model.getArtifactId()); exit.setGroupId(model.getGroupId()); exit.setVersion(model.getVersion()); po.addexistDependency(exit); // parser Root po.setDependencys(ParserUtils.parserDependency(model.getDependencies())); if (model.getDependencyManagement() != null) { po.setDependencyManagements(ParserUtils.parserDependency(model.getDependencyManagement().getDependencies())); } if (model.getBuild() != null && model.getBuild().getPluginManagement() != null) { po.setPluginManagements(ParserUtils.parserPlugin(model.getBuild().getPluginManagement().getPlugins())); } if (model.getBuild() != null) { po.setPlugins(ParserUtils.parserPlugin(model.getBuild().getPlugins())); } log.debug("parser profile"); // parser profile List<Profile> pfs = model.getProfiles(); for (Profile pf : pfs) { po.setDependencys(ParserUtils.parserDependency(pf.getDependencies())); if (pf.getDependencyManagement() != null) { po.setDependencyManagements(ParserUtils .parserDependency(pf.getDependencyManagement().getDependencies())); } if (pf.getBuild() != null) { po.setPlugins(ParserUtils.parserPlugin(pf.getBuild().getPlugins())); if (pf.getBuild().getPluginManagement() != null) { po.setPluginManagements(ParserUtils.parserPlugin(pf.getBuild().getPluginManagement().getPlugins())); } } } |
|
返回顶楼 | |
发表时间:2014-02-25
貌似可以啊,非常感谢,我先试试啊
|
|
返回顶楼 | |