Search in sources :

Example 6 with BuildLauncher

use of org.gradle.tooling.BuildLauncher in project meghanada-server by mopemope.

the class AndroidSupport method prepareCompileAndroidTestJavaV2.

private void prepareCompileAndroidTestJavaV2() {
    ProjectConnection connection = this.project.getProjectConnection();
    try {
        BuildLauncher buildLauncher = connection.newBuild();
        String genTestTask = this.project.getName() + genUnitTestTaskName;
        String genAndroidTestTask = this.project.getName() + genAndroidTestTaskName;
        buildLauncher.forTasks(genTestTask, genAndroidTestTask).run();
        int size = this.project.getDependencies().size();
        String aar = Joiner.on(File.separator).join(this.project.getProjectRoot(), BUILD_DIR, INTERMEDIATE_DIR, EXPLODED_DIR);
        List<File> jars = FileUtils.collectFiles(new File(aar), EXT_JAR);
        for (File jar : jars) {
            addAAR(jar);
        }
        int after = this.project.getDependencies().size();
        if (size != after) {
            CachedASMReflector.getInstance().createClassIndexes(jars);
            this.project.resetCachedClasspath();
        }
    } finally {
        connection.close();
    }
}
Also used : BuildLauncher(org.gradle.tooling.BuildLauncher) ProjectConnection(org.gradle.tooling.ProjectConnection) File(java.io.File)

Example 7 with BuildLauncher

use of org.gradle.tooling.BuildLauncher in project meghanada-server by mopemope.

the class GradleProject method runPrepareCompileTask.

private void runPrepareCompileTask() throws IOException {
    if (!this.prepareCompileTask.isEmpty()) {
        final ProjectConnection connection = this.getProjectConnection();
        try {
            final String[] tasks = prepareCompileTask.toArray(new String[prepareCompileTask.size()]);
            final BuildLauncher buildLauncher = connection.newBuild();
            log.info("project {} run tasks:{}", this.name, (Object) tasks);
            this.setBuildJVMArgs(buildLauncher);
            buildLauncher.forTasks(tasks).run();
        } finally {
            connection.close();
        }
    }
}
Also used : BuildLauncher(org.gradle.tooling.BuildLauncher) ProjectConnection(org.gradle.tooling.ProjectConnection)

Example 8 with BuildLauncher

use of org.gradle.tooling.BuildLauncher in project meghanada-server by mopemope.

the class GradleProject method runPrepareTestCompileTask.

private void runPrepareTestCompileTask() throws IOException {
    if (!this.prepareTestCompileTask.isEmpty()) {
        final ProjectConnection connection = this.getProjectConnection();
        try {
            final String[] tasks = prepareTestCompileTask.toArray(new String[prepareTestCompileTask.size()]);
            final BuildLauncher buildLauncher = connection.newBuild();
            log.info("project {} run tasks:{}", this.name, (Object) tasks);
            this.setBuildJVMArgs(buildLauncher);
            buildLauncher.forTasks(tasks).run();
        } finally {
            connection.close();
        }
    }
}
Also used : BuildLauncher(org.gradle.tooling.BuildLauncher) ProjectConnection(org.gradle.tooling.ProjectConnection)

Example 9 with BuildLauncher

use of org.gradle.tooling.BuildLauncher in project meghanada-server by mopemope.

the class GradleProject method runTask.

@Override
public InputStream runTask(final List<String> args) throws IOException {
    try {
        final List<String> tasks = new ArrayList<>(4);
        final List<String> taskArgs = new ArrayList<>(4);
        for (final String temp : args) {
            for (final String arg : Splitter.on(" ").split(temp)) {
                if (arg.startsWith("-")) {
                    taskArgs.add(arg.trim());
                } else {
                    tasks.add(arg.trim());
                }
            }
        }
        log.debug("task:{}:{} args:{}:{}", tasks, tasks.size(), taskArgs, taskArgs.size());
        final ProjectConnection projectConnection = getProjectConnection();
        final BuildLauncher build = projectConnection.newBuild();
        this.setBuildJVMArgs(build);
        build.forTasks(tasks.toArray(new String[tasks.size()]));
        if (taskArgs.size() > 0) {
            build.withArguments(taskArgs.toArray(new String[taskArgs.size()]));
        }
        final PipedOutputStream outputStream = new PipedOutputStream();
        PipedInputStream inputStream = new PipedInputStream(outputStream);
        build.setStandardError(outputStream);
        build.setStandardOutput(outputStream);
        final VoidResultHandler handler = new VoidResultHandler(outputStream, inputStream, projectConnection);
        build.run(handler);
        return inputStream;
    } finally {
        Config.setProjectRoot(this.projectRoot.getCanonicalPath());
    }
}
Also used : ArrayList(java.util.ArrayList) BuildLauncher(org.gradle.tooling.BuildLauncher) ProjectConnection(org.gradle.tooling.ProjectConnection) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream)

Example 10 with BuildLauncher

use of org.gradle.tooling.BuildLauncher in project liferay-ide by liferay.

the class LiferayGradleProject method getOutputBundle.

@Override
public IPath getOutputBundle(boolean cleanBuild, IProgressMonitor monitor) throws CoreException {
    ProjectConnection connection = null;
    try {
        IPath projectLocation = getProject().getLocation();
        File projectFile = projectLocation.toFile();
        GradleConnector connector = GradleConnector.newConnector().forProjectDirectory(projectFile);
        connection = connector.connect();
        BuildLauncher launcher = connection.newBuild();
        BlockingResultHandler<Object> handler = new BlockingResultHandler<>(Object.class);
        if (cleanBuild) {
            launcher.forTasks("clean", "assemble").run(handler);
        } else {
            launcher.forTasks("assemble").run(handler);
        }
        handler.getResult();
    } catch (Exception e) {
        GradleCore.logError("Project " + getProject().getName() + " build output error", e);
        return null;
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
    IPath outputBundlePath = getOutputBundlePath();
    if (FileUtil.exists(outputBundlePath)) {
        return outputBundlePath;
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) BuildLauncher(org.gradle.tooling.BuildLauncher) ProjectConnection(org.gradle.tooling.ProjectConnection) IFile(org.eclipse.core.resources.IFile) File(java.io.File) CoreException(org.eclipse.core.runtime.CoreException) GradleConnector(org.gradle.tooling.GradleConnector)

Aggregations

BuildLauncher (org.gradle.tooling.BuildLauncher)12 ProjectConnection (org.gradle.tooling.ProjectConnection)12 File (java.io.File)7 GradleConnector (org.gradle.tooling.GradleConnector)5 IOException (java.io.IOException)2 BuildMode (com.android.tools.idea.gradle.util.BuildMode)1 ExternalSystemException (com.intellij.openapi.externalSystem.model.ExternalSystemException)1 ExternalSystemTaskId (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId)1 ExternalSystemTaskNotificationListener (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener)1 ExternalSystemProgressEventUnsupportedImpl (com.intellij.openapi.externalSystem.model.task.event.ExternalSystemProgressEventUnsupportedImpl)1 ExternalSystemTaskExecutionEvent (com.intellij.openapi.externalSystem.model.task.event.ExternalSystemTaskExecutionEvent)1 ExternalSystemTaskManager (com.intellij.openapi.externalSystem.task.ExternalSystemTaskManager)1 ExternalSystemApiUtil (com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil)1 Key (com.intellij.openapi.util.Key)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 ArrayUtil (com.intellij.util.ArrayUtil)1 Function (com.intellij.util.Function)1 SystemProperties (com.intellij.util.SystemProperties)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1