public void apply(final IDocument document) {
   IProject p = marker.getResource().getProject();
   IFile f = BuildWrapperPlugin.getCabalFile(p);
   IDocumentProvider prov = new TextFileDocumentProvider();
   try {
     prov.connect(f);
     IDocument doc = prov.getDocument(f);
     PackageDescription pd = PackageDescriptionLoader.load(f);
     int length = pd.getStanzas().size();
     for (int a = 0; a < length; a++) {
       PackageDescriptionStanza pds = pd.getStanzas().get(a);
       CabalSyntax cs = pds.getType();
       if (CabalSyntax.SECTION_EXECUTABLE.equals(cs)
           || CabalSyntax.SECTION_LIBRARY.equals(cs)
           || CabalSyntax.SECTION_TESTSUITE.equals(cs)) {
         RealValuePosition rvp = pds.addToPropertyList(CabalSyntax.FIELD_BUILD_DEPENDS, pkg);
         if (rvp != null) {
           rvp.updateDocument(doc);
           pd = PackageDescriptionLoader.load(doc.get());
         }
       }
     }
     prov.saveDocument(new NullProgressMonitor(), f, doc, true);
   } catch (CoreException ce) {
     HaskellUIPlugin.log(ce);
   }
 }
Ejemplo n.º 2
0
 public Object[] getChildren(final Object parentElement) {
   List<IFolder> list = new ArrayList<IFolder>();
   /*if( parentElement instanceof IHaskellProject ) {
     IHaskellProject hsProject = ( IHaskellProject )parentElement;
     Set<IPath> sourcePaths = hsProject.getSourcePaths();
     for( IPath sourcePath: sourcePaths ) {
       IProject project = hsProject.getResource();
       if( !sourcePath.equals( project.getProjectRelativePath() ) ) {
         list.add( project.getFolder( sourcePath ) );
       }
     }
   }*/
   if (parentElement instanceof IProject) {
     IProject project = (IProject) parentElement;
     IFile f = BuildWrapperPlugin.getCabalFile(project);
     try {
       PackageDescription pd = PackageDescriptionLoader.load(f);
       for (String sourcePath : pd.getStanzasBySourceDir().keySet()) {
         if (sourcePath.length() > 0) {
           list.add(project.getFolder(sourcePath));
         }
       }
     } catch (CoreException ex) {
       HaskellUIPlugin.log(ex);
     }
   }
   return list.toArray();
 }
Ejemplo n.º 3
0
  protected PackageDescription getCabalFile(final Map<String, String> vars) {

    /*String s=CabalSyntax.FIELD_NAME.getCabalName()+":           " + name + NL //$NON-NLS-1$
           + CabalSyntax.FIELD_VERSION.getCabalName()+":        0.1 "+ NL + NL //$NON-NLS-1$
           ;
    if (isLibrary()){
      s+= CabalSyntax.SECTION_LIBRARY.getCabalName() + NL
        + "  "+ CabalSyntax.FIELD_HS_SOURCE_DIRS.getCabalName()+": src" + NL + NL//$NON-NLS-1$ //$NON-NLS-2$
      ;
    }

    if (isExecutable()){
        s+= CabalSyntax.SECTION_EXECUTABLE.getCabalName()+" " + name + NL //$NON-NLS-1$
           + "  "+ CabalSyntax.FIELD_HS_SOURCE_DIRS.getCabalName()+": src" + NL //$NON-NLS-1$ //$NON-NLS-2$
           + "  "+ CabalSyntax.FIELD_MAIN_IS.getCabalName()+": Main.hs"+ NL + NL; //$NON-NLS-1$ //$NON-NLS-2$
    }


    return s;*/
    /*PackageDescription pd=new PackageDescription( name );
    pd.getStanzas().get( 0 ).update( CabalSyntax.FIELD_VERSION, "0.1" ); //$NON-NLS-1$
    pd.getStanzas().get( 0 ).update( CabalSyntax.FIELD_CABAL_VERSION, ">= 1.2" ); //$NON-NLS-1$
    pd.getStanzas().get( 0 ).update( CabalSyntax.FIELD_BUILD_TYPE, "Simple" ); //$NON-NLS-1$
    String userName=PlatformUtil.getCurrentUser();
    if (userName!=null){
      pd.getStanzas().get( 0 ).update( CabalSyntax.FIELD_AUTHOR, userName );
    }

    if (isLibrary()){
      PackageDescriptionStanza pds=pd.addStanza( CabalSyntax.SECTION_LIBRARY, null );
      pds.update( CabalSyntax.FIELD_HS_SOURCE_DIRS, src );
      pds.update( CabalSyntax.FIELD_BUILD_DEPENDS, "base >= 4" ); //$NON-NLS-1$
      pds.update( CabalSyntax.FIELD_GHC_OPTIONS, "-Wall" ); //$NON-NLS-1$
    }

    if (isExecutable()){
      PackageDescriptionStanza pds=pd.addStanza( CabalSyntax.SECTION_EXECUTABLE, name );
      pds.update( CabalSyntax.FIELD_HS_SOURCE_DIRS, src );
      pds.update( CabalSyntax.FIELD_MAIN_IS, "Main.hs" ); //$NON-NLS-1$
      pds.update( CabalSyntax.FIELD_BUILD_DEPENDS, "base >= 4" ); //$NON-NLS-1$
      pds.update( CabalSyntax.FIELD_GHC_OPTIONS, "-Wall" ); //$NON-NLS-1$
    }*/

    String library = ""; // $NON-NLS-1$

    if (isLibrary()) {
      library =
          HaskellCorePlugin.populateTemplate(ICorePreferenceNames.TEMPLATE_CABAL_LIBRARY, vars);
    }
    vars.put(TemplateVariables.LIBRARY, library);

    String exe = ""; // $NON-NLS-1$
    if (isExecutable()) {
      exe = HaskellCorePlugin.populateTemplate(ICorePreferenceNames.TEMPLATE_CABAL_EXE, vars);
    }
    vars.put(TemplateVariables.EXECUTABLE, exe);

    String content = HaskellCorePlugin.populateTemplate(ICorePreferenceNames.TEMPLATE_CABAL, vars);
    PackageDescription pd = PackageDescriptionLoader.load(content);

    for (ICabalContributor c : CabalContributorManager.getContributors()) {
      c.contributeOnNewProject(pd);
    }

    return pd;
  }