mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
support conversion of artifact settings
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.conversion;
|
||||
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public interface ArtifactsSettings {
|
||||
@NotNull
|
||||
Collection<? extends Element> getArtifacts();
|
||||
}
|
||||
@@ -64,6 +64,8 @@ public interface ConversionContext {
|
||||
|
||||
ProjectLibrariesSettings getProjectLibrariesSettings() throws CannotConvertException;
|
||||
|
||||
ArtifactsSettings getArtifactsSettings() throws CannotConvertException;
|
||||
|
||||
@NotNull
|
||||
String expandPath(@NotNull String path);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,11 @@ public abstract class ProjectConverter {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ConversionProcessor<ArtifactsSettings> createArtifactsConverter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Collection<File> getAdditionalAffectedFiles() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.conversion.impl;
|
||||
|
||||
import com.intellij.conversion.ArtifactsSettings;
|
||||
import com.intellij.conversion.CannotConvertException;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public class ArtifactsSettingsImpl extends MultiFilesSettings implements ArtifactsSettings {
|
||||
protected ArtifactsSettingsImpl(@Nullable File projectFile,
|
||||
@Nullable File[] settingsFiles,
|
||||
@NotNull ConversionContextImpl context) throws CannotConvertException {
|
||||
super(projectFile, settingsFiles, context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<? extends Element> getArtifacts() {
|
||||
return getSettings("ArtifactManager", "artifact");
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,7 @@ public class ConversionContextImpl implements ConversionContext {
|
||||
private ComponentManagerSettings myProjectRootManagerSettings;
|
||||
private ComponentManagerSettingsImpl myModulesSettings;
|
||||
private ProjectLibrariesSettingsImpl myProjectLibrariesSettings;
|
||||
private ArtifactsSettingsImpl myArtifactsSettings;
|
||||
private ComponentManagerSettings myProjectFileVersionSettings;
|
||||
private final Set<String> myPerformedConversionIds;
|
||||
|
||||
@@ -465,20 +466,31 @@ public class ConversionContextImpl implements ConversionContext {
|
||||
@Override
|
||||
public ProjectLibrariesSettingsImpl getProjectLibrariesSettings() throws CannotConvertException {
|
||||
if (myProjectLibrariesSettings == null) {
|
||||
if (myStorageScheme == StorageScheme.DEFAULT) {
|
||||
myProjectLibrariesSettings = new ProjectLibrariesSettingsImpl(myProjectFile, null, this);
|
||||
}
|
||||
else {
|
||||
final File librariesDir = new File(mySettingsBaseDir, "libraries");
|
||||
final File[] files = librariesDir.exists() ? librariesDir.listFiles(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
return !file.isDirectory() && file.getName().endsWith(".xml");
|
||||
}
|
||||
}) : ArrayUtil.EMPTY_FILE_ARRAY;
|
||||
myProjectLibrariesSettings = new ProjectLibrariesSettingsImpl(null, files, this);
|
||||
}
|
||||
myProjectLibrariesSettings = myStorageScheme == StorageScheme.DEFAULT
|
||||
? new ProjectLibrariesSettingsImpl(myProjectFile, null, this)
|
||||
: new ProjectLibrariesSettingsImpl(null, getSettingsXmlFiles("libraries"), this);
|
||||
}
|
||||
return myProjectLibrariesSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArtifactsSettingsImpl getArtifactsSettings() throws CannotConvertException {
|
||||
if (myArtifactsSettings == null) {
|
||||
myArtifactsSettings = myStorageScheme == StorageScheme.DEFAULT
|
||||
? new ArtifactsSettingsImpl(myProjectFile, null, this)
|
||||
: new ArtifactsSettingsImpl(null, getSettingsXmlFiles("artifacts"), this);
|
||||
}
|
||||
return myArtifactsSettings;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private File[] getSettingsXmlFiles(@NotNull String dirName) {
|
||||
final File librariesDir = new File(mySettingsBaseDir, dirName);
|
||||
return librariesDir.exists() ? librariesDir.listFiles(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
return !file.isDirectory() && file.getName().endsWith(".xml");
|
||||
}
|
||||
}) : ArrayUtil.EMPTY_FILE_ARRAY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,10 +35,12 @@ public class ConversionRunner {
|
||||
private boolean myProcessWorkspaceFile;
|
||||
private boolean myProcessRunConfigurations;
|
||||
private boolean myProcessProjectLibraries;
|
||||
private boolean myArtifacts;
|
||||
private final List<File> myModulesFilesToProcess = new ArrayList<File>();
|
||||
private final ProjectConverter myConverter;
|
||||
private final ConversionProcessor<RunManagerSettings> myRunConfigurationsConverter;
|
||||
private final ConversionProcessor<ProjectLibrariesSettings> myProjectLibrariesConverter;
|
||||
private final ConversionProcessor<ArtifactsSettings> myArtifactsConverter;
|
||||
|
||||
public ConversionRunner(ConverterProvider provider, ConversionContextImpl context) {
|
||||
myProvider = provider;
|
||||
@@ -49,6 +51,7 @@ public class ConversionRunner {
|
||||
myWorkspaceConverter = myConverter.createWorkspaceFileConverter();
|
||||
myRunConfigurationsConverter = myConverter.createRunConfigurationsConverter();
|
||||
myProjectLibrariesConverter = myConverter.createProjectLibrariesConverter();
|
||||
myArtifactsConverter = myConverter.createArtifactsConverter();
|
||||
}
|
||||
|
||||
public boolean isConversionNeeded() throws CannotConvertException {
|
||||
@@ -75,6 +78,9 @@ public class ConversionRunner {
|
||||
myProcessProjectLibraries = myProjectLibrariesConverter != null
|
||||
&& myProjectLibrariesConverter.isConversionNeeded(myContext.getProjectLibrariesSettings());
|
||||
|
||||
myArtifacts = myArtifactsConverter != null
|
||||
&& myArtifactsConverter.isConversionNeeded(myContext.getArtifactsSettings());
|
||||
|
||||
return myProcessProjectFile ||
|
||||
myProcessWorkspaceFile ||
|
||||
myProcessRunConfigurations ||
|
||||
@@ -108,6 +114,9 @@ public class ConversionRunner {
|
||||
if (myProcessProjectLibraries) {
|
||||
affectedFiles.addAll(myContext.getProjectLibrariesSettings().getAffectedFiles());
|
||||
}
|
||||
if (myArtifacts) {
|
||||
affectedFiles.addAll(myContext.getArtifactsSettings().getAffectedFiles());
|
||||
}
|
||||
}
|
||||
catch (CannotConvertException ignored) {
|
||||
}
|
||||
@@ -143,6 +152,9 @@ public class ConversionRunner {
|
||||
myProjectLibrariesConverter.preProcess(myContext.getProjectLibrariesSettings());
|
||||
}
|
||||
|
||||
if (myArtifacts) {
|
||||
myArtifactsConverter.preProcess(myContext.getArtifactsSettings());
|
||||
}
|
||||
myConverter.preProcessingFinished();
|
||||
}
|
||||
|
||||
@@ -166,6 +178,10 @@ public class ConversionRunner {
|
||||
if (myProcessProjectLibraries) {
|
||||
myProjectLibrariesConverter.process(myContext.getProjectLibrariesSettings());
|
||||
}
|
||||
|
||||
if (myArtifacts) {
|
||||
myArtifactsConverter.process(myContext.getArtifactsSettings());
|
||||
}
|
||||
myConverter.processingFinished();
|
||||
}
|
||||
|
||||
@@ -189,6 +205,10 @@ public class ConversionRunner {
|
||||
if (myProcessProjectLibraries) {
|
||||
myProjectLibrariesConverter.postProcess(myContext.getProjectLibrariesSettings());
|
||||
}
|
||||
|
||||
if (myArtifacts) {
|
||||
myArtifactsConverter.postProcess(myContext.getArtifactsSettings());
|
||||
}
|
||||
myConverter.postProcessingFinished();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.conversion.impl;
|
||||
|
||||
import com.intellij.conversion.CannotConvertException;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
class MultiFilesSettings {
|
||||
private SettingsXmlFile myProjectFile;
|
||||
private final List<SettingsXmlFile> mySettingsFiles;
|
||||
|
||||
protected MultiFilesSettings(@Nullable File projectFile, @Nullable File[] settingsFiles, @NotNull ConversionContextImpl context)
|
||||
throws CannotConvertException {
|
||||
if (projectFile == null && settingsFiles == null) {
|
||||
throw new IllegalArgumentException("Either project file or settings files should be not null");
|
||||
}
|
||||
|
||||
if (projectFile != null && projectFile.exists()) {
|
||||
myProjectFile = context.getOrCreateFile(projectFile);
|
||||
}
|
||||
mySettingsFiles = new ArrayList<SettingsXmlFile>();
|
||||
|
||||
if (settingsFiles != null) {
|
||||
for (File file : settingsFiles) {
|
||||
mySettingsFiles.add(context.getOrCreateFile(file));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Collection<? extends Element> getSettings(@NotNull String componentName, @NotNull String tagName) {
|
||||
final List<Element> result = new ArrayList<Element>();
|
||||
if (myProjectFile != null) {
|
||||
result.addAll(JDOMUtil.getChildren(myProjectFile.findComponent(componentName), tagName));
|
||||
}
|
||||
|
||||
for (SettingsXmlFile file : mySettingsFiles) {
|
||||
result.addAll(JDOMUtil.getChildren(file.getRootElement(), tagName));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Collection<File> getAffectedFiles() {
|
||||
final List<File> files = new ArrayList<File>();
|
||||
|
||||
if (myProjectFile != null) {
|
||||
files.add(myProjectFile.getFile());
|
||||
}
|
||||
for (SettingsXmlFile file : mySettingsFiles) {
|
||||
files.add(file.getFile());
|
||||
}
|
||||
return files;
|
||||
}
|
||||
}
|
||||
+3
-42
@@ -19,62 +19,23 @@ package com.intellij.conversion.impl;
|
||||
import com.intellij.conversion.CannotConvertException;
|
||||
import com.intellij.conversion.ProjectLibrariesSettings;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ProjectLibrariesSettingsImpl implements ProjectLibrariesSettings {
|
||||
private SettingsXmlFile myProjectFile;
|
||||
private final List<SettingsXmlFile> myLibrariesFiles;
|
||||
public class ProjectLibrariesSettingsImpl extends MultiFilesSettings implements ProjectLibrariesSettings {
|
||||
|
||||
public ProjectLibrariesSettingsImpl(@Nullable File projectFile, @Nullable File[] librariesFiles,
|
||||
ConversionContextImpl context) throws CannotConvertException {
|
||||
if (projectFile == null && librariesFiles == null) {
|
||||
throw new IllegalArgumentException("Either project file or libraries files should be not null");
|
||||
}
|
||||
|
||||
if (projectFile != null && projectFile.exists()) {
|
||||
myProjectFile = context.getOrCreateFile(projectFile);
|
||||
}
|
||||
|
||||
myLibrariesFiles = new ArrayList<SettingsXmlFile>();
|
||||
if (librariesFiles != null) {
|
||||
for (File file : librariesFiles) {
|
||||
myLibrariesFiles.add(context.getOrCreateFile(file));
|
||||
}
|
||||
}
|
||||
super(projectFile, librariesFiles, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<? extends Element> getProjectLibraries() {
|
||||
final List<Element> result = new ArrayList<Element>();
|
||||
if (myProjectFile != null) {
|
||||
result.addAll(JDOMUtil.getChildren(myProjectFile.findComponent("libraryTable"), LibraryImpl.ELEMENT));
|
||||
}
|
||||
|
||||
for (SettingsXmlFile file : myLibrariesFiles) {
|
||||
result.addAll(JDOMUtil.getChildren(file.getRootElement(), LibraryImpl.ELEMENT));
|
||||
}
|
||||
|
||||
return result;
|
||||
return getSettings("libraryTable", LibraryImpl.ELEMENT);
|
||||
}
|
||||
|
||||
public Collection<File> getAffectedFiles() {
|
||||
final List<File> files = new ArrayList<File>();
|
||||
if (myProjectFile != null) {
|
||||
files.add(myProjectFile.getFile());
|
||||
}
|
||||
for (SettingsXmlFile file : myLibrariesFiles) {
|
||||
files.add(file.getFile());
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user