Search in sources :

Example 6 with CompileScope

use of com.intellij.openapi.compiler.CompileScope in project intellij-community by JetBrains.

the class InternalProjectTaskRunner method buildArtifacts.

private static void buildArtifacts(@NotNull Project project, @NotNull List<Artifact> artifacts, @Nullable Object sessionId, @Nullable CompileStatusNotification compileNotification, boolean forceArtifactBuild) {
    if (!artifacts.isEmpty()) {
        final CompileScope scope = ArtifactCompileScope.createArtifactsScope(project, artifacts, forceArtifactBuild);
        ArtifactsWorkspaceSettings.getInstance(project).setArtifactsToBuild(artifacts);
        ExecutionManagerImpl.EXECUTION_SESSION_ID_KEY.set(scope, sessionId);
        //in external build we can set 'rebuild' flag per target type
        CompilerManager.getInstance(project).make(scope, compileNotification);
    }
}
Also used : ArtifactCompileScope(com.intellij.packaging.impl.compiler.ArtifactCompileScope) CompileScope(com.intellij.openapi.compiler.CompileScope)

Example 7 with CompileScope

use of com.intellij.openapi.compiler.CompileScope in project android by JetBrains.

the class GradleModuleTasksProvider method getAffectedModules.

@NotNull
private static Module[] getAffectedModules(@NotNull Project project, @NotNull Module[] modules) {
    final CompilerManager compilerManager = CompilerManager.getInstance(project);
    CompileScope scope = compilerManager.createModulesCompileScope(modules, true, true);
    return scope.getAffectedModules();
}
Also used : CompileScope(com.intellij.openapi.compiler.CompileScope) CompilerManager(com.intellij.openapi.compiler.CompilerManager) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with CompileScope

use of com.intellij.openapi.compiler.CompileScope in project android by JetBrains.

the class ApkStep method _commit.

@Override
public void _commit(boolean finishChosen) throws CommitStepException {
    final String apkPath = myApkPathField.getText().trim();
    if (apkPath.length() == 0) {
        throw new CommitStepException(AndroidBundle.message("android.extract.package.specify.apk.path.error"));
    }
    AndroidFacet facet = myWizard.getFacet();
    PropertiesComponent properties = PropertiesComponent.getInstance(myWizard.getProject());
    properties.setValue(ChooseModuleStep.MODULE_PROPERTY, facet != null ? facet.getModule().getName() : "");
    properties.setValue(getApkPathPropertyName(), apkPath);
    File folder = new File(apkPath).getParentFile();
    if (folder == null) {
        throw new CommitStepException(AndroidBundle.message("android.cannot.create.file.error", apkPath));
    }
    try {
        if (!folder.exists()) {
            folder.mkdirs();
        }
    } catch (Exception e) {
        throw new CommitStepException(e.getMessage());
    }
    final CompileScope compileScope = CompilerManager.getInstance(myWizard.getProject()).createModuleCompileScope(facet.getModule(), true);
    AndroidCompileUtil.setReleaseBuild(compileScope);
    properties.setValue(RUN_PROGUARD_PROPERTY, Boolean.toString(myProguardCheckBox.isSelected()));
    if (myProguardCheckBox.isSelected()) {
        final List<String> proguardOsCfgPaths = myProGuardConfigFilesPanel.getOsPaths();
        if (proguardOsCfgPaths.isEmpty()) {
            throw new CommitStepException(AndroidBundle.message("android.extract.package.specify.proguard.cfg.path.error"));
        }
        final String proguardPathsStr = mergeProguardCfgPathsToOneString(proguardOsCfgPaths);
        properties.setValue(PROGUARD_CFG_PATHS_PROPERTY, proguardPathsStr);
        for (String path : proguardOsCfgPaths) {
            if (!new File(path).isFile()) {
                throw new CommitStepException("Cannot find file " + path);
            }
        }
        compileScope.putUserData(AndroidCompileUtil.PROGUARD_CFG_PATHS_KEY, proguardPathsStr);
    }
    myWizard.setCompileScope(compileScope);
    myWizard.setApkPath(apkPath);
}
Also used : CommitStepException(com.intellij.ide.wizard.CommitStepException) CompileScope(com.intellij.openapi.compiler.CompileScope) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) CommitStepException(com.intellij.ide.wizard.CommitStepException)

Example 9 with CompileScope

use of com.intellij.openapi.compiler.CompileScope in project android by JetBrains.

the class AndroidCompileUtil method doGenerate.

