2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.openapi
.roots
.ui
.configuration
.artifacts
;
18 import com
.intellij
.openapi
.util
.io
.FileUtil
;
19 import com
.intellij
.openapi
.vfs
.LocalFileSystem
;
20 import com
.intellij
.openapi
.vfs
.VirtualFile
;
21 import com
.intellij
.openapi
.diagnostic
.Logger
;
22 import com
.intellij
.packaging
.artifacts
.ArtifactType
;
23 import com
.intellij
.packaging
.elements
.CompositePackagingElement
;
24 import com
.intellij
.packaging
.elements
.PackagingElementResolvingContext
;
25 import com
.intellij
.packaging
.impl
.elements
.ManifestFileUtil
;
26 import com
.intellij
.packaging
.ui
.ManifestFileConfiguration
;
27 import org
.jetbrains
.annotations
.NotNull
;
31 import java
.util
.HashMap
;
33 public class ManifestFilesInfo
{
34 private static final Logger LOG
= Logger
.getInstance("#com.intellij.openapi.roots.ui.configuration.artifacts.ManifestFilesInfo");
35 private Map
<CompositePackagingElement
<?
>, ManifestFileConfiguration
> myManifestFiles
= new HashMap
<CompositePackagingElement
<?
>, ManifestFileConfiguration
>();
36 private Map
<CompositePackagingElement
<?
>, ManifestFileConfiguration
> myOriginalManifestFiles
= new HashMap
<CompositePackagingElement
<?
>, ManifestFileConfiguration
>();
38 public ManifestFileConfiguration
getManifestFile(CompositePackagingElement
<?
> element
, ArtifactType artifactType
,
39 final PackagingElementResolvingContext context
) {
40 ManifestFileConfiguration manifestFile
= myManifestFiles
.get(element
);
41 if (manifestFile
== null) {
42 manifestFile
= ManifestFileUtil
.createManifestFileConfiguration(element
, context
, artifactType
);
43 myOriginalManifestFiles
.put(element
, new ManifestFileConfiguration(manifestFile
));
44 myManifestFiles
.put(element
, manifestFile
);
49 public void saveManifestFiles() {
50 for (Map
.Entry
<CompositePackagingElement
<?
>, ManifestFileConfiguration
> entry
: myManifestFiles
.entrySet()) {
51 final ManifestFileConfiguration configuration
= entry
.getValue();
52 final String path
= configuration
.getManifestFilePath();
53 if (path
== null) continue;
55 final ManifestFileConfiguration original
= myOriginalManifestFiles
.get(entry
.getKey());
56 if (original
!= null && original
.equals(configuration
)) {
60 VirtualFile file
= LocalFileSystem
.getInstance().findFileByPath(path
);
62 final File ioFile
= new File(FileUtil
.toSystemDependentName(path
));
63 FileUtil
.createIfDoesntExist(ioFile
);
64 file
= LocalFileSystem
.getInstance().refreshAndFindFileByIoFile(ioFile
);
67 LOG
.error("cannot create file: " + ioFile
);
71 ManifestFileUtil
.updateManifest(file
, configuration
, true);
75 public boolean isManifestFilesModified() {
76 return !myOriginalManifestFiles
.equals(myManifestFiles
);
80 myManifestFiles
.clear();
81 myOriginalManifestFiles
.clear();
84 public boolean isManifestFile(@NotNull String path
) {
85 for (ManifestFileConfiguration configuration
: myManifestFiles
.values()) {
86 if (path
.equals(configuration
.getManifestFilePath())) {