This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 187678
Collapse All | Expand All

(-)a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/FeatureUpdateElementImpl.java (-5 / +52 lines)
Lines 51-56 Link Here
51
import java.util.Collections;
51
import java.util.Collections;
52
import java.util.Date;
52
import java.util.Date;
53
import java.util.HashSet;
53
import java.util.HashSet;
54
import java.util.Iterator;
54
import java.util.List;
55
import java.util.List;
55
import java.util.Set;
56
import java.util.Set;
56
import java.util.logging.Level;
57
import java.util.logging.Level;
Lines 304-309 Link Here
304
    public static class Agent extends FeatureUpdateElementImpl {
305
    public static class Agent extends FeatureUpdateElementImpl {
305
        
306
        
306
        private Set<ModuleUpdateElementImpl> moduleElementsImpl;
307
        private Set<ModuleUpdateElementImpl> moduleElementsImpl;
308
        private Set<FeatureUpdateElementImpl> featureElementsImpl;
307
        private FeatureItem featureItem;
309
        private FeatureItem featureItem;
308
        
310
        
309
        public Agent (FeatureItem item, String providerName, UpdateManager.TYPE type) {
311
        public Agent (FeatureItem item, String providerName, UpdateManager.TYPE type) {
Lines 315-333 Link Here
315
        public Set<ModuleUpdateElementImpl> getContainedModuleElements () {
317
        public Set<ModuleUpdateElementImpl> getContainedModuleElements () {
316
            synchronized(this) {
318
            synchronized(this) {
317
                if (moduleElementsImpl == null) {
319
                if (moduleElementsImpl == null) {
318
                    moduleElementsImpl = processContainedModules (featureItem.getModuleCodeNames (), null);
320
                    Set<FeatureUpdateElementImpl> depFeatures = new HashSet<FeatureUpdateElementImpl>();
321
                    moduleElementsImpl = processContainedModules (featureItem.getModuleCodeNames (), null, depFeatures);
322
                    featureElementsImpl = depFeatures;
319
                }
323
                }
320
            }
324
            }
321
            assert moduleElementsImpl != null : "FeatureUpdateElementImpl contains modules " + moduleElementsImpl;
325
            assert moduleElementsImpl != null : "FeatureUpdateElementImpl contains modules " + moduleElementsImpl;
322
            return moduleElementsImpl;
326
            return moduleElementsImpl;
323
        }
327
        }
324
        
328
        
325
        private Set<ModuleUpdateElementImpl> processContainedModules (Set<String> dependenciesToModules, UpdateUnitProvider provider) {
329
        private Set<ModuleUpdateElementImpl> processContainedModules (
330
            Set<String> dependenciesToModules,
331
            UpdateUnitProvider provider,
332
            Set<FeatureUpdateElementImpl> depFeatures
333
        ) {
326
            Set<ModuleUpdateElementImpl> res = new HashSet<ModuleUpdateElementImpl> ();
334
            Set<ModuleUpdateElementImpl> res = new HashSet<ModuleUpdateElementImpl> ();
327
            assert dependenciesToModules != null : "Invalid Feature " + this + " with null modules.";
335
            assert dependenciesToModules != null : "Invalid Feature " + this + " with null modules.";
328
            if (dependenciesToModules == null) {
336
            if (dependenciesToModules == null) {
329
                dependenciesToModules = Collections.emptySet ();
337
                dependenciesToModules = new HashSet<String>();
330
            } 
338
            } else {
339
                dependenciesToModules = new HashSet<String>(dependenciesToModules);
340
            }
331
            Set<Dependency> deps = new HashSet<Dependency> ();
341
            Set<Dependency> deps = new HashSet<Dependency> ();
332
            for (String depSpec : dependenciesToModules) {
342
            for (String depSpec : dependenciesToModules) {
333
                deps.addAll (Dependency.create (Dependency.TYPE_MODULE, depSpec));
343
                deps.addAll (Dependency.create (Dependency.TYPE_MODULE, depSpec));
Lines 336-342 Link Here
336
                UpdateManager.getDefault ().getUpdateUnits (UpdateManager.TYPE.MODULE) :
346
                UpdateManager.getDefault ().getUpdateUnits (UpdateManager.TYPE.MODULE) :
337
                provider.getUpdateUnits (UpdateManager.TYPE.MODULE);
347
                provider.getUpdateUnits (UpdateManager.TYPE.MODULE);
338
            for (UpdateUnit unit : moduleUnits) {
348
            for (UpdateUnit unit : moduleUnits) {
339
                for (Dependency dep : deps) {
349
                for (Iterator<Dependency> it = deps.iterator(); it.hasNext();) {
350
                    Dependency dep = it.next();
340
                    assert Dependency.TYPE_MODULE == dep.getType () : "Only Dependency.TYPE_MODULE supported, but " + dep;
351
                    assert Dependency.TYPE_MODULE == dep.getType () : "Only Dependency.TYPE_MODULE supported, but " + dep;
341
                    String name = dep.getName ();
352
                    String name = dep.getName ();
342
                    // trim release impl.
353
                    // trim release impl.
Lines 350-361 Link Here
350
                            assert Trampoline.API.impl (el) instanceof ModuleUpdateElementImpl : "Impl of " + el + " is instanceof ModuleUpdateElementImpl.";
361
                            assert Trampoline.API.impl (el) instanceof ModuleUpdateElementImpl : "Impl of " + el + " is instanceof ModuleUpdateElementImpl.";
351
                            ModuleUpdateElementImpl impl = (ModuleUpdateElementImpl) Trampoline.API.impl (el);
362
                            ModuleUpdateElementImpl impl = (ModuleUpdateElementImpl) Trampoline.API.impl (el);
352
                            res.add (impl);
363
                            res.add (impl);
364
                            dependenciesToModules.remove(name);
365
                            it.remove();
353
                        } else {
366
                        } else {
354
                            LOG.log (Level.INFO, getUpdateUnit () + " requires a module " + name + " what is not present.");
367
                            LOG.log (Level.INFO, getUpdateUnit () + " requires a module " + name + " what is not present.");
355
                        }
368
                        }
356
                    }
369
                    }
357
                }
370
                }
358
            }
371
            }
372
            if (!dependenciesToModules.isEmpty()) {
373
                List<UpdateUnit> features = provider == null
374
                        ? UpdateManager.getDefault().getUpdateUnits(UpdateManager.TYPE.FEATURE)
375
                        : provider.getUpdateUnits(UpdateManager.TYPE.FEATURE);
376
                for (UpdateUnit feat : features) {
377
                    for (Iterator<Dependency> it = deps.iterator(); it.hasNext();) {
378
                        Dependency dep = it.next();
379
                        final String name = dep.getName();
380
                        if (name.equals(feat.getCodeName())) {
381
                            UpdateElement el = getMatchedUpdateElement(feat, dep);
382
                            if (el != null) {
383
                                assert Trampoline.API.impl(el) instanceof FeatureUpdateElementImpl : "Impl of " + el + " is instanceof ModuleUpdateElementImpl.";
384
                                FeatureUpdateElementImpl impl = (FeatureUpdateElementImpl) Trampoline.API.impl(el);
385
                                depFeatures.add(impl);
386
                                dependenciesToModules.remove(name);
387
                                it.remove();
388
                            } else {
389
                                LOG.log(Level.INFO, getUpdateUnit() + " requires a module " + name + " what is not present.");
390
                            }
391
                        }
392
                    }
393
                }
394
            }
395
            if (!dependenciesToModules.isEmpty()) {
396
                throw new IllegalStateException("" + dependenciesToModules);
397
            }
359
            return res;
398
            return res;
360
        }
399
        }
361
400
Lines 378-383 Link Here
378
            if (el == null) {
417
            if (el == null) {
379
                return false;
418
                return false;
380
            }
419
            }
420
            UpdateElementImpl impl = Trampoline.API.impl(el);
421
            if (impl instanceof FeatureUpdateElementImpl) {
422
                if (dep.getVersion() == null) {
423
                    return true;
424
                }
425
                SpecificationVersion v = new SpecificationVersion(dep.getVersion());
426
                return v.compareTo(impl.getSpecificationVersion()) >= 0;
427
            }
381
            return DependencyChecker.checkDependencyModuleAllowEqual (dep, Utilities.takeModuleInfo (el));
428
            return DependencyChecker.checkDependencyModuleAllowEqual (dep, Utilities.takeModuleInfo (el));
382
        }
429
        }
