Example usage for org.apache.maven.project MavenProject getBuild

List of usage examples for org.apache.maven.project MavenProject getBuild

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getBuild.

Prototype

public Build getBuild() 

Source Link

Usage

From source file:org.ebayopensource.turmeric.plugins.stubs.ProjectClassLoader.java

License:Open Source License

private static URL[] getMavenProjectClassLoaderURLS(MavenProject project) throws MalformedURLException {
    List<File> searchPaths = new ArrayList<File>();

    // Project Compile Artifacts
    @SuppressWarnings("unchecked")
    final List<Artifact> arts = project.getCompileArtifacts();
    if (arts != null) {
        for (Artifact arti : arts) {
            File artiFile = arti.getFile();
            if ((artiFile != null) && (artiFile.exists())) {
                searchPaths.add(artiFile);
            }//from   www.j  av a 2s  .  c  o  m
        }
    }

    // Project Resources
    final List<Resource> resources = project.getBuild().getResources();

    for (Resource resource : resources) {
        String resDir = resource.getDirectory();
        File dir = new File(resDir);
        if (!dir.isAbsolute()) {
            dir = new File(project.getBasedir(), resDir);
        }
        searchPaths.add(dir);
    }

    // The Classes Dir
    File classesDir = new File(project.getBuild().getOutputDirectory());
    if (!classesDir.isAbsolute()) {
        classesDir = new File(project.getBasedir(), project.getBuild().getOutputDirectory());
    }

    searchPaths.add(classesDir);

    // Compile Source Roots - (needed for codegen javac)
    @SuppressWarnings("unchecked")
    List<String> sourceRoots = project.getCompileSourceRoots();
    if (sourceRoots != null) {
        for (String srcRoot : sourceRoots) {
            if (StringUtils.isBlank(srcRoot)) {
                // skip
                continue;
            }
            File src = new File(srcRoot);
            if (src.exists()) {
                searchPaths.add(new File(srcRoot));
            }
        }
    }

    int count = searchPaths.size();
    URL urls[] = new URL[count];
    for (int i = 0; i < count; i++) {
        urls[i] = searchPaths.get(i).toURI().toURL();
        System.out.printf("### ProjectClassLoader[%d]: %s%n", i, urls[i].toExternalForm());
    }

    return urls;
}

From source file:org.eclipse.ebr.tycho.extras.plugin.RecipeBundleProject.java

License:Open Source License

private File getBuildDirectory(final MavenProject project) {
    return new File(project.getBuild().getDirectory());
}

From source file:org.eclipse.m2e.addons.MavenBuildDirectoryViewFilter.java

License:Open Source License

private boolean select(IJavaProject javaProject, IFolder element) throws CoreException {
    IProject project = javaProject.getProject();
    if (project.hasNature(MAVEN_NATURE_ID)) {
        IMavenProjectRegistry registry = MavenPlugin.getMavenProjectRegistry();
        IMavenProjectFacade mavenProjectFacade = registry.getProject(project);
        if (mavenProjectFacade != null) {
            MavenProject mavenProject = mavenProjectFacade.getMavenProject(null);
            Build build = mavenProject.getBuild();
            if (build != null) {
                String directory = build.getDirectory();
                if (directory != null) {
                    IFolder targetFolder = project
                            .getFolder(mavenProjectFacade.getProjectRelativePath(directory));
                    if (targetFolder.equals(element)) {
                        return false;
                    }/*  www  .  j a  v a 2  s.c o m*/
                }
            }
        }
    }
    return true;
}

From source file:org.eclipse.m2e.core.internal.project.registry.MavenProjectFacade.java

License:Open Source License

