org.gradle.util.GUtil Java Examples

The following examples show how to use org.gradle.util.GUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultPersistentDirectoryCache.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public boolean requiresInitialization(FileLock lock) {
    if (!didRebuild) {
        if (validator!=null && !validator.isValid()) {
            LOGGER.debug("Invalidating {} as cache validator return false.", this);
            return true;
        }
    }

    if (!lock.getUnlockedCleanly()) {
        LOGGER.debug("Invalidating {} as it was not closed cleanly.", this);
        return true;
    }

    Properties currentProperties = GUtil.loadProperties(propertiesFile);
    for (Map.Entry<?, ?> entry : properties.entrySet()) {
        if (!entry.getValue().toString().equals(currentProperties.getProperty(entry.getKey().toString()))) {
            LOGGER.debug("Invalidating {} as cache property {} has changed value.", this, entry.getKey());
            return true;
        }
    }
    return false;
}
 
Example #2
Source File: JavadocExecHandleBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ExecAction getExecHandle() {
    try {
        options.write(optionsFile);
    } catch (IOException e) {
        throw new GradleException("Failed to store javadoc options.", e);
    }

    ExecAction execAction = execActionFactory.newExecAction();
    execAction.workingDir(execDirectory);
    execAction.executable(GUtil.elvis(executable, Jvm.current().getJavadocExecutable()));
    execAction.args("@" + optionsFile.getAbsolutePath());

    options.contributeCommandLineOptions(execAction);

    return execAction;
}
 
Example #3
Source File: TaskNameResolvingBuildConfigurationAction.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void configure(BuildExecutionContext context) {
    GradleInternal gradle = context.getGradle();
    List<String> taskNames = gradle.getStartParameter().getTaskNames();
    Multimap<String, Task> selectedTasks = commandLineTaskParser.parseTasks(taskNames, selector);

    TaskGraphExecuter executer = gradle.getTaskGraph();
    for (String name : selectedTasks.keySet()) {
        executer.addTasks(selectedTasks.get(name));
    }

    if (selectedTasks.keySet().size() == 1) {
        LOGGER.info("Selected primary task {}", GUtil.toString(selectedTasks.keySet()));
    } else {
        LOGGER.info("Selected primary tasks {}", GUtil.toString(selectedTasks.keySet()));
    }

    context.proceed();
}
 
Example #4
Source File: ProjectReportTask.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void render(final Project project, GraphRenderer renderer, boolean lastChild,
                    final StyledTextOutput textOutput) {
    renderer.visit(new Action<StyledTextOutput>() {
        public void execute(StyledTextOutput styledTextOutput) {
            styledTextOutput.text(StringUtils.capitalize(project.toString()));
            if (GUtil.isTrue(project.getDescription())) {
                textOutput.withStyle(Description).format(" - %s", project.getDescription());
            }
        }
    }, lastChild);
    renderer.startChildren();
    List<Project> children = getChildren(project);
    for (Project child : children) {
        render(child, renderer, child == children.get(children.size() - 1), textOutput);
    }
    renderer.completeChildren();
}
 
Example #5
Source File: ProjectPropertySettingBuildLoader.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void addPropertiesToProject(Project project) {
    Properties projectProperties = new Properties();
    File projectPropertiesFile = new File(project.getProjectDir(), Project.GRADLE_PROPERTIES);
    LOGGER.debug("Looking for project properties from: {}", projectPropertiesFile);
    if (projectPropertiesFile.isFile()) {
        projectProperties = GUtil.loadProperties(projectPropertiesFile);
        LOGGER.debug("Adding project properties (if not overwritten by user properties): {}",
                projectProperties.keySet());
    } else {
        LOGGER.debug("project property file does not exists. We continue!");
    }
    
    Map<String, String> mergedProperties = propertiesLoader.mergeProperties(new HashMap(projectProperties));
    ExtraPropertiesExtension extraProperties = new DslObject(project).getExtensions().getExtraProperties();
    for (Map.Entry<String, String> entry: mergedProperties.entrySet()) {
        try {
            project.setProperty(entry.getKey(), entry.getValue());
        } catch (MissingPropertyException e) {
            if (!entry.getKey().equals(e.getProperty())) {
                throw e;
            }
            // Ignore and define as an extra property
            extraProperties.set(entry.getKey(), entry.getValue());
        }
    }
}
 
