当前位置: 首页>>代码示例>>Java>>正文


Java ProjectBuilder类代码示例

本文整理汇总了Java中org.apache.maven.project.ProjectBuilder的典型用法代码示例。如果您正苦于以下问题:Java ProjectBuilder类的具体用法?Java ProjectBuilder怎么用?Java ProjectBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ProjectBuilder类属于org.apache.maven.project包,在下文中一共展示了ProjectBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: MavenLoader

import org.apache.maven.project.ProjectBuilder; //导入依赖的package包/类
public MavenLoader(final String m2Home) {
    setMavenHome(m2Home);
    try {
        loadMaven();
        
        final ProjectBuilder projectBuilder = new DefaultProjectBuilder();

        for (final URL pomUrl : lookupPomFiles()) {
            info("URL: %s", pomUrl); 
            setMavenProject(projectBuilder.build(new File(pomUrl.getFile()), new DefaultProjectBuildingRequest()).getProject());
                // mavenProjectClass.getMethod("setPomFile", new Class[] { File.class }).invoke(mavenProject, new File(pomUrl.getFile()));
        } 
    }
    catch (MalformedURLException mue) {
        mue.printStackTrace();
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    setDependencyHandler(new MavenDependencyHandler(mavenProject));
}
 
开发者ID:r351574nc3,项目名称:maven-runtime-agent,代码行数:23,代码来源:MavenLoader.java

示例2: lookupConfiguredMojo

import org.apache.maven.project.ProjectBuilder; //导入依赖的package包/类
/**
 * Workaround for parent class lookupMojo and lookupConfiguredMojo.
 * @param name the name of the Mojo to lookup
 * @param pomPath where to find the POM file
 * @return a configured MSBuild Mojo for testing
 * @throws Exception if we can't find the Mojo or the POM is malformed
 */
protected final Mojo lookupConfiguredMojo( String name, String pomPath ) throws Exception
{
    File pom = new File( getClass().getResource( pomPath ).getPath() );
    assertTrue( pom.exists() );

    // The following 4 lines are simply to get a MavenProject object
    MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
    ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
    ProjectBuilder projectBuilder = this.lookup( ProjectBuilder.class );
    MavenProject mavenProject = projectBuilder.build( pom, buildingRequest ).getProject();
    assertNotNull( mavenProject );
    
    // Used lookupMojo as it sets up most of what we need and reads configuration
    // variables from the poms.
    // It doesn't set a MavenProject so we have to do that manually
    // lookupConfiguredMojo doesn't work properly, configuration variables are no expanded
    // as we expect and it fails to setup a Log.
    Mojo mojo = lookupMojo( name, pom );
    //Mojo mojo = super.lookupConfiguredMojo( mavenProject, name );
    assertNotNull( mojo );

    setVariableValueToObject( mojo, "mavenProject", mavenProject );
    
    return mojo;
}
 
开发者ID:andi12,项目名称:msbuild-maven-plugin,代码行数:33,代码来源:AbstractMSBuildMojoTestCase.java

示例3: resolveDependenciesFromPOM

import org.apache.maven.project.ProjectBuilder; //导入依赖的package包/类
public List<Dependency> resolveDependenciesFromPOM(File pomFile) throws Exception
{
   PlexusContainer plexus = new PlexusContainer();
   List<Dependency> result;
   try
   {
      ProjectBuildingRequest request = getBuildingRequest(plexus);
      request.setResolveDependencies(true);
      ProjectBuilder builder = plexus.lookup(ProjectBuilder.class);
      ProjectBuildingResult build = builder.build(pomFile, request);
      result = build.getDependencyResolutionResult().getDependencies();
   }
   finally
   {
      plexus.shutdown();
   }
   return result;
}
 
开发者ID:forge,项目名称:furnace,代码行数:19,代码来源:ProjectHelper.java

示例4: getProjectBuilder

import org.apache.maven.project.ProjectBuilder; //导入依赖的package包/类
private ProjectBuilder getProjectBuilder()
{
    if ( projectBuilder != null )
    {
        return projectBuilder;
    }

    try
    {
        projectBuilder = container.lookup( ProjectBuilder.class );
    }
    catch ( ComponentLookupException e )
    {
        // Won't happen
    }

    return projectBuilder;
}
 
开发者ID:gems-uff,项目名称:oceano,代码行数:19,代码来源:MavenMetadataSource.java

示例5: testSomething

import org.apache.maven.project.ProjectBuilder; //导入依赖的package包/类
/**
 * @throws Exception if any
 */
@Test
public void testSomething()
        throws Exception {
    File projectBase = getTestFile("src/test/resources/com/vityuk/ginger/maven/");
    File pom = new File(projectBase, "pom.xml");
    assertNotNull(pom);
    assertTrue(pom.exists());

    MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
    ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
    ProjectBuilder projectBuilder = lookup(ProjectBuilder.class);
    MavenProject project = projectBuilder.build(pom, buildingRequest).getProject();

    MavenGeneratorMojo myMojo = (MavenGeneratorMojo) lookupConfiguredMojo(project, "ginger-generator");
    assertNotNull(myMojo);

    myMojo.execute();

    File outputDirectory = new File(myMojo.outputDirectory);
    File resultFile = new File(outputDirectory, "com/vityuk/ginger/test1/GeneralConstants.java");
    assertTrue("GeneralConstants.java is NOT generated", resultFile.exists());
}
 
开发者ID:avityuk,项目名称:ginger,代码行数:26,代码来源:MavenGeneratorTest.java

示例6: loadParentOf

import org.apache.maven.project.ProjectBuilder; //导入依赖的package包/类
/**
 * replacement for MavenProject.getParent() which has bad long term memory behaviour. We offset it by recalculating/reparsing everything
 * therefore should not be used lightly!
 * pass a MavenProject instance and current configuration and other settings will be applied when loading the parent.
 * @param project
 * @return null or the parent mavenproject
 */

public MavenProject loadParentOf(MavenEmbedder embedder, MavenProject project) throws ProjectBuildingException {

    MavenProject parent = null;
    ProjectBuilder builder = embedder.lookupComponent(ProjectBuilder.class);
    MavenExecutionRequest req = embedder.createMavenExecutionRequest();
    M2Configuration active = configProvider.getActiveConfiguration();
    req.addActiveProfiles(active.getActivatedProfiles());
    req.setNoSnapshotUpdates(true);
    req.setUpdateSnapshots(false);
    req.setInteractiveMode(false);
    req.setRecursive(false);
    req.setOffline(true);
    //#238800 important to merge, not replace
    Properties uprops = req.getUserProperties();
    uprops.putAll(MavenProjectCache.createUserPropsForProjectLoading(active.getProperties()));
    req.setUserProperties(uprops);
    
    ProjectBuildingRequest request = req.getProjectBuildingRequest();
    request.setRemoteRepositories(project.getRemoteArtifactRepositories());
    DefaultMaven maven = (DefaultMaven) embedder.lookupComponent(Maven.class);
    
    request.setRepositorySession(maven.newRepositorySession(req));

    if (project.getParentFile() != null) {
        parent = builder.build(project.getParentFile(), request).getProject();
    } else if (project.getModel().getParent() != null) {
        parent = builder.build(project.getParentArtifact(), request).getProject();
    }
    //clear the project building request, it references multiple Maven Models via the RepositorySession cache
    //is not used in maven itself, most likely used by m2e only..
    if (parent != null) {
        parent.setProjectBuildingRequest(null);
    }
    MavenEmbedder.normalizePaths(parent);
    return parent;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:45,代码来源:NbMavenProjectImpl.java

示例7: runMavenValidationImpl

import org.apache.maven.project.ProjectBuilder; //导入依赖的package包/类
static List<ModelProblem> runMavenValidationImpl(final File pom) {
    //TODO profiles based on current configuration??
    MavenEmbedder embedder = EmbedderFactory.getProjectEmbedder();
    MavenExecutionRequest meReq = embedder.createMavenExecutionRequest();
    ProjectBuildingRequest req = meReq.getProjectBuildingRequest();
    req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1); // currently enables just <reporting> warning
    req.setLocalRepository(embedder.getLocalRepository());
    List<ArtifactRepository> remoteRepos = RepositoryPreferences.getInstance().remoteRepositories(embedder);
    req.setRemoteRepositories(remoteRepos);
    req.setRepositorySession(((DefaultMaven) embedder.lookupComponent(Maven.class)).newRepositorySession(meReq));
    List<ModelProblem> problems;
    try {
        problems = embedder.lookupComponent(ProjectBuilder.class).build(pom, req).getProblems();
    } catch (ProjectBuildingException x) {
        problems = new ArrayList<ModelProblem>();
        List<ProjectBuildingResult> results = x.getResults();
        if (results != null) { //one code point throwing ProjectBuildingException contains results,
            for (ProjectBuildingResult result : results) {
                problems.addAll(result.getProblems());
            }
        } else {
            // another code point throwing ProjectBuildingException doesn't contain results..
            Throwable cause = x.getCause();
            if (cause instanceof ModelBuildingException) {
                problems.addAll(((ModelBuildingException) cause).getProblems());
            }
        }
    }
    return problems;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:EffectivePomMD.java

示例8: MavenEmbedder

import org.apache.maven.project.ProjectBuilder; //导入依赖的package包/类
MavenEmbedder(EmbedderConfiguration configuration) throws ComponentLookupException {
    embedderConfiguration = configuration;
    plexus = configuration.getContainer();
    this.maven = (DefaultMaven) plexus.lookup(Maven.class);
    this.projectBuilder = plexus.lookup(ProjectBuilder.class);
    this.repositorySystem = plexus.lookup(RepositorySystem.class);
    this.settingsBuilder = plexus.lookup(SettingsBuilder.class);
    this.populator = plexus.lookup(MavenExecutionRequestPopulator.class);
    settingsDecrypter = plexus.lookup(SettingsDecrypter.class);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:MavenEmbedder.java

示例9: runMavenValidationImpl

import org.apache.maven.project.ProjectBuilder; //导入依赖的package包/类
static List<ModelProblem> runMavenValidationImpl(final File pom) {
    MavenEmbedder embedder = EmbedderFactory.getProjectEmbedder();
    MavenExecutionRequest meReq = embedder.createMavenExecutionRequest();
    ProjectBuildingRequest req = meReq.getProjectBuildingRequest();
    req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0); // 3.1 currently enables just <reporting> warning, see issue 223562 for details on why it's bad to show.
    req.setLocalRepository(embedder.getLocalRepository());
    List<ArtifactRepository> remoteRepos = RepositoryPreferences.getInstance().remoteRepositories(embedder);
    req.setRemoteRepositories(remoteRepos);
    req.setRepositorySession(((DefaultMaven) embedder.lookupComponent(Maven.class)).newRepositorySession(meReq));
    List<ModelProblem> problems;
    try {
        problems = embedder.lookupComponent(ProjectBuilder.class).build(pom, req).getProblems();
    } catch (ProjectBuildingException x) {
        problems = new ArrayList<ModelProblem>();
        List<ProjectBuildingResult> results = x.getResults();
        if (results != null) { //one code point throwing ProjectBuildingException contains results,
            for (ProjectBuildingResult result : results) {
                problems.addAll(result.getProblems());
            }
        } else {
            // another code point throwing ProjectBuildingException doesn't contain results..
            Throwable cause = x.getCause();
            if (cause instanceof ModelBuildingException) {
                problems.addAll(((ModelBuildingException) cause).getProblems());
            }
        }
    }
    List<ModelProblem> toRet = new LinkedList<ModelProblem>();
    for (ModelProblem problem : problems) {
        if(ModelUtils.checkByCLIMavenValidationLevel(problem)) {
            toRet.add(problem);
        }
    }
    return toRet;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:StatusProvider.java

示例10: createDependencyEnforcer

import org.apache.maven.project.ProjectBuilder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private DependencyChecker createDependencyEnforcer(final EnforcerRuleHelper enforcerRuleHelper)
        throws ComponentLookupException, ExpressionEvaluationException {

    return new DependencyChecker(log,
            (RepositorySystem) enforcerRuleHelper.getComponent(RepositorySystem.class),
            (ProjectBuilder) enforcerRuleHelper.getComponent(ProjectBuilder.class),
            (RepositorySystemSession) enforcerRuleHelper.evaluate("${session.repositorySession}"),
            exclusions == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(exclusions)),
            getWhitelistedLicensesSet());
}
 
开发者ID:patrickpilch,项目名称:dependency-license-checker,代码行数:12,代码来源:LicenseEnforcerRule.java

示例11: findMojo

import org.apache.maven.project.ProjectBuilder; //导入依赖的package包/类
private <T extends AbstractGolangMojo> T findMojo(final Class<T> klazz, final String pomName, final String goal) throws Exception {
  final File pomFile = new File(GolangMojoCfgTest.class.getResource(pomName).toURI());
  final MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
  final ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
  final ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
  final MavenProject project = projectBuilder.build(pomFile, buildingRequest).getProject();
  return klazz.cast(this.lookupConfiguredMojo(project, goal));
}
 
开发者ID:raydac,项目名称:mvn-golang,代码行数:9,代码来源:GolangMojoCfgTest.java

示例12: lookupMojo

import org.apache.maven.project.ProjectBuilder; //导入依赖的package包/类
protected Mojo lookupMojo(Path pomPath, String goal) throws Exception {
    File pom = getTestFile(pomPath.toString());
    assertTrue(pom.exists());

    MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
    ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
    buildingRequest.setRepositorySession(new DefaultRepositorySystemSession());

    ProjectBuilder projectBuilder = lookup(ProjectBuilder.class);
    MavenProject project = projectBuilder.build(pom, buildingRequest).getProject();

    return lookupConfiguredMojo(project, goal);
}
 
开发者ID:dglecom,项目名称:rpm-systemd-maven-plugin,代码行数:14,代码来源:AbstractHarnessMojoTestCase.java

示例13: ScmRepositoryIndex

import org.apache.maven.project.ProjectBuilder; //导入依赖的package包/类
private ScmRepositoryIndex(MavenSession session, RepositorySystemSession repoSession,
        ArtifactFactory repositorySystem, ProjectBuilder projectBuilder, Set<org.srcdeps.core.Scm> scms) {
    super();
    this.session = session;
    this.repoSession = repoSession;
    this.repositorySystem = repositorySystem;
    this.projectBuilder = projectBuilder;
    this.remoteRepos = RepositoryUtils.toRepos(session.getProjectBuildingRequest().getRemoteRepositories());
    this.scms = scms;
}
 
开发者ID:srcdeps,项目名称:srcdeps-maven,代码行数:11,代码来源:SrcdepsInitMojo.java

示例14: lookupConfiguredMojo

import org.apache.maven.project.ProjectBuilder; //导入依赖的package包/类
private Mojo lookupConfiguredMojo(String goal, File pom) throws Exception
{
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setBaseDirectory(pom.getParentFile());
    ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
    // Fix for bug: https://git-wip-us.apache.org/repos/asf?p=maven-plugin-testing.git;a=commit;h=3cd5f47c586499e438a3f9393304ac9d1f9a7f53
    configuration.setRepositorySession(new DefaultRepositorySystemSession());
    MavenProject project = lookup(ProjectBuilder.class).build(pom, configuration).getProject();
    return super.lookupConfiguredMojo(project, goal);
}
 
开发者ID:NordeaOSS,项目名称:copybook4java,代码行数:11,代码来源:CodeGenMojoTest.java

示例15: newMojo

import org.apache.maven.project.ProjectBuilder; //导入依赖的package包/类
protected AbstractXmlMojo newMojo( String pDir )
        throws Exception
    {
        File testPom = new File( new File( getBasedir(), pDir ), "pom.xml" );
        
        MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
        ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
        ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
        MavenProject project = projectBuilder.build(testPom, buildingRequest).getProject();
//        final Build build = new Build();
//        build.setDirectory( "target" );
//        project.setBuild(build);
        project.getBuild().setDirectory("target");
        AbstractXmlMojo vm = (AbstractXmlMojo) lookupConfiguredMojo(project, getGoal());
        setVariableValueToObject( vm, "basedir", new File( getBasedir(), pDir ) );
        final Log log = new SilentLog();
        DefaultResourceManager rm = new DefaultResourceManager();
        setVariableValueToObject( rm, "logger", log );
        setVariableValueToObject( vm, "locator", rm );
        final Map<String, ResourceLoader> resourceLoaders = new HashMap<String, ResourceLoader>();
        resourceLoaders.put( "file", new FileResourceLoader() );
        resourceLoaders.put( "jar", new JarResourceLoader() );
        resourceLoaders.put( "classloader", new ThreadContextClasspathResourceLoader() );
        URLResourceLoader url = new URLResourceLoader();
        setVariableValueToObject( url, "logger", log );
        resourceLoaders.put( "url", url );
        setVariableValueToObject( rm, "resourceLoaders", resourceLoaders );

//        MavenProjectStub project = new MavenProjectStub()
//        {
//            public Build getBuild()
//            {
//                return build;
//            }
//        };
//        setVariableValueToObject( vm, "project", project );
        return vm;
    }
 
开发者ID:mojohaus,项目名称:xml-maven-plugin,代码行数:39,代码来源:AbstractXmlMojoTestCase.java


注:本文中的org.apache.maven.project.ProjectBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。