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

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

Introduction

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

Prototype

public List<Plugin> getBuildPlugins() 

Source Link

Usage

From source file:org.onosproject.yangutils.plugin.manager.YangPluginUtils.java

License:Apache License

/**
 * Adds version meta data files for YSR to know version of YANG tools.
 *
 * @param project maven project// ww w. ja v a 2 s.com
 * @param dir     directory
 * @throws IOException when fails to do IO operations
 */
private static void addVersionMetaDataFile(MavenProject project, String dir) throws IOException {
    List<Plugin> plugins = project.getBuildPlugins();
    Iterator<Plugin> it = plugins.iterator();
    Plugin plugin = it.next();
    String data = EMPTY_STRING;
    while (it.hasNext()) {
        if (plugin.getArtifactId().equals(PLUGIN_ARTIFACT)) {
            data = plugin.getGroupId() + COLON + plugin.getArtifactId() + COLON + plugin.getVersion();
        }
        plugin = it.next();
    }
    if (data.equals(EMPTY_STRING)) {
        throw new IOException("Invalid artifact for " + PLUGIN_ARTIFACT);
    }
    String verFileName = dir + VERSION_META_DATA + TEXT_FILE_EXTENSION;
    PrintWriter out = new PrintWriter(verFileName);
    out.print(data);
    out.close();
}

From source file:org.phpmaven.core.ComponentFactory.java

License:Apache License

/**
 * {@inheritDoc}/*from   w w w  . j a v  a  2  s.  c  o  m*/
 */
@Override
public Xpp3Dom getBuildConfig(final MavenProject project, String groupid, String artifactId) {
    if (project == null) {
        return null;
    }
    final List<Plugin> plugins = project.getBuildPlugins();
    for (final Plugin plugin : plugins) {
        if (plugin.getGroupId().equals(groupid) && plugin.getArtifactId().equals(artifactId)) {
            return (Xpp3Dom) plugin.getConfiguration();
        }
    }
    return null;
}

From source file:org.revapi.maven.ReportAggregateMojo.java

License:Apache License

protected static Plugin findRevapi(MavenProject project) {
    return project.getBuildPlugins().stream().filter(p -> "org.revapi:revapi-maven-plugin".equals(p.getKey()))
            .findAny().orElse(null);/*from  w  w w. j  a  v  a  2  s  . c om*/
}

From source file:org.sonar.api.batch.maven.MavenPlugin.java

License:Open Source License

/**
 * Returns a plugin from a pom based on its group id and artifact id
 * <p/>/*from  w w w  .  j  a v  a 2 s. c om*/
 * <p>It searches in the build section, then the reporting section and finally the pluginManagement section</p>
 *
 * @param pom the project pom
 * @param groupId the plugin group id
 * @param artifactId the plugin artifact id
 * @return the plugin if it exists, null otherwise
 */
public static MavenPlugin getPlugin(MavenProject pom, String groupId, String artifactId) {
    if (pom == null) {
        return null;
    }
    // look for plugin in <build> section
    Plugin plugin = null;
    if (pom.getBuildPlugins() != null) {
        plugin = getPlugin(pom.getBuildPlugins(), groupId, artifactId);
    }

    // look for plugin in <report> section
    if (plugin == null && pom.getReportPlugins() != null) {
        plugin = getReportPlugin(pom.getReportPlugins(), groupId, artifactId);
    }

    // look for plugin in <pluginManagement> section
    if (pom.getPluginManagement() != null) {
        Plugin pluginManagement = getPlugin(pom.getPluginManagement().getPlugins(), groupId, artifactId);
        if (plugin == null) {
            plugin = pluginManagement;

        } else if (pluginManagement != null) {
            if (pluginManagement.getConfiguration() != null) {
                if (plugin.getConfiguration() == null) {
                    plugin.setConfiguration(pluginManagement.getConfiguration());
                } else {
                    Xpp3Dom.mergeXpp3Dom((Xpp3Dom) plugin.getConfiguration(),
                            (Xpp3Dom) pluginManagement.getConfiguration());
                }
            }
            if (plugin.getDependencies() == null && pluginManagement.getDependencies() != null) {
                plugin.setDependencies(pluginManagement.getDependencies());
            }
            if (plugin.getVersion() == null) {
                plugin.setVersion(pluginManagement.getVersion());
            }
        }
    }

    if (plugin != null) {
        return new MavenPlugin(plugin);
    }
    return null;
}

From source file:org.sonar.api.batch.maven.MavenPlugin.java

License:Open Source License

private static void unregisterPlugin(MavenProject pom, String groupId, String artifactId) {
    if (pom.getPluginManagement() != null && pom.getPluginManagement().getPlugins() != null) {
        unregisterPlugin(pom.getPluginManagement().getPlugins(), groupId, artifactId);
    }//from w  w w  .j  a v  a  2 s  .c  o m
    List plugins = pom.getBuildPlugins();
    if (plugins != null) {
        unregisterPlugin(plugins, groupId, artifactId);
    }
    plugins = pom.getReportPlugins();
    if (plugins != null) {
        unregisterReportPlugin(plugins, groupId, artifactId);
    }
}

