stataru8 commented on code in PR #317: URL: https://github.com/apache/camel-karaf/pull/317#discussion_r1625712160
########## tooling/camel-karaf-feature-maven-plugin/src/test/java/org/apache/camel/karaf/feature/maven/EnsureWrapBundleVersionMojoTest.java: ########## @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.karaf.feature.maven; + + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class EnsureWrapBundleVersionMojoTest { + + private final EnsureWrapBundleVersionMojo ensureVersionMojo = new EnsureWrapBundleVersionMojo(); + + @Test + void modifyLocationTest() throws Exception { + // add bundle version at the end + String location = "wrap:mvn:org.apache.olingo/odata-server-core/5.0.0"; + String expected = "wrap:mvn:org.apache.olingo/odata-server-core/5.0.0$Bundle-Version=5.0.0"; + assertEquals(expected, ensureVersionMojo.processLocation(location)); + + location = "wrap:mvn:org.apache.olingo/odata-server-core/5.0.0$overwrite=merge"; + expected = "wrap:mvn:org.apache.olingo/odata-server-core/5.0.0$overwrite=merge&Bundle-Version=5.0.0"; + assertEquals(expected, ensureVersionMojo.processLocation(location)); + + location = "wrap:mvn:org.apache.olingo/odata-server-core/5.0.0$overwrite=merge&Export-Package=org.apache.olingo.*;version=5.0.0"; + expected = "wrap:mvn:org.apache.olingo/odata-server-core/5.0.0$overwrite=merge&Bundle-Version=5.0.0&Export-Package=org.apache.olingo.*;version=5.0.0"; + assertEquals(expected, ensureVersionMojo.processLocation(location)); + + // original version won't work in the karaf container + location = "wrap:mvn:com.google.apis/google-api-services-storage/v1-rev20240209-2.0.0"; + expected = "wrap:mvn:com.google.apis/google-api-services-storage/v1-rev20240209-2.0.0$Bundle-Version=0.0.0.v1-rev20240209-2_0_0"; + assertEquals(expected, ensureVersionMojo.processLocation(location)); + + // bundle version header is present but it won't work in the karaf container + location = "mvn:commons-io/commons-io/2.15.1$Bundle-Version=2.15.0"; + expected = "mvn:commons-io/commons-io/2.15.1$Bundle-Version=2.15.0"; + ; + assertEquals(expected, ensureVersionMojo.processLocation(location)); + + // bundle version header is present but it points to the wrong value + location = "mvn:commons-io/commons-io/2.15.1$Bundle-Version=2.15.0"; + expected = "mvn:commons-io/commons-io/2.15.1$Bundle-Version=2.15.0"; + ; + assertEquals(expected, ensureVersionMojo.processLocation(location)); + } + + @Test + void getVersionStartIndexTest() { + assertEquals(51, + ensureVersionMojo.getVersionStartIndex("wrap:mvn:org.apache.httpcomponents.core5/httpcore5/5.2.1")); + assertEquals(51, ensureVersionMojo.getVersionStartIndex( + "wrap:mvn:org.eclipse.californium/element-connector/3.11.0$overwrite=merge&Import-Package=net.i2p.crypto.eddsa;resolution:=optional")); + } + + @Test + void getVersionEndIndexTest() { + assertEquals(55, + ensureVersionMojo.getVersionEndIndex("wrap:mvn:org.apache.httpcomponents.core5/httpcore5/5.2.1")); + assertEquals(56, ensureVersionMojo.getVersionEndIndex( + "wrap:mvn:org.eclipse.californium/element-connector/3.11.0$overwrite=merge&Import-Package=net.i2p.crypto.eddsa;resolution:=optional")); + } + + @Test + void getVersionTest() { + assertEquals("${google-oauth-client-version}", ensureVersionMojo.getVersion( + "wrap:mvn:com.google.oauth-client/google-oauth-client-jetty/${google-oauth-client-version}$overwrite=merge&Import-Package=com.sun.net.httpserver;resolution:=optional,*")); Review Comment: Yes, but I believe it's necessary to obtain the placeholder declaration even if it's not resolved, to avoid processing the bundle location. https://github.com/apache/camel-karaf/blob/4bf0ed9588df89d3774bcb872ad61348fe75a7b5/tooling/camel-karaf-feature-maven-plugin/src/main/java/org/apache/camel/karaf/feature/maven/EnsureWrapBundleVersionMojo.java#L259 https://github.com/apache/camel-karaf/blob/4bf0ed9588df89d3774bcb872ad61348fe75a7b5/tooling/camel-karaf-feature-maven-plugin/src/main/java/org/apache/camel/karaf/feature/maven/EnsureWrapBundleVersionMojo.java#L260 then https://github.com/apache/camel-karaf/blob/4bf0ed9588df89d3774bcb872ad61348fe75a7b5/tooling/camel-karaf-feature-maven-plugin/src/main/java/org/apache/camel/karaf/feature/maven/EnsureWrapBundleVersionMojo.java#L159 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org