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

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

Introduction

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

Prototype

public Plugin getPlugin(String pluginKey) 

Source Link

Usage

From source file:org.eclipse.tycho.core.resolver.CompilerOptionsManager.java

License:Open Source License

public CompilerOptions getCompilerOptions(MavenProject project) {

    Plugin plugin = project.getPlugin("org.eclipse.tycho:tycho-compiler-plugin");

    OptionalResolutionAction optionalAction = null;
    List<Dependency> extraRequirements = null;
    if (plugin != null) {
        // TODO check version?
        Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
        if (configuration != null) {
            optionalAction = getOptionalResolutionAction(configuration);
            extraRequirements = getExtraRequirements(configuration);
        }/*from w ww .  j a va 2 s  . c o m*/
    }

    if (optionalAction == null) {
        optionalAction = OptionalResolutionAction.REQUIRE;
    }
    return new CompilerOptions(optionalAction, extraRequirements);
    // TODO cache this value by attaching it to the project?
}

From source file:org.eclipse.tycho.core.resolver.DefaultTargetPlatformConfigurationReader.java

License:Open Source License

public TargetPlatformConfiguration getTargetPlatformConfiguration(MavenSession session, MavenProject project) {
    TargetPlatformConfiguration result = new TargetPlatformConfiguration();

    // Use org.eclipse.tycho:target-platform-configuration/configuration/environment, if provided
    Plugin plugin = project.getPlugin("org.eclipse.tycho:target-platform-configuration");

    if (plugin != null) {
        Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
        if (configuration != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("target-platform-configuration for " + project.toString() + ":\n"
                        + configuration.toString());
            }//ww  w .j av  a 2 s  . c  om

            addTargetEnvironments(result, project, configuration);

            setTargetPlatformResolver(result, configuration);

            setTarget(result, session, project, configuration);

            setPomDependencies(result, configuration);

            setAllowConflictingDependencies(result, configuration);

            setDisableP2Mirrors(result, configuration);

            setExecutionEnvironment(result, configuration);

            readFilters(result, configuration);

            readExtraRequirements(result, configuration);

            setOptionalDependencies(result, configuration);
        }
    }

    if (result.getEnvironments().isEmpty()) {
        TychoProject projectType = projectTypes.get(project.getPackaging());
        if (projectType != null) {
            TargetEnvironment env = projectType.getImplicitTargetEnvironment(project);
            if (env != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug(
                            "Implicit target environment for " + project.toString() + ": " + env.toString());
                }

                result.addEnvironment(env);
            }
        }
    }

    if (result.getEnvironments().isEmpty()) {
        // applying defaults
        logger.warn("No explicit target runtime environment configuration. Build is platform dependent.");

        // Otherwise, use project or execution properties, if provided
        Properties properties = (Properties) project.getContextValue(TychoConstants.CTX_MERGED_PROPERTIES);

        // Otherwise, use current system os/ws/nl/arch
        String os = PlatformPropertiesUtils.getOS(properties);
        String ws = PlatformPropertiesUtils.getWS(properties);
        String arch = PlatformPropertiesUtils.getArch(properties);

        result.addEnvironment(new TargetEnvironment(os, ws, arch, null /* nl */));

        result.setImplicitTargetEnvironment(true);
    } else {
        result.setImplicitTargetEnvironment(false);
    }

    return result;
}

From source file:org.eclipse.tycho.extras.custombundle.CustomBundleP2MetadataProvider.java

License:Open Source License

public Map<String, IDependencyMetadata> getDependencyMetadata(MavenSession session, MavenProject project,
        List<Map<String, String>> environments, OptionalResolutionAction optionalAction) {
    Map<String, IDependencyMetadata> metadata = new LinkedHashMap<String, IDependencyMetadata>();
    Plugin plugin = project.getPlugin("org.eclipse.tycho.extras:tycho-custom-bundle-plugin");
    if (plugin != null) {
        // it is possible to configure manifest location at <plugin> level, but it does not make sense to do so
        for (PluginExecution execution : plugin.getExecutions()) {
            File location = getBundleLocation(execution);
            String classifier = getClassifier(execution);
            if (location != null && classifier != null) {
                IArtifactFacade artifact = new AttachedArtifact(project, location, classifier);
                metadata.put(classifier, new SecondaryDependencyMetadata(
                        generator.generateMetadata(artifact, environments, optionalAction)));
            }/*from  w  w w  . j  a  v a  2 s. c o  m*/
        }
    }
    return metadata;
}

