Skip to content

Commit

Permalink
Format code with Palantir Java Format (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Apr 1, 2023
1 parent f2ec04e commit 367c1e5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 36 deletions.
6 changes: 1 addition & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,8 @@
<!-- define a language-specific format -->
<java>
<!-- no need to specify files, inferred automatically -->
<!-- apply a specific flavor of google-java-format -->
<googleJavaFormat>
<version>1.15.0</version>
<style>AOSP</style>
</googleJavaFormat>
<endWithNewline />
<palantirJavaFormat />
<removeUnusedImports />
</java>
<pom>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ public String getDefaultDate() {
public Date getDefaultDateObject() {
Date buildtime = new Date(),
now = new Date(),
defaultScheduleTime =
new ScheduleBuildGlobalConfiguration().getDefaultScheduleTimeObject();
defaultScheduleTime = new ScheduleBuildGlobalConfiguration().getDefaultScheduleTimeObject();
DateFormat dateFormat = dateFormat();
try {
now = dateFormat.parse(dateFormat.format(now));
Expand Down Expand Up @@ -178,18 +177,16 @@ public HttpResponse doNext(StaplerRequest req, @AncestorInPath Item item)
}

public boolean isJobParameterized() {
ParametersDefinitionProperty paramDefinitions =
target.getProperty(ParametersDefinitionProperty.class);
ParametersDefinitionProperty paramDefinitions = target.getProperty(ParametersDefinitionProperty.class);
return paramDefinitions != null
&& paramDefinitions.getParameterDefinitions() != null
&& paramDefinitions.getParameterDefinitions().size() > 0;
}

private DateFormat dateFormat() {
Locale locale =
Stapler.getCurrentRequest() != null
? Stapler.getCurrentRequest().getLocale()
: Locale.getDefault();
Locale locale = Stapler.getCurrentRequest() != null
? Stapler.getCurrentRequest().getLocale()
: Locale.getDefault();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
df.setTimeZone(new ScheduleBuildGlobalConfiguration().getTimeZoneObject());
return df;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public boolean shownByDefault() {
}
}

@Extension public static final Descriptor<ListViewColumn> DESCRIPTOR = new DescriptorImpl();
@Extension
public static final Descriptor<ListViewColumn> DESCRIPTOR = new DescriptorImpl();

@Override
public Descriptor<ListViewColumn> getDescriptor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ public TimeZone getTimeZoneObject() {
}

private DateFormat getTimeFormat() {
Locale locale =
Stapler.getCurrentRequest() != null
? Stapler.getCurrentRequest().getLocale()
: Locale.getDefault();
Locale locale = Stapler.getCurrentRequest() != null
? Stapler.getCurrentRequest().getLocale()
: Locale.getDefault();
return DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
}

Expand All @@ -64,8 +63,7 @@ public Date getDefaultScheduleTimeObject() {

@RequirePOST
public FormValidation doCheckDefaultScheduleTime(@QueryParameter String value) {
Jenkins.get()
.checkPermission(Jenkins.ADMINISTER); // Admin permission required for global config
Jenkins.get().checkPermission(Jenkins.ADMINISTER); // Admin permission required for global config
try {
getTimeFormat().parse(value);
} catch (ParseException ex) {
Expand All @@ -76,8 +74,7 @@ public FormValidation doCheckDefaultScheduleTime(@QueryParameter String value) {

@RequirePOST
public FormValidation doCheckTimeZone(@QueryParameter String value) {
Jenkins.get()
.checkPermission(Jenkins.ADMINISTER); // Admin permission required for global config
Jenkins.get().checkPermission(Jenkins.ADMINISTER); // Admin permission required for global config
TimeZone zone = TimeZone.getTimeZone(value);
if (StringUtils.equals(zone.getID(), value)) {
return FormValidation.ok();
Expand All @@ -93,8 +90,7 @@ public boolean configure(StaplerRequest req, JSONObject json) throws FormExcepti
this.timeZone = null;
if (json.containsKey("defaultScheduleTime") && json.containsKey("timeZone")) {
try {
this.defaultScheduleTime =
getTimeFormat().parse(json.getString("defaultScheduleTime"));
this.defaultScheduleTime = getTimeFormat().parse(json.getString("defaultScheduleTime"));
this.timeZone = json.getString("timeZone");
save();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

public class ScheduleBuildActionTest {

@Rule public JenkinsRule j = new JenkinsRule();
@Rule
public JenkinsRule j = new JenkinsRule();

private ScheduleBuildAction scheduleBuildAction;
private FreeStyleProject project;

Expand All @@ -43,9 +45,7 @@ public void testGetIconFileName() throws Exception {

@Test
public void testGetIconClassName() throws Exception {
assertThat(
scheduleBuildAction.getIconClassName(),
is("symbol-calendar-outline plugin-ionicons-api"));
assertThat(scheduleBuildAction.getIconClassName(), is("symbol-calendar-outline plugin-ionicons-api"));
project.disable();
assertThat(scheduleBuildAction.getIconClassName(), is(nullValue()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@

public class ScheduleBuildGlobalConfigurationTest {

@Rule public final JenkinsRule j = new JenkinsRule();
@Rule
public final JenkinsRule j = new JenkinsRule();

private ScheduleBuildGlobalConfiguration globalConfig = null;

public ScheduleBuildGlobalConfigurationTest() {}

@Before
public void setUp() {
globalConfig =
GlobalConfiguration.all().getInstance(ScheduleBuildGlobalConfiguration.class);
globalConfig = GlobalConfiguration.all().getInstance(ScheduleBuildGlobalConfiguration.class);
}

@Test
Expand Down Expand Up @@ -62,11 +63,9 @@ public void configRoundTripTestWithChanges() throws Exception {

@Test
public void testBadScheduleTime() throws Exception {
assertThrows(
java.text.ParseException.class,
() -> {
globalConfig.setDefaultScheduleTime("34:56:78");
});
assertThrows(java.text.ParseException.class, () -> {
globalConfig.setDefaultScheduleTime("34:56:78");
});
}

@Test
Expand Down

0 comments on commit 367c1e5

Please sign in to comment.