From source file:org.sonarsource.scanner.maven.bootstrap.MavenPlugin.java

License:Open Source License

/**
 * Returns a plugin from a pom based on its group id and artifact id
 * <p>//from w ww.j  a va2 s .  c o m
 * It searches in the build section, then the reporting section and finally the pluginManagement section
 * </p>
 *
 * @param pom the project pom
 * @param groupId the plugin group id
 * @param artifactId the plugin artifact id
 * @return the plugin if it exists, null otherwise
 */
@CheckForNull
public static MavenPlugin getPlugin(MavenProject pom, String groupId, String artifactId) {
    Object pluginConfiguration = null;

    // look for plugin in <build> section
    Plugin plugin = getPlugin(pom.getBuildPlugins(), groupId, artifactId);

    if (plugin != null) {
        pluginConfiguration = plugin.getConfiguration();
    } else {
        // look for plugin in reporting
        Reporting reporting = pom.getModel().getReporting();
        if (reporting != null) {
            ReportPlugin reportPlugin = getReportPlugin(reporting.getPlugins(), groupId, artifactId);
            if (reportPlugin != null) {
                pluginConfiguration = reportPlugin.getConfiguration();
            }
        }
    }

    // look for plugin in <pluginManagement> section
    PluginManagement pluginManagement = pom.getPluginManagement();
    if (pluginManagement != null) {
        Plugin pluginFromManagement = getPlugin(pluginManagement.getPlugins(), groupId, artifactId);
        if (pluginFromManagement != null) {
            Object pluginConfigFromManagement = pluginFromManagement.getConfiguration();
            if (pluginConfiguration == null) {
                pluginConfiguration = pluginConfigFromManagement;
            } else if (pluginConfigFromManagement != null) {
                Xpp3Dom.mergeXpp3Dom((Xpp3Dom) pluginConfiguration, (Xpp3Dom) pluginConfigFromManagement);
            }
        }
    }

    if (pluginConfiguration != null) {
        return new MavenPlugin(pluginConfiguration);
    }
    return null;

}

From source file:org.sonatype.m2e.webby.internal.config.WarConfigurationExtractor.java

License:Open Source License

private Plugin getWarPlugin(MavenProject mvnProject) {
    List<Plugin> plugins = mvnProject.getBuildPlugins();
    for (Plugin plugin : plugins) {
        if (WAR_PLUGIN_GID.equals(plugin.getGroupId()) && WAR_PLUGIN_AID.equals(plugin.getArtifactId())) {
            return plugin;
        }//from  w w  w .j ava  2  s . c  om
    }
    return null;
}

From source file:org.sourcepit.b2.internal.generator.ArtifactCatapultProjectGenerator.java

License:Apache License

private static List<Environment> configureModuleTargetEnvironments(MavenProject project,
        Properties properties) {//from w  w  w .  j a  va 2  s  . c  o m
    final List<Environment> environments = new ArrayList<Environment>();

    for (Plugin plugin : project.getBuildPlugins()) {
        if ("org.eclipse.tycho:target-platform-configuration".equals(plugin.getKey())) {
            Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
            if (configuration != null) {
                Xpp3Dom envs = configuration.getChild("environments");
                if (envs != null) {
                    for (Xpp3Dom envNode : envs.getChildren("environment")) {
                        Environment env = new Environment();

                        Xpp3Dom node = envNode.getChild("os");
                        if (node != null) {
                            env.os = node.getValue();
                        }

                        node = envNode.getChild("ws");
                        if (node != null) {
                            env.ws = node.getValue();
                        }

                        node = envNode.getChild("arch");
                        if (node != null) {
                            env.arch = node.getValue();
                        }

                        environments.add(env);
                    }
                }
            }
        }
    }

    if (environments.isEmpty()) {
        String os = PlatformPropertiesUtils.getOS(properties);
        String ws = PlatformPropertiesUtils.getWS(properties);
        String arch = PlatformPropertiesUtils.getArch(properties);

        Environment env = new Environment();
        env.setOs(os);
        env.setWs(ws);
        env.setArch(arch);

        environments.add(env);
    }

    return environments;
}

From source file:org.sourcepit.tpmp.resolver.tycho.TychoSessionTargetPlatformResolver.java

License:Apache License