383
430
(-)450bd39d99c8 (+241 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
package org.netbeans.modules.autoupdate.services;
45
46
import org.netbeans.api.autoupdate.UpdateUnitProvider.CATEGORY;
47
import org.netbeans.modules.autoupdate.updateprovider.*;
48
import org.netbeans.api.autoupdate.*;
49
import java.io.IOException;
50
import java.util.Collections;
51
import java.util.HashSet;
52
import java.util.List;
53
import java.util.Map;
54
import java.util.Set;
55
import org.netbeans.junit.MockServices;
56
import org.netbeans.junit.NbTestCase;
57
import org.netbeans.modules.autoupdate.updateprovider.InstalledModuleProvider;
58
import org.netbeans.spi.autoupdate.UpdateItem;
59
import org.netbeans.spi.autoupdate.UpdateProvider;
60
import org.openide.modules.Dependency;
61
import org.openide.modules.ModuleInfo;
62
import org.openide.modules.SpecificationVersion;
63
import org.openide.util.Lookup;
64
65
/**
66
 * @author Jaroslav Tulach
67
 */
68
public class FeatureDependsOnFeatureTest extends NbTestCase
69
70
{
71
72
    protected boolean modulesOnly = true;
73
    List<UpdateUnit> keepItNotToGC;
74
75
    public FeatureDependsOnFeatureTest (String testName) {
76
        super (testName);
77
    }
78
79
    public static class MyProvider implements UpdateProvider {
80
81
        public String getName () {
82
            return FeatureDependsOnFeatureTest.class.getName ();
83
        }
84
85
        public String getDisplayName () {
86
            return getName ();
87
        }
88
89
        public String getDescription () {
90
            return getName ();
91
        }
92
93
        public Map<String, UpdateItem> getUpdateItems () throws IOException {
94
            Map<String, UpdateItem> items = InstalledModuleProvider.getDefault().getUpdateItems ();
95
            assertNotNull ("Installed modules must found.", items);
96
            int size = items.size ();
97
            assertTrue ("Count of installed modules are more then once.", size > 1);
98
            String pilotName = items.keySet ().iterator ().next ();
99
            assertNotNull (pilotName + "must found", items.get (pilotName));
100
            UpdateItem pilotItem = items.get (pilotName);
101
            assertNotNull ("Impl of " + pilotItem + " available", Trampoline.SPI.impl (pilotItem));
102
            UpdateItemImpl pilotItemImpl = Trampoline.SPI.impl (pilotItem);
103
            assertTrue ("Impl of " + pilotItem + "is ModuleItem", pilotItemImpl instanceof ModuleItem);
104
            ModuleItem pilotModuleItem = (ModuleItem) pilotItemImpl;
105
            SpecificationVersion pilotSV = new SpecificationVersion (pilotModuleItem.getSpecificationVersion ());
106
            assertTrue ("a dot is present in " + pilotSV, pilotSV.toString ().indexOf ('.') != -1);
107
            int dot = pilotSV.toString ().indexOf ('.');
108
            String postSpec = pilotSV.toString ().substring (dot + 1);
109
            String preSpec = pilotSV.toString ().substring (0, dot);
110
            Integer digit = 0;
111
            try {
112
                digit = Integer.parseInt (preSpec) + 1;
113
            } catch (NumberFormatException nfe) {
114
                fail (nfe.getLocalizedMessage ());
115
            }
116
            SpecificationVersion higherSV = new SpecificationVersion (digit + "." + postSpec);
117
            assertTrue (higherSV + " is more then " + pilotSV, higherSV.compareTo (pilotSV) > 0);
118
            String higherDep = pilotModuleItem.getModuleInfo ().getCodeNameBase () + " > " + higherSV;
119
120
            Set<String> deps = new HashSet<String> (items.size ());
121
            for (String id : items.keySet ()) {
122
                String dep;
123
                if (! pilotName.equals (id)) {
124
                    UpdateItem item = items.get (id);
125
                    assertNotNull ("Impl of " + item + " available", Trampoline.SPI.impl (item));
126
                    UpdateItemImpl itemImpl = Trampoline.SPI.impl (item);
127
                    assertTrue ("Impl of " + item + "is ModuleItem", itemImpl instanceof ModuleItem);
128
                    ModuleItem moduleItem = (ModuleItem) itemImpl;
129
                    dep = moduleItem.getModuleInfo ().getCodeNameBase () + " > " + moduleItem.getSpecificationVersion ();
130
                } else {
131
                    dep = higherDep;
132
                }
133
                deps.add (dep);
134
            }
135
            Map<String, UpdateItem> res = InstalledModuleProvider.getDefault().getUpdateItems ();
136
            ModuleInfo info = pilotModuleItem.getModuleInfo ();
137
            UpdateItemImpl higherItemImpl = new InstalledModuleItem (
138
                    info.getCodeNameBase (),
139
                    higherSV.toString (),
140
                    new HackedModuleInfo (info, higherSV),
141
                    null, // XXX author
142
                    null, // installed cluster
143
                    null);
144
            UpdateItem higherModuleItem = Utilities.createUpdateItem (higherItemImpl);
145
            
146
            res.put ("testFeatueVsStandaloneModules",
147
                    UpdateItem.createFeature (
148
                        "testFeatueVsStandaloneModules",
149
                        "1.0",
150
                        deps,
151
                        null,
152
                        null,
153
                        null));
154
            res.put (pilotName, higherModuleItem);
155
            res.put("testTransitive", UpdateItem.createFeature(
156
                "testTransitive", "1.3",
157
                Collections.singleton("testFeatueVsStandaloneModules"), 
158
                null, null, null
159
            ));
160
            return res;
161
        }
162
163
        public boolean refresh (boolean force) throws IOException {
164
            return true;
165
        }
166
167
        public CATEGORY getCategory() {
168
            return CATEGORY.COMMUNITY;
169
        }
170
    }
171
172
    @Override
173
    protected void setUp () throws Exception {
174
        super.setUp ();
175
        this.clearWorkDir ();
176
        TestUtils.setUserDir (getWorkDirPath ());
177
        TestUtils.testInit ();
178
        MockServices.setServices (MyProvider.class);
179
        assert Lookup.getDefault ().lookup (MyProvider.class) != null;
180
        UpdateUnitProviderFactory.getDefault ().refreshProviders (null, true);
181
    }
182
183
    public void testNoUpToDateFeature () {
184
        assertNotNull ("A feature found.", UpdateManager.getDefault ().getUpdateUnits (UpdateManager.TYPE.FEATURE));
185
        List<UpdateUnit> units = UpdateManager.getDefault ().getUpdateUnits (UpdateManager.TYPE.FEATURE);
186
        assertEquals ("Two features there.", 2, units.size ());
187
        UpdateUnit feature = units.get (0);
188
        if (feature.getCodeName().equals("testFeatueVsStandaloneModules")) {
189
            feature = units.get(1);
190
        }
191
        assertNotNull (feature + " is installed.", feature.getInstalled ());
192
        assertFalse (feature + " has some available updates.", feature.getAvailableUpdates ().isEmpty ());
193
    }
194
    
195
    final static class HackedModuleInfo extends ModuleInfo {
196
        private ModuleInfo info;
197
        private SpecificationVersion hackedVersion;
198
        
199
        public HackedModuleInfo (ModuleInfo info, SpecificationVersion hackedVersion) {
200
            this.info = info;
201
            this.hackedVersion = hackedVersion;
202
        }
203
204
        public String getCodeNameBase () {
205
            return info.getCodeNameBase ();
206
        }
207
208
        public int getCodeNameRelease () {
209
            return info.getCodeNameRelease ();
210
        }
211
212
        public String getCodeName () {
213
            return info.getCodeName ();
214
        }
215
216
        public SpecificationVersion getSpecificationVersion () {
217
            return hackedVersion;
218
        }
219
220
        public boolean isEnabled () {
221
            return info.isEnabled ();
222
        }
223
224
        public Object getAttribute (String attr) {
225
            return info.getAttribute (attr);
226
        }
227
228
        public Object getLocalizedAttribute (String attr) {
229
            return info.getLocalizedAttribute (attr);
230
        }
231
232
        public Set<Dependency> getDependencies () {
233
            return info.getDependencies ();
234
        }
235
236
        public boolean owns (Class<?> clazz) {
237
            return info.owns (clazz);
238
        }
239
        
240
    }
241
}
(-)a/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/FoDUpdateUnitProvider.java (-1 / +5 lines)
Lines 169-175 Link Here
169
                        }
