Java Code Examples for org.netbeans.modules.maven.model.Utilities#createModelSource()

The following examples show how to use org.netbeans.modules.maven.model.Utilities#createModelSource() . 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: SettingsContextProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void runTaskWithinContext(Lookup context, Task task) {
    JTextComponent component = context.lookup(JTextComponent.class);
    if (component != null) {
        DataObject dobj = NbEditorUtilities.getDataObject(component.getDocument());
        if (dobj != null) {
            FileObject fo = dobj.getPrimaryFile();
            ModelSource ms = Utilities.createModelSource(fo);
            SettingsModel model = SettingsModelFactory.getDefault().getModel(ms);
            if (model != null) {
                Lookup newContext = new ProxyLookup(context, Lookups.fixed(model));
                task.run(newContext);
                return;
            }
        }
    }
    task.run(context);
}
 
Example 2
Source File: ContextProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void runTaskWithinContext(Lookup context, Task task) {
    JTextComponent component = context.lookup(JTextComponent.class);
    if (component != null) {
        DataObject dobj = NbEditorUtilities.getDataObject(component.getDocument());
        if (dobj != null) {
            FileObject fo = dobj.getPrimaryFile();
            ModelSource ms = Utilities.createModelSource(fo);
            if (ms.isEditable()) {
                POMModel model = POMModelFactory.getDefault().getModel(ms);
                if (model != null) {
                    Lookup newContext = new ProxyLookup(context, Lookups.fixed(model));
                    task.run(newContext);
                    return;
                }
            }
        }
    }
    task.run(context);
}
 
Example 3
Source File: StatusProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void initializeModel() {
    FileObject fo = NbEditorUtilities.getFileObject(document);
    if (fo != null) {
        //#236116 passing document protects from looking it up later and causing a deadlock.
        ModelSource ms = Utilities.createModelSource(fo, null, document instanceof BaseDocument ? (BaseDocument)document : null);
        model = POMModelFactory.getDefault().createFreshModel(ms);
        project = FileOwnerQuery.getOwner(fo);
        fo.addFileChangeListener(FileUtil.weakFileChangeListener(listener, fo));
    }
}
 
Example 4
Source File: TaskListBridge.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public List<? extends Task> scan(FileObject resource) {
    if (Constants.POM_MIME_TYPE.equals(resource.getMIMEType()) //NOI18N
            && "pom.xml".equals(resource.getNameExt())) { //NOI18N
        Project prj = FileOwnerQuery.getOwner(resource);
        if (prj != null && prj.getLookup().lookup(NbMavenProject.class) != null) {
            ModelSource ms = Utilities.createModelSource(resource);
            POMModel model = POMModelFactory.getDefault().getModel(ms);
            model.setAutoSyncActive(false);
            List<ErrorDescription> errs = StatusProvider.StatusProviderImpl.findHints(model, prj, -1, -1, -1);
            List<Task> tasks = new ArrayList<Task>();

            for (ErrorDescription error : errs) {
                try {
                    Task task = Task.create(resource,
                            severityToTaskListString(error.getSeverity()),
                            error.getDescription(),
                            error.getRange().getBegin().getLine() + 1);

                    tasks.add(task);
                } catch (IOException e) {
                    Logger.getLogger(TaskListBridge.class.getName()).
                            log(Level.INFO, "Error while converting errors to tasklist", e);
                }
            }
            return tasks;
        }
    }
    return Collections.<Task>emptyList();
}
 
Example 5
Source File: Selenium2MavenSupportImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private POMModel getPOMModel(Project project) {
    FileObject pom = getPomFile(project);
    ModelSource source = Utilities.createModelSource(pom);
    return POMModelFactory.getDefault().getModel(source);
}