Search in sources :

Example 11 with Spec

use of org.gradle.api.specs.Spec in project gradle by gradle.

the class PCHCompileTaskConfig method configureCompileTask.

@Override
protected void configureCompileTask(AbstractNativeCompileTask task, final NativeBinarySpecInternal binary, final LanguageSourceSetInternal languageSourceSet) {
    // Note that the sourceSet is the sourceSet this pre-compiled header will be used with - it's not an
    // input sourceSet to the compile task.
    final DependentSourceSetInternal sourceSet = (DependentSourceSetInternal) languageSourceSet;
    task.setDescription("Compiles a pre-compiled header for the " + sourceSet + " of " + binary);
    // Add the source of the source set to the include paths to resolve any headers that may be in source directories
    task.includes(sourceSet.getSource().getSourceDirectories());
    final Project project = task.getProject();
    task.source(sourceSet.getPrefixHeaderFile());
    task.getObjectFileDir().set(new File(binary.getNamingScheme().getOutputDirectory(project.getBuildDir(), "objs"), languageSourceSet.getProjectScopedName() + "PCH"));
    task.dependsOn(project.getTasks().withType(PrefixHeaderFileGenerateTask.class).matching(new Spec<PrefixHeaderFileGenerateTask>() {

        @Override
        public boolean isSatisfiedBy(PrefixHeaderFileGenerateTask prefixHeaderFileGenerateTask) {
            return prefixHeaderFileGenerateTask.getPrefixHeaderFile().equals(sourceSet.getPrefixHeaderFile());
        }
    }));
    // This is so that VisualCpp has the object file of the generated source file available at link time
    binary.binaryInputs(task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.obj", "**/*.o")));
    PreCompiledHeader pch = binary.getPrefixFileToPCH().get(sourceSet.getPrefixHeaderFile());
    pch.setPchObjects(task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.pch", "**/*.gch")));
    pch.builtBy(task);
}
Also used : Project(org.gradle.api.Project) PrefixHeaderFileGenerateTask(org.gradle.nativeplatform.tasks.PrefixHeaderFileGenerateTask) PreCompiledHeader(org.gradle.nativeplatform.toolchain.internal.PreCompiledHeader) Spec(org.gradle.api.specs.Spec) File(java.io.File) PatternSet(org.gradle.api.tasks.util.PatternSet)

Example 12 with Spec

use of org.gradle.api.specs.Spec in project gradle by gradle.

the class DefaultMethodRuleDefinition method reference.

private ModelReference<?> reference(List<Annotation> annotations, int i) {
    Path pathAnnotation = (Path) findFirst(annotations, new Spec<Annotation>() {

        @Override
        public boolean isSatisfiedBy(Annotation element) {
            return element.annotationType().equals(Path.class);
        }
    });
    ModelPath path = pathAnnotation == null ? null : ModelPath.path(pathAnnotation.value());
    ModelType<?> cast = method.getGenericParameterTypes().get(i);
    return ModelReference.of(path, cast, PARAMETER_DESC[i]);
}
Also used : Path(org.gradle.model.Path) ModelPath(org.gradle.model.internal.core.ModelPath) ModelPath(org.gradle.model.internal.core.ModelPath) Spec(org.gradle.api.specs.Spec) Annotation(java.lang.annotation.Annotation)

Example 13 with Spec

use of org.gradle.api.specs.Spec in project gradle by gradle.

the class AvailableToolChains method findSwiftcs.

static List<ToolChainCandidate> findSwiftcs() {
    List<ToolChainCandidate> toolChains = Lists.newArrayList();
    SwiftcMetadataProvider versionDeterminer = new SwiftcMetadataProvider(TestFiles.execActionFactory());
    // On Linux, we assume swift is installed into /opt/swift
    File rootSwiftInstall = new File("/opt/swift");
    File[] swiftCandidates = GUtil.getOrDefault(rootSwiftInstall.listFiles(swiftInstall -> swiftInstall.isDirectory() && !swiftInstall.getName().equals("latest")), () -> new File[0]);
    for (File swiftInstall : swiftCandidates) {
        File swiftc = new File(swiftInstall, "/usr/bin/swiftc");
        SearchResult<SwiftcMetadata> version = versionDeterminer.getCompilerMetaData(Collections.emptyList(), spec -> spec.executable(swiftc));
        if (version.isAvailable()) {
            File binDir = swiftc.getParentFile();
            toolChains.add(new InstalledSwiftc(binDir, version.getComponent().getVersion()).inPath(binDir, new File("/usr/bin")));
        }
    }
    // On macOS, we assume co-located Xcode is installed into /opt/xcode and default location at /Applications/Xcode.app
    toolChains.addAll(findXcodes().stream().map(InstalledXcode::getSwiftc).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()));
    List<File> swiftcCandidates = OperatingSystem.current().findAllInPath("swiftc");
    for (File candidate : swiftcCandidates) {
        SearchResult<SwiftcMetadata> version = versionDeterminer.getCompilerMetaData(Collections.emptyList(), spec -> spec.executable(candidate));
        if (version.isAvailable()) {
            File binDir = candidate.getParentFile();
            InstalledSwiftc swiftc = new InstalledSwiftc(binDir, version.getComponent().getVersion());
            swiftc.inPath(binDir, new File("/usr/bin"));
            toolChains.add(swiftc);
        }
    }
    if (toolChains.isEmpty()) {
        toolChains.add(new UnavailableToolChain(ToolFamily.SWIFTC));
    } else {
        toolChains.sort(LATEST_RELEASED_FIRST);
    }
    return toolChains;
}
Also used : VisualStudioLocatorTestFixture(org.gradle.nativeplatform.fixtures.msvcpp.VisualStudioLocatorTestFixture) CollectionUtils(org.gradle.util.internal.CollectionUtils) Arrays(java.util.Arrays) GradleExecuter(org.gradle.integtests.fixtures.executer.GradleExecuter) MicrosoftVisualCppCompilerPlugin(org.gradle.nativeplatform.toolchain.plugins.MicrosoftVisualCppCompilerPlugin) TestFiles(org.gradle.api.internal.file.TestFiles) VisualCpp(org.gradle.nativeplatform.toolchain.VisualCpp) SwiftcMetadata(org.gradle.nativeplatform.toolchain.internal.swift.metadata.SwiftcMetadata) GccMetadataProvider(org.gradle.nativeplatform.toolchain.internal.gcc.metadata.GccMetadataProvider) ProcessEnvironment(org.gradle.internal.nativeintegration.ProcessEnvironment) SwiftCompilerPlugin(org.gradle.nativeplatform.toolchain.plugins.SwiftCompilerPlugin) ArrayList(java.util.ArrayList) GccCompilerPlugin(org.gradle.nativeplatform.toolchain.plugins.GccCompilerPlugin) GUtil(org.gradle.util.internal.GUtil) SearchResult(org.gradle.platform.base.internal.toolchain.SearchResult) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) Lists(com.google.common.collect.Lists) Swiftc(org.gradle.nativeplatform.toolchain.Swiftc) Matcher(java.util.regex.Matcher) ImmutableList(com.google.common.collect.ImmutableList) Gcc(org.gradle.nativeplatform.toolchain.Gcc) VersionedTool(org.gradle.integtests.fixtures.VersionedTool) VersionNumber(org.gradle.util.internal.VersionNumber) VisualStudioInstall(org.gradle.nativeplatform.toolchain.internal.msvcpp.VisualStudioInstall) VisualStudioVersion(org.gradle.nativeplatform.fixtures.msvcpp.VisualStudioVersion) Nullable(javax.annotation.Nullable) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) NativeServicesTestFixture(org.gradle.testfixtures.internal.NativeServicesTestFixture) Clang(org.gradle.nativeplatform.toolchain.Clang) GccMetadata(org.gradle.nativeplatform.toolchain.internal.gcc.metadata.GccMetadata) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) OperatingSystem(org.gradle.internal.os.OperatingSystem) ClangCompilerPlugin(org.gradle.nativeplatform.toolchain.plugins.ClangCompilerPlugin) List(java.util.List) Spec(org.gradle.api.specs.Spec) Optional(java.util.Optional) TestFile(org.gradle.test.fixtures.file.TestFile) Pattern(java.util.regex.Pattern) SwiftcMetadataProvider(org.gradle.nativeplatform.toolchain.internal.swift.metadata.SwiftcMetadataProvider) Comparator(java.util.Comparator) Collections(java.util.Collections) Joiner(com.google.common.base.Joiner) Optional(java.util.Optional) SwiftcMetadataProvider(org.gradle.nativeplatform.toolchain.internal.swift.metadata.SwiftcMetadataProvider) SwiftcMetadata(org.gradle.nativeplatform.toolchain.internal.swift.metadata.SwiftcMetadata) File(java.io.File) TestFile(org.gradle.test.fixtures.file.TestFile)