Example #6
Source File: DefaultLibraryResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private NativeLibraryBinary resolve(Set<? extends NativeLibraryBinary> candidates) {
    for (NativeLibraryBinary candidate : candidates) {
        if (flavor != null && !flavor.getName().equals(candidate.getFlavor().getName())) {
            continue;
        }
        if (platform != null && !platform.getName().equals(candidate.getTargetPlatform().getName())) {
            continue;
        }
        if (buildType != null && !buildType.getName().equals(candidate.getBuildType().getName())) {
            continue;
        }

        return candidate;
    }

    String typeName = GUtil.elvis(requirement.getLinkage(), "shared");
    throw new LibraryResolveException(String.format("No %s library binary available for library '%s' with [flavor: '%s', platform: '%s', buildType: '%s']",
            typeName, requirement.getLibraryName(), flavor.getName(), platform.getName(), buildType.getName()));
}
 
Example #7
Source File: TaskReportRenderer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void writeTask(TaskDetails task, String prefix) {
    getTextOutput().text(prefix);
    getTextOutput().withStyle(Identifier).text(task.getPath());
    if (GUtil.isTrue(task.getDescription())) {
        getTextOutput().withStyle(Description).format(" - %s", task.getDescription());
    }
    if (detail) {
        SortedSet<Path> sortedDependencies = new TreeSet<Path>();
        for (TaskDetails dependency : task.getDependencies()) {
            sortedDependencies.add(dependency.getPath());
        }
        if (sortedDependencies.size() > 0) {
            getTextOutput().withStyle(Info).format(" [%s]", CollectionUtils.join(", ", sortedDependencies));
        }
    }
    getTextOutput().println();
}
 
Example #8
Source File: ClassPageRenderer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected void renderFailures(SimpleHtmlWriter htmlWriter) throws IOException {
    for (TestResult test : getResults().getFailures()) {
        htmlWriter.startElement("div").attribute("class", "test")
            .startElement("a").attribute("name", test.getId().toString()).characters("").endElement() //browsers dont understand <a name="..."/>
            .startElement("h3").attribute("class", test.getStatusClass()).characters(test.getName()).endElement();
        for (TestFailure failure : test.getFailures()) {
            String message;
            if (GUtil.isTrue(failure.getMessage()) && !failure.getStackTrace().contains(failure.getMessage())) {
                message = failure.getMessage() + SystemProperties.getLineSeparator() + SystemProperties.getLineSeparator() + failure.getStackTrace();
            } else {
                message = failure.getStackTrace();
            }
            codePanelRenderer.render(message, htmlWriter);
        }
        htmlWriter.endElement();
    }
}
 
Example #9
Source File: FlatteningNotationParser.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Set<T> parseNotation(Object notation) {
    Set<T> out = new LinkedHashSet<T>();
    Collection notations = GUtil.collectionize(notation);
    for (Object n : notations) {
        out.add(delegate.parseNotation(n));
    }
    return out;
}
 
Example #10
Source File: GradlePluginLord.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static String getMessage(Throwable throwable) {
    String message = throwable.getMessage();
    if (!GUtil.isTrue(message)) {
        message = String.format("%s (no error message)", throwable.getClass().getName());
    }

    if (throwable.getCause() != null) {
        message += "\nCaused by: " + getMessage(throwable.getCause());
    }

    return message;
}
 
Example #11
Source File: TaskReportRenderer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void startTaskGroup(String taskGroup) {
    if (!GUtil.isTrue(taskGroup)) {
        addSubheading("Tasks");
    } else {
        addSubheading(StringUtils.capitalize(taskGroup) + " tasks");
    }
    currentProjectHasTasks = true;
}
 
Example #12
Source File: ListBackedFileSet.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public String getDisplayName() {
    switch (files.size()) {
        case 0:
            return "empty file collection";
        case 1:
            return String.format("file '%s'", files.iterator().next());
        default:
            return String.format("files %s", GUtil.toString(files));
    }
}
 
Example #13
Source File: DefaultGradlePropertiesLoader.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void addGradleProperties(Map<String, String> target, File... files) {
    for (File propertyFile : files) {
        if (propertyFile.isFile()) {
            Properties properties = GUtil.loadProperties(propertyFile);
            target.putAll(new HashMap(properties));
        }
    }
}
 
Example #14
Source File: BuildExceptionReporter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String getMessage(Throwable throwable) {
    String message = throwable.getMessage();
    if (GUtil.isTrue(message)) {
        return message;
    }
    return String.format("%s (no error message)", throwable.getClass().getName());
}
 
Example #15
Source File: DefaultArtifactRepositoryContainer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DependencyResolver addBefore(Object userDescription, final String afterResolverName, Closure configureClosure) {
    if (!GUtil.isTrue(afterResolverName)) {
        throw new InvalidUserDataException("You must specify afterResolverName");
    }
    DeprecationLogger.nagUserOfDiscontinuedMethod("ArtifactRepositoryContainer.addBefore()");
    final ArtifactRepository after = getByName(afterResolverName);
    return addCustomDependencyResolver(userDescription, configureClosure, new Action<ArtifactRepository>() {
        public void execute(ArtifactRepository repository) {
            DefaultArtifactRepositoryContainer.super.add(indexOf(after), repository);
        }
    });
}
 
