Skip to content

Commit

Permalink
Re-enable Checkstyle (#10214)
Browse files Browse the repository at this point in the history
  • Loading branch information
krisstern authored Jan 27, 2025
2 parents 72e3665 + f6c5f6f commit deb663a
Show file tree
Hide file tree
Showing 24 changed files with 61 additions and 20 deletions.
3 changes: 3 additions & 0 deletions cli/src/main/java/hudson/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,17 +343,20 @@ public void onOpen(Session session, EndpointConfig config) {}

class Authenticator extends ClientEndpointConfig.Configurator {
HandshakeResponse hr;

@Override
public void beforeRequest(Map<String, List<String>> headers) {
if (factory.authorization != null) {
headers.put("Authorization", List.of(factory.authorization));
}
}

@Override
public void afterResponse(HandshakeResponse hr) {
this.hr = hr;
}
}

var authenticator = new Authenticator();

ClientManager client = ClientManager.createClient(JdkClientContainer.class.getName()); // ~ ContainerProvider.getWebSocketContainer()
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/ClassicPluginStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ protected ClassLoader createClassLoader(List<File> paths, ClassLoader parent) th
/**
* @deprecated since 2.459 use {@link #createClassLoader(String, List, ClassLoader, Attributes)}
*/
@Deprecated(since="2.459")
@Deprecated(since = "2.459")
protected ClassLoader createClassLoader(List<File> paths, ClassLoader parent, Attributes atts) throws IOException {
// generate a legacy id so at least we can track to something
return createClassLoader("unidentified-" + UUID.randomUUID(), paths, parent, atts);
Expand Down
16 changes: 15 additions & 1 deletion core/src/main/java/hudson/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,21 @@ public Proc launch(ProcStarter ps) throws IOException {
final String workDir = psPwd == null ? null : psPwd.getRemote();

try {
RemoteLaunchCallable remote = new RemoteLaunchCallable(ps.commands, ps.masks, ps.envs, in, ps.reverseStdin, out, ps.reverseStdout, err, ps.reverseStderr, ps.quiet, workDir, listener, ps.stdoutListener, envVarsFilterRuleWrapper);
RemoteLaunchCallable remote = new RemoteLaunchCallable(
ps.commands,
ps.masks,
ps.envs,
in,
ps.reverseStdin,
out,
ps.reverseStdout,
err,
ps.reverseStderr,
ps.quiet,
workDir,
listener,
ps.stdoutListener,
envVarsFilterRuleWrapper);
// reset the rules to prevent build step without rules configuration to re-use those
envVarsFilterRuleWrapper = null;
return new ProcImpl(getChannel().call(remote));
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/ComputerSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public static List<NodeMonitor> get_monitors() {
}

/**
* @deprecated Use {@link #getComputers()} instead.
* @return All {@link Computer} instances managed by this set.
* @deprecated Use {@link #getComputers()} instead.
*/
@Deprecated(since = "2.480")
public Computer[] get_all() {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/hudson/model/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,12 @@ public interface BuildNumberAssigner extends ExtensionPoint {
* Implementation of {@link Job#assignBuildNumber}.
*/
int assignBuildNumber(Job<?, ?> job, SaveNextBuildNumber saveNextBuildNumber) throws IOException;

/**
* Provides an externally accessible alias for {@link Job#saveNextBuildNumber}, which is {@code protected}.
* ({@link #getNextBuildNumber} and {@link #fastUpdateNextBuildNumber} are already accessible.)
*/

interface SaveNextBuildNumber {
void call() throws IOException;
}
Expand Down
4 changes: 1 addition & 3 deletions core/src/main/java/hudson/model/UserPropertyDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,9 @@ public boolean isEnabled() {
* Method proposed to prevent plugins to rely on too recent core version
* while keeping the possibility to use the categories.
*
* @deprecated This should only be used when the core requirement is below the version this method was added
*
* @return String name corresponding to the symbol of {@link #getUserPropertyCategory()}
*
* @since 2.468
* @deprecated This should only be used when the core requirement is below the version this method was added
*/
@Deprecated
protected @CheckForNull String getUserPropertyCategoryAsString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.model.userproperty;

import edu.umd.cs.findbugs.annotations.NonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.model.userproperty;

import edu.umd.cs.findbugs.annotations.NonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.model.userproperty;

import edu.umd.cs.findbugs.annotations.NonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.model.userproperty;

import edu.umd.cs.findbugs.annotations.NonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.model.userproperty;

import edu.umd.cs.findbugs.annotations.NonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.model.userproperty;

package hudson.model.userproperty;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,14 @@ protected Object unmarshalField(final UnmarshallingContext context, final Object
return context.convertAnother(result, type, converter);
}

private void writeValueToImplicitCollection(HierarchicalStreamReader reader, UnmarshallingContext context, Object value, Map<String, Collection<Object>> implicitCollections, Map<String, Class<?>> implicitCollectionElementTypes, Object result, String itemFieldName) {
private void writeValueToImplicitCollection(
HierarchicalStreamReader reader,
UnmarshallingContext context,
Object value,
Map<String, Collection<Object>> implicitCollections,
Map<String, Class<?>> implicitCollectionElementTypes,
Object result,
String itemFieldName) {
String fieldName = mapper.getFieldNameForItemTypeAndName(context.getRequiredType(), value.getClass(), itemFieldName);
if (fieldName != null) {
Collection collection = implicitCollections.get(fieldName);
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/jenkins/agents/IOfflineCause.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package jenkins.agents;

import edu.umd.cs.findbugs.annotations.NonNull;
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/jenkins/model/IComputer.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ default String getIconClassName() {
* Returns the number of {@link IExecutor}s that are doing some work right now.
*/
int countBusy();

/**
* Returns the current size of the executor pool for this computer.
*/
Expand All @@ -194,6 +195,7 @@ default String getIconClassName() {
* @return true if the computer is online.
*/
boolean isOnline();

/**
* @return the number of {@link IExecutor}s that are idle right now.
*/
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/model/Nodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public List<Node> getNodes() {
* @throws IOException if the new list of nodes could not be persisted.
*/
public void setNodes(final @NonNull Collection<? extends Node> nodes) throws IOException {
Map<String,Node> toRemove = new HashMap<>();
Map<String, Node> toRemove = new HashMap<>();
Queue.withLock(() -> {
toRemove.putAll(Nodes.this.nodes);
for (var node : nodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void validate(URL url) throws IOException {
LOGGER.log(Level.FINE, () -> "Allowing URL: " + url);
}
}

@SuppressFBWarnings(
value = "DMI_COLLECTION_OF_URLS",
justification = "All URLs point to local files, so no DNS lookup.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private static String s(String fullString, boolean simplify) {
* name, and expected value for each of the resource files used by
* the test.
*
* @param simplifyExpectedValue if true, then the expected value
* @param simplify if true, then the expected value
* is simplified by replacing ' ' with '-', by replacing '/' with
* '-', and by removing '(' and ')'.
* @return arguments for ParameterizedTest, resource file name,
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ THE SOFTWARE.
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<!-- Version specified in parent POM -->
</plugin>
</plugins>
</build>

Expand Down
2 changes: 1 addition & 1 deletion test/src/test/java/hudson/model/UserPropertyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class UserPropertyTest {
public JenkinsRule j = new JenkinsRule();

public User configRoundtrip(User u) throws Exception {
submit(j.createWebClient().goTo(u.getUrl()+"/account/").getFormByName("config"));
submit(j.createWebClient().goTo(u.getUrl() + "/account/").getFormByName("config"));
return u;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private static void validatePasswordLengthForFIPSStep(JenkinsRule j) throws Exce
User u1 = securityRealm.createAccount("test", "aValidFipsPass");

WebClient wc = j.createWebClient();
wc.login("test","aValidFipsPass");
wc.login("test", "aValidFipsPass");

HtmlPage configurePage = wc.goTo(u1.getUrl() + "/security/");
HtmlPasswordInput password1 = configurePage.getElementByName("user.password");
Expand Down Expand Up @@ -192,7 +192,7 @@ private static void validatePasswordMismatchForFIPSStep(JenkinsRule j) throws Ex


WebClient wc = j.createWebClient();
wc.login("test","aValidFipsPass");
wc.login("test", "aValidFipsPass");

HtmlPage configurePage = wc.goTo(u1.getUrl() + "/security/");
HtmlPasswordInput password1 = configurePage.getElementByName("user.password");
Expand All @@ -219,7 +219,7 @@ private static void validatePasswordSuccessForFIPSStep(JenkinsRule j) throws Exc
User u1 = securityRealm.createAccount("test", "aValidFipsPass");

WebClient wc = j.createWebClient();
wc.login("test","aValidFipsPass");
wc.login("test", "aValidFipsPass");

HtmlPage configurePage = wc.goTo(u1.getUrl() + "/security/");
HtmlPasswordInput password1 = configurePage.getElementByName("user.password");
Expand Down
2 changes: 1 addition & 1 deletion test/src/test/java/hudson/util/FormFieldValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static class ValidatingDescribable extends Builder {
private Secret populatedPassword = Secret.fromString("secret!");
private String textarea;
private Secret emptySecretTextarea;
private Secret populatedSecretTextarea = Secret.fromString("sensitive!");;
private Secret populatedSecretTextarea = Secret.fromString("sensitive!");

@DataBoundConstructor
public ValidatingDescribable() {
Expand Down
2 changes: 1 addition & 1 deletion test/src/test/java/jenkins/model/NodesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ protected void onDeleted(@NonNull Node node) {
private static class DumbSlaveNameAndRemoteFSMatcher extends TypeSafeMatcher<DumbSlavePair> {
private final DumbSlavePair expected;

public DumbSlaveNameAndRemoteFSMatcher(DumbSlavePair expected) {
DumbSlaveNameAndRemoteFSMatcher(DumbSlavePair expected) {
this.expected = expected;
}

Expand Down
11 changes: 7 additions & 4 deletions test/src/test/java/jenkins/security/Security3430Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ private static void _run(JenkinsRule j, String agentName, String expectedRemotin
// outdated remoting.jar will fail, but up to date one passes
if (requestingJarFromAgent) {
final IOException ex = assertThrows(IOException.class, () -> channel.preloadJar(j.jenkins.getPluginManager().uberClassLoader, Stapler.class));
assertThat(ex.getMessage(), containsString("No hudson.remoting.JarURLValidator has been set for this channel, so all #fetchJar calls are rejected. This is likely a bug in Jenkins. As a workaround, try updating the agent.jar file."));
assertThat(ex.getMessage(), containsString(
"No hudson.remoting.JarURLValidator has been set for this channel, so all #fetchJar calls are rejected. This is likely a bug in Jenkins. As a workaround, try updating the agent.jar file."));
} else {
assertTrue(channel.preloadJar(j.jenkins.getPluginManager().uberClassLoader, Stapler.class));
assertThat(logRecords.stream().map(LogRecord::getMessage).toList(), is(empty()));
Expand Down Expand Up @@ -227,7 +228,8 @@ private static void _run(JenkinsRule j, String agentName, String expectedRemotin
assertThat(logRecords, not(hasItem(logMessageContainsString("Allowing URL"))));
assertThat(logRecords, hasItem(logMessageContainsString("Rejecting URL: ")));
} else {
assertThat(itex.getCause().getMessage(), containsString("No hudson.remoting.JarURLValidator has been set for this channel, so all #fetchJar calls are rejected. This is likely a bug in Jenkins. As a workaround, try updating the agent.jar file."));
assertThat(itex.getCause().getMessage(), containsString(
"No hudson.remoting.JarURLValidator has been set for this channel, so all #fetchJar calls are rejected. This is likely a bug in Jenkins. As a workaround, try updating the agent.jar file."));
}
}

Expand Down Expand Up @@ -264,10 +266,11 @@ private static class Exploit extends MasterToSlaveCallable<Void, Exception> {
private final URL controllerFilePath;
private final String expectedContent;

public Exploit(URL controllerFilePath, String expectedContent) {
Exploit(URL controllerFilePath, String expectedContent) {
this.controllerFilePath = controllerFilePath;
this.expectedContent = expectedContent;
}

@Override
public Void call() throws Exception {
final ClassLoader ccl = Thread.currentThread().getContextClassLoader();
Expand All @@ -290,7 +293,7 @@ private static Matcher<LogRecord> logMessageContainsString(String needle) {
private static final class LogMessageContainsString extends TypeSafeMatcher<LogRecord> {
private final Matcher<String> stringMatcher;

public LogMessageContainsString(Matcher<String> stringMatcher) {
LogMessageContainsString(Matcher<String> stringMatcher) {
this.stringMatcher = stringMatcher;
}

Expand Down

0 comments on commit deb663a

Please sign in to comment.