Skip to content

Commit

Permalink
reficio#241: add new flag skipBndErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
sparsick committed Mar 27, 2021
1 parent f570b14 commit c923db1
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/main/java/org/reficio/p2/P2Mojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ public class P2Mojo extends AbstractMojo implements Contextualizable {
@Parameter(defaultValue = "")
private String additionalArgs;

/**
* Skipe coming from embedded bnd tools should be skipped.
*
* <p>
* This flag controls if the processing should be continued anyway, if the embedded bnd tool throws errors.
* It defaults to false to keep the old behavior (ignoring bnd tool errors).
*/
@Parameter(defaultValue = "true")
private boolean skipBndErrors;

/**
* Dependency injection container - used to get some components programatically
*/
Expand Down Expand Up @@ -520,7 +530,7 @@ private void processEclipseArtifacts() {
}

private ArtifactBundler getArtifactBundler() {
return new AquteBundler(pedantic);
return new AquteBundler(pedantic, skipBndErrors);
}

private void executeP2PublisherPlugin() throws IOException, MojoExecutionException {
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/reficio/p2/bundler/impl/AquteBundler.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ public class AquteBundler implements ArtifactBundler {

protected final BundleUtils bundleUtils;
private final boolean pedantic;
private final boolean skipBndErrors;

public AquteBundler(boolean pedantic) {
public AquteBundler(boolean pedantic, boolean skipBndErrors) {
this.skipBndErrors = skipBndErrors;
this.bundleUtils = new BundleUtils();
this.pedantic = pedantic;
}

AquteBundler(boolean pedantic, BundleUtils bundleUtils) {
AquteBundler(boolean pedantic, boolean skipBndErrors, BundleUtils bundleUtils) {
this.skipBndErrors = skipBndErrors;
this.bundleUtils = bundleUtils;
this.pedantic = pedantic;
}
Expand Down Expand Up @@ -97,7 +100,7 @@ private void prepareOutputFile(File file) {
private void handleVanillaJarWrap(ArtifactBundlerRequest request, ArtifactBundlerInstructions instructions) throws Exception {
try (Analyzer analyzer = AquteHelper.buildAnalyzer(request, instructions, pedantic)) {
populateJar(analyzer, request.getBinaryOutputFile());
if (bundleUtils.reportErrors(analyzer)) {
if (bundleUtils.reportErrors(analyzer) && !skipBndErrors) {
throw new AquteAnalyzerException("Aqute Jar Analyser reports error.");
}
removeSignature(request.getBinaryOutputFile());
Expand Down
21 changes: 21 additions & 0 deletions src/test/integration/issue-241-it/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Copyright (c) 2012 Reficio (TM) - Reestablish your software! All Rights Reserved.
#
# 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.
#

invoker.goals=p2:site
invoker.buildResult=failure
73 changes: 73 additions & 0 deletions src/test/integration/issue-241-it/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012 Reficio (TM) - Reestablish your software! All Rights Reserved.
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001 XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.reficio</groupId>
<artifactId>integration</artifactId>
<version>@project.version@</version>
<relativePath>../integration.xml</relativePath>
</parent>

<artifactId>config</artifactId>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<description>
Test the skip bnd error config option
</description>

<build>
<plugins>
<plugin>
<groupId>org.reficio</groupId>
<artifactId>p2-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<skipBndErrors>false</skipBndErrors>
<artifacts>
<artifact>
<id>org.python:jython-standalone:2.5.3</id>
<override>true</override>
<instructions>
<Eclipse-BundleShape>dir</Eclipse-BundleShape>
<Eclipse-BuddyPolicy>registered</Eclipse-BuddyPolicy>
</instructions>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>

</project>
14 changes: 13 additions & 1 deletion src/test/java/org/reficio/p2/bundler/impl/AquteBundlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,22 @@ public void bndAnalyzerProduceErrorThenExceptionIsExpected() {
theMock.when(() -> AquteHelper.buildAnalyzer(any(ArtifactBundlerRequest.class), any(ArtifactBundlerInstructions.class), anyBoolean()))
.thenReturn(new AnalyzerStub());

AquteBundler bundlerUnderTest = new AquteBundler(true, new BundleUtilsStub());
AquteBundler bundlerUnderTest = new AquteBundler(true, false, new BundleUtilsStub());
ThrowableAssert.ThrowingCallable methodUnderTest = () -> bundlerUnderTest.execute(new ArtifactBundlerRequest(new File(""), new File("target/tmp.jar"), null, null, true), ArtifactBundlerInstructions.builder().build());

assertThatThrownBy(methodUnderTest).isInstanceOf(RuntimeException.class).hasRootCauseInstanceOf(AquteAnalyzerException.class);
}
}

@Test
public void bndAnalyzerProduceErrorThenExceptionIsUnexpected() {
try (MockedStatic<AquteHelper> theMock = mockStatic(AquteHelper.class)) {
theMock.when(() -> AquteHelper.buildAnalyzer(any(ArtifactBundlerRequest.class), any(ArtifactBundlerInstructions.class), anyBoolean()))
.thenReturn(new AnalyzerStub());

AquteBundler bundlerUnderTest = new AquteBundler(true, true, new BundleUtilsStub());

bundlerUnderTest.execute(new ArtifactBundlerRequest(new File(""), new File("target/tmp.jar"), null, null, true), ArtifactBundlerInstructions.builder().build());
}
}
}

0 comments on commit c923db1

Please sign in to comment.