private <T extends ComponentSpec> void registerImplementation(
     ComponentSpecFactory components, List<ModelView<?>> inputs) {
   ServiceRegistry serviceRegistry =
       ModelViews.assertType(inputs.get(0), ModelType.of(ServiceRegistry.class)).getInstance();
   final Instantiator instantiator = serviceRegistry.get(Instantiator.class);
   final ProjectIdentifier projectIdentifier =
       ModelViews.assertType(inputs.get(1), ModelType.of(ProjectIdentifier.class)).getInstance();
   final ProjectSourceSet projectSourceSet =
       ModelViews.assertType(inputs.get(2), ModelType.of(ProjectSourceSet.class)).getInstance();
   components.registerFactory(
       Cast.<ModelType<ComponentSpec>>uncheckedCast(publicType),
       descriptor,
       new BiFunction<ComponentSpec, String, MutableModelNode>() {
         @Override
         public ComponentSpec apply(String name, MutableModelNode modelNode) {
           ComponentSpecIdentifier id =
               new DefaultComponentSpecIdentifier(projectIdentifier.getPath(), name);
           return BaseComponentSpec.create(
               implementationType.getConcreteClass(),
               id,
               modelNode,
               projectSourceSet,
               instantiator);
         }
       });
   components.registerImplementation(
       Cast.<ModelType<T>>uncheckedCast(publicType),
       descriptor,
       Cast.<ModelType<? extends T>>uncheckedCast(implementationType));
   if (COMPONENT_SPEC_INTERNAL_MODEL_TYPE.isAssignableFrom(implementationType)) {
     components.registerInternalView(publicType, descriptor, COMPONENT_SPEC_INTERNAL_MODEL_TYPE);
   }
 }
 protected C getDelegate(boolean write) {
   if (write) {
     state.assertCanMutate();
   }
   Collection<T> delegate = Cast.uncheckedCast(ScalarCollectionSchema.get(modelNode));
   return initialValue(write, delegate);
 }
    public void execute(
        final MutableModelNode modelNode, final T binary, List<ModelView<?>> inputs) {
      NamedEntityInstantiator<Task> taskFactory =
          Cast.uncheckedCast(ModelViews.getInstance(inputs.get(0), ITaskFactory.class));
      ModelMap<Task> cast =
          DomainObjectCollectionBackedModelMap.wrap(
              Task.class,
              binary.getTasks(),
              taskFactory,
              new Task.Namer(),
              new Action<Task>() {
                @Override
                public void execute(Task task) {
                  binary.getTasks().add(task);
                  binary.builtBy(task);
                }
              });

      List<ModelView<?>> inputsWithBinary = new ArrayList<ModelView<?>>(inputs.size());
      inputsWithBinary.addAll(inputs.subList(1, inputs.size()));
      inputsWithBinary.add(
          InstanceModelView.of(getSubject().getPath(), getSubject().getType(), binary));

      invoke(inputsWithBinary, cast, binary, binary);
    }
 private static Node childNodeNamed(Node root, String name) {
   for (Node child : Cast.<List<Node>>uncheckedCast(root.children())) {
     if (localNameOf(child).equals(name)) {
       return child;
     }
   }
   return null;
 }
 private C initialValue(boolean write, Collection<T> delegate) {
   if (delegate == null) {
     if (write) {
       delegate = createPrivateData(true);
       ScalarCollectionSchema.set(modelNode, delegate);
     } else {
       delegate = createPrivateData(false);
     }
   }
   return Cast.uncheckedCast(delegate);
 }
예제 #6
0
  private PasswordCredentials getPasswordCredentials(Authentication authentication) {
    org.gradle.api.credentials.Credentials credentials =
        ((AuthenticationInternal) authentication).getCredentials();
    if (!(credentials instanceof PasswordCredentials)) {
      throw new IllegalArgumentException(
          String.format(
              "Credentials must be an instance of: %s",
              PasswordCredentials.class.getCanonicalName()));
    }

    return Cast.uncheckedCast(credentials);
  }
예제 #7
0
파일: ModelType.java 프로젝트: Cazen/gradle
  /**
   * Casts this {@code ModelType} object to represent a subclass of the class represented by the
   * specified class object. Checks that the cast is valid, and throws a {@code ClassCastException}
   * if it is not. If this method succeeds, it always returns a reference to this {@code ModelType}
   * object.
   *
   * @throws ClassCastException if this cannot be cast as the subtype of the given type.
   * @throws IllegalStateException if this is a wildcard.
   * @throws IllegalArgumentException if the given type is a wildcard.
   */
  public <U> ModelType<? extends U> asSubtype(ModelType<U> modelType) {
    if (isWildcard()) {
      throw new IllegalStateException(this + " is a wildcard type");
    }
    if (modelType.isWildcard()) {
      throw new IllegalArgumentException(modelType + " is a wildcard type");
    }

    if (modelType.getRawClass().isAssignableFrom(getRawClass())) {
      return Cast.uncheckedCast(this);
    } else {
      throw new ClassCastException(
          String.format("'%s' cannot be cast as a subtype of '%s'", this, modelType));
    }
  }
