Esempio n. 1
0
 private TreeSnapshot createTreeSnapshot(
     final FileSnapshotter fileSnapshotter, final StringInterner stringInterner) {
   final Collection<FileSnapshotWithKey> fileSnapshots =
       CollectionUtils.collect(
           getEntries(),
           new Transformer<FileSnapshotWithKey, FileTreeElement>() {
             @Override
             public FileSnapshotWithKey transform(FileTreeElement fileTreeElement) {
               String absolutePath =
                   getInternedAbsolutePath(fileTreeElement.getFile(), stringInterner);
               IncrementalFileSnapshot incrementalFileSnapshot;
               if (fileTreeElement.isDirectory()) {
                 incrementalFileSnapshot = DirSnapshot.getInstance();
               } else {
                 incrementalFileSnapshot =
                     new FileHashSnapshot(
                         fileSnapshotter.snapshot(fileTreeElement).getHash(),
                         fileTreeElement.getLastModified());
               }
               return new FileSnapshotWithKey(absolutePath, incrementalFileSnapshot);
             }
           });
   if (missingFiles != null) {
     for (File file : missingFiles) {
       fileSnapshots.add(
           new FileSnapshotWithKey(
               getInternedAbsolutePath(file, stringInterner), MissingFileSnapshot.getInstance()));
     }
   }
   return new DefaultTreeSnapshot(fileSnapshots, shareable, nextId);
 }
Esempio n. 2
0
 /** Wraps the given items in a named domain object set. */
 public static <T extends Named> NamedDomainObjectSet<T> toNamedDomainObjectSet(
     Class<T> type, T... items) {
   DefaultNamedDomainObjectSet<T> domainObjectSet =
       new DefaultNamedDomainObjectSet<T>(type, new DirectInstantiator());
   CollectionUtils.addAll(domainObjectSet, items);
   return domainObjectSet;
 }
 Set<File> getFiles(Spec<? super Dependency> dependencySpec) {
   Set<Dependency> selectedDependencies = CollectionUtils.filter(dependencies, dependencySpec);
   for (Dependency dependency : selectedDependencies) {
     resolveContext.add(dependency);
   }
   return resolveContext.resolve().getFiles();
 }
Esempio n. 4
0
  public String resolveAsRelativePath(Object path) {
    List<String> basePath =
        Arrays.asList(StringUtils.split(baseDir.getAbsolutePath(), "/" + File.separator));
    File targetFile = resolve(path);
    List<String> targetPath =
        new ArrayList<String>(
            Arrays.asList(StringUtils.split(targetFile.getAbsolutePath(), "/" + File.separator)));

    // Find and remove common prefix
    int maxDepth = Math.min(basePath.size(), targetPath.size());
    int prefixLen = 0;
    while (prefixLen < maxDepth && basePath.get(prefixLen).equals(targetPath.get(prefixLen))) {
      prefixLen++;
    }
    basePath = basePath.subList(prefixLen, basePath.size());
    targetPath = targetPath.subList(prefixLen, targetPath.size());

    for (int i = 0; i < basePath.size(); i++) {
      targetPath.add(0, "..");
    }
    if (targetPath.isEmpty()) {
      return ".";
    }
    return CollectionUtils.join(File.separator, targetPath);
  }
Esempio n. 5
0
 public Set<File> getFilesWithoutCreating() {
   return CollectionUtils.collect(
       elements.keySet(),
       new Transformer<File, RelativePath>() {
         @Override
         public File transform(RelativePath relativePath) {
           return createFileInstance(relativePath);
         }
       });
 }
 public List<ExtractedModelRule> getRules() {
   return CollectionUtils.collect(
       rules,
       new Transformer<ExtractedModelRule, ExtractedRuleDetails>() {
         @Override
         public ExtractedModelRule transform(ExtractedRuleDetails extractedRuleDetails) {
           return extractedRuleDetails.rule;
         }
       });
 }
 @Override
 public boolean supports(final Credentials credentials) {
   return CollectionUtils.any(
       getSupportedCredentials(),
       new Spec<Class<? extends Credentials>>() {
         @Override
         public boolean isSatisfiedBy(Class<? extends Credentials> element) {
           return element.isAssignableFrom(credentials.getClass());
         }
       });
 }