169
                        }
170
                        FeatureInfo fi = FeatureManager.findInfo(d.getName());
170
                        FeatureInfo fi = FeatureManager.findInfo(d.getName());
171
                        if (fi != null) {
171
                        if (fi != null) {
172
                            justKits.addAll(fi.getCodeNames());
172
                            assert fi.getFeatureCodeNameBase() != null : "NoCNB for " + fi;
173
                            String cnb = "fod." + fi.getFeatureCodeNameBase();
174
                            if (!cnb.equals(name)) {
175
                                justKits.add(cnb);
176
                            }
173
                        }
177
                        }
174
                    }
178
                    }
175
                    continue;
179
                    continue;
(-)a/ide.ergonomics/test/unit/src/org/netbeans/modules/ide/ergonomics/fod/EnableJ2EEEnablesJavaTest.java (-2 lines)
Lines 42-48 Link Here
42
42
43
package org.netbeans.modules.ide.ergonomics.fod;
43
package org.netbeans.modules.ide.ergonomics.fod;
44
44
45
import java.lang.reflect.Method;
46
import java.util.List;
45
import java.util.List;
47
import java.util.Set;
46
import java.util.Set;
48
import java.util.HashSet;
47
import java.util.HashSet;
Lines 50-56 Link Here
50
import org.netbeans.api.autoupdate.OperationContainer;
49
import org.netbeans.api.autoupdate.OperationContainer;
51
import org.netbeans.api.autoupdate.OperationContainer.OperationInfo;
50
import org.netbeans.api.autoupdate.OperationContainer.OperationInfo;
52
import org.netbeans.api.autoupdate.OperationSupport;
51
import org.netbeans.api.autoupdate.OperationSupport;
53
import org.netbeans.api.autoupdate.OperationSupport.Restarter;
54
import org.netbeans.api.autoupdate.UpdateElement;
52
import org.netbeans.api.autoupdate.UpdateElement;
55
import org.netbeans.api.autoupdate.UpdateManager;
53
import org.netbeans.api.autoupdate.UpdateManager;
56
import org.netbeans.api.autoupdate.UpdateUnit;
54
import org.netbeans.api.autoupdate.UpdateUnit;

Return to bug 187678