refactor: manual YAML Cleanup (#3229)

* refactor: add missing license headers

* fix: remove unused exceptions

* refactor: remove unused single quote / slash param
This commit is contained in:
Connor Tumbleson 2023-07-29 06:14:40 -04:00 committed by GitHub
parent 6e5d49bd66
commit fe93fd21d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 122 additions and 22 deletions

View File

@ -146,15 +146,13 @@ public class ApkInfo implements YamlSerializable {
} }
public static ApkInfo load(InputStream is) throws AndrolibException { public static ApkInfo load(InputStream is) throws AndrolibException {
// return getYaml().loadAs(is, ApkInfo.class);
YamlReader reader = new YamlReader(is); YamlReader reader = new YamlReader(is);
ApkInfo apkInfo = new ApkInfo(); ApkInfo apkInfo = new ApkInfo();
reader.readRoot(apkInfo); reader.readRoot(apkInfo);
return apkInfo; return apkInfo;
} }
public static ApkInfo load(File appDir) public static ApkInfo load(File appDir) throws AndrolibException {
throws AndrolibException {
try( try(
InputStream in = new FileDirectory(appDir).getFileInput("apktool.yml"); InputStream in = new FileDirectory(appDir).getFileInput("apktool.yml");
) { ) {

View File

@ -16,14 +16,12 @@
*/ */
package brut.androlib.apk; package brut.androlib.apk;
import brut.androlib.exceptions.AndrolibException;
public class PackageInfo implements YamlSerializable { public class PackageInfo implements YamlSerializable {
public String forcedPackageId; public String forcedPackageId;
public String renameManifestPackage; public String renameManifestPackage;
@Override @Override
public void readItem(YamlReader reader) throws AndrolibException { public void readItem(YamlReader reader) {
YamlLine line = reader.getLine(); YamlLine line = reader.getLine();
switch (line.getKey()) { switch (line.getKey()) {
case "forcedPackageId": { case "forcedPackageId": {
@ -42,5 +40,4 @@ public class PackageInfo implements YamlSerializable {
writer.writeString("forcedPackageId", forcedPackageId); writer.writeString("forcedPackageId", forcedPackageId);
writer.writeString("renameManifestPackage", renameManifestPackage); writer.writeString("renameManifestPackage", renameManifestPackage);
} }
} }

View File

@ -16,14 +16,12 @@
*/ */
package brut.androlib.apk; package brut.androlib.apk;
import brut.androlib.exceptions.AndrolibException;
public class VersionInfo implements YamlSerializable { public class VersionInfo implements YamlSerializable {
public String versionCode; public String versionCode;
public String versionName; public String versionName;
@Override @Override
public void readItem(YamlReader reader) throws AndrolibException { public void readItem(YamlReader reader) {
YamlLine line = reader.getLine(); YamlLine line = reader.getLine();
switch (line.getKey()) { switch (line.getKey()) {
case "versionCode": { case "versionCode": {

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
* Copyright (C) 2010 Connor Tumbleson <connor.tumbleson@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib.apk; package brut.androlib.apk;
import java.util.Objects; import java.util.Objects;

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
* Copyright (C) 2010 Connor Tumbleson <connor.tumbleson@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib.apk; package brut.androlib.apk;
import brut.androlib.exceptions.AndrolibException; import brut.androlib.exceptions.AndrolibException;

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
* Copyright (C) 2010 Connor Tumbleson <connor.tumbleson@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib.apk; package brut.androlib.apk;
import brut.androlib.exceptions.AndrolibException; import brut.androlib.exceptions.AndrolibException;

View File

@ -26,22 +26,20 @@ import java.io.Writer;
public class YamlStringEscapeUtils { public class YamlStringEscapeUtils {
public static String escapeString(String str) { public static String escapeString(String str) {
return escapeJavaStyleString(str, false, false); return escapeJavaStyleString(str);
} }
/** /**
* @param str String to escape values in, may be null * @param str String to escape values in, may be null
* @param escapeSingleQuotes escapes single quotes if <code>true</code>
* @param escapeForwardSlash TODO
* @return the escaped string * @return the escaped string
*/ */
private static String escapeJavaStyleString(String str, boolean escapeSingleQuotes, boolean escapeForwardSlash) { private static String escapeJavaStyleString(String str) {
if (str == null) { if (str == null) {
return null; return null;
} }
try { try {
StringWriter writer = new StringWriter(str.length() * 2); StringWriter writer = new StringWriter(str.length() * 2);
escapeJavaStyleString(writer, str, escapeSingleQuotes, escapeForwardSlash); escapeJavaStyleString(writer, str);
return writer.toString(); return writer.toString();
} catch (IOException ioe) { } catch (IOException ioe) {
// this should never ever happen while writing to a StringWriter // this should never ever happen while writing to a StringWriter
@ -50,14 +48,11 @@ public class YamlStringEscapeUtils {
} }
/** /**
* @param out write to receieve the escaped string * @param out write to receive the escaped string
* @param str String to escape values in, may be null * @param str String to escape values in, may be null
* @param escapeSingleQuote escapes single quotes if <code>true</code>
* @param escapeForwardSlash TODO
* @throws IOException if an IOException occurs * @throws IOException if an IOException occurs
*/ */
private static void escapeJavaStyleString(Writer out, String str, boolean escapeSingleQuote, private static void escapeJavaStyleString(Writer out, String str) throws IOException {
boolean escapeForwardSlash) throws IOException {
if (out == null) { if (out == null) {
throw new IllegalArgumentException("The Writer must not be null"); throw new IllegalArgumentException("The Writer must not be null");
} }
@ -101,7 +96,7 @@ public class YamlStringEscapeUtils {
} else { } else {
switch (ch) { switch (ch) {
case '\'' : case '\'' :
if (escapeSingleQuote) { if (false) {
out.write('\\'); out.write('\\');
} }
out.write('\''); out.write('\'');
@ -115,7 +110,7 @@ public class YamlStringEscapeUtils {
out.write('\\'); out.write('\\');
break; break;
case '/' : case '/' :
if (escapeForwardSlash) { if (false) {
out.write('\\'); out.write('\\');
} }
out.write('/'); out.write('/');

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
* Copyright (C) 2010 Connor Tumbleson <connor.tumbleson@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib.apk; package brut.androlib.apk;
import java.io.*; import java.io.*;

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
* Copyright (C) 2010 Connor Tumbleson <connor.tumbleson@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib.apk; package brut.androlib.apk;
import brut.androlib.exceptions.AndrolibException; import brut.androlib.exceptions.AndrolibException;

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
* Copyright (C) 2010 Connor Tumbleson <connor.tumbleson@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib.apk; package brut.androlib.apk;
import brut.androlib.exceptions.AndrolibException; import brut.androlib.exceptions.AndrolibException;

View File

@ -1,3 +1,19 @@
/*
* Copyright (C) 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
* Copyright (C) 2010 Connor Tumbleson <connor.tumbleson@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package brut.androlib.apk; package brut.androlib.apk;
import org.junit.Test; import org.junit.Test;