Search in sources :

Example 61 with GradleException

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

the class DistributionPlugin method configureArchiveTask.

private <T extends AbstractArchiveTask> Task configureArchiveTask(Project project, String taskName, final Distribution distribution, Class<T> type) {
    final T archiveTask = project.getTasks().create(taskName, type);
    archiveTask.setDescription("Bundles the project as a distribution.");
    archiveTask.setGroup(DISTRIBUTION_GROUP);
    archiveTask.getConventionMapping().map("baseName", new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            if (distribution.getBaseName() == null || distribution.getBaseName().equals("")) {
                throw new GradleException("Distribution baseName must not be null or empty! Check your configuration of the distribution plugin.");
            }
            return distribution.getBaseName();
        }
    });
    Callable<String> baseDir = new Callable<String>() {

        @Override
        public String call() throws Exception {
            return TextUtil.minus(archiveTask.getArchiveName(), "." + archiveTask.getExtension());
        }
    };
    CopySpec childSpec = project.copySpec();
    childSpec.into(baseDir);
    childSpec.with(distribution.getContents());
    archiveTask.with(childSpec);
    ArchivePublishArtifact archiveArtifact = new ArchivePublishArtifact(archiveTask);
    project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(archiveArtifact);
    return archiveTask;
}
Also used : CopySpec(org.gradle.api.file.CopySpec) DefaultArtifactPublicationSet(org.gradle.api.internal.plugins.DefaultArtifactPublicationSet) ArchivePublishArtifact(org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact) GradleException(org.gradle.api.GradleException) GradleException(org.gradle.api.GradleException) Callable(java.util.concurrent.Callable)

Example 62 with GradleException

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

the class ApplicationPlugin method configureInstallTask.

private void configureInstallTask(Task installTask) {
    installTask.doFirst(new Action<Task>() {

        @Override
        public void execute(Task task) {
            Sync sync = (Sync) task;
            if (sync.getDestinationDir().isDirectory()) {
                if (!new File(sync.getDestinationDir(), "lib").isDirectory() || !new File(sync.getDestinationDir(), "bin").isDirectory()) {
                    throw new GradleException("The specified installation directory \'" + sync.getDestinationDir() + "\' is neither empty nor does it contain an installation for \'" + pluginConvention.getApplicationName() + "\'.\n" + "If you really want to install to this directory, delete it and run the install task again.\n" + "Alternatively, choose a different installation directory.");
                }
            }
        }
    });
    installTask.doLast(new Action<Task>() {

        @Override
        public void execute(Task task) {
            Sync sync = (Sync) task;
            HashMap<String, Object> args = new HashMap<String, Object>();
            args.put("file", "" + sync.getDestinationDir().getAbsolutePath() + "/bin/" + pluginConvention.getApplicationName());
            args.put("perm", "ugo+x");
            project.getAnt().invokeMethod("chmod", args);
        }
    });
}
Also used : Task(org.gradle.api.Task) HashMap(java.util.HashMap) GradleException(org.gradle.api.GradleException) Sync(org.gradle.api.tasks.Sync) File(java.io.File)

Example 63 with GradleException

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

the class PlayApplicationRunner method start.

public PlayApplicationRunnerToken start(PlayRunSpec spec) {
    WorkerProcess process = createWorkerProcess(spec.getProjectPath(), workerFactory, spec, adapter);
    process.start();
    PlayWorkerClient clientCallBack = new PlayWorkerClient();
    process.getConnection().addIncoming(PlayRunWorkerClientProtocol.class, clientCallBack);
    PlayRunWorkerServerProtocol workerServer = process.getConnection().addOutgoing(PlayRunWorkerServerProtocol.class);
    process.getConnection().connect();
    PlayAppLifecycleUpdate result = clientCallBack.waitForRunning();
    if (result.isRunning()) {
        return new PlayApplicationRunnerToken(workerServer, clientCallBack, process);
    } else {
        throw new GradleException("Unable to start Play application.", result.getException());
    }
}
Also used : WorkerProcess(org.gradle.process.internal.worker.WorkerProcess) GradleException(org.gradle.api.GradleException)

