Search in sources :

Example 26 with Project

use of org.gradle.api.Project in project atlas by alibaba.

the class AppVariantContext method getAwSourceOutputDir.

public List<ConfigurableFileTree> getAwSourceOutputDir(AwbBundle awbBundle) {
    Project project = scope.getGlobalScope().getProject();
    // Build the list of source folders.
    ImmutableList.Builder<ConfigurableFileTree> sourceSets = ImmutableList.builder();
    // then all the generated src folders.
    if (getAwbRClassSourceOutputDir(awbBundle) != null) {
        sourceSets.add(project.fileTree(getAwbRClassSourceOutputDir(awbBundle)));
    }
    if (scope.getGlobalScope().getExtension().getDataBinding().isEnabled()) {
        sourceSets.add(project.fileTree(getAwbClassOutputForDataBinding(awbBundle)));
    }
    return sourceSets.build();
}
Also used : Project(org.gradle.api.Project) ImmutableList(com.google.common.collect.ImmutableList) ConfigurableFileTree(org.gradle.api.file.ConfigurableFileTree)

Example 27 with Project

use of org.gradle.api.Project in project intellij-community by JetBrains.

the class ModelBuildScriptClasspathBuilderImpl method buildAll.

@Nullable
@Override
public Object buildAll(final String modelName, final Project project) {
    BuildScriptClasspathModelImpl buildScriptClasspath = cache.get(project.getPath());
    if (buildScriptClasspath != null)
        return buildScriptClasspath;
    if (mySourceSetFinder == null)
        mySourceSetFinder = new SourceSetCachedFinder(project);
    buildScriptClasspath = new BuildScriptClasspathModelImpl();
    final File gradleHomeDir = project.getGradle().getGradleHomeDir();
    buildScriptClasspath.setGradleHomeDir(gradleHomeDir);
    buildScriptClasspath.setGradleVersion(GradleVersion.current().getVersion());
    boolean downloadJavadoc = false;
    boolean downloadSources = true;
    final IdeaPlugin ideaPlugin = project.getPlugins().findPlugin(IdeaPlugin.class);
    if (ideaPlugin != null) {
        final IdeaModule ideaModule = ideaPlugin.getModel().getModule();
        downloadJavadoc = ideaModule.isDownloadJavadoc();
        downloadSources = ideaModule.isDownloadSources();
    }
    Project parent = project.getParent();
    if (parent != null) {
        BuildScriptClasspathModelImpl parentBuildScriptClasspath = (BuildScriptClasspathModelImpl) buildAll(modelName, parent);
        if (parentBuildScriptClasspath != null) {
            for (ClasspathEntryModel classpathEntryModel : parentBuildScriptClasspath.getClasspath()) {
                buildScriptClasspath.add(classpathEntryModel);
            }
        }
    }
    Configuration classpathConfiguration = project.getBuildscript().getConfigurations().findByName(CLASSPATH_CONFIGURATION_NAME);
    if (classpathConfiguration == null)
        return null;
    Collection<ExternalDependency> dependencies = new DependencyResolverImpl(project, false, downloadJavadoc, downloadSources, mySourceSetFinder).resolveDependencies(classpathConfiguration);
    for (ExternalDependency dependency : new DependencyTraverser(dependencies)) {
        if (dependency instanceof ExternalLibraryDependency) {
            final ExternalLibraryDependency libraryDep = (ExternalLibraryDependency) dependency;
            buildScriptClasspath.add(new ClasspathEntryModelImpl(pathSet(libraryDep.getFile()), pathSet(libraryDep.getSource()), pathSet(libraryDep.getJavadoc())));
        }
        if (dependency instanceof ExternalMultiLibraryDependency) {
            ExternalMultiLibraryDependency multiLibraryDependency = (ExternalMultiLibraryDependency) dependency;
            buildScriptClasspath.add(new ClasspathEntryModelImpl(pathSet(multiLibraryDependency.getFiles()), pathSet(multiLibraryDependency.getSources()), pathSet(multiLibraryDependency.getJavadoc())));
        }
        if (dependency instanceof FileCollectionDependency) {
            FileCollectionDependency fileCollectionDependency = (FileCollectionDependency) dependency;
            buildScriptClasspath.add(new ClasspathEntryModelImpl(pathSet(fileCollectionDependency.getFiles()), new HashSet<String>(), new HashSet<String>()));
        }
    }
    cache.put(project.getPath(), buildScriptClasspath);
    return buildScriptClasspath;
}
Also used : BuildScriptClasspathModelImpl(org.jetbrains.plugins.gradle.tooling.internal.BuildScriptClasspathModelImpl) Configuration(org.gradle.api.artifacts.Configuration) IdeaPlugin(org.gradle.plugins.ide.idea.IdeaPlugin) SourceSetCachedFinder(org.jetbrains.plugins.gradle.tooling.util.SourceSetCachedFinder) DependencyTraverser(org.jetbrains.plugins.gradle.tooling.util.DependencyTraverser) ClasspathEntryModelImpl(org.jetbrains.plugins.gradle.tooling.internal.ClasspathEntryModelImpl) Project(org.gradle.api.Project) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) DependencyResolverImpl(org.jetbrains.plugins.gradle.tooling.util.DependencyResolverImpl) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 28 with Project

