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);
}
}
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);
}
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);
}
}
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;
}
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;
}
Aggregations