summaryrefslogtreecommitdiffstats
path: root/jack/src
diff options
context:
space:
mode:
authormikaelpeltier <mikaelpeltier@google.com>2014-11-28 11:18:24 +0100
committermikaelpeltier <mikaelpeltier@google.com>2014-11-28 15:12:40 +0100
commit480700d449f6eaf0ce46e9e55a57e01bb186dc31 (patch)
tree58e6c45d3b05e0a19f8082537033b32d0e0f50d6 /jack/src
parent298513d90d3f534dc2fc11201d33739b57d0a8ed (diff)
downloadtoolchain_jack-480700d449f6eaf0ce46e9e55a57e01bb186dc31.zip
toolchain_jack-480700d449f6eaf0ce46e9e55a57e01bb186dc31.tar.gz
toolchain_jack-480700d449f6eaf0ce46e9e55a57e01bb186dc31.tar.bz2
Clean FileType enum
- Add buildPropertyName, buildFileVPath and buildDirVPath methods - Inline property key names directly into enum constructor - Add description parameter into enum constructor Change-Id: I7353d800269cfd80ec43ec88242bc2bc2c4446a0
Diffstat (limited to 'jack/src')
-rw-r--r--jack/src/com/android/jack/backend/dex/DexProperties.java29
-rw-r--r--jack/src/com/android/jack/backend/jayce/JayceFileImporter.java4
-rw-r--r--jack/src/com/android/jack/jayce/JayceProperties.java12
-rw-r--r--jack/src/com/android/jack/jayce/JayceWriterFactory.java4
-rw-r--r--jack/src/com/android/jack/library/CommonJackLibrary.java2
-rw-r--r--jack/src/com/android/jack/library/FileType.java62
-rw-r--r--jack/src/com/android/jack/library/v0000/OutputJackLibraryImpl.java7
-rw-r--r--jack/src/com/android/jack/library/v0001/InputJackLibraryImpl.java12
-rw-r--r--jack/src/com/android/jack/library/v0001/OutputJackLibraryImpl.java12
-rw-r--r--jack/src/com/android/jack/meta/LibraryMetaWriter.java4
-rw-r--r--jack/src/com/android/jack/preprocessor/PreprocessorProperties.java28
-rw-r--r--jack/src/com/android/jack/resource/ResourceProperties.java27
12 files changed, 57 insertions, 146 deletions
diff --git a/jack/src/com/android/jack/backend/dex/DexProperties.java b/jack/src/com/android/jack/backend/dex/DexProperties.java
deleted file mode 100644
index 3f5629c..0000000
--- a/jack/src/com/android/jack/backend/dex/DexProperties.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * 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
- *
- * http://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 com.android.jack.backend.dex;
-
-import javax.annotation.Nonnull;
-
-/**
- * Properties related to dex files.
- */
-public interface DexProperties {
-
- @Nonnull
- public static final String KEY_DEX = "dex";
-
-}
diff --git a/jack/src/com/android/jack/backend/jayce/JayceFileImporter.java b/jack/src/com/android/jack/backend/jayce/JayceFileImporter.java
index 22e2fdf..47fcf31 100644
--- a/jack/src/com/android/jack/backend/jayce/JayceFileImporter.java
+++ b/jack/src/com/android/jack/backend/jayce/JayceFileImporter.java
@@ -147,12 +147,12 @@ public class JayceFileImporter {
name = ((ZipLocation) jayceFile.getLocation()).getEntryName();
if (jackLibrary.getMajorVersion() != 0) {
name = name.substring(
- fileType.getVPathPrefix().split().iterator().next().length() + 1);
+ fileType.buildDirVPath(VPath.ROOT).split().iterator().next().length() + 1);
}
} else {
name = ((FileLocation) jayceFile.getLocation()).getPath();
if (jackLibrary.getMajorVersion() != 0) {
- String prefix = fileType.getVPathPrefix().split().iterator().next() + '/';
+ String prefix = fileType.buildDirVPath(VPath.ROOT).split().iterator().next() + '/';
name = name.substring(name.lastIndexOf(prefix) + prefix.length());
}
}
diff --git a/jack/src/com/android/jack/jayce/JayceProperties.java b/jack/src/com/android/jack/jayce/JayceProperties.java
index f5421e4..cf029e1 100644
--- a/jack/src/com/android/jack/jayce/JayceProperties.java
+++ b/jack/src/com/android/jack/jayce/JayceProperties.java
@@ -16,18 +16,20 @@
package com.android.jack.jayce;
+import com.android.jack.library.FileType;
+
import javax.annotation.Nonnull;
+
/**
* Properties related to Jayce files.
*/
public interface JayceProperties {
@Nonnull
- public static final String KEY_JAYCE = "jayce";
+ public static final String KEY_JAYCE_MAJOR_VERSION =
+ FileType.JAYCE.buildPropertyName(".version.major");
@Nonnull
- public static final String KEY_JAYCE_MAJOR_VERSION = "jayce.version.major";
- @Nonnull
- public static final String KEY_JAYCE_MINOR_VERSION = "jayce.version.minor";
-
+ public static final String KEY_JAYCE_MINOR_VERSION =
+ FileType.JAYCE.buildPropertyName(".version.minor");
}
diff --git a/jack/src/com/android/jack/jayce/JayceWriterFactory.java b/jack/src/com/android/jack/jayce/JayceWriterFactory.java
index f4f2c8e..2bf8848 100644
--- a/jack/src/com/android/jack/jayce/JayceWriterFactory.java
+++ b/jack/src/com/android/jack/jayce/JayceWriterFactory.java
@@ -17,6 +17,7 @@
package com.android.jack.jayce;
import com.android.jack.jayce.v0002.io.JayceInternalWriterImpl;
+import com.android.jack.library.FileType;
import com.android.jack.library.OutputJackLibrary;
import java.io.OutputStream;
@@ -35,7 +36,8 @@ public abstract class JayceWriterFactory {
@Nonnull OutputStream out) {
JayceInternalWriterImpl jayceWriter = new JayceInternalWriterImpl(out);
- outputJackLibrary.putProperty(JayceProperties.KEY_JAYCE, String.valueOf(true));
+ outputJackLibrary.putProperty(FileType.JAYCE.buildPropertyName(null /* suffix */),
+ String.valueOf(true));
outputJackLibrary.putProperty(JayceProperties.KEY_JAYCE_MAJOR_VERSION,
String.valueOf(DEFAULT_MAJOR_VERSION));
outputJackLibrary.putProperty(JayceProperties.KEY_JAYCE_MINOR_VERSION,
diff --git a/jack/src/com/android/jack/library/CommonJackLibrary.java b/jack/src/com/android/jack/library/CommonJackLibrary.java
index 8010285..b9ddf89 100644
--- a/jack/src/com/android/jack/library/CommonJackLibrary.java
+++ b/jack/src/com/android/jack/library/CommonJackLibrary.java
@@ -88,7 +88,7 @@ public abstract class CommonJackLibrary implements JackLibrary {
protected void fillFileTypes() {
for (FileType ft : FileType.values()) {
try {
- String propertyName = ft.getPropertyPrefix();
+ String propertyName = ft.buildPropertyName(null /*suffix*/);
if (containsProperty(propertyName) && Boolean.parseBoolean(getProperty(propertyName))) {
fileTypes.add(ft);
}
diff --git a/jack/src/com/android/jack/library/FileType.java b/jack/src/com/android/jack/library/FileType.java
index 041e851..5bc0954 100644
--- a/jack/src/com/android/jack/library/FileType.java
+++ b/jack/src/com/android/jack/library/FileType.java
@@ -16,13 +16,10 @@
package com.android.jack.library;
-import com.android.jack.backend.dex.DexProperties;
-import com.android.jack.jayce.JayceProperties;
-import com.android.jack.preprocessor.PreprocessorProperties;
-import com.android.jack.resource.ResourceProperties;
import com.android.sched.vfs.InputVFile;
import com.android.sched.vfs.VPath;
+import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
@@ -30,44 +27,31 @@ import javax.annotation.Nonnull;
* File types supported by jack library.
*/
public enum FileType {
- DEX("dex", DexProperties.KEY_DEX, ".dex") {
- @Override
- public String toString() {
- return "dex";
- }
+ DEX("dex", "dex", ".dex", "dex") {
@Override
public void check() throws LibraryFormatException {
}
},
- JAYCE("jayce", JayceProperties.KEY_JAYCE, ".jayce") {
- @Override
- public String toString() {
- return "jayce";
- }
+ JAYCE("jayce", "jayce", ".jayce", "jayce") {
@Override
public void check() throws LibraryFormatException {
}
},
- JPP("jpp", PreprocessorProperties.KEY_JPP, ".jpp") {
- @Override
- public String toString() {
- return "java pre-processor";
- }
+ JPP("jpp", "jpp", ".jpp", "java pre-processor") {
@Override
public void check() throws LibraryFormatException {
}
},
- RSC("rsc", ResourceProperties.KEY_RESOURCE, "") {
- @Override
- public String toString() {
- return "resource";
- }
+ RSC("rsc", "rsc", "", "resource") {
@Override
public void check() throws LibraryFormatException {
}
};
@Nonnull
+ private final String description;
+
+ @Nonnull
private final String extension;
@Nonnull
@@ -80,11 +64,12 @@ public enum FileType {
private final String propertyPrefix;
private FileType(@Nonnull String vpathPrefix, @Nonnull String propertyPrefix,
- @Nonnull String extension) {
+ @Nonnull String extension, @Nonnull String description) {
this.prefix = vpathPrefix;
this.vpathPrefix = new VPath(vpathPrefix, '/');
this.propertyPrefix = propertyPrefix;
this.extension = extension;
+ this.description = description;
}
public abstract void check() throws LibraryFormatException;
@@ -93,6 +78,11 @@ public enum FileType {
return (v.getName().endsWith(getFileExtension()));
}
+ @Override
+ public String toString() {
+ return description;
+ }
+
@Nonnull
public String getFileExtension() {
return extension;
@@ -104,13 +94,20 @@ public enum FileType {
}
@Nonnull
- public String getPropertyPrefix() {
- return propertyPrefix;
+ public String buildPropertyName(@CheckForNull String suffix) {
+ return (propertyPrefix + (suffix == null ? "" : suffix));
}
@Nonnull
- public VPath getVPathPrefix() {
- return vpathPrefix;
+ public VPath buildDirVPath(@Nonnull VPath vpath) {
+ return getPathWithPrefix(vpath);
+ }
+
+ @Nonnull
+ public VPath buildFileVPath(@Nonnull VPath vpath) {
+ VPath clonedPath = getPathWithPrefix(vpath);
+ clonedPath.addSuffix(getFileExtension());
+ return clonedPath;
}
@Nonnull
@@ -123,4 +120,11 @@ public enum FileType {
throw new UnsupportedFileTypeException(v);
}
+
+ @Nonnull
+ private VPath getPathWithPrefix(@Nonnull VPath vpath) {
+ VPath clonedPath = vpath.clone();
+ clonedPath.prependPath(vpathPrefix);
+ return clonedPath;
+ }
}
diff --git a/jack/src/com/android/jack/library/v0000/OutputJackLibraryImpl.java b/jack/src/com/android/jack/library/v0000/OutputJackLibraryImpl.java
index b3d0efc..f7bcffb 100644
--- a/jack/src/com/android/jack/library/v0000/OutputJackLibraryImpl.java
+++ b/jack/src/com/android/jack/library/v0000/OutputJackLibraryImpl.java
@@ -87,7 +87,7 @@ public class OutputJackLibraryImpl extends OutputJackLibrary {
@Nonnull
public OutputVFile createFile(@Nonnull FileType fileType, @Nonnull VPath typePath)
throws CannotCreateFileException {
- putProperty(fileType.getPropertyPrefix(), String.valueOf(true));
+ putProperty(fileType.buildPropertyName(null /*suffix*/), String.valueOf(true));
addFileType(fileType);
VPath clonedPath = typePath.clone();
clonedPath.addSuffix(fileType.getFileExtension());
@@ -141,10 +141,7 @@ public class OutputJackLibraryImpl extends OutputJackLibrary {
public InputVFile getFile(@Nonnull FileType fileType, @Nonnull VPath typePath)
throws FileTypeDoesNotExistException {
try {
- VPath clonedPath = typePath.clone();
- clonedPath.addSuffix(fileType.getFileExtension());
- clonedPath.prependPath(fileType.getVPathPrefix());
- return vfs.getRootDir().getInputVFile(clonedPath);
+ return vfs.getRootDir().getInputVFile(fileType.buildFileVPath(typePath));
} catch (NotFileOrDirectoryException e) {
throw new FileTypeDoesNotExistException(getLocation(), typePath, fileType);
} catch (NoSuchFileException e) {
diff --git a/jack/src/com/android/jack/library/v0001/InputJackLibraryImpl.java b/jack/src/com/android/jack/library/v0001/InputJackLibraryImpl.java
index 085ad8c..b21e43a 100644
--- a/jack/src/com/android/jack/library/v0001/InputJackLibraryImpl.java
+++ b/jack/src/com/android/jack/library/v0001/InputJackLibraryImpl.java
@@ -100,10 +100,7 @@ public class InputJackLibraryImpl extends InputJackLibrary {
public InputVFile getFile(@Nonnull FileType fileType, @Nonnull VPath typePath)
throws FileTypeDoesNotExistException {
try {
- VPath clonedPath = typePath.clone();
- clonedPath.addSuffix(fileType.getFileExtension());
- clonedPath.prependPath(fileType.getVPathPrefix());
- return vfs.getRootDir().getInputVFile(clonedPath);
+ return vfs.getRootDir().getInputVFile(fileType.buildFileVPath(typePath));
} catch (NotFileOrDirectoryException e) {
throw new FileTypeDoesNotExistException(getLocation(), typePath, fileType);
} catch (NoSuchFileException e) {
@@ -117,9 +114,7 @@ public class InputJackLibraryImpl extends InputJackLibrary {
public InputVDir getDir(@Nonnull FileType fileType, @Nonnull VPath typePath)
throws FileTypeDoesNotExistException {
try {
- VPath clonedPath = typePath.clone();
- clonedPath.prependPath(fileType.getVPathPrefix());
- return vfs.getRootDir().getInputVDir(clonedPath);
+ return vfs.getRootDir().getInputVDir(fileType.buildDirVPath(typePath));
} catch (NotFileOrDirectoryException e) {
throw new FileTypeDoesNotExistException(getLocation(), typePath, fileType);
} catch (NoSuchFileException e) {
@@ -136,7 +131,8 @@ public class InputJackLibraryImpl extends InputJackLibrary {
List<InputVFile> inputVFiles = new ArrayList<InputVFile>();
try {
- fillFiles(vfs.getRootDir().getInputVDir(fileType.getVPathPrefix()), fileType, inputVFiles);
+ fillFiles(vfs.getRootDir().getInputVDir(fileType.buildDirVPath(VPath.ROOT)), fileType,
+ inputVFiles);
} catch (NotFileOrDirectoryException e) {
throw new AssertionError(
getLocation().getDescription() + " is an invalid library: " + e.getMessage());
diff --git a/jack/src/com/android/jack/library/v0001/OutputJackLibraryImpl.java b/jack/src/com/android/jack/library/v0001/OutputJackLibraryImpl.java
index 4845638..a84fc01 100644
--- a/jack/src/com/android/jack/library/v0001/OutputJackLibraryImpl.java
+++ b/jack/src/com/android/jack/library/v0001/OutputJackLibraryImpl.java
@@ -87,12 +87,9 @@ public class OutputJackLibraryImpl extends OutputJackLibrary {
@Nonnull
public OutputVFile createFile(@Nonnull FileType fileType, @Nonnull final VPath typePath)
throws CannotCreateFileException {
- putProperty(fileType.getPropertyPrefix(), String.valueOf(true));
+ putProperty(fileType.buildPropertyName(null /*suffix*/), String.valueOf(true));
addFileType(fileType);
- VPath clonedPath = typePath.clone();
- clonedPath.addSuffix(fileType.getFileExtension());
- clonedPath.prependPath(fileType.getVPathPrefix());
- return vfs.getRootDir().createOutputVFile(clonedPath);
+ return vfs.getRootDir().createOutputVFile(fileType.buildFileVPath(typePath));
}
@Override
@@ -152,10 +149,7 @@ public class OutputJackLibraryImpl extends OutputJackLibrary {
public InputVFile getFile(@Nonnull FileType fileType, @Nonnull VPath typePath)
throws FileTypeDoesNotExistException {
try {
- VPath clonedPath = typePath.clone();
- clonedPath.addSuffix(fileType.getFileExtension());
- clonedPath.prependPath(fileType.getVPathPrefix());
- return vfs.getRootDir().getInputVFile(clonedPath);
+ return vfs.getRootDir().getInputVFile(fileType.buildFileVPath(typePath));
} catch (NotFileOrDirectoryException e) {
throw new FileTypeDoesNotExistException(getLocation(), typePath, fileType);
} catch (NoSuchFileException e) {
diff --git a/jack/src/com/android/jack/meta/LibraryMetaWriter.java b/jack/src/com/android/jack/meta/LibraryMetaWriter.java
index 1db7554..79f35c3 100644
--- a/jack/src/com/android/jack/meta/LibraryMetaWriter.java
+++ b/jack/src/com/android/jack/meta/LibraryMetaWriter.java
@@ -77,14 +77,14 @@ public class LibraryMetaWriter implements RunnableSchedulable<JSession> {
name = ((ZipLocation) jppFile.getLocation()).getEntryName();
if (jackLibrary.getMajorVersion() != 0) {
name = name.substring(
- FileType.JPP.getVPathPrefix().split().iterator().next().length() + 1);
+ FileType.JPP.buildDirVPath(VPath.ROOT).split().iterator().next().length() + 1);
} else {
name = name.substring("JACK-INF/".length());
}
} else {
name = ((FileLocation) jppFile.getLocation()).getPath();
if (jackLibrary.getMajorVersion() != 0) {
- String prefix = FileType.JPP.getVPathPrefix().split().iterator().next() + '/';
+ String prefix = FileType.JPP.buildDirVPath(VPath.ROOT).split().iterator().next() + '/';
name = name.substring(name.lastIndexOf(prefix) + prefix.length());
} else {
name = name.substring("JACK-INF/".length());
diff --git a/jack/src/com/android/jack/preprocessor/PreprocessorProperties.java b/jack/src/com/android/jack/preprocessor/PreprocessorProperties.java
deleted file mode 100644
index cef9b51..0000000
--- a/jack/src/com/android/jack/preprocessor/PreprocessorProperties.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * 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
- *
- * http://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 com.android.jack.preprocessor;
-
-import javax.annotation.Nonnull;
-
-/**
- * Properties related to preprocessor.
- */
-public interface PreprocessorProperties {
-
- @Nonnull
- public static final String KEY_JPP = "jpp";
-}
diff --git a/jack/src/com/android/jack/resource/ResourceProperties.java b/jack/src/com/android/jack/resource/ResourceProperties.java
deleted file mode 100644
index 4b1761d..0000000
--- a/jack/src/com/android/jack/resource/ResourceProperties.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * 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
- *
- * http://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 com.android.jack.resource;
-
-import javax.annotation.Nonnull;
-
-/**
- * Properties related to resources.
- */
-public interface ResourceProperties {
- @Nonnull
- public static final String KEY_RESOURCE = "rsc";
-}