예제 #8
0
  public <T> T getPrivateData(ModelType<T> type) {
    if (privateData == null) {
      return null;
    }

    if (!type.isAssignableFrom(privateDataType)) {
      throw new ClassCastException(
          "Cannot get private data '"
              + privateData
              + "' of type '"
              + privateDataType
              + "' as type '"
              + type);
    }
    return Cast.uncheckedCast(privateData);
  }
예제 #9
0
 private static PatternSpecFactory createPatternSpecFactory() {
   try {
     // prevents adding CachingPatternSpecFactory and it's dependencies to the Tooling API jar
     // Jarjar scans all String literals for class names and this prevents that scanning from
     // finding the class name and adding it as a dependency
     Class clazz =
         PatternSet.class
             .getClassLoader()
             .loadClass(
                 new StringBuilder("org.gradle.api.tasks.util.internal.")
                     .append("CachingPatternSpecFactory")
                     .toString());
     return Cast.uncheckedCast(DirectInstantiator.instantiate(clazz));
   } catch (ClassNotFoundException e) {
     return new PatternSpecFactory();
   }
 }
예제 #10
0
파일: ModelType.java 프로젝트: Cazen/gradle
 public Class<T> getConcreteClass() {
   return Cast.uncheckedCast(wrapper.getRawClass());
 }
예제 #11
0
파일: ModelType.java 프로젝트: Cazen/gradle
 public Class<? super T> getRawClass() {
   return Cast.uncheckedCast(wrapper.getRawClass());
 }
예제 #12
0
 private <T> Class<? extends T> getGeneratedImplementation(
     StructSchema<T> schema, StructSchema<? extends T> delegateSchema)
     throws java.util.concurrent.ExecutionException {
   return Cast.uncheckedCast(
       generatedImplementationTypes.get(new CacheKey<T>(schema, delegateSchema)));
 }
예제 #13
0
 @Override
 public <T> ExtractedRuleSource<T> newInstance(Class<T> source) {
   StructSchema<T> schema = Cast.uncheckedCast(this.schema);
   return new ParameterizedExtractedRuleSource<T>(
       rules, target, implicitInputs, schema, bindings, proxyFactory);
 }
예제 #14
0
 @Override
 public <T> ExtractedRuleSource<T> newInstance(Class<T> source) {
   return Cast.uncheckedCast(ruleSource);
 }
예제 #15
0
  @Override
  public DeploymentDescriptor readFrom(Reader reader) {
    try {
      Node appNode = createParser().parse(reader);
      version = (String) appNode.attribute("version");
      for (final Node child : Cast.<List<Node>>uncheckedCast(appNode.children())) {
        String childLocalName = localNameOf(child);
        if (childLocalName.equals("application-name")) {

          applicationName = child.text();

        } else if (childLocalName.equals("initialize-in-order")) {

          initializeInOrder = Boolean.valueOf(child.text());

        } else if (childLocalName.equals("description")) {

          description = child.text();

        } else if (childLocalName.equals("display-name")) {

          displayName = child.text();

        } else if (childLocalName.equals("library-directory")) {

          libraryDirectory = child.text();

        } else if (childLocalName.equals("module")) {

          EarModule module = null;
          for (Node moduleNode : Cast.<List<Node>>uncheckedCast(child.children())) {
            String moduleNodeLocalName = localNameOf(moduleNode);
            if (moduleNodeLocalName.equals("web")) {
              String webUri = childNodeNamed(moduleNode, "web-uri").text();
              String contextRoot = childNodeNamed(moduleNode, "context-root").text();
              module = new DefaultEarWebModule(webUri, contextRoot);
              modules.add(module);
              moduleTypeMappings.put(module.getPath(), "web");
            } else if (moduleNodeLocalName.equals("alt-dd")) {
              assert module != null;
              module.setAltDeployDescriptor(moduleNode.text());
            } else {
              module = new DefaultEarModule(moduleNode.text());
              modules.add(module);
              moduleTypeMappings.put(module.getPath(), moduleNodeLocalName);
            }
          }

        } else if (childLocalName.equals("security-role")) {

          String roleName = childNodeNamed(child, "role-name").text();
          String description = childNodeNamed(child, "description").text();
          securityRoles.add(new DefaultEarSecurityRole(roleName, description));

        } else {
          withXml(
              new Action<XmlProvider>() {
                @Override
                public void execute(XmlProvider xmlProvider) {
                  xmlProvider.asNode().append(child);
                }
              });
        }
      }
    } catch (IOException ex) {
      throw new UncheckedIOException(ex);
    } catch (SAXException ex) {
      throw new UncheckedException(ex);
    } finally {
      IOUtils.closeQuietly(reader);
    }
    return this;
  }
 public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
   return Cast.uncheckedCast(annotations.get(annotationType));
 }