use of org.gradle.api.Project in project meecrowave by apache.

the class MeecrowaveTask method fixConfig.

private void fixConfig() {
    final Project project = getProject();
    // defaults
    if (classpath == null) {
        classpath = project.getConfigurations().getByName(MeecrowavePlugin.NAME);
    }
    if (dir == null) {
        dir = new File(project.getBuildDir(), "meecrowave/run").getAbsolutePath();
    }
    // extension override
    final MeecrowaveExtension extension = MeecrowaveExtension.class.cast(project.getExtensions().findByName(MeecrowavePlugin.NAME));
    if (extension != null) {
        for (final Field f : MeecrowaveTask.class.getDeclaredFields()) {
            if (f.isAnnotationPresent(Input.class)) {
                try {
                    final Field extField = MeecrowaveExtension.class.getDeclaredField(f.getName());
                    if (!extField.isAccessible()) {
                        extField.setAccessible(true);
                    }
                    final Object val = extField.get(extension);
                    if (val != null) {
                        if (!f.isAccessible()) {
                            f.setAccessible(true);
                        }
                        f.set(this, val);
                    }
                } catch (final IllegalAccessException | NoSuchFieldException e) {
                    getLogger().debug("No field " + f.getName() + " in " + extension, e);
                }
            }
        }
    }
}
Also used : Project(org.gradle.api.Project) Field(java.lang.reflect.Field) File(java.io.File)

Example 29 with Project

use of org.gradle.api.Project in project gradle by gradle.

the class XCTestConventionPlugin method apply.

