Search in sources :

Example 16 with Artifact

use of com.intellij.packaging.artifacts.Artifact in project intellij-community by JetBrains.

the class AppEngineSupportProvider method addSupport.

private void addSupport(final Module module, final ModifiableRootModel rootModel, FrameworkSupportModel frameworkSupportModel, String sdkPath, @Nullable PersistenceApi persistenceApi) {
    FacetType<AppEngineFacet, AppEngineFacetConfiguration> facetType = AppEngineFacet.getFacetType();
    AppEngineFacet appEngineFacet = FacetManager.getInstance(module).addFacet(facetType, facetType.getDefaultFacetName(), null);
    AppEngineWebIntegration webIntegration = AppEngineWebIntegration.getInstance();
    webIntegration.registerFrameworkInModel(frameworkSupportModel, appEngineFacet);
    final AppEngineFacetConfiguration facetConfiguration = appEngineFacet.getConfiguration();
    facetConfiguration.setSdkHomePath(sdkPath);
    final AppEngineSdk sdk = appEngineFacet.getSdk();
    final Artifact webArtifact = findOrCreateWebArtifact(appEngineFacet);
    final VirtualFile webDescriptorDir = webIntegration.suggestParentDirectoryForAppEngineWebXml(module, rootModel);
    if (webDescriptorDir != null) {
        VirtualFile descriptor = createFileFromTemplate(AppEngineTemplateGroupDescriptorFactory.APP_ENGINE_WEB_XML_TEMPLATE, webDescriptorDir, AppEngineUtil.APP_ENGINE_WEB_XML_NAME);
        if (descriptor != null) {
            webIntegration.addDescriptor(webArtifact, module.getProject(), descriptor);
        }
    }
    final Project project = module.getProject();
    webIntegration.addDevServerToModuleDependencies(rootModel, sdk);
    final Library apiJar = addProjectLibrary(module, "AppEngine API", sdk.getUserLibraryPaths(), VirtualFile.EMPTY_ARRAY);
    rootModel.addLibraryEntry(apiJar);
    webIntegration.addLibraryToArtifact(apiJar, webArtifact, project);
    if (persistenceApi != null) {
        facetConfiguration.setRunEnhancerOnMake(true);
        facetConfiguration.setPersistenceApi(persistenceApi);
        facetConfiguration.getFilesToEnhance().addAll(AppEngineUtil.getDefaultSourceRootsToEnhance(rootModel));
        try {
            final VirtualFile[] sourceRoots = rootModel.getSourceRoots();
            final VirtualFile sourceRoot;
            if (sourceRoots.length > 0) {
                sourceRoot = sourceRoots[0];
            } else {
                sourceRoot = findOrCreateChildDirectory(rootModel.getContentRoots()[0], "src");
            }
            VirtualFile metaInf = findOrCreateChildDirectory(sourceRoot, "META-INF");
            if (persistenceApi == PersistenceApi.JDO || persistenceApi == PersistenceApi.JDO3) {
                createFileFromTemplate(AppEngineTemplateGroupDescriptorFactory.APP_ENGINE_JDO_CONFIG_TEMPLATE, metaInf, AppEngineUtil.JDO_CONFIG_XML_NAME);
            } else {
                final VirtualFile file = createFileFromTemplate(AppEngineTemplateGroupDescriptorFactory.APP_ENGINE_JPA_CONFIG_TEMPLATE, metaInf, AppEngineUtil.JPA_CONFIG_XML_NAME);
                if (file != null) {
                    webIntegration.setupJpaSupport(module, file);
                }
            }
        } catch (IOException e) {
            LOG.error(e);
        }
        final Library library = addProjectLibrary(module, "AppEngine ORM", Collections.singletonList(sdk.getOrmLibDirectoryPath()), sdk.getOrmLibSources());
        rootModel.addLibraryEntry(library);
        webIntegration.addLibraryToArtifact(library, webArtifact, project);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Library(com.intellij.openapi.roots.libraries.Library) IOException(java.io.IOException) AppEngineSdk(com.intellij.appengine.sdk.AppEngineSdk) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 17 with Artifact

use of com.intellij.packaging.artifacts.Artifact in project intellij-community by JetBrains.

the class AppEngineSupportProvider method findOrCreateWebArtifact.

@NotNull
private static Artifact findOrCreateWebArtifact(AppEngineFacet appEngineFacet) {
    Module module = appEngineFacet.getModule();
    ArtifactType webArtifactType = AppEngineWebIntegration.getInstance().getAppEngineWebArtifactType();
    final Collection<Artifact> artifacts = ArtifactUtil.getArtifactsContainingModuleOutput(module);
    for (Artifact artifact : artifacts) {
        if (webArtifactType.equals(artifact.getArtifactType())) {
            return artifact;
        }
    }
    ArtifactManager artifactManager = ArtifactManager.getInstance(module.getProject());
    PackagingElementFactory elementFactory = PackagingElementFactory.getInstance();
    ArtifactRootElement<?> root = elementFactory.createArtifactRootElement();
    elementFactory.getOrCreateDirectory(root, "WEB-INF/classes").addOrFindChild(elementFactory.createModuleOutput(module));
    return artifactManager.addArtifact(module.getName(), webArtifactType, root);
}
Also used : ArtifactManager(com.intellij.packaging.artifacts.ArtifactManager) ArtifactType(com.intellij.packaging.artifacts.ArtifactType) PackagingElementFactory(com.intellij.packaging.elements.PackagingElementFactory) Module(com.intellij.openapi.module.Module) Artifact(com.intellij.packaging.artifacts.Artifact) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with Artifact

use of com.intellij.packaging.artifacts.Artifact in project intellij-community by JetBrains.

the class AppEngineUtil method setupAppEngineArtifactCombobox.

public static void setupAppEngineArtifactCombobox(@NotNull Project project, @NotNull final JComboBox comboBox, final boolean withAppEngineFacetOnly) {
    comboBox.setRenderer(new ListCellRendererWrapper<Artifact>() {

        @Override
        public void customize(JList list, Artifact value, int index, boolean selected, boolean hasFocus) {
            if (value != null) {
                setIcon(value.getArtifactType().getIcon());
                setText(value.getName());
            }
        }
    });
    comboBox.removeAllItems();
    for (Artifact artifact : collectAppEngineArtifacts(project, withAppEngineFacetOnly)) {
        comboBox.addItem(artifact);
    }
}
Also used : Artifact(com.intellij.packaging.artifacts.Artifact)

Example 19 with Artifact

use of com.intellij.packaging.artifacts.Artifact in project android by JetBrains.

the class AndroidPrecompileTask method checkArtifacts.

private static boolean checkArtifacts(@NotNull CompileContext context) {
    final Project project = context.getProject();
    final CompileScope scope = context.getCompileScope();
    final Set<Artifact> artifacts = ApplicationManager.getApplication().runReadAction(new Computable<Set<Artifact>>() {

        @Override
        public Set<Artifact> compute() {
            return ArtifactCompileScope.getArtifactsToBuild(project, scope, false);
        }
    });
    if (artifacts == null) {
        return true;
    }
    final Set<Artifact> debugArtifacts = new HashSet<>();
    final Set<Artifact> releaseArtifacts = new HashSet<>();
    final Map<AndroidFacet, List<Artifact>> facet2artifacts = new HashMap<>();
    for (final Artifact artifact : artifacts) {
        final ArtifactProperties<?> properties = artifact.getProperties(AndroidArtifactPropertiesProvider.getInstance());
        if (properties instanceof AndroidApplicationArtifactProperties) {
            final AndroidArtifactSigningMode mode = ((AndroidApplicationArtifactProperties) properties).getSigningMode();
            if (mode == AndroidArtifactSigningMode.DEBUG || mode == AndroidArtifactSigningMode.DEBUG_WITH_CUSTOM_CERTIFICATE) {
                debugArtifacts.add(artifact);
            } else {
                releaseArtifacts.add(artifact);
            }
        }
        final AndroidFacet facet = ApplicationManager.getApplication().runReadAction(new Computable<AndroidFacet>() {

            @Nullable
            @Override
            public AndroidFacet compute() {
                return AndroidArtifactUtil.getPackagedFacet(project, artifact);
            }
        });
        if (facet != null) {
            List<Artifact> list = facet2artifacts.get(facet);
            if (list == null) {
                list = new ArrayList<>();
                facet2artifacts.put(facet, list);
            }
            list.add(artifact);
        }
    }
    boolean success = true;
    if (debugArtifacts.size() > 0 && releaseArtifacts.size() > 0) {
        final String message = "Cannot build debug and release Android artifacts in the same session\n" + "Debug artifacts: " + toString(debugArtifacts) + "\n" + "Release artifacts: " + toString(releaseArtifacts);
        context.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
        success = false;
    }
    if (releaseArtifacts.size() > 0 && CompileStepBeforeRun.getRunConfiguration(context) != null) {
        final String message = "Cannot build release Android artifacts in the 'make before run' session\n" + "Release artifacts: " + toString(releaseArtifacts);
        context.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
        success = false;
    }
    for (Map.Entry<AndroidFacet, List<Artifact>> entry : facet2artifacts.entrySet()) {
        final List<Artifact> list = entry.getValue();
        final String moduleName = entry.getKey().getModule().getName();
        if (list.size() > 1) {
            final Artifact firstArtifact = list.get(0);
            final Object[] firstArtifactProGuardOptions = getProGuardOptions(firstArtifact);
            for (int i = 1; i < list.size(); i++) {
                final Artifact artifact = list.get(i);
                if (!Arrays.equals(getProGuardOptions(artifact), firstArtifactProGuardOptions)) {
                    context.addMessage(CompilerMessageCategory.ERROR, "Artifacts related to the same module '" + moduleName + "' have different ProGuard options: " + firstArtifact.getName() + ", " + artifact.getName(), null, -1, -1);
                    success = false;
                    break;
                }
            }
        }
    }
    return success;
}
Also used : HashSet(com.intellij.util.containers.hash.HashSet) HashMap(com.intellij.util.containers.HashMap) AndroidApplicationArtifactProperties(org.jetbrains.android.compiler.artifact.AndroidApplicationArtifactProperties) HashSet(com.intellij.util.containers.hash.HashSet) Artifact(com.intellij.packaging.artifacts.Artifact) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) ArtifactCompileScope(com.intellij.packaging.impl.compiler.ArtifactCompileScope) AndroidArtifactSigningMode(org.jetbrains.android.compiler.artifact.AndroidArtifactSigningMode) HashMap(com.intellij.util.containers.HashMap) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with Artifact

use of com.intellij.packaging.artifacts.Artifact in project android by JetBrains.

the class AndroidCompileUtil method getProguardConfigFilePathIfShouldRun.

@Nullable
public static ProguardRunningOptions getProguardConfigFilePathIfShouldRun(@NotNull AndroidFacet facet, CompileContext context) {
    // wizard
    String pathsStr = context.getCompileScope().getUserData(PROGUARD_CFG_PATHS_KEY);
    if (pathsStr != null) {
        final String[] paths = pathsStr.split(File.pathSeparator);
        if (paths.length > 0) {
            return new ProguardRunningOptions(Arrays.asList(paths));
        }
    }
    final AndroidPlatform platform = AndroidPlatform.getInstance(facet.getModule());
    final String sdkHomePath = platform != null ? FileUtil.toCanonicalPath(platform.getSdkData().getPath()) : null;
    // artifact
    final Project project = context.getProject();
    final Set<Artifact> artifacts = ArtifactCompileScope.getArtifactsToBuild(project, context.getCompileScope(), false);
    for (Artifact artifact : artifacts) {
        if (artifact.getArtifactType() instanceof AndroidApplicationArtifactType && facet.equals(AndroidArtifactUtil.getPackagedFacet(project, artifact))) {
            final ArtifactProperties<?> properties = artifact.getProperties(AndroidArtifactPropertiesProvider.getInstance());
            if (properties instanceof AndroidApplicationArtifactProperties) {
                final AndroidApplicationArtifactProperties p = (AndroidApplicationArtifactProperties) properties;
                if (p.isRunProGuard()) {
                    final List<String> paths = AndroidUtils.urlsToOsPaths(p.getProGuardCfgFiles(), sdkHomePath);
                    return new ProguardRunningOptions(paths);
                }
            }
        }
    }
    // facet
    final AndroidFacetConfiguration configuration = facet.getConfiguration();
    final JpsAndroidModuleProperties properties = configuration.getState();
    if (properties != null && properties.RUN_PROGUARD) {
        final List<String> urls = properties.myProGuardCfgFiles;
        final List<String> paths = AndroidUtils.urlsToOsPaths(urls, sdkHomePath);
        return new ProguardRunningOptions(paths);
    }
    return null;
}
Also used : AndroidFacetConfiguration(org.jetbrains.android.facet.AndroidFacetConfiguration) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) Artifact(com.intellij.packaging.artifacts.Artifact) Project(com.intellij.openapi.project.Project) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Artifact (com.intellij.packaging.artifacts.Artifact)52 ArrayList (java.util.ArrayList)13 Project (com.intellij.openapi.project.Project)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Module (com.intellij.openapi.module.Module)7 NotNull (org.jetbrains.annotations.NotNull)6 ArtifactManager (com.intellij.packaging.artifacts.ArtifactManager)5 File (java.io.File)5 PackagingElement (com.intellij.packaging.elements.PackagingElement)4 ArtifactCompileScope (com.intellij.packaging.impl.compiler.ArtifactCompileScope)4 ArtifactPackagingElement (com.intellij.packaging.impl.elements.ArtifactPackagingElement)4 Nullable (org.jetbrains.annotations.Nullable)4 ArtifactType (com.intellij.packaging.artifacts.ArtifactType)3 PackagingElementPath (com.intellij.packaging.impl.artifacts.PackagingElementPath)3 ReadAction (com.intellij.openapi.application.ReadAction)2 Result (com.intellij.openapi.application.Result)2 Pair (com.intellij.openapi.util.Pair)2 ModifiableArtifactModel (com.intellij.packaging.artifacts.ModifiableArtifactModel)2 CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)2 PackagingElementFactory (com.intellij.packaging.elements.PackagingElementFactory)2