Java Code Examples for org.netbeans.modules.maven.api.NbMavenProject#getMavenProject()
The following examples show how to use
org.netbeans.modules.maven.api.NbMavenProject#getMavenProject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java From netbeans with Apache License 2.0 | 6 votes |
private static Set<String> collectClasspaths(Project prj) throws DependencyResolutionRequiredException { Set<String> toRet = new HashSet<String>(); NbMavenProject watcher = prj.getLookup().lookup(NbMavenProject.class); MavenProject mproject = watcher.getMavenProject(); //TODO this ought to be really configurable based on what class gets debugged. toRet.addAll(mproject.getTestClasspathElements()); //for poms also include all module projects recursively.. boolean isPom = NbMavenProject.TYPE_POM.equals(watcher.getPackagingType()); if (isPom) { ProjectContainerProvider subs = prj.getLookup().lookup(ProjectContainerProvider.class); ProjectContainerProvider.Result res = subs.getContainedProjects(); for (Project pr : res.getProjects()) { toRet.addAll(collectClasspaths(pr)); } } return toRet; }
Example 2
Source File: SearchClassDependencyInRepo.java From netbeans with Apache License 2.0 | 6 votes |
private Artifact getArtifact(NbMavenProject mavProj, List<NBVersionInfo> nbvis, boolean isTestSource) { MavenProject mp = mavProj.getMavenProject(); List<Artifact> arts = new LinkedList<Artifact>(isTestSource ? mp.getTestArtifacts() : mp.getCompileArtifacts()); for (NBVersionInfo info : nbvis) { for (Artifact a : arts) { if (a.getGroupId() != null && a.getGroupId().equals(info.getGroupId())) { if (a.getArtifactId() != null && a.getArtifactId().equals(info.getArtifactId())) { String scope = a.getScope(); if ("compile".equals(scope) || "test".equals(scope)) { // NOI18N return a; } } } } } return null; }
Example 3
Source File: CommandLineOutputHandler.java From netbeans with Apache License 2.0 | 6 votes |
@Override public @CheckForNull NbMavenProject find(@NonNull Project root) { // XXX EventSpy (#194090) would make this more reliable and efficient for (Project module : root.getLookup().lookup(ProjectContainerProvider.class).getContainedProjects().getProjects()) { if (Thread.interrupted()) { break; } NbMavenProject nbmp = module.getLookup().lookup(NbMavenProject.class); if (nbmp == null) { continue; } MavenProject mp = nbmp.getMavenProject(); if (firstFailure.equals(mp.getName())) { return nbmp; } } return null; }
Example 4
Source File: NbmWizardIterator.java From netbeans with Apache License 2.0 | 6 votes |
private static ModelOperation<POMModel> addNbmPluginOsgiParameter(File projFile) throws IOException { FileObject prjDir = FileUtil.toFileObject(projFile); if (prjDir != null) { FileObject pom = prjDir.getFileObject("pom.xml"); if (pom != null) { Project prj = ProjectManager.getDefault().findProject(prjDir); if (prj == null) { return null; // invalid? #184466 } NbMavenProject mav = prj.getLookup().lookup(NbMavenProject.class); return new AddOSGiParamToNbmPluginConfiguration(true, mav.getMavenProject()); } } //TODO report inability to create? or if the file doesn't exist, it was already //reported? return null; }
Example 5
Source File: Selenium2MavenSupportImpl.java From netbeans with Apache License 2.0 | 6 votes |
private FileObject getTestRoot(Project project) { NbMavenProject nbProject = project.getLookup().lookup(NbMavenProject.class); MavenProject mvp = nbProject.getMavenProject(); @SuppressWarnings("unchecked") List<String> testRoots = mvp.getTestCompileSourceRoots(); if (testRoots.isEmpty()) { return null; } File testRoot = new File(testRoots.get(0)); FileObject result = null; try { result = FileUtil.createFolder(testRoot); } catch (IOException ex) { Logger.getLogger(Selenium2MavenSupportImpl.class.getName()).log(Level.SEVERE, "Impossible to create test root file object", ex); //NOI18N } return result; }
Example 6
Source File: CosChecker.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected void projectClosed() { NbMavenProject prj = project.getLookup().lookup(NbMavenProject.class); if (prj != null) { prj.removePropertyChangeListener(listener); final MavenProject mvn = prj.getMavenProject(); //TODO do we want to reconsider this? RP.post(new Runnable() { @Override public void run() { // try { // //also delete the IDE generated class files now? // cleanGeneratedClassfiles(project); // } catch (IOException ex) { // LOG.log(Level.FINE, "Error cleaning up", ex); // } finally { deleteCoSTimeStamp(mvn, true); deleteCoSTimeStamp(mvn, false); // } } }); } }
Example 7
Source File: CosChecker.java From netbeans with Apache License 2.0 | 6 votes |
static void touchProject(Project project) { NbMavenProject prj = project.getLookup().lookup(NbMavenProject.class); if (prj != null) { MavenProject mvn = prj.getMavenProject(); if (RunUtils.isCompileOnSaveEnabled(project)) { touchCoSTimeStamp(mvn, false); touchCoSTimeStamp(mvn, true); } else { File f = getCoSFile(mvn, false); boolean doClean = f != null && f.exists(); if (doClean) { try { cleanGeneratedClassfiles(project); } catch (IOException ex) { LOG.log(Level.FINE, "Error cleaning up", ex); } } deleteCoSTimeStamp(mvn, false); deleteCoSTimeStamp(mvn, true); } } }
Example 8
Source File: Info.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void run() { try { final NbMavenProject nb = project.getLookup().lookup(NbMavenProject.class); if (!nb.isMavenProjectLoaded()) { nb.getMavenProject(); } String s = getDisplayName(nb); if(!s.equals(displayName)) { displayName = s; pcs.firePropertyChange(ProjectInformation.PROP_DISPLAY_NAME, null, null); } } finally { displayNameRunning = false; } }
Example 9
Source File: Utils.java From netbeans with Apache License 2.0 | 6 votes |
private static Set<String> collectSourceRoots(Project prj) { Set<String> toRet = new HashSet<String>(); NbMavenProject watcher = prj.getLookup().lookup(NbMavenProject.class); MavenProject mproject = watcher.getMavenProject(); //TODO this ought to be really configurable based on what class gets debugged. toRet.addAll(mproject.getTestCompileSourceRoots()); //for poms also include all module projects recursively.. boolean isPom = NbMavenProject.TYPE_POM.equals(watcher.getPackagingType()); if (isPom) { //only for pom is correct use of subprojectprovider ProjectContainerProvider subs = prj.getLookup().lookup(ProjectContainerProvider.class); ProjectContainerProvider.Result res = subs.getContainedProjects(); for (Project pr : res.getProjects()) { toRet.addAll(collectSourceRoots(pr)); } } return toRet; }
Example 10
Source File: WebModuleImpl.java From netbeans with Apache License 2.0 | 6 votes |
private Profile getProfileFromPOM(final Project project) { final NbMavenProject nbMavenProject = project.getLookup().lookup(NbMavenProject.class); if (nbMavenProject != null) { MavenProject mavenProject = nbMavenProject.getMavenProject(); List<Dependency> dependencies = mavenProject.getDependencies(); for (Map.Entry<Profile, List<DependencyDesc>> entry : javaEEMap.entrySet()) { for (DependencyDesc dependencyDesc : entry.getValue()) { Dependency dependency = checkForDependency(dependencies, dependencyDesc); if (dependency != null) { String version = dependency.getVersion(); if (dependencyDesc.version == null || (version != null && version.startsWith(dependencyDesc.version))) { return entry.getKey(); } } } } } return null; }
Example 11
Source File: ReloadAction.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { Lookup context = Utilities.actionsGlobalContext(); Project project = context.lookup(Project.class); if(project == null) { return; } NbMavenProject nbMavenProject = project.getLookup().lookup(NbMavenProject.class); MavenProject mavenProject = nbMavenProject.getMavenProject(); MicroApplication microApplication = MicroApplication.getInstance(project); if (microApplication == null) { StatusDisplayer.getDefault() .setStatusText(getMessage(ReloadAction.class, "ERR_Payara_Micro_Plugin_Not_Found", mavenProject.getArtifactId())); } else if (!isCompileOnSaveEnabled(microApplication.getProject())) { StatusDisplayer.getDefault() .setStatusText(getMessage(ReloadAction.class, "ERR_Compile_On_Save_Not_Enabled", mavenProject.getArtifactId())); } else { RP.post(() -> { String action = RunUtils.isCompileOnSaveEnabled(project) ? EXPLODE_ACTION : COMPILE_EXPLODE_ACTION; NetbeansActionMapping mapping = ActionToGoalUtils.getDefaultMapping(action, project); ModelRunConfig rc = new ModelRunConfig(project, mapping, mapping.getActionName(), null, Lookup.EMPTY, false); rc.setTaskDisplayName(getMessage(ReloadAction.class, "TXT_Reload", mavenProject.getArtifactId())); rc.getGoals().addAll(MicroActionsProvider.getGoals(action)); RunUtils.run(rc); }); } }
Example 12
Source File: MavenTestNGSupport.java From netbeans with Apache License 2.0 | 5 votes |
private boolean hasEffectiveDependency(String groupId, String artifactId, NbMavenProject prj) { MavenProject mp = prj.getMavenProject(); List<org.apache.maven.model.Dependency> dl = new ArrayList<org.apache.maven.model.Dependency>(); dl.addAll(mp.getDependencies()); org.apache.maven.model.DependencyManagement dm = mp.getDependencyManagement(); if (dm != null) { dl.addAll(dm.getDependencies()); } for (org.apache.maven.model.Dependency d : dl) { if (groupId.equals(d.getGroupId()) && artifactId.equals(d.getArtifactId())) { return true; } } return false; }
Example 13
Source File: MavenProjectSupport.java From netbeans with Apache License 2.0 | 5 votes |
private static String readSettingsFromPom(Project project, final String key) { final NbMavenProject nbMavenProject = project.getLookup().lookup(NbMavenProject.class); if (nbMavenProject != null) { MavenProject mavenProject = nbMavenProject.getMavenProject(); java.util.Properties properties = mavenProject.getProperties(); if (properties != null) { return properties.getProperty(key); } } return null; }
Example 14
Source File: SearchClassDependencyInRepo.java From netbeans with Apache License 2.0 | 5 votes |
private Collection<NBVersionInfo> filter(NbMavenProject mavProj, List<NBVersionInfo> nbvis, boolean test) { Map<String, NBVersionInfo> items = new HashMap<String, NBVersionInfo>(); //check dependency already added List<Dependency> dependencies = new ArrayList<Dependency>(); MavenProject prj = mavProj.getMavenProject(); if (test) { dependencies.addAll(prj.getTestDependencies()); } else { dependencies.addAll(prj.getDependencies()); } for (NBVersionInfo info : nbvis) { String key = info.getGroupId() + ":" + info.getArtifactId(); boolean b = items.containsKey(key); if (!b) { items.put(key, info); } for (Dependency dependency : dependencies) { //check group id and ArtifactId and Scope even if (dependency.getGroupId() != null && dependency.getGroupId().equals(info.getGroupId())) { if (dependency.getArtifactId() != null && dependency.getArtifactId().equals(info.getArtifactId())) { if (!test && dependency.getScope() != null && ("compile".equals(dependency.getScope()))) {//NOI18N return Collections.emptyList(); } } } } } List<NBVersionInfo> filterd = new ArrayList<NBVersionInfo>(items.values()); return filterd; }
Example 15
Source File: Info.java From netbeans with Apache License 2.0 | 4 votes |
@Messages({ "# {0} - dir basename", "LBL_misconfigured_project={0} [unloadable]", "# {0} - path to project", "TXT_Maven_project_at=Maven project at {0}" }) private String getDisplayName(NbMavenProject nb) { MavenProject pr = nb.getMavenProject(); if (NbMavenProject.isErrorPlaceholder(pr)) { return LBL_misconfigured_project(project.getProjectDirectory().getNameExt()); } String custom = project.getLookup().lookup(AuxiliaryProperties.class).get(Constants.HINT_DISPLAY_NAME, true); if (custom == null) { custom = NbPreferences.forModule(Info.class).get(MavenSettings.PROP_PROJECTNODE_NAME_PATTERN, null); } if (custom != null) { //we evaluate because of global property and property in nb-configuration.xml file. The pom.xml originating value should be already resolved. ExpressionEvaluator evaluator = PluginPropertyUtils.createEvaluator(project); try { Object s = evaluator.evaluate(custom); if (s != null) { //just make sure the name gets resolved String ss = s.toString().replace("${project.name)", "" + pr.getGroupId() + ":" + pr.getArtifactId()); return ss; } } catch (ExpressionEvaluationException ex) { //now just continue to the default processing LOG.log(Level.INFO, "bad display name expression:" + custom, ex); } } String toReturn = pr.getName(); if (toReturn == null) { String grId = pr.getGroupId(); String artId = pr.getArtifactId(); if (grId != null && artId != null) { toReturn = grId + ":" + artId; //NOI18N } else { toReturn = TXT_Maven_project_at(FileUtil.getFileDisplayName(project.getProjectDirectory())); } } return toReturn; }
Example 16
Source File: MicroApplication.java From netbeans with Apache License 2.0 | 4 votes |
public MicroApplication(Project project) { this.project = project; NbMavenProject nbMavenProject = project.getLookup().lookup(NbMavenProject.class); this.mavenProject = nbMavenProject.getMavenProject(); }
Example 17
Source File: AddDependencyPanel.java From netbeans with Apache License 2.0 | 4 votes |
/** Loads dependencies outside EQ thread, updates tab state in EQ */ @Override public void run() { Project[] prjs = OpenProjects.getDefault().getOpenProjects(); final List<Node> toRet = new ArrayList<Node>(); for (Project p : prjs) { if (p == project) { continue; } NbMavenProject mav = p.getLookup().lookup(NbMavenProject.class); if (mav != null) { boolean continueProjectIteration = false; MavenProject mavenProject = mav.getMavenProject(); Iterator<Dependency> iterator = project.getLookup().lookup(NbMavenProject.class).getMavenProject().getDependencies().iterator(); while (iterator.hasNext()) { Dependency dependency = iterator.next(); if (mavenProject.getGroupId().equals(dependency.getGroupId()) && mavenProject.getArtifactId().equals(dependency.getArtifactId())) { continueProjectIteration = true; break; } } if ( continueProjectIteration ) { continue; } LogicalViewProvider lvp = p.getLookup().lookup(LogicalViewProvider.class); toRet.add(createFilterWithDefaultAction(lvp.createLogicalView(), true)); } } Children.Array ch = new Children.Array(); ch.add(toRet.toArray(new Node[0])); Node root = new AbstractNode(ch); getExplorerManager().setRootContext(root); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { boolean opEmpty = toRet.isEmpty(); tabPane.setEnabledAt(1, !opEmpty); } }); }
Example 18
Source File: CPExtender.java From netbeans with Apache License 2.0 | 4 votes |
@Override protected boolean addProjects(final Project[] projects, SourceGroup sg, String classPathType) throws IOException, UnsupportedOperationException { final AtomicBoolean added = new AtomicBoolean(); final AtomicBoolean nonMavenError = new AtomicBoolean(); final String scope = findScope(sg, classPathType); ModelOperation<POMModel> operation = new ModelOperation<POMModel>() { public @Override void performOperation(POMModel model) { Set<Artifact> arts = project.getLookup().lookup(NbMavenProject.class).getMavenProject().getArtifacts(); for (Project prj: projects) { NbMavenProject nbprj = prj.getLookup().lookup(NbMavenProject.class); if (nbprj != null) { MavenProject mp = nbprj.getMavenProject(); String id = mp.getArtifact().getId(); for (Artifact a : arts) { if (a.getId().equals(id)) { //already there.. continue; } } Dependency dependency = ModelUtils.checkModelDependency(model, mp.getGroupId(), mp.getArtifactId(), true); dependency.setVersion(mp.getVersion()); if (scope != null) { dependency.setScope(scope); } added.set(true); } else { // unsupported usecase, not a maven project nonMavenError.set(true); } } } }; FileObject pom = project.getProjectDirectory().getFileObject(POM_XML);//NOI18N org.netbeans.modules.maven.model.Utilities.performPOMModelOperations(pom, Collections.singletonList(operation)); if (nonMavenError.get()) { //throw late to prevent the pom model to go bust eventually throw new UnsupportedOperationException("Attempting to add a non-Maven project dependency to a Maven project, not supported."); //NOI18N } return added.get(); }
Example 19
Source File: HyperlinkProviderImpl.java From netbeans with Apache License 2.0 | 4 votes |
private void calculateInfo(Token<XMLTokenId> token, TokenSequence<XMLTokenId> xml) { isText = token.id() == XMLTokenId.TEXT; if (isText) { ftokenOff = xml.offset(); ftext = token.text().toString(); if (projectFileObject != null && getPath(projectFileObject, ftext) != null) { xml.movePrevious(); token = xml.token(); if (token != null && token.id().equals(XMLTokenId.TAG) && TokenUtilities.equals(token.text(), ">")) {//NOI18N xml.movePrevious(); token = xml.token(); if (token != null && token.id().equals(XMLTokenId.TAG)) { if (TokenUtilities.equals(token.text(), "<module")) {//NOI18N if (!ftext.endsWith("/pom.xml")) { ftext += "/pom.xml"; //NOI18N } } } } } else { xml.movePrevious(); token = xml.token(); if (token != null && token.id().equals(XMLTokenId.TAG) && TokenUtilities.equals(token.text(), ">")) { //NOI18N xml.movePrevious(); String tokenString = xml.token().text().toString(); if ("<artifactId".equals(tokenString) || //NOI18N "<groupId".equals(tokenString) || //NOI18N "<type".equals(tokenString) || //NOI18N ("<version".equals(tokenString) && !ftext.startsWith("${"))) { resetSequenceToDependencytagToken(xml); if (TokenUtilities.equals(xml.token().text(), "<dependency")) { //NOI18N while (!TokenUtilities.equals(xml.token().text(), "</dependency")) { //NOI18N switch (xml.token().text().toString()) { case "<artifactId": moveToXmlTokenById(xml, XMLTokenId.TEXT); token = xml.token(); artifactId = token.text().toString(); break; case "<groupId": moveToXmlTokenById(xml, XMLTokenId.TEXT); token = xml.token(); groupId = token.text().toString(); break; case "<version": moveToXmlTokenById(xml, XMLTokenId.TEXT); token = xml.token(); if (TokenUtilities.startsWith(token.text(), "${")) { //NOI18N Project nbprj = getProject(doc); if (nbprj != null) { try { version = (String) PluginPropertyUtils.createEvaluator(nbprj).evaluate(token.text().toString()); } catch (ExpressionEvaluationException eee) { LOG.log(Level.INFO, "Unable to evaluate property: " + token.text().toString(), eee); } } } else { version = token.text().toString(); } break; case "<type" : moveToXmlTokenById(xml, XMLTokenId.TEXT); token = xml.token(); type = token.text().toString(); break; } xml.moveNext(); moveToXmlTokenById(xml, XMLTokenId.TAG); } // handle cases where the version element is covered in a // parent pom/dependenciesManagement if (version == null) { NbMavenProject projectForDocument = getNbMavenProject(doc); if (projectForDocument != null) { MavenProject mavenProject = projectForDocument.getMavenProject(); for (Artifact artifact : mavenProject.getArtifacts()) { if (artifact.getGroupId().equals(groupId) && artifact.getArtifactId().equals(artifactId)) { version = artifact.getVersion(); break; } } } } } } } } } }
Example 20
Source File: ForeignClassBundlerImpl.java From netbeans with Apache License 2.0 | 4 votes |
private boolean calculateValue() { NbMavenProject nbmp = project.getLookup().lookup(NbMavenProject.class); if (nbmp == null) { return true; } boolean oldVal = hasProblem.get(); boolean newVal = false; try { MavenProject mp = nbmp.getMavenProject(); Properties props = PluginPropertyUtils.getPluginPropertyParameter(project, "org.apache.felix", "maven-bundle-plugin", "instructions", "bundle"); if (props != null) { //String embed = props.getProperty("Embed-Dependency"); //TODO should we parse it somehow? //are embedded ones a problem? not on CP I guess // if (embed != null && embed.contains("inline=true")) { // return false; // } String exportedPack = props.getProperty("Export-Package"); String privatePack = props.getProperty("Private-Package"); if (exportedPack != null || privatePack != null) { Matcher exported = new Matcher(exportedPack); Matcher prived = new Matcher(privatePack); for (Artifact a : mp.getRuntimeArtifacts()) { //TODO runtime or compile?? File f = a.getFile(); if (f != null && f.isFile()) { try { JarFile jf = new JarFile(f); Enumeration<JarEntry> en = jf.entries(); while (en.hasMoreElements()) { JarEntry je = en.nextElement(); if (je.isDirectory() && !je.getName().startsWith("META-INF")) { //is this optimization correct? String pack = je.getName().substring(0, je.getName().length() - 1).replace("/", "."); //last char is / if (exported.matches(pack) || prived.matches(pack)) { newVal = true; return false; } } } } catch (IOException ex) { Exceptions.printStackTrace(ex); } } } } } } finally { if (newVal != oldVal) { hasProblem.set(newVal); RP.post(new Runnable() { @Override public void run() { pchs.firePropertyChange(ProjectProblemsProvider.PROP_PROBLEMS, null, null); } }); } } //according to http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html default value is just //project's own sources return true; }