コード例 #1
1
 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);
   }
 }
コード例 #2
0
 @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());
   }
 }
コード例 #3
0
 /**
  * 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());
   }
 }
コード例 #4
0
 @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);
   }
 }
コード例 #5
0
 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;
 }
コード例 #6
0
 public void add(Object message) {
   try {
     queue.put(message);
   } catch (InterruptedException e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }
コード例 #7
0
 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();
   }
 }
コード例 #8
0
 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();
 }
コード例 #9
0
  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();
    }
  }
コード例 #10
0
  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();
    }
  }
コード例 #11
0
ファイル: OpenApiFixture.java プロジェクト: nobeans/gradle
  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;
  }
コード例 #12
0
ファイル: JavaReflectionUtil.java プロジェクト: mrhaki/gradle
 public void setValue(Object target, Object value) {
   try {
     field.set(target, value);
   } catch (IllegalAccessException e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }
コード例 #13
0
 public void waitFor() {
   try {
     latch.await();
   } catch (InterruptedException e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }
コード例 #14
0
ファイル: JavaReflectionUtil.java プロジェクト: mrhaki/gradle
 @Override
 public F getValue(T target) {
   try {
     return fieldType.cast(field.get(target));
   } catch (IllegalAccessException e) {
     throw UncheckedException.throwAsUncheckedException(e);
   }
 }
コード例 #15
0
ファイル: JavaReflectionUtil.java プロジェクト: mrhaki/gradle
 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);
   }
 }
コード例 #16
0
ファイル: JavaReflectionUtil.java プロジェクト: mrhaki/gradle
 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);
   }
 }
コード例 #17
0
  private void rethrowFailures() {
    if (failures.isEmpty()) {
      return;
    }

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

    throw UncheckedException.throwAsUncheckedException(failures.get(0));
  }
コード例 #18
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);
   }
 }
コード例 #19
0
 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;
 }
コード例 #20
0
  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);
    }
  }
コード例 #21
0
ファイル: Test.java プロジェクト: pidster/gradle
 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);
   }
 }
コード例 #22
0
    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);
      }
    }
コード例 #23
0
 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();
   }
 }
コード例 #24
0
ファイル: InetAddressFactory.java プロジェクト: GUIpsp/gradle
 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);
   }
 }
コード例 #25
0
 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);
   }
 }
コード例 #26
0
 private void stopMonitoring() {
   lock.lock();
   try {
     while (notifying) {
       try {
         condition.await();
       } catch (InterruptedException e) {
         throw UncheckedException.throwAsUncheckedException(e);
       }
     }
     handler = null;
   } finally {
     lock.unlock();
   }
 }
コード例 #27
0
 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();
   }
 }
コード例 #28
0
 /** 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();
   }
 }
コード例 #29
0
 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);
   }
 }
コード例 #30
0
    public void onOutput(long classId, long testId, TestOutputEvent outputEvent) {
      boolean stdout = outputEvent.getDestination() == TestOutputEvent.Destination.StdOut;
      mark(classId, testId, stdout);

      output.writeBoolean(stdout);
      output.writeLong(classId);
      output.writeLong(testId);

      byte[] bytes;
      try {
        bytes = outputEvent.getMessage().getBytes(messageStorageCharset.name());
      } catch (UnsupportedEncodingException e) {
        throw UncheckedException.throwAsUncheckedException(e);
      }
      output.writeInt(bytes.length);
      output.writeBytes(bytes);
    }