Skip to content

Commit

Permalink
Merge pull request #101 from cobratbq/use-catch-syntax-for-typecheck
Browse files Browse the repository at this point in the history
Fix control flow error and use catch-syntax for instance checking
  • Loading branch information
slawekjaranowski authored May 15, 2020
2 parents 183049d + c61ee0f commit e12cc0b
Show file tree
Hide file tree
Showing 13 changed files with 347 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/it/noKeyFail/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright 2017 Slawomir Jaranowski
# Portions copyright 2020 Danny van Heumen
#
# Licensed 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.buildResult = failure
19 changes: 19 additions & 0 deletions src/it/noKeyFail/keysmap.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright 2020 Slawomir Jaranowski
# Portions copyright 2020 Danny van Heumen
#
# Licensed 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.
#

# PGP key below is not actually available anywhere. It was generated to sign the test artifact and then deleted.
nl.dannyvanheumen:helloworld:1.0 = 0x466583F9480EBE2462C46B309F1A263E15FD0AC9
60 changes: 60 additions & 0 deletions src/it/noKeyFail/pom-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2020 Slawomir Jaranowski
~ Portions copyright 2020 Danny van Heumen
~
~ Licensed 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>test</groupId>
<artifactId>it-test-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/>
</parent>

<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<dependencies>
<dependency>
<groupId>nl.dannyvanheumen</groupId>
<artifactId>helloworld</artifactId>
<version>1.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.simplify4u.plugins</groupId>
<artifactId>pgpverify-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<keysMapLocation>${project.basedir}/keysmap.list</keysMapLocation>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
20 changes: 20 additions & 0 deletions src/it/noKeyFail/postbuild.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2020 Slawomir Jaranowski
* Portions copyright 2020 Danny van Heumen
*
* Licensed 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.
*/
def buildLog = new File( basedir, 'build.log' ).text

assert buildLog.contains('for artifact nl.dannyvanheumen:helloworld:jar:1.0: cannot find public key on keyserver.')
assert buildLog.contains('[INFO] BUILD FAILURE')
18 changes: 18 additions & 0 deletions src/it/noKeyOK/keysmap.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright 2020 Slawomir Jaranowski
# Portions copyright 2020 Danny van Heumen
#
# Licensed 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.
#

nl.dannyvanheumen:helloworld:1.0 = noKey
60 changes: 60 additions & 0 deletions src/it/noKeyOK/pom-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2020 Slawomir Jaranowski
~ Portions copyright 2020 Danny van Heumen
~
~ Licensed 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>test</groupId>
<artifactId>it-test-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/>
</parent>

<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<dependencies>
<dependency>
<groupId>nl.dannyvanheumen</groupId>
<artifactId>helloworld</artifactId>
<version>1.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.simplify4u.plugins</groupId>
<artifactId>pgpverify-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<keysMapLocation>${project.basedir}/keysmap.list</keysMapLocation>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
21 changes: 21 additions & 0 deletions src/it/noKeyOK/postbuild.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2020 Slawomir Jaranowski
* Portions copyright 2020 Danny van Heumen
*
* Licensed 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.
*/
def buildLog = new File( basedir, 'build.log' ).text

assert buildLog.contains('[INFO] nl.dannyvanheumen:helloworld:jar:1.0 PGP key not found on server, consistent with keys map.')
assert buildLog.contains('[INFO] nl.dannyvanheumen:helloworld:pom:1.0 PGP key not found on server, consistent with keys map.')
assert buildLog.contains('[INFO] BUILD SUCCESS')
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-----BEGIN PGP SIGNATURE-----

iQEzBAABCgAdFiEERmWD+UgOviRixGswnxomPhX9CskFAl6+yzwACgkQnxomPhX9
CslwWAf+IsAeoaZC0yo38k1PZ58IAeHQP9iavrfZ4LMCMxFacXmBGZF4SVniBmZ3
o7gaQpp+EYi7LikfBDphX0iNchSn/7jGlDq8eK12JCeoyD7s0rYAYu94itQSPuvE
MZWDD//C0pGNSoK14EZB4TdzE2Ey87+lXqBd2NKNdmSTntL+ijyOPZRMTsLs7o6F
cEwRJQ1T2i26/uC2dpiQ4qelk/bo0eZM/BjJp6DZqjmh4CZDaY/vMTxrM5v7LNVE
4ChAcuu3V8oiNMgWicXFRGHNqyEMrJUM6f7yx325si7ziH3l/CL1iGymVt1DdLzq
3R/QK/dX6YGYEUjJJbxWmx7DTc3HDA==
=DNhd
-----END PGP SIGNATURE-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>nl.dannyvanheumen</groupId>
<artifactId>helloworld</artifactId>
<version>1.0</version>

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

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.5</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<showWarnings>true</showWarnings>
<failOnWarning>true</failOnWarning>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>nl.dannyvanheumen.helloworld.HelloWorld</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-----BEGIN PGP SIGNATURE-----

iQEzBAABCgAdFiEERmWD+UgOviRixGswnxomPhX9CskFAl6+yzwACgkQnxomPhX9
CsnFnAf/Tj2u5jhbYV3TgwWpS63zXPCcHr9ARv9OULozca5JvhMk7alBpsL6Dsyf
y0PMMTQP4mjcIwcf0HWgpIJtHe5WaL9CMLxJCo4nQ90AbF/lT2bs2+ZnA34wdZYE
4p/WaF/MXHRLZKtTf/+t/9OT5FFP7cxyUzqJKyG7lrasZvnEGPftMT0YuJ3vpoSd
tG86DSFXxn6GRvNh9rTi5mFpUw/066qrSTGuSST6jEC+hZh0kY2cUTsv12FDaVbm
XafwznmghUZFC9luBuM+QDNAMbnhZUNZ0u24pyikSoFXA9eO5o4TUgiNHMxPOvee
bn9RRRV7hufI/RVrDdCx6RTjSjO6Qw==
=E9yz
-----END PGP SIGNATURE-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>nl.dannyvanheumen</groupId>
<artifactId>helloworld</artifactId>
<versioning>
<release>1.0</release>
<versions>
<version>1.0</version>
</versions>
<lastUpdated>20200515170252</lastUpdated>
</versioning>
</metadata>
9 changes: 6 additions & 3 deletions src/main/java/org/simplify4u/plugins/PGPVerifyMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@ private boolean verifyPGPSignature(Artifact artifact, Artifact ascArtifact) thro
+ " signature.hashAlgorithm: " + pgpSignature.getHashAlgorithm());

return verifySignatureStatus(pgpSignature.verify(), artifact, publicKey, publicKeyRing);
} catch (IOException | PGPException e) {
if (e.getCause() instanceof PGPKeyNotFound && keysMap.isKeyMissing(artifact)) {
final String logMessage = String.format("%s PGP Key not found on server, consistent with keys map.",
} catch (PGPKeyNotFound e) {
if (keysMap.isKeyMissing(artifact)) {
final String logMessage = String.format("%s PGP key not found on server, consistent with keys map.",
artifact.getId());
if (quiet) {
getLog().debug(logMessage);
Expand All @@ -479,6 +479,9 @@ private boolean verifyPGPSignature(Artifact artifact, Artifact ascArtifact) thro
}
return true;
}
throw new MojoFailureException("Failed to process signature '" + signatureFile + "' for artifact "
+ artifact.getId() + ": cannot find public key on keyserver.", e);
} catch (IOException | PGPException e) {
throw new MojoFailureException("Failed to process signature '" + signatureFile + "' for artifact "
+ artifact.getId(), e);
}
Expand Down

0 comments on commit e12cc0b

Please sign in to comment.