public MavenProjectFacade(ProjectRegistryManager manager, IFile pom, MavenProject mavenProject,
        Map<String, List<MojoExecution>> executionPlans, ResolverConfiguration resolverConfiguration) {
    this.manager = manager;
    this.pom = pom;
    IPath location = pom.getLocation();/*from   w  w w .  j a v a 2s. c o  m*/
    this.pomFile = location == null ? null : location.toFile(); // save pom file
    this.resolverConfiguration = resolverConfiguration;

    this.mavenProject = mavenProject;
    this.executionPlans = executionPlans;

    this.artifactKey = new ArtifactKey(mavenProject.getArtifact());
    this.packaging = mavenProject.getPackaging();
    this.modules = mavenProject.getModules();

    this.resourceLocations = MavenProjectUtils.getResourceLocations(getProject(), mavenProject.getResources());
    this.testResourceLocations = MavenProjectUtils.getResourceLocations(getProject(),
            mavenProject.getTestResources());
    this.compileSourceLocations = MavenProjectUtils.getSourceLocations(getProject(),
            mavenProject.getCompileSourceRoots());
    this.testCompileSourceLocations = MavenProjectUtils.getSourceLocations(getProject(),
            mavenProject.getTestCompileSourceRoots());

    IPath fullPath = getProject().getFullPath();

    IPath path = getProjectRelativePath(mavenProject.getBuild().getOutputDirectory());
    this.outputLocation = (path != null) ? fullPath.append(path) : null;

    path = getProjectRelativePath(mavenProject.getBuild().getTestOutputDirectory());
    this.testOutputLocation = path != null ? fullPath.append(path) : null;

    this.artifactRepositories = new LinkedHashSet<ArtifactRepositoryRef>();
    for (ArtifactRepository repository : mavenProject.getRemoteArtifactRepositories()) {
        this.artifactRepositories.add(new ArtifactRepositoryRef(repository));
    }

    this.pluginArtifactRepositories = new LinkedHashSet<ArtifactRepositoryRef>();
    for (ArtifactRepository repository : mavenProject.getPluginArtifactRepositories()) {
        this.pluginArtifactRepositories.add(new ArtifactRepositoryRef(repository));
    }

    setMavenProjectArtifacts();

    updateTimestamp();
}

From source file:org.eclipse.m2e.core.project.configurator.AbstractLifecycleMapping.java

License:Open Source License

/**
 * Calls #configure method of all registered project configurators
 *///from  w  ww. ja  v a  2  s. c  o  m
public void configure(ProjectConfigurationRequest request, IProgressMonitor mon) throws CoreException {
    final SubMonitor monitor = SubMonitor.convert(mon, 5);
    try {
        MavenPlugin.getProjectConfigurationManager().addMavenBuilder(request.getProject(), null /*description*/,
                monitor.newChild(1));

        IMavenProjectFacade projectFacade = request.getMavenProjectFacade();
        MavenProject mavenProject = request.getMavenProject();

        Build build = mavenProject.getBuild();
        if (build != null) {
            String directory = build.getDirectory();
            if (directory != null) {
                IContainer container = projectFacade.getProject()
                        .getFolder(projectFacade.getProjectRelativePath(directory));
                if (container != null) {
                    if (!container.exists() && container instanceof IFolder) {
                        M2EUtils.createFolder((IFolder) container, true, monitor.newChild(1));
                    } else {
                        container.setDerived(true, monitor.newChild(1));
                    }
                }
            }
        }

        MavenProjectMutableState snapshot = MavenProjectMutableState.takeSnapshot(mavenProject);

        try {
            //run pre-configuration build
            Map<MojoExecutionKey, List<AbstractBuildParticipant>> participants = new LinkedHashMap<MojoExecutionKey, List<AbstractBuildParticipant>>();
            for (Map.Entry<MojoExecutionKey, List<AbstractBuildParticipant>> entry : getBuildParticipants(
                    projectFacade, monitor).entrySet()) {
                List<AbstractBuildParticipant> participants2 = new ArrayList<AbstractBuildParticipant>();
                for (AbstractBuildParticipant participant : entry.getValue()) {
                    if (participant instanceof AbstractBuildParticipant2) {
                        participants2.add(participant);
                    }
                }

                if (!participants2.isEmpty()) {
                    // @TODO do we want mapping for all executions???
                    participants.put(entry.getKey(), participants2);
                }
            }
            builder.build(request.getMavenSession(), projectFacade,
                    AbstractBuildParticipant2.PRECONFIGURE_BUILD, Collections.<String, String>emptyMap(),
                    participants, monitor);

            //perform configuration
            for (AbstractProjectConfigurator configurator : getProjectConfigurators(projectFacade,
                    monitor.newChild(1))) {
                if (monitor.isCanceled()) {
                    throw new OperationCanceledException();
                }
                configurator.configure(request, monitor.newChild(1));
            }
        } finally {
            snapshot.restore(mavenProject);
        }
    } finally {
        monitor.done();
    }
}

