Skip to content

Commit

Permalink
enable spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
jtnord committed Jun 24, 2024
1 parent fdcdeb0 commit 58cf36d
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 137 deletions.
44 changes: 21 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
~ THE SOFTWARE.
-->

<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>

Expand All @@ -38,9 +37,7 @@
<packaging>hpi</packaging>

<name>bouncycastle API Plugin</name>
<description>
This plugin provides an stable API to Bouncy Castle related tasks.
</description>
<description>This plugin provides an stable API to Bouncy Castle related tasks.</description>
<url>https://github.com/jenkinsci/bouncycastle-api-plugin</url>
<licenses>
<license>
Expand All @@ -61,31 +58,18 @@
<scm>
<connection>scm:git:https://github.com/jenkinsci/bouncycastle-api-plugin.git</connection>
<developerConnection>scm:git:[email protected]:jenkinsci/bouncycastle-api-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/bouncycastle-api-plugin</url>
<tag>${scmTag}</tag>
<url>https://github.com/jenkinsci/bouncycastle-api-plugin</url>
</scm>

<properties>
<revision>1.78.1</revision>
<changelist>999999-SNAPSHOT</changelist>
<jenkins.version>2.361.4</jenkins.version>
<useBeta>true</useBeta>
<spotless.check.skip>false</spotless.check.skip>
</properties>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

<dependencies>
<!--
The BouncyCastle jars are exposed as regular dependencies to other plugins who depend on this plugin on the build classpath.
Expand All @@ -111,13 +95,27 @@
<version>${revision}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.26.0</version>
<scope>test</scope>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.26.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

<build>
<pluginManagement>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jenkins.bouncycastle.api;

import java.security.Security;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
Expand Down Expand Up @@ -42,5 +41,4 @@ static void register(boolean prioritize) {
Security.addProvider(new BouncyCastleProvider());
}
}

}
38 changes: 24 additions & 14 deletions src/main/java/jenkins/bouncycastle/api/BouncyCastlePlugin.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package jenkins.bouncycastle.api;

import hudson.Main;
import hudson.Plugin;
import hudson.PluginWrapper;
import hudson.remoting.Which;
import java.io.File;
import java.io.IOException;
import java.security.Provider;
import java.security.Security;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import hudson.Main;
import hudson.Plugin;
import hudson.PluginWrapper;
import hudson.remoting.Which;
import java.io.IOException;
import jenkins.model.Jenkins;

@SuppressWarnings("deprecation") // there is no other way to achieve this at the correct lifecycle point
@Restricted(NoExternalUse.class) // just for Jenkins access not part of the API
Expand All @@ -27,9 +27,11 @@ public class BouncyCastlePlugin extends Plugin {
Provider p = Security.getProvider("BCFIPS");
isActive = (p == null);

LOG.log(Level.CONFIG,
isActive ? "BouncyCastle Providers from BouncyCastle API plugin will be active" :
"Detected the presence of the BouncyCastle FIPS provider, the regular BouncyCastle JARs will not be available.");
LOG.log(
Level.CONFIG,
isActive

Check warning on line 32 in src/main/java/jenkins/bouncycastle/api/BouncyCastlePlugin.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 32 is only partially covered, one branch is missing
? "BouncyCastle Providers from BouncyCastle API plugin will be active"
: "Detected the presence of the BouncyCastle FIPS provider, the regular BouncyCastle JARs will not be available.");

Check warning on line 34 in src/main/java/jenkins/bouncycastle/api/BouncyCastlePlugin.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 34 is not covered by tests
}

@Override
Expand All @@ -50,9 +52,15 @@ public void start() throws Exception {

if (optionalLibs == null || optionalLibs.length == 0) {
if (Main.isUnitTest) {
LOG.log(Level.INFO, "{0} not found; for non RealJenkinsRule this is fine and can be ignored.", optionalLibDir);
LOG.log(
Level.INFO,
"{0} not found; for non RealJenkinsRule this is fine and can be ignored.",
optionalLibDir);
} else {
LOG.log(Level.WARNING, "No optional-libs not found at {0}, BouncyCastle APIs will be unavailable causing strange runtime issues.", optionalLibDir);
LOG.log(

Check warning on line 60 in src/main/java/jenkins/bouncycastle/api/BouncyCastlePlugin.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 60 is not covered by tests
Level.WARNING,
"No optional-libs not found at {0}, BouncyCastle APIs will be unavailable causing strange runtime issues.",
optionalLibDir);
// fail fast, most likely a packaging issue
throw new IllegalStateException("BouncyCastle libs are missing from WEB-INF/optional-libs");
}
Expand All @@ -66,16 +74,18 @@ public static boolean isActive() {
return isActive;
}


private final File getOptionalLibDirectory() throws IOException {
PluginWrapper pw = getWrapper();
File explodedPluginsDir = pw.parent.getWorkDir();
if (explodedPluginsDir == null) {
// not overridden use default of ${JENKINS_HOME}/plugins
explodedPluginsDir = new File(Jenkins.get().getRootDir(), "plugins");
LOG.log(Level.FINE, "plugindir not specified, falling back to $'{'JENKINS_HOME/plugins'}' as {0}", explodedPluginsDir);
LOG.log(
Level.FINE,
"plugindir not specified, falling back to $'{'JENKINS_HOME/plugins'}' as {0}",
explodedPluginsDir);
}
File f = new File(explodedPluginsDir, pw.getShortName() + "/WEB-INF/optional-lib/");
File f = new File(explodedPluginsDir, pw.getShortName() + "/WEB-INF/optional-lib/");
if (!f.isDirectory()) {
File here = Which.jarFile(BouncyCastlePlugin.class);
File alt = new File(here.getParentFile().getParentFile(), "optional-lib");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,17 @@

package jenkins.bouncycastle.api;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.remoting.Channel;
import hudson.remoting.ChannelProperty;
import hudson.remoting.Future;
import hudson.slaves.SlaveComputer;
import java.io.IOException;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import edu.umd.cs.findbugs.annotations.NonNull;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import hudson.remoting.Channel;
import hudson.remoting.Future;
import jenkins.security.MasterToSlaveCallable;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

/**
* Allows registering Bouncy Castle on a remote agent. Just call {@link #on(Channel)} or {@link #on(SlaveComputer)}.
Expand All @@ -54,8 +51,8 @@ public class InstallBouncyCastleJCAProvider extends MasterToSlaveCallable<Boolea
/**
* The property that holds the future for registration.
*/
private static final ChannelProperty<Future> BOUNCYCASTLE_REGISTERED
= new ChannelProperty<>(Future.class, "Bouncy Castle Registered");
private static final ChannelProperty<Future> BOUNCYCASTLE_REGISTERED =
new ChannelProperty<>(Future.class, "Bouncy Castle Registered");

private final boolean prioritize;

Expand All @@ -81,7 +78,7 @@ public Boolean call() throws Exception {

/**
* Registers bouncy castle on the slave JVM
*
*
* @param c the slave
* @throws IOException if there is a problem registering bouncycastle
* @throws InterruptedException if interrupted while trying to register
Expand All @@ -96,7 +93,7 @@ public static void on(@NonNull SlaveComputer c) throws IOException, InterruptedE
throw new IOException("Remote agent is off-line");
}
}
/**
/**
* Registers bouncy castle on the slave JVM
*
* @param channel the {@link Channel}
Expand Down
Loading

0 comments on commit 58cf36d

Please sign in to comment.