Example #16
Source File: DefaultPersistentDirectoryCache.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void initialize(FileLock fileLock) {
    for (File file : getBaseDir().listFiles()) {
        if (fileLock.isLockFile(file) || file.equals(propertiesFile)) {
            continue;
        }
        GFileUtils.forceDelete(file);
    }
    if (initAction != null) {
        initAction.execute(DefaultPersistentDirectoryCache.this);
    }
    GUtil.saveProperties(properties, propertiesFile);
    didRebuild = true;
}
 
Example #17
Source File: DefaultSourceSet.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public String getTaskName(String verb, String target) {
    if (verb == null) {
        return StringUtils.uncapitalize(String.format("%s%s", getTaskBaseName(), StringUtils.capitalize(target)));
    }
    if (target == null) {
        return StringUtils.uncapitalize(String.format("%s%s", verb, GUtil.toCamelCase(name)));
    }
    return StringUtils.uncapitalize(String.format("%s%s%s", verb, getTaskBaseName(), StringUtils.capitalize(target)));
}
 
Example #18
Source File: TaskFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public TaskInternal createTask(Map<String, ?> args) {
    Map<String, Object> actualArgs = new HashMap<String, Object>(args);
    checkTaskArgsAndCreateDefaultValues(actualArgs);

    String name = actualArgs.get(Task.TASK_NAME).toString();
    if (!GUtil.isTrue(name)) {
        throw new InvalidUserDataException("The task name must be provided.");
    }

    Class<? extends TaskInternal> type = (Class) actualArgs.get(Task.TASK_TYPE);
    Boolean generateSubclass = Boolean.valueOf(actualArgs.get(GENERATE_SUBCLASS).toString());
    TaskInternal task = createTaskObject(project, type, name, generateSubclass);

    Object dependsOnTasks = actualArgs.get(Task.TASK_DEPENDS_ON);
    if (dependsOnTasks != null) {
        task.dependsOn(dependsOnTasks);
    }
    Object description = actualArgs.get(Task.TASK_DESCRIPTION);
    if (description != null) {
        task.setDescription(description.toString());
    }
    Object group = actualArgs.get(Task.TASK_GROUP);
    if (group != null) {
        task.setGroup(group.toString());
    }
    Object action = actualArgs.get(Task.TASK_ACTION);
    if (action instanceof Action) {
        Action<? super Task> taskAction = (Action<? super Task>) action;
        task.doFirst(taskAction);
    } else if (action != null) {
        Closure closure = (Closure) action;
        task.doFirst(closure);
    }

    return task;
}
 
Example #19
Source File: DefaultArtifactHandler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object methodMissing(String name, Object arg) {
    Object[] args = (Object[]) arg;
    Configuration configuration = configurationContainer.findByName(name);
    if (configuration == null) {
        throw new MissingMethodException(name, this.getClass(), args);
    }
    List<Object> normalizedArgs = GUtil.flatten(Arrays.asList(args), false);
    if (normalizedArgs.size() == 2 && normalizedArgs.get(1) instanceof Closure) {
        return pushArtifact(configuration, normalizedArgs.get(0), (Closure) normalizedArgs.get(1));
    }
    for (Object notation : args) {
        pushArtifact(configuration, notation, null);
    }
    return null;
}
 
Example #20
Source File: TaskReportRenderer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void startTaskGroup(String taskGroup) {
    if (!GUtil.isTrue(taskGroup)) {
        addSubheading("Tasks");
    } else {
        addSubheading(StringUtils.capitalize(taskGroup) + " tasks");
    }
    currentProjectHasTasks = true;
}
 
Example #21
Source File: DefaultTestLogging.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private <T extends Enum<T>> T toEnum(Class<T> enumType, Object value) {
    if (enumType.isInstance(value)) {
        return enumType.cast(value);
    }
    if (value instanceof CharSequence) {
        return Enum.valueOf(enumType, GUtil.toConstant(value.toString()));
    }
    throw new IllegalArgumentException(String.format("Cannot convert value '%s' of type '%s' to enum type '%s'",
            value, value.getClass(), enumType));
}
 
Example #22
Source File: BasicTemplateBasedProjectInitDescriptor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public BasicTemplateBasedProjectInitDescriptor(TemplateOperationFactory templateOperationFactory , TemplateOperation settingsTemplateOperation) {
    register(settingsTemplateOperation);
    register(templateOperationFactory.newTemplateOperation()
                    .withTemplate("build.gradle.template")
                    .withTarget("build.gradle")
                    .withDocumentationBindings(GUtil.map("ref_userguide_java_tutorial", "tutorial_java_projects"))
                    .create()
    );
}
 