private MavenProject setupAggregatedProject(MavenSession session,
        TargetPlatformConfiguration aggregatedConfiguration) {
    PropertiesMap mvnProperties = new LinkedPropertiesMap();
    mvnProperties.load(getClass().getClassLoader(), "META-INF/tpmp/maven.properties");

    String groupId = mvnProperties.get("groupId");
    String artifactId = mvnProperties.get("artifactId");
    String version = mvnProperties.get("version");

    final String tpmpKey = Plugin.constructKey(groupId, artifactId);

    MavenProject origin = session.getCurrentProject();

    Model model = origin.getModel().clone();
    Build build = model.getBuild();/* ww  w  .j a  va  2  s .  co m*/
    if (build.getPluginsAsMap().get(tpmpKey) == null) {
        Plugin tpmp = new Plugin();
        tpmp.setGroupId(groupId);
        tpmp.setArtifactId(artifactId);
        tpmp.setVersion(version);

        build.getPlugins().add(tpmp);
        build.flushPluginMap();
    }

    MavenProject fake = new MavenProject(model);
    fake.setClassRealm(origin.getClassRealm());
    fake.setFile(origin.getFile());

    final Map<String, ArtifactRepository> artifactRepositories = new LinkedHashMap<String, ArtifactRepository>();
    final Map<String, ArtifactRepository> pluginRepositories = new LinkedHashMap<String, ArtifactRepository>();
    for (MavenProject project : session.getProjects()) {
        for (ArtifactRepository repository : project.getRemoteArtifactRepositories()) {
            if (!artifactRepositories.containsKey(repository.getId())) {
                artifactRepositories.put(repository.getId(), repository);
            }
        }
        for (ArtifactRepository repository : project.getPluginArtifactRepositories()) {
            if (!pluginRepositories.containsKey(repository.getId())) {
                pluginRepositories.put(repository.getId(), repository);
            }
        }
    }

    fake.setRemoteArtifactRepositories(new ArrayList<ArtifactRepository>(artifactRepositories.values()));
    fake.setPluginArtifactRepositories(new ArrayList<ArtifactRepository>(pluginRepositories.values()));
    fake.setManagedVersionMap(origin.getManagedVersionMap());

    if (getTychoProject(fake) == null) {
        fake.setPackaging("eclipse-repository");
    }

    fake.getBuildPlugins();

    AbstractTychoProject tychoProject = (AbstractTychoProject) getTychoProject(fake);
    tychoProject.setupProject(session, fake);

    Properties properties = new Properties();
    properties.putAll(fake.getProperties());
    properties.putAll(session.getSystemProperties()); // session wins
    properties.putAll(session.getUserProperties());
    fake.setContextValue(TychoConstants.CTX_MERGED_PROPERTIES, properties);

    fake.setContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION, aggregatedConfiguration);

    ExecutionEnvironmentConfiguration eeConfiguration = new ExecutionEnvironmentConfigurationImpl(logger,
            aggregatedConfiguration.isResolveWithEEConstraints());
    tychoProject.readExecutionEnvironmentConfiguration(fake, eeConfiguration);
    fake.setContextValue(TychoConstants.CTX_EXECUTION_ENVIRONMENT_CONFIGURATION, eeConfiguration);

    final DependencyMetadata dm = new DependencyMetadata();
    for (ReactorProject reactorProject : DefaultReactorProject.adapt(session)) {
        mergeMetadata(dm, reactorProject, true);
        mergeMetadata(dm, reactorProject, false);
    }

    int i = 0;
    for (Object object : dm.getMetadata(true)) {
        InstallableUnitDAO dao = new TychoSourceIUResolver.InstallableUnitDAO(
                object.getClass().getClassLoader());
        dao.setProperty(object, RepositoryLayoutHelper.PROP_CLASSIFIER, "fake_" + i);
        i++;
    }

    for (Object object : dm.getMetadata(false)) {
        InstallableUnitDAO dao = new TychoSourceIUResolver.InstallableUnitDAO(
                object.getClass().getClassLoader());
        dao.setProperty(object, RepositoryLayoutHelper.PROP_CLASSIFIER, "fake_" + i);
        i++;
    }

    Map<String, DependencyMetadata> metadata = new LinkedHashMap<String, DependencyMetadata>();
    metadata.put(null, dm);

    fake.setContextValue("tpmp.aggregatedMetadata", metadata);

    return fake;
}

From source file:org.springframework.cloud.contract.maven.verifier.ManifestCreator.java

License:Apache License

public static Manifest createManifest(MavenProject project) throws ManifestException {
    Manifest manifest = new Manifest();
    Plugin verifierMavenPlugin = findMavenPlugin(project.getBuildPlugins());
    if (verifierMavenPlugin != null) {
        manifest.addConfiguredAttribute(new Manifest.Attribute("Spring-Cloud-Contract-Maven-Plugin-Version",
                verifierMavenPlugin.getVersion()));
    }/* w  w  w .  j  ava  2 s.  co m*/
    if (verifierMavenPlugin != null && !verifierMavenPlugin.getDependencies().isEmpty()) {
        Dependency verifierDependency = findVerifierDependency(verifierMavenPlugin.getDependencies());
        if (verifierDependency != null) {
            String verifierVersion = verifierDependency.getVersion();
            manifest.addConfiguredAttribute(
                    new Manifest.Attribute("Spring-Cloud-Contract-Verifier-Version", verifierVersion));
        }
    }
    return manifest;
}