Assembla home | Assembla project page
 

Changeset 833:3ef15811b6c1

Show
Ignore:
Timestamp:
08/10/08 16:23:57 (4 months ago)
Author:
Bastian Doetsch <bastian.doetsch@gmx.de>
branch:
default
Message:

Added signature verification for signed changesets in history view.

Green background = valid
Red background = invalid / unknown key

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/com/vectrace/MercurialEclipse/commands/HgSignClient.java

    r428 r833  
    1717import java.util.List; 
    1818 
    19 import org.eclipse.core.resources.IProject; 
    2019import org.eclipse.core.resources.ResourcesPlugin; 
    2120 
     
    3332public class HgSignClient { 
    3433 
     34     
     35     
    3536    /** 
    3637     * Calls hg sign. add a signature for the current or given revision If no 
     
    3839     * no revision is checked out. 
    3940     *  
    40      * @param project 
     41     * @param directory 
    4142     *            the current project (working directory) 
    4243     * @param cs 
     
    6162     *  
    6263     */ 
    63     public static String sign(IProject project, ChangeSet cs, String key, 
     64    public static String sign(File directory, ChangeSet cs, String key, 
    6465            String message, String user, boolean local, boolean force, 
    6566            boolean noCommit, String passphrase) throws HgException { 
    66         HgCommand command = new HgCommand("sign", project, true); 
     67        HgCommand command = new HgCommand("sign", directory, true); 
    6768        File file = new File("me.gpg.tmp"); 
    6869        String cmd = "gpg.cmd=".concat( 
  • src/com/vectrace/MercurialEclipse/history/GraphLogTableViewer.java

    r777 r833  
    2020 
    2121import com.vectrace.MercurialEclipse.MercurialEclipsePlugin; 
     22import com.vectrace.MercurialEclipse.exception.HgException; 
    2223import com.vectrace.MercurialEclipse.model.GChangeSet; 
     24import com.vectrace.MercurialEclipse.model.Signature; 
    2325import com.vectrace.MercurialEclipse.model.GChangeSet.Edge; 
    2426import com.vectrace.MercurialEclipse.model.GChangeSet.EdgeList; 
     
    7274                refreshJob.join(); 
    7375            } catch (InterruptedException e) { 
     76                MercurialEclipsePlugin.logError(e); 
     77            } 
     78        } 
     79         
     80        // validate signed changesets 
     81        Signature sig = rev.getSignature(); 
     82        if (sig != null) { 
     83            try { 
     84                if (sig.validate()) { 
     85                    tableItem.setBackground(colours.get(0)); 
     86                } else { 
     87                    tableItem.setBackground(colours.get(2)); 
     88                } 
     89            } catch (HgException e) { 
    7490                MercurialEclipsePlugin.logError(e); 
    7591            } 
  • src/com/vectrace/MercurialEclipse/history/MercurialHistory.java

    r784 r833  
    1313package com.vectrace.MercurialEclipse.history; 
    1414 
     15import java.io.File; 
    1516import java.util.Comparator; 
    1617import java.util.HashMap; 
     
    3031import com.vectrace.MercurialEclipse.commands.HgGLogClient; 
    3132import com.vectrace.MercurialEclipse.commands.HgLogClient; 
     33import com.vectrace.MercurialEclipse.commands.HgSigsClient; 
    3234import com.vectrace.MercurialEclipse.model.ChangeSet; 
    3335import com.vectrace.MercurialEclipse.model.GChangeSet; 
     36import com.vectrace.MercurialEclipse.model.Signature; 
    3437import com.vectrace.MercurialEclipse.preferences.MercurialPreferenceConstants; 
    3538import com.vectrace.MercurialEclipse.team.MercurialTeamProvider; 
     
    184187                    .getLocation()); 
    185188            if (localChangeSets != null) { 
     189                // get signatures 
     190                File file = resource.getLocation().toFile(); 
     191                List<Signature> sigs = HgSigsClient.getSigs(file); 
     192                Map<String, Signature> sigMap = new HashMap<String, Signature>(); 
     193                for (Signature signature : sigs) { 
     194                    sigMap.put(signature.getNodeId(), signature); 
     195                } 
     196 
    186197                changeSets.addAll(localChangeSets); 
    187198 
     
    202213                } 
    203214                for (ChangeSet cs : changeSets) { 
     215                    Signature sig = sigMap.get(cs.getChangeset()); 
    204216                    revisions.add(new MercurialRevision(cs, gChangeSets 
    205217                            .get(Integer.valueOf(cs.getChangesetIndex())), 
    206                             resource)); 
     218                            resource, sig)); 
    207219                } 
    208220            } 
  • src/com/vectrace/MercurialEclipse/history/MercurialRevision.java

    r773 r833  
    2222import com.vectrace.MercurialEclipse.model.ChangeSet; 
    2323import com.vectrace.MercurialEclipse.model.GChangeSet; 
     24import com.vectrace.MercurialEclipse.model.Signature; 
    2425import com.vectrace.MercurialEclipse.team.IStorageMercurialRevision; 
    2526 
    2627/** 
    2728 * @author zingo 
    28  * 
     29 *  
    2930 */ 
    30 public class MercurialRevision extends FileRevision 
    31 
    32   @Override 
     31public class MercurialRevision extends FileRevision { 
     32     
     33 
     34    public Signature getSignature() { 
     35        return signature; 
     36    } 
     37 
     38    @Override 
    3339    public int hashCode() { 
    3440        final int prime = 31; 
     
    7076    } 
    7177 
    72     private IResource resource;  
    73   private ChangeSet changeSet;  
    74   private IStorageMercurialRevision iStorageMercurialRevision; //Cached data 
    75   private final GChangeSet gChangeSet; 
    76   private String revision; 
    77   private String hash; 
     78    private IResource resource; 
     79    private ChangeSet changeSet; 
     80    private IStorageMercurialRevision iStorageMercurialRevision; // Cached data 
     81    private final GChangeSet gChangeSet; 
     82    private String revision; 
     83    private String hash; 
     84    private Signature signature; 
     85     
     86    public MercurialRevision(ChangeSet changeSet, GChangeSet gChangeSet, 
     87            IResource resource, Signature sig) { 
     88        super(); 
     89        this.changeSet = changeSet; 
     90        this.gChangeSet = gChangeSet; 
    7891 
    79   public MercurialRevision(ChangeSet changeSet, GChangeSet gChangeSet, IResource resource) 
    80   { 
    81     super(); 
    82     this.changeSet = changeSet;     
    83     this.gChangeSet = gChangeSet; 
    84      
    85         this.revision = changeSet.getChangesetIndex()+""; 
    86         this.hash = changeSet.getChangeset(); 
    87     this.resource=resource; 
    88   } 
    89    
    90   public ChangeSet getChangeSet() 
    91   { 
    92     return changeSet; 
    93   } 
     92        this.revision = changeSet.getChangesetIndex() + ""; 
     93        this.hash = changeSet.getChangeset(); 
     94        this.resource = resource; 
     95        this.signature = sig; 
     96    } 
    9497 
    95   public GChangeSet getGChangeSet() 
    96   { 
    97     return gChangeSet; 
    98   } 
     98    public ChangeSet getChangeSet() { 
     99        return changeSet; 
     100    } 
    99101 
    100   /* (non-Javadoc) 
    101    * @see org.eclipse.team.core.history.IFileRevision#getName() 
    102    */ 
    103   public String getName() 
    104   { 
    105     return resource.getName(); 
    106   } 
     102    public GChangeSet getGChangeSet() { 
     103        return gChangeSet; 
     104    } 
    107105 
    108   @Override 
    109   public String getContentIdentifier()  
    110   { 
    111     return changeSet.getChangeset(); 
    112   } 
    113    
    114   /* (non-Javadoc) 
    115    * @see org.eclipse.team.core.history.IFileRevision#getStorage(org.eclipse.core.runtime.IProgressMonitor) 
    116    */ 
    117   public IStorage getStorage(IProgressMonitor monitor) throws CoreException { 
    118                 if (iStorageMercurialRevision == null) {                         
    119                         iStorageMercurialRevision = new IStorageMercurialRevision(resource, 
    120                                         revision, hash, changeSet); 
    121                 } 
    122                 return iStorageMercurialRevision; 
    123         } 
     106    /* 
     107     * (non-Javadoc) 
     108     *  
     109     * @see org.eclipse.team.core.history.IFileRevision#getName() 
     110     */ 
     111    public String getName() { 
     112        return resource.getName(); 
     113    } 
    124114 
    125   /* 
    126          * (non-Javadoc) 
    127          *  
    128          * @see org.eclipse.team.core.history.IFileRevision#isPropertyMissing() 
    129          */ 
    130   public boolean isPropertyMissing() 
    131   { 
    132     return false; 
    133   } 
     115    @Override 
     116    public String getContentIdentifier() { 
     117        return changeSet.getChangeset(); 
     118    } 
    134119 
    135   /* (non-Javadoc) 
    136    * @see org.eclipse.team.core.history.IFileRevision#withAllProperties(org.eclipse.core.runtime.IProgressMonitor) 
    137    */ 
    138   public IFileRevision withAllProperties(IProgressMonitor monitor) throws CoreException 
    139   { 
    140     return null; 
    141   } 
     120    /* 
     121     * (non-Javadoc) 
     122     *  
     123     * @see 
     124     * org.eclipse.team.core.history.IFileRevision#getStorage(org.eclipse.core 
     125     * .runtime.IProgressMonitor) 
     126     */ 
     127    public IStorage getStorage(IProgressMonitor monitor) throws CoreException { 
     128        if (iStorageMercurialRevision == null) { 
     129            iStorageMercurialRevision = new IStorageMercurialRevision(resource, 
     130                    revision, hash, changeSet); 
     131        } 
     132        return iStorageMercurialRevision; 
     133    } 
    142134 
     135    /* 
     136     * (non-Javadoc) 
     137     *  
     138     * @see org.eclipse.team.core.history.IFileRevision#isPropertyMissing() 
     139     */ 
     140    public boolean isPropertyMissing() { 
     141        return false; 
     142    } 
    143143 
     144    /* 
     145     * (non-Javadoc) 
     146     *  
     147     * @see 
     148     * org.eclipse.team.core.history.IFileRevision#withAllProperties(org.eclipse 
     149     * .core.runtime.IProgressMonitor) 
     150     */ 
     151    public IFileRevision withAllProperties(IProgressMonitor monitor) 
     152            throws CoreException { 
     153        return null; 
     154    } 
    144155 
    145 /** 
    146  * @return the revision 
    147  */ 
    148 public String getRevision() { 
    149        return revision; 
    150 
     156    /** 
     157     * @return the revision 
     158     */ 
     159    public String getRevision() { 
     160        return revision; 
     161   
    151162 
     163    /** 
     164     * @param revision 
     165     *            the revision to set 
     166     */ 
     167    public void setRevision(String revision) { 
     168        this.revision = revision; 
     169    } 
    152170 
     171    /** 
     172     * @return the hash 
     173     */ 
     174    public String getHash() { 
     175        return hash; 
     176    } 
    153177 
    154 /** 
    155  * @param revision the revision to set 
    156  */ 
    157 public void setRevision(String revision) { 
    158         this.revision = revision; 
    159 
     178    /** 
     179     * @param hash 
     180     *            the hash to set 
     181     */ 
     182    public void setHash(String hash) { 
     183        this.hash = hash; 
     184    } 
    160185 
    161  
    162  
    163 /** 
    164  * @return the hash 
    165  */ 
    166 public String getHash() { 
    167         return hash; 
    168 
    169  
    170  
    171  
    172 /** 
    173  * @param hash the hash to set 
    174  */ 
    175 public void setHash(String hash) { 
    176         this.hash = hash; 
    177 
    178  
    179 public IResource getResource() { 
    180         return resource; 
    181 
     186    public IResource getResource() { 
     187        return resource; 
     188    } 
    182189 
    183190} 
  • src/com/vectrace/MercurialEclipse/team/cache/AbstractCache.java

    r819 r833  
    150150     *  
    151151     * @param changeSet 
    152      *            string in format rev:nodeshort 
     152     *            string in format rev:nodeshort or rev:node 
    153153     * @return 
    154154     */ 
  • src/com/vectrace/MercurialEclipse/wizards/SignWizardPage.java

    r774 r833  
    166166        boolean noCommit = noCommitCheckBox.getSelection(); 
    167167        try { 
    168             HgSignClient.sign(project, cs, key, msg, user, local, force, 
     168            HgSignClient.sign(project.getLocation().toFile(), cs, key, msg, 
     169                    user, local, force, 
    169170                    noCommit, pass); 
    170171        } catch (HgException e) { 
  • test/com/vectrace/MercurialEclipse/commands/AbstractCommandTest.java

    r802 r833  
    120120    } 
    121121 
     122    protected void addToRepository(File newFile) throws InterruptedException, 
     123            IOException { 
     124                Runtime runtime = Runtime.getRuntime(); 
     125                runtime.exec("hg add " + newFile.getAbsolutePath(), null, getRepository()).waitFor(); 
     126            } 
     127 
    122128} 
  • test/com/vectrace/MercurialEclipse/commands/HgCommitClientTest.java

    r801 r833  
    1212 
    1313import java.io.File; 
    14 import java.io.IOException; 
    1514import java.util.ArrayList; 
    1615import java.util.List; 
     
    5352        HgCommitClient.commit(hgroot, files, "Simple", "the message"); 
    5453    } 
    55     private void addToRepository(File newFile) throws InterruptedException, IOException { 
    56         Runtime runtime = Runtime.getRuntime(); 
    57         runtime.exec("hg add " + newFile.getAbsolutePath(), null, getRepository()).waitFor(); 
    58     } 
    5954}