Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
-Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
1 change: 1 addition & 0 deletions .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
-DaltSnapshotDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-snapshot-local
-Djspecify.enabled=true
-P spring
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.cloud.task.batch.autoconfigure;

import org.jspecify.annotations.Nullable;

import org.springframework.batch.infrastructure.item.file.transform.Range;
import org.springframework.core.convert.converter.Converter;

Expand All @@ -31,7 +33,7 @@
public class RangeConverter implements Converter<String, Range> {

@Override
public Range convert(String source) {
public @Nullable Range convert(String source) {
if (source == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.Step;
import org.springframework.batch.core.step.builder.SimpleStepBuilder;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.core.step.builder.ChunkOrientedStepBuilder;
import org.springframework.batch.infrastructure.item.ItemProcessor;
import org.springframework.batch.infrastructure.item.ItemReader;
import org.springframework.batch.infrastructure.item.ItemWriter;
Expand Down Expand Up @@ -78,16 +77,16 @@ private void validateProperties(SingleStepJobProperties properties) {
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "spring.batch.job", name = "job-name")
public Job job(ItemReader<Map<String, Object>> itemReader, ItemWriter<Map<String, Object>> itemWriter) {

SimpleStepBuilder<Map<String, Object>, Map<String, Object>> stepBuilder = new StepBuilder(
this.properties.getStepName(), this.jobRepository)
.<Map<String, Object>, Map<String, Object>>chunk(this.properties.getChunkSize(), this.transactionManager)
Assert.state(properties.getStepName() != null, "A step name is required");
Assert.state(properties.getChunkSize() != null, "A chunkSize is required");
var chunkOrientedStepBuilder = new ChunkOrientedStepBuilder(properties.getStepName(), this.jobRepository,
this.properties.getChunkSize())
.transactionManager(this.transactionManager)
.reader(itemReader);
chunkOrientedStepBuilder.processor(this.itemProcessor);
Step step = chunkOrientedStepBuilder.writer(itemWriter).build();

stepBuilder.processor(this.itemProcessor);

Step step = stepBuilder.writer(itemWriter).build();

Assert.state(this.properties.getJobName() != null, "A job name is required");
return new JobBuilder(this.properties.getJobName(), this.jobRepository).start(step).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.cloud.task.batch.autoconfigure;

import org.jspecify.annotations.Nullable;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
Expand All @@ -30,63 +32,63 @@ public class SingleStepJobProperties {
/**
* Name of the step in the single step job.
*/
private String stepName;
private @Nullable String stepName;

/**
* The number of items to process per transaction or chunk.
*/
private Integer chunkSize;
private @Nullable Integer chunkSize;

/**
* The name of the job.
*/
private String jobName;
private @Nullable String jobName;

/**
* Name of the step in the single step job.
* @return name
*/
public String getStepName() {
public @Nullable String getStepName() {
return stepName;
}

/**
* Set the name of the step.
* @param stepName name
*/
public void setStepName(String stepName) {
public void setStepName(@Nullable String stepName) {
this.stepName = stepName;
}

/**
* The number of items to process per transaction/chunk.
* @return number of items
*/
public Integer getChunkSize() {
public @Nullable Integer getChunkSize() {
return chunkSize;
}

/**
* Set the number of items within a transaction/chunk.
* @param chunkSize number of items
*/
public void setChunkSize(Integer chunkSize) {
public void setChunkSize(@Nullable Integer chunkSize) {
this.chunkSize = chunkSize;
}

/**
* The name of the job.
* @return name
*/
public String getJobName() {
public @Nullable String getJobName() {
return jobName;
}

/**
* Set the name of the job.
* @param jobName name
*/
public void setJobName(String jobName) {
public void setJobName(@Nullable String jobName) {
this.jobName = jobName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.task.batch.autoconfigure.RangeConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.util.Assert;

/**
* Autconfiguration for a {@code FlatFileItemReader}.
Expand Down Expand Up @@ -71,6 +72,8 @@ public FlatFileItemReader<Map<String, Object>> itemReader(@Autowired(required =
@Autowired(required = false) LineMapper<Map<String, Object>> lineMapper,
@Autowired(required = false) LineCallbackHandler skippedLinesCallback,
@Autowired(required = false) RecordSeparatorPolicy recordSeparatorPolicy) {
Assert.state(this.properties.getName() != null, "A name is required");
Assert.state(this.properties.getResource() != null, "A resource is required");
FlatFileItemReaderBuilder<Map<String, Object>> mapFlatFileItemReaderBuilder = new FlatFileItemReaderBuilder<Map<String, Object>>()
.name(this.properties.getName())
.resource(this.properties.getResource())
Expand All @@ -90,6 +93,7 @@ public FlatFileItemReader<Map<String, Object>> itemReader(@Autowired(required =
mapFlatFileItemReaderBuilder.skippedLinesCallback(skippedLinesCallback);

if (this.properties.isDelimited()) {
Assert.state(this.properties.getNames() != null, "Names are required");
mapFlatFileItemReaderBuilder.delimited()
.quoteCharacter(this.properties.getQuoteCharacter())
.delimiter(this.properties.getDelimiter())
Expand All @@ -99,9 +103,14 @@ public FlatFileItemReader<Map<String, Object>> itemReader(@Autowired(required =
.fieldSetMapper(new MapFieldSetMapper());
}
else if (this.properties.isFixedLength()) {
Assert.state(this.properties.getNames() != null, "Names are required");
RangeConverter rangeConverter = new RangeConverter();
List<Range> ranges = new ArrayList<>();
this.properties.getRanges().forEach(range -> ranges.add(rangeConverter.convert(range)));
this.properties.getRanges().forEach(range -> {
Range result = rangeConverter.convert(range);
Assert.state(result != null, "Range String could not converted to non-null range");
ranges.add(result);
});
mapFlatFileItemReaderBuilder.fixedLength()
.columns(ranges.toArray(new Range[0]))
.names(this.properties.getNames())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.ArrayList;
import java.util.List;

import org.jspecify.annotations.Nullable;

import org.springframework.batch.infrastructure.item.file.FlatFileItemReader;
import org.springframework.batch.infrastructure.item.file.transform.DelimitedLineTokenizer;
import org.springframework.batch.infrastructure.item.file.transform.Range;
Expand All @@ -44,7 +46,7 @@ public class FlatFileItemReaderProperties {
* {@link org.springframework.batch.infrastructure.item.ExecutionContext}. Required if
* {@link #setSaveState} is set to {@code true}.
*/
private String name;
private @Nullable String name;

/**
* Configure the maximum number of items to be read.
Expand All @@ -64,7 +66,7 @@ public class FlatFileItemReaderProperties {
/**
* The {@link Resource} to be used as input.
*/
private Resource resource;
private @Nullable Resource resource;

/**
* Configure whether the reader should be in strict mode (require the input
Expand Down Expand Up @@ -118,7 +120,7 @@ public class FlatFileItemReaderProperties {
/**
* The names of the fields to be parsed from the file.
*/
private String[] names;
private String @Nullable [] names;

/**
* Indicates whether the number of tokens must match the number of configured fields.
Expand Down Expand Up @@ -150,7 +152,7 @@ public void setSaveState(boolean saveState) {
* keys.
* @return the name
*/
public String getName() {
public @Nullable String getName() {
return this.name;
}

Expand All @@ -161,7 +163,7 @@ public String getName() {
* @param name name of the reader instance
* @see org.springframework.batch.infrastructure.item.ItemStreamSupport#setName(String)
*/
public void setName(String name) {
public void setName(@Nullable String name) {
this.name = name;
}

Expand Down Expand Up @@ -219,7 +221,7 @@ public void setComments(List<String> comments) {
* The input file for the {@code FlatFileItemReader}.
* @return a Resource
*/
public Resource getResource() {
public @Nullable Resource getResource() {
return this.resource;
}

Expand All @@ -228,7 +230,7 @@ public Resource getResource() {
* @param resource the input to the reader.
* @see FlatFileItemReader#setResource(Resource)
*/
public void setResource(Resource resource) {
public void setResource(@Nullable Resource resource) {
this.resource = resource;
}

Expand Down Expand Up @@ -391,15 +393,15 @@ public void setRanges(List<String> ranges) {
* Names of each column.
* @return names
*/
public String[] getNames() {
public String @Nullable [] getNames() {
return this.names;
}

/**
* The names of the fields to be parsed from the file.
* @param names names of fields
*/
public void setNames(String[] names) {
public void setNames(String @Nullable [] names) {
this.names = names;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.WritableResource;
import org.springframework.util.Assert;

/**
* Autoconfiguration for a {@code FlatFileItemWriter}.
Expand All @@ -47,7 +48,7 @@
@AutoConfigureAfter(BatchAutoConfiguration.class)
public class FlatFileItemWriterAutoConfiguration {

private FlatFileItemWriterProperties properties;
private final FlatFileItemWriterProperties properties;

@Autowired(required = false)
private LineAggregator<Map<String, Object>> lineAggregator;
Expand Down Expand Up @@ -78,7 +79,8 @@ else if ((this.properties.isFormatted() || this.properties.isDelimited()) && thi
throw new IllegalStateException(
"A LineAggregator must be configured if the " + "output is not formatted or delimited");
}

Assert.state(this.properties.getName() != null, "name must not be null");
Assert.state(this.properties.getResource() != null, "resource must not be null");
FlatFileItemWriterBuilder<Map<String, Object>> builder = new FlatFileItemWriterBuilder<Map<String, Object>>()
.name(this.properties.getName())
.resource((WritableResource) this.properties.getResource())
Expand All @@ -101,10 +103,13 @@ else if ((this.properties.isFormatted() || this.properties.isDelimited()) && thi
delimitedBuilder.fieldExtractor(this.fieldExtractor);
}
else {
Assert.state(this.properties.getNames() != null, "names must not be null");
delimitedBuilder.fieldExtractor(new MapFieldExtractor(this.properties.getNames()));
}
}
else if (this.properties.isFormatted()) {
Assert.state(this.properties.getFormat() != null, "format must not be null");

FlatFileItemWriterBuilder.FormattedBuilder<Map<String, Object>> formattedBuilder = builder.formatted()
.format(this.properties.getFormat())
.locale(this.properties.getLocale())
Expand All @@ -115,6 +120,7 @@ else if (this.properties.isFormatted()) {
formattedBuilder.fieldExtractor(this.fieldExtractor);
}
else {
Assert.state(this.properties.getNames() != null, "names must not be null");
formattedBuilder.fieldExtractor(new MapFieldExtractor(this.properties.getNames()));
}
}
Expand All @@ -131,7 +137,7 @@ else if (this.lineAggregator != null) {
*/
public static class MapFieldExtractor implements FieldExtractor<Map<String, Object>> {

private String[] names;
private final String[] names;

public MapFieldExtractor(String[] names) {
this.names = names;
Expand Down
Loading