Search in sources :

Example 1 with Classpath

use of org.gradle.api.tasks.Classpath in project spring-boot by spring-projects.

the class CheckClasspathForConflicts method checkForConflicts.

@TaskAction
public void checkForConflicts() throws IOException {
    ClasspathContents classpathContents = new ClasspathContents();
    for (File file : this.classpath) {
        if (file.isDirectory()) {
            Path root = file.toPath();
            Files.walk(root).filter((path) -> Files.isRegularFile(path)).forEach((entry) -> classpathContents.add(root.relativize(entry).toString(), root.toString()));
        } else {
            try (JarFile jar = new JarFile(file)) {
                for (JarEntry entry : Collections.list(jar.entries())) {
                    if (!entry.isDirectory()) {
                        classpathContents.add(entry.getName(), file.getAbsolutePath());
                    }
                }
            }
        }
    }
    Map<String, List<String>> conflicts = classpathContents.getConflicts(this.ignores);
    if (!conflicts.isEmpty()) {
        StringBuilder message = new StringBuilder(String.format("Found classpath conflicts:%n"));
        conflicts.forEach((entry, locations) -> {
            message.append(String.format("    %s%n", entry));
            locations.forEach((location) -> message.append(String.format("        %s%n", location)));
        });
        throw new GradleException(message.toString());
    }
}
Also used : Path(java.nio.file.Path) Classpath(org.gradle.api.tasks.Classpath) Arrays(java.util.Arrays) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) JarFile(java.util.jar.JarFile) Collectors(java.util.stream.Collectors) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) JarEntry(java.util.jar.JarEntry) TaskAction(org.gradle.api.tasks.TaskAction) List(java.util.List) Task(org.gradle.api.Task) TreeMap(java.util.TreeMap) GradleException(org.gradle.api.GradleException) Map(java.util.Map) Entry(java.util.Map.Entry) DefaultTask(org.gradle.api.DefaultTask) Path(java.nio.file.Path) Collections(java.util.Collections) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) List(java.util.List) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) File(java.io.File) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with Classpath

use of org.gradle.api.tasks.Classpath in project gradle by gradle.

the class AbstractInputFilePropertyAnnotationHandler method visitPropertyValue.

@Override
public void visitPropertyValue(String propertyName, PropertyValue value, PropertyMetadata propertyMetadata, PropertyVisitor visitor, BeanPropertyContext context) {
    Annotation fileNormalization = propertyMetadata.getAnnotationForCategory(NORMALIZATION);
    Class<? extends FileNormalizer> fileNormalizer;
    if (fileNormalization == null) {
        fileNormalizer = null;
    } else if (fileNormalization instanceof PathSensitive) {
        PathSensitivity pathSensitivity = ((PathSensitive) fileNormalization).value();
        fileNormalizer = FileParameterUtils.determineNormalizerForPathSensitivity(pathSensitivity);
    } else if (fileNormalization instanceof Classpath) {
        fileNormalizer = ClasspathNormalizer.class;
    } else if (fileNormalization instanceof CompileClasspath) {
        fileNormalizer = CompileClasspathNormalizer.class;
    } else {
        throw new IllegalStateException("Unknown normalization annotation used: " + fileNormalization);
    }
    visitor.visitInputFileProperty(propertyName, propertyMetadata.isAnnotationPresent(Optional.class), propertyMetadata.isAnnotationPresent(SkipWhenEmpty.class), determineDirectorySensitivity(propertyMetadata), propertyMetadata.isAnnotationPresent(NormalizeLineEndings.class) ? LineEndingSensitivity.NORMALIZE_LINE_ENDINGS : LineEndingSensitivity.DEFAULT, propertyMetadata.isAnnotationPresent(Incremental.class), fileNormalizer, value, getFilePropertyType());
}
Also used : Incremental(org.gradle.work.Incremental) CompileClasspath(org.gradle.api.tasks.CompileClasspath) Optional(org.gradle.api.tasks.Optional) SkipWhenEmpty(org.gradle.api.tasks.SkipWhenEmpty) CompileClasspathNormalizer(org.gradle.api.tasks.CompileClasspathNormalizer) Classpath(org.gradle.api.tasks.Classpath) CompileClasspath(org.gradle.api.tasks.CompileClasspath) PathSensitivity(org.gradle.api.tasks.PathSensitivity) PathSensitive(org.gradle.api.tasks.PathSensitive) Annotation(java.lang.annotation.Annotation)

Aggregations

Classpath (org.gradle.api.tasks.Classpath)2 File (java.io.File)1 IOException (java.io.IOException)1 Annotation (java.lang.annotation.Annotation)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 Predicate (java.util.function.Predicate)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 Collectors (java.util.stream.Collectors)1