Search in sources :

Example 1 with DefaultLogger

use of com.intellij.openapi.diagnostic.DefaultLogger in project teamcity-git by JetBrains.

the class RetryTest method retryable.

@NotNull
private Retry.Retryable<Void> retryable(@NotNull final StringBuilder result, int failAttempts) {
    final Ref<Integer> attemptNum = new Ref(1);
    return new Retry.Retryable<Void>() {

        @Override
        public boolean requiresRetry(@NotNull final Exception e, int attempt, int maxAttempts) {
            return attempt < maxAttempts;
        }

        @Nullable
        @Override
        public Void call() throws VcsException {
            int num = attemptNum.get();
            try {
                if (num <= failAttempts)
                    throw new VcsException("the exception");
                return null;
            } finally {
                attemptNum.set(num + 1);
            }
        }

        @NotNull
        @Override
        public Logger getLogger() {
            return new DefaultLogger() {

                @Override
                public void debug(final String message) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void debug(final Throwable t) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void debug(final String message, final Throwable t) {
                    append("DEBUG", message, t);
                }

                private void append(final String category, final String message, final Throwable t) {
                    result.append(category).append(" ").append(message);
                    if (t != null) {
                        result.append(": ").append(t.getMessage());
                    }
                    result.append("\n");
                }

                @Override
                public void error(final String message, final Throwable t, final String... details) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void info(final String message) {
                    append("INFO", message, null);
                }

                @Override
                public void info(final String message, final Throwable t) {
                    append("INFO", message, t);
                }

                @Override
                public void warn(final String message, final Throwable t) {
                    append("WARN", message, t);
                }

                @Override
                public boolean isDebugEnabled() {
                    return true;
                }
            };
        }
    };
}
Also used : Ref(com.intellij.openapi.util.Ref) VcsException(jetbrains.buildServer.vcs.VcsException) NotNull(org.jetbrains.annotations.NotNull) DefaultLogger(com.intellij.openapi.diagnostic.DefaultLogger) VcsException(jetbrains.buildServer.vcs.VcsException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with DefaultLogger

use of com.intellij.openapi.diagnostic.DefaultLogger in project android by JetBrains.

the class RenderClassLoaderTest method testRemovingJarFile.

@Test
public void testRemovingJarFile() throws IOException {
    ourLoggerInstance = new DefaultLogger("") {

        @Override
        public void error(@NonNls String message, @Nullable Throwable t, @NonNls @NotNull String... details) {
            fail("Logger shouldn't receive any error calls");
        }
    };
    File jarSource = new File(AndroidTestBase.getTestDataPath(), "rendering/renderClassLoader/lib.jar");
    File testJarFile = File.createTempFile("RenderClassLoader", ".jar");
    FileUtil.copy(jarSource, testJarFile);
    URL testJarFileUrl = testJarFile.toURI().toURL();
    RenderClassLoader loader = new RenderClassLoader(this.getClass().getClassLoader(), 0) {

        @Override
        protected List<URL> getExternalJars() {
            return ImmutableList.of(testJarFileUrl);
        }
    };
    loader.loadClassFromJar("com.myjar.MyJarClass");
    assertTrue(testJarFile.delete());
    loader.loadClassFromJar("com.myjar.MyJarClass");
}
Also used : DefaultLogger(com.intellij.openapi.diagnostic.DefaultLogger) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 3 with DefaultLogger

use of com.intellij.openapi.diagnostic.DefaultLogger in project android by JetBrains.

the class RenderClassLoaderTest method testRemovingClassFile.

@Test
public void testRemovingClassFile() throws IOException {
    ourLoggerInstance = new DefaultLogger("") {

        @Override
        public void error(@NonNls String message, @Nullable Throwable t, @NonNls @NotNull String... details) {
            fail("Logger shouldn't receive any error calls");
        }
    };
    File classSource = new File(AndroidTestBase.getTestDataPath(), "rendering/renderClassLoader/MyJarClass.class");
    byte[] classBytes = Files.readAllBytes(classSource.toPath());
    RenderClassLoader loader = new RenderClassLoader(this.getClass().getClassLoader(), 0) {

        @Override
        protected List<URL> getExternalJars() {
            return ImmutableList.of();
        }

        @NotNull
        @Override
        protected Class<?> defineClassAndPackage(@NotNull String name, @NotNull byte[] b, int offset, int len) {
            // We do not really want to define the class in the test, only make sure that this call is made.
            return RenderClassLoaderTest.class;
        }
    };
    VirtualFile vFile = mock(VirtualFile.class);
    when(vFile.contentsToByteArray()).thenReturn(classBytes);
    assertEquals(RenderClassLoaderTest.class, loader.loadClassFile("com.myjar.MyJarClass", vFile));
    vFile = mock(VirtualFile.class);
    when(vFile.contentsToByteArray()).thenThrow(new FileNotFoundException(""));
    assertNull(loader.loadClassFile("com.myjar.MyJarClass", vFile));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileNotFoundException(java.io.FileNotFoundException) DefaultLogger(com.intellij.openapi.diagnostic.DefaultLogger) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull) URL(java.net.URL) Test(org.junit.Test)

Aggregations

DefaultLogger (com.intellij.openapi.diagnostic.DefaultLogger)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 URL (java.net.URL)2 NotNull (org.jetbrains.annotations.NotNull)2 Test (org.junit.Test)2 Ref (com.intellij.openapi.util.Ref)1 FileNotFoundException (java.io.FileNotFoundException)1 VcsException (jetbrains.buildServer.vcs.VcsException)1