Example 14 with Spec

use of org.gradle.api.specs.Spec in project gradle by gradle.

the class DefaultCopySpec method filesNotMatching.

public CopySpec filesNotMatching(Iterable<String> patterns, Action<? super FileCopyDetails> action) {
    if (!patterns.iterator().hasNext()) {
        throw new InvalidUserDataException("must provide at least one pattern to not match");
    }
    List<Spec> matchers = new ArrayList<Spec>();
    for (String pattern : patterns) {
        matchers.add(PatternMatcherFactory.getPatternMatcher(true, isCaseSensitive(), pattern));
    }
    Spec unionMatcher = Specs.union(matchers.toArray(new Spec[matchers.size()]));
    return eachFile(new MatchingCopyAction(Specs.<RelativePath>negate(unionMatcher), action));
}
Also used : RelativePath(org.gradle.api.file.RelativePath) InvalidUserDataException(org.gradle.api.InvalidUserDataException) ArrayList(java.util.ArrayList) CopySpec(org.gradle.api.file.CopySpec) CopyProcessingSpec(org.gradle.api.file.CopyProcessingSpec) Spec(org.gradle.api.specs.Spec)

Example 15 with Spec

use of org.gradle.api.specs.Spec in project gradle by gradle.

the class DefaultDomainObjectCollectionTest method filteredCollectionExecutesClosureWhenMatchingObjectAdded.