From source file:org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog.java

License:Open Source License

/**
 * @param parent/* w  w w .ja va2  s.  com*/
 * @param title
 * @param mp
 * @param p
 * @param inManagedSection true when the result will be added to the dependencyManagement section of the pom.
 * @return
 */
public static MavenRepositorySearchDialog createSearchPluginDialog(Shell parent, String title, MavenProject mp,
        IProject p, boolean inManagedSection) {
    Set<ArtifactKey> artifacts = new HashSet<ArtifactKey>();
    Set<ArtifactKey> managed = new HashSet<ArtifactKey>();
    Set<ArtifactKey> keys = inManagedSection ? artifacts : managed;
    if (mp != null && mp.getBuild() != null) {
        PluginManagement pm = mp.getBuild().getPluginManagement();
        if (pm != null && pm.getPlugins() != null) {
            for (Plugin plug : pm.getPlugins()) {
                keys.add(new ArtifactKey(plug.getGroupId(), plug.getArtifactId(), plug.getVersion(), null));
            }
        }
        if (!inManagedSection && mp.getModel().getBuild() != null) {
            for (Plugin plug : mp.getModel().getBuild().getPlugins()) {
                artifacts
                        .add(new ArtifactKey(plug.getGroupId(), plug.getArtifactId(), plug.getVersion(), null));
            }
        }

    }
    return new MavenRepositorySearchDialog(parent, title, IIndex.SEARCH_PLUGIN, artifacts, managed, false, mp,
            p, true);
}

From source file:org.eclipse.m2e.jdt.internal.AbstractJavaProjectConfigurator.java

License:Open Source License

protected IContainer getOutputLocation(ProjectConfigurationRequest request, IProject project) {
    MavenProject mavenProject = request.getMavenProject();
    return getFolder(project, mavenProject.getBuild().getOutputDirectory());
}

From source file:org.eclipse.m2e.jdt.internal.AbstractJavaProjectConfigurator.java

License:Open Source License

