Search in sources :

Example 11 with VersionNumber

use of org.gradle.util.VersionNumber in project gradle by gradle.

the class GroovySystemLoaderFactory method forClassLoader.

public GroovySystemLoader forClassLoader(ClassLoader classLoader) {
    try {
        Class<?> groovySystem;
        try {
            groovySystem = classLoader.loadClass("groovy.lang.GroovySystem");
        } catch (ClassNotFoundException e) {
            // Not a Groovy implementation, or not an implementation that we need to deal with
            return NOT_BROKEN;
        }
        if (groovySystem.getClassLoader() != classLoader) {
            // Groovy implementation visible from somewhere else
            return NOT_BROKEN;
        }
        String versionString;
        try {
            Method getVersion = groovySystem.getDeclaredMethod("getVersion");
            versionString = (String) getVersion.invoke(null);
        } catch (NoSuchMethodException ex) {
            return NOT_BROKEN;
        }
        VersionNumber groovyVersion = VersionNumber.parse(versionString);
        boolean isFaultyGroovy = groovyVersion.getMajor() == 2 && groovyVersion.getMinor() == 4;
        return isFaultyGroovy ? new LeakyOnJava7GroovySystemLoader(classLoader) : NOT_BROKEN;
    } catch (Exception e) {
        throw new GradleException("Could not inspect the Groovy system for ClassLoader " + classLoader, e);
    }
}
Also used : GradleException(org.gradle.api.GradleException) Method(java.lang.reflect.Method) VersionNumber(org.gradle.util.VersionNumber) GradleException(org.gradle.api.GradleException)

Example 12 with VersionNumber

use of org.gradle.util.VersionNumber in project gradle by gradle.

the class DefaultUcrtLocator method locateUserSpecifiedUcrt.

private SearchResult locateUserSpecifiedUcrt(File candidate) {
    File ucrtDir = FileUtils.canonicalize(candidate);
    String[] versionDirs = getUcrtVersionDirs(ucrtDir);
    if (versionDirs.length > 0) {
        for (String versionDir : versionDirs) {
            VersionNumber version = VersionNumber.withPatchNumber().parse(versionDir);
            LOGGER.debug("Found ucrt {} ({}) at {}", version.toString(), versionDir, ucrtDir);
            if (!foundUcrts.containsKey(ucrtDir)) {
                putUcrt(new Ucrt(ucrtDir, NAME_USER, version));
            }
        }
        return new UcrtFound(getBestUcrt(candidate));
    } else {
        return new UcrtNotFound(String.format("The specified installation directory '%s' does not appear to contain a ucrt installation.", candidate));
    }
}
Also used : File(java.io.File) VersionNumber(org.gradle.util.VersionNumber)

Example 13 with VersionNumber

use of org.gradle.util.VersionNumber in project gradle by gradle.

the class DefaultVisualStudioLocator method locateInstallsInRegistry.

private void locateInstallsInRegistry(String baseKey) {
    List<String> visualCppVersions;
    try {
        visualCppVersions = windowsRegistry.getValueNames(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, baseKey + REGISTRY_ROOTPATH_VC);
    } catch (MissingRegistryEntryException e) {
        // No Visual Studio information available in the registry
        return;
    }
    for (String valueName : visualCppVersions) {
        if (!valueName.matches("\\d+\\.\\d+")) {
            // Ignore the other values
            continue;
        }
        File visualCppDir = new File(windowsRegistry.getStringValue(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, baseKey + REGISTRY_ROOTPATH_VC, valueName));
        visualCppDir = FileUtils.canonicalize(visualCppDir);
        File visualStudioDir = visualCppDir.getParentFile();
        if (isVisualCpp(visualCppDir) && isVisualStudio(visualStudioDir)) {
            LOGGER.debug("Found Visual C++ {} at {}", valueName, visualCppDir);
            VersionNumber version = VersionNumber.parse(valueName);
            VisualCppInstall visualCpp = buildVisualCppInstall("Visual C++ " + valueName, visualStudioDir, visualCppDir, version);
            VisualStudioInstall visualStudio = new VisualStudioInstall(visualStudioDir, visualCpp);
            foundInstalls.put(visualStudioDir, visualStudio);
        } else {
            LOGGER.debug("Ignoring candidate Visual C++ directory {} as it does not look like a Visual C++ installation.", visualCppDir);
        }
    }
}
Also used : MissingRegistryEntryException(net.rubygrapefruit.platform.MissingRegistryEntryException) File(java.io.File) VersionNumber(org.gradle.util.VersionNumber)