From source file:org.eclipse.tycho.extras.sourcefeature.SourceFeatureP2MetadataProvider.java

License:Open Source License

public Map<String, IDependencyMetadata> getDependencyMetadata(MavenSession session, MavenProject project,
        List<Map<String, String>> environments, OptionalResolutionAction optionalAction) {
    File template = new File(project.getBasedir(), SourceFeatureMojo.FEATURE_TEMPLATE_DIR);

    if (!ArtifactKey.TYPE_ECLIPSE_FEATURE.equals(project.getPackaging()) || !template.isDirectory()) {
        return null;
    }//from w w w. j  a v a 2  s  . c  o m

    Plugin plugin = project.getPlugin("org.eclipse.tycho.extras:tycho-source-feature-plugin");
    if (plugin != null) {
        try {
            File sourceFeatureBasedir = SourceFeatureMojo.getSourcesFeatureDir(project);

            /*
             * There is no easy way to determine what *exact* source bundles/features will be
             * included in the source feature at this point. Because of this, the source feature
             * dependency-only metadata does not include any dependencies.
             * 
             * This has two implications.
             * 
             * First, any missing source bundles/features will not be detected/reported until
             * source feature mojo is executed. This is inconsistent with how everything else
             * works in Tycho, but probably is a good thing.
             * 
             * More importantly, though, source bundles/features are not included as transitive
             * dependencies of other reactor projects that include the source feature. To solve
             * this for eclipse-repository project, repository project dependencies are
             * recalculated during repository packaging. Other 'aggregating' project types, like
             * eclipse-update-site and eclipse-feature with deployableFeature=true, will not be
             * compatible with source features until
             * https://bugs.eclipse.org/bugs/show_bug.cgi?id=353889 is implemented.
             */
            Feature feature = Feature.read(new File(project.getBasedir(), "feature.xml"));

            Document document = new Document();
            document.setRootNode(new Element("feature"));
            document.setXmlDeclaration(new XMLDeclaration("1.0", "UTF-8"));
            Feature sourceFeature = new Feature(document);

            sourceFeature.setId(feature.getId() + ".source");
            sourceFeature.setVersion(feature.getVersion());

            Feature.write(sourceFeature, new File(sourceFeatureBasedir, Feature.FEATURE_XML));

            String classifier = SourceFeatureMojo.SOURCES_FEATURE_CLASSIFIER;
            IArtifactFacade artifact = new AttachedArtifact(project, sourceFeatureBasedir, classifier);
            return Collections.singletonMap(classifier,
                    generator.generateMetadata(artifact, null, OptionalResolutionAction.REQUIRE));
        } catch (IOException e) {
            log.error("Could not create sources feature.xml", e);
        }
    }

    return null;
}

From source file:org.eclipse.tycho.source.OsgiSourceMojo.java

License:Open Source License

protected static boolean isRelevantProjectImpl(MavenProject project,
        BuildPropertiesParser buildPropertiesParser) {
    String packaging = project.getPackaging();
    boolean relevant = org.eclipse.tycho.ArtifactKey.TYPE_ECLIPSE_PLUGIN.equals(packaging)
            || org.eclipse.tycho.ArtifactKey.TYPE_ECLIPSE_TEST_PLUGIN.equals(packaging);
    if (!relevant) {
        return false;
    }//from ww  w .  j a v  a2s.  c  o m

    // this assumes that sources generation has to be explicitly enabled in pom.xml
    Plugin plugin = project.getPlugin("org.eclipse.tycho:tycho-source-plugin");

    if (plugin == null) {
        return false;
    }

    for (PluginExecution execution : plugin.getExecutions()) {
        if (execution.getGoals().contains(GOAL)) {
            boolean requireSourceRoots = Boolean
                    .parseBoolean(getParameterValue(execution, "requireSourceRoots", "false"));
            if (requireSourceRoots) {
                return true;
            }
            try {
                if (!getSources(project, requireSourceRoots, buildPropertiesParser).isEmpty()) {
                    return true;
                }
            } catch (MojoExecutionException e) {
                // can't happen because requireSourceRoots==false 
            }
        }
    }

    return false;
}

