diff options
author | Benoit Lamarche <benoitlamarche@google.com> | 2014-10-24 11:24:28 +0200 |
---|---|---|
committer | Benoit Lamarche <benoitlamarche@google.com> | 2015-02-19 17:10:36 +0100 |
commit | 089cbc89a5f2fdc873508174403a64caca168761 (patch) | |
tree | 52fc81c0bfc689ab2f402398c468b08b930d3bbd | |
parent | f2843b92a2802f57606ac3b9323baa9289e4ded2 (diff) | |
download | toolchain_jack-089cbc89a5f2fdc873508174403a64caca168761.zip toolchain_jack-089cbc89a5f2fdc873508174403a64caca168761.tar.gz toolchain_jack-089cbc89a5f2fdc873508174403a64caca168761.tar.bz2 |
Redo exceptions in JayceFileImporter
Change-Id: Id1f50e8a0a655116ba80184e3f6a039a72d27a3d
12 files changed, 241 insertions, 68 deletions
diff --git a/jack-tests/tests/com/android/jack/fileconflict/FileConflictTests.java b/jack-tests/tests/com/android/jack/fileconflict/FileConflictTests.java index 20ef80e..451a030 100644 --- a/jack-tests/tests/com/android/jack/fileconflict/FileConflictTests.java +++ b/jack-tests/tests/com/android/jack/fileconflict/FileConflictTests.java @@ -17,10 +17,12 @@ package com.android.jack.fileconflict; -import com.android.jack.backend.jayce.ImportConflictException; +import com.android.jack.JackAbortException; import com.android.jack.backend.jayce.JayceFileImporter; +import com.android.jack.backend.jayce.TypeImportConflictException; import com.android.jack.library.FileType; import com.android.jack.library.JackLibrary; +import com.android.jack.library.LibraryReadingException; import com.android.jack.resource.ResourceImportConflictException; import com.android.jack.resource.ResourceImporter; import com.android.jack.shrob.obfuscation.NameProviderFactory; @@ -41,6 +43,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -49,6 +52,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; +import java.io.OutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -125,10 +129,17 @@ public class FileConflictTests { @Test public void test001a() throws Exception { File jackOutput = AbstractTestTools.createTempDir(); + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); try { - runTest001(jackOutput, null, /* isApiTest = */ true); + runTest001(jackOutput, null, errOut, /* isApiTest = */ true); Assert.fail(); - } catch (ImportConflictException e) { + } catch (JackAbortException e) { + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + Assert.assertTrue(e.getCause().getCause() instanceof TypeImportConflictException); + String errString = errOut.toString(); + Assert.assertTrue( + errString.contains("Type com.android.jack.fileconflict.test001.jack.MyClass")); + Assert.assertTrue(errString.contains("has already been imported")); } } @@ -140,10 +151,17 @@ public class FileConflictTests { @Test public void test001b() throws Exception { File jackOutput = AbstractTestTools.createTempDir(); + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); try { - runTest001(jackOutput, "fail", /* isApiTest = */ true); + runTest001(jackOutput, "fail", errOut, /* isApiTest = */ true); Assert.fail(); - } catch (ImportConflictException e) { + } catch (JackAbortException e) { + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + Assert.assertTrue(e.getCause().getCause() instanceof TypeImportConflictException); + String errString = errOut.toString(); + Assert.assertTrue( + errString.contains("Type com.android.jack.fileconflict.test001.jack.MyClass")); + Assert.assertTrue(errString.contains("has already been imported")); } } @@ -155,13 +173,22 @@ public class FileConflictTests { @Test public void test001c() throws Exception { File jackOutput = AbstractTestTools.createTempDir(); - runTest001(jackOutput, "keep-first", /* isApiTest = */ false); + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + runTest001(jackOutput, "keep-first", errOut /* errorStream */, /* isApiTest = */ false); File myClass1 = new File(jackOutput, JACK_FILE_PATH_1); File myClass2 = new File(jackOutput, JACK_FILE_PATH_2); File myClass3 = new File(jackOutput, JACK_FILE_PATH_3); Assert.assertTrue(myClass1.exists()); Assert.assertTrue(myClass2.exists()); Assert.assertTrue(myClass3.exists()); + String errString = errOut.toString(); + Assert.assertTrue( + errString.contains("Type com.android.jack.fileconflict.test001.jack.MyClass")); + Assert.assertTrue( + errString.contains("Type com.android.jack.fileconflict.test001.jack.MyClass2")); + Assert.assertTrue( + errString.contains("Type com.android.jack.fileconflict.test001.jack.MyClass3")); + Assert.assertTrue(errString.contains("has already been imported")); } /** @@ -172,10 +199,17 @@ public class FileConflictTests { @Test public void test002a() throws Exception { File jackOutput; + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); try { - jackOutput = runTest002(false /* non-zipped */, null, /* isApiTest = */ true); + jackOutput = runTest002(false /* non-zipped */, null /* collisionPolicy */, errOut, /* isApiTest = */ true); Assert.fail(); - } catch (ResourceImportConflictException e) { + } catch (JackAbortException e) { + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + Assert.assertTrue(e.getCause().getCause() instanceof ResourceImportConflictException); + String errString = errOut.toString(); + Assert.assertTrue(errString.contains("Resource in")); + Assert.assertTrue(errString.contains("rsc/Resource1")); + Assert.assertTrue(errString.contains("has already been imported")); } } @@ -187,10 +221,17 @@ public class FileConflictTests { @Test public void test002b() throws Exception { File jackOutput; + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); try { - jackOutput = runTest002(false /* non-zipped */, "fail", /* isApiTest = */ true); + jackOutput = runTest002(false /* non-zipped */, "fail", errOut, /* isApiTest = */ true); Assert.fail(); - } catch (ResourceImportConflictException e) { + } catch (JackAbortException e) { + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + Assert.assertTrue(e.getCause().getCause() instanceof ResourceImportConflictException); + String errString = errOut.toString(); + Assert.assertTrue(errString.contains("Resource in")); + Assert.assertTrue(errString.contains("rsc/Resource1")); + Assert.assertTrue(errString.contains("has already been imported")); } } @@ -202,10 +243,15 @@ public class FileConflictTests { @Test public void test002c() throws Exception { File jackOutput; - jackOutput = runTest002(false /* non-zipped */, "keep-first", /* isApiTest = */ false); + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + jackOutput = runTest002(false /* non-zipped */, "keep-first", errOut, /* isApiTest = */ false); checkResourceContent(jackOutput, RESOURCE1_LONGPATH, "Res1"); checkResourceContent(jackOutput, RESOURCE2_LONGPATH, "Res2"); checkResourceContent(jackOutput, RESOURCE3_LONGPATH, "Res3"); + String errString = errOut.toString(); + Assert.assertTrue(errString.contains("Resource in")); + Assert.assertTrue(errString.contains("rsc/Resource1")); + Assert.assertTrue(errString.contains("has already been imported")); } /** @@ -216,10 +262,17 @@ public class FileConflictTests { @Test public void test002d() throws Exception { File jackOutput; + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); try { - jackOutput = runTest002(true /* zipped */, null, /* isApiTest = */ true); + jackOutput = runTest002(true /* zipped */, null, errOut, /* isApiTest = */ true); Assert.fail(); - } catch (ResourceImportConflictException e) { + } catch (JackAbortException e) { + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + Assert.assertTrue(e.getCause().getCause() instanceof ResourceImportConflictException); + String errString = errOut.toString(); + Assert.assertTrue(errString.contains("Resource in")); + Assert.assertTrue(errString.contains("rsc/Resource1")); + Assert.assertTrue(errString.contains("has already been imported")); } } @@ -231,10 +284,17 @@ public class FileConflictTests { @Test public void test002e() throws Exception { File jackOutput; + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); try { - jackOutput = runTest002(true /* zipped */, "fail", /* isApiTest = */ true); + jackOutput = runTest002(true /* zipped */, "fail", errOut, /* isApiTest = */ true); Assert.fail(); - } catch (ResourceImportConflictException e) { + } catch (JackAbortException e) { + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + Assert.assertTrue(e.getCause().getCause() instanceof ResourceImportConflictException); + String errString = errOut.toString(); + Assert.assertTrue(errString.contains("Resource in")); + Assert.assertTrue(errString.contains("rsc/Resource1")); + Assert.assertTrue(errString.contains("has already been imported")); } } @@ -246,11 +306,16 @@ public class FileConflictTests { @Test public void test002f() throws Exception { File jackOutput; - jackOutput = runTest002(true /* zipped */, "keep-first", /* isApiTest = */ false); + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + jackOutput = runTest002(true /* zipped */, "keep-first", errOut, /* isApiTest = */ false); ZipFile zipFile = new ZipFile(jackOutput); checkResourceContent(zipFile, RESOURCE1_LONGPATH, "Res1"); checkResourceContent(zipFile, RESOURCE2_LONGPATH, "Res2"); checkResourceContent(zipFile, RESOURCE3_LONGPATH, "Res3"); + String errString = errOut.toString(); + Assert.assertTrue(errString.contains("Resource in")); + Assert.assertTrue(errString.contains("rsc/Resource1")); + Assert.assertTrue(errString.contains("has already been imported")); } /** @@ -390,7 +455,6 @@ public class FileConflictTests { copyFileToDir(libProperties, libPropName, jackImport1); copyFileToDir(myClass1, jackFilePath, jackImport1); copyFileToDir(resource, "com/android/jack/fileconflict/test004/jack/MyClass.txt", jackImport1); - System.out.println(jackImport1.getAbsolutePath()); // copy a different resource to output dir with the same name File resource2 = new File(testSrcDir, "a.txt"); @@ -417,14 +481,16 @@ public class FileConflictTests { } private void runTest001(@Nonnull File jackOutput, @CheckForNull String collisionPolicy, - boolean isApiTest) throws Exception { + @CheckForNull OutputStream errorStream, boolean isApiTest) throws Exception { // compile source files to a Jack dir File tempJackFolder = AbstractTestTools.createTempDir(); JackBasedToolchain toolchain = getToolchain(isApiTest); - toolchain.addToClasspath(toolchain.getDefaultBootClasspath()) - .srcToLib( + if (errorStream != null) { + toolchain.setErrorStream(errorStream); + } + toolchain.addToClasspath(toolchain.getDefaultBootClasspath()).srcToLib( tempJackFolder, /* zipFile = */ false, TEST001_DIR); @@ -466,11 +532,14 @@ public class FileConflictTests { if (collisionPolicy != null) { toolchain.addProperty(JayceFileImporter.COLLISION_POLICY.getName(), collisionPolicy); } + if (errorStream != null) { + toolchain.setErrorStream(errorStream); + } toolchain.libToLib(new File [] {jackImport1, jackImport2}, jackOutput, /* zipFiles = */ false); } @Nonnull - private File runTest002(boolean zip, @CheckForNull String collisionPolicy, boolean isApiTest) + private File runTest002(boolean zip, @CheckForNull String collisionPolicy, @CheckForNull OutputStream errorStream, boolean isApiTest) throws Exception { // compile source files to a Jack dir File jackImport1 = AbstractTestTools.createTempDir(); @@ -478,8 +547,10 @@ public class FileConflictTests { JackBasedToolchain toolchain = getToolchain(isApiTest); toolchain.addResource(new File(lib1, "rsc")); - toolchain.addToClasspath(toolchain.getDefaultBootClasspath()) - .srcToLib( + if (errorStream != null) { + toolchain.setErrorStream(errorStream); + } + toolchain.addToClasspath(toolchain.getDefaultBootClasspath()).srcToLib( jackImport1, /* zipFiles = */ false, lib1); @@ -488,8 +559,10 @@ public class FileConflictTests { File lib2 = new File(TEST002_DIR, "lib2"); toolchain = getToolchain(isApiTest); toolchain.addResource(new File(lib2, "rsc")); - toolchain.addToClasspath(toolchain.getDefaultBootClasspath()) - .srcToLib( + if (errorStream != null) { + toolchain.setErrorStream(errorStream); + } + toolchain.addToClasspath(toolchain.getDefaultBootClasspath()).srcToLib( jackImport2, /* zipFiles = */ false, lib2); @@ -506,6 +579,9 @@ public class FileConflictTests { } else { jackOutput = AbstractTestTools.createTempDir(); } + if (errorStream != null) { + toolchain.setErrorStream(errorStream); + } toolchain.libToLib(new File[] {jackImport1,jackImport2}, jackOutput, /* zipFiles = */ zip); return jackOutput; diff --git a/jack-tests/tests/com/android/jack/imports/ImportTests.java b/jack-tests/tests/com/android/jack/imports/ImportTests.java index f0a3c0c..3b508cf 100644 --- a/jack-tests/tests/com/android/jack/imports/ImportTests.java +++ b/jack-tests/tests/com/android/jack/imports/ImportTests.java @@ -16,9 +16,10 @@ package com.android.jack.imports; -import com.android.jack.backend.jayce.ImportConflictException; +import com.android.jack.JackAbortException; import com.android.jack.backend.jayce.JayceFileImporter; import com.android.jack.backend.jayce.TypeImportConflictException; +import com.android.jack.library.LibraryReadingException; import com.android.jack.test.toolchain.AbstractTestTools; import com.android.jack.test.toolchain.IToolchain; import com.android.jack.test.toolchain.JackApiToolchain; @@ -29,6 +30,7 @@ import junit.framework.Assert; import org.junit.BeforeClass; import org.junit.Test; +import java.io.ByteArrayOutputStream; import java.io.File; public class ImportTests { @@ -69,6 +71,9 @@ public class ImportTests { toolchain = AbstractTestTools.getCandidateToolchain(); toolchain.addStaticLibs(jackOut); + + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setErrorStream(errOut); try { toolchain.addToClasspath(toolchain.getDefaultBootClasspath()) .srcToExe( @@ -76,8 +81,13 @@ public class ImportTests { /* zipFile = */ false, AbstractTestTools.getTestRootDir("com.android.jack.fibonacci.test001.jack")); Assert.fail(); - } catch (ImportConflictException e) { + } catch (JackAbortException e) { // expected + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + Assert.assertTrue(e.getCause().getCause() instanceof TypeImportConflictException); + String errString = errOut.toString(); + Assert.assertTrue(errString.contains("Type com.android.jack.fibonacci.test001.jack.Fibo")); + Assert.assertTrue(errString.contains("has already been imported")); } } @@ -120,6 +130,9 @@ public class ImportTests { // import twice the same lib toolchain.addStaticLibs(lib, lib); toolchain.addProperty(JayceFileImporter.COLLISION_POLICY.getName(), "fail"); + + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setErrorStream(errOut); try { toolchain.addToClasspath(toolchain.getDefaultBootClasspath()) .srcToExe( @@ -127,8 +140,13 @@ public class ImportTests { /* zipFile = */ true, AbstractTestTools.getTestRootDir(testName + ".jack")); Assert.fail(); - } catch (TypeImportConflictException e) { + } catch (JackAbortException e) { // Exception is ok + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + Assert.assertTrue(e.getCause().getCause() instanceof TypeImportConflictException); + String errString = errOut.toString(); + Assert.assertTrue(errString.contains("Type com.android.jack.inner.test015.lib.A")); + Assert.assertTrue(errString.contains("has already been imported")); } } @@ -158,6 +176,8 @@ public class ImportTests { toolchain.addStaticLibs(lib1, lib2); toolchain.addProperty(JayceFileImporter.COLLISION_POLICY.getName(), "fail"); + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + toolchain.setErrorStream(errOut); try { toolchain.addToClasspath(toolchain.getDefaultBootClasspath()) .srcToExe( @@ -165,8 +185,13 @@ public class ImportTests { /* zipFile = */ true, AbstractTestTools.getTestRootDir(testName + ".jack")); Assert.fail(); - } catch (TypeImportConflictException e) { + } catch (JackAbortException e) { // Exception is ok + Assert.assertTrue(e.getCause() instanceof LibraryReadingException); + Assert.assertTrue(e.getCause().getCause() instanceof TypeImportConflictException); + String errString = errOut.toString(); + Assert.assertTrue(errString.contains("Type com.android.jack.inner.test015.lib.A")); + Assert.assertTrue(errString.contains("has already been imported")); } } } diff --git a/jack/src/com/android/jack/Jack.java b/jack/src/com/android/jack/Jack.java index 74cd8ea..e5ad087 100644 --- a/jack/src/com/android/jack/Jack.java +++ b/jack/src/com/android/jack/Jack.java @@ -89,6 +89,7 @@ import com.android.jack.library.FileType; import com.android.jack.library.InputJackLibrary; import com.android.jack.library.InputLibrary; import com.android.jack.library.LibraryIOException; +import com.android.jack.library.LibraryReadingException; import com.android.jack.library.OutputLibrary; import com.android.jack.lookup.CommonTypes; import com.android.jack.lookup.JPhantomLookup; @@ -809,7 +810,12 @@ public abstract class Jack { throw new JackAbortException(e); } - jayceImporter.doImport(session); + try { + jayceImporter.doImport(session); + } catch (LibraryReadingException e) { + session.getReporter().report(Severity.FATAL, e); + throw new JackAbortException(e); + } if (options.flags != null && (options.flags.shrink() || options.flags.obfuscate())) { Event eventIdMerger = tracer.start(JackEventType.METHOD_ID_MERGER); diff --git a/jack/src/com/android/jack/backend/jayce/ImportConflictException.java b/jack/src/com/android/jack/backend/jayce/ImportConflictException.java index 6a6a407..fdab240 100644 --- a/jack/src/com/android/jack/backend/jayce/ImportConflictException.java +++ b/jack/src/com/android/jack/backend/jayce/ImportConflictException.java @@ -16,12 +16,11 @@ package com.android.jack.backend.jayce; -import com.android.jack.JackUserException; /** * Thrown when a conflict prevents the import of a Jack container entry. */ -public abstract class ImportConflictException extends JackUserException { +public abstract class ImportConflictException extends Exception { private static final long serialVersionUID = 1L; diff --git a/jack/src/com/android/jack/backend/jayce/JayceFileImporter.java b/jack/src/com/android/jack/backend/jayce/JayceFileImporter.java index 54e17b0..6089e7f 100644 --- a/jack/src/com/android/jack/backend/jayce/JayceFileImporter.java +++ b/jack/src/com/android/jack/backend/jayce/JayceFileImporter.java @@ -16,19 +16,22 @@ package com.android.jack.backend.jayce; -import com.android.jack.Jack; import com.android.jack.JackEventType; import com.android.jack.config.id.Brest; import com.android.jack.ir.ast.JDefinedClassOrInterface; -import com.android.jack.ir.ast.JPackageLookupException; import com.android.jack.ir.ast.JSession; import com.android.jack.ir.ast.JTypeLookupException; import com.android.jack.ir.ast.Resource; import com.android.jack.library.FileType; +import com.android.jack.library.IgnoringImportMessage; import com.android.jack.library.InputJackLibrary; import com.android.jack.library.InputLibrary; +import com.android.jack.library.LibraryReadingException; import com.android.jack.library.TypeInInputLibraryLocation; import com.android.jack.lookup.JLookup; +import com.android.jack.lookup.JLookupException; +import com.android.jack.reporting.Reporter; +import com.android.jack.reporting.Reporter.Severity; import com.android.jack.resource.ResourceImportConflictException; import com.android.jack.resource.ResourceImporter; import com.android.sched.util.HasDescription; @@ -114,23 +117,41 @@ public class JayceFileImporter { this.jackLibraries = jackLibraries; } - public void doImport(@Nonnull JSession session) throws JPackageLookupException, - ImportConflictException, JTypeLookupException { + public void doImport(@Nonnull JSession session) throws LibraryReadingException { for (InputJackLibrary jackLibrary : jackLibraries) { + Reporter reporter = session.getReporter(); logger.log(Level.FINE, "Importing {0}", jackLibrary.getLocation().getDescription()); Iterator<InputVFile> jayceFileIt = jackLibrary.iterator(FileType.JAYCE); while (jayceFileIt.hasNext()) { InputVFile jayceFile = jayceFileIt.next(); String name = getNameFromInputVFile(jackLibrary, jayceFile, FileType.JAYCE); - addImportedTypes(session, name, jackLibrary); + try { + addImportedTypes(session, name, jackLibrary); + } catch (JLookupException e) { + throw new LibraryReadingException(e); + } catch (TypeImportConflictException e) { + if (collisionPolicy == CollisionPolicy.FAIL) { + throw new LibraryReadingException(e); + } else { + reporter.report(Severity.NON_FATAL, new IgnoringImportMessage(e)); + } + } } Iterator<InputVFile> rscFileIt = jackLibrary.iterator(FileType.RSC); while (rscFileIt.hasNext()) { InputVFile rscFile = rscFileIt.next(); String name = getNameFromInputVFile(jackLibrary, rscFile, FileType.RSC); - addImportedResource(rscFile, session, name); + try { + addImportedResource(rscFile, session, name); + } catch (ResourceImportConflictException e) { + if (resourceCollisionPolicy == CollisionPolicy.FAIL) { + throw new LibraryReadingException(e); + } else { + reporter.report(Severity.NON_FATAL, new IgnoringImportMessage(e)); + } + } } } } @@ -171,16 +192,7 @@ public class JayceFileImporter { if (!(existingSource instanceof TypeInInputLibraryLocation) || ((TypeInInputLibraryLocation) existingSource).getInputLibraryLocation().getInputLibrary() != intendedInputLibrary) { - if (collisionPolicy == CollisionPolicy.FAIL) { - throw new TypeImportConflictException(declaredType, intendedInputLibrary.getLocation()); - } else { - session.getUserLogger().log(Level.INFO, - "Type ''{0}'' from {1} has already been imported from {2}: " - + "ignoring import", new Object[] { - Jack.getUserFriendlyFormatter().getName(declaredType), - intendedInputLibrary.getLocation().getDescription(), - existingSource.getDescription()}); - } + throw new TypeImportConflictException(declaredType, intendedInputLibrary.getLocation()); } else { session.addTypeToEmit(declaredType); } @@ -201,16 +213,8 @@ public class JayceFileImporter { Resource newResource = new Resource(path, file); for (Resource existingResource : session.getResources()) { if (existingResource.getPath().equals(path)) { - if (resourceCollisionPolicy == CollisionPolicy.FAIL) { - throw new ResourceImportConflictException(newResource.getLocation(), - existingResource.getLocation()); - } else { - session.getUserLogger().log(Level.INFO, - "Resource in {0} has already been imported from {1}: ignoring import", new Object[] { - newResource.getLocation().getDescription(), - existingResource.getLocation().getDescription()}); - } - return; + throw new ResourceImportConflictException(newResource.getLocation(), + existingResource.getLocation()); } } session.addResource(newResource); diff --git a/jack/src/com/android/jack/backend/jayce/TypeImportConflictException.java b/jack/src/com/android/jack/backend/jayce/TypeImportConflictException.java index af9ba1d..12a6eca 100644 --- a/jack/src/com/android/jack/backend/jayce/TypeImportConflictException.java +++ b/jack/src/com/android/jack/backend/jayce/TypeImportConflictException.java @@ -44,8 +44,7 @@ public class TypeImportConflictException extends ImportConflictException { @Nonnull public String getMessage() { Location existingSource = existingType.getLocation(); - return "Failed to perform import: Type " - + Jack.getUserFriendlyFormatter().getName(existingType) + " from " + return "Type " + Jack.getUserFriendlyFormatter().getName(existingType) + " from " + failedToImportSource.getDescription() + " has already been imported from " + existingSource.getDescription() + " (see property '" + JayceFileImporter.COLLISION_POLICY.getName() diff --git a/jack/src/com/android/jack/library/IgnoringImportMessage.java b/jack/src/com/android/jack/library/IgnoringImportMessage.java new file mode 100644 index 0000000..cda299b --- /dev/null +++ b/jack/src/com/android/jack/library/IgnoringImportMessage.java @@ -0,0 +1,48 @@ +/* + * 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.library; + +import com.android.jack.backend.jayce.ImportConflictException; +import com.android.jack.reporting.Reportable; + +import javax.annotation.Nonnull; + +/** + * A {@link Reportable} message during the library import phase. + */ +public class IgnoringImportMessage implements Reportable { + + @Nonnull + private final ImportConflictException exception; + + public IgnoringImportMessage(@Nonnull ImportConflictException exception) { + this.exception = exception; + } + + @Override + @Nonnull + public String getMessage() { + return "Ignoring import: " + exception.getMessage(); + } + + @Override + @Nonnull + public ProblemLevel getDefaultProblemLevel() { + return ProblemLevel.INFO; + } + +} diff --git a/jack/src/com/android/jack/meta/MetaImporter.java b/jack/src/com/android/jack/meta/MetaImporter.java index 50efd93..fbcaae7 100644 --- a/jack/src/com/android/jack/meta/MetaImporter.java +++ b/jack/src/com/android/jack/meta/MetaImporter.java @@ -18,6 +18,7 @@ package com.android.jack.meta; import com.android.jack.ir.ast.JSession; import com.android.jack.resource.ResourceOrMetaImporter; +import com.android.jack.resource.ResourceReadingException; import com.android.sched.vfs.InputVFS; import com.android.sched.vfs.InputVFile; import com.android.sched.vfs.VPath; @@ -36,6 +37,16 @@ public class MetaImporter extends ResourceOrMetaImporter { } @Override + public void doImport(@Nonnull JSession session) { + try { + super.doImport(session); + } catch (ResourceReadingException e) { + // should not happen for meta + throw new AssertionError(e); + } + } + + @Override protected void addImportedResource(@Nonnull InputVFile file, @Nonnull JSession session, @Nonnull String currentPath) { VPath path = new VPath(currentPath, ResourceOrMetaImporter.VPATH_SEPARATOR); diff --git a/jack/src/com/android/jack/reporting/Reportable.java b/jack/src/com/android/jack/reporting/Reportable.java index dff2f6a..00a3a17 100644 --- a/jack/src/com/android/jack/reporting/Reportable.java +++ b/jack/src/com/android/jack/reporting/Reportable.java @@ -27,7 +27,7 @@ public interface Reportable { * The level of a problem. */ public static enum ProblemLevel { - ERROR, WARNING + ERROR, WARNING, INFO } @Nonnull diff --git a/jack/src/com/android/jack/resource/ResourceImportConflictException.java b/jack/src/com/android/jack/resource/ResourceImportConflictException.java index 46d79dc..fcac334 100644 --- a/jack/src/com/android/jack/resource/ResourceImportConflictException.java +++ b/jack/src/com/android/jack/resource/ResourceImportConflictException.java @@ -42,7 +42,7 @@ public class ResourceImportConflictException extends ImportConflictException { @Override @Nonnull public String getMessage() { - return "Failed to perform import: Resource in " + return "Resource in " + newResourceLocation.getDescription() + " has already been imported from " + existingResourceLocation.getDescription() + " (see property '" + ResourceImporter.RESOURCE_COLLISION_POLICY.getName() diff --git a/jack/src/com/android/jack/resource/ResourceImporter.java b/jack/src/com/android/jack/resource/ResourceImporter.java index 143f1cf..df91104 100644 --- a/jack/src/com/android/jack/resource/ResourceImporter.java +++ b/jack/src/com/android/jack/resource/ResourceImporter.java @@ -56,7 +56,7 @@ public class ResourceImporter extends ResourceOrMetaImporter { @Override protected void addImportedResource(@Nonnull InputVFile file, @Nonnull JSession session, - @Nonnull String currentPath) { + @Nonnull String currentPath) throws ResourceImportConflictException { VPath path = new VPath(currentPath, ResourceOrMetaImporter.VPATH_SEPARATOR); Resource newResource = new Resource(path, file); for (Resource existingResource : session.getResources()) { diff --git a/jack/src/com/android/jack/resource/ResourceOrMetaImporter.java b/jack/src/com/android/jack/resource/ResourceOrMetaImporter.java index 386190b..1badf38 100644 --- a/jack/src/com/android/jack/resource/ResourceOrMetaImporter.java +++ b/jack/src/com/android/jack/resource/ResourceOrMetaImporter.java @@ -42,14 +42,19 @@ public abstract class ResourceOrMetaImporter { this.resourceDirs = resourceDirs; } - public void doImport(@Nonnull JSession session) { - for (InputVFS resourceDir : resourceDirs) { - importResourceDirElement(resourceDir.getRootInputVDir().list(), session, ""); + public void doImport(@Nonnull JSession session) throws ResourceReadingException { + try { + for (InputVFS resourceDir : resourceDirs) { + importResourceDirElement(resourceDir.getRootInputVDir().list(), session, ""); + } + } catch (ResourceImportConflictException e) { + throw new ResourceReadingException(e); } } private void importResourceDirElement(@Nonnull Collection<? extends InputVElement> elements, - @Nonnull JSession session, @Nonnull String currentPath) { + @Nonnull JSession session, @Nonnull String currentPath) + throws ResourceImportConflictException { for (InputVElement element : elements) { String path = currentPath + element.getName(); if (element.isVDir()) { @@ -62,5 +67,5 @@ public abstract class ResourceOrMetaImporter { } protected abstract void addImportedResource(@Nonnull InputVFile file, @Nonnull JSession session, - @Nonnull String currentPath); + @Nonnull String currentPath) throws ResourceImportConflictException; } |