public void applyChanges() { if (setts == null) { setts = MavenSettingsSingleton.getInstance().createUserSettingsModel(); } getPanel().applyValues(setts); try { File userDir = MavenSettingsSingleton.getInstance().getM2UserDir(); WriterUtils.writeSettingsModel(FileUtil.createFolder(userDir), setts); } catch (IOException ex) { ex.printStackTrace(); } }
public static synchronized MavenSettingsSingleton getInstance() { if (instance == null) { instance = new MavenSettingsSingleton(); } return instance; } /**
public void update() { if (setts == null) { setts = MavenSettingsSingleton.getInstance().createUserSettingsModel(); } getPanel().setValues(setts); }
/** * this method should rather use the embedder's settings, however there's no clear * way of retrieving/using them. * @deprecated rather not use, doesn't contain the global setting values */ @Deprecated public Settings getSettings() { //TODO need probably some kind of caching.. Settings sets = createUserSettingsModel(); if (sets.getLocalRepository() == null) { sets.setLocalRepository(new File(getM2UserDir(), "repository").toString()); } return sets; }
@Override public Action[] getActions(boolean context) { Collection<Action> col = new ArrayList<Action>(); if (project.getProjectDirectory().getFileObject("profiles.xml") == null) { //NOI18N col.add(new AddProfileXmlAction()); } if (! new File(MavenSettingsSingleton.getInstance().getM2UserDir(), "settings.xml").exists()) { //NOI18N col.add(new AddSettingsXmlAction()); } return col.toArray(new Action[col.size()]); }
public List<String> getMergedActiveProfiles(boolean shared) { Set<String> prifileides = new HashSet<String>(); MavenProject mavenProject = nmp.getOriginalMavenProject(); List<Profile> profiles = mavenProject.getActiveProfiles(); for (Profile profile : profiles) { prifileides.add(profile.getId()); } //read from Settings.xml List<String> profileStrings = MavenSettingsSingleton.getInstance().createUserSettingsModel().getActiveProfiles(); for (String profile : profileStrings) { prifileides.add(profile); } File basedir = FileUtil.normalizeFile(mavenProject.getBasedir()); FileObject fileObject = FileUtil.toFileObject(basedir); //read from profiles.xml Iterator it2 = MavenSettingsSingleton.createProfilesModel(fileObject).getActiveProfiles().iterator(); while (it2.hasNext()) { prifileides.add((String) it2.next()); } prifileides.addAll(getActiveProfiles(shared)); return new ArrayList<String>(prifileides); }
public Set<String> getAvailableGoals() { Set<String> cached = goalsRef != null ? goalsRef.get() :null; if (cached == null) { File expandedPath = InstalledFileLocator.getDefault().locate("maven2/maven-plugins-xml", null, false); //NOI18N assert expandedPath != null : "Shall have path expanded.."; //NOI18N //TODO we should have a "resolved instance here with defaults injected correctly List<String> groups = MavenSettingsSingleton.getInstance().getSettings().getPluginGroups(); groups.add("org.apache.maven.plugins"); //NOI18N groups.add("org.codehaus.mojo"); //NOI18N cached = new TreeSet<String>(); for (String group : groups) { File folder = new File(expandedPath, group.replace('.', File.separatorChar)); checkFolder(folder, cached, false); } goalsRef = new WeakReference<Set<String>>(cached); } return cached; }
public Settings createUserSettingsModel() { Settings sets = null; File dir = getM2UserDir(); try { File fil = new File(dir, "settings.xml"); if (fil.exists()) { sets = builder.read(new InputStreamReader(new FileInputStream(fil))); } } catch (IOException ex) { ex.printStackTrace(); } catch (XmlPullParserException ex) { ex.printStackTrace(); } if (sets == null) { sets = new Settings(); } return sets; }
private static void extractProfiles(Set<String> profileIds, File file) { extractProfilesFromModelLineage(file, profileIds); File basedir = FileUtil.normalizeFile(file.getParentFile()); FileObject fileObject = FileUtil.toFileObject(basedir); //read from profiles.xml Iterator it2 = MavenSettingsSingleton.createProfilesModel(fileObject).getProfiles().iterator(); while (it2.hasNext()) { org.apache.maven.profiles.Profile prof = (org.apache.maven.profiles.Profile) it2.next(); profileIds.add(prof.getId()); } }
public FileObject getHomeDirectory() { File homeFile = MavenSettingsSingleton.getInstance().getM2UserDir(); FileObject home = null; try { home = FileUtil.createFolder(homeFile); } catch (IOException ex) { Exceptions.printStackTrace(ex); } if (home == null) { //TODO this is a problem, probably UNC path on windows - MEVENIDE-380 // some functionality won't work ErrorManager.getDefault().log("Cannot convert home dir to FileObject, some functionality won't work. It's usually the case on Windows and UNC paths. The path is " + homeFile); //NOI18N } return home; }
public List<String> getAllProfiles() { Set<String> profileIds = new HashSet<String>(); //pom+profiles.xml profiles come first extractProfiles(profileIds, nmp.getPOMFile()); //Add settings file Properties profileIds.addAll(MavenSettingsSingleton.getInstance().createUserSettingsModel(). getProfilesAsMap().keySet()); return new ArrayList<String>(profileIds); }
public static ModelHandle createModelHandle(NbMavenProject project) throws IOException, XmlPullParserException { Model model = project.getEmbedder().readModel(project.getPOMFile()); ProfilesRoot prof = MavenSettingsSingleton.createProfilesModel(project.getProjectDirectory()); UserActionGoalProvider usr = project.getLookup().lookup(org.codehaus.mevenide.netbeans.execute.UserActionGoalProvider.class); ActionToGoalMapping mapping = new NetbeansBuildActionXpp3Reader().read(new StringReader(usr.getRawMappingsAsString())); return CustomizerProviderImpl.ACCESSOR.createHandle(model, prof, project.getOriginalMavenProject(), Collections.<String, ActionToGoalMapping>singletonMap(M2Configuration.DEFAULT,mapping), null, null); }
private void doFireReload() { //TODO is root folder refresh enough? // replace with FileUtil.refresh(File) once it gets into the netbeans.org codebase. project.getProjectDirectory().refresh(); FileObject fo = FileUtil.toFileObject(MavenSettingsSingleton.getInstance().getM2UserDir()); if (fo != null) { fo.refresh(); } support.firePropertyChange(NbMavenProject.PROP_PROJECT, null, null); }
pnl.readMapping(mapping, project, maps); pnl.setShowDebug(MavenExecutionSettings.getDefault().isShowDebug()); pnl.setOffline(MavenSettingsSingleton.getInstance().createUserSettingsModel().isOffline()); pnl.setRecursive(true); Object retValue = DialogDisplayer.getDefault().notify(dd);
private void init() throws XmlPullParserException, FileNotFoundException, IOException { Model model = project.getEmbedder().readModel(project.getPOMFile()); ProfilesRoot prof = MavenSettingsSingleton.createProfilesModel(project.getProjectDirectory()); UserActionGoalProvider usr = project.getLookup().lookup(org.codehaus.mevenide.netbeans.execute.UserActionGoalProvider.class); Map<String, ActionToGoalMapping> mapps = new HashMap<String, ActionToGoalMapping>();
private void regenerateKeys(boolean refresh) { Collection<File> keys = new ArrayList<File>(); keys.add(new File(FileUtil.toFile(project.getProjectDirectory()), "pom.xml")); //NOI18N keys.add(new File(FileUtil.toFile(project.getProjectDirectory()), "profiles.xml")); //NOI18N keys.add(new File(MavenSettingsSingleton.getInstance().getM2UserDir(), "settings.xml")); //NOI18N setKeys(keys); ((ProjectFilesNode)getNode()).setMyFiles(); if (refresh) { for (File key : keys) { refreshKey(key); } } } }
public void actionPerformed(ActionEvent e) { try { File fil = MavenSettingsSingleton.getInstance().getM2UserDir(); DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(fil)); // path to template... FileObject temp = Repository.getDefault().getDefaultFileSystem().findResource("Maven2Templates/settings.xml"); //NOI18N DataObject dobj = DataObject.find(temp); DataObject newOne = dobj.createFromTemplate(folder); EditCookie cook = newOne.getCookie(EditCookie.class); if (cook != null) { cook.edit(); } } catch (DataObjectNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } }