blob: c3af5ba08e471cf3863924c7135fbe77844de08e [file] [log] [blame]
Stuart McCullochf978c532007-12-27 09:16:34 +00001/*
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 */
19package org.apache.felix.bundleplugin;
20
Stuart McCulloch5ae59142008-01-29 06:21:05 +000021
Stuart McCullochf978c532007-12-27 09:16:34 +000022import org.apache.maven.archiver.MavenArchiveConfiguration;
23import org.apache.maven.project.MavenProject;
24import org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter;
25import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup;
26import org.codehaus.plexus.component.configurator.converters.lookup.DefaultConverterLookup;
27import org.codehaus.plexus.component.configurator.expression.DefaultExpressionEvaluator;
28import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
29import org.codehaus.plexus.configuration.PlexusConfiguration;
30import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
31import org.codehaus.plexus.util.xml.Xpp3Dom;
32
Stuart McCulloch5ae59142008-01-29 06:21:05 +000033
Stuart McCullochf978c532007-12-27 09:16:34 +000034/**
35 * Provide access to the archive configuration from the jar plugin
36 *
Richard S. Hall3bc8afd2009-08-12 19:03:19 +000037 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
Stuart McCullochf978c532007-12-27 09:16:34 +000038 */
Stuart McCulloch9366a822008-01-29 07:45:57 +000039public final class JarPluginConfiguration
Stuart McCullochf978c532007-12-27 09:16:34 +000040{
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 McCulloch378e76c2009-01-30 09:51:35 +000052 PlexusConfiguration settings = null;
Stuart McCullochf978c532007-12-27 09:16:34 +000053
Stuart McCulloch378e76c2009-01-30 09:51:35 +000054 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 McCullochf978c532007-12-27 09:16:34 +000072 }
Stuart McCulloch5ae59142008-01-29 06:21:05 +000073 catch ( Exception e )
Stuart McCullochf978c532007-12-27 09:16:34 +000074 {
75 // ignore and return empty configuration...
76 }
77
78 return archiveConfig;
79 }
80
Stuart McCulloch5ae59142008-01-29 06:21:05 +000081
Stuart McCullochf978c532007-12-27 09:16:34 +000082 private static PlexusConfiguration getCorePluginConfiguration( MavenProject project, String pluginName )
83 {
84 return getPluginConfiguration( project, "org.apache.maven.plugins", "maven-" + pluginName + "-plugin" );
85 }
86
Stuart McCulloch5ae59142008-01-29 06:21:05 +000087
Stuart McCullochf978c532007-12-27 09:16:34 +000088 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}