@Test
public void filteredCollectionExecutesClosureWhenMatchingObjectAdded() {
    final TestClosure closure = context.mock(TestClosure.class);
    context.checking(new Expectations() {

        {
            oneOf(closure).call("a");
        }
    });
    Spec<CharSequence> spec = new Spec<CharSequence>() {

        public boolean isSatisfiedBy(CharSequence element) {
            return !element.equals("b");
        }
    };
    container.matching(spec).whenObjectAdded(TestUtil.toClosure(closure));
    container.add("a");
    container.add("b");
}
Also used : TestClosure(org.gradle.util.TestClosure) Expectations(org.jmock.Expectations) Spec(org.gradle.api.specs.Spec) Test(org.junit.Test)

Aggregations

Spec (org.gradle.api.specs.Spec)25 Test (org.junit.Test)8 Task (org.gradle.api.Task)7 File (java.io.File)6 Project (org.gradle.api.Project)4 TestClosure (org.gradle.util.TestClosure)4 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 Expectations (org.jmock.Expectations)3 Callable (java.util.concurrent.Callable)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Usage (org.gradle.api.attributes.Usage)2 FileTreeElement (org.gradle.api.file.FileTreeElement)2 TaskInternal (org.gradle.api.internal.TaskInternal)2 SourceSet (org.gradle.api.tasks.SourceSet)2 TaskAction (org.gradle.api.tasks.TaskAction)2 TaskContainer (org.gradle.api.tasks.TaskContainer)2 SdkConstants (com.android.SdkConstants)1 NonNull (com.android.annotations.NonNull)1