public static boolean doGenerate(AndroidFacet facet, final AndroidAutogeneratorMode mode) {
    assert !ApplicationManager.getApplication().isDispatchThread();
    final CompileContext[] contextWrapper = new CompileContext[1];
    final Module module = facet.getModule();
    final Project project = module.getProject();
    ApplicationManager.getApplication().runReadAction(new Runnable() {

        @Override
        public void run() {
            if (project.isDisposed())
                return;
            CompilerTask task = new CompilerTask(project, "Android auto-generation", true, false, true, true);
            CompileScope scope = new ModuleCompileScope(module, false);
            contextWrapper[0] = new CompileContextImpl(project, task, scope, false, false);
        }
    });
    CompileContext context = contextWrapper[0];
    if (context == null) {
        return false;
    }
    generate(facet, mode, context, false);
    return context.getMessages(CompilerMessageCategory.ERROR).length == 0;
}
Also used : Project(com.intellij.openapi.project.Project) ModuleCompileScope(com.intellij.compiler.impl.ModuleCompileScope) CompileScope(com.intellij.openapi.compiler.CompileScope) ArtifactCompileScope(com.intellij.packaging.impl.compiler.ArtifactCompileScope) CompilerTask(com.intellij.compiler.progress.CompilerTask) CompileContextImpl(com.intellij.compiler.impl.CompileContextImpl) Module(com.intellij.openapi.module.Module) CompileContext(com.intellij.openapi.compiler.CompileContext) ModuleCompileScope(com.intellij.compiler.impl.ModuleCompileScope)

Example 10 with CompileScope

use of com.intellij.openapi.compiler.CompileScope in project android by JetBrains.

the class AndroidJunitPatcher method handleJavaResources.

/**
   * Puts folders with merged java resources for the selected variant of every module on the classpath.
   *
   * <p>The problem we're solving here is that CompilerModuleExtension supports only one directory for "compiler output". When IJ compiles
   * Java projects, it copies resources to the output classes dir. This is something our Gradle plugin doesn't do, so we need to add the
   * resource directories to the classpath here.
   *
   * <p>We need to do this for every project dependency as well, since we're using classes and resources directories of these directly.
   *
   * @see <a href="http://b.android.com/172409">Bug 172409</a>
   */
private static void handleJavaResources(@NotNull Module module, @NotNull AndroidModuleModel androidModel, @NotNull PathsList classPath) {
    CompilerManager compilerManager = CompilerManager.getInstance(module.getProject());
    CompileScope scope = compilerManager.createModulesCompileScope(new Module[] { module }, true, true);
    // The only test resources we want to use, are the ones from the module where the test is. They should go first, before main resources.
    JavaArtifact testArtifact = androidModel.getUnitTestArtifactInSelectedVariant();
    if (testArtifact != null) {
        try {
            classPath.add(testArtifact.getJavaResourcesFolder());
        } catch (UnsupportedMethodException ignored) {
        // Java resources were not present in older versions of the gradle plugin.
        }
    }
    FileRootSearchScope excludeScope = null;
    TestArtifactSearchScopes testScopes = TestArtifactSearchScopes.get(module);
    if (testScopes != null) {
        excludeScope = testScopes.getUnitTestExcludeScope();
    }
    for (Module affectedModule : scope.getAffectedModules()) {
        AndroidFacet facet = AndroidFacet.getInstance(affectedModule);
        if (facet != null) {
            AndroidModuleModel affectedAndroidModel = AndroidModuleModel.get(facet);
            if (affectedAndroidModel != null) {
                try {
                    File resourceFolder = affectedAndroidModel.getMainArtifact().getJavaResourcesFolder();
                    if (excludeScope != null && excludeScope.accept(resourceFolder)) {
                        continue;
                    }
                    classPath.add(resourceFolder);
                } catch (UnsupportedMethodException ignored) {
                // Java resources were not present in older versions of the gradle plugin.
                }
            }
        }
    }
}
Also used : CompileScope(com.intellij.openapi.compiler.CompileScope) JavaArtifact(com.android.builder.model.JavaArtifact) UnsupportedMethodException(org.gradle.tooling.model.UnsupportedMethodException) CompilerManager(com.intellij.openapi.compiler.CompilerManager) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) File(java.io.File) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Aggregations

CompileScope (com.intellij.openapi.compiler.CompileScope)10 ArtifactCompileScope (com.intellij.packaging.impl.compiler.ArtifactCompileScope)6 CompilerManager (com.intellij.openapi.compiler.CompilerManager)5 CompileContext (com.intellij.openapi.compiler.CompileContext)4 Module (com.intellij.openapi.module.Module)4 CompileStatusNotification (com.intellij.openapi.compiler.CompileStatusNotification)3 Project (com.intellij.openapi.project.Project)2 File (java.io.File)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 JavaArtifact (com.android.builder.model.JavaArtifact)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 CompileContextImpl (com.intellij.compiler.impl.CompileContextImpl)1 ModuleCompileScope (com.intellij.compiler.impl.ModuleCompileScope)1 CompilerTask (com.intellij.compiler.progress.CompilerTask)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 CommitStepException (com.intellij.ide.wizard.CommitStepException)1 Pair (com.intellij.openapi.util.Pair)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Artifact (com.intellij.packaging.artifacts.Artifact)1