@Override
public void apply(ProjectInternal project) {
    project.getPluginManager().apply(SwiftBasePlugin.class);
    project.getPluginManager().apply(NativeTestingBasePlugin.class);
    // Create test suite component
    final DefaultSwiftXCTestSuite testComponent = createTestSuite(project);
    project.afterEvaluate(new Action<Project>() {

        @Override
        public void execute(final Project project) {
            String operatingSystemSuffix = "";
            OperatingSystemFamily operatingSystem = objectFactory.named(OperatingSystemFamily.class, DefaultNativePlatform.getCurrentOperatingSystem().toFamilyName());
            Usage runtimeUsage = objectFactory.named(Usage.class, Usage.NATIVE_RUNTIME);
            Provider<String> group = project.provider(new Callable<String>() {

                @Override
                public String call() throws Exception {
                    return project.getGroup().toString();
                }
            });
            Provider<String> version = project.provider(new Callable<String>() {

                @Override
                public String call() throws Exception {
                    return project.getVersion().toString();
                }
            });
            AttributeContainer attributesDebug = attributesFactory.mutable();
            attributesDebug.attribute(Usage.USAGE_ATTRIBUTE, runtimeUsage);
            attributesDebug.attribute(DEBUGGABLE_ATTRIBUTE, true);
            attributesDebug.attribute(OPTIMIZED_ATTRIBUTE, false);
            NativeVariantIdentity debugVariant = new NativeVariantIdentity("debug" + operatingSystemSuffix, testComponent.getModule(), group, version, true, false, operatingSystem, null, new DefaultUsageContext("debug" + operatingSystemSuffix + "-runtime", runtimeUsage, attributesDebug));
            ToolChainSelector.Result<SwiftPlatform> result = toolChainSelector.select(SwiftPlatform.class);
            // Create test suite executable
            DefaultSwiftXCTestBinary binary;
            if (result.getTargetPlatform().getOperatingSystem().isMacOsX()) {
                binary = (DefaultSwiftXCTestBinary) testComponent.addBundle("executable", debugVariant, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
            } else {
                binary = (DefaultSwiftXCTestBinary) testComponent.addExecutable("executable", debugVariant, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
            }
            testComponent.getTestBinary().set(binary);
            // TODO: Publishing for test executable?
            final ProductionSwiftComponent mainComponent = project.getComponents().withType(ProductionSwiftComponent.class).findByName("main");
            if (mainComponent != null) {
                testComponent.getTestedComponent().set(mainComponent);
                // Test configuration extends main configuration
                testComponent.getImplementationDependencies().extendsFrom(mainComponent.getImplementationDependencies());
                project.getDependencies().add(binary.getImportPathConfiguration().getName(), project);
            }
            testComponent.getBinaries().whenElementKnown(DefaultSwiftXCTestBinary.class, new Action<DefaultSwiftXCTestBinary>() {

                @Override
                public void execute(DefaultSwiftXCTestBinary binary) {
                    // Create test suite test task
                    XCTest testingTask = createTestingTask(project);
                    binary.getRunTask().set(testingTask);
                    // Configure tasks
                    configureTestingTask(binary, testingTask);
                    configureTestSuiteBuildingTasks((ProjectInternal) project, binary);
                    configureTestSuiteWithTestedComponentWhenAvailable(project, testComponent, binary);
                }
            });
            testComponent.getBinaries().realizeNow();
        }
    });
}
Also used : OperatingSystemFamily(org.gradle.nativeplatform.OperatingSystemFamily) Usage(org.gradle.api.attributes.Usage) Action(org.gradle.api.Action) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) AttributeContainer(org.gradle.api.attributes.AttributeContainer) NativeVariantIdentity(org.gradle.language.cpp.internal.NativeVariantIdentity) Callable(java.util.concurrent.Callable) Provider(org.gradle.api.provider.Provider) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) Project(org.gradle.api.Project) DefaultSwiftXCTestBinary(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBinary) DefaultUsageContext(org.gradle.language.cpp.internal.DefaultUsageContext) DefaultSwiftXCTestSuite(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestSuite) SwiftPlatform(org.gradle.language.swift.SwiftPlatform) XCTest(org.gradle.nativeplatform.test.xctest.tasks.XCTest)

Example 30 with Project

use of org.gradle.api.Project in project gradle by gradle.

the class DefaultTaskExecutionPlan method determineExecutionPlan.