protected void addProjectSourceFolders(IClasspathDescriptor classpath, ProjectConfigurationRequest request,
        IProgressMonitor monitor) throws CoreException {
    SubMonitor mon = SubMonitor.convert(monitor, 6);
    try {/*  w  w  w .  ja v  a  2 s. com*/
        IProject project = request.getProject();
        MavenProject mavenProject = request.getMavenProject();
        IMavenProjectFacade projectFacade = request.getMavenProjectFacade();

        IFolder classes = getFolder(project, mavenProject.getBuild().getOutputDirectory());
        IFolder testClasses = getFolder(project, mavenProject.getBuild().getTestOutputDirectory());

        M2EUtils.createFolder(classes, true, mon.newChild(1));
        M2EUtils.createFolder(testClasses, true, mon.newChild(1));

        IPath[] inclusion = new IPath[0];
        IPath[] exclusion = new IPath[0];

        IPath[] inclusionTest = new IPath[0];
        IPath[] exclusionTest = new IPath[0];

        String mainSourceEncoding = null;
        String testSourceEncoding = null;

        String mainResourcesEncoding = null;
        String testResourcesEncoding = null;

        List<MojoExecution> executions = getCompilerMojoExecutions(request, mon.newChild(1));

        for (MojoExecution compile : executions) {
            if (isCompileExecution(compile)) {
                mainSourceEncoding = maven.getMojoParameterValue(mavenProject, compile, "encoding", //$NON-NLS-1$
                        String.class, monitor);
                try {
                    inclusion = toPaths(maven.getMojoParameterValue(mavenProject, compile, "includes", //$NON-NLS-1$
                            String[].class, monitor));
                } catch (CoreException ex) {
                    log.error("Failed to determine compiler inclusions, assuming defaults", ex);
                }
                try {
                    exclusion = toPaths(maven.getMojoParameterValue(mavenProject, compile, "excludes", //$NON-NLS-1$
                            String[].class, monitor));
                } catch (CoreException ex) {
                    log.error("Failed to determine compiler exclusions, assuming defaults", ex);
                }
            }
        }

        for (MojoExecution compile : executions) {
            if (isTestCompileExecution(compile)) {
                testSourceEncoding = maven.getMojoParameterValue(mavenProject, compile, "encoding", //$NON-NLS-1$
                        String.class, monitor);
                try {
                    inclusionTest = toPaths(maven.getMojoParameterValue(mavenProject, compile, "testIncludes", //$NON-NLS-1$
                            String[].class, monitor));
                } catch (CoreException ex) {
                    log.error("Failed to determine compiler test inclusions, assuming defaults", ex);
                }
                try {
                    exclusionTest = toPaths(maven.getMojoParameterValue(mavenProject, compile, "testExcludes", //$NON-NLS-1$
                            String[].class, monitor));
                } catch (CoreException ex) {
                    log.error("Failed to determine compiler test exclusions, assuming defaults", ex);
                }
            }
        }

        for (MojoExecution resources : projectFacade.getMojoExecutions(RESOURCES_PLUGIN_GROUP_ID,
                RESOURCES_PLUGIN_ARTIFACT_ID, mon.newChild(1), GOAL_RESOURCES)) {
            mainResourcesEncoding = maven.getMojoParameterValue(mavenProject, resources, "encoding", //$NON-NLS-1$
                    String.class, monitor);
        }

        for (MojoExecution resources : projectFacade.getMojoExecutions(RESOURCES_PLUGIN_GROUP_ID,
                RESOURCES_PLUGIN_ARTIFACT_ID, mon.newChild(1), GOAL_TESTRESOURCES)) {
            testResourcesEncoding = maven.getMojoParameterValue(mavenProject, resources, "encoding", //$NON-NLS-1$
                    String.class, monitor);
        }

        addSourceDirs(classpath, project, mavenProject.getCompileSourceRoots(), classes.getFullPath(),
                inclusion, exclusion, mainSourceEncoding, mon.newChild(1));
        addResourceDirs(classpath, project, mavenProject.getBuild().getResources(), classes.getFullPath(),
                mainResourcesEncoding, mon.newChild(1));

        addSourceDirs(classpath, project, mavenProject.getTestCompileSourceRoots(), testClasses.getFullPath(),
                inclusionTest, exclusionTest, testSourceEncoding, mon.newChild(1));
        addResourceDirs(classpath, project, mavenProject.getBuild().getTestResources(),
                testClasses.getFullPath(), testResourcesEncoding, mon.newChild(1));
    } finally {
        mon.done();
    }
}

From source file:org.eclipse.m2e.jdt.internal.InternalModuleSupport.java

License:Open Source License

private static String getModuleNameFromProject(IPath projectPath, IProgressMonitor monitor) {
    IJavaProject project = getJavaProject(projectPath);
    String module = null;/*from  w w  w . j a  va2  s.c o m*/
    if (project != null) {
        try {
            if (project.getModuleDescription() == null) {
                String buildName = null;
                IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry()
                        .getProject(project.getProject());
                if (facade != null) {
                    MavenProject mavenProject = facade.getMavenProject(monitor);
                    if (mavenProject != null) {
                        buildName = mavenProject.getBuild().getFinalName();
                    }
                }
                if (buildName == null || buildName.isEmpty()) {
                    buildName = project.getElementName();
                }
                module = new String(AutomaticModuleNaming.determineAutomaticModuleName(buildName, false, null));
            } else {
                module = project.getModuleDescription().getElementName();
            }
        } catch (CoreException ex) {
            log.error(ex.getMessage(), ex);
        }
    }
    return module;
}

From source file:org.eclipse.m2e.wtp.ConnectorProjectConfiguratorDelegate.java

License:Open Source License

private void addSourceLinks(IVirtualComponent component, MavenProject mavenProject, IProgressMonitor monitor)
        throws CoreException {
    IProject project = component.getProject();
    IPath classesPath = MavenProjectUtils.getProjectRelativePath(project,
            mavenProject.getBuild().getOutputDirectory());
    if (classesPath != null) {
        for (IPath location : MavenProjectUtils.getSourceLocations(project,
                mavenProject.getCompileSourceRoots())) {
            addLinkIfNecessary(component, location, monitor);
        }//from   www  .j av a2s.  com
        for (IPath location : MavenProjectUtils.getResourceLocations(project, mavenProject.getResources())) {
            addLinkIfNecessary(component, location, monitor);
        }
    }
}