Esempio n. 8
0
  private String compilerConfig(String action, String... args) {
    String quotedArgs =
        CollectionUtils.join(",", CollectionUtils.collect(args, new SingleQuotingTransformer()));
    StringBuilder builder = new StringBuilder();
    for (String plugin : getPluginList()) {
      String compilerPrefix = getCompilerPrefix(plugin);
      if (compilerPrefix == null) {
        continue;
      }
      builder
          .append(compilerPrefix)
          .append("Compiler.")
          .append(action)
          .append(" ")
          .append(quotedArgs)
          .append("\n");
    }

    return builder.toString();
  }
Esempio n. 9
0
 @Override
 protected Object getAntPropertyValue(String fieldName, Object value) {
   if (fieldName.equals("deprecation")) {
     return toOnOffString(deprecation);
   }
   if (fieldName.equals("unchecked")) {
     return toOnOffString(unchecked);
   }
   if (fieldName.equals("additionalParameters")) {
     return CollectionUtils.asCommandLine(getAdditionalParameters());
   }
   return value;
 }
 private String describeHandlers() {
   String desc =
       Joiner.on(", ")
           .join(
               CollectionUtils.collect(
                   handlers,
                   new Transformer<String, MethodModelRuleExtractor>() {
                     public String transform(MethodModelRuleExtractor original) {
                       return original.getDescription();
                     }
                   }));
   return "[" + desc + "]";
 }
Esempio n. 11
0
 public List<JvmInstallation> findJvms() {
   List<JvmInstallation> jvms = new ArrayList<JvmInstallation>();
   if (OperatingSystem.current().isLinux()) {
     jvms.add(
         new JvmInstallation(
             JavaVersion.VERSION_1_5,
             "1.5.0",
             new File("/opt/jdk/sun-jdk-5"),
             true,
             JvmInstallation.Arch.i386));
     jvms.add(
         new JvmInstallation(
             JavaVersion.VERSION_1_6,
             "1.6.0",
             new File("/opt/jdk/sun-jdk-6"),
             true,
             JvmInstallation.Arch.x86_64));
     jvms.add(
         new JvmInstallation(
             JavaVersion.VERSION_1_6,
             "1.6.0",
             new File("/opt/jdk/ibm-jdk-6"),
             true,
             JvmInstallation.Arch.x86_64));
     jvms.add(
         new JvmInstallation(
             JavaVersion.VERSION_1_7,
             "1.7.0",
             new File("/opt/jdk/oracle-jdk-7"),
             true,
             JvmInstallation.Arch.x86_64));
     jvms.add(
         new JvmInstallation(
             JavaVersion.VERSION_1_8,
             "1.8.0",
             new File("/opt/jdk/oracle-jdk-8"),
             true,
             JvmInstallation.Arch.x86_64));
   }
   return CollectionUtils.filter(
       jvms,
       new Spec<JvmInstallation>() {
         public boolean isSatisfiedBy(JvmInstallation element) {
           return element.getJavaHome().isDirectory();
         }
       });
 }
Esempio n. 12
0
  public void determineExecutionPlan() {
    List<TaskInfo> nodeQueue =
        CollectionUtils.collect(
            new ArrayList<Task>(entryTasks),
            new Transformer<TaskInfo, Task>() {
              public TaskInfo transform(Task original) {
                return graph.getNode(original);
              }
            });

    Set<TaskInfo> visitingNodes = new HashSet<TaskInfo>();
    while (!nodeQueue.isEmpty()) {
      TaskInfo taskNode = nodeQueue.get(0);
      boolean filtered = !filter.isSatisfiedBy(taskNode.getTask());
      if (filtered) {
        taskNode.setRequired(false);
      }

      if (!taskNode.getRequired() || executionPlan.containsKey(taskNode.getTask())) {
        nodeQueue.remove(0);
        continue;
      }

      if (visitingNodes.add(taskNode)) {
        // Have not seen this task before - add its dependencies to the head of the queue and leave
        // this
        // task in the queue
        ArrayList<TaskInfo> dependsOnTasks = new ArrayList<TaskInfo>();
        addAllReversed(dependsOnTasks, taskNode.getHardSuccessors());
        addAllReversed(dependsOnTasks, taskNode.getSoftSuccessors());
        for (TaskInfo dependsOnTask : dependsOnTasks) {
          if (visitingNodes.contains(dependsOnTask)) {
            throw new CircularReferenceException(
                String.format(
                    "Circular dependency between tasks. Cycle includes [%s, %s].",
                    taskNode.getTask(), dependsOnTask.getTask()));
          }
          nodeQueue.add(0, dependsOnTask);
        }
      } else {
        // Have visited this task's dependencies - add it to the end of the plan
        nodeQueue.remove(0);
        visitingNodes.remove(taskNode);
        executionPlan.put(taskNode.getTask(), taskNode);
      }
    }
  }