public void determineExecutionPlan() {
    List<TaskInfoInVisitingSegment> nodeQueue = Lists.newArrayList(Iterables.transform(entryTasks, new Function<TaskInfo, TaskInfoInVisitingSegment>() {

        int index;

        public TaskInfoInVisitingSegment apply(TaskInfo taskInfo) {
            return new TaskInfoInVisitingSegment(taskInfo, index++);
        }
    }));
    int visitingSegmentCounter = nodeQueue.size();
    HashMultimap<TaskInfo, Integer> visitingNodes = HashMultimap.create();
    Deque<GraphEdge> walkedShouldRunAfterEdges = new ArrayDeque<GraphEdge>();
    Deque<TaskInfo> path = new ArrayDeque<TaskInfo>();
    HashMap<TaskInfo, Integer> planBeforeVisiting = new HashMap<TaskInfo, Integer>();
    while (!nodeQueue.isEmpty()) {
        TaskInfoInVisitingSegment taskInfoInVisitingSegment = nodeQueue.get(0);
        int currentSegment = taskInfoInVisitingSegment.visitingSegment;
        TaskInfo taskNode = taskInfoInVisitingSegment.taskInfo;
        if (taskNode.isIncludeInGraph() || executionPlan.containsKey(taskNode.getTask())) {
            nodeQueue.remove(0);
            visitingNodes.remove(taskNode, currentSegment);
            maybeRemoveProcessedShouldRunAfterEdge(walkedShouldRunAfterEdges, taskNode);
            continue;
        }
        boolean alreadyVisited = visitingNodes.containsKey(taskNode);
        visitingNodes.put(taskNode, currentSegment);
        if (!alreadyVisited) {
            // Have not seen this task before - add its dependencies to the head of the queue and leave this
            // task in the queue
            recordEdgeIfArrivedViaShouldRunAfter(walkedShouldRunAfterEdges, path, taskNode);
            removeShouldRunAfterSuccessorsIfTheyImposeACycle(visitingNodes, taskInfoInVisitingSegment);
            takePlanSnapshotIfCanBeRestoredToCurrentTask(planBeforeVisiting, taskNode);
            ArrayList<TaskInfo> successors = new ArrayList<TaskInfo>();
            addAllSuccessorsInReverseOrder(taskNode, successors);
            for (TaskInfo successor : successors) {
                if (visitingNodes.containsEntry(successor, currentSegment)) {
                    if (!walkedShouldRunAfterEdges.isEmpty()) {
                        // remove the last walked should run after edge and restore state from before walking it
                        GraphEdge toBeRemoved = walkedShouldRunAfterEdges.pop();
                        toBeRemoved.from.removeShouldRunAfterSuccessor(toBeRemoved.to);
                        restorePath(path, toBeRemoved);
                        restoreQueue(nodeQueue, visitingNodes, toBeRemoved);
                        restoreExecutionPlan(planBeforeVisiting, toBeRemoved);
                        break;
                    } else {
                        onOrderingCycle();
                    }
                }
                nodeQueue.add(0, new TaskInfoInVisitingSegment(successor, currentSegment));
            }
            path.push(taskNode);
        } else {
            // Have visited this task's dependencies - add it to the end of the plan
            nodeQueue.remove(0);
            maybeRemoveProcessedShouldRunAfterEdge(walkedShouldRunAfterEdges, taskNode);
            visitingNodes.remove(taskNode, currentSegment);
            path.pop();
            executionPlan.put(taskNode.getTask(), taskNode);
            Project project = taskNode.getTask().getProject();
            projectLocks.put(project, getOrCreateProjectLock(project));
            TaskMutationInfo taskMutationInfo = getOrCreateMutationsOf(taskNode);
            for (TaskInfo dependency : taskNode.getDependencySuccessors()) {
                getOrCreateMutationsOf(dependency).consumingTasks.add(taskNode);
                taskMutationInfo.consumesOutputOf.add(dependency);
            }
            // Add any finalizers to the queue
            ArrayList<TaskInfo> finalizerTasks = new ArrayList<TaskInfo>();
            addAllReversed(finalizerTasks, taskNode.getFinalizers());
            for (TaskInfo finalizer : finalizerTasks) {
                if (!visitingNodes.containsKey(finalizer)) {
                    nodeQueue.add(finalizerTaskPosition(finalizer, nodeQueue), new TaskInfoInVisitingSegment(finalizer, visitingSegmentCounter++));
                }
            }
        }
    }
    executionQueue.clear();
    executionQueue.addAll(executionPlan.values());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ArrayDeque(java.util.ArrayDeque) Function(com.google.common.base.Function) Project(org.gradle.api.Project)

Aggregations

Project (org.gradle.api.Project)93 File (java.io.File)20 Task (org.gradle.api.Task)12 Action (org.gradle.api.Action)11 Configuration (org.gradle.api.artifacts.Configuration)11 Set (java.util.Set)8 Callable (java.util.concurrent.Callable)8 TaskAction (org.gradle.api.tasks.TaskAction)8 DefaultGradleProject (org.gradle.tooling.internal.gradle.DefaultGradleProject)8 Provider (org.gradle.api.provider.Provider)7 ArrayList (java.util.ArrayList)6 AttributeContainer (org.gradle.api.attributes.AttributeContainer)6 Usage (org.gradle.api.attributes.Usage)6 Gradle (org.gradle.api.invocation.Gradle)6 StyledTextOutput (org.gradle.internal.logging.text.StyledTextOutput)6 DefaultUsageContext (org.gradle.language.cpp.internal.DefaultUsageContext)6 NativeVariantIdentity (org.gradle.language.cpp.internal.NativeVariantIdentity)6 OperatingSystemFamily (org.gradle.nativeplatform.OperatingSystemFamily)6 FileCollection (org.gradle.api.file.FileCollection)4 IdeaProject (org.gradle.plugins.ide.idea.model.IdeaProject)4