Example 14 with VersionNumber

use of org.gradle.util.VersionNumber in project gradle by gradle.

the class AntGroovydoc method execute.

public void execute(final FileCollection source, File destDir, boolean use, boolean noTimestamp, boolean noVersionStamp, String windowTitle, String docTitle, String header, String footer, String overview, boolean includePrivate, final Set<Groovydoc.Link> links, final Iterable<File> groovyClasspath, Iterable<File> classpath, Project project) {
    final File tmpDir = new File(project.getBuildDir(), "tmp/groovydoc");
    FileOperations fileOperations = (ProjectInternal) project;
    fileOperations.delete(tmpDir);
    fileOperations.copy(new Action<CopySpec>() {

        public void execute(CopySpec copySpec) {
            copySpec.from(source).into(tmpDir);
        }
    });
    List<File> combinedClasspath = ImmutableList.<File>builder().addAll(classpath).addAll(groovyClasspath).build();
    VersionNumber version = VersionNumber.parse(getGroovyVersion(combinedClasspath));
    final Map<String, Object> args = Maps.newLinkedHashMap();
    args.put("sourcepath", tmpDir.toString());
    args.put("destdir", destDir);
    args.put("use", use);
    if (isAtLeast(version, "2.4.6")) {
        args.put("noTimestamp", noTimestamp);
        args.put("noVersionStamp", noVersionStamp);
    }
    args.put("private", includePrivate);
    putIfNotNull(args, "windowtitle", windowTitle);
    putIfNotNull(args, "doctitle", docTitle);
    putIfNotNull(args, "header", header);
    putIfNotNull(args, "footer", footer);
    if (overview != null) {
        args.put("overview", overview);
    }
    invokeGroovydoc(links, combinedClasspath, args);
}
Also used : CopySpec(org.gradle.api.file.CopySpec) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) FileOperations(org.gradle.api.internal.file.FileOperations) File(java.io.File) VersionNumber(org.gradle.util.VersionNumber)

Example 15 with VersionNumber

use of org.gradle.util.VersionNumber in project gradle by gradle.

the class ApiGroovyCompiler method applyConfigurationScript.

private void applyConfigurationScript(File configScript, CompilerConfiguration configuration) {
    VersionNumber version = parseGroovyVersion();
    if (version.compareTo(VersionNumber.parse("2.1")) < 0) {
        throw new GradleException("Using a Groovy compiler configuration script requires Groovy 2.1+ but found Groovy " + version + "");
    }
    Binding binding = new Binding();
    binding.setVariable("configuration", configuration);
    CompilerConfiguration configuratorConfig = new CompilerConfiguration();
    ImportCustomizer customizer = new ImportCustomizer();
    customizer.addStaticStars("org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder");
    configuratorConfig.addCompilationCustomizers(customizer);
    GroovyShell shell = new GroovyShell(binding, configuratorConfig);
    try {
        shell.evaluate(configScript);
    } catch (Exception e) {
        throw new GradleException("Could not execute Groovy compiler configuration script: " + configScript.getAbsolutePath(), e);
    }
}
Also used : Binding(groovy.lang.Binding) GradleException(org.gradle.api.GradleException) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) ImportCustomizer(org.codehaus.groovy.control.customizers.ImportCustomizer) VersionNumber(org.gradle.util.VersionNumber) GroovyShell(groovy.lang.GroovyShell) GradleException(org.gradle.api.GradleException)

Aggregations

VersionNumber (org.gradle.util.VersionNumber)19 File (java.io.File)10 MissingRegistryEntryException (net.rubygrapefruit.platform.MissingRegistryEntryException)3 HashMap (java.util.HashMap)2 CompilerConfiguration (org.codehaus.groovy.control.CompilerConfiguration)2 GradleException (org.gradle.api.GradleException)2 UncheckedIOException (org.gradle.api.UncheckedIOException)2 ArchitectureInternal (org.gradle.nativeplatform.platform.internal.ArchitectureInternal)2 IdeaModel (org.gradle.plugins.ide.idea.model.IdeaModel)2 Binding (groovy.lang.Binding)1 GroovyClassLoader (groovy.lang.GroovyClassLoader)1 GroovyShell (groovy.lang.GroovyShell)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1