Skip to content

Commit 589ac1c

Browse files
committed
Ignore empty columns and rows, fixes #47
1 parent 586e1c0 commit 589ac1c

File tree

14 files changed

+93
-79
lines changed

14 files changed

+93
-79
lines changed

.travis.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 1.0.19
2+
- Filter out empty rows and columns, fixes XLS(X) parsing errors - [#47](https://github.com/koral--/android-gradle-localization-plugin/issues/47)
3+
- Dependency versions bump
4+
15
### 1.0.18
26
- Add option to evaluate formulas in XLS(X) files - [#45](https://github.com/koral--/android-gradle-localization-plugin/pull/45)
37
- Dependency versions bump

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Generation has to be invoked as additional gradle task. Java 1.8 is required.
2525
In whichever `build.gradle` file.
2626
```groovy
2727
plugins {
28-
id 'pl.droidsonroids.localization' version '1.0.17'
28+
id 'pl.droidsonroids.localization' version '1.0.19'
2929
}
3030
```
3131
Note: exact version number must be specified, `+` cannot be used as wildcard.
@@ -40,8 +40,8 @@ Note: exact version number must be specified, `+` cannot be used as wildcard.
4040
jcenter()
4141
}
4242
dependencies {
43-
classpath 'com.android.tools.build:gradle:3.4.2'
44-
classpath 'pl.droidsonroids.gradle.localization:android-gradle-localization-plugin:1.0.17'
43+
classpath 'com.android.tools.build:gradle:3.5.3'
44+
classpath 'pl.droidsonroids.gradle.localization:android-gradle-localization-plugin:1.0.19'
4545
}
4646
}
4747
```
@@ -158,7 +158,7 @@ ignored if `useAllSheets` is set to true
158158

159159
#### Advanced options:
160160
* `ignorableColumns` - default=`[]`, columns from that list will be ignored during parsing. List should
161-
contain column names e.g. `['Section', 'Notes']`
161+
contain column names e.g. `['Section', 'Notes']`. Columns containing only empty cells are always ignored.
162162
* `allowNonTranslatableTranslation` - default=`false`, if set to true resources marked
163163
non-translatable but translated are permitted
164164
* `allowEmptyTranslations` - default=`false`, if set to true then empty values are permitted

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ repositories {
2424

2525
dependencies {
2626
implementation gradleApi()
27-
implementation 'org.codehaus.groovy:groovy:2.5.8'
27+
implementation 'org.codehaus.groovy:groovy:2.5.9'
2828
implementation 'org.marketcetera.fork:commons-csv:3.2.0'
2929
implementation 'org.apache.poi:poi-ooxml-schemas:4.1.1'
3030
implementation 'org.apache.poi:poi-ooxml:4.1.1'
3131
implementation 'org.apache.poi:poi:4.1.1'
3232
implementation 'org.apache.poi:ooxml-schemas:1.4'
33-
testImplementation 'junit:junit:4.12'
33+
testImplementation 'junit:junit:4.13'
3434
testImplementation 'org.assertj:assertj-core:3.14.0'
3535
testImplementation 'org.xmlunit:xmlunit-core:2.6.3'
3636
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION_NAME=1.0.18
1+
VERSION_NAME=1.0.19
22
GROUP=pl.droidsonroids.gradle.localization
33

44
POM_DESCRIPTION=Gradle plugin for generating localized string resources

gradle/wrapper/gradle-wrapper.jar

-7 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/groovy/pl/droidsonroids/gradle/localization/ParserEngine.groovy

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ class ParserEngine {
6565
void parseSpreadsheet() {
6666
mCloseableInput.withCloseable {
6767
Map<String, String[][]> sheets = mParser.getResult()
68-
for (String sheetName: sheets.keySet()) {
68+
for (String sheetName : sheets.keySet()) {
6969
String[][] allCells = sheets.get(sheetName)
70+
71+
def shouldIgnoreEmptyHeaderCell = mConfig.ignorableColumns.contains("")
72+
Utils.validateColumnEmptiness(allCells, shouldIgnoreEmptyHeaderCell)
73+
7074
String outputFileName
7175
if (sheetName != null) {
7276
outputFileName = sheetName + ".xml"
@@ -96,7 +100,7 @@ class ParserEngine {
96100
def arrays = new HashMap<String, List<StringArrayItem>>()
97101
for (i in 1..cells.length - 1) {
98102
String[] row = cells[i]
99-
if (row == null) {
103+
if (row == null || row.every { it.isEmpty() }) {
100104
continue
101105
}
102106
if (row.length < sourceInfo.mColumnsCount) {
@@ -108,7 +112,7 @@ class ParserEngine {
108112
}
109113

110114
String name = row[sourceInfo.mNameIdx]
111-
def value = row[j]
115+
String value = row[j]
112116

113117
String comment = null
114118
if (sourceInfo.mCommentIndex >= 0 && !row[sourceInfo.mCommentIndex].empty) {

src/main/groovy/pl/droidsonroids/gradle/localization/SourceInfo.groovy

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ class SourceInfo {
1414
}
1515

1616
SourceInfo(String[] headerLine, ConfigExtension config, File resDir, String outputFileName) {
17-
if (headerLine == null || headerLine.length < 2) {
18-
throw new IllegalArgumentException("Invalid header: $headerLine")
19-
}
20-
2117
List<String> header = Arrays.asList(headerLine)
2218
mColumnsCount = headerLine.length
2319
mBuilders = new XMLBuilder[mColumnsCount]
@@ -47,7 +43,7 @@ class SourceInfo {
4743
throw new IllegalStateException("Default locale column not present")
4844
}
4945

50-
def reservedColumns = [config.commentColumnName, config.translatableColumnName, config.formattedColumnName]
46+
def reservedColumns = [config.commentColumnName, config.translatableColumnName, config.formattedColumnName, ""]
5147
if (config.tagEscapingStrategyColumnName != null) {
5248
reservedColumns.add(config.tagEscapingStrategyColumnName)
5349
}

src/main/groovy/pl/droidsonroids/gradle/localization/Utils.groovy

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,22 @@ class Utils {
1919
static boolean containsHTML(String text) {
2020
return TAG_PATTERN.matcher(text).find() || CDATA_PATTERN.matcher(text).find()
2121
}
22+
23+
static void validateColumnEmptiness(String[][] allCells, boolean shouldIgnoreEmptyHeaderCell) {
24+
def headerLine = allCells[0]
25+
if (headerLine == null || headerLine.length < 2) {
26+
throw new IllegalArgumentException("Invalid header: $headerLine")
27+
}
28+
29+
if (!shouldIgnoreEmptyHeaderCell) {
30+
def emptyHeaderIndices = headerLine.findIndexValues { it.empty }
31+
allCells.eachWithIndex { String[] row, int rowIndex ->
32+
emptyHeaderIndices.forEach { i ->
33+
if (i < row.length && !row[i.intValue()].empty) {
34+
throw new IllegalArgumentException("Not ignored column #$i contains empty header but non-empty cell at row #$rowIndex")
35+
}
36+
}
37+
}
38+
}
39+
}
2240
}

0 commit comments

Comments
 (0)