Richard S. Hall | 01a56ce | 2007-05-20 22:31:11 +0000 | [diff] [blame] | 1 | package org.apache.felix.bundleplugin; |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 2 | |
Stuart McCulloch | 6a70547 | 2008-01-29 06:22:10 +0000 | [diff] [blame] | 3 | |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 4 | /* |
| 5 | * Licensed to the Apache Software Foundation (ASF) under one |
| 6 | * or more contributor license agreements. See the NOTICE file |
| 7 | * distributed with this work for additional information |
| 8 | * regarding copyright ownership. The ASF licenses this file |
| 9 | * to you under the Apache License, Version 2.0 (the |
| 10 | * "License"); you may not use this file except in compliance |
| 11 | * with the License. You may obtain a copy of the License at |
| 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
| 15 | * Unless required by applicable law or agreed to in writing, |
| 16 | * software distributed under the License is distributed on an |
| 17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 18 | * KIND, either express or implied. See the License for the |
| 19 | * specific language governing permissions and limitations |
| 20 | * under the License. |
| 21 | */ |
| 22 | |
| 23 | import java.io.File; |
Stuart McCulloch | 9e63195 | 2011-11-09 00:45:12 +0000 | [diff] [blame] | 24 | import java.io.FileOutputStream; |
| 25 | import java.util.Arrays; |
Stuart McCulloch | c7a5a03 | 2011-10-26 18:50:20 +0000 | [diff] [blame] | 26 | import java.util.HashMap; |
| 27 | import java.util.LinkedHashSet; |
Richard S. Hall | bec8dc4 | 2007-05-18 14:33:55 +0000 | [diff] [blame] | 28 | import java.util.Map; |
Stuart McCulloch | 6dd4dd2 | 2009-09-02 22:45:33 +0000 | [diff] [blame] | 29 | import java.util.Properties; |
Stuart McCulloch | c7a5a03 | 2011-10-26 18:50:20 +0000 | [diff] [blame] | 30 | import java.util.Set; |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 31 | import java.util.TreeMap; |
Stuart McCulloch | c7a5a03 | 2011-10-26 18:50:20 +0000 | [diff] [blame] | 32 | import java.util.jar.Manifest; |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 33 | |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 34 | import org.apache.maven.model.Organization; |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 35 | import org.apache.maven.plugin.testing.stubs.MavenProjectStub; |
| 36 | import org.apache.maven.project.MavenProject; |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 37 | import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder; |
| 38 | import org.apache.maven.shared.dependency.graph.DependencyNode; |
Stuart McCulloch | c7a5a03 | 2011-10-26 18:50:20 +0000 | [diff] [blame] | 39 | import org.osgi.framework.Constants; |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 40 | |
Stuart McCulloch | 42151ee | 2012-07-16 13:43:38 +0000 | [diff] [blame] | 41 | import aQute.bnd.osgi.Analyzer; |
| 42 | import aQute.bnd.osgi.Builder; |
| 43 | import aQute.bnd.osgi.Jar; |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 44 | |
Stuart McCulloch | 6a70547 | 2008-01-29 06:22:10 +0000 | [diff] [blame] | 45 | |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 46 | /** |
| 47 | * Test for {@link BundlePlugin}. |
Carsten Ziegeler | 846bd7a | 2015-05-15 08:53:36 +0000 | [diff] [blame] | 48 | * |
Richard S. Hall | f3b6b48 | 2009-08-12 19:07:21 +0000 | [diff] [blame] | 49 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 50 | */ |
Stuart McCulloch | 6a70547 | 2008-01-29 06:22:10 +0000 | [diff] [blame] | 51 | public class BundlePluginTest extends AbstractBundlePluginTest |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 52 | { |
| 53 | |
| 54 | private BundlePlugin plugin; |
| 55 | |
Stuart McCulloch | 6a70547 | 2008-01-29 06:22:10 +0000 | [diff] [blame] | 56 | |
Carsten Ziegeler | 846bd7a | 2015-05-15 08:53:36 +0000 | [diff] [blame] | 57 | @Override |
Stuart McCulloch | 6a70547 | 2008-01-29 06:22:10 +0000 | [diff] [blame] | 58 | protected void setUp() throws Exception |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 59 | { |
| 60 | super.setUp(); |
| 61 | plugin = new BundlePlugin(); |
Stuart McCulloch | d6e642f | 2008-03-03 02:19:21 +0000 | [diff] [blame] | 62 | plugin.setBuildDirectory( "." ); |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 63 | plugin.setOutputDirectory(new File(getBasedir(), "target" + File.separatorChar + "scratch")); |
| 64 | setVariableValueToObject(plugin, "m_dependencyGraphBuilder", lookup(DependencyGraphBuilder.class.getName(), "default")); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Stuart McCulloch | 6a70547 | 2008-01-29 06:22:10 +0000 | [diff] [blame] | 67 | |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 68 | public void testConvertVersionToOsgi() |
| 69 | { |
| 70 | String osgiVersion; |
| 71 | |
| 72 | osgiVersion = plugin.convertVersionToOsgi( "2.1.0-SNAPSHOT" ); |
| 73 | assertEquals( "2.1.0.SNAPSHOT", osgiVersion ); |
| 74 | |
| 75 | osgiVersion = plugin.convertVersionToOsgi( "2.1-SNAPSHOT" ); |
| 76 | assertEquals( "2.1.0.SNAPSHOT", osgiVersion ); |
| 77 | |
| 78 | osgiVersion = plugin.convertVersionToOsgi( "2-SNAPSHOT" ); |
| 79 | assertEquals( "2.0.0.SNAPSHOT", osgiVersion ); |
| 80 | |
| 81 | osgiVersion = plugin.convertVersionToOsgi( "2" ); |
Stuart McCulloch | de88f0c | 2007-10-04 13:12:06 +0000 | [diff] [blame] | 82 | assertEquals( "2.0.0", osgiVersion ); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 83 | |
| 84 | osgiVersion = plugin.convertVersionToOsgi( "2.1" ); |
Stuart McCulloch | de88f0c | 2007-10-04 13:12:06 +0000 | [diff] [blame] | 85 | assertEquals( "2.1.0", osgiVersion ); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 86 | |
| 87 | osgiVersion = plugin.convertVersionToOsgi( "2.1.3" ); |
| 88 | assertEquals( "2.1.3", osgiVersion ); |
| 89 | |
| 90 | osgiVersion = plugin.convertVersionToOsgi( "2.1.3.4" ); |
| 91 | assertEquals( "2.1.3.4", osgiVersion ); |
| 92 | |
| 93 | osgiVersion = plugin.convertVersionToOsgi( "4aug2000r7-dev" ); |
Guillaume Nodet | 6da2254 | 2010-03-05 14:12:41 +0000 | [diff] [blame] | 94 | assertEquals( "0.0.0.4aug2000r7-dev", osgiVersion ); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 95 | |
| 96 | osgiVersion = plugin.convertVersionToOsgi( "1.1-alpha-2" ); |
Guillaume Nodet | 6da2254 | 2010-03-05 14:12:41 +0000 | [diff] [blame] | 97 | assertEquals( "1.1.0.alpha-2", osgiVersion ); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 98 | |
| 99 | osgiVersion = plugin.convertVersionToOsgi( "1.0-alpha-16-20070122.203121-13" ); |
Guillaume Nodet | 6da2254 | 2010-03-05 14:12:41 +0000 | [diff] [blame] | 100 | assertEquals( "1.0.0.alpha-16-20070122_203121-13", osgiVersion ); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 101 | |
| 102 | osgiVersion = plugin.convertVersionToOsgi( "1.0-20070119.021432-1" ); |
Guillaume Nodet | 6da2254 | 2010-03-05 14:12:41 +0000 | [diff] [blame] | 103 | assertEquals( "1.0.0.20070119_021432-1", osgiVersion ); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 104 | |
| 105 | osgiVersion = plugin.convertVersionToOsgi( "1-20070119.021432-1" ); |
Guillaume Nodet | 6da2254 | 2010-03-05 14:12:41 +0000 | [diff] [blame] | 106 | assertEquals( "1.0.0.20070119_021432-1", osgiVersion ); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 107 | |
| 108 | osgiVersion = plugin.convertVersionToOsgi( "1.4.1-20070217.082013-7" ); |
Guillaume Nodet | 6da2254 | 2010-03-05 14:12:41 +0000 | [diff] [blame] | 109 | assertEquals( "1.4.1.20070217_082013-7", osgiVersion ); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Stuart McCulloch | 6a70547 | 2008-01-29 06:22:10 +0000 | [diff] [blame] | 112 | |
| 113 | public void testReadExportedModules() throws Exception |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 114 | { |
| 115 | File osgiBundleFile = getTestBundle(); |
| 116 | |
| 117 | assertTrue( osgiBundleFile.exists() ); |
| 118 | |
Stuart McCulloch | c7a5a03 | 2011-10-26 18:50:20 +0000 | [diff] [blame] | 119 | MavenProject project = getMavenProjectStub(); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 120 | |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 121 | // PackageVersionAnalyzer analyzer = new PackageVersionAnalyzer(); |
Richard S. Hall | ea93d68 | 2010-11-04 13:54:27 +0000 | [diff] [blame] | 122 | Builder analyzer = new Builder(); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 123 | Jar jar = new Jar( "name", osgiBundleFile ); |
| 124 | analyzer.setJar( jar ); |
Stuart McCulloch | 6a70547 | 2008-01-29 06:22:10 +0000 | [diff] [blame] | 125 | analyzer.setClasspath( new Jar[] |
| 126 | { jar } ); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 127 | |
| 128 | analyzer.setProperty( Analyzer.EXPORT_PACKAGE, "*" ); |
Stuart McCulloch | fa00e22 | 2012-07-26 17:52:00 +0000 | [diff] [blame] | 129 | analyzer.getJar().setManifest( analyzer.calcManifest() ); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 130 | |
| 131 | assertEquals( 3, analyzer.getExports().size() ); |
Stuart McCulloch | d8a04c5 | 2008-08-06 16:05:23 +0000 | [diff] [blame] | 132 | |
| 133 | analyzer.close(); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Stuart McCulloch | 6a70547 | 2008-01-29 06:22:10 +0000 | [diff] [blame] | 136 | |
| 137 | public void testTransformDirectives() throws Exception |
Richard S. Hall | bec8dc4 | 2007-05-18 14:33:55 +0000 | [diff] [blame] | 138 | { |
| 139 | Map instructions = new TreeMap(); |
| 140 | |
Stuart McCulloch | 6a70547 | 2008-01-29 06:22:10 +0000 | [diff] [blame] | 141 | instructions.put( "a", "1" ); |
| 142 | instructions.put( "-a", "2" ); |
| 143 | instructions.put( "_a", "3" ); |
| 144 | instructions.put( "A", "3" ); |
| 145 | instructions.put( "_A", "1" ); |
| 146 | instructions.put( "_b", "4" ); |
| 147 | instructions.put( "b", "6" ); |
| 148 | instructions.put( "_B", "6" ); |
| 149 | instructions.put( "-B", "5" ); |
| 150 | instructions.put( "B", "4" ); |
Richard S. Hall | bec8dc4 | 2007-05-18 14:33:55 +0000 | [diff] [blame] | 151 | |
Stuart McCulloch | 6a70547 | 2008-01-29 06:22:10 +0000 | [diff] [blame] | 152 | instructions.put( "z", null ); |
| 153 | instructions.put( "_z", null ); |
Richard S. Hall | bec8dc4 | 2007-05-18 14:33:55 +0000 | [diff] [blame] | 154 | |
Stuart McCulloch | 9366a82 | 2008-01-29 07:45:57 +0000 | [diff] [blame] | 155 | Map transformedInstructions = BundlePlugin.transformDirectives( instructions ); |
Richard S. Hall | bec8dc4 | 2007-05-18 14:33:55 +0000 | [diff] [blame] | 156 | |
Stuart McCulloch | 6a70547 | 2008-01-29 06:22:10 +0000 | [diff] [blame] | 157 | assertEquals( "1", transformedInstructions.get( "a" ) ); |
| 158 | assertEquals( "3", transformedInstructions.get( "-a" ) ); |
| 159 | assertEquals( null, transformedInstructions.get( "_a" ) ); |
| 160 | assertEquals( "3", transformedInstructions.get( "A" ) ); |
| 161 | assertEquals( "1", transformedInstructions.get( "-A" ) ); |
| 162 | assertEquals( null, transformedInstructions.get( "_A" ) ); |
| 163 | assertEquals( null, transformedInstructions.get( "_b" ) ); |
| 164 | assertEquals( "4", transformedInstructions.get( "-b" ) ); |
| 165 | assertEquals( "6", transformedInstructions.get( "b" ) ); |
| 166 | assertEquals( null, transformedInstructions.get( "_B" ) ); |
| 167 | assertEquals( "6", transformedInstructions.get( "-B" ) ); |
| 168 | assertEquals( "4", transformedInstructions.get( "B" ) ); |
Richard S. Hall | bec8dc4 | 2007-05-18 14:33:55 +0000 | [diff] [blame] | 169 | |
Stuart McCulloch | 6a70547 | 2008-01-29 06:22:10 +0000 | [diff] [blame] | 170 | assertEquals( "", transformedInstructions.get( "z" ) ); |
| 171 | assertEquals( "", transformedInstructions.get( "-z" ) ); |
Richard S. Hall | bec8dc4 | 2007-05-18 14:33:55 +0000 | [diff] [blame] | 172 | } |
Stuart McCulloch | d6e642f | 2008-03-03 02:19:21 +0000 | [diff] [blame] | 173 | |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 174 | |
Stuart McCulloch | 6dd4dd2 | 2009-09-02 22:45:33 +0000 | [diff] [blame] | 175 | public void testDefaultPropertiesIncludeOrganization() |
| 176 | { |
| 177 | final Organization organization = new Organization(); |
| 178 | organization.setName( "Example Organization" ); |
| 179 | organization.setUrl( "http://example.org" ); |
| 180 | |
| 181 | // MavenProjectStub.setOrganization(Organization) doesn't do anything, so we have to make it work this way |
| 182 | MavenProject project = new MavenProjectStub() |
| 183 | { |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 184 | @Override |
| 185 | public Organization getOrganization() |
Stuart McCulloch | 6dd4dd2 | 2009-09-02 22:45:33 +0000 | [diff] [blame] | 186 | { |
| 187 | return organization; |
| 188 | } |
| 189 | }; |
| 190 | project.setGroupId( "group" ); |
Stuart McCulloch | c7a5a03 | 2011-10-26 18:50:20 +0000 | [diff] [blame] | 191 | project.setArtifactId( "project" ); |
| 192 | project.setVersion( "1.2.3.4" ); |
Stuart McCulloch | 6dd4dd2 | 2009-09-02 22:45:33 +0000 | [diff] [blame] | 193 | |
| 194 | Properties properties = plugin.getDefaultProperties( project ); |
| 195 | assertEquals( organization.getName(), properties.getProperty( "project.organization.name" ) ); |
| 196 | assertEquals( organization.getName(), properties.getProperty( "pom.organization.name" ) ); |
| 197 | assertEquals( organization.getUrl(), properties.getProperty( "project.organization.url" ) ); |
| 198 | assertEquals( organization.getUrl(), properties.getProperty( "pom.organization.url" ) ); |
| 199 | } |
Stuart McCulloch | d6e642f | 2008-03-03 02:19:21 +0000 | [diff] [blame] | 200 | |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 201 | |
Stuart McCulloch | d6e642f | 2008-03-03 02:19:21 +0000 | [diff] [blame] | 202 | public void testVersion() throws Exception |
| 203 | { |
| 204 | String cleanupVersion = Builder.cleanupVersion( "0.0.0.4aug2000r7-dev" ); |
| 205 | assertEquals( "0.0.0.4aug2000r7-dev", cleanupVersion ); |
| 206 | } |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 207 | |
| 208 | |
Stuart McCulloch | e71aa49 | 2011-06-24 18:21:16 +0000 | [diff] [blame] | 209 | public void testPackageInfoDetection() throws Exception |
| 210 | { |
Stuart McCulloch | c7a5a03 | 2011-10-26 18:50:20 +0000 | [diff] [blame] | 211 | MavenProject project = getMavenProjectStub(); |
Stuart McCulloch | e71aa49 | 2011-06-24 18:21:16 +0000 | [diff] [blame] | 212 | project.addCompileSourceRoot( getBasedir() + "/src/test/java" ); |
Guillaume Nodet | 09157a9 | 2010-03-10 17:40:45 +0000 | [diff] [blame] | 213 | |
Guillaume Nodet | 09194e6 | 2014-06-16 07:07:12 +0000 | [diff] [blame] | 214 | String resourcePaths = plugin.getMavenResourcePaths( project, false ); |
Stuart McCulloch | e71aa49 | 2011-06-24 18:21:16 +0000 | [diff] [blame] | 215 | |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 216 | assertEquals( "org/apache/felix/bundleplugin/packageinfo=" |
| 217 | + "src/test/java/org/apache/felix/bundleplugin/packageinfo", resourcePaths ); |
Stuart McCulloch | e71aa49 | 2011-06-24 18:21:16 +0000 | [diff] [blame] | 218 | } |
Stuart McCulloch | c7a5a03 | 2011-10-26 18:50:20 +0000 | [diff] [blame] | 219 | |
| 220 | |
Stuart McCulloch | e8851a5 | 2011-10-26 21:14:28 +0000 | [diff] [blame] | 221 | public void testEmbedDependencyPositiveClauses() throws Exception |
Stuart McCulloch | c7a5a03 | 2011-10-26 18:50:20 +0000 | [diff] [blame] | 222 | { |
| 223 | ArtifactStubFactory artifactFactory = new ArtifactStubFactory( plugin.getOutputDirectory(), true ); |
| 224 | |
| 225 | Set artifacts = new LinkedHashSet(); |
| 226 | |
| 227 | artifacts.addAll( artifactFactory.getClassifiedArtifacts() ); |
| 228 | artifacts.addAll( artifactFactory.getScopedArtifacts() ); |
| 229 | artifacts.addAll( artifactFactory.getTypedArtifacts() ); |
| 230 | |
| 231 | MavenProject project = getMavenProjectStub(); |
| 232 | project.setDependencyArtifacts( artifacts ); |
| 233 | |
| 234 | Map instructions = new HashMap(); |
Stuart McCulloch | 999fc31 | 2011-10-26 19:36:52 +0000 | [diff] [blame] | 235 | instructions.put( DependencyEmbedder.EMBED_DEPENDENCY, "*;classifier=;type=jar;scope=compile," |
| 236 | + "*;classifier=;type=jar;scope=runtime" ); |
Stuart McCulloch | c7a5a03 | 2011-10-26 18:50:20 +0000 | [diff] [blame] | 237 | Properties props = new Properties(); |
| 238 | |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 239 | DependencyNode dependencyGraph = plugin.buildDependencyGraph(project); |
| 240 | Builder builder = plugin.buildOSGiBundle( project, dependencyGraph, instructions, props, plugin.getClasspath( project, dependencyGraph ) ); |
Stuart McCulloch | c7a5a03 | 2011-10-26 18:50:20 +0000 | [diff] [blame] | 241 | Manifest manifest = builder.getJar().getManifest(); |
| 242 | |
| 243 | String bcp = manifest.getMainAttributes().getValue( Constants.BUNDLE_CLASSPATH ); |
Stuart McCulloch | e78eff9 | 2011-10-26 21:54:03 +0000 | [diff] [blame] | 244 | assertEquals( ".," + "compile-1.0.jar,b-1.0.jar,runtime-1.0.jar", bcp ); |
Stuart McCulloch | c7a5a03 | 2011-10-26 18:50:20 +0000 | [diff] [blame] | 245 | |
| 246 | String eas = manifest.getMainAttributes().getValue( "Embedded-Artifacts" ); |
Stuart McCulloch | 999fc31 | 2011-10-26 19:36:52 +0000 | [diff] [blame] | 247 | assertEquals( "compile-1.0.jar;g=\"g\";a=\"compile\";v=\"1.0\"," + "b-1.0.jar;g=\"g\";a=\"b\";v=\"1.0\"," |
| 248 | + "runtime-1.0.jar;g=\"g\";a=\"runtime\";v=\"1.0\"", eas ); |
| 249 | } |
| 250 | |
| 251 | |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 252 | public void testEmbedDependencyNegativeClauses() throws Exception |
| 253 | { |
| 254 | ArtifactStubFactory artifactFactory = new ArtifactStubFactory( plugin.getOutputDirectory(), true ); |
| 255 | |
| 256 | Set artifacts = new LinkedHashSet(); |
| 257 | |
| 258 | artifacts.addAll( artifactFactory.getClassifiedArtifacts() ); |
| 259 | artifacts.addAll( artifactFactory.getScopedArtifacts() ); |
| 260 | artifacts.addAll( artifactFactory.getTypedArtifacts() ); |
| 261 | |
| 262 | MavenProject project = getMavenProjectStub(); |
| 263 | project.setDependencyArtifacts( artifacts ); |
| 264 | |
| 265 | Map instructions = new HashMap(); |
| 266 | instructions.put( DependencyEmbedder.EMBED_DEPENDENCY, "!type=jar, !artifactId=c" ); |
| 267 | Properties props = new Properties(); |
| 268 | |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 269 | DependencyNode dependencyGraph = plugin.buildDependencyGraph(project); |
| 270 | Builder builder = plugin.buildOSGiBundle( project, dependencyGraph, instructions, props, plugin.getClasspath( project, dependencyGraph ) ); |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 271 | Manifest manifest = builder.getJar().getManifest(); |
| 272 | |
| 273 | String bcp = manifest.getMainAttributes().getValue( Constants.BUNDLE_CLASSPATH ); |
Stuart McCulloch | d75b291 | 2012-02-11 14:51:06 +0000 | [diff] [blame] | 274 | assertEquals( ".," + "a-1.0.war," + "d-1.0.zip," + "e-1.0.rar", bcp ); |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 275 | |
| 276 | String eas = manifest.getMainAttributes().getValue( "Embedded-Artifacts" ); |
Stuart McCulloch | d75b291 | 2012-02-11 14:51:06 +0000 | [diff] [blame] | 277 | assertEquals( "a-1.0.war;g=\"g\";a=\"a\";v=\"1.0\"," + "d-1.0.zip;g=\"g\";a=\"d\";v=\"1.0\"," |
| 278 | + "e-1.0.rar;g=\"g\";a=\"e\";v=\"1.0\"", eas ); |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | |
Stuart McCulloch | e8851a5 | 2011-10-26 21:14:28 +0000 | [diff] [blame] | 282 | public void testEmbedDependencyDuplicateKeys() throws Exception |
| 283 | { |
| 284 | ArtifactStubFactory artifactFactory = new ArtifactStubFactory( plugin.getOutputDirectory(), true ); |
| 285 | |
| 286 | Set artifacts = new LinkedHashSet(); |
| 287 | |
| 288 | artifacts.addAll( artifactFactory.getClassifiedArtifacts() ); |
| 289 | artifacts.addAll( artifactFactory.getScopedArtifacts() ); |
| 290 | artifacts.addAll( artifactFactory.getTypedArtifacts() ); |
| 291 | |
| 292 | MavenProject project = getMavenProjectStub(); |
| 293 | project.setDependencyArtifacts( artifacts ); |
| 294 | |
| 295 | Map instructions = new HashMap(); |
| 296 | instructions.put( DependencyEmbedder.EMBED_DEPENDENCY, "c;type=jar,c;type=sources" ); |
| 297 | Properties props = new Properties(); |
| 298 | |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 299 | DependencyNode dependencyGraph = plugin.buildDependencyGraph(project); |
| 300 | Builder builder = plugin.buildOSGiBundle( project, dependencyGraph, instructions, props, plugin.getClasspath( project, dependencyGraph ) ); |
Stuart McCulloch | e8851a5 | 2011-10-26 21:14:28 +0000 | [diff] [blame] | 301 | Manifest manifest = builder.getJar().getManifest(); |
| 302 | |
| 303 | String bcp = manifest.getMainAttributes().getValue( Constants.BUNDLE_CLASSPATH ); |
Stuart McCulloch | e78eff9 | 2011-10-26 21:54:03 +0000 | [diff] [blame] | 304 | assertEquals( ".," + "c-1.0-three.jar," + "c-1.0.sources", bcp ); |
Stuart McCulloch | e8851a5 | 2011-10-26 21:14:28 +0000 | [diff] [blame] | 305 | |
| 306 | String eas = manifest.getMainAttributes().getValue( "Embedded-Artifacts" ); |
| 307 | assertEquals( "c-1.0-three.jar;g=\"g\";a=\"c\";v=\"1.0\";c=\"three\"," |
| 308 | + "c-1.0.sources;g=\"g\";a=\"c\";v=\"1.0\"", eas ); |
| 309 | } |
| 310 | |
| 311 | |
Stuart McCulloch | 0e76233 | 2011-10-26 22:11:22 +0000 | [diff] [blame] | 312 | public void testEmbedDependencyMissingPositiveKey() throws Exception |
Stuart McCulloch | e78eff9 | 2011-10-26 21:54:03 +0000 | [diff] [blame] | 313 | { |
| 314 | ArtifactStubFactory artifactFactory = new ArtifactStubFactory( plugin.getOutputDirectory(), true ); |
| 315 | |
| 316 | Set artifacts = new LinkedHashSet(); |
| 317 | |
| 318 | artifacts.addAll( artifactFactory.getClassifiedArtifacts() ); |
| 319 | artifacts.addAll( artifactFactory.getScopedArtifacts() ); |
| 320 | artifacts.addAll( artifactFactory.getTypedArtifacts() ); |
| 321 | |
| 322 | MavenProject project = getMavenProjectStub(); |
| 323 | project.setDependencyArtifacts( artifacts ); |
| 324 | |
| 325 | Map instructions = new HashMap(); |
| 326 | instructions.put( DependencyEmbedder.EMBED_DEPENDENCY, "artifactId=a|b" ); |
| 327 | Properties props = new Properties(); |
| 328 | |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 329 | DependencyNode dependencyGraph = plugin.buildDependencyGraph(project); |
| 330 | Builder builder = plugin.buildOSGiBundle( project, dependencyGraph, instructions, props, plugin.getClasspath( project, dependencyGraph ) ); |
Stuart McCulloch | e78eff9 | 2011-10-26 21:54:03 +0000 | [diff] [blame] | 331 | Manifest manifest = builder.getJar().getManifest(); |
| 332 | |
| 333 | String bcp = manifest.getMainAttributes().getValue( Constants.BUNDLE_CLASSPATH ); |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 334 | assertEquals( ".," + "a-1.0-one.jar," + "b-1.0-two.jar," + "a-1.0.war," + "b-1.0.jar", bcp ); |
Stuart McCulloch | e78eff9 | 2011-10-26 21:54:03 +0000 | [diff] [blame] | 335 | |
| 336 | String eas = manifest.getMainAttributes().getValue( "Embedded-Artifacts" ); |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 337 | assertEquals( "a-1.0-one.jar;g=\"g\";a=\"a\";v=\"1.0\";c=\"one\"," |
| 338 | + "b-1.0-two.jar;g=\"g\";a=\"b\";v=\"1.0\";c=\"two\"," + "a-1.0.war;g=\"g\";a=\"a\";v=\"1.0\"," |
| 339 | + "b-1.0.jar;g=\"g\";a=\"b\";v=\"1.0\"", eas ); |
Stuart McCulloch | e78eff9 | 2011-10-26 21:54:03 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | |
Stuart McCulloch | 0e76233 | 2011-10-26 22:11:22 +0000 | [diff] [blame] | 343 | public void testEmbedDependencyMissingNegativeKey() throws Exception |
Stuart McCulloch | 999fc31 | 2011-10-26 19:36:52 +0000 | [diff] [blame] | 344 | { |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 345 | ArtifactStubFactory artifactFactory = new ArtifactStubFactory( plugin.getOutputDirectory(), true ); |
| 346 | |
| 347 | Set artifacts = new LinkedHashSet(); |
| 348 | |
| 349 | artifacts.addAll( artifactFactory.getClassifiedArtifacts() ); |
| 350 | artifacts.addAll( artifactFactory.getScopedArtifacts() ); |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 351 | artifacts.addAll(artifactFactory.getTypedArtifacts()); |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 352 | |
| 353 | MavenProject project = getMavenProjectStub(); |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 354 | project.setDependencyArtifacts(artifacts); |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 355 | Properties props = new Properties(); |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 356 | DependencyNode dependencyGraph = plugin.buildDependencyGraph(project); |
| 357 | Jar[] classpath = plugin.getClasspath(project, dependencyGraph); |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 358 | |
| 359 | Map instructions1 = new HashMap(); |
| 360 | instructions1.put( DependencyEmbedder.EMBED_DEPENDENCY, "!scope=compile" ); |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 361 | Builder builder1 = plugin.buildOSGiBundle( project, dependencyGraph, instructions1, props, classpath ); |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 362 | Manifest manifest1 = builder1.getJar().getManifest(); |
| 363 | |
| 364 | Map instructions2 = new HashMap(); |
| 365 | instructions2.put( DependencyEmbedder.EMBED_DEPENDENCY, "scope=!compile" ); |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 366 | Builder builder2 = plugin.buildOSGiBundle( project, dependencyGraph, instructions2, props, classpath ); |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 367 | Manifest manifest2 = builder2.getJar().getManifest(); |
| 368 | |
| 369 | String bcp1 = manifest1.getMainAttributes().getValue( Constants.BUNDLE_CLASSPATH ); |
Stuart McCulloch | d75b291 | 2012-02-11 14:51:06 +0000 | [diff] [blame] | 370 | assertEquals( ".," + "provided-1.0.jar," + "test-1.0.jar," + "runtime-1.0.jar," + "system-1.0.jar", bcp1 ); |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 371 | |
| 372 | String eas1 = manifest1.getMainAttributes().getValue( "Embedded-Artifacts" ); |
Stuart McCulloch | d75b291 | 2012-02-11 14:51:06 +0000 | [diff] [blame] | 373 | assertEquals( "provided-1.0.jar;g=\"g\";a=\"provided\";v=\"1.0\"," |
| 374 | + "test-1.0.jar;g=\"g\";a=\"test\";v=\"1.0\"," + "runtime-1.0.jar;g=\"g\";a=\"runtime\";v=\"1.0\"," |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 375 | + "system-1.0.jar;g=\"g\";a=\"system\";v=\"1.0\"", eas1 ); |
| 376 | |
| 377 | String bcp2 = manifest2.getMainAttributes().getValue( Constants.BUNDLE_CLASSPATH ); |
| 378 | assertEquals( bcp1, bcp2 ); |
| 379 | |
| 380 | String eas2 = manifest2.getMainAttributes().getValue( "Embedded-Artifacts" ); |
| 381 | assertEquals( eas1, eas2 ); |
Stuart McCulloch | c7a5a03 | 2011-10-26 18:50:20 +0000 | [diff] [blame] | 382 | } |
Stuart McCulloch | 9e63195 | 2011-11-09 00:45:12 +0000 | [diff] [blame] | 383 | |
| 384 | |
| 385 | public void testPropertySanitizing() throws Exception |
| 386 | { |
| 387 | MavenProject project = getMavenProjectStub(); |
| 388 | |
| 389 | Properties props = new Properties(); |
| 390 | |
| 391 | props.put( new File( "A" ), new File( "B" ) ); |
| 392 | props.put( new int[4], new HashMap( 2 ) ); |
| 393 | props.put( Arrays.asList( 1, "two", 3.0 ), new float[5] ); |
| 394 | |
| 395 | props.put( "A", new File( "B" ) ); |
| 396 | props.put( "4", new HashMap( 2 ) ); |
| 397 | props.put( "1, two, 3.0", new char[5] ); |
| 398 | |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 399 | DependencyNode dependencyGraph = plugin.buildDependencyGraph(project); |
| 400 | Builder builder = plugin.getOSGiBuilder( project, new HashMap(), props, plugin.getClasspath( project, dependencyGraph ) ); |
Stuart McCulloch | 9e63195 | 2011-11-09 00:45:12 +0000 | [diff] [blame] | 401 | |
| 402 | File file = new File( getBasedir(), "target" + File.separatorChar + "test.props" ); |
| 403 | builder.getProperties().store( new FileOutputStream( file ), "TEST" ); |
| 404 | } |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 405 | } |