Search in sources :

Example 66 with GradleException

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

the class OsgiHelper method getVersion.

public String getVersion(String version) {
    /* if it's already OSGi compliant don't touch it */
    final Matcher m = OSGI_VERSION_PATTERN.matcher(version);
    if (m.matches()) {
        return version;
    }
    int group = 0;
    boolean groupToken = true;
    String[] groups = new String[4];
    groups[0] = "0";
    groups[1] = "0";
    groups[2] = "0";
    groups[3] = "";
    StringTokenizer st = new StringTokenizer(version, ",./;'?:\\|=+-_*&^%$#@!~", true);
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if (groupToken) {
            if (group < 3) {
                if (ONLY_NUMBERS.matcher(token).matches()) {
                    groups[group++] = token;
                    groupToken = false;
                } else {
                    // if not a number, i.e. 2.ABD
                    groups[3] = token + fillQualifier(st);
                }
            } else {
                // Last group; what ever is left take that replace all characters that are not alphanum or '_' or '-'
                groups[3] = token + fillQualifier(st);
            }
        } else {
            // If a delimiter; if dot, swap to groupToken, otherwise the rest belongs in qualifier.
            if (".".equals(token)) {
                groupToken = true;
            } else {
                groups[3] = fillQualifier(st);
            }
        }
    }
    String ver = groups[0] + "." + groups[1] + "." + groups[2];
    String result;
    if (groups[3].length() > 0) {
        result = ver + "." + groups[3];
    } else {
        result = ver;
    }
    if (!OSGI_VERSION_PATTERN.matcher(result).matches()) {
        throw new GradleException("OSGi plugin unable to convert version to a compliant version");
    }
    return result;
}
Also used : StringTokenizer(java.util.StringTokenizer) Matcher(java.util.regex.Matcher) GradleException(org.gradle.api.GradleException)

Example 67 with GradleException

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

the class AbstractJettyRunTask method startJettyInternal.

public void startJettyInternal() {
    ProgressLoggerFactory progressLoggerFactory = getServices().get(ProgressLoggerFactory.class);
    ProgressLogger progressLogger = progressLoggerFactory.newOperation(AbstractJettyRunTask.class).start("Start Jetty server", "Starting Jetty");
    try {
        setServer(createServer());
        applyJettyXml();
        JettyPluginServer plugin = getServer();
        Object[] configuredConnectors = getConnectors();
        plugin.setConnectors(configuredConnectors);
        Object[] connectors = plugin.getConnectors();
        if (connectors == null || connectors.length == 0) {
            configuredConnectors = new Object[] { plugin.createDefaultConnector(getHttpPort()) };
            plugin.setConnectors(configuredConnectors);
        }
        //set up a RequestLog if one is provided
        if (getRequestLog() != null) {
            getServer().setRequestLog(getRequestLog());
        }
        //set up the webapp and any context provided
        getServer().configureHandlers();
        configureWebApplication();
        getServer().addWebApplication(webAppConfig);
        // set up security realms
        Object[] configuredRealms = getUserRealms();
        for (int i = 0; (configuredRealms != null) && i < configuredRealms.length; i++) {
            LOGGER.debug(configuredRealms[i].getClass().getName() + ": " + configuredRealms[i].toString());
        }
        plugin.setUserRealms(configuredRealms);
        //do any other configuration required by the
        //particular Jetty version
        finishConfigurationBeforeStart();
        // start Jetty
        server.start();
        if (getStopPort() != null && getStopPort() > 0 && getStopKey() != null) {
            Monitor monitor = new Monitor(getStopPort(), getStopKey(), (Server) server.getProxiedObject());
            monitor.start();
        }
        if (daemon) {
            return;
        }
        // start the scanner thread (if necessary) on the main webapp
        configureScanner();
        startScanner();
        // start the new line scanner thread if necessary
        startConsoleScanner();
    } catch (Exception e) {
        throw new GradleException("Could not start the Jetty server.", e);
    } finally {
        progressLogger.completed();
    }
    progressLogger = progressLoggerFactory.newOperation(AbstractJettyRunTask.class).start("Run Jetty at http://localhost:" + getHttpPort() + "/" + getContextPath(), "Running at http://localhost:" + getHttpPort() + "/" + getContextPath());
    try {
        // keep the thread going if not in daemon mode
        server.join();
    } catch (Exception e) {
        throw new GradleException("Failed to wait for the Jetty server to stop.", e);
    } finally {
        progressLogger.completed();
    }
}
Also used : Monitor(org.gradle.api.plugins.jetty.internal.Monitor) ProgressLoggerFactory(org.gradle.internal.logging.progress.ProgressLoggerFactory) GradleException(org.gradle.api.GradleException) ProgressLogger(org.gradle.internal.logging.progress.ProgressLogger) JettyPluginServer(org.gradle.api.plugins.jetty.internal.JettyPluginServer) GradleException(org.gradle.api.GradleException)

Example 68 with GradleException

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

the class JacocoCoverageVerification method check.

@TaskAction
public void check() {
    final Spec<File> fileExistsSpec = new Spec<File>() {

        @Override
        public boolean isSatisfiedBy(File file) {
            return file.exists();
        }
    };
    JacocoCheckResult checkResult = new AntJacocoCheck(getAntBuilder()).execute(getJacocoClasspath(), getProject().getName(), getAllClassDirs().filter(fileExistsSpec), getAllSourceDirs().filter(fileExistsSpec), getExecutionData(), getViolationRules());
    if (!checkResult.isSuccess()) {
        throw new GradleException(checkResult.getFailureMessage());
    }
}
Also used : GradleException(org.gradle.api.GradleException) AntJacocoCheck(org.gradle.internal.jacoco.AntJacocoCheck) Spec(org.gradle.api.specs.Spec) File(java.io.File) JacocoCheckResult(org.gradle.internal.jacoco.JacocoCheckResult) TaskAction(org.gradle.api.tasks.TaskAction)

Example 69 with GradleException

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

the class UnavailablePlatformToolProvider method failure.

private RuntimeException failure() {
    TreeFormatter formatter = new TreeFormatter();
    this.explain(formatter);
    return new GradleException(formatter.toString());
}
Also used : TreeFormatter(org.gradle.internal.text.TreeFormatter) GradleException(org.gradle.api.GradleException)

Example 70 with GradleException

use of org.gradle.api.GradleException 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

GradleException (org.gradle.api.GradleException)114 File (java.io.File)40 IOException (java.io.IOException)32 TaskAction (org.gradle.api.tasks.TaskAction)16 ArrayList (java.util.ArrayList)10 UncheckedIOException (org.gradle.api.UncheckedIOException)10 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)9 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)8 HashSet (java.util.HashSet)8 FileOutputStream (java.io.FileOutputStream)6 Method (java.lang.reflect.Method)6 UncheckedException (org.gradle.internal.UncheckedException)6 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)5 URL (java.net.URL)5 List (java.util.List)5 ConsoleRenderer (org.gradle.internal.logging.ConsoleRenderer)5 ProcessOutputHandler (com.android.ide.common.process.ProcessOutputHandler)4 FileInputStream (java.io.FileInputStream)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 MalformedURLException (java.net.MalformedURLException)4