~ubuntu-branches/ubuntu/utopic/eclipse-eclox/utopic

« back to all changes in this revision

Viewing changes to eclox.core/src/eclox/core/doxygen/BundledDoxygen.java

  • Committer: Package Import Robot
  • Author(s): Graham Inggs
  • Date: 2013-07-07 20:33:10 UTC
  • Revision ID: package-import@ubuntu.com-20130707203310-a44yw80gqtc2s9ob
Tags: upstream-0.10.0
ImportĀ upstreamĀ versionĀ 0.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (C) 2003-2006, 2013, Guillaume Brocker
 
3
 * 
 
4
 * All rights reserved. This program and the accompanying materials
 
5
 * are made available under the terms of the Eclipse Public License v1.0
 
6
 * which accompanies this distribution, and is available at
 
7
 * http://www.eclipse.org/legal/epl-v10.html
 
8
 *
 
9
 * Contributors:
 
10
 *     Guillaume Brocker - Initial API and implementation
 
11
 *
 
12
 ******************************************************************************/ 
 
13
 
 
14
package eclox.core.doxygen;
 
15
 
 
16
import java.net.URL;
 
17
import java.util.Collection;
 
18
import java.util.Vector;
 
19
 
 
20
import org.eclipse.core.runtime.FileLocator;
 
21
import org.eclipse.core.runtime.IConfigurationElement;
 
22
import org.eclipse.core.runtime.IExtension;
 
23
import org.eclipse.core.runtime.IExtensionPoint;
 
24
import org.eclipse.core.runtime.IExtensionRegistry;
 
25
import org.eclipse.core.runtime.Path;
 
26
import org.eclipse.core.runtime.Platform;
 
27
 
 
28
import eclox.core.Plugin;
 
29
 
 
30
public final class BundledDoxygen extends Doxygen {
 
31
        
 
32
        private URL     location;
 
33
        
 
34
        /**
 
35
         * Retrieves all available bundled doxygen binaries.
 
36
         * 
 
37
         * @return      a collection with all collected bundled doxygen wrappers
 
38
         */
 
39
        public static Collection getAll() {
 
40
                Collection                      doxygens        = new Vector();
 
41
                IExtensionRegistry      registry        = Platform.getExtensionRegistry();
 
42
                IExtensionPoint         point           = registry.getExtensionPoint("org.gna.eclox.core.doxygen");
 
43
                IExtension[]            extensions      = point.getExtensions();
 
44
                
 
45
                for (int i = 0; i < extensions.length; i++) {
 
46
                        IExtension                              extension       = extensions[i];
 
47
                        IConfigurationElement[] elements        = extension.getConfigurationElements();
 
48
                        
 
49
                        for (int j = 0; j < elements.length; j++) {
 
50
                                final String    arch    = elements[j].getAttribute("arch");
 
51
                                final String    os              = elements[j].getAttribute("os");
 
52
                                
 
53
                                if( Platform.getOS().equals(os) && Platform.getOSArch().equals(arch) ) {
 
54
                                        final Path              path    = new Path( elements[j].getAttribute("path") );
 
55
                                        URL                             url             = FileLocator.find(Plugin.getDefault().getBundle(), path, null);
 
56
                                        
 
57
                                        if( url != null ) {
 
58
                                                doxygens.add( new BundledDoxygen(url) );
 
59
                                        }
 
60
                                        else {
 
61
                                                Plugin.getDefault().logError( path.toString() + ": not a valid doxygen path." );
 
62
                                        }                                       
 
63
                                }
 
64
                        }
 
65
                }
 
66
                return doxygens;                
 
67
        }
 
68
        
 
69
        /**
 
70
         * Creates a bundled doxygen instance from the given identifier
 
71
         * 
 
72
         * @param       identifier      a string containing an identifier
 
73
         * 
 
74
         * @return      a new bundled doxygen wrapper
 
75
         */
 
76
        public static BundledDoxygen createFromIdentifier( final String identifier ) {
 
77
                BundledDoxygen  doxygen = null;
 
78
                
 
79
                if( identifier.startsWith( BundledDoxygen.class.getName() ) ) {
 
80
                        final String    location =  identifier.substring( identifier.indexOf(' ') + 1 );
 
81
                        
 
82
                        try {
 
83
                                doxygen = new BundledDoxygen( new URL(location) );
 
84
                        }
 
85
                        catch( Throwable t ) {
 
86
                                Plugin.log( t );
 
87
                                doxygen = null;
 
88
                        }
 
89
                }
 
90
                return doxygen;
 
91
        }
 
92
 
 
93
        /**
 
94
         * @see eclox.core.doxygen.Doxygen#getCommand()
 
95
         */
 
96
        public String getCommand() {
 
97
                try {
 
98
                        return FileLocator.resolve( location ).getPath();
 
99
                }
 
100
                catch( Throwable t ) {
 
101
                        Plugin.log(t);
 
102
                        return null;
 
103
                }
 
104
        }
 
105
 
 
106
        /**
 
107
         * @see eclox.core.doxygen.Doxygen#getDescription()
 
108
         */
 
109
        public String getDescription() {
 
110
                return new String();
 
111
        }
 
112
 
 
113
        /**
 
114
         * @see eclox.core.doxygen.Doxygen#getIdentifier()
 
115
         */
 
116
        public String getIdentifier() {
 
117
                return this.getClass().getName() + " " + location;
 
118
        }
 
119
        
 
120
        /**
 
121
         * Constructor
 
122
         * 
 
123
         * @param       location        an url giving the location a doxygen binary
 
124
         */
 
125
        private BundledDoxygen( URL location ) {
 
126
                this.location = location;
 
127
 
 
128
                assert( location != null );
 
129
        }
 
130
 
 
131
}