use of com.maddyhome.idea.copyright.CopyrightProfile in project intellij-community by JetBrains.
the class UpdateCopyrightProcessor method preprocessFile.
protected Runnable preprocessFile(final PsiFile file, final boolean allowReplacement) throws IncorrectOperationException {
VirtualFile vfile = file.getVirtualFile();
if (vfile == null)
return EmptyRunnable.getInstance();
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
if (progressIndicator != null) {
progressIndicator.setText2(vfile.getPresentableUrl());
}
Module mod = module;
if (module == null) {
mod = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(vfile);
}
if (mod == null)
return EmptyRunnable.getInstance();
CopyrightProfile opts = CopyrightManager.getInstance(project).getCopyrightOptions(file);
if (opts != null && FileTypeUtil.isSupportedFile(file)) {
logger.debug("process " + file);
final UpdateCopyright update = UpdateCopyrightFactory.createUpdateCopyright(project, mod, file, opts);
if (update == null)
return EmptyRunnable.getInstance();
update.prepare();
if (update instanceof UpdatePsiFileCopyright && !((UpdatePsiFileCopyright) update).hasUpdates())
return EmptyRunnable.getInstance();
return () -> {
try {
if (update instanceof UpdatePsiFileCopyright) {
((UpdatePsiFileCopyright) update).complete(allowReplacement);
} else {
update.complete();
}
} catch (Exception e) {
logger.error(e);
}
};
} else {
return EmptyRunnable.getInstance();
}
}
use of com.maddyhome.idea.copyright.CopyrightProfile in project intellij-community by JetBrains.
the class ExternalOptionHelper method loadOptions.
@Nullable
public static List<CopyrightProfile> loadOptions(File file) {
try {
List<CopyrightProfile> profiles = new ArrayList<>();
Element root = JDOMUtil.load(file);
if (root.getName().equals("component")) {
final Element copyrightElement = root.getChild("copyright");
if (copyrightElement != null)
extractNewNoticeAndKeyword(copyrightElement, profiles);
} else {
for (Element component : root.getChildren("component")) {
String name = component.getAttributeValue("name");
if (name.equals("CopyrightManager")) {
for (Object o : component.getChildren("copyright")) {
extractNewNoticeAndKeyword((Element) o, profiles);
}
} else if (name.equals("copyright")) {
extractNoticeAndKeyword(component, profiles);
}
}
}
return profiles;
} catch (Exception e) {
logger.info(e);
Messages.showErrorDialog(e.getMessage(), "Import Failure");
return null;
}
}
use of com.maddyhome.idea.copyright.CopyrightProfile in project intellij-community by JetBrains.
the class CopyrightProfilesPanel method getAllProfiles.
public Map<String, CopyrightProfile> getAllProfiles() {
final Map<String, CopyrightProfile> profiles = new HashMap<>();
if (!myInitialized.get()) {
for (CopyrightProfile profile : myManager.getCopyrights()) {
profiles.put(profile.getName(), profile);
}
} else {
for (int i = 0; i < myRoot.getChildCount(); i++) {
MyNode node = (MyNode) myRoot.getChildAt(i);
final CopyrightProfile copyrightProfile = ((CopyrightConfigurable) node.getConfigurable()).getEditableObject();
profiles.put(copyrightProfile.getName(), copyrightProfile);
}
}
return profiles;
}
use of com.maddyhome.idea.copyright.CopyrightProfile in project intellij-community by JetBrains.
the class ProjectSettingsPanel method reloadCopyrightProfiles.
public void reloadCopyrightProfiles() {
final DefaultComboBoxModel boxModel = (DefaultComboBoxModel) myProfilesComboBox.getModel();
boxModel.removeAllElements();
boxModel.addElement(null);
for (CopyrightProfile profile : myProfilesModel.getAllProfiles().values()) {
boxModel.addElement(profile);
}
}
use of com.maddyhome.idea.copyright.CopyrightProfile in project intellij-community by JetBrains.
the class AbstractFileProcessor method findFiles.
private static void findFiles(List<PsiFile> files, PsiDirectory directory, boolean subdirs) {
final Project project = directory.getProject();
PsiFile[] locals = directory.getFiles();
for (PsiFile local : locals) {
CopyrightProfile opts = CopyrightManager.getInstance(project).getCopyrightOptions(local);
if (opts != null && FileTypeUtil.isSupportedFile(local)) {
files.add(local);
}
}
if (subdirs) {
for (PsiDirectory dir : directory.getSubdirectories()) {
findFiles(files, dir, true);
}
}
}
Aggregations