Esempio n. 13
0
  protected List<String> getCompleteArgs() {
    List<String> args = new ArrayList<>(getArgs());

    List<String> dirNames = getDirNames();

    if (dirNames.size() == 1) {
      args.add("sass.dir=/" + _removeLeadingSlash(dirNames.get(0)));
    } else {
      for (int i = 0; i < dirNames.size(); i++) {
        String dirName = dirNames.get(i);

        args.add("sass.dir." + i + "=/" + _removeLeadingSlash(dirName));
      }
    }

    String docrootDirName = FileUtil.getAbsolutePath(getDocrootDir());

    args.add("sass.docroot.dir=" + _removeTrailingSlash(docrootDirName));

    args.add("sass.generate.source.map=" + isGenerateSourceMap());

    args.add("sass.output.dir=" + _addTrailingSlash(getOutputDirName()));

    String portalCommonPath = FileUtil.getAbsolutePath(getPortalCommonPath());

    args.add("sass.portal.common.path=" + portalCommonPath);

    args.add("sass.precision=" + getPrecision());

    String rtlExcludedPathRegexps = CollectionUtils.join(",", getRtlExcludedPathRegexps());

    args.add("sass.rtl.excluded.path.regexps=" + rtlExcludedPathRegexps);

    String sassCompilerClassName = getSassCompilerClassName();

    if (Validator.isNotNull(sassCompilerClassName)) {
      args.add("sass.compiler.class.name=" + sassCompilerClassName);
    }

    return args;
  }
Esempio n. 14
0
  private static List<Method> findAllMethodsInternal(
      Class<?> target,
      Spec<Method> predicate,
      MultiMap<String, Method> seen,
      List<Method> collector,
      boolean stopAtFirst) {
    for (final Method method : target.getDeclaredMethods()) {
      List<Method> seenWithName = seen.get(method.getName());
      Method override =
          CollectionUtils.findFirst(
              seenWithName,
              new Spec<Method>() {
                public boolean isSatisfiedBy(Method potentionOverride) {
                  return potentionOverride.getName().equals(method.getName())
                      && Arrays.equals(
                          potentionOverride.getParameterTypes(), method.getParameterTypes());
                }
              });

      if (override == null) {
        seenWithName.add(method);
        if (predicate.isSatisfiedBy(method)) {
          collector.add(method);
          if (stopAtFirst) {
            return collector;
          }
        }
      }
    }

    Class<?> parent = target.getSuperclass();
    if (parent != null) {
      return findAllMethodsInternal(parent, predicate, seen, collector, stopAtFirst);
    }

    return collector;
  }
 public static String getBuilderTypeDescriptionForCreatableTypes(
     Collection<? extends Class<?>> createableTypes) {
   StringBuilder sb = new StringBuilder(CollectionBuilder.class.getName());
   if (createableTypes.size() == 1) {
     @SuppressWarnings("ConstantConditions")
     String onlyType = Iterables.getFirst(createableTypes, null).getName();
     sb.append("<").append(onlyType).append(">");
   } else {
     sb.append("<T>; where T is one of [");
     Joiner.on(", ")
         .appendTo(
             sb,
             CollectionUtils.sort(
                 Iterables.transform(
                     createableTypes,
                     new Function<Class<?>, String>() {
                       public String apply(Class<?> input) {
                         return input.getName();
                       }
                     })));
     sb.append("]");
   }
   return sb.toString();
 }
 public ClassLoader createIsolatedClassLoader(Iterable<URI> uris) {
   return doCreateIsolatedClassLoader(CollectionUtils.collect(uris, Transformers.toURL()));
 }
Esempio n. 17
0
 public PatternSet excludeSpecs(Iterable<Spec<FileTreeElement>> excludes) {
   CollectionUtils.addAll(this.excludeSpecs, excludes);
   return this;
 }
