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;
}
};
}
};
}
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");
}
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));
}
Aggregations