public <T> T createProxy(
     ModelElementState state,
     StructSchema<T> viewSchema,
     @Nullable StructSchema<? extends T> delegateSchema,
     TypeConverter typeConverter) {
   try {
     Class<? extends T> generatedClass = getGeneratedImplementation(viewSchema, delegateSchema);
     if (generatedClass == null) {
       throw new IllegalStateException(
           "No managed implementation class available for: " + viewSchema.getType());
     }
     if (delegateSchema == null) {
       Constructor<? extends T> constructor =
           generatedClass.getConstructor(ModelElementState.class, TypeConverter.class);
       return constructor.newInstance(state, typeConverter);
     } else {
       ModelType<? extends T> delegateType = delegateSchema.getType();
       Object delegate = state.getBackingNode().getPrivateData(delegateType);
       Constructor<? extends T> constructor =
           generatedClass.getConstructor(
               ModelElementState.class, TypeConverter.class, delegateType.getConcreteClass());
       return constructor.newInstance(state, typeConverter, delegate);
     }
   } catch (InvocationTargetException e) {
     throw UncheckedException.throwAsUncheckedException(e.getTargetException());
   } catch (Exception e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }
 public void setValue(Object target, Object value) {
   try {
     method.invoke(target, value);
   } catch (InvocationTargetException e) {
     throw UncheckedException.unwrapAndRethrow(e);
   } catch (Exception e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }
 public F getValue(T target) {
   try {
     return returnType.cast(method.invoke(target));
   } catch (InvocationTargetException e) {
     throw UncheckedException.unwrapAndRethrow(e);
   } catch (Exception e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }
 /**
  * Creates a new rule source instance to be applied to a model element.
  *
  * @throws InvalidModelRuleDeclarationException On badly formed rule source class.
  */
 public <T> ExtractedRuleSource<T> extract(Class<T> source)
     throws InvalidModelRuleDeclarationException {
   try {
     return cache.get(source).newInstance(source);
   } catch (ExecutionException e) {
     throw UncheckedException.throwAsUncheckedException(e);
   } catch (UncheckedExecutionException e) {
     throw UncheckedException.throwAsUncheckedException(e.getCause());
   }
 }
 @Override
 public NodeInitializer getNodeInitializer(NodeInitializerContext<?> nodeInitializerContext) {
   try {
     return cache.get(nodeInitializerContext);
   } catch (ExecutionException e) {
     throw UncheckedException.throwAsUncheckedException(e);
   } catch (UncheckedExecutionException e) {
     throw UncheckedException.throwAsUncheckedException(e.getCause());
   }
 }
 @Override
 public T create() {
   Class<T> concreteClass = type.getConcreteClass();
   try {
     Constructor<T> declaredConstructor = concreteClass.getDeclaredConstructor();
     declaredConstructor.setAccessible(true);
     return declaredConstructor.newInstance();
   } catch (InvocationTargetException e) {
     throw UncheckedException.throwAsUncheckedException(e.getTargetException());
   } catch (Exception e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }
 public Object take(long timeoutValue, TimeUnit timeoutUnits) {
   Object result;
   try {
     result = queue.poll(timeoutValue, timeoutUnits);
   } catch (InterruptedException e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
   if (result instanceof Throwable) {
     Throwable failure = (Throwable) result;
     throw UncheckedException.throwAsUncheckedException(failure);
   }
   return result == END ? null : result;
 }
 public void add(Object message) {
   try {
     queue.put(message);
   } catch (InterruptedException e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }
 private void onFinishCommand() {
   lock.lock();
   try {
     String execution = currentCommandExecution;
     LOGGER.debug("onFinishCommand() called while execution = {}", execution);
     currentCommandExecution = null;
     onDisconnect = null;
     updateActivityTimestamp();
     switch (state) {
       case Running:
         try {
           onFinishCommand.run();
           condition.signalAll();
         } catch (Throwable throwable) {
           setState(State.Broken);
           throw UncheckedException.throwAsUncheckedException(throwable);
         }
         break;
       case StopRequested:
         stop();
         break;
       case Stopped:
         break;
       default:
         throw new IllegalStateException("Daemon is in unexpected state: " + state);
     }
   } finally {
     lock.unlock();
   }
 }
Exemple #10
0
  public DualPaneUIVersion1 createDualPaneUI() {
    TestSingleDualPaneUIInteractionVersion1 testSingleDualPaneUIInteractionVersion1 =
        new TestSingleDualPaneUIInteractionVersion1(
            new TestAlternateUIInteractionVersion1(), new TestSettingsNodeVersion1());
    DualPaneUIVersion1 dualPane;
    try {
      dualPane =
          UIFactory.createDualPaneUI(
              getClass().getClassLoader(),
              dist.getGradleHomeDir(),
              testSingleDualPaneUIInteractionVersion1,
              false);
    } catch (Exception e) {
      throw UncheckedException.throwAsUncheckedException(e);
    }

    // make sure we got something
    Assert.assertNotNull(dualPane);

    dualPane.setCurrentDirectory(dist.getTestDir());
    dualPane.addCommandLineArgumentAlteringListener(
        new ExtraTestCommandLineOptionsListener(dist.getUserHomeDir()));

    return dualPane;
  }
 public T parseNotation(Object notation) {
   if (notation == null) {
     return null;
   }
   if (notation instanceof CharSequence
       || notation instanceof Number
       || notation instanceof Boolean) {
     return (T) notation.toString();
   }
   if (notation instanceof Closure) {
     final Closure closure = (Closure) notation;
     final Object called = closure.call();
     return parseNotation(called);
   }
   if (notation instanceof Callable) {
     try {
       final Callable callableNotation = (Callable) notation;
       final Object called = callableNotation.call();
       return parseNotation(called);
     } catch (Exception e) {
       throw UncheckedException.throwAsUncheckedException(e);
     }
   }
   DeprecationLogger.nagUserOfDeprecated(
       String.format(
           "Converting class %s to path using toString() method", notation.getClass().getName()),
       "Please use java.io.File, java.lang.CharSequence, java.lang.Number, java.util.concurrent.Callable or groovy.lang.Closure");
   return (T) notation.toString();
 }
  private void onStartCommand(String commandDisplayName, Runnable onDisconnect) {
    lock.lock();
    try {
      switch (state) {
        case Broken:
          throw new DaemonUnavailableException("This daemon is in a broken state and will stop.");
        case StopRequested:
          throw new DaemonUnavailableException("This daemon is currently stopping.");
        case Stopped:
          throw new DaemonUnavailableException("This daemon has stopped.");
      }
      if (currentCommandExecution != null) {
        throw new DaemonUnavailableException(
            String.format("This daemon is currently executing: %s", currentCommandExecution));
      }

      LOGGER.debug(
          "onStartCommand({}) called after {} minutes of idle",
          commandDisplayName,
          getIdleMinutes());
      try {
        onStartCommand.run();
        currentCommandExecution = commandDisplayName;
        this.onDisconnect = onDisconnect;
        updateActivityTimestamp();
        condition.signalAll();
      } catch (Throwable throwable) {
        setState(State.Broken);
        throw UncheckedException.throwAsUncheckedException(throwable);
      }
    } finally {
      lock.unlock();
    }
  }
  public T getResult() {
    Object result;
    try {
      result = queue.take();
    } catch (InterruptedException e) {
      throw UncheckedException.asUncheckedException(e);
    }

    if (result instanceof Throwable) {
      throw UncheckedException.asUncheckedException((Throwable) result);
    }
    if (result == NULL) {
      return null;
    }
    return resultType.cast(result);
  }
Exemple #14
0
 public void setValue(Object target, Object value) {
   try {
     field.set(target, value);
   } catch (IllegalAccessException e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }
  public T receive() {
    lock.lock();
    try {
      while (true) {
        DelayedMessage message = queue.peek();
        if (message == null && stopping) {
          return null;
        }
        if (message == null) {
          condition.await();
          continue;
        }

        long now = timeProvider.getCurrentTime();
        if (message.dispatchTime > now) {
          condition.awaitUntil(new Date(message.dispatchTime));
        } else {
          queue.poll();
          if (queue.isEmpty()) {
            condition.signalAll();
          }
          return message.message;
        }
      }
    } catch (InterruptedException e) {
      throw UncheckedException.throwAsUncheckedException(e);
    } finally {
      lock.unlock();
    }
  }
 public void waitFor() {
   try {
     latch.await();
   } catch (InterruptedException e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }
Exemple #17
0
 @Override
 public F getValue(T target) {
   try {
     return fieldType.cast(field.get(target));
   } catch (IllegalAccessException e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }
  private void rethrowFailures() {
    if (failures.isEmpty()) {
      return;
    }

    if (failures.size() > 1) {
      throw new MultipleBuildFailures(failures);
    }

    throw UncheckedException.throwAsUncheckedException(failures.get(0));
  }
 private Object newInstanceOf(String className) {
   // we must use a String literal here, otherwise using things like Foo.class.name will trigger
   // unnecessary
   // loading of classes in the classloader of the DefaultIsolatedAntBuilder, which is not what we
   // want.
   try {
     return antAdapterLoader.loadClass(className).newInstance();
   } catch (Exception e) {
     // should never happen
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }
 static {
   Method equalsMethod;
   Method hashCodeMethod;
   try {
     equalsMethod = Object.class.getMethod("equals", Object.class);
     hashCodeMethod = Object.class.getMethod("hashCode");
   } catch (NoSuchMethodException e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
   EQUALS_METHOD = equalsMethod;
   HASHCODE_METHOD = hashCodeMethod;
 }
  public CrossVersionResultsStore(File dbFile) {
    this.dbFile = dbFile;
    db = new H2FileDb(dbFile, new CrossVersionResultsSchemaInitializer());

    // Ignore some broken samples before the given date
    DateFormat timeStampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    timeStampFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    try {
      ignoreV17Before = timeStampFormat.parse("2013-07-03 00:00:00").getTime();
    } catch (ParseException e) {
      throw UncheckedException.throwAsUncheckedException(e);
    }
  }
Exemple #22
0
 private String getTestReportUrl() {
   // File.toURI().toString() leads to an URL like this on Mac: file:/reports/index.html
   // This URL is not recognized by the Mac terminal (too few leading slashes). We solve
   // this be creating an URI with an empty authority.
   File indexFile = new File(getTestReportDir(), "index.html");
   try {
     if (OperatingSystem.current().isWindows()) {
       return indexFile.toURI().toString();
     }
     return new URI("file", "", indexFile.toString(), null, null).toString();
   } catch (URISyntaxException e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }
    private void doWriteAction(Runnable action) {
      if (mode != LockMode.Exclusive) {
        throw new InsufficientLockModeException("An exclusive lock is required for this operation");
      }

      try {
        integrityViolated = true;
        markDirty();
        action.run();
        markClean();
        integrityViolated = false;
      } catch (Throwable t) {
        throw UncheckedException.throwAsUncheckedException(t);
      }
    }
 private void restoreOwner() {
   lock.lock();
   try {
     while (owner != null) {
       try {
         condition.await();
       } catch (InterruptedException e) {
         throw UncheckedException.throwAsUncheckedException(e);
       }
     }
     owner = Thread.currentThread();
   } finally {
     lock.unlock();
   }
 }
 private void stopMonitoring() {
   lock.lock();
   try {
     while (notifying) {
       try {
         condition.await();
       } catch (InterruptedException e) {
         throw UncheckedException.throwAsUncheckedException(e);
       }
     }
     handler = null;
   } finally {
     lock.unlock();
   }
 }
 protected void disposeBuilder(Object antBuilder, Object antLogger) {
   try {
     Object project = getProject(antBuilder);
     Class<?> projectClass = project.getClass();
     ClassLoader cl = projectClass.getClassLoader();
     // remove build listener
     Class<?> buildListenerClass = cl.loadClass("org.apache.tools.ant.BuildListener");
     Method removeBuildListener =
         projectClass.getDeclaredMethod("removeBuildListener", buildListenerClass);
     removeBuildListener.invoke(project, antLogger);
     antBuilder.getClass().getDeclaredMethod("close").invoke(antBuilder);
   } catch (Exception ex) {
     throw UncheckedException.throwAsUncheckedException(ex);
   }
 }
Exemple #27
0
 public Boolean transform(NetworkInterface original) {
   try {
     try {
       return (Boolean) method.invoke(original);
     } catch (InvocationTargetException e) {
       if (!(e.getCause() instanceof SocketException)) {
         throw e.getCause();
       }
       // Ignore - treat as if we don't know
       return null;
     }
   } catch (Throwable throwable) {
     throw UncheckedException.throwAsUncheckedException(throwable);
   }
 }
 private void takeOwnership(String operationDisplayName) {
   lock.lock();
   try {
     while (owner != null && owner != Thread.currentThread()) {
       try {
         condition.await();
       } catch (InterruptedException e) {
         throw UncheckedException.throwAsUncheckedException(e);
       }
     }
     owner = Thread.currentThread();
     operations.pushCacheAction(operationDisplayName);
   } finally {
     lock.unlock();
   }
 }
 /** Blocks until all queued messages are delivered. */
 public void stop() {
   lock.lock();
   try {
     stopping = true;
     condition.signalAll();
     while (!queue.isEmpty()) {
       try {
         condition.await();
       } catch (InterruptedException e) {
         throw UncheckedException.throwAsUncheckedException(e);
       }
     }
   } finally {
     lock.unlock();
   }
 }
 private URI getDistribution(
     String repositoryUrl, GradleVersion version, String archiveName, String archiveClassifier) {
   try {
     return new URI(
         repositoryUrl
             + "/"
             + archiveName
             + "-"
             + version.getVersion()
             + "-"
             + archiveClassifier
             + ".zip");
   } catch (URISyntaxException e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }