use of org.apache.maven.model.Plugin in project tycho by eclipse.
the class TychoMavenLifecycleParticipantTest method addTychoPlugin.
private void addTychoPlugin(MavenProject project, String artifactId, String version) {
Plugin plugin = new Plugin();
plugin.setGroupId("org.eclipse.tycho");
plugin.setArtifactId(artifactId);
plugin.setVersion(version);
project.getBuild().addPlugin(plugin);
}
use of org.apache.maven.model.Plugin in project tycho by eclipse.
the class OsgiSourceMojo method isRelevantProjectImpl.
protected static boolean isRelevantProjectImpl(MavenProject project, BuildPropertiesParser buildPropertiesParser) {
String packaging = project.getPackaging();
boolean relevant = PackagingType.TYPE_ECLIPSE_PLUGIN.equals(packaging) || PackagingType.TYPE_ECLIPSE_TEST_PLUGIN.equals(packaging);
if (!relevant) {
return false;
}
// 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;
}
boolean hasAdditionalFilesets = getConfigurationElement((Xpp3Dom) execution.getConfiguration(), "additionalFileSets") != null;
if (hasAdditionalFilesets) {
return true;
}
BuildProperties buildProperties = buildPropertiesParser.parse(project.getBasedir());
if (buildProperties.getJarToSourceFolderMap().size() > 0 || buildProperties.getSourceIncludes().size() > 0) {
return true;
}
}
}
return false;
}
use of org.apache.maven.model.Plugin in project tycho by eclipse.
the class OsgiSourceMojoTest method createStubProject.
private MavenProject createStubProject(String packaging, String testResourceFolder, boolean enableSourePlugin, boolean requireSourceRoots) {
MavenProject stubProject = new MavenProject();
stubProject.setPackaging(packaging);
if (enableSourePlugin) {
Build build = new Build();
stubProject.setBuild(build);
Plugin tychoSourcePlugin = new Plugin();
tychoSourcePlugin.setGroupId("org.eclipse.tycho");
tychoSourcePlugin.setArtifactId("tycho-source-plugin");
PluginExecution execution = new PluginExecution();
execution.setGoals(asList("plugin-source"));
if (requireSourceRoots) {
Xpp3Dom config = new Xpp3Dom("configuration");
Xpp3Dom requireSourceRootsDom = new Xpp3Dom("requireSourceRoots");
requireSourceRootsDom.setValue("true");
config.addChild(requireSourceRootsDom);
execution.setConfiguration(config);
}
tychoSourcePlugin.setExecutions(asList(execution));
build.setPlugins(asList(tychoSourcePlugin));
}
stubProject.setFile(new File("src/test/resources/sourceMojo/" + testResourceFolder + "/pom.xml"));
return stubProject;
}
use of org.apache.maven.model.Plugin in project mule by mulesoft.
the class DeployableMavenClassLoaderModelLoader method exportSharedLibrariesResourcesAndPackages.
private void exportSharedLibrariesResourcesAndPackages(File applicationFolder, ClassLoaderModelBuilder classLoaderModelBuilder, Set<BundleDependency> dependencies) {
Model model = loadPomModel(applicationFolder);
Build build = model.getBuild();
if (build != null) {
List<Plugin> plugins = build.getPlugins();
if (plugins != null) {
Optional<Plugin> packagingPluginOptional = plugins.stream().filter(plugin -> plugin.getArtifactId().equals(MULE_MAVEN_PLUGIN_ARTIFACT_ID) && plugin.getGroupId().equals(MULE_MAVEN_PLUGIN_GROUP_ID)).findFirst();
packagingPluginOptional.ifPresent(packagingPlugin -> {
Object configuration = packagingPlugin.getConfiguration();
if (configuration != null) {
Xpp3Dom sharedLibrariesDom = ((Xpp3Dom) configuration).getChild("sharedLibraries");
if (sharedLibrariesDom != null) {
Xpp3Dom[] sharedLibraries = sharedLibrariesDom.getChildren("sharedLibrary");
if (sharedLibraries != null) {
FileJarExplorer fileJarExplorer = new FileJarExplorer();
for (Xpp3Dom sharedLibrary : sharedLibraries) {
String groupId = getSharedLibraryAttribute(applicationFolder, sharedLibrary, "groupId");
String artifactId = getSharedLibraryAttribute(applicationFolder, sharedLibrary, "artifactId");
Optional<BundleDependency> bundleDependencyOptional = dependencies.stream().filter(bundleDependency -> bundleDependency.getDescriptor().getArtifactId().equals(artifactId) && bundleDependency.getDescriptor().getGroupId().equals(groupId)).findFirst();
bundleDependencyOptional.map(bundleDependency -> {
JarInfo jarInfo = fileJarExplorer.explore(bundleDependency.getBundleUri());
classLoaderModelBuilder.exportingPackages(jarInfo.getPackages());
classLoaderModelBuilder.exportingResources(jarInfo.getResources());
return bundleDependency;
}).orElseThrow(() -> new MuleRuntimeException(I18nMessageFactory.createStaticMessage(format("Dependency %s:%s could not be found within the artifact %s. It must be declared within the maven dependencies of the artifact.", groupId, artifactId, applicationFolder.getName()))));
}
}
}
}
});
}
}
}
use of org.apache.maven.model.Plugin in project tycho by eclipse.
the class PluginRealmHelper method execute.
public void execute(MavenSession session, MavenProject project, Runnable runnable, PluginFilter filter) throws MavenExecutionException {
for (Plugin plugin : project.getBuildPlugins()) {
if (plugin.isExtensions()) {
// https://cwiki.apache.org/MAVEN/maven-3x-class-loading.html
continue;
}
try {
lifecyclePluginResolver.resolveMissingPluginVersions(project, session);
PluginDescriptor pluginDescriptor;
try {
pluginDescriptor = compatibilityHelper.getPluginDescriptor(plugin, project, session);
} catch (PluginResolutionException e) {
// if the plugin really does not exist, the Maven build will fail later on anyway -> ignore for now (cf. bug #432957)
logger.debug("PluginResolutionException while looking for components from " + plugin, e);
continue;
}
if (pluginDescriptor != null) {
if (pluginDescriptor.getArtifactMap().isEmpty() && pluginDescriptor.getDependencies().isEmpty()) {
// force plugin descriptor reload to workaround http://jira.codehaus.org/browse/MNG-5212
// this branch won't be executed on 3.0.5+, where MNG-5212 is fixed already
PluginDescriptorCache.Key descriptorCacheKey = compatibilityHelper.createKey(plugin, project, session);
pluginDescriptorCache.put(descriptorCacheKey, null);
pluginDescriptor = compatibilityHelper.getPluginDescriptor(plugin, project, session);
}
if (filter == null || filter.accept(pluginDescriptor)) {
ClassRealm pluginRealm;
MavenProject oldCurrentProject = session.getCurrentProject();
session.setCurrentProject(project);
try {
pluginRealm = buildPluginManager.getPluginRealm(session, pluginDescriptor);
} finally {
session.setCurrentProject(oldCurrentProject);
}
if (pluginRealm != null) {
ClassLoader origTCCL = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(pluginRealm);
runnable.run();
} finally {
Thread.currentThread().setContextClassLoader(origTCCL);
}
}
}
}
} catch (PluginManagerException e) {
throw newMavenExecutionException(e);
} catch (PluginResolutionException e) {
throw newMavenExecutionException(e);
} catch (PluginVersionResolutionException e) {
throw newMavenExecutionException(e);
} catch (PluginDescriptorParsingException e) {
throw newMavenExecutionException(e);
} catch (InvalidPluginDescriptorException e) {
throw newMavenExecutionException(e);
}
}
}
Aggregations