Example 64 with GradleException

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

the class PropertiesToDaemonParametersConverter method convert.

public void convert(Map<String, String> properties, DaemonParameters target) {
    String prop = properties.get(IDLE_TIMEOUT_PROPERTY);
    if (prop != null) {
        try {
            target.setIdleTimeout(new Integer(prop));
        } catch (NumberFormatException e) {
            throw new GradleException(String.format("Unable to parse %s property. The value should be an int but is: %s", IDLE_TIMEOUT_PROPERTY, prop));
        }
    }
    prop = properties.get(HEALTH_CHECK_INTERVAL_PROPERTY);
    if (prop != null) {
        try {
            target.setPeriodicCheckInterval(new Integer(prop));
        } catch (NumberFormatException e) {
            throw new GradleException(String.format("Unable to parse %s property. Expected an int but got: %s", HEALTH_CHECK_INTERVAL_PROPERTY, prop), e);
        }
    }
    prop = properties.get(JVM_ARGS_PROPERTY);
    if (prop != null) {
        target.setJvmArgs(JvmOptions.fromString(prop));
    }
    prop = properties.get(JAVA_HOME_PROPERTY);
    if (prop != null) {
        File javaHome = new File(prop);
        if (!javaHome.isDirectory()) {
            throw new GradleException(String.format("Java home supplied via '%s' is invalid. Invalid directory: %s", JAVA_HOME_PROPERTY, prop));
        }
        JavaInfo jvm;
        try {
            jvm = Jvm.forHome(javaHome);
        } catch (JavaHomeException e) {
            throw new GradleException(String.format("Java home supplied via '%s' seems to be invalid: %s", JAVA_HOME_PROPERTY, prop));
        }
        target.setJvm(jvm);
    }
    prop = properties.get(DAEMON_BASE_DIR_PROPERTY);
    if (prop != null) {
        target.setBaseDir(new File(prop));
    }
    String daemonEnabledPropertyValue = properties.get(DAEMON_ENABLED_PROPERTY);
    if (daemonEnabledPropertyValue != null) {
        target.setEnabled(isTrue(daemonEnabledPropertyValue));
    }
    final String debugEnabledPropertyValue = properties.get(DEBUG_MODE_PROPERTY);
    if (debugEnabledPropertyValue != null) {
        target.setDebug(isTrue(debugEnabledPropertyValue));
    }
}
Also used : GradleException(org.gradle.api.GradleException) JavaInfo(org.gradle.internal.jvm.JavaInfo) JavaHomeException(org.gradle.internal.jvm.JavaHomeException) File(java.io.File)

Example 65 with GradleException

use of org.gradle.api.GradleException in project hibernate-orm by hibernate.

the class HibernatePlugin method writeOutEnhancedClass.

private void writeOutEnhancedClass(byte[] enhancedBytecode, File file) {
    try {
        if (file.delete()) {
            if (!file.createNewFile()) {
                logger.error("Unable to recreate class file [" + file.getName() + "]");
            }
        } else {
            logger.error("Unable to delete class file [" + file.getName() + "]");
        }
    } catch (IOException e) {
        logger.warn("Problem preparing class file for writing out enhancements [" + file.getName() + "]");
    }
    try {
        FileOutputStream outputStream = new FileOutputStream(file, false);
        try {
            outputStream.write(enhancedBytecode);
            outputStream.flush();
        } catch (IOException e) {
            throw new GradleException("Error writing to enhanced class [" + file.getName() + "] to file [" + file.getAbsolutePath() + "]", e);
        } finally {
            try {
                outputStream.close();
            } catch (IOException ignore) {
            }
        }
    } catch (FileNotFoundException e) {
        throw new GradleException("Error opening class file for writing : " + file.getAbsolutePath(), e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) GradleException(org.gradle.api.GradleException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

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