private static void removeOldProjectData(@NotNull final Project project) { final ModifiableModuleModel moduleModel = ModuleManager.getInstance(project).getModifiableModel(); for (Module module : moduleModel.getModules()) { moduleModel.disposeModule(module); } final LibraryTable.ModifiableModel libraryModel = ProjectLibraryTable.getInstance(project).getModifiableModel(); for (Library library : libraryModel.getLibraries()) { libraryModel.removeLibrary(library); } ApplicationManager.getApplication().runWriteAction(() -> { moduleModel.commit(); libraryModel.commit(); }); final GradleSupport gradleSupport = GradleSupport.getInstance(); if (gradleSupport != null) { gradleSupport.clearLinkedProjectSettings(project); } final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(project); for (AntBuildFile antBuildFile : antConfiguration.getBuildFiles()) { antConfiguration.removeBuildFile(antBuildFile); } }
public final AntDomProject getContextAntProject() { final AntConfigurationBase antConfig = AntConfigurationBase.getInstance(getManager().getProject()); final XmlElement xmlElement = getXmlElement(); if (xmlElement == null) { return getAntProject(); } PsiFile containingFile = xmlElement.getContainingFile(); if (containingFile != null) { containingFile = containingFile.getOriginalFile(); } if (!(containingFile instanceof XmlFile)) { return getAntProject(); } final XmlFile contextFile = antConfig.getEffectiveContextFile(((XmlFile)containingFile)); if (contextFile == null) { return getAntProject(); } return AntSupport.getAntDomProject(contextFile); }
@NotNull public final ClassLoader getClassLoader() { ClassLoader loader = myClassLoader; if (loader == null) { final XmlTag tag = getXmlTag(); final PsiFile containingFile = tag.getContainingFile(); final AntBuildFileImpl buildFile = (AntBuildFileImpl)AntConfigurationBase.getInstance(containingFile.getProject()).getAntBuildFile(containingFile); if (buildFile != null) { loader = buildFile.getClassLoader(); } else { AntInstallation antInstallation = getAntInstallation(); loader = antInstallation.getClassLoader(); } myClassLoader = loader; } return loader; }
@Nullable public final Sdk getTargetJdk() { final XmlTag tag = getXmlTag(); final PsiFile containingFile = tag.getContainingFile(); final AntBuildFileImpl buildFile = (AntBuildFileImpl)AntConfigurationBase.getInstance(containingFile.getProject()).getAntBuildFile(containingFile); if (buildFile != null) { String jdkName = AntBuildFileImpl.CUSTOM_JDK_NAME.get(buildFile.getAllOptions()); if (jdkName == null || jdkName.length() == 0) { jdkName = AntConfigurationImpl.DEFAULT_JDK_NAME.get(buildFile.getAllOptions()); } if (jdkName != null && jdkName.length() > 0) { return ProjectJdkTable.getInstance().findJdk(jdkName); } } return ProjectRootManager.getInstance(tag.getProject()).getProjectSdk(); }
private Map<String, String> getProperties() { Map<String, String> properties = myProperties; if (properties == null) { final ReflectedProject reflected = ReflectedProject.getProject(getClassLoader()); Map<String, String> externals = Collections.emptyMap(); final PsiFile containingFile = getXmlTag().getContainingFile(); if (containingFile != null) { final AntBuildFileImpl buildFile = (AntBuildFileImpl)AntConfigurationBase.getInstance(containingFile.getProject()).getAntBuildFile(containingFile); if (buildFile != null) { externals = buildFile.getExternalProperties(); } } myProperties = (properties = loadPredefinedProperties(reflected.getProperties(), externals)); } return properties; }
@NotNull public final ClassLoader getClassLoader() { ClassLoader loader = myClassLoader; if (loader == null) { final XmlTag tag = getXmlTag(); final PsiFile containingFile = tag.getContainingFile(); final AntBuildFileImpl buildFile = (AntBuildFileImpl)AntConfigurationBase.getInstance(containingFile.getProject()).getAntBuildFile(containingFile); if (buildFile != null) { loader = buildFile.getClassLoader(); } else { Sdk antInstallation = getAntInstallation(); loader = AntSdkClassLoaderUtil.getClassLoader(antInstallation); } myClassLoader = loader; } return loader; }
@Nullable public final Sdk getTargetJdk() { final XmlTag tag = getXmlTag(); final PsiFile containingFile = tag.getContainingFile(); final AntBuildFileImpl buildFile = (AntBuildFileImpl)AntConfigurationBase.getInstance(containingFile.getProject()).getAntBuildFile(containingFile); if (buildFile != null) { String jdkName = AntBuildFileImpl.CUSTOM_JDK_NAME.get(buildFile.getAllOptions()); if (jdkName == null || jdkName.length() == 0) { jdkName = AntConfigurationImpl.DEFAULT_JDK_NAME.get(buildFile.getAllOptions()); } if (jdkName != null && jdkName.length() > 0) { return SdkTable.getInstance().findSdk(jdkName); } } return AntJavaSdkUtil.getBundleSdk(); }
@NotNull public AnAction[] getChildren(@Nullable AnActionEvent e) { if (e == null) return AnAction.EMPTY_ARRAY; Project project = e.getProject(); if (project == null) return AnAction.EMPTY_ARRAY; final List<AnAction> children = new ArrayList<AnAction>(); final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(project); for (final AntBuildFile buildFile : antConfiguration.getBuildFiles()) { final String name = buildFile.getPresentableName(); DefaultActionGroup subgroup = new DefaultActionGroup(); subgroup.getTemplatePresentation().setText(name, false); subgroup.setPopup(true); fillGroup(buildFile, subgroup, antConfiguration); if (subgroup.getChildrenCount() > 0) { children.add(subgroup); } } return children.toArray(new AnAction[children.size()]); }
@Override public AntBuildFile[] getFilesForGroup(@NotNull AntBuildFileGroup group) { final List<VirtualFile> virtualFiles = myFileGroupList.get(group); if (virtualFiles == null || virtualFiles.isEmpty()) { return AntBuildFile.EMPTY_ARRAY; } List<AntBuildFile> files = new ArrayList<AntBuildFile>(); final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(myProject); final PsiManager manager = PsiManager.getInstance(myProject); for (VirtualFile virtualFile : virtualFiles) { final PsiFile file = manager.findFile(virtualFile); if (!(file instanceof XmlFile)) { continue; } final AntBuildFileBase antBuildFile = antConfiguration.getAntBuildFile(file); if (antBuildFile == null) { continue; } files.add(antBuildFile); } return files.toArray(new AntBuildFile[files.size()]); }
@Override public void configure( @NotNull HybrisProjectDescriptor hybrisProjectDescriptor, @NotNull final List<HybrisModuleDescriptor> allModules, @NotNull final Project project ) { this.hybrisProjectDescriptor = hybrisProjectDescriptor; parseModules(allModules); if (platformDescriptor == null) { return; } final File platformDir = platformDescriptor.getRootDirectory(); createAntInstallation(platformDir); if (antInstallation == null) { return; } createAntClassPath(platformDir); AntConfigurationBase.getInstance(project).setFilterTargets(true); antConfiguration = AntConfigurationBase.getInstance(project); final AntBuildFileBase buildFile = registerAntInstallation(platformDir, platformDir, desirablePlatformTargets); customHybrisModuleDescriptorList.forEach( e -> registerAntInstallation(platformDir, e.getRootDirectory(), desirableCustomTargets) ); saveAntInstallation(antInstallation); removeMake(project); createMetaTargets(buildFile); final ToolWindowManager manager = ToolWindowManager.getInstance(project); final ToolWindow window = manager.getToolWindow("Ant Build"); window.show(null); }
private void triggerCleanAll(final Project project) { final HybrisProjectSettings yProjectSettings = HybrisProjectSettingsComponent.getInstance(project).getState(); final File platformDir = new File(project.getBasePath() + "/" + yProjectSettings.getHybrisDirectory() + PLATFORM_MODULE_PREFIX); final VirtualFile vfPlatformDir = VfsUtil.findFileByIoFile(platformDir, true); final VirtualFile vfBuildFile = VfsUtil.findRelativeFile(vfPlatformDir, HybrisConstants.ANT_BUILD_XML); if (vfBuildFile == null) { return; } final PsiFile psiBuildFile = PsiManager.getInstance(project).findFile(vfBuildFile); if (psiBuildFile == null) { return; } final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(project); final AntBuildFileBase antBuildFile = antConfiguration.getAntBuildFile(psiBuildFile); if (antBuildFile != null) { ExecutionHandler.runBuild( antBuildFile, antCleanAll, null, getDataContext(project), Collections.emptyList(), AntBuildListener.NULL ); } }
public SaveMetaTargetDialog(final Component parent, final ExecuteCompositeTargetEvent event, final AntConfigurationBase antConfiguration, final AntBuildFile buildFile) { super(parent, true); myInitialEvent = event; myAntConfiguration = antConfiguration; myBuildFile = buildFile; setModal(true); init(); }
public void update(@NotNull AnActionEvent e) { final DataContext dataContext = e.getDataContext(); final Presentation presentation = e.getPresentation(); final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project != null) { final VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); if (files != null && files.length > 0) { for (VirtualFile file : files) { final PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (!(psiFile instanceof XmlFile)) { continue; } final XmlFile xmlFile = (XmlFile)psiFile; final XmlDocument document = xmlFile.getDocument(); if (document == null) { continue; } final XmlTag rootTag = document.getRootTag(); if (rootTag == null) { continue; } if (!"project".equals(rootTag.getName())) { continue; } if (AntConfigurationBase.getInstance(project).getAntBuildFile(psiFile) != null) { continue; } // found at least one candidate file enable(presentation); return; } } } disable(presentation); }
public TreeView(final Project project, final AntBuildFile buildFile) { myProject = project; myBuildFile = buildFile; myAutoScrollToSourceHandler = new AutoScrollToSourceHandler() { protected boolean isAutoScrollMode() { return AntConfigurationBase.getInstance(myProject).isAutoScrollToSource(); } protected void setAutoScrollMode(boolean state) { AntConfigurationBase.getInstance(myProject).setAutoScrollToSource(state); } }; myPanel = createPanel(); }
@Override public boolean execute(CompileContext compileContext) { final DataContext dataContext = SimpleDataContext.getProjectContext(compileContext.getProject()); final AntConfiguration config = AntConfiguration.getInstance(compileContext.getProject()); ((AntConfigurationBase)config).ensureInitialized(); return config.executeTargetBeforeCompile(dataContext); }
@Override public boolean execute(CompileContext compileContext) { final DataContext dataContext = SimpleDataContext.getProjectContext(compileContext.getProject()); final AntConfiguration config = AntConfiguration.getInstance(compileContext.getProject()); ((AntConfigurationBase)config).ensureInitialized(); return config.executeTargetAfterCompile(dataContext); }
public void setSelected(AnActionEvent event, boolean state) { final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(myProject); if (state) { final AntBuildFileBase buildFile = (AntBuildFileBase)((myTarget instanceof MetaTarget) ? ((MetaTarget)myTarget).getBuildFile() : myTarget.getModel().getBuildFile()); antConfiguration.setTargetForEvent(buildFile, myTarget.getName(), myExecutionEvent); } else { antConfiguration.clearTargetForEvent(myExecutionEvent); } myBuilder.queueUpdate(); }
public void actionPerformed(AnActionEvent e) { final AntBuildFile buildFile = getCurrentBuildFile(); final String[] targets = getTargetNamesFromPaths(myTree.getSelectionPaths()); final ExecuteCompositeTargetEvent event = new ExecuteCompositeTargetEvent(targets); final SaveMetaTargetDialog dialog = new SaveMetaTargetDialog(myTree, event, AntConfigurationBase.getInstance(myProject), buildFile); dialog.setTitle(e.getPresentation().getText()); dialog.show(); if (dialog.isOK()) { myBuilder.queueUpdate(); myTree.repaint(); } }
private void doAction() { final TreePath[] paths = myTree.getSelectionPaths(); if (paths == null) { return; } try { // try to remove build file if (paths.length == 1) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode)paths[0].getLastPathComponent(); if (node.getUserObject() instanceof AntBuildFileNodeDescriptor) { final AntBuildFileNodeDescriptor descriptor = (AntBuildFileNodeDescriptor)node.getUserObject(); if (descriptor.getBuildFile().equals(getCurrentBuildFile())) { removeBuildFile(); return; } } } // try to remove meta targets final AntBuildTarget[] targets = getTargetObjectsFromPaths(paths); final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(myProject); for (final AntBuildTarget buildTarget : targets) { if (buildTarget instanceof MetaTarget) { for (final ExecutionEvent event : antConfiguration.getEventsForTarget(buildTarget)) { if (event instanceof ExecuteCompositeTargetEvent) { antConfiguration.clearTargetForEvent(event); } } } } } finally { myBuilder.queueUpdate(); myTree.repaint(); } }
public AbstractProperty.AbstractPropertyContainer getProperties(Project project) { return new CompositePropertyContainer(new AbstractProperty.AbstractPropertyContainer[]{ myProperties, AntConfigurationBase.getInstance(project).getProperties() }); }
public AntBuildFileImpl(final XmlFile antFile, final AntConfigurationBase configuration) { myVFile = antFile.getOriginalFile().getVirtualFile(); myProject = antFile.getProject(); myAntConfiguration = configuration; myWorkspaceOptions = new ExternalizablePropertyContainer(); myWorkspaceOptions.registerProperty(RUN_IN_BACKGROUND); myWorkspaceOptions.registerProperty(CLOSE_ON_NO_ERRORS); myWorkspaceOptions.registerProperty(TREE_VIEW); myWorkspaceOptions.registerProperty(VERBOSE); myWorkspaceOptions.registerProperty(TARGET_FILTERS, "filter", NewInstanceFactory.fromClass(TargetFilter.class)); myWorkspaceOptions.rememberKey(RUN_WITH_ANT); myProjectOptions = new ExternalizablePropertyContainer(); myProjectOptions.registerProperty(MAX_HEAP_SIZE); myProjectOptions.registerProperty(MAX_STACK_SIZE); myProjectOptions.registerProperty(CUSTOM_JDK_NAME); myProjectOptions.registerProperty(ANT_COMMAND_LINE_PARAMETERS); myProjectOptions.registerProperty(ANT_PROPERTIES, "property", NewInstanceFactory.fromClass(BuildFileProperty.class)); myProjectOptions.registerProperty(ADDITIONAL_CLASSPATH, "entry", SinglePathEntry.EXTERNALIZER); myProjectOptions.registerProperty(ANT_REFERENCE, AntReference.EXTERNALIZER); myAllOptions = new CompositePropertyContainer(new AbstractProperty.AbstractPropertyContainer[]{ myWorkspaceOptions, myProjectOptions, GlobalAntConfiguration.getInstance().getProperties(getProject()) }); myClassloaderHolder = new AntBuildFileClassLoaderHolder(myAllOptions); }
@Nullable private static Pair<AntBuildFileBase, AntDomTarget> findAntTarget(@NotNull AnActionEvent e) { final DataContext dataContext = e.getDataContext(); final Editor editor = CommonDataKeys.EDITOR.getData(dataContext); final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null || editor == null) { return null; } final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext); if (file == null) { return null; } final PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (!(psiFile instanceof XmlFile)) { return null; } final XmlFile xmlFile = (XmlFile)psiFile; final AntBuildFileBase antFile = AntConfigurationBase.getInstance(project).getAntBuildFile(xmlFile); if (antFile == null) { return null; } final PsiElement element = xmlFile.findElementAt(editor.getCaretModel().getOffset()); if (element == null) { return null; } final XmlTag xmlTag = PsiTreeUtil.getParentOfType(element, XmlTag.class); if (xmlTag == null) { return null; } DomElement dom = AntSupport.getAntDomElement(xmlTag); while (dom != null && !(dom instanceof AntDomTarget)) { dom = dom.getParent(); } final AntDomTarget domTarget = (AntDomTarget)dom; if (domTarget == null) { return null; } return Pair.create(antFile, domTarget); }
public AbstractProperty.AbstractPropertyContainer getProperties(Project project) { return new CompositePropertyContainer(new AbstractProperty.AbstractPropertyContainer[]{ myProperties, AntConfigurationBase.getInstance(project).getProperties()}); }
public void testAntFilePropertyWithContexts() throws Exception { final PsiReference refImporting = configureByFile("PropertyAntFileImporting.ant"); final PsiFile importing = refImporting.getElement().getContainingFile(); assertTrue(importing instanceof XmlFile); final VirtualFile vFile = importing.getVirtualFile(); assertTrue(vFile != null); final PsiReference refImported = configureByFile("PropertyAntFileImported.ant", vFile.getParent()); final PsiFile imported = refImported.getElement().getContainingFile(); assertTrue(imported instanceof XmlFile); final VirtualFile importedVFile = imported.getVirtualFile(); assertTrue(importedVFile != null); AntConfigurationBase.getInstance(getProject()).setContextFile((XmlFile)imported, (XmlFile)importing); assertTrue(refImported.resolve() != null); assertTrue(refImporting.resolve() != null); }
public void update(AnActionEvent e) { final DataContext dataContext = e.getDataContext(); final Presentation presentation = e.getPresentation(); final Project project = PlatformDataKeys.PROJECT.getData(dataContext); if (project == null) { disable(presentation); return; } final VirtualFile file = PlatformDataKeys.VIRTUAL_FILE.getData(dataContext); if (file == null) { disable(presentation); return; } final PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (!(psiFile instanceof XmlFile)) { disable(presentation); return; } final XmlFile xmlFile = (XmlFile)psiFile; final XmlDocument document = xmlFile.getDocument(); if (document == null) { disable(presentation); return; } final XmlTag rootTag = document.getRootTag(); if (rootTag == null) { disable(presentation); return; } if (!"project".equals(rootTag.getName())) { disable(presentation); return; } if (AntConfigurationBase.getInstance(project).getAntBuildFile(psiFile) != null) { disable(presentation); return; } enable(presentation); }
@Nullable private static Pair<AntBuildFileBase, AntDomTarget> findAntTarget(@NotNull AnActionEvent e) { final DataContext dataContext = e.getDataContext(); final Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); final Project project = PlatformDataKeys.PROJECT.getData(dataContext); if (project == null || editor == null) { return null; } final VirtualFile file = PlatformDataKeys.VIRTUAL_FILE.getData(dataContext); if (file == null) { return null; } final PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (!(psiFile instanceof XmlFile)) { return null; } final XmlFile xmlFile = (XmlFile)psiFile; final AntBuildFileBase antFile = AntConfigurationBase.getInstance(project).getAntBuildFile(xmlFile); if (antFile == null) { return null; } final PsiElement element = xmlFile.findElementAt(editor.getCaretModel().getOffset()); if (element == null) { return null; } final XmlTag xmlTag = PsiTreeUtil.getParentOfType(element, XmlTag.class); if (xmlTag == null) { return null; } DomElement dom = AntSupport.getAntDomElement(xmlTag); while (dom != null && !(dom instanceof AntDomTarget)) { dom = dom.getParent(); } final AntDomTarget domTarget = (AntDomTarget)dom; if (domTarget == null) { return null; } return Pair.create(antFile, domTarget); }
public boolean isSelected(AnActionEvent event) { final Project project = myProject; return project != null && AntConfigurationBase.getInstance(project).isFilterTargets(); }
public boolean isSelected(AnActionEvent event) { final Project project = myProject; return project != null && AntConfigurationBase.getInstance(project).isModuleGrouping(); }