Esempio n. 18
0
 @Override
 public TestLauncher withJvmTestMethods(String testClass, String... methods) {
   withJvmTestMethods(testClass, CollectionUtils.toList(methods));
   return this;
 }
Esempio n. 19
0
 @Override
 public TestLauncher withJvmTestClasses(Iterable<String> testClasses) {
   testClassNames.addAll(CollectionUtils.toList(testClasses));
   return this;
 }
Esempio n. 20
0
 @Override
 public TestLauncher withJvmTestClasses(String... classNames) {
   testClassNames.addAll(CollectionUtils.toList(classNames));
   return this;
 }
Esempio n. 21
0
 @Override
 public TestLauncher withTests(Iterable<? extends TestOperationDescriptor> descriptors) {
   operationDescriptors.addAll(CollectionUtils.toList(descriptors));
   return this;
 }
  public DaemonStartupInfo startDaemon() {
    String daemonUid = UUID.randomUUID().toString();

    GradleInstallation gradleInstallation = CurrentGradleInstallation.get();
    ModuleRegistry registry = new DefaultModuleRegistry(gradleInstallation);
    ClassPath classpath;
    List<File> searchClassPath;
    if (gradleInstallation == null) {
      // When not running from a Gradle distro, need runtime impl for launcher plus the search path
      // to look for other modules
      classpath = new DefaultClassPath();
      for (Module module : registry.getModule("gradle-launcher").getAllRequiredModules()) {
        classpath = classpath.plus(module.getClasspath());
      }
      searchClassPath = registry.getAdditionalClassPath().getAsFiles();
    } else {
      // When running from a Gradle distro, only need launcher jar. The daemon can find everything
      // from there.
      classpath = registry.getModule("gradle-launcher").getImplementationClasspath();
      searchClassPath = Collections.emptyList();
    }
    if (classpath.isEmpty()) {
      throw new IllegalStateException(
          "Unable to construct a bootstrap classpath when starting the daemon");
    }

    versionValidator.validate(daemonParameters);

    List<String> daemonArgs = new ArrayList<String>();
    daemonArgs.add(daemonParameters.getEffectiveJvm().getJavaExecutable().getAbsolutePath());

    List<String> daemonOpts = daemonParameters.getEffectiveJvmArgs();
    daemonArgs.addAll(daemonOpts);
    daemonArgs.add("-cp");
    daemonArgs.add(CollectionUtils.join(File.pathSeparator, classpath.getAsFiles()));

    if (Boolean.getBoolean("org.gradle.daemon.debug")) {
      daemonArgs.add("-Xdebug");
      daemonArgs.add("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005");
    }
    LOGGER.debug("Using daemon args: {}", daemonArgs);

    daemonArgs.add(GradleDaemon.class.getName());
    // Version isn't used, except by a human looking at the output of jps.
    daemonArgs.add(GradleVersion.current().getVersion());

    // Serialize configuration to daemon via the process' stdin
    ByteArrayOutputStream serializedConfig = new ByteArrayOutputStream();
    FlushableEncoder encoder =
        new KryoBackedEncoder(new EncodedStream.EncodedOutput(serializedConfig));
    try {
      encoder.writeString(daemonParameters.getGradleUserHomeDir().getAbsolutePath());
      encoder.writeString(daemonDir.getBaseDir().getAbsolutePath());
      encoder.writeSmallInt(daemonParameters.getIdleTimeout());
      encoder.writeString(daemonUid);
      encoder.writeSmallInt(daemonOpts.size());
      for (String daemonOpt : daemonOpts) {
        encoder.writeString(daemonOpt);
      }
      encoder.writeSmallInt(searchClassPath.size());
      for (File file : searchClassPath) {
        encoder.writeString(file.getAbsolutePath());
      }
      encoder.flush();
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
    ByteArrayInputStream stdInput = new ByteArrayInputStream(serializedConfig.toByteArray());

    DaemonStartupInfo daemonInfo = startProcess(daemonArgs, daemonDir.getVersionedDir(), stdInput);
    listener.daemonStarted(daemonInfo);
    return daemonInfo;
  }
Esempio n. 23
0
 private <T> void addAllReversed(List<T> list, TreeSet<T> set) {
   List<T> elements = CollectionUtils.toList(set);
   Collections.reverse(elements);
   list.addAll(elements);
 }