From source file:org.jboss.tools.maven.jaxrs.configurators.JaxrsProjectConfigurator.java

License:Open Source License

private String getWarSourceDirectory(MavenProject mavenProject, IProject project) {
    Plugin plugin = mavenProject.getPlugin("org.apache.maven.plugins:maven-war-plugin");
    if (plugin != null && plugin.getConfiguration() instanceof Xpp3Dom) {
        Xpp3Dom dom = (Xpp3Dom) plugin.getConfiguration();
        Xpp3Dom[] warSourceDirectory = dom.getChildren("warSourceDirectory");
        if (warSourceDirectory != null && warSourceDirectory.length > 0) {
            // first one wins
            String dir = warSourceDirectory[0].getValue();
            if (project != null) {
                return WTPProjectsUtil.tryProjectRelativePath(project, dir).toOSString();
            }//from  w  w w .  j  a v  a2 s  .co  m
            return dir;
        }
    }
    return "src/main/webapp";
}

From source file:org.jboss.tools.maven.jsf.configurators.JSFProjectConfigurator.java

License:Open Source License

private String getWarSourceDirectory(MavenProject mavenProject, IProject project) {
    Plugin plugin = mavenProject.getPlugin("org.apache.maven.plugins:maven-war-plugin");
    if (plugin == null) {
        return null;
    }//from www. j  a v  a 2 s .  co  m
    Xpp3Dom config = (Xpp3Dom) plugin.getConfiguration();
    if (config == null) {
        return WAR_SOURCE_FOLDER;
    }
    Xpp3Dom[] warSourceDirectory = config.getChildren("warSourceDirectory");
    if (warSourceDirectory != null && warSourceDirectory.length > 0) {
        String dir = warSourceDirectory[0].getValue();
        if (project != null) {
            return tryProjectRelativePath(project, dir).toOSString();
        }
        return dir;
    }
    return WAR_SOURCE_FOLDER;
}

From source file:org.maven.ide.eclipse.ajdt.AspectJPluginConfiguration.java

License:Open Source License

private static Plugin getAspectJPlugin(MavenProject mavenProject) {
    return mavenProject.getPlugin("org.codehaus.mojo:aspectj-maven-plugin");
}

From source file:org.maven.ide.eclipse.annotations.AptConfigurator.java

License:Open Source License

private ProcessorConfiguration getProcessorConfiguration(final ProjectConfigurationRequest p_request,
        final IProgressMonitor p_monitor) throws CoreException {
    IMavenProjectFacade projectFacade = p_request.getMavenProjectFacade();
    MavenProject mavenProject = projectFacade.getMavenProject(p_monitor);

    Plugin queryDslPlugin = mavenProject.getPlugin("org.bsc.maven:maven-processor-plugin");
    ProcessorConfiguration processorConfiguration = new ProcessorConfiguration(queryDslPlugin);

    return processorConfiguration;
}

From source file:org.maven.ide.eclipse.checkstyle.MavenCheckstyleProjectConfigurator.java

License:Open Source License

/**
 * Find (if exist) the maven-checkstyle-plugin configuration in the
 * mavenProject//from ww  w .j a  va 2s . com
 */
private Plugin getCheckstylePlugin(final MavenProject mavenProject) {
    return mavenProject.getPlugin(CHECKSTYLE_PLUGIN_GROUPID + ":" + CHECKSTYLE_PLUGIN_ARTIFACTID);
}