Stuart McCulloch | f978c53 | 2007-12-27 09:16:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.apache.felix.bundleplugin; |
| 20 | |
Stuart McCulloch | 5ae5914 | 2008-01-29 06:21:05 +0000 | [diff] [blame] | 21 | |
Stuart McCulloch | f978c53 | 2007-12-27 09:16:34 +0000 | [diff] [blame] | 22 | import org.apache.maven.archiver.MavenArchiveConfiguration; |
| 23 | import org.apache.maven.project.MavenProject; |
| 24 | import org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter; |
| 25 | import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; |
| 26 | import org.codehaus.plexus.component.configurator.converters.lookup.DefaultConverterLookup; |
| 27 | import org.codehaus.plexus.component.configurator.expression.DefaultExpressionEvaluator; |
| 28 | import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; |
| 29 | import org.codehaus.plexus.configuration.PlexusConfiguration; |
| 30 | import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; |
| 31 | import org.codehaus.plexus.util.xml.Xpp3Dom; |
| 32 | |
Stuart McCulloch | 5ae5914 | 2008-01-29 06:21:05 +0000 | [diff] [blame] | 33 | |
Stuart McCulloch | f978c53 | 2007-12-27 09:16:34 +0000 | [diff] [blame] | 34 | /** |
| 35 | * Provide access to the archive configuration from the jar plugin |
| 36 | * |
Richard S. Hall | 3bc8afd | 2009-08-12 19:03:19 +0000 | [diff] [blame] | 37 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
Stuart McCulloch | f978c53 | 2007-12-27 09:16:34 +0000 | [diff] [blame] | 38 | */ |
Stuart McCulloch | 9366a82 | 2008-01-29 07:45:57 +0000 | [diff] [blame] | 39 | public final class JarPluginConfiguration |
Stuart McCulloch | f978c53 | 2007-12-27 09:16:34 +0000 | [diff] [blame] | 40 | { |
| 41 | public static MavenArchiveConfiguration getArchiveConfiguration( MavenProject project ) |
| 42 | { |
| 43 | MavenArchiveConfiguration archiveConfig = new MavenArchiveConfiguration(); |
| 44 | |
| 45 | try |
| 46 | { |
| 47 | ObjectWithFieldsConverter converter = new ObjectWithFieldsConverter(); |
| 48 | ClassLoader loader = JarPluginConfiguration.class.getClassLoader(); |
| 49 | ExpressionEvaluator evaluator = new DefaultExpressionEvaluator(); |
| 50 | ConverterLookup converters = new DefaultConverterLookup(); |
| 51 | |
Stuart McCulloch | 378e76c | 2009-01-30 09:51:35 +0000 | [diff] [blame] | 52 | PlexusConfiguration settings = null; |
Stuart McCulloch | f978c53 | 2007-12-27 09:16:34 +0000 | [diff] [blame] | 53 | |
Stuart McCulloch | 378e76c | 2009-01-30 09:51:35 +0000 | [diff] [blame] | 54 | try |
| 55 | { |
| 56 | // first look for bundle specific archive settings |
| 57 | settings = getPluginConfiguration( project, "org.apache.felix", "maven-bundle-plugin" ); |
| 58 | settings = settings.getChild( "archive" ); |
| 59 | } |
| 60 | catch ( Exception e ) |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | // if it's empty fall back to the jar archive settings |
| 65 | if ( null == settings || settings.getChildCount() == 0 ) |
| 66 | { |
| 67 | settings = getCorePluginConfiguration( project, "jar" ); |
| 68 | settings = settings.getChild( "archive" ); |
| 69 | } |
| 70 | |
| 71 | converter.processConfiguration( converters, archiveConfig, loader, settings, evaluator, null ); |
Stuart McCulloch | f978c53 | 2007-12-27 09:16:34 +0000 | [diff] [blame] | 72 | } |
Stuart McCulloch | 5ae5914 | 2008-01-29 06:21:05 +0000 | [diff] [blame] | 73 | catch ( Exception e ) |
Stuart McCulloch | f978c53 | 2007-12-27 09:16:34 +0000 | [diff] [blame] | 74 | { |
| 75 | // ignore and return empty configuration... |
| 76 | } |
| 77 | |
| 78 | return archiveConfig; |
| 79 | } |
| 80 | |
Stuart McCulloch | 5ae5914 | 2008-01-29 06:21:05 +0000 | [diff] [blame] | 81 | |
Stuart McCulloch | f978c53 | 2007-12-27 09:16:34 +0000 | [diff] [blame] | 82 | private static PlexusConfiguration getCorePluginConfiguration( MavenProject project, String pluginName ) |
| 83 | { |
| 84 | return getPluginConfiguration( project, "org.apache.maven.plugins", "maven-" + pluginName + "-plugin" ); |
| 85 | } |
| 86 | |
Stuart McCulloch | 5ae5914 | 2008-01-29 06:21:05 +0000 | [diff] [blame] | 87 | |
Stuart McCulloch | f978c53 | 2007-12-27 09:16:34 +0000 | [diff] [blame] | 88 | private static PlexusConfiguration getPluginConfiguration( MavenProject project, String groupId, String artifactId ) |
| 89 | { |
| 90 | Xpp3Dom pluginConfig = project.getGoalConfiguration( groupId, artifactId, null, null ); |
| 91 | |
| 92 | return new XmlPlexusConfiguration( pluginConfig ); |
| 93 | } |
| 94 | } |