Example #23
Source File: ProjectView.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Instantiates an immutable view of a project. This is only meant to be called internally whenever generating a hierarchy of projects and tasks.
 */
/*package*/ ProjectView(ProjectView parentProject, String name, File buildFile, String description) {
    this.parentProject = parentProject;
    this.name = name;
    this.buildFile = buildFile;
    this.description = GUtil.elvis(description, "");
    if (parentProject != null) {
        parentProject.addSubProject(this);
    }
}
 
Example #24
Source File: DefaultExcludeRuleConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultExcludeRule createExcludeRule(String configurationName, ExcludeRule excludeRule) {
    String org = GUtil.elvis(excludeRule.getGroup(), PatternMatcher.ANY_EXPRESSION);
    String module = GUtil.elvis(excludeRule.getModule(), PatternMatcher.ANY_EXPRESSION);
    DefaultExcludeRule ivyExcludeRule = new DefaultExcludeRule(new ArtifactId(
            IvyUtil.createModuleId(org, module), PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION,
            PatternMatcher.ANY_EXPRESSION),
            ExactPatternMatcher.INSTANCE, null);
    ivyExcludeRule.addConfiguration(configurationName);
    return ivyExcludeRule;
}
 
Example #25
Source File: DefaultMavenPublication.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public String determinePackagingFromArtifacts() {
    for (MavenArtifact mavenArtifact : mavenArtifacts) {
        if (!GUtil.isTrue(mavenArtifact.getClassifier()) && GUtil.isTrue(mavenArtifact.getExtension())) {
            return mavenArtifact.getExtension();
        }
    }
    return "pom";
}
 
Example #26
Source File: RunBuildAction.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public RunBuildAction(BuildActionExecuter<BuildActionParameters> executer, StartParameter startParameter, File currentDir, BuildClientMetaData clientMetaData, long startTime, Map<?, ?> systemProperties, Map<String, String> envVariables) {
    this.executer = executer;
    this.startParameter = startParameter;
    this.currentDir = currentDir;
    this.clientMetaData = clientMetaData;
    this.startTime = startTime;
    this.systemProperties = new HashMap<String, String>();
    GUtil.addToMap(this.systemProperties, systemProperties);
    this.envVariables = envVariables;
}
 
Example #27
Source File: DefaultTasksBuildExecutionAction.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void configure(BuildExecutionContext context) {
    StartParameter startParameter = context.getGradle().getStartParameter();

    for (TaskExecutionRequest request : startParameter.getTaskRequests()) {
        if (!request.getArgs().isEmpty()) {
            context.proceed();
            return;
        }
    }

    // Gather the default tasks from this first group project
    ProjectInternal project = context.getGradle().getDefaultProject();

    //so that we don't miss out default tasks
    projectConfigurer.configure(project);

    List<String> defaultTasks = project.getDefaultTasks();
    if (defaultTasks.size() == 0) {
        defaultTasks = Arrays.asList(ProjectInternal.HELP_TASK);
        LOGGER.info("No tasks specified. Using default task {}", GUtil.toString(defaultTasks));
    } else {
        LOGGER.info("No tasks specified. Using project default tasks {}", GUtil.toString(defaultTasks));
    }

    startParameter.setTaskNames(defaultTasks);
    context.proceed();
}
 
Example #28
Source File: DefaultWorkerProcessFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void attachStdInContent(WorkerFactory workerFactory, JavaExecHandleBuilder javaCommand) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    OutputStream encoded = new EncodedStream.EncodedOutput(bytes);
    GUtil.serialize(workerFactory.create(), encoded);
    ByteArrayInputStream stdinContent = new ByteArrayInputStream(bytes.toByteArray());
    javaCommand.setStandardInput(stdinContent);
}
 
Example #29
Source File: ListBackedFileSet.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public String getDisplayName() {
    switch (files.size()) {
        case 0:
            return "empty file collection";
        case 1:
            return String.format("file '%s'", files.iterator().next());
        default:
            return String.format("files %s", GUtil.toString(files));
    }
}
 
Example #30
Source File: DefaultTestLogging.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private <T extends Enum<T>> T toEnum(Class<T> enumType, Object value) {
    if (enumType.isInstance(value)) {
        return enumType.cast(value);
    }
    if (value instanceof CharSequence) {
        return Enum.valueOf(enumType, GUtil.toConstant(value.toString()));
    }
    throw new IllegalArgumentException(String.format("Cannot convert value '%s' of type '%s' to enum type '%s'",
